Yangman - requests settings
[dlux.git] / modules / yangman-resources / src / main / resources / yangman / controllers / module-detail.controller.js
1 define([
2     'app/yangman/directives/abn-tree.directive',
3 ], function () {
4     'use strict';
5
6     angular.module('app.yangman').controller('ModuleDetailCtrl', ModuleDetailCtrl);
7
8     ModuleDetailCtrl.$inject = ['$scope', '$rootScope', '$timeout', 'YangmanService', 'constants'];
9
10     function ModuleDetailCtrl($scope, $rootScope, $timeout, YangmanService, constants) {
11         var moduleDetail = this;
12
13         moduleDetail.treeApis = [];
14         moduleDetail.selectedInnerDatastore = null;
15
16         // methods
17         moduleDetail.setApiNode = setApiNode;
18         moduleDetail.setDataDetailStore = setDataDetailStore;
19
20         // WATCHERS
21         $scope.$on(constants.YANGMAN_MODULE_D_INIT, function (){
22             init();
23         });
24
25         /**
26          * Initialization
27          */
28         function init(){
29             $timeout(function () {
30                 moduleDetail.selectedDataStoreIndex =
31                     YangmanService.getDataStoreIndex($scope.selectedModule.children, $scope.selectedDatastore.label);
32                 moduleDetail.treeApis = $scope.selectedDatastore.children;
33             });
34         }
35
36         /**
37          * Set global selected yang node
38          * @param apiIndex
39          * @param subApiIndex
40          */
41         function setApiNode(apiIndex, subApiIndex){
42
43             if (apiIndex !== undefined && subApiIndex !== undefined ) {
44
45                 $scope.setApi($scope.apis[apiIndex], $scope.apis[apiIndex].subApis[subApiIndex], true, true);
46                 $scope.setNode($scope.selectedSubApi.node);
47                 $scope.clearCM();
48                 // let request header ctrl know, that codemirror data should be renewed with data from node
49                 $scope.rootBroadcast(constants.YANGMAN_CHANGE_TO_JSON);
50             }
51         }
52
53         /**
54          * Set datastore to global param
55          * @param dataStore
56          */
57         function setDataDetailStore(dataStore){
58             $scope.setDataStore(dataStore);
59             $scope.setApi($scope.selectedApi, null);
60             $scope.setNode(null);
61             moduleDetail.treeApis = dataStore.children;
62         }
63     }
64
65 });