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;
42 $scope.rightPanelSection = constants.DISPLAY_TYPE_REQ_DATA;
43 $scope.augmentations = {};
44 $scope.selectedApi = null;
45 $scope.selectedSubApi = null;
46 $scope.historyReqsSelected = false;
47 $scope.requestToShow = null;
48 $scope.requestDataToShow = '';
49 $scope.parametersList = ParametersService.createEmptyParametersList('yangman_parameters');
50 $scope.shownCMHint = false;
51 $scope.historySettings = HistorySettingsService.createHistorySettings().loadFromStorage();
53 main.selectedMainTab = 0;
54 main.leftPanelTab = 0;
59 main.executingRequestProgress = false;
60 main.constants = constants;
63 main.initModuleDetailHeight = initModuleDetailHeight;
64 main.switchedTab = switchedTab;
65 main.toggleLeftPanel = toggleLeftPanel;
66 main.leftPanelShowModule = leftPanelShowModule;
67 main.modulesTreeDisplayed = modulesTreeDisplayed;
69 // scope global methods
70 $scope.buildRootRequest = buildRootRequest;
71 $scope.checkAddingListElement = checkAddingListElement;
72 $scope.clearCM = clearCM;
73 $scope.rootBroadcast = rootBroadcast;
74 $scope.setApi = setApi;
75 $scope.setDataStore = setDataStore;
76 $scope.setGlobalParams = setGlobalParams;
77 $scope.setJsonView = setJsonView;
78 $scope.setLeftPanel = setLeftPanel;
79 $scope.setModule = setModule;
80 $scope.setNode = setNode;
81 $scope.setRequestToShow = setRequestToShow;
82 $scope.setRightPanelSection = setRightPanelSection;
83 $scope.switchSection = switchSection;
84 $scope.setParametersList = setParametersList;
85 $scope.unsetPlugin = unsetPlugin;
91 * Start showing progressbar in request header view
93 function startExecutingRequestProgress() {
94 main.executingRequestProgress = true;
99 * Stop showing progressbar in request header view
101 function stopExecutingRequestProgress() {
102 main.executingRequestProgress = false;
106 * Set parametersList to $scope to be available for all controllers directly
107 * @param parametersList
109 function setParametersList(parametersList) {
110 $scope.parametersList = parametersList;
118 $scope.$on(constants.YANGMAN_EXECUTING_REQUEST_PROGRESS_START, startExecutingRequestProgress);
119 $scope.$on(constants.YANGMAN_EXECUTING_REQUEST_PROGRESS_STOP, stopExecutingRequestProgress);
121 YangmanDesignService.hideMainMenu();
122 YangmanDesignService.setDraggableLeftPanel();
123 YangmanDesignService.setJsonSplitter(forceCMsRefresh);
125 EventDispatcherService.registerHandler(constants.EV_FILL_PATH, fillPathIdentifiersByKey);
126 EventDispatcherService.registerHandler(constants.EV_LIST_CHANGED, fillPathIdentifiersByListData);
130 * Initialize module detail height, with timeout
132 function initModuleDetailHeight(){
133 $timeout(function () {
134 YangmanDesignService.setModuleDetailHeight();
139 * Method for fill key into request path, used by yangutils via event dispatching
142 function fillPathIdentifiersByKey(inputs) {
143 var node = inputs[0],
144 value = inputs[1] || '';
146 if ($scope.selectedSubApi && node.parent && $scope.selectedSubApi.node.id === node.parent.id) {
148 $scope.selectedSubApi.pathArray[$scope.selectedSubApi.pathArray.length - 1].identifiers;
150 PathUtilsService.fillIdentifiers(identifiers, node.label, value);
156 * Method for bulk filling path identifiers, used by yangutils via event dispatching
159 function fillPathIdentifiersByListData(inputs) {
160 var node = inputs[0];
162 if ($scope.selectedSubApi && node && $scope.selectedSubApi.node.id === node.id) {
164 $scope.selectedSubApi.pathArray[$scope.selectedSubApi.pathArray.length - 1].identifiers,
167 keys.forEach(function (key) {
168 PathUtilsService.fillIdentifiers(identifiers, key.label, key.value);
175 * Check if the main tab containing tree with modules is displayed
178 function modulesTreeDisplayed() {
179 return main.selectedMainTab === 0;
183 * Set switched tab index
185 function switchedTab(index){
186 main.selectedMainTab = index;
190 * Switcher between modules list and module detail
192 function toggleLeftPanel(){
193 main.leftPanelTab = (main.leftPanelTab + 1) % 2;
197 * Method for opening model detail tab
199 function leftPanelShowModule() {
201 main.leftPanelTab = 1;
206 * General method for switching different section in application
210 function switchSection(param, section){
211 $scope[param] = section;
215 * Genereal method for clearing code mirror - both sent and received data, needs to be in $scope to be available
219 $scope.rootBroadcast(constants.YANGMAN_SET_CODEMIRROR_DATA_RECEIVED, { data: JSON.stringify({}) });
220 $scope.rootBroadcast(constants.YANGMAN_SET_CODEMIRROR_DATA_SENT, { data: JSON.stringify({}) });
225 * Switcher for module detail and module list
228 function setLeftPanel(value) {
229 if ( !angular.isUndefined(value) ) {
230 main.leftPanelTab = value;
235 * Set global necessary params
237 * @param augmentations
239 function setGlobalParams(apis, augmentations){
241 $scope.augmentations = augmentations;
245 * Set node to global param
248 function setNode(node){
253 $scope.$broadcast(constants.YANGMAN_DISABLE_ADDING_LIST_ELEMENT);
258 * Set module to global param
261 function setModule(module){
262 $scope.selectedModule = module;
266 * Set dataStore to global param, open module detail in left panel
271 function setDataStore(dataStore, expand, leftPanel){
272 $scope.selectedDatastore = dataStore;
276 setLeftPanel(leftPanel);
277 $scope.$broadcast(constants.YANGMAN_MODULE_D_INIT);
286 * Build request json from root node
288 function buildRootRequest() {
290 $scope.node.buildRequest(RequestBuilderService, obj, $scope.node.module);
295 * Set api and sub api to global param
299 * @param clearPathArray
301 function setApi(api, subApi, setUrl, clearPathArray){
302 $scope.selectedApi = api;
303 $scope.selectedSubApi = subApi;
305 if ( clearPathArray ){
306 PathUtilsService.clearPath($scope.selectedSubApi.pathArray);
309 $scope.$broadcast(constants.SET_SEL_OPERATIONS, subApi ? $scope.selectedSubApi.operations : [], setUrl);
313 * Call broadcast from root to child controllers
318 function rootBroadcast(broadcast, params, cbk){
319 $scope.$broadcast(broadcast, { params: params, cbk: cbk });
323 * Set request from history or collections to show data in code mirror
325 * @param {'sentData'|'receivedData'} dataType
327 function setRequestToShow(reqObj, dataType) {
328 $scope.requestToShow = reqObj;
329 $scope.requestDataToShow = dataType;
333 * Set rightPanelSection to display current section in right panel
334 * @param section 'form', 'req-data'
336 function setRightPanelSection(section) {
337 $scope.rightPanelSection = section;
341 * Which codemirror instances will be displayed
345 function setJsonView(received, sent){
346 main.jsonView.received = received;
347 main.jsonView.sent = sent;
349 YangmanDesignService.setJsonSplitter(forceCMsRefresh);
353 * Force refresh of all codemirror instances
355 function forceCMsRefresh(){
356 var elems = angular.element(document).find('.CodeMirror');
357 for (var i = 0; i < elems.length; i++){
358 var cmInstance = elems[i].CodeMirror;
359 cmInstance._handlers.changes[0](cmInstance);
364 * Global method for unset plugin
365 * @param selectedPlugin
368 function unsetPlugin(controller){
369 PluginsUnsetterService.unset($scope, controller);
373 * Checks if the element list should be disabled
375 function checkAddingListElement(node) {
376 return $scope.node === node && $scope.node.type === 'list' &&
377 $scope.node.refKey && $scope.node.refKey.length;