diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2016-09-29 20:26:16 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2016-09-30 07:37:58 +0300 |
commit | 3845b7bc703431811efab61bbbdf12190e4ec399 (patch) | |
tree | 979b8f760d0c4f8fc15db7ddf35abac9bb769c84 /plugins | |
parent | 644db32bcfce59b90bfa566d05e9702512bea398 (diff) |
lots of improvements
Diffstat (limited to 'plugins')
-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 |
9 files changed, 81 insertions, 9 deletions
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 %} |