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',
18 'app/yangman/directives/height-watcher.directive',
22 angular.module('app.yangman').controller('YangmanCtrl', YangmanCtrl);
24 YangmanCtrl.$inject = [
25 '$scope', '$rootScope', 'HistorySettingsService', 'YangmanDesignService', 'RequestBuilderService',
26 'EventDispatcherService', 'constants', 'ParametersService', 'PathUtilsService', 'PluginsUnsetterService',
31 $scope, $rootScope, HistorySettingsService, YangmanDesignService, RequestBuilderService, EventDispatcherService,
32 constants, ParametersService, PathUtilsService, PluginsUnsetterService, $timeout
36 $rootScope.section_logo = 'assets/images/logo_yangman.png';
37 $scope.globalViewPath = 'src/app/yangman/views/';
39 $scope.selectedModule = null;
40 $scope.selectedDatastore = null;
41 $scope.selectedPlugin = false;
44 $scope.rightPanelSection = constants.DISPLAY_TYPE_REQ_DATA;
45 $scope.augmentations = {};
46 $scope.selectedApi = null;
47 $scope.selectedSubApi = null;
48 $scope.historyReqsSelected = false;
49 $scope.requestToShow = null;
50 $scope.requestDataToShow = '';
51 $scope.parametersList = ParametersService.createEmptyParametersList('yangman_parameters');
52 $scope.shownCMHint = false;
53 $scope.historySettings = HistorySettingsService.createHistorySettings().loadFromStorage();
55 main.selectedMainTab = 0;
56 main.leftPanelTab = 0;
61 main.executingRequestProgress = false;
62 main.constants = constants;
65 main.initModuleDetailHeight = initModuleDetailHeight;
66 main.switchedTab = switchedTab;
67 main.toggleLeftPanel = toggleLeftPanel;
68 main.leftPanelShowModule = leftPanelShowModule;
69 main.modulesTreeDisplayed = modulesTreeDisplayed;
71 // scope global methods
72 $scope.buildRootRequest = buildRootRequest;
73 $scope.checkAddingListElement = checkAddingListElement;
74 $scope.clearCM = clearCM;
75 $scope.rootBroadcast = rootBroadcast;
76 $scope.setApi = setApi;
77 $scope.setDataStore = setDataStore;
78 $scope.setGlobalParams = setGlobalParams;
79 $scope.setJsonView = setJsonView;
80 $scope.setLeftPanel = setLeftPanel;
81 $scope.setModule = setModule;
82 $scope.setNode = setNode;
83 $scope.setRequestToShow = setRequestToShow;
84 $scope.setRightPanelSection = setRightPanelSection;
85 $scope.switchSection = switchSection;
86 $scope.setParametersList = setParametersList;
87 $scope.unsetPlugin = unsetPlugin;
88 $scope.setSelectedPlugin = setSelectedPlugin;
94 function setSelectedPlugin(selected) {
95 $scope.selectedPlugin = selected;
99 * Start showing progressbar in request header view
101 function startExecutingRequestProgress() {
102 main.executingRequestProgress = true;
107 * Stop showing progressbar in request header view
109 function stopExecutingRequestProgress() {
110 main.executingRequestProgress = false;
114 * Set parametersList to $scope to be available for all controllers directly
115 * @param parametersList
117 function setParametersList(parametersList) {
118 $scope.parametersList = parametersList;
126 $scope.$on(constants.YANGMAN_EXECUTING_REQUEST_PROGRESS_START, startExecutingRequestProgress);
127 $scope.$on(constants.YANGMAN_EXECUTING_REQUEST_PROGRESS_STOP, stopExecutingRequestProgress);
129 YangmanDesignService.hideMainMenu();
130 YangmanDesignService.setDraggableLeftPanel();
131 YangmanDesignService.setJsonSplitter(forceCMsRefresh);
133 EventDispatcherService.registerHandler(constants.EV_FILL_PATH, fillPathIdentifiersByKey);
134 EventDispatcherService.registerHandler(constants.EV_LIST_CHANGED, fillPathIdentifiersByListData);
138 * Initialize module detail height, with timeout
140 function initModuleDetailHeight(){
141 $timeout(function () {
142 YangmanDesignService.setModuleDetailHeight();
147 * Method for fill key into request path, used by yangutils via event dispatching
150 function fillPathIdentifiersByKey(inputs) {
151 var node = inputs[0],
152 value = inputs[1] || '';
154 if ($scope.selectedSubApi && node.parent && $scope.selectedSubApi.node.id === node.parent.id) {
156 $scope.selectedSubApi.pathArray[$scope.selectedSubApi.pathArray.length - 1].identifiers;
158 PathUtilsService.fillIdentifiers(identifiers, node.label, value);
164 * Method for bulk filling path identifiers, used by yangutils via event dispatching
167 function fillPathIdentifiersByListData(inputs) {
168 var node = inputs[0];
170 if ($scope.selectedSubApi && node && $scope.selectedSubApi.node.id === node.id) {
172 $scope.selectedSubApi.pathArray[$scope.selectedSubApi.pathArray.length - 1].identifiers,
175 keys.forEach(function (key) {
176 PathUtilsService.fillIdentifiers(identifiers, key.label, key.value);
183 * Check if the main tab containing tree with modules is displayed
186 function modulesTreeDisplayed() {
187 return main.selectedMainTab === 0;
191 * Set switched tab index
193 function switchedTab(index){
194 main.selectedMainTab = index;
198 * Switcher between modules list and module detail
200 function toggleLeftPanel(){
201 main.leftPanelTab = (main.leftPanelTab + 1) % 2;
205 * Method for opening model detail tab
207 function leftPanelShowModule() {
209 main.leftPanelTab = 1;
214 * General method for switching different section in application
218 function switchSection(param, section){
219 $scope[param] = section;
223 * Genereal method for clearing code mirror - both sent and received data, needs to be in $scope to be available
227 $scope.rootBroadcast(constants.YANGMAN_SET_CODEMIRROR_DATA_RECEIVED, { data: JSON.stringify({}) });
228 $scope.rootBroadcast(constants.YANGMAN_SET_CODEMIRROR_DATA_SENT, { data: JSON.stringify({}) });
233 * Switcher for module detail and module list
236 function setLeftPanel(value) {
237 if ( !angular.isUndefined(value) ) {
238 main.leftPanelTab = value;
243 * Set global necessary params
245 * @param augmentations
247 function setGlobalParams(apis, augmentations){
249 $scope.augmentations = augmentations;
253 * Set node to global param
256 function setNode(node){
261 $scope.$broadcast(constants.YANGMAN_DISABLE_ADDING_LIST_ELEMENT);
266 * Set module to global param
269 function setModule(module){
270 $scope.selectedModule = module;
274 * Set dataStore to global param, open module detail in left panel
279 function setDataStore(dataStore, expand, leftPanel){
280 $scope.selectedDatastore = dataStore;
284 setLeftPanel(leftPanel);
285 $scope.$broadcast(constants.YANGMAN_MODULE_D_INIT);
294 * Build request json from root node
296 function buildRootRequest() {
298 $scope.node.buildRequest(RequestBuilderService, obj, $scope.node.module);
303 * Set api and sub api to global param
307 * @param clearPathArray
309 function setApi(api, subApi, setUrl, clearPathArray){
310 var oldSubApiPathArray = $scope.selectedSubApi ? angular.copy($scope.selectedSubApi.pathArray) : [];
311 $scope.selectedApi = api;
312 $scope.selectedSubApi = subApi;
314 if ( clearPathArray ){
315 PathUtilsService.clearPath($scope.selectedSubApi.pathArray);
317 // todo: move to pathUtils service
318 $scope.selectedSubApi.pathArray.forEach(function (subApiPathElem) {
319 oldSubApiPathArray.forEach(function (oldSubApiPathElem){
320 if (oldSubApiPathElem.module === subApiPathElem.module && oldSubApiPathElem.name === subApiPathElem.name) {
321 oldSubApiPathElem.identifiers.forEach(function (oldPathElemIdentifier, oldPathElemIdentifierKey){
322 subApiPathElem.identifiers.forEach(function (pathElemIdentifier) {
323 if (oldPathElemIdentifier.label === pathElemIdentifier.label) {
324 pathElemIdentifier.value = oldPathElemIdentifier.value;
325 oldSubApiPathElem.identifiers.splice(oldPathElemIdentifierKey, 1);
338 $scope.$broadcast(constants.SET_SEL_OPERATIONS, subApi ? $scope.selectedSubApi.operations : [], setUrl);
342 * Call broadcast from root to child controllers
347 function rootBroadcast(broadcast, params, cbk){
348 $scope.$broadcast(broadcast, { params: params, cbk: cbk });
352 * Set request from history or collections to show data in code mirror
354 * @param {'sentData'|'receivedData'} dataType
356 function setRequestToShow(reqObj, dataType) {
357 $scope.requestToShow = reqObj;
358 $scope.requestDataToShow = dataType;
362 * Set rightPanelSection to display current section in right panel
363 * @param section 'form', 'req-data'
365 function setRightPanelSection(section) {
366 $scope.rightPanelSection = section;
370 * Which codemirror instances will be displayed
374 function setJsonView(received, sent){
375 main.jsonView.received = received;
376 main.jsonView.sent = sent;
378 YangmanDesignService.setJsonSplitter(forceCMsRefresh);
382 * Force refresh of all codemirror instances
384 function forceCMsRefresh(){
385 var elems = angular.element(document).find('.CodeMirror');
386 for (var i = 0; i < elems.length; i++){
387 var cmInstance = elems[i].CodeMirror;
388 cmInstance._handlers.changes[0](cmInstance);
393 * Global method for unset plugin
394 * @param selectedPlugin
397 function unsetPlugin(controller){
398 PluginsUnsetterService.unset($scope, controller);
402 * Checks if the element list should be disabled
404 function checkAddingListElement(node) {
405 return $scope.node === node && $scope.node.type === 'list' &&
406 $scope.node.refKey && $scope.node.refKey.length;