SearchKit - Add numbers to links when > 1 of the same entity
authorColeman Watts <coleman@civicrm.org>
Fri, 26 Feb 2021 20:50:17 +0000 (15:50 -0500)
committerColeman Watts <coleman@civicrm.org>
Fri, 26 Feb 2021 20:50:17 +0000 (15:50 -0500)
ext/afform/admin/ang/afGuiEditor/afGuiSearch.component.js
ext/search/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js

index f8c282e5a9196fc08b03079d364c1bb2b1a21a14..cf251992b8ebc63e2b552e08efb6ddaf8da9bc88 100644 (file)
@@ -65,7 +65,7 @@
           var joinInfo = join[0].split(' AS '),
             entity = afGui.getEntity(joinInfo[0]),
             alias = joinInfo[1];
-          entityCount[entity.entity] = entityCount[entity.entity] ? entityCount[entity.entity] + 1 : 1;
+          entityCount[entity.entity] = (entityCount[entity.entity] || 0) + 1;
           $scope.fieldList.push({
             entityType: entity.entity,
             label: ts('%1 Fields', {1: entity.label + (entityCount[entity.entity] > 1 ? ' ' + entityCount[entity.entity] : '')}),
index 2e3fd7aebec2bd95600287e3d5dd047e16809f70..83323e732dc392d8ea292b85cee237520644e688 100644 (file)
       // Build a list of all possible links to main entity or join entities
       function buildLinks() {
         // Links to main entity
-        var links = _.cloneDeep(searchMeta.getEntity(ctrl.savedSearch.api_entity).paths || []);
+        var links = _.cloneDeep(searchMeta.getEntity(ctrl.savedSearch.api_entity).paths || []),
+          entityCount = {};
+        entityCount[ctrl.savedSearch.api_entity] = 1;
         // Links to explicitly joined entities
         _.each(ctrl.savedSearch.api_params.join, function(join) {
           var joinName = join[0].split(' AS '),
             joinEntity = searchMeta.getEntity(joinName[0]);
+          entityCount[joinEntity.name] = (entityCount[joinEntity.name] || 0) + 1;
           _.each(joinEntity.paths, function(path) {
             var link = _.cloneDeep(path);
             link.path = link.path.replace(/\[/g, '[' + joinName[1] + '.');
+            if (entityCount[joinEntity.name] > 1) {
+              link.title += ' ' + entityCount[joinEntity.name];
+            }
             links.push(link);
           });
         });