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 modulesList.treeApis = YangUtilsService.generateApiTreeData(apis);
107 // $scope.processingModulesSuccessCallback();
108 modulesList.showLoadingBox = false;
109 showToastInfoBox('YANGMAN_LOADED_MODULES');
111 PluginsHandlerService.plugAll(apis, modulesList);
112 // $scope.$broadcast('LOAD_REQ_DATA');
114 showToastInfoBox('YANGMAN_LOADED_MODULES_ERROR');
115 modulesList.showLoadingBox = false;
120 * Set and expand module in tree
122 function setModule(module, e){
123 if ( $(e.target).hasClass('top-element') ) {
124 module.expanded = !module.expanded;
125 //$scope.setModule(module);
130 * Set data store || rpc
134 function setDataStore(dataStore, module){
135 $scope.setModule(module);
136 $scope.setDataStore(dataStore, true, 1);
140 * Method for showing toast box
143 function showToastInfoBox(text){
147 .textContent($filter('translate')(text))
148 .position('bottom left')
149 .parent(angular.element('.yangmanModule__left-panel'))