Merge changes from topic 'bugfix/update-ui-compo'
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / app.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * 
22  */
23
24 'use strict';
25
26 /* App Module */
27
28 var app = angular.module('clds-app', ['ngRoute',
29     'ngResource',
30     'ui.bootstrap',
31     'angular-loading-bar',
32     'ngAnimate',
33     'dialogs.main',
34     'ngSanitize',
35     'ngCookies',
36     'ui.bootstrap.modal'
37   ])
38   .config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {
39
40     cfpLoadingBarProvider.includeBar = true;
41     cfpLoadingBarProvider.includeSpinner = true;
42   }])
43   .config(
44     function($httpProvider) {
45
46       $httpProvider.responseInterceptors
47         .push('myHttpInterceptor');
48
49       var spinnerFunction = function spinnerFunction(data,
50         headersGetter) {
51
52         return data;
53       };
54
55       $httpProvider.defaults.transformRequest
56         .push(spinnerFunction);
57     })
58   .config(
59     [
60       '$routeProvider',
61       '$locationProvider',
62       '$compileProvider',
63       'cfpLoadingBarProvider',
64       function($routeProvider, $locationProvider,
65         cfpLoadingBarProvider, $timeout, dialogs,
66         $cookies) {
67         $locationProvider.html5Mode(false);
68         // alert("App.js");
69
70         $routeProvider
71           .when('/otherwise', {
72             templateUrl: 'please_wait.html',
73             controller: QueryParamsHandlerCtrl
74           })
75           .
76         // when('/dashboard_submit', { templateUrl:
77         // 'partials/portfolios/dashboard_submit.html',
78         // controller: CreateNewPrjCtrl }).
79         when(
80             '/dashboard', {
81               templateUrl: 'partials/portfolios/clds_modelling.html',
82               controller: DashboardCtrl
83             })
84           .
85         // when('/dashboard_upload', { templateUrl:
86         // 'partials/portfolios/dashboard_upload.html',
87         // controller: DashboardCtrl }).
88         when(
89           '/activity_modelling', {
90             templateUrl: 'partials/portfolios/clds_modelling.html',
91             controller: DashboardCtrl
92           }).when('/authenticate', {
93           templateUrl: 'authenticate.html',
94           controller: AuthenticateCtrl
95         }).when('/invalidlogin', {
96           templateUrl: 'invalid_login.html',
97           controller: PageUnderConstructionCtrl
98         }).otherwise({
99           redirectTo: '/otherwise'
100         });
101
102       }
103     ])
104   .controller(
105     'dialogCtrl',
106     function($scope, $rootScope, $timeout, dialogs) {
107
108       // -- Variables --//
109
110       $scope.lang = 'en-US';
111       $scope.language = 'English';
112
113       var _progress = 100;
114
115       $scope.name = '';
116       $scope.confirmed = 'No confirmation yet!';
117
118       $scope.custom = {
119         val: 'Initial Value'
120       };
121
122       // -- Listeners & Watchers --//
123
124       $scope.$watch('lang', function(val, old) {
125
126         switch (val) {
127           case 'en-US':
128             $scope.language = 'English';
129             break;
130           case 'es':
131             $scope.language = 'Spanish';
132             break;
133         }
134       });
135
136       // -- Methods --//
137       $rootScope.testCaseRequirements = [];
138       $rootScope.validTestRequirements = [];
139       /* $rootScope.testCaseValue=[]; */
140       $scope.setLanguage = function(lang) {
141
142         $scope.lang = lang;
143         $translate.use(lang);
144       };
145
146       $rootScope.launch = function(which) {
147
148         switch (which) {
149           case 'error':
150             dialogs.error();
151             break;
152           case 'wait':
153             // var dlg =
154             // dialogs.wait(undefined,undefined,_progress);
155             // _fakeWaitProgress();
156             break;
157           case 'customwait':
158             // var dlg = dialogs.wait('Custom Wait
159             // Header','Custom Wait Message',_progress);
160             // _fakeWaitProgress();
161             break;
162           case 'notify':
163             dialogs.notify();
164             break;
165           case 'confirm':
166             var dlg = dialogs.confirm();
167             dlg.result.then(function(btn) {
168
169               $scope.confirmed = 'You confirmed "Yes."';
170             }, function(btn) {
171
172               $scope.confirmed = 'You confirmed "No."';
173             });
174             break;
175           case 'custom':
176             var dlg = dialogs.create('/dialogs/custom.html',
177               'customDialogCtrl', {}, {
178                 size: 'lg',
179                 keyboard: true,
180                 backdrop: 'static',
181                 windowClass: 'my-class'
182               });
183             dlg.result
184               .then(
185                 function(name) {
186
187                   $scope.name = name;
188                 },
189                 function() {
190
191                   if (angular.equals($scope.name,
192                       ''))
193                     $scope.name = 'You did not enter in your name!';
194                 });
195             break;
196           case 'custom2':
197             var dlg = dialogs.create('/dialogs/custom2.html',
198               'customDialogCtrl2', $scope.custom, {
199                 size: 'lg'
200               });
201             break;
202           case 'custom3':
203             var dlg = dialogs
204               .notify(
205                 'Message',
206                 'All is not supported, Please select interface(s)/version(s) to fetch real time federated coverage report.');
207             break;
208           case 'custom4':
209             var dlg = dialogs
210               .confirm(
211                 'Message',
212                 'You are about to fetch real time federated coverage report.This may take sometime!!!.');
213             dlg.result.then(function(btn) {
214
215               $scope.confirmed = 'You confirmed "Yes."';
216             }, function(btn) {
217
218               $scope.confirmed = 'You confirmed "No."';
219             });
220             break;
221           case 'custom5':
222             var dlg = dialogs.notify('Success',
223               'Request has been successfully processed.');
224             break;
225           case 'custom6':
226             var dlg = dialogs.notify('Message',
227               'Please type Testscenario Name');
228             break;
229         }
230       }; // end launch
231
232       var _fakeWaitProgress = function() {
233
234         $timeout(function() {
235
236           if (_progress < 100) {
237             _progress += 33;
238             $rootScope.$broadcast('dialogs.wait.progress', {
239               'progress': _progress
240             });
241             _fakeWaitProgress();
242           } else {
243             $rootScope.$broadcast('dialogs.wait.complete');
244             _progress = 0;
245           }
246         }, 1000);
247       };
248     })
249   .controller(
250     'MenuCtrl', [
251       '$scope',
252       '$rootScope',
253       '$timeout',
254       'dialogs',
255       '$location',
256       'MenuService',
257       'Datafactory',
258       'userPreferencesService',
259       'cldsModelService',
260       'extraUserInfoService',
261       function($scope, $rootScope, $timeout, dialogs,
262         $location, MenuService, Datafactory,
263         userPreferencesService, cldsModelService, extraUserInfoService) {
264         console.log("MenuCtrl");
265         $rootScope.screenName = "Universal Test Modeler";
266         $rootScope.testSet = null;
267         var testingType = "";
268         $rootScope.contactUs = function() {
269           console.log("contactUs");
270           var link = "mailto:onap-discuss@lists.onap.org?subject=CLAMP&body=Please send us suggestions or feature enhancements or defect. If possible, please send us the steps to replicate any defect.";
271           window.location.href = link;
272         };
273
274         extraUserInfoService
275           .getUserInfo()
276           .then(
277             function(pars) {
278               $scope.userInfo = pars;
279               if (!($scope.userInfo["permissionUpdateCl"])) {
280                 readMOnly = true;
281               };
282             });
283
284         $scope.emptyMenuClick = function(value, name) {
285           if ($rootScope.isNewClosed &&
286             name != "Save CL" &&
287             name != "Close Model" &&
288             name != "Properties CL") {
289             saveConfirmationNotificationPopUp();
290           } else {
291             isSaveCheck(name);
292           }
293
294           function saveConfirmationNotificationPopUp() {
295             $scope
296               .saveConfirmationNotificationPopUp(function(
297                 data) {
298                 if (data) {
299                   if ($rootScope.isNewClosed) {
300                     isSaveCheck("Save CL");
301                   } 
302                   $rootScope.isNewClosed = false;
303                 } else {
304                   return false;
305                 }
306               });
307           }
308
309           function isSaveCheck(name) {
310             if (name == "User Info") {
311               $scope.extraUserInfo();
312             } else if (name == "Wiki") {
313               window.open(value);
314             } else if (name == "Contact Us") {
315               $rootScope.contactUs();
316             } else if (name == "Revert Model Changes") {
317               $scope.cldsRevertModel();
318             } else if (name == "Close Model") {
319               $scope.cldsClose();
320             } else if (name == "Refresh ASDC") {
321               $scope.cldsRefreshASDC();
322             } else if (name == "Create CL") {
323               $rootScope.isNewClosed = true;
324               $scope.cldsCreateModel();
325             } else if (name == "Open CL") {
326               $scope.cldsOpenModel();
327             } else if (name == "Save CL") {
328               $rootScope.isNewClosed = false;
329               $scope.cldsPerformAction("SAVE");
330             } else if (name == "Validation Test") {
331               $scope.cldsPerformAction("TEST");
332             } else if (name == "Submit") {
333               $scope
334                 .cldsConfirmPerformAction("SUBMIT");
335             } else if (name == "Resubmit") {
336               $scope
337                 .cldsConfirmPerformAction("RESUBMIT");
338             } else if (name == "Update") {
339               $scope
340                 .cldsConfirmPerformAction("UPDATE");
341             } else if (name.toLowerCase() == "delete") {
342               $scope
343                 .manageConfirmPerformAction("DELETE");
344             } else if (name == "Stop") {
345               $scope.cldsConfirmPerformAction("STOP");
346             } else if (name == "Restart") {
347               $scope
348                 .cldsConfirmPerformAction("RESTART");
349             } else if (name == "Refresh Status") {
350               $scope.refreshStatus();
351             } else if (name == "Properties CL") {
352               $scope.cldsOpenModelProperties();
353             } else if (name == "Deploy") {
354               $scope
355                 .cldsAskDeployParametersPerformAction();
356             } else if (name == "UnDeploy") {
357               $scope
358                 .cldsConfirmToggleDeployPerformAction("UnDeploy");
359             } else {
360               $rootScope.screenName = name;
361               $scope.updatebreadcrumb(value);
362               $location.path(value);
363             }
364           }
365         };
366
367         $rootScope.impAlerts = function() {
368
369         };
370
371         $scope.tabs = {
372           "Closed Loop": [{
373             link: "/cldsCreateModel",
374             name: "Create CL"
375           }, {
376             link: "/cldsOpenModel",
377             name: "Open CL"
378           }, {
379             link: "/cldsSaveModel",
380             name: "Save CL"
381           }, {
382             link: "/cldsOpenModelProperties",
383             name: "Properties CL"
384           }, {
385             link: "/RevertChanges",
386             name: "Revert Model Changes"
387           }, {
388             link: "/Close",
389             name: "Close Model"
390           }],
391           "Manage": [{
392             link: "/cldsTestActivate",
393             name: "Validation Test"
394           }, {
395             link: "/cldsSubmit",
396             name: "Submit"
397           }, {
398             link: "/cldsResubmit",
399             name: "Resubmit"
400           }, {
401             link: "/cldsUpdate",
402             name: "Update"
403           }, {
404             link: "/cldsStop",
405             name: "Stop"
406           }, {
407             link: "/cldsRestart",
408             name: "Restart"
409           }, {
410             link: "/cldsDelete",
411             name: "Delete"
412           }, {
413             link: "/cldsDeploy",
414             name: "Deploy"
415           }, {
416             link: "/cldsUnDeploy",
417             name: "UnDeploy"
418           }],
419           "View": [{
420             link: "/refreshStatus",
421             name: "Refresh Status"
422           }, {
423             link: "/cldsRefreshASDC",
424             name: "Refresh ASDC"
425           }],
426           "Help": [{
427             link: "http://wiki.onap.org",
428             name: "Wiki"
429           }, {
430             link: "/contact_us",
431             name: "Contact Us"
432           }, {
433             link: "/extraUserInfo",
434             name: "User Info"
435           }]
436         };
437
438         if (!Object.keys) {
439           Object.keys = function(obj) {
440             var keys = [];
441
442             for (var i in obj) {
443               if (obj.hasOwnProperty(i)) {
444                 keys.push(i);
445               }
446             }
447
448             return keys;
449           };
450           $scope.keyList = Object.keys($scope.tabs);
451         } else {
452           $scope.keyList = Object.keys($scope.tabs);
453         }
454
455         $scope.updatebreadcrumb = function(path) {
456
457           var currentURL = $location.path();
458           if (path != undefined) {
459             currentURL = path;
460           }
461
462           if (currentURL == "/dashboard") {
463             $rootScope.screenName = "Universal Test Modeler";
464             $rootScope.parentMenu = "Home";
465             $rootScope.rightTabName = "UTM Build Configuration";
466           }
467           /*
468            * else if(currentURL=="/quicksearch") {
469            * $rootScope.screenName = "Quick Search";
470            * $rootScope.parentMenu = "Home"; }
471            */
472           else {
473             var found = false;
474
475             angular
476               .forEach(
477                 $scope.keyList,
478                 function(value, key) {
479
480                   if (!found) {
481                     $rootScope.parentMenu = value;
482
483                     angular
484                       .forEach(
485                         $scope.tabs[value],
486                         function(
487                           value,
488                           key) {
489
490                           if (currentURL == value.link) {
491                             $rootScope.screenName = value.name;
492                             found = true;
493                           }
494                         });
495                   }
496                 });
497           }
498         };
499
500         $scope.updatebreadcrumb();
501
502         $scope.homePage = function() {
503
504           $location.path('/dashboard');
505         };
506         $scope.propertyExplorerErrorMessage = function(msg) {
507
508           var dlg = dialogs.notify('Error', msg);
509         }
510
511         // $scope.fromTstMultipleFlag=false;
512         /* onclicking of review testset / generate testset */
513
514         $scope.reviewTestSet = function() {
515
516           $rootScope.modeltestset = list_model_test_sets[selected_model];
517
518           $rootScope.isPalette = false;
519           $rootScope.isTestset = true;
520           $rootScope.isRequirementCoverage = false;
521           document.getElementById("modeler_name").textContent = "UTM Test Set";
522           // document.getElementById('propertyExplorer').classList.add('visible');
523
524           // $( "#propertyExplorer" ).prev().css(
525           // "display", "none" );
526           $('div').find('.k-collapse-next').click();
527
528           // $rootScope.$apply();
529
530         };
531         $scope.requirementCoverage = function() {
532
533           $rootScope.testCaseRequirements = [];
534           $rootScope.validTestRequirementArray = [];
535           $rootScope.validTestRequirements = {};
536           $rootScope.modeltestset = list_model_test_sets[selected_model];
537           var allPathDetails = [];
538           $scope.currentSelectedModel = {};
539           // $scope.getPathDetails($rootScope.utmModels,selected_model);
540           // $scope.populatePathDetails(allPathDetails,$scope.currentSelectedModel);
541           $rootScope.pathDetailsList = list_model_path_details[selected_model];
542           /*
543            * for(var p=0;p<100;p++){
544            * $rootScope.testCaseRequirements.push("Requirement"+p); }
545            * for(var p=0;p<100;p++){
546            * $rootScope.testCaseValue.push("TestCase"+p); }
547            */
548           for (var x = 0; x < allPathDetails.length; x++) {
549             var tempPathDetails = allPathDetails[x];
550             if (tempPathDetails != null) {
551               for (var i = 0; i < tempPathDetails.length; i++) {
552                 var pathDetails = tempPathDetails[i];
553                 if (pathDetails.requirement !== '' &&
554                   pathDetails.requirement !== null) {
555                   $rootScope.testCaseRequirements
556                     .push(pathDetails.requirement);
557                 }
558
559                 /*
560                  * for (var j = 0; j <
561                  * pathDetails.decisionIdentifiers.length;
562                  * j++) {
563                  * if(pathDetails.decisionIdentifiers[j].requirement
564                  * !== '' &&
565                  * pathDetails.decisionIdentifiers[j].requirement
566                  * !== null){
567                  * $rootScope.testCaseRequirements.push(pathDetails.decisionIdentifiers[j].requirement); } }
568                  */
569               }
570             }
571
572           }
573           for (var p = 0; p < $rootScope.modeltestset.activityTestCases.length; p++) {
574             var activityTestCases = $rootScope.modeltestset.activityTestCases[p];
575             if (activityTestCases.mappedRequirements != null) {
576               for (var i = 0; i < activityTestCases.mappedRequirements.length; i++) {
577                 // $rootScope.testCaseRequirements
578                 // .push(activityTestCases.mappedRequirements[i]);
579                 var testCaseNames = $rootScope.validTestRequirements[activityTestCases.mappedRequirements[i]];
580                 if (testCaseNames == null) {
581                   testCaseNames = [];
582                 }
583                 if (activityTestCases.version != null)
584                   var testCase = activityTestCases.testCaseName +
585                     "_" +
586                     activityTestCases.version;
587                 else
588                   var testCase = activityTestCases.testCaseName;
589                 testCaseNames.push(testCase);
590                 $rootScope.validTestRequirements[activityTestCases.mappedRequirements[i]] = testCaseNames;
591               }
592             }
593           }
594
595           $rootScope.isPalette = false;
596           $rootScope.isTestset = false;
597           $rootScope.isRequirementCoverage = true;
598           document.getElementById("modeler_name").textContent = "Test Case / Requirement Coverage";
599
600           $('div').find('.k-collapse-next').click();
601
602
603         };
604
605         $scope.activityModelling = function() {
606         };
607
608
609         $scope.cldsClose = function() {
610
611           var dlg = dialogs
612             .create(
613               'partials/portfolios/confirmation_window.html',
614               'CldsOpenModelCtrl', {
615                 closable: true,
616                 draggable: true
617               }, {
618                 size: 'lg',
619                 keyboard: true,
620                 backdrop: 'static',
621                 windowClass: 'my-class'
622               });
623
624           dlg.result.then(function(name) {
625
626             // $scope.name = name;
627           }, function() {
628
629             // if(angular.equals($scope.name,''))
630             // $scope.name = 'You did not enter in your
631             // name!';
632           });
633         };
634         $scope.saveConfirmationNotificationPopUp = function(
635           callBack) {
636
637           var dlg = dialogs
638             .create(
639               'partials/portfolios/save_confirmation.html',
640               'saveConfirmationModalPopUpCtrl', {
641                 closable: true,
642                 draggable: true
643               }, {
644                 size: 'lg',
645                 keyboard: true,
646                 backdrop: 'static',
647                 windowClass: 'my-class'
648               });
649
650           dlg.result.then(function(name) {
651             callBack("OK");
652           }, function() {
653             callBack(null);
654           });
655
656         };
657
658         $scope.cldsRefreshASDC = function() {
659
660           var dlg = dialogs
661             .create(
662               'partials/portfolios/refresh_asdc.html',
663               'CldsOpenModelCtrl', {
664                 closable: true,
665                 draggable: true
666               }, {
667                 size: 'lg',
668                 keyboard: true,
669                 backdrop: 'static',
670                 windowClass: 'my-class'
671               });
672           dlg.result.then(function(name) {
673
674             // $scope.name = name;
675           }, function() {
676
677             // if(angular.equals($scope.name,''))
678             // $scope.name = 'You did not enter in your
679             // name!';
680           });
681         }
682         $scope.cldsRevertModel = function() {
683
684           var dlg = dialogs
685             .create(
686               'partials/portfolios/ConfirmRevertChanges.html',
687               'CldsOpenModelCtrl', {
688                 closable: true,
689                 draggable: true
690               }, {
691                 size: 'lg',
692                 keyboard: true,
693                 backdrop: 'static',
694                 windowClass: 'my-class'
695               });
696
697           dlg.result.then(function(name) {
698
699             // $scope.name = name;
700           }, function() {
701
702             // if(angular.equals($scope.name,''))
703             // $scope.name = 'You did not enter in your
704             // name!';
705           });
706
707         };
708
709         $rootScope.cldsOpenModelProperties = function() {
710
711           var dlg = dialogs
712             .create(
713               'partials/portfolios/global_properties.html',
714               'GlobalPropertiesCtrl', {}, {
715                 size: 'lg',
716                 keyboard: true,
717                 backdrop: 'static',
718                 windowClass: 'my-class'
719               });
720
721           dlg.result.then(function(name) {}, function() {});
722         };
723
724         $scope.cldsOpenModel = function() {
725
726           var dlg = dialogs
727             .create(
728               'partials/portfolios/clds_open_model.html',
729               'CldsOpenModelCtrl', {
730                 closable: true,
731                 draggable: true
732               }, {
733                 size: 'lg',
734                 keyboard: true,
735                 backdrop: 'static',
736                 windowClass: 'my-class'
737               });
738
739           dlg.result.then(function(name) {
740
741             // $scope.name = name;
742           }, function() {
743
744             // if(angular.equals($scope.name,''))
745             // $scope.name = 'You did not enter in your
746             // name!';
747           });
748         };
749         $scope.cldsCreateModel = function() {
750
751           var dlg = dialogs
752             .create(
753               'partials/portfolios/clds_create_model_off_Template.html',
754               'CldsOpenModelCtrl', {
755                 closable: true,
756                 draggable: true
757               }, {
758                 size: 'lg',
759                 keyboard: true,
760                 backdrop: 'static',
761                 windowClass: 'my-class'
762               });
763
764           dlg.result.then(function(name) {
765
766             // $scope.name = name;
767           }, function() {
768
769             // if(angular.equals($scope.name,''))
770             // $scope.name = 'You did not enter in your
771             // name!';
772           });
773
774         };
775         $scope.extraUserInfo = function() {
776
777           var dlg = dialogs
778             .create(
779               'partials/portfolios/extra_user_info.html',
780               'ExtraUserInfoCtrl', {
781                 closable: true,
782                 draggable: true
783               }, {
784                 size: 'lg',
785                 keyboard: true,
786                 backdrop: 'static',
787                 windowClass: 'my-class'
788               });
789
790           dlg.result.then(function(name) {}, function() {});
791
792         };
793         $scope.cldsPerformAction = function(uiAction) {
794
795           var modelName = selected_model;
796           var controlNamePrefix = "ClosedLoop-";
797           var bpmnText = modelXML;
798           // serialize model properties
799           var propText = JSON.stringify(elementMap);
800           var templateName = selected_template
801
802           var svgXml = $("#svgContainer").html(); 
803
804           console.log("cldsPerformAction: " + uiAction +
805             " modelName=" + modelName);
806           console.log("cldsPerformAction: " + uiAction +
807             " controlNamePrefix=" +
808             controlNamePrefix);
809           console.log("cldsPerformAction: " + uiAction +
810             " bpmnText=" + bpmnText);
811           console.log("cldsPerformAction: " + uiAction +
812             " propText=" + propText);
813           console.log("cldsPerformAction: " + uiAction +
814             " typeID=" + typeID);
815           console.log("cldsPerformAction: " + uiAction +
816             " deploymentId=" + deploymentId);
817           cldsModelService
818             .processAction(uiAction, modelName,
819               controlNamePrefix, bpmnText,
820               propText, svgXml, templateName,
821               typeID, deploymentId)
822             .then(
823               function(pars) {
824                 console
825                   .log("cldsPerformAction: pars=" +
826                     pars);
827                 cldsModelService
828                   .processRefresh(pars);
829               },
830               function(data) {
831
832                 // alert("setModel failed: "
833                 // + data);
834               });
835         };
836         $scope.refreshStatus = function() {
837             var modelName = selected_model;
838             var svgXml = $("#svgContainer").html(); 
839             console.log("refreStatus modelName=" + modelName);
840             cldsModelService
841               .getModel(modelName)
842               .then(
843                 function(pars) {
844                   console
845                     .log("refreStatus: pars=" +
846                       pars);
847                   cldsModelService
848                     .processRefresh(pars);
849                 },
850                 function(data) {
851                 });
852           };
853         $scope.cldsConfirmPerformAction = function(uiAction) {
854           var dlg = dialogs.confirm('Message',
855             'Do you want to ' +
856             uiAction.toLowerCase() +
857             ' the closed loop?');
858           dlg.result.then(function(btn) {
859
860             $scope.cldsPerformAction(uiAction);
861           }, function(btn) {
862
863             // $modalInstance.close("closed");
864           });
865         };
866
867         $scope.cldsAskDeployParametersPerformAction = function() {
868             var dlg = dialogs.create('partials/portfolios/deploy_parameters.html',
869                                      'DeploymentCtrl',
870                                      {}, {keyboard: true, backdrop: true, windowClass: 'deploy-parameters'});
871             dlg.result.then(function() {
872                 var confirm = dialogs.confirm('Deploy', 'Are you sure you want to deploy the closed loop?');
873                 confirm.result.then(function() {
874                     cldsToggleDeploy("deploy");
875                 });
876             });
877         };
878
879         $scope.cldsConfirmToggleDeployPerformAction = function(
880           uiAction) {
881
882           var dlg = dialogs.confirm('Message',
883             'Do you want to ' +
884             uiAction.toLowerCase() +
885             ' the closed loop?');
886           dlg.result.then(function(btn) {
887             cldsToggleDeploy(uiAction.toLowerCase());
888           }, function(btn) {
889
890             // $modalInstance.close("closed");
891           });
892         };
893
894         function cldsToggleDeploy(uiAction) {
895           var modelName = selected_model;
896           var controlNamePrefix = "ClosedLoop-";
897           var bpmnText = modelXML;
898           // serialize model properties
899           var propText = JSON.stringify(elementMap);
900           var templateName = selected_template;
901           var svgXml = $("#svgContainer").html();
902
903           console.log("cldsPerformAction: " + uiAction +
904             " modelName=" + modelName);
905           console.log("cldsPerformAction: " + uiAction +
906             " controlNamePrefix=" +
907             controlNamePrefix);
908           console.log("cldsPerformAction: " + uiAction +
909             " bpmnText=" + bpmnText);
910           console.log("cldsPerformAction: " + uiAction +
911             " propText=" + propText);
912           console.log("cldsPerformAction: " + uiAction +
913             " modelEventService=" +
914             modelEventService);
915           console.log("cldsPerformAction: " + uiAction +
916             " typeID=" + typeID);
917           console.log("cldsPerformAction: " + uiAction +
918             " deploymentId=" + deploymentId);
919           cldsModelService
920             .toggleDeploy(uiAction, modelName,
921               controlNamePrefix, bpmnText,
922               propText, svgXml, templateName,
923               typeID, controlNameUuid,
924               modelEventService, deploymentId)
925             .then(
926               function(pars) {
927                 typeID = pars.typeId;
928                 controlNameUuid = pars.controlNameUuid;
929                 selected_template = pars.templateName;
930                 modelEventService = pars.event;
931                 // actionCd =
932                 // pars.event.actionCd;
933                 actionStateCd = pars.event.actionStateCd;
934                 deploymentId = pars.deploymentId;
935                 cldsModelService
936                   .processActionResponse(
937                     modelName,
938                     pars);
939
940               },
941               function(data) {
942
943               });
944         }
945         $scope.managePerformAction = function(action) {
946           if (action.toLowerCase() === "delete") {
947             cldsModelService
948               .manageAction(
949                 selected_model,
950                 "805b9f83-261f-48d9-98c7-8011fc2cc8e8",
951                 "ClosedLoop-ABCD-0000.yml")
952               .then(function(pars) {
953
954               }, function(data) {
955
956                 // alert("setModel failed: " +
957                 // data);
958               });
959           }
960         };
961         $scope.manageConfirmPerformAction = function(
962           uiAction) {
963
964           var dlg = dialogs.confirm('Message',
965             'Do you want to ' +
966             uiAction.toLowerCase() +
967             ' the closed loop?');
968           dlg.result.then(function(btn) {
969
970             $scope.managePerformAction(uiAction);
971           }, function(btn) {
972
973             // $modalInstance.close("closed");
974           });
975         };
976         $scope.VesCollectorWindow = function(vesCollector) {
977
978             var dlg = dialogs
979               .create(
980                 'partials/portfolios/vesCollector_properties.html',
981                 'ImportSchemaCtrl', {
982                   closable: true,
983                   draggable: true
984                 }, {
985                   size: 'lg',
986                   keyboard: true,
987                   backdrop: 'static',
988                   windowClass: 'my-class'
989                 });
990
991             dlg.result.then(function(name) {
992
993             }, function() {
994
995             });
996
997
998         };
999
1000         $scope.HolmesWindow = function(holmes) {
1001
1002           var partial = 'partials/portfolios/holmes_properties.html'
1003
1004           var dlg = dialogs
1005             .create(
1006               partial,
1007               'ImportSchemaCtrl',
1008               holmes, {
1009                 closable: true,
1010                 draggable: true
1011               }, {
1012                 size: 'lg',
1013                 keyboard: true,
1014                 backdrop: 'static',
1015                 windowClass: 'my-class'
1016               });
1017         };
1018
1019         $scope.TCAWindow = function(tca) {
1020
1021             var dlg = dialogs
1022               .create(
1023                 'partials/portfolios/tca_properties.html',
1024                 'ImportSchemaCtrl', {
1025                   closable: true,
1026                   draggable: true
1027                 }, {
1028                   size: 'lg',
1029                   keyboard: true,
1030                   backdrop: 'static',
1031                   windowClass: 'my-class'
1032                 });
1033
1034             dlg.result.then(function(name) {
1035               // $scope.name = name;
1036             }, function() {
1037               // if(angular.equals($scope.name,''))
1038               // $scope.name = 'You did not enter in
1039               // your name!';
1040             });
1041
1042         };
1043
1044         $scope.PolicyWindow = function(policy) {
1045             var dlg = dialogs
1046               .create(
1047                 'partials/portfolios/PolicyWindow_properties.html',
1048                 'ImportSchemaCtrl', {
1049                   closable: true,
1050                   draggable: true
1051                 }, {
1052                   size: 'lg',
1053                   keyboard: true,
1054                   backdrop: 'static',
1055                   windowClass: 'my-class'
1056                 });
1057
1058             dlg.result.then(function(name) {
1059
1060               // $scope.name = name;
1061             }, function() {
1062
1063               // if(angular.equals($scope.name,''))
1064               // $scope.name = 'You did not enter in
1065               // your name!';
1066             });
1067
1068         };
1069
1070       }
1071     ]);
1072
1073 app.service('MenuService', ['$http', '$q', function($http, $q) {
1074
1075   /*
1076    * this.generateMDTTestSet = function(utmMDTRequest, generateTestSetMDTURL){
1077    *
1078    * console.log("generateMDTTestSet"); //alert("In generateMDTTestSet :: " +
1079    * JSON.stringify(utmMDTRequest)); var def = $q.defer(); var sets = [];
1080    *
1081    * $http.post(generateTestSetMDTURL, utmMDTRequest) .success(function(data){
1082    * console.log("success"); sets = data; def.resolve(data); })
1083    * .error(function(data){ console.log("error");
1084    * def.reject("GenerateMDTTestSet not successful"); });
1085    *
1086    * return def.promise; };
1087    */
1088 }]);
1089
1090 app.directive('focus', function($timeout) {
1091
1092   return {
1093     scope: {
1094       trigger: '@focus'
1095     },
1096     link: function(scope, element) {
1097       scope.$watch('trigger', function(value) {
1098
1099         if (value === "true") {
1100           $timeout(function() {
1101
1102             element[0].focus();
1103           });
1104         }
1105       });
1106     }
1107   };
1108 });
1109 app.directive('draggable', function($document) {
1110
1111   return function(scope, element, attr) {
1112
1113     var startX = 0,
1114       startY = 0,
1115       x = 0,
1116       y = 0;
1117     element.css({
1118       position: 'relative',
1119
1120       backgroundColor: 'white',
1121       cursor: 'move',
1122       display: 'block',
1123
1124     });
1125     element.on('mousedown', function(event) {
1126
1127       // Prevent default dragging of selected content
1128       // event.preventDefault();
1129       startX = event.screenX - x;
1130       startY = event.screenY - y;
1131       $document.on('mousemove', mousemove);
1132       $document.on('mouseup', mouseup);
1133     });
1134
1135     function mousemove(event) {
1136
1137       y = event.screenY - startY;
1138       x = event.screenX - startX;
1139       element.css({
1140         top: y + 'px',
1141         left: x + 'px'
1142       });
1143     }
1144
1145     function mouseup() {
1146
1147       $document.off('mousemove', mousemove);
1148       $document.off('mouseup', mouseup);
1149     }
1150   };
1151 });
1152
1153 app.factory('myHttpInterceptor', function($q, $window) {
1154
1155   return function(promise) {
1156
1157     return promise.then(function(response) {
1158
1159       return response;
1160     }, function(response) {
1161
1162       return $q.reject(response);
1163     });
1164   };
1165 });
1166
1167 app.run(['$route', function($route) {
1168
1169   $route.reload();
1170 }]);
1171
1172 function TestCtrl($scope) {
1173
1174   $scope.msg = "Hello from a controller method.";
1175   $scope.returnHello = function() {
1176
1177     return $scope.msg;
1178   }
1179 }
1180
1181 function importshema() {
1182
1183   angular.element(document.getElementById('navbar')).scope().importSchema();
1184
1185 }
1186
1187 function VesCollectorWindow(vesCollectorWin) {
1188   angular.element(document.getElementById('navbar')).scope()
1189     .VesCollectorWindow(vesCollectorWin);
1190 }
1191
1192 function HolmesWindow(holmesWin) {
1193   angular.element(document.getElementById('navbar')).scope()
1194     .HolmesWindow(holmesWin);
1195 }
1196
1197 function F5Window() {
1198
1199   angular.element(document.getElementById('navbar')).scope().F5Window();
1200
1201 }
1202
1203 function TCAWindow(tca) {
1204
1205   angular.element(document.getElementById('navbar')).scope().TCAWindow(tca);
1206
1207 }
1208
1209 function GOCWindow() {
1210
1211   angular.element(document.getElementById('navbar')).scope().GOCWindow();
1212
1213 }
1214
1215 function PolicyWindow(PolicyWin) {
1216
1217   angular.element(document.getElementById('navbar')).scope().PolicyWindow(
1218     PolicyWin);
1219
1220 }
1221
1222 function pathDetails(bpmnElementID, bpmnElementName, pathIdentifiers) {
1223
1224   angular.element(document.getElementById('navbar')).scope().pathDetails(
1225     bpmnElementID, bpmnElementName, pathIdentifiers);
1226
1227 }
1228
1229 function setdefaultvalue() {
1230
1231   angular.element(document.getElementById('navbar')).scope()
1232     .setDefaultValue();
1233
1234 }
1235
1236 function upgradeSchemaVersion() {
1237
1238   angular.element(document.getElementById('navbar')).scope()
1239     .upgradeSchemaVersion();
1240
1241 }
1242
1243 function saveProject() {
1244
1245   angular.element(document.getElementById('navbar')).scope().saveProject();
1246
1247 }
1248
1249 function modifySchema() {
1250
1251   angular.element(document.getElementById('navbar')).scope().modifySchema();
1252
1253 }
1254
1255 function definePID() {
1256
1257   angular.element(document.getElementById('navbar')).scope().definePID();
1258
1259 }
1260
1261 function defineServiceAcronym() {
1262
1263   angular.element(document.getElementById('navbar')).scope()
1264     .defineServiceAcronym();
1265
1266 }
1267
1268 function errorProperty(msg) {
1269
1270   angular.element(document.getElementById('navbar')).scope()
1271     .propertyExplorerErrorMessage(msg);
1272 }
1273
1274 function invisiblepropertyExplorer() {
1275
1276   angular.element(document.getElementById('navbar')).scope()
1277     .invisibleproperty();
1278 }
1279
1280 function updateDecisionLabel(originalLabel, newLabel) {
1281
1282   angular.element(document.getElementById('navbar')).scope()
1283     .updateDecisionLabels(originalLabel, newLabel);
1284 }
1285
1286 // Used to logout the session , when browser window was closed
1287 window.onunload = function() {
1288   window.localStorage.removeItem("isAuth");
1289   window.localStorage.removeItem("loginuser");
1290   window.localStorage.removeItem("invalidUser");
1291 };