diff --git a/core/ViewDataTable/Config.php b/core/ViewDataTable/Config.php index 364b6d59e33de4dd16711b0500ef63ba0a1f8631..2ccd975c7bf524570ec89b162b5c6ff55cba139a 100644 --- a/core/ViewDataTable/Config.php +++ b/core/ViewDataTable/Config.php @@ -274,6 +274,14 @@ class Config */ public $title = ''; + /** + * If a URL is set, the title of the report will be clickable. Is supposed to be set for entities that can be + * configured (edited) such as goal. Eg when there is a goal report, and someone is allowed to edit the goal entity, + * a link is supposed to be with a URL to the edit goal form. + * @var string + */ + public $title_edit_entity_url = ''; + /** * The report description. eg like a goal description */ diff --git a/plugins/CoreHome/angularjs/reporting-menu/reportingmenu.controller.js b/plugins/CoreHome/angularjs/reporting-menu/reportingmenu.controller.js index f82eca4038e36dce8409592a5544a4fb5dd046c9..dd2b685dc5c5fac2c55ae6dd8ed6e551223f3021 100644 --- a/plugins/CoreHome/angularjs/reporting-menu/reportingmenu.controller.js +++ b/plugins/CoreHome/angularjs/reporting-menu/reportingmenu.controller.js @@ -63,6 +63,7 @@ subcategory.active = true; if (subsubcategory) { + subcategory.name = subsubcategory.name; subsubcategory.active = true; } }; @@ -120,8 +121,9 @@ }); $rootScope.$on('$locationChangeSuccess', function () { - var category = $location.search().category; - var subcategory = $location.search().subcategory; + var $search = $location.search(); + var category = $search.category; + var subcategory = $search.subcategory; period = getUrlParam('period'); date = getUrlParam('date'); diff --git a/plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js b/plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js index cb41198e23a8e80c7e5e89ce35d8154886135ea8..0115b7371516e3998c227e0489352a7187b5c148 100644 --- a/plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js +++ b/plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js @@ -129,6 +129,7 @@ currentElement = contentNode.html(response).children(); if (scope.widgetName) { + // we need to respect the widget title, which overwrites a possibly set report title var $title = currentElement.find('> .card-content .card-title'); if ($title.size()) { $title.text(scope.widgetName); diff --git a/plugins/CoreHome/templates/_dataTable.twig b/plugins/CoreHome/templates/_dataTable.twig index d387244fb75021b5ec3fcb368f6842ee4837dbe1..2ec3f00fa6327f21b3037e99aa5f1d5c0eb4f159 100644 --- a/plugins/CoreHome/templates/_dataTable.twig +++ b/plugins/CoreHome/templates/_dataTable.twig @@ -12,6 +12,7 @@ <div class="card-content"> {% if properties.title %} <h2 class="card-title" + {% if properties.title_edit_entity_url %}edit-url="{{ properties.title_edit_entity_url }}"{% endif %} piwik-enriched-headline >{{ properties.title }}</h2> {% endif %} diff --git a/plugins/CoreVisualizations/Visualizations/Sparklines.php b/plugins/CoreVisualizations/Visualizations/Sparklines.php index fac492c30a7a8f88c9d5a6be161a406b29845790..0407259221df257092dee0aa31e787dc04722ea1 100644 --- a/plugins/CoreVisualizations/Visualizations/Sparklines.php +++ b/plugins/CoreVisualizations/Visualizations/Sparklines.php @@ -72,6 +72,7 @@ class Sparklines extends ViewDataTable $view->sparklines = $this->config->getSortedSparklines(); $view->isWidget = Common::getRequestVar('widget', 0, 'int'); + $view->titleAttributes = $this->config->title_attributes; $view->title = ''; if ($this->config->show_title) { diff --git a/plugins/CoreVisualizations/Visualizations/Sparklines/Config.php b/plugins/CoreVisualizations/Visualizations/Sparklines/Config.php index ca54a6d5643dace9f769048741a2518e7bc1358d..70100f6896b0d8503d1f2bedbe4d49f81d7cb146 100644 --- a/plugins/CoreVisualizations/Visualizations/Sparklines/Config.php +++ b/plugins/CoreVisualizations/Visualizations/Sparklines/Config.php @@ -33,6 +33,13 @@ class Config extends \Piwik\ViewDataTable\Config */ private $sparklines = array(); + /** + * Adds possibility to set html attributes on the sparklines title / headline. For example can be used + * to set an angular directive + * @var string + */ + public $title_attributes = array(); + public function __construct() { parent::__construct(); diff --git a/plugins/CoreVisualizations/templates/_dataTableViz_sparklines.twig b/plugins/CoreVisualizations/templates/_dataTableViz_sparklines.twig index 4ed2dbc6558f153f5827d17128f520aea4948f73..cf4c655fcea20c587649bdc8720b37c604e9de59 100644 --- a/plugins/CoreVisualizations/templates/_dataTableViz_sparklines.twig +++ b/plugins/CoreVisualizations/templates/_dataTableViz_sparklines.twig @@ -3,8 +3,9 @@ {% if not isWidget %} <div class="card"><div class="card-content"> {% endif %} - {% if title is not empty %}<h2 class="card-title">{{ title }}</h2>{% endif %} - + {% if title is not empty %}<h2 class="card-title" + {% if titleAttributes is not empty %}{% for attribute, value in titleAttributes %}{{ attribute }}="{{ value }}"{% endfor %}{% endif %} + >{{ title }}</h2>{% endif %} {% if not isWidget %} <div class="row"> <div class="col m6"> diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php index bdda0b1a60ea0ce7d6a8f4380e35aa547695de0c..0ea6543ccfd09eaebd77070e5ba9dd2f2d5440b0 100644 --- a/plugins/Goals/Goals.php +++ b/plugins/Goals/Goals.php @@ -246,6 +246,7 @@ class Goals extends \Piwik\Plugin public function getJsFiles(&$jsFiles) { + $jsFiles[] = "plugins/Goals/angularjs/common/directives/goal-page-link.js"; $jsFiles[] = "plugins/Goals/angularjs/manage-goals/manage-goals.controller.js"; $jsFiles[] = "plugins/Goals/angularjs/manage-goals/manage-goals.directive.js"; } diff --git a/plugins/Goals/Reports/Get.php b/plugins/Goals/Reports/Get.php index 712a98693780cfd1c6b1f0d4491ea41e867db895..2d64f90364e39c8dcf2abf6528d87bd121130c77 100644 --- a/plugins/Goals/Reports/Get.php +++ b/plugins/Goals/Reports/Get.php @@ -23,6 +23,7 @@ use Piwik\Plugins\Goals\Pages; use Piwik\Report\ReportWidgetFactory; use Piwik\Site; use Piwik\Tracker\GoalManager; +use Piwik\Url; use Piwik\Widget\WidgetsList; class Get extends Base @@ -101,14 +102,19 @@ class Get extends Base { $idGoal = Common::getRequestVar('idGoal', 0, 'string'); + $idSite = $this->getIdSite(); + if ($view->isViewDataTableId(Sparklines::ID)) { /** @var Sparklines $view */ - $idSite = $this->getIdSite(); $isEcommerceEnabled = $this->isEcommerceEnabled($idSite); $onlySummary = Common::getRequestVar('only_summary', 0, 'int'); if ($onlySummary && !empty($idGoal)) { + if (is_numeric($idGoal)) { + $view->config->title_attributes = array('piwik-goal-page-link' => $idGoal); + } + // in Goals overview summary we show proper title for a goal $goal = $this->getGoal($idGoal); if (!empty($goal['name'])) { @@ -182,6 +188,17 @@ class Get extends Base } } } else if ($view->isViewDataTableId(Evolution::ID)) { + if (!empty($idSite) && Piwik::isUserHasAdminAccess($idSite)) { + $view->config->title_edit_entity_url = 'index.php' . Url::getCurrentQueryStringWithParametersModified(array( + 'module' => 'Goals', + 'action' => 'manage', + 'forceView' => null, + 'viewDataTable' => null, + 'showtitle' => null, + 'random' => null + )); + } + $goal = $this->getGoal($idGoal); if (!empty($goal['name'])) { $view->config->title = Piwik::translate('Goals_GoalX', "'" . $goal['name'] . "'"); diff --git a/plugins/Goals/angularjs/common/directives/goal-page-link.js b/plugins/Goals/angularjs/common/directives/goal-page-link.js new file mode 100644 index 0000000000000000000000000000000000000000..590359e033151cfbbe187f46a95676fd4cf1f103 --- /dev/null +++ b/plugins/Goals/angularjs/common/directives/goal-page-link.js @@ -0,0 +1,44 @@ +/*! + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * + * Usage: + * <div piwik-goal-page-link="idGoal"> + */ +(function () { + angular.module('piwikApp.directive').directive('piwikGoalPageLink', piwikGoalPageLink); + + piwikGoalPageLink.$inject = ['$location', 'piwik']; + + function piwikGoalPageLink($location, piwik){ + + return { + restrict: 'A', + compile: function (element, attrs) { + + if (attrs.piwikGoalPageLink && piwik.helper.isAngularRenderingThePage()) { + var title = element.text(); + element.html('<a></a>'); + var link = element.find('a'); + link.text(title); + link.attr('href', 'javascript:void(0)'); + link.bind('click', function () { + var $search = $location.search(); + $search.category = 'Goals_Goals'; + $search.subcategory = encodeURIComponent(attrs.piwikGoalPageLink); + $location.search($search); + }); + } + + return function (scope, element, attrs) { + + }; + } + }; + } +})(); \ No newline at end of file