2 'app/yangman/yangman.filters',
3 'app/yangman/controllers/modules-list.controller',
4 'app/yangman/controllers/module-detail.controller',
5 'app/yangman/controllers/yang-form.controller',
6 'app/yangman/controllers/requests-list.controller',
7 'app/yangman/controllers/request-header.controller',
8 'app/yangman/controllers/request-data.controller',
9 'app/yangman/services/yangman.services',
10 'app/yangman/services/handle-file.services',
11 'app/yangman/services/yangman-design.services',
12 'app/yangman/services/requests.services',
13 'app/yangman/services/parameters.services',
14 'app/yangman/services/plugins-unsetter.services',
15 'app/yangman/services/history-settings.services',
16 'app/yangman/directives/ui-codemirror.directive',
17 'app/yangman/directives/read_file.directive',
21 angular.module('app.yangman').controller('YangmanCtrl', YangmanCtrl);
23 YangmanCtrl.$inject = [
24 '$scope', '$rootScope', 'HistorySettingsService', 'YangmanDesignService', 'RequestBuilderService',
25 'EventDispatcherService', 'constants', 'ParametersService', 'PathUtilsService', 'PluginsUnsetterService',
30 $scope, $rootScope, HistorySettingsService, YangmanDesignService, RequestBuilderService, EventDispatcherService,
31 constants, ParametersService, PathUtilsService, PluginsUnsetterService, $timeout
35 $rootScope.section_logo = 'assets/images/logo_yangman.png';
36 $scope.globalViewPath = 'src/app/yangman/views/';
38 $scope.selectedModule = null;
39 $scope.selectedDatastore = null;
40 $scope.selectedPlugin = false;
43 $scope.rightPanelSection = constants.DISPLAY_TYPE_REQ_DATA;
44 $scope.augmentations = {};
45 $scope.selectedApi = null;
46 $scope.selectedSubApi = null;
47 $scope.historyReqsSelected = false;
48 $scope.requestToShow = null;
49 $scope.requestDataToShow = '';
50 $scope.parametersList = ParametersService.createEmptyParametersList('yangman_parameters');
51 $scope.shownCMHint = false;
52 $scope.historySettings = HistorySettingsService.createHistorySettings().loadFromStorage();
54 main.selectedMainTab = 0;
55 main.leftPanelTab = 0;
60 main.executingRequestProgress = false;
61 main.constants = constants;
64 main.initModuleDetailHeight = initModuleDetailHeight;
65 main.switchedTab = switchedTab;
66 main.toggleLeftPanel = toggleLeftPanel;
67 main.leftPanelShowModule = leftPanelShowModule;
68 main.modulesTreeDisplayed = modulesTreeDisplayed;
70 // scope global methods
71 $scope.buildRootRequest = buildRootRequest;
72 $scope.checkAddingListElement = checkAddingListElement;
73 $scope.clearCM = clearCM;
74 $scope.rootBroadcast = rootBroadcast;
75 $scope.setApi = setApi;
76 $scope.setDataStore = setDataStore;
77 $scope.setGlobalParams = setGlobalParams;
78 $scope.setJsonView = setJsonView;
79 $scope.setLeftPanel = setLeftPanel;
80 $scope.setModule = setModule;
81 $scope.setNode = setNode;
82 $scope.setRequestToShow = setRequestToShow;
83 $scope.setRightPanelSection = setRightPanelSection;
84 $scope.switchSection = switchSection;
85 $scope.setParametersList = setParametersList;
86 $scope.unsetPlugin = unsetPlugin;
87 $scope.setSelectedPlugin = setSelectedPlugin;
93 function setSelectedPlugin(selected) {
94 $scope.selectedPlugin = selected;
98 * Start showing progressbar in request header view
100 function startExecutingRequestProgress() {
101 main.executingRequestProgress = true;
106 * Stop showing progressbar in request header view
108 function stopExecutingRequestProgress() {
109 main.executingRequestProgress = false;
113 * Set parametersList to $scope to be available for all controllers directly
114 * @param parametersList
116 function setParametersList(parametersList) {
117 $scope.parametersList = parametersList;
125 $scope.$on(constants.YANGMAN_EXECUTING_REQUEST_PROGRESS_START, startExecutingRequestProgress);
126 $scope.$on(constants.YANGMAN_EXECUTING_REQUEST_PROGRESS_STOP, stopExecutingRequestProgress);
128 YangmanDesignService.hideMainMenu();
129 YangmanDesignService.setDraggableLeftPanel();
130 YangmanDesignService.setJsonSplitter(forceCMsRefresh);
132 EventDispatcherService.registerHandler(constants.EV_FILL_PATH, fillPathIdentifiersByKey);
133 EventDispatcherService.registerHandler(constants.EV_LIST_CHANGED, fillPathIdentifiersByListData);
137 * Initialize module detail height, with timeout
139 function initModuleDetailHeight(){
140 $timeout(function () {
141 YangmanDesignService.setModuleDetailHeight();
146 * Method for fill key into request path, used by yangutils via event dispatching
149 function fillPathIdentifiersByKey(inputs) {
150 var node = inputs[0],
151 value = inputs[1] || '';
153 if ($scope.selectedSubApi && node.parent && $scope.selectedSubApi.node.id === node.parent.id) {
155 $scope.selectedSubApi.pathArray[$scope.selectedSubApi.pathArray.length - 1].identifiers;
157 PathUtilsService.fillIdentifiers(identifiers, node.label, value);
163 * Method for bulk filling path identifiers, used by yangutils via event dispatching
166 function fillPathIdentifiersByListData(inputs) {
167 var node = inputs[0];
169 if ($scope.selectedSubApi && node && $scope.selectedSubApi.node.id === node.id) {
171 $scope.selectedSubApi.pathArray[$scope.selectedSubApi.pathArray.length - 1].identifiers,
174 keys.forEach(function (key) {
175 PathUtilsService.fillIdentifiers(identifiers, key.label, key.value);
182 * Check if the main tab containing tree with modules is displayed
185 function modulesTreeDisplayed() {
186 return main.selectedMainTab === 0;
190 * Set switched tab index
192 function switchedTab(index){
193 main.selectedMainTab = index;
197 * Switcher between modules list and module detail
199 function toggleLeftPanel(){
200 main.leftPanelTab = (main.leftPanelTab + 1) % 2;
204 * Method for opening model detail tab
206 function leftPanelShowModule() {
208 main.leftPanelTab = 1;
213 * General method for switching different section in application
217 function switchSection(param, section){
218 $scope[param] = section;
222 * Genereal method for clearing code mirror - both sent and received data, needs to be in $scope to be available
226 $scope.rootBroadcast(constants.YANGMAN_SET_CODEMIRROR_DATA_RECEIVED, { data: JSON.stringify({}) });
227 $scope.rootBroadcast(constants.YANGMAN_SET_CODEMIRROR_DATA_SENT, { data: JSON.stringify({}) });
232 * Switcher for module detail and module list
235 function setLeftPanel(value) {
236 if ( !angular.isUndefined(value) ) {
237 main.leftPanelTab = value;
242 * Set global necessary params
244 * @param augmentations
246 function setGlobalParams(apis, augmentations){
248 $scope.augmentations = augmentations;
252 * Set node to global param
255 function setNode(node){
260 $scope.$broadcast(constants.YANGMAN_DISABLE_ADDING_LIST_ELEMENT);
265 * Set module to global param
268 function setModule(module){
269 $scope.selectedModule = module;
273 * Set dataStore to global param, open module detail in left panel
278 function setDataStore(dataStore, expand, leftPanel){
279 $scope.selectedDatastore = dataStore;
283 setLeftPanel(leftPanel);
284 $scope.$broadcast(constants.YANGMAN_MODULE_D_INIT);
293 * Build request json from root node
295 function buildRootRequest() {
297 $scope.node.buildRequest(RequestBuilderService, obj, $scope.node.module);
302 * Set api and sub api to global param
306 * @param clearPathArray
308 function setApi(api, subApi, setUrl, clearPathArray){
309 var oldSubApiPathArray = $scope.selectedSubApi ? angular.copy($scope.selectedSubApi.pathArray) : [];
310 $scope.selectedApi = api;
311 $scope.selectedSubApi = subApi;
313 if ( clearPathArray ){
314 PathUtilsService.clearPath($scope.selectedSubApi.pathArray);
316 // todo: move to pathUtils service
317 $scope.selectedSubApi.pathArray.forEach(function (subApiPathElem) {
318 oldSubApiPathArray.forEach(function (oldSubApiPathElem){
319 if (oldSubApiPathElem.module === subApiPathElem.module && oldSubApiPathElem.name === subApiPathElem.name) {
320 oldSubApiPathElem.identifiers.forEach(function (oldPathElemIdentifier, oldPathElemIdentifierKey){
321 subApiPathElem.identifiers.forEach(function (pathElemIdentifier) {
322 if (oldPathElemIdentifier.label === pathElemIdentifier.label) {
323 pathElemIdentifier.value = oldPathElemIdentifier.value;
324 oldSubApiPathElem.identifiers.splice(oldPathElemIdentifierKey, 1);
337 $scope.$broadcast(constants.SET_SEL_OPERATIONS, subApi ? $scope.selectedSubApi.operations : [], setUrl);
341 * Call broadcast from root to child controllers
346 function rootBroadcast(broadcast, params, cbk){
347 $scope.$broadcast(broadcast, { params: params, cbk: cbk });
351 * Set request from history or collections to show data in code mirror
353 * @param {'sentData'|'receivedData'} dataType
355 function setRequestToShow(reqObj, dataType) {
356 $scope.requestToShow = reqObj;
357 $scope.requestDataToShow = dataType;
361 * Set rightPanelSection to display current section in right panel
362 * @param section 'form', 'req-data'
364 function setRightPanelSection(section) {
365 $scope.rightPanelSection = section;
369 * Which codemirror instances will be displayed
373 function setJsonView(received, sent){
374 main.jsonView.received = received;
375 main.jsonView.sent = sent;
377 YangmanDesignService.setJsonSplitter(forceCMsRefresh);
381 * Force refresh of all codemirror instances
383 function forceCMsRefresh(){
384 var elems = angular.element(document).find('.CodeMirror');
385 for (var i = 0; i < elems.length; i++){
386 var cmInstance = elems[i].CodeMirror;
387 cmInstance._handlers.changes[0](cmInstance);
392 * Global method for unset plugin
393 * @param selectedPlugin
396 function unsetPlugin(controller){
397 PluginsUnsetterService.unset($scope, controller);
401 * Checks if the element list should be disabled
403 function checkAddingListElement(node) {
404 return $scope.node === node && $scope.node.type === 'list' &&
405 $scope.node.refKey && $scope.node.refKey.length;