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/directives/ui-codemirror.directive',
16 'app/yangman/directives/read_file.directive',
20 angular.module('app.yangman').controller('YangmanCtrl', YangmanCtrl);
22 YangmanCtrl.$inject = [
23 '$mdDialog', '$scope', '$rootScope', 'YangmanDesignService', 'RequestBuilderService',
24 'EventDispatcherService', 'constants', 'ParametersService', 'PathUtilsService', 'PluginsUnsetterService', '$timeout',
28 $mdDialog, $scope, $rootScope, YangmanDesignService, RequestBuilderService,
29 EventDispatcherService, constants, ParametersService, PathUtilsService, PluginsUnsetterService, $timeout
33 $rootScope.section_logo = 'assets/images/logo_yangman.png';
34 $scope.globalViewPath = 'src/app/yangman/views/';
36 $scope.selectedModule = null;
37 $scope.selectedDatastore = null;
40 $scope.rightPanelSection = constants.DISPLAY_TYPE_REQ_DATA;
41 $scope.augmentations = {};
42 $scope.selectedApi = null;
43 $scope.selectedSubApi = null;
44 $scope.historyReqsSelected = false;
45 $scope.requestToShow = null;
46 $scope.requestDataToShow = '';
47 $scope.parametersList = ParametersService.createEmptyParametersList('yangman_parameters');
48 $scope.shownCMHint = false;
50 main.selectedMainTab = 0;
51 main.leftPanelTab = 0;
56 main.executingRequestProgress = false;
57 main.constants = constants;
61 main.initModuleDetailHeight = initModuleDetailHeight;
62 main.switchedTab = switchedTab;
63 main.toggleLeftPanel = toggleLeftPanel;
64 main.leftPanelShowModule = leftPanelShowModule;
65 main.modulesTreeDisplayed = modulesTreeDisplayed;
67 // scope global methods
68 $scope.buildRootRequest = buildRootRequest;
69 $scope.broadcastFromRoot = broadcastFromRoot;
70 $scope.checkAddingListElement = checkAddingListElement;
71 $scope.clearCM = clearCM;
72 $scope.rootBroadcast = rootBroadcast;
73 $scope.setApi = setApi;
74 $scope.setDataStore = setDataStore;
75 $scope.setGlobalParams = setGlobalParams;
76 $scope.setJsonView = setJsonView;
77 $scope.setLeftPanel = setLeftPanel;
78 $scope.setModule = setModule;
79 $scope.setNode = setNode;
80 $scope.setRequestToShow = setRequestToShow;
81 $scope.setRightPanelSection = setRightPanelSection;
82 $scope.switchSection = switchSection;
83 $scope.setParametersList = setParametersList;
84 $scope.unsetPlugin = unsetPlugin;
85 $scope.setCMHintShown = setCMHintShown;
89 function setCMHintShown(shown) {
90 $scope.shownCMHint = shown;
93 function startExecutingRequestProgress() {
94 main.executingRequestProgress = true;
97 function stopExecutingRequestProgress() {
98 main.executingRequestProgress = false;
103 * @param parametersList
105 function setParametersList(parametersList) {
106 $scope.parametersList = parametersList;
111 * Broadcast from this main controller to all children ctrls
115 function broadcastFromRoot(eventName, val) {
116 $scope.$broadcast(eventName, val);
122 $scope.$on('YANGMAN_EXECUTING_REQUEST_PROGRESS_START', startExecutingRequestProgress);
123 $scope.$on('YANGMAN_EXECUTING_REQUEST_PROGRESS_STOP', stopExecutingRequestProgress);
125 YangmanDesignService.hideMainMenu();
126 YangmanDesignService.setDraggableLeftPanel();
127 YangmanDesignService.setJsonSplitter(forceCMsRefresh);
129 EventDispatcherService.registerHandler(constants.EV_FILL_PATH, fillPathIdentifiersByKey);
130 EventDispatcherService.registerHandler(constants.EV_LIST_CHANGED, fillPathIdentifiersByListData);
134 * Initialize module detail height, with timeout
136 function initModuleDetailHeight(){
137 $timeout(function () {
138 YangmanDesignService.setModuleDetailHeight();
143 * Method for fill key into request path
146 function fillPathIdentifiersByKey(inputs) {
147 var node = inputs[0],
148 value = inputs[1] || '';
150 if ($scope.selectedSubApi && node.parent && $scope.selectedSubApi.node.id === node.parent.id) {
152 $scope.selectedSubApi.pathArray[$scope.selectedSubApi.pathArray.length - 1].identifiers;
154 PathUtilsService.fillIdentifiers(identifiers, node.label, value);
158 // TODO :: description
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);
173 // TODO :: description
174 function modulesTreeDisplayed() {
175 return main.selectedMainTab === 0;
179 * Set switched tab index
181 function switchedTab(index){
182 main.selectedMainTab = index;
186 * Switcher between modules list and module detail
188 function toggleLeftPanel(){
189 main.leftPanelTab = (main.leftPanelTab + 1) % 2;
193 * Method for opening model detail tab
195 function leftPanelShowModule() {
197 main.leftPanelTab = 1;
202 * General method for switching different section in application
206 function switchSection(param, section){
207 $scope[param] = section;
211 * Genereal method for clearing code mirror - sent and received data too
214 $scope.rootBroadcast('YANGMAN_SET_CODEMIRROR_DATA_RECEIVED', { data: JSON.stringify({}) });
215 $scope.rootBroadcast('YANGMAN_SET_CODEMIRROR_DATA_SENT', { data: JSON.stringify({}) });
222 * Switcher for module detail and module list
225 function setLeftPanel(value) {
226 if ( !angular.isUndefined(value) ) {
227 main.leftPanelTab = value;
232 * Set global necessary params
235 function setGlobalParams(apis, augmentations){
237 $scope.augmentations = augmentations;
241 * Set node to global param
244 function setNode(node){
249 $scope.$broadcast('YANGMAN_DISABLE_ADDING_LIST_ELEMENT');
254 * Set module to global param
257 function setModule(module){
258 $scope.selectedModule = module;
262 * Set dataStore to global param && open module detail in left panel
266 function setDataStore(dataStore, expand, leftPanel){
267 $scope.selectedDatastore = dataStore;
271 setLeftPanel(leftPanel);
272 $scope.$broadcast('YANGMAN_MODULE_D_INIT');
282 * Build request json from root node
284 function buildRootRequest() {
286 $scope.node.buildRequest(RequestBuilderService, obj, $scope.node.module);
291 * Set api and sub api to global param
295 function setApi(api, subApi, setUrl, clearPathArray){
296 $scope.selectedApi = api;
297 $scope.selectedSubApi = subApi;
299 if ( clearPathArray ){
300 PathUtilsService.clearPath($scope.selectedSubApi.pathArray);
303 $scope.$broadcast('SET_SEL_OPERATIONS', subApi ? $scope.selectedSubApi.operations : [], setUrl);
307 * Call broadcast from root to child controllers
312 function rootBroadcast(broadcast, params, cbk){
313 $scope.$broadcast(broadcast, { params: params, cbk: cbk });
317 * Set request from history or collections to show data in code mirror
319 * @param {'sentData'|'receivedData'} dataType
321 function setRequestToShow(reqObj, dataType) {
322 $scope.requestToShow = reqObj;
323 $scope.requestDataToShow = dataType;
327 * Set rightPanelSection to display current section in right panel
328 * @param section 'form', 'req-data'
330 function setRightPanelSection(section) {
331 $scope.rightPanelSection = section;
335 * Which codemirror instances will be displayed
339 function setJsonView(received, sent){
340 main.jsonView.received = received;
341 main.jsonView.sent = sent;
343 YangmanDesignService.setJsonSplitter(forceCMsRefresh);
347 * Force refresh of all codemirror instances
349 function forceCMsRefresh(){
350 var elems = angular.element(document).find('.CodeMirror');
351 for (var i = 0; i < elems.length; i++){
352 var cmInstance = elems[i].CodeMirror;
353 cmInstance._handlers.changes[0](cmInstance);
358 * Global method for unset plugin
359 * @param selectedPlugin
362 function unsetPlugin(controller){
363 PluginsUnsetterService.unset($scope, controller);
367 * Checks if the element list should be disabled
369 function checkAddingListElement(node) {
370 return $scope.node === node && $scope.node.type === 'list' &&
371 $scope.node.refKey && $scope.node.refKey.length;