2 'app/yangman/services/plugins-handler.services',
6 angular.module('app.yangman').controller('ModulesListCtrl', ModulesListCtrl);
8 ModulesListCtrl.$inject = ['$scope', '$rootScope', '$mdToast', 'YangUtilsService', 'PluginsHandlerService',
9 '$filter', '$timeout'];
11 function ModulesListCtrl($scope, $rootScope, $mdToast, YangUtilsService, PluginsHandlerService, $filter, $timeout) {
12 var modulesList = this;
14 modulesList.treeApis = [];
15 modulesList.showLoadingBox = true;
16 modulesList.moduleListTitle = '';
17 modulesList.search = '';
20 modulesList.clearFilter = clearFilter;
21 modulesList.customSearch = customSearch;
22 modulesList.checkSelectedModule = checkSelectedModule;
23 modulesList.setDataStore = setDataStore;
24 modulesList.setModule = setModule;
27 $scope.$on('YANGMAN_GET_API_TREE_DATA', function (event, args) {
28 (args.cbk || angular.noop)(modulesList.treeApis);
32 $scope.$on('YANGMAN_SET_API_TREE_DATA', function (event, args) {
33 modulesList.treeApis = args.params;
34 modulesList.showLoadingBox = false;
35 showToastInfoBox('YANGMAN_LOADED_MODULES');
38 // show hide loading box
39 $scope.$on('YANGMAN_SET_LOADING_BOX', function (event, args){
40 modulesList.showLoadingBox = args.params;
41 (args.cbk || angular.noop)();
44 // show info box with custom title
45 $scope.$on('YANGMAN_SHOW_TOAST', function (event, args) {
46 showToastInfoBox(args.params);
49 $scope.$on('YANGMAN_SET_MODULE_LIST_TITLE', function (event, args) {
50 modulesList.moduleListTitle = args.params;
63 * Check if module and one of it datastore is selected
65 * @returns {boolean|*|Function|o}
67 function checkSelectedModule(module){
68 var haveSelectedDS = [];
70 if ( $scope.selectedDatastore && (module === $scope.selectedModule)) {
71 haveSelectedDS = $scope.selectedModule.children.filter(function(item){
72 return item === $scope.selectedDatastore;
76 return haveSelectedDS.length;
80 * Custom search function for searching by api label
83 function customSearch(api){
84 return api.label.toLowerCase().indexOf(modulesList.search.toLowerCase()) > -1;
88 * Clear current ctrl search value
90 function clearFilter(){
91 modulesList.search = '';
95 * Load apis and modules
98 modulesList.allNodes = [];
99 modulesList.treeApis = [];
101 modulesList.showLoadingBox = true;
103 YangUtilsService.generateNodesToApis(function (apis, allNodes, augGroups) {
104 $scope.setGlobalParams(apis, augGroups);
105 modulesList.allNodes = allNodes;
106 // console.info('INFO :: got data', apis, modulesList.allNodes, modulesList.augmentations);
107 modulesList.treeApis = YangUtilsService.generateApiTreeData(apis);
108 //console.info('INFO :: tree api', modulesList.treeApis);
109 // $scope.processingModulesSuccessCallback();
110 modulesList.showLoadingBox = false;
111 showToastInfoBox('YANGMAN_LOADED_MODULES');
113 PluginsHandlerService.plugAll(apis, modulesList);
114 // $scope.$broadcast('LOAD_REQ_DATA');
116 showToastInfoBox('YANGMAN_LOADED_MODULES_ERROR');
117 modulesList.showLoadingBox = false;
122 * Set and expand module in tree
124 function setModule(module, e){
125 if ( $(e.target).hasClass('top-element') ) {
126 module.expanded = !module.expanded;
127 //$scope.setModule(module);
132 * Set data store || rpc
136 function setDataStore(dataStore, module){
137 $scope.setModule(module);
138 $scope.setDataStore(dataStore, true, 1);
142 * Method for showing toast box
145 function showToastInfoBox(text){
149 .textContent($filter('translate')(text))
150 .position('bottom left')
151 .parent(angular.element('.yangmanModule__left-panel'))