From 0c02f7d034447edd2fe6ab9bada900403c8389dd Mon Sep 17 00:00:00 2001
From: Thomas Steur <thomas.steur@gmail.com>
Date: Mon, 17 Oct 2016 08:44:32 +0000
Subject: [PATCH] make sure to create a submenu chooser when there are more
 than 5 entries of the same type such as goals or dashboards

---
 plugins/CoreHome/CoreHome.php                 |  1 +
 .../reporting-menu/reportingmenu-model.js     | 30 +++++++++----------
 plugins/CoreHome/lang/en.json                 |  1 +
 plugins/Goals/Goals.php                       |  1 -
 plugins/Goals/lang/en.json                    |  1 -
 5 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/plugins/CoreHome/CoreHome.php b/plugins/CoreHome/CoreHome.php
index e7d8c52185..4c5abc8071 100644
--- a/plugins/CoreHome/CoreHome.php
+++ b/plugins/CoreHome/CoreHome.php
@@ -257,6 +257,7 @@ class CoreHome extends \Piwik\Plugin
         $translationKeys[] = 'Intl_Year_Short';
         $translationKeys[] = 'General_MultiSitesSummary';
         $translationKeys[] = 'General_SearchNoResults';
+        $translationKeys[] = 'CoreHome_ChooseX';
         $translationKeys[] = 'CoreHome_YouAreUsingTheLatestVersion';
         $translationKeys[] = 'CoreHome_IncludeRowsWithLowPopulation';
         $translationKeys[] = 'CoreHome_ExcludeRowsWithLowPopulation';
diff --git a/plugins/CoreHome/angularjs/reporting-menu/reportingmenu-model.js b/plugins/CoreHome/angularjs/reporting-menu/reportingmenu-model.js
index 83a714ceb7..ca26581da0 100644
--- a/plugins/CoreHome/angularjs/reporting-menu/reportingmenu-model.js
+++ b/plugins/CoreHome/angularjs/reporting-menu/reportingmenu-model.js
@@ -82,7 +82,7 @@
 
                 category.subcategories = [];
 
-                var goalsGroup = false;
+                var categoryGroups = false;
 
                 angular.forEach(pages, function (page, key) {
                     if (page.category.id === categoryId) {
@@ -92,25 +92,25 @@
                             subcategory.active = true;
                         }
 
-                        if (page.widgets && page.widgets[0] && page.category.id === 'Goals_Goals' && isNumeric(page.subcategory.id)) {
+                        if (page.widgets && page.widgets[0] && isNumeric(page.subcategory.id)) {
                             // we handle a goal
-                            if (!goalsGroup) {
-                                goalsGroup = angular.copy(subcategory);
-                                goalsGroup.name = $filter('translate')('Goals_ChooseGoal');
-                                goalsGroup.isGroup = true;
-                                goalsGroup.subcategories = [];
-                                goalsGroup.order = 10;
+                            if (!categoryGroups) {
+                                categoryGroups = angular.copy(subcategory);
+                                categoryGroups.name = $filter('translate')('CoreHome_ChooseX', [category.name]);
+                                categoryGroups.isGroup = true;
+                                categoryGroups.subcategories = [];
+                                categoryGroups.order = 10;
                             }
 
                             if (subcategory.active) {
-                                goalsGroup.name = subcategory.name;
-                                goalsGroup.active = true;
+                                categoryGroups.name = subcategory.name;
+                                categoryGroups.active = true;
                             }
 
                             var goalId = page.subcategory.id;
                             subcategory.tooltip = subcategory.name + ' (id = ' + goalId + ' )';
 
-                            goalsGroup.subcategories.push(subcategory);
+                            categoryGroups.subcategories.push(subcategory);
                             return;
                         }
 
@@ -118,12 +118,12 @@
                     }
                 });
 
-                if (goalsGroup && goalsGroup.subcategories && goalsGroup.subcategories.length <= 3) {
-                    angular.forEach(goalsGroup.subcategories, function (subcategory) {
+                if (categoryGroups && categoryGroups.subcategories && categoryGroups.subcategories.length <= 5) {
+                    angular.forEach(categoryGroups.subcategories, function (subcategory) {
                         category.subcategories.push(subcategory);
                     });
-                } else if(goalsGroup) {
-                    category.subcategories.push(goalsGroup);
+                } else if(categoryGroups) {
+                    category.subcategories.push(categoryGroups);
                 }
 
                 category.subcategories = sortMenuItems(category.subcategories);
diff --git a/plugins/CoreHome/lang/en.json b/plugins/CoreHome/lang/en.json
index 814c647cb2..500d67868c 100644
--- a/plugins/CoreHome/lang/en.json
+++ b/plugins/CoreHome/lang/en.json
@@ -7,6 +7,7 @@
         "ClickToEditX": "Click to edit %s",
         "CloseSearch": "Close search",
         "CloseWidgetDirections": "You can close this widget by clicking on the 'X' icon at the top of the widget.",
+        "ChooseX": "Choose %1$s",
         "DataForThisReportHasBeenPurged": "The data for this report is more than %s months old and has been purged.",
         "DataTableExcludeAggregateRows": "Aggregate rows are shown %s Hide them",
         "DataTableIncludeAggregateRows": "Aggregate rows are hidden %s Show them",
diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php
index 0ea6543ccf..0700d8aa75 100644
--- a/plugins/Goals/Goals.php
+++ b/plugins/Goals/Goals.php
@@ -272,6 +272,5 @@ class Goals extends \Piwik\Plugin
         $translationKeys[] = 'Goals_DeleteGoalConfirm';
         $translationKeys[] = 'Goals_Ecommerce';
         $translationKeys[] = 'Goals_Optional';
-        $translationKeys[] = 'Goals_ChooseGoal';
     }
 }
diff --git a/plugins/Goals/lang/en.json b/plugins/Goals/lang/en.json
index 4c886392b2..d78a22a276 100644
--- a/plugins/Goals/lang/en.json
+++ b/plugins/Goals/lang/en.json
@@ -16,7 +16,6 @@
         "CategoryTextVisitsSummary_VisitsSummary": "User attribute",
         "CategoryTextDevicesDetection_DevicesDetection": "Devices",
         "CategoryTextGeneral_Visit": "engagement",
-        "ChooseGoal": "Choose Goal",
         "ClickOutlink": "Click on a Link to an external website",
         "SendEvent": "Send an event",
         "ColumnAverageOrderRevenueDocumentation": "Average Order Value (AOV) is the total revenue from all Ecommerce Orders divided by the number of orders.",
-- 
GitLab