diff options
-rw-r--r-- | core/Report/ReportWidgetConfig.php | 2 | ||||
-rw-r--r-- | core/Widget/WidgetConfig.php | 20 | ||||
-rw-r--r-- | plugins/API/SegmentMetadata.php | 36 | ||||
-rw-r--r-- | plugins/API/WidgetMetadata.php | 1 | ||||
-rw-r--r-- | plugins/CoreHome/Controller.php | 28 | ||||
-rw-r--r-- | plugins/CoreHome/angularjs/reporting-page/reportingpage-model.js | 4 | ||||
-rw-r--r-- | plugins/CoreHome/templates/_singleWidget.twig | 3 | ||||
-rw-r--r-- | plugins/CoreVisualizations/Visualizations/Sparklines.php | 2 | ||||
-rw-r--r-- | plugins/CoreVisualizations/Visualizations/Sparklines/Config.php | 8 | ||||
-rw-r--r-- | plugins/CoreVisualizations/templates/_dataTableViz_sparklines.twig | 4 | ||||
-rw-r--r-- | plugins/CoreVisualizations/templates/macros.twig | 4 | ||||
-rw-r--r-- | tests/PHPUnit/Unit/Widget/WidgetConfigTest.php | 11 |
12 files changed, 114 insertions, 9 deletions
diff --git a/core/Report/ReportWidgetConfig.php b/core/Report/ReportWidgetConfig.php index 3169280ef5..aa27136dde 100644 --- a/core/Report/ReportWidgetConfig.php +++ b/core/Report/ReportWidgetConfig.php @@ -7,6 +7,7 @@ * */ namespace Piwik\Report; +use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable\AllColumns; use Piwik\ViewDataTable\Factory; use Piwik\Widget\WidgetConfig; @@ -20,6 +21,7 @@ class ReportWidgetConfig extends WidgetConfig protected $viewDataTable = null; protected $forceViewDataTable = false; + /** * Sets a default viewDataTable that should be used to render the report. This is not neccessarily the * view that will be actually used to render the report. Eg if a user switched manually to another viewDataTable diff --git a/core/Widget/WidgetConfig.php b/core/Widget/WidgetConfig.php index fcfc72c24b..e50afaff7c 100644 --- a/core/Widget/WidgetConfig.php +++ b/core/Widget/WidgetConfig.php @@ -29,6 +29,7 @@ class WidgetConfig protected $order = 99; protected $isEnabled = true; protected $isWidgetizable = true; + protected $isWide = false; /** * Set the id of the category the widget belongs to. @@ -345,5 +346,24 @@ class WidgetConfig return $this->middlewareParameters; } + /** + * Marks this widget as a "wide" widget that requires the full width. + * + * @return $this + */ + public function setIsWide() + { + $this->isWide = true; + return $this; + } + + /** + * Detect whether the widget should be shown wide or not. + * @return bool + */ + public function isWide() + { + return $this->isWide; + } }
\ No newline at end of file diff --git a/plugins/API/SegmentMetadata.php b/plugins/API/SegmentMetadata.php index 95757638c2..1cce5fd3dd 100644 --- a/plugins/API/SegmentMetadata.php +++ b/plugins/API/SegmentMetadata.php @@ -10,6 +10,7 @@ namespace Piwik\Plugins\API; use Piwik\Columns\Dimension; use Piwik\Piwik; +use Piwik\Plugin\Segment; class SegmentMetadata { @@ -17,14 +18,41 @@ class SegmentMetadata { $segments = array(); + /** + * Triggered to add custom segment definitions. + * + * **Example** + * + * public function addSegments(&$segments) + * { + * $segment = new Segment(); + * $segment->setSegment('my_segment_name'); + * $segment->setType(Segment::TYPE_DIMENSION); + * $segment->setName('My Segment Name'); + * $segment->setSqlSegment('log_table.my_segment_name'); + * $segments[] = $segment; + * } + * + * @param array &$segments An array containing a list of segment entries. + */ + Piwik::postEvent('Segment.addSegments', array(&$segments)); + foreach (Dimension::getAllDimensions() as $dimension) { foreach ($dimension->getSegments() as $segment) { - if ($segment->isRequiresAtLeastViewAccess()) { - $segment->setPermission($isAuthenticatedWithViewAccess); - } + $segments[] = $segment; + } + } - $segments[] = $segment->toArray(); + /** @var Segment[] $dimensionSegments */ + $dimensionSegments = $segments; + $segments = array(); + + foreach ($dimensionSegments as $segment) { + if ($segment->isRequiresAtLeastViewAccess()) { + $segment->setPermission($isAuthenticatedWithViewAccess); } + + $segments[] = $segment->toArray(); } foreach ($segments as &$segment) { diff --git a/plugins/API/WidgetMetadata.php b/plugins/API/WidgetMetadata.php index 8f0fb0330f..2d77e7698d 100644 --- a/plugins/API/WidgetMetadata.php +++ b/plugins/API/WidgetMetadata.php @@ -82,6 +82,7 @@ class WidgetMetadata $item['order'] = $widget->getOrder(); $item['parameters'] = $widget->getParameters(); $item['uniqueId'] = $widget->getUniqueId(); + $item['isWide'] = $widget->isWide(); $middleware = $widget->getMiddlewareParameters(); diff --git a/plugins/CoreHome/Controller.php b/plugins/CoreHome/Controller.php index 4cd94020ab..542b49e394 100644 --- a/plugins/CoreHome/Controller.php +++ b/plugins/CoreHome/Controller.php @@ -11,7 +11,6 @@ namespace Piwik\Plugins\CoreHome; use Exception; use Piwik\API\Request; use Piwik\Common; -use Piwik\DataTable\Renderer\Json; use Piwik\Date; use Piwik\FrontController; use Piwik\Notification\Manager as NotificationManager; @@ -29,6 +28,7 @@ use Piwik\UpdateCheck; use Piwik\Url; use Piwik\View; use Piwik\ViewDataTable\Manager as ViewDataTableManager; +use Piwik\Widget\WidgetConfig; class Controller extends \Piwik\Plugin\Controller { @@ -86,7 +86,31 @@ class Controller extends \Piwik\Plugin\Controller { Piwik::checkUserHasSomeViewAccess(); - return $widget->render(); + $config = new WidgetConfig(); + $widget::configure($config); + + $content = $widget->render(); + + if ($config->getName() && Common::getRequestVar('showtitle', '', 'string') === '1') { + if (strpos($content, '<h2') !== false + || strpos($content, ' content-title=') !== false + || strpos($content, ' piwik-enriched-headline') !== false + || strpos($content, '<h1') !== false ) { + // already includes title + return $content; + } + + if (strpos($content, 'piwik-content-block') === false + && strpos($content, 'card') === false + && strpos($content, 'card-content') === false) { + $view = new View('@CoreHome/_singleWidget'); + $view->title = $config->getName(); + $view->content = $content; + return $view->render(); + } + } + + return $content; } function redirectToCoreHomeIndex() diff --git a/plugins/CoreHome/angularjs/reporting-page/reportingpage-model.js b/plugins/CoreHome/angularjs/reporting-page/reportingpage-model.js index 9683228b4f..f9784ea40b 100644 --- a/plugins/CoreHome/angularjs/reporting-page/reportingpage-model.js +++ b/plugins/CoreHome/angularjs/reporting-page/reportingpage-model.js @@ -47,6 +47,10 @@ return true; } + if ('undefined' !== typeof widget.isWide && widget.isWide) { + return true; + } + return widget.viewDataTable && widget.viewDataTable === 'tableAllColumns'; } diff --git a/plugins/CoreHome/templates/_singleWidget.twig b/plugins/CoreHome/templates/_singleWidget.twig new file mode 100644 index 0000000000..9c2cd98bbe --- /dev/null +++ b/plugins/CoreHome/templates/_singleWidget.twig @@ -0,0 +1,3 @@ +<div piwik-content-block content-title="{{ title|translate|e('html_attr') }}"> + {{ content|raw }} +</div>
\ No newline at end of file diff --git a/plugins/CoreVisualizations/Visualizations/Sparklines.php b/plugins/CoreVisualizations/Visualizations/Sparklines.php index 0407259221..82cdf959cc 100644 --- a/plugins/CoreVisualizations/Visualizations/Sparklines.php +++ b/plugins/CoreVisualizations/Visualizations/Sparklines.php @@ -63,6 +63,8 @@ class Sparklines extends ViewDataTable } } + $view->allMetricsDocumentation = Metrics::getDefaultMetricsDocumentation(); + $this->requestConfig->request_parameters_to_modify['columns'] = $columnsList; $this->requestConfig->request_parameters_to_modify['format_metrics'] = '1'; diff --git a/plugins/CoreVisualizations/Visualizations/Sparklines/Config.php b/plugins/CoreVisualizations/Visualizations/Sparklines/Config.php index 70100f6896..6557abb44b 100644 --- a/plugins/CoreVisualizations/Visualizations/Sparklines/Config.php +++ b/plugins/CoreVisualizations/Visualizations/Sparklines/Config.php @@ -204,9 +204,17 @@ class Config extends \Piwik\ViewDataTable\Config $description = array($description); } + if (!empty($requestParamsForSparkline['columns']) + && count($requestParamsForSparkline['columns']) === count($values)) { + $columns = array_values($requestParamsForSparkline['columns']); + } else { + $columns = array(); + } + if (count($values) === count($description)) { foreach ($values as $index => $value) { $metrics[] = array( + 'column' => isset($columns[$index]) ? $columns[$index] : '', 'value' => $value, 'description' => $description[$index] ); diff --git a/plugins/CoreVisualizations/templates/_dataTableViz_sparklines.twig b/plugins/CoreVisualizations/templates/_dataTableViz_sparklines.twig index cf4c655fce..b0e29cc26a 100644 --- a/plugins/CoreVisualizations/templates/_dataTableViz_sparklines.twig +++ b/plugins/CoreVisualizations/templates/_dataTableViz_sparklines.twig @@ -13,7 +13,7 @@ {% for key, sparkline in sparklines %} {% if key is even %} - {{ macros.singleSparkline(sparkline) }} + {{ macros.singleSparkline(sparkline, allMetricsDocumentation) }} {% endif %} {% endfor %} @@ -25,7 +25,7 @@ {% for key, sparkline in sparklines %} {% if key is odd %} - {{ macros.singleSparkline(sparkline) }} + {{ macros.singleSparkline(sparkline, allMetricsDocumentation) }} {% endif %} {% endfor %} diff --git a/plugins/CoreVisualizations/templates/macros.twig b/plugins/CoreVisualizations/templates/macros.twig index ffd1885be1..43d8c2158e 100644 --- a/plugins/CoreVisualizations/templates/macros.twig +++ b/plugins/CoreVisualizations/templates/macros.twig @@ -1,12 +1,14 @@ -{% macro singleSparkline(sparkline) %} +{% macro singleSparkline(sparkline, allMetricsDocumentation) %} <div class="sparkline"> {% if sparkline.url %}{{ sparkline(sparkline.url)|raw }}{% endif %} {% for metric in sparkline.metrics %} + <span {% if allMetricsDocumentation[metric.column] is defined and allMetricsDocumentation[metric.column] %}title="{{ allMetricsDocumentation[metric.column] }}"{% endif %}> {% if '%s' in metric.description -%} {{ metric.description|translate("<strong>"~metric.value~"</strong>")|raw }} {%- else %} <strong>{{ metric.value }}</strong> {{ metric.description }} {%- endif %}{% if not loop.last %}, {% endif %} + </span> {% endfor %} {% if sparkline.evolution is defined %} diff --git a/tests/PHPUnit/Unit/Widget/WidgetConfigTest.php b/tests/PHPUnit/Unit/Widget/WidgetConfigTest.php index de6917ef0e..6b0b070804 100644 --- a/tests/PHPUnit/Unit/Widget/WidgetConfigTest.php +++ b/tests/PHPUnit/Unit/Widget/WidgetConfigTest.php @@ -52,6 +52,17 @@ class WidgetConfigTest extends \PHPUnit_Framework_TestCase $this->assertSame('', $this->config->getCategoryId()); } + public function test_isWide_shouldBeFalseByDefault() + { + $this->assertFalse($this->config->isWide()); + } + + public function test_setisWide() + { + $this->config->setIsWide(); + $this->assertTrue($this->config->isWide()); + } + public function test_subcategoryId_set_get() { $this->config->setSubcategoryId('testsubcat'); |