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