Yangman - Refactor refresh/expand collections 51/40951/3
authorMartin Péter Lakatoš <martin.lakatos@pantheon.tech>
Tue, 28 Jun 2016 15:16:15 +0000 (17:16 +0200)
committerDaniel Malachovsky <dmalacho@cisco.com>
Wed, 20 Jul 2016 20:11:25 +0000 (22:11 +0200)
Wrapped function calls inside a new function 'refreshCollections':
 - 'getExpandedCollectionNames'
 - 'expandCollectionByName'

Change-Id: I2de779a1e93cedf84bb5246a4c3f03acc525e349
Signed-off-by: Martin Péter Lakatoš <martin.lakatos@pantheon.tech>
modules/yangman-resources/src/main/resources/yangman/controllers/requests-list.controller.js

index 4c8b06421adad1503f177c978bc29f054c387d6b..a7ce27d40f2ef73a830c4b5515ec8f217f4e9c25 100644 (file)
@@ -35,6 +35,7 @@ define([
         vm.init = init;
         vm.loadRequests = loadRequests;
         vm.readCollectionFromFile = readCollectionFromFile;
+        vm.refreshCollections = refreshCollections;
         vm.selectAllRequests = selectAllRequests;
         vm.selectRequest = selectRequest;
         vm.showData = showData;
@@ -287,7 +288,7 @@ define([
 
 
         /**
-         * Dialog for delete collection
+         * Dialog for deleting collection and refreshing collections
          * @param ev
          * @param collObj
          */
@@ -304,10 +305,7 @@ define([
                 ev.stopPropagation();
                 vm.collectionList.deleteCollection(collObj);
                 vm.collectionList.saveToStorage();
-                var collectionNames = vm.collectionList.getExpandedCollectionNames();
-                $scope.rootBroadcast('YANGMAN_REFRESH_AND_EXPAND_COLLECTIONS', null, function(){
-                    vm.collectionList.expandCollectionByNames(collectionNames);
-                });
+                refreshCollections();
             });
         }
 
@@ -419,23 +417,17 @@ define([
         function changeCollectionName(names){
             vm.collectionList.renameCollection(names[0], names[1]);
             vm.collectionList.saveToStorage();
-            var collectionNames = vm.collectionList.getExpandedCollectionNames();
-            $scope.rootBroadcast('YANGMAN_REFRESH_AND_EXPAND_COLLECTIONS', null, function(){
-                vm.collectionList.expandCollectionByNames(collectionNames);
-            });
+            refreshCollections();
         }
 
         /**
-         * Create collection duplicate and save
+         * Create collection duplicate, save and refresh collections
          * @param {array} names 0. element is old name, 1. element is new name
          */
         function duplicateCollection(names){
             vm.collectionList.duplicateCollection(names[0], names[1]);
             vm.collectionList.saveToStorage();
-            var collectionNames = vm.collectionList.getExpandedCollectionNames();
-            $scope.rootBroadcast('YANGMAN_REFRESH_AND_EXPAND_COLLECTIONS', null, function(){
-                vm.collectionList.expandCollectionByNames(collectionNames);
-            });
+            refreshCollections();
         }
 
         /**
@@ -511,6 +503,16 @@ define([
             });
         }
 
+        /**
+         * Refresh and expand collections
+         */
+        function refreshCollections(){
+            var collectionNames = vm.collectionList.getExpandedCollectionNames();
+            $scope.rootBroadcast('YANGMAN_REFRESH_AND_EXPAND_COLLECTIONS', null, function(){
+                vm.collectionList.expandCollectionByNames(collectionNames);
+            });
+        }
+
     }
 
 });