Code Improvement
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / app.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 'use strict';
25
26 /* App Module */
27
28 var app = angular.module('clds-app', ['ngRoute',
29     'ngResource',
30     'angularjs-dropdown-multiselect',
31     'angularjs-dropdown-multiselect-new',
32     'hljs',
33     'ui.bootstrap',
34     'angular-loading-bar',
35     'ngAnimate',
36     'dialogs.main',
37     'ui.grid',
38     'ui.grid.resizeColumns',
39     'ui.grid.paging',
40     'ui.grid.selection',
41     'ui.grid.cellNav',
42     'ui.grid.pinning',
43     'ngSanitize',
44     'ngCookies',
45     'ui.bootstrap.modal',
46     'ui.grid.exporter',
47     'angucomplete',
48     'kendo.directives',
49     'angular-md5'
50   ])
51   .config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {
52
53     cfpLoadingBarProvider.includeBar = true;
54     cfpLoadingBarProvider.includeSpinner = true;
55   }])
56   .config(
57     function($httpProvider) {
58
59       $httpProvider.responseInterceptors
60         .push('myHttpInterceptor');
61
62       var spinnerFunction = function spinnerFunction(data,
63         headersGetter) {
64
65         return data;
66       };
67
68       $httpProvider.defaults.transformRequest
69         .push(spinnerFunction);
70     })
71   .config(
72     [
73       '$routeProvider',
74       '$locationProvider',
75       '$compileProvider',
76       'cfpLoadingBarProvider',
77       function($routeProvider, $locationProvider,
78         cfpLoadingBarProvider, $timeout, dialogs,
79         $cookies) {
80         console
81           .log("$routeProvider','$locationProvider', '$compileProvider','cfpLoadingBarProvider','md5'")
82         $locationProvider.html5Mode(false);
83         // alert("App.js");
84
85         $routeProvider
86           .when('/otherwise', {
87             templateUrl: 'please_wait.html',
88             controller: QueryParamsHandlerCtrl
89           })
90           .
91         // when('/dashboard_submit', { templateUrl:
92         // 'partials/portfolios/dashboard_submit.html',
93         // controller: CreateNewPrjCtrl }).
94         when(
95             '/dashboard', {
96               templateUrl: 'partials/portfolios/clds_modelling.html',
97               controller: DashboardCtrl
98             })
99           .
100         // when('/dashboard_upload', { templateUrl:
101         // 'partials/portfolios/dashboard_upload.html',
102         // controller: DashboardCtrl }).
103         when(
104           '/activity_modelling', {
105             templateUrl: 'partials/portfolios/clds_modelling.html',
106             controller: DashboardCtrl
107           }).when('/authenticate', {
108           templateUrl: 'authenticate.html',
109           controller: AuthenticateCtrl
110         }).when('/invalidlogin', {
111           templateUrl: 'invalid_login.html',
112           controller: PageUnderConstructionCtrl
113         }).otherwise({
114           redirectTo: '/otherwise'
115         });
116
117       }
118     ])
119   .controller(
120     'dialogCtrl',
121     function($scope, $rootScope, $timeout, dialogs) {
122
123       // -- Variables --//
124
125       $scope.lang = 'en-US';
126       $scope.language = 'English';
127
128       var _progress = 100;
129
130       $scope.name = '';
131       $scope.confirmed = 'No confirmation yet!';
132
133       $scope.custom = {
134         val: 'Initial Value'
135       };
136
137       // -- Listeners & Watchers --//
138
139       $scope.$watch('lang', function(val, old) {
140
141         switch (val) {
142           case 'en-US':
143             $scope.language = 'English';
144             break;
145           case 'es':
146             $scope.language = 'Spanish';
147             break;
148         }
149       });
150
151       // -- Methods --//
152       $rootScope.testCaseRequirements = [];
153       $rootScope.validTestRequirements = [];
154       /* $rootScope.testCaseValue=[]; */
155       $scope.setLanguage = function(lang) {
156
157         $scope.lang = lang;
158         $translate.use(lang);
159       };
160
161       $rootScope.launch = function(which) {
162
163         switch (which) {
164           case 'error':
165             dialogs.error();
166             break;
167           case 'wait':
168             // var dlg =
169             // dialogs.wait(undefined,undefined,_progress);
170             // _fakeWaitProgress();
171             break;
172           case 'customwait':
173             // var dlg = dialogs.wait('Custom Wait
174             // Header','Custom Wait Message',_progress);
175             // _fakeWaitProgress();
176             break;
177           case 'notify':
178             dialogs.notify();
179             break;
180           case 'confirm':
181             var dlg = dialogs.confirm();
182             dlg.result.then(function(btn) {
183
184               $scope.confirmed = 'You confirmed "Yes."';
185             }, function(btn) {
186
187               $scope.confirmed = 'You confirmed "No."';
188             });
189             break;
190           case 'custom':
191             var dlg = dialogs.create('/dialogs/custom.html',
192               'customDialogCtrl', {}, {
193                 size: 'lg',
194                 keyboard: true,
195                 backdrop: 'static',
196                 windowClass: 'my-class'
197               });
198             dlg.result
199               .then(
200                 function(name) {
201
202                   $scope.name = name;
203                 },
204                 function() {
205
206                   if (angular.equals($scope.name,
207                       ''))
208                     $scope.name = 'You did not enter in your name!';
209                 });
210             break;
211           case 'custom2':
212             var dlg = dialogs.create('/dialogs/custom2.html',
213               'customDialogCtrl2', $scope.custom, {
214                 size: 'lg'
215               });
216             break;
217           case 'custom3':
218             var dlg = dialogs
219               .notify(
220                 'Message',
221                 'All is not supported, Please select interface(s)/version(s) to fetch real time federated coverage report.');
222             break;
223           case 'custom4':
224             var dlg = dialogs
225               .confirm(
226                 'Message',
227                 'You are about to fetch real time federated coverage report.This may take sometime!!!.');
228             dlg.result.then(function(btn) {
229
230               $scope.confirmed = 'You confirmed "Yes."';
231             }, function(btn) {
232
233               $scope.confirmed = 'You confirmed "No."';
234             });
235             break;
236           case 'custom5':
237             var dlg = dialogs.notify('Success',
238               'Request has been successfully processed.');
239             break;
240           case 'custom6':
241             var dlg = dialogs.notify('Message',
242               'Please type Testscenario Name');
243             break;
244         }
245       }; // end launch
246
247       var _fakeWaitProgress = function() {
248
249         $timeout(function() {
250
251           if (_progress < 100) {
252             _progress += 33;
253             $rootScope.$broadcast('dialogs.wait.progress', {
254               'progress': _progress
255             });
256             _fakeWaitProgress();
257           } else {
258             $rootScope.$broadcast('dialogs.wait.complete');
259             _progress = 0;
260           }
261         }, 1000);
262       };
263     })
264   .controller(
265     'MenuCtrl', [
266       '$scope',
267       '$rootScope',
268       '$timeout',
269       'dialogs',
270       '$location',
271       'MenuService',
272       'Datafactory',
273       'userPreferencesService',
274       'cldsModelService',
275       'cldsTemplateService',
276       'extraUserInfoService',
277       function($scope, $rootScope, $timeout, dialogs,
278         $location, MenuService, Datafactory,
279         userPreferencesService, cldsModelService,
280         cldsTemplateService, extraUserInfoService) {
281         console.log("MenuCtrl");
282         $rootScope.screenName = "Universal Test Modeler";
283         $rootScope.testSet = null;
284         $rootScope.isNew = false;
285         var testingType = "";
286         $rootScope.contactUs = function() {
287           console.log("contactUs");
288           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.";
289           window.location.href = link;
290         };
291
292         extraUserInfoService
293           .getUserInfo()
294           .then(
295             function(pars) {
296               $scope.userInfo = pars;
297               if (!($scope.userInfo["permissionUpdateTemplate"])) {
298                 readTOnly = true;
299               };
300               if (!($scope.userInfo["permissionUpdateCl"])) {
301                 readMOnly = true;
302               };
303             });
304
305         $scope.emptyMenuClick = function(value, name) {
306           if ($rootScope.isNew &&
307             (name != "Save Template" &&
308               name != "Close Template" && name != "Template Properties")) {
309             saveConfirmationNotificationPopUp();
310           } else if ($rootScope.isNewClosed &&
311             name != "Save CL" &&
312             name != "Close Model" &&
313             name != "Properties CL") {
314             saveConfirmationNotificationPopUp();
315           } else {
316             isSaveCheck(name);
317           }
318
319           function saveConfirmationNotificationPopUp() {
320             $scope
321               .saveConfirmationNotificationPopUp(function(
322                 data) {
323                 if (data) {
324                   if ($rootScope.isNewClosed) {
325                     isSaveCheck("Save CL");
326                   } else {
327                     isSaveCheck("Save Template");
328                   }
329                   $rootScope.isNewClosed = false;
330                   $rootScope.isNew = false;
331                 } else {
332                   return false;
333                 }
334               });
335           }
336
337           function isSaveCheck(name) {
338             if (name == "User Info") {
339               $scope.extraUserInfo();
340             } else if (name == "Wiki") {
341               window.open(value);
342             } else if (name == "Contact Us") {
343               $rootScope.contactUs();
344             } else if (name == "Log Out") {
345               $scope.logout();
346             } else if (name == "Revert Template Changes") {
347               $scope.cldsRevertTemplate();
348             } else if (name == "Revert Model Changes") {
349               $scope.cldsRevertModel();
350             } else if (name == "Create Template") {
351               $rootScope.isNew = true;
352               $scope.cldsCreateTemplate();
353             } else if (name == "Open Template") {
354               $scope.cldsOpenTemplate();
355             } else if (name == "Save Template") {
356               $scope
357                 .cldsTemplatePerformAction("SAVE");
358               $rootScope.isNewClosed = false;
359               $rootScope.isNew = false;
360             } else if (name == "Template Properties") {
361               $scope.cldsOpenTemplateProperties();
362             } else if (name == "Close Model" ||
363               name == "Close Template") {
364               $scope.cldsClose();
365             } else if (name == "Refresh ASDC") {
366               $scope.cldsRefreshASDC();
367             } else if (name == "Create CL") {
368               $rootScope.isNewClosed = true;
369               $scope.cldsCreateModel();
370             } else if (name == "Open CL") {
371               $scope.cldsOpenModel();
372             } else if (name == "Save CL") {
373               $rootScope.isNewClosed = false;
374               $rootScope.isNew = false;
375               $scope.cldsPerformAction("SAVE");
376             } else if (name == "Validation Test") {
377               $scope.cldsPerformAction("TEST");
378             } else if (name == "Submit") {
379               $scope
380                 .cldsConfirmPerformAction("SUBMIT");
381             } else if (name == "Resubmit") {
382               $scope
383                 .cldsConfirmPerformAction("RESUBMIT");
384             } else if (name == "Update") {
385               $scope
386                 .cldsConfirmPerformAction("UPDATE");
387             } else if (name.toLowerCase() == "delete") {
388               $scope
389                 .manageConfirmPerformAction("DELETE");
390             } else if (name == "Stop") {
391               $scope.cldsConfirmPerformAction("STOP");
392             } else if (name == "Restart") {
393               $scope
394                 .cldsConfirmPerformAction("RESTART");
395             } else if (name == "Refresh Status") {
396               $scope.cldsPerformAction("REFRESH");
397             } else if (name == "Properties CL") {
398               $scope.cldsOpenModelProperties();
399             } else if (name == "Deploy") {
400               $scope
401                 .cldsConfirmToggleDeployPerformAction("Deploy");
402             } else if (name == "UnDeploy") {
403               $scope
404                 .cldsConfirmToggleDeployPerformAction("UnDeploy");
405             } else {
406               $rootScope.screenName = name;
407               $scope.updatebreadcrumb(value);
408               $location.path(value);
409             }
410           }
411         };
412
413         $rootScope.impAlerts = function() {
414
415         };
416
417         $scope.tabs = {
418           "Template": [{
419             link: "/cldsCreateTemplate",
420             name: "Create Template"
421           }, {
422             link: "/cldsOpenTemplate",
423             name: "Open Template"
424           }, {
425             link: "/cldsSaveTemplate",
426             name: "Save Template"
427           }, {
428             link: "/cldsOpenTemplateProperties",
429             name: "Template Properties"
430           }, {
431             link: "/RevertChanges",
432             name: "Revert Template Changes"
433           }, {
434             link: "/Close",
435             name: "Close Template"
436           }],
437
438           "Closed Loop": [{
439             link: "/cldsCreateModel",
440             name: "Create CL"
441           }, {
442             link: "/cldsOpenModel",
443             name: "Open CL"
444           }, {
445             link: "/cldsSaveModel",
446             name: "Save CL"
447           }, {
448             link: "/cldsOpenModelProperties",
449             name: "Properties CL"
450           }, {
451             link: "/RevertChanges",
452             name: "Revert Model Changes"
453           }, {
454             link: "/Close",
455             name: "Close Model"
456           }],
457           "Manage": [{
458             link: "/cldsTestActivate",
459             name: "Validation Test"
460           }, {
461             link: "/cldsSubmit",
462             name: "Submit"
463           }, {
464             link: "/cldsResubmit",
465             name: "Resubmit"
466           }, {
467             link: "/cldsUpdate",
468             name: "Update"
469           }, {
470             link: "/cldsStop",
471             name: "Stop"
472           }, {
473             link: "/cldsRestart",
474             name: "Restart"
475           }, {
476             link: "/cldsDelete",
477             name: "Delete"
478           }, {
479             link: "/cldsDeploy",
480             name: "Deploy"
481           }, {
482             link: "/cldsUnDeploy",
483             name: "UnDeploy"
484           }],
485           "View": [{
486             link: "/refreshStatus",
487             name: "Refresh Status"
488           }, {
489             link: "/refreshASDCProperties",
490             name: "Refresh ASDC"
491           }],
492           "Help": [{
493             link: "http://wiki.onap.org",
494             name: "Wiki"
495           }, {
496             link: "/contact_us",
497             name: "Contact Us"
498           }, {
499             link: "/extraUserInfo",
500             name: "User Info"
501           }],
502           "Log Out": [{
503             link: "/log_out.html",
504             name: "Log Out"
505           }]
506         };
507
508         if (!Object.keys) {
509           Object.keys = function(obj) {
510             var keys = [];
511
512             for (var i in obj) {
513               if (obj.hasOwnProperty(i)) {
514                 keys.push(i);
515               }
516             }
517
518             return keys;
519           };
520           $scope.keyList = Object.keys($scope.tabs);
521         } else {
522           $scope.keyList = Object.keys($scope.tabs);
523         }
524
525         $scope.updatebreadcrumb = function(path) {
526
527           var currentURL = $location.path();
528           if (path != undefined) {
529             currentURL = path;
530           }
531
532           if (currentURL == "/dashboard") {
533             $rootScope.screenName = "Universal Test Modeler";
534             $rootScope.parentMenu = "Home";
535             $rootScope.rightTabName = "UTM Build Configuration";
536           }
537           /*
538            * else if(currentURL=="/quicksearch") {
539            * $rootScope.screenName = "Quick Search";
540            * $rootScope.parentMenu = "Home"; }
541            */
542           else {
543             var found = false;
544
545             angular
546               .forEach(
547                 $scope.keyList,
548                 function(value, key) {
549
550                   if (!found) {
551                     $rootScope.parentMenu = value;
552
553                     angular
554                       .forEach(
555                         $scope.tabs[value],
556                         function(
557                           value,
558                           key) {
559
560                           if (currentURL == value.link) {
561                             $rootScope.screenName = value.name;
562                             found = true;
563                           }
564                         });
565                   }
566                 });
567           }
568         };
569
570         $scope.updatebreadcrumb();
571
572         $scope.createNewProject = function() {
573
574           if ($rootScope.projectName != null) {
575             var dlg = dialogs
576               .confirm('Message',
577                 'Do you want to over-write  the project ?');
578
579             dlg.result
580               .then(
581                 function(btn) {
582
583                   $scope.clearProject();
584                   var dlg1 = dialogs
585                     .create(
586                       'partials/portfolios/create_new_project.html',
587                       'CreateNewPrjCtrl', {}, {
588                         size: 'sm',
589                         keyboard: true,
590                         backdrop: false,
591                         windowClass: 'my-class'
592                       });
593                   dlg1.result.then(
594                     function(name) {
595
596                       // $scope.name
597                       // = name;
598                     },
599                     function() {
600
601                       // if(angular.equals($scope.name,''))
602                       // $scope.name
603                       // = 'You
604                       // did not
605                       // enter in
606                       // your
607                       // name!';
608                     });
609                 },
610                 function(btn) {
611
612                   // $modalInstance.close("closed");
613                 });
614
615           } else {
616             var dlg = dialogs
617               .create(
618                 'partials/portfolios/create_new_project.html',
619                 'CreateNewPrjCtrl', {}, {
620                   size: 'lg',
621                   keyboard: true,
622                   backdrop: false,
623                   windowClass: 'my-class'
624                 });
625             dlg.result.then(function(name) {
626
627               // $scope.name = name;
628             }, function() {
629
630               // if(angular.equals($scope.name,''))
631               // $scope.name = 'You did not enter in
632               // your name!';
633             });
634
635           }
636         };
637
638         $scope.clearProject = function() {
639
640           $rootScope.projectName = null;
641           $rootScope.revision = -1;
642           // $rootScope.models.length=0;
643           $rootScope.utmModels = $rootScope.$new(true);
644           $rootScope.serviceInfo = $rootScope.$new(true);
645           $rootScope.serviceInfo = null;
646           $rootScope.serviceInputPartInfo = $rootScope
647             .$new(true);
648           $rootScope.serviceOutputPartInfo = $rootScope
649             .$new(true);
650           $rootScope.servicefaultPartInfo = $rootScope
651             .$new(true);
652           $rootScope.isModel = false;
653           $("#paletteDiv").load(
654             './modeler/dist/index.html');
655           $rootScope.isPalette = false;
656           $rootScope.isTestset = false;
657           $rootScope.isRequirementCoverage = false;
658           $rootScope.ispropertyExplorer = false;
659           // $("#propertyDiv").load('./partials/portfolios/Property_Explorer.html');
660           $rootScope.modelName = "";
661           // document.getElementById('propertyExplorer').classList.remove('visible');
662           document.getElementById("modeler_name").textContent = "Activity Modeler";
663           // $( "#propertyExplorer" ).prev().css(
664           // "display", "block" );
665           $("#activity_modeler").prev().css("display",
666             "block");
667           $('div').find('.k-expand-next').click();
668
669           $rootScope.$apply();
670
671         };
672
673         $scope.homePage = function() {
674
675           $location.path('/dashboard');
676         };
677         $scope.propertyExplorerErrorMessage = function(msg) {
678
679           var dlg = dialogs.notify('Error', msg);
680         }
681
682         // $scope.fromTstMultipleFlag=false;
683         /* onclicking of review testset / generate testset */
684
685         $scope.reviewTestSet = function() {
686
687           $rootScope.modeltestset = list_model_test_sets[selected_model];
688
689           $rootScope.isPalette = false;
690           $rootScope.isTestset = true;
691           $rootScope.isRequirementCoverage = false;
692           document.getElementById("modeler_name").textContent = "UTM Test Set";
693           // document.getElementById('propertyExplorer').classList.add('visible');
694
695           // $( "#propertyExplorer" ).prev().css(
696           // "display", "none" );
697           $('div').find('.k-collapse-next').click();
698
699           // $rootScope.$apply();
700
701         };
702         $scope.requirementCoverage = function() {
703
704           $rootScope.testCaseRequirements = [];
705           $rootScope.validTestRequirementArray = [];
706           $rootScope.validTestRequirements = {};
707           $rootScope.modeltestset = list_model_test_sets[selected_model];
708           var allPathDetails = [];
709           $scope.currentSelectedModel = {};
710           // $scope.getPathDetails($rootScope.utmModels,selected_model);
711           // $scope.populatePathDetails(allPathDetails,$scope.currentSelectedModel);
712           $rootScope.pathDetailsList = list_model_path_details[selected_model];
713           /*
714            * for(var p=0;p<100;p++){
715            * $rootScope.testCaseRequirements.push("Requirement"+p); }
716            * for(var p=0;p<100;p++){
717            * $rootScope.testCaseValue.push("TestCase"+p); }
718            */
719           for (var x = 0; x < allPathDetails.length; x++) {
720             var tempPathDetails = allPathDetails[x];
721             if (tempPathDetails != null) {
722               for (var i = 0; i < tempPathDetails.length; i++) {
723                 var pathDetails = tempPathDetails[i];
724                 if (pathDetails.requirement !== '' &&
725                   pathDetails.requirement !== null) {
726                   $rootScope.testCaseRequirements
727                     .push(pathDetails.requirement);
728                 }
729
730                 /*
731                  * for (var j = 0; j <
732                  * pathDetails.decisionIdentifiers.length;
733                  * j++) {
734                  * if(pathDetails.decisionIdentifiers[j].requirement
735                  * !== '' &&
736                  * pathDetails.decisionIdentifiers[j].requirement
737                  * !== null){
738                  * $rootScope.testCaseRequirements.push(pathDetails.decisionIdentifiers[j].requirement); } }
739                  */
740               }
741             }
742
743           }
744           for (var p = 0; p < $rootScope.modeltestset.activityTestCases.length; p++) {
745             var activityTestCases = $rootScope.modeltestset.activityTestCases[p];
746             if (activityTestCases.mappedRequirements != null) {
747               for (var i = 0; i < activityTestCases.mappedRequirements.length; i++) {
748                 // $rootScope.testCaseRequirements
749                 // .push(activityTestCases.mappedRequirements[i]);
750                 var testCaseNames = $rootScope.validTestRequirements[activityTestCases.mappedRequirements[i]];
751                 if (testCaseNames == null) {
752                   testCaseNames = [];
753                 }
754                 if (activityTestCases.version != null)
755                   var testCase = activityTestCases.testCaseName +
756                     "_" +
757                     activityTestCases.version;
758                 else
759                   var testCase = activityTestCases.testCaseName;
760                 testCaseNames.push(testCase);
761                 $rootScope.validTestRequirements[activityTestCases.mappedRequirements[i]] = testCaseNames;
762               }
763             }
764           }
765
766           $rootScope.isPalette = false;
767           $rootScope.isTestset = false;
768           $rootScope.isRequirementCoverage = true;
769           document.getElementById("modeler_name").textContent = "Test Case / Requirement Coverage";
770           // document.getElementById('propertyExplorer').classList.add('visible');
771           // console.log("modeltestset"+JSON.stringify($rootScope.modeltestset));
772           // $( "#propertyExplorer" ).prev().css(
773           // "display", "none" );
774           $('div').find('.k-collapse-next').click();
775           // $rootScope.$apply();
776
777         };
778
779         $scope.activityModelling = function() {
780
781           // window.open("./bpmn-js-examples-master/modeler/dist/index.html",
782           // "_self");
783           // $location.path('/activity_modelling');
784         };
785         /*
786          * $scope.openProject = function(){
787          * $location.path('/dashboard_upload'); };
788          */
789         $rootScope.cldsOpenTemplateProperties = function() {
790
791           var dlg = dialogs
792             .create(
793               'partials/portfolios/global_template_properties.html',
794               'CldsOpenTemplateCtrl', {}, {
795                 size: 'lg',
796                 keyboard: true,
797                 backdrop: 'static',
798                 windowClass: 'my-class'
799               });
800
801           dlg.result.then(function(name) {
802
803             // $scope.modelName =modelName;
804             // $("#" +
805             // selected_model).addClass("selectedcolor");
806             // alert ("model name:"+$scope.modelName);
807           }, function() {
808
809             // if(angular.equals($scope.name,''))
810             // $scope.name = 'You did not enter in your
811             // name!';
812           });
813         }
814
815         $scope.cldsClose = function() {
816
817           var dlg = dialogs
818             .create(
819               'partials/portfolios/confirmation_window.html',
820               'CldsOpenTemplateCtrl', {
821                 closable: true,
822                 draggable: true
823               }, {
824                 size: 'lg',
825                 keyboard: true,
826                 backdrop: 'static',
827                 windowClass: 'my-class'
828               });
829
830           dlg.result.then(function(name) {
831
832             // $scope.name = name;
833           }, function() {
834
835             // if(angular.equals($scope.name,''))
836             // $scope.name = 'You did not enter in your
837             // name!';
838           });
839         };
840         $scope.cldsOpenTemplate = function() {
841
842           var dlg = dialogs
843             .create(
844               'partials/portfolios/clds_open_template.html',
845               'CldsOpenTemplateCtrl', {
846                 closable: true,
847                 draggable: true
848               }, {
849                 size: 'lg',
850                 keyboard: true,
851                 backdrop: 'static',
852                 windowClass: 'my-class'
853               });
854
855           dlg.result.then(function(name) {
856
857             // $scope.name = name;
858           }, function() {
859
860             // if(angular.equals($scope.name,''))
861             // $scope.name = 'You did not enter in your
862             // name!';
863           });
864         };
865         $scope.saveConfirmationNotificationPopUp = function(
866           callBack) {
867
868           var dlg = dialogs
869             .create(
870               'partials/portfolios/save_confirmation.html',
871               'saveConfirmationModalPopUpCtrl', {
872                 closable: true,
873                 draggable: true
874               }, {
875                 size: 'lg',
876                 keyboard: true,
877                 backdrop: 'static',
878                 windowClass: 'my-class'
879               });
880
881           dlg.result.then(function(name) {
882             callBack("OK");
883           }, function() {
884             callBack(null);
885           });
886
887         };
888         $scope.cldsCreateTemplate = function() {
889
890           var dlg = dialogs
891             .create(
892               'partials/portfolios/clds_create_template.html',
893               'CldsOpenTemplateCtrl', {
894                 closable: true,
895                 draggable: true
896               }, {
897                 size: 'lg',
898                 keyboard: true,
899                 backdrop: 'static',
900                 windowClass: 'my-class'
901               });
902
903           dlg.result.then(function(name) {
904
905             // $scope.name = name;
906           }, function() {
907
908             // if(angular.equals($scope.name,''))
909             // $scope.name = 'You did not enter in your
910             // name!';
911           });
912
913         };
914         $scope.cldsRefreshASDC = function() {
915
916           var dlg = dialogs
917             .create(
918               'partials/portfolios/refresh_asdc.html',
919               'CldsOpenModelCtrl', {
920                 closable: true,
921                 draggable: true
922               }, {
923                 size: 'lg',
924                 keyboard: true,
925                 backdrop: 'static',
926                 windowClass: 'my-class'
927               });
928           dlg.result.then(function(name) {
929
930             // $scope.name = name;
931           }, function() {
932
933             // if(angular.equals($scope.name,''))
934             // $scope.name = 'You did not enter in your
935             // name!';
936           });
937         }
938         $scope.cldsRevertModel = function() {
939
940           var dlg = dialogs
941             .create(
942               'partials/portfolios/ConfirmRevertChanges.html',
943               'CldsOpenModelCtrl', {
944                 closable: true,
945                 draggable: true
946               }, {
947                 size: 'lg',
948                 keyboard: true,
949                 backdrop: 'static',
950                 windowClass: 'my-class'
951               });
952
953           dlg.result.then(function(name) {
954
955             // $scope.name = name;
956           }, function() {
957
958             // if(angular.equals($scope.name,''))
959             // $scope.name = 'You did not enter in your
960             // name!';
961           });
962
963         };
964
965         $scope.cldsRevertTemplate = function() {
966
967           var dlg = dialogs
968             .create(
969               'partials/portfolios/ConfirmRevertChanges.html',
970               'CldsOpenTemplateCtrl', {
971                 closable: true,
972                 draggable: true
973               }, {
974                 size: 'lg',
975                 keyboard: true,
976                 backdrop: 'static',
977                 windowClass: 'my-class'
978               });
979
980           dlg.result.then(function(name) {
981
982             // $scope.name = name;
983           }, function() {
984
985             // if(angular.equals($scope.name,''))
986             // $scope.name = 'You did not enter in your
987             // name!';
988           });
989
990         };
991         $scope.cldsTemplatePerformAction = function(
992           uiAction) {
993
994           var modelName = selected_model;
995           var controlNamePrefix = "ClosedLoop-";
996           var bpmnText = modelXML;
997           // serialize model properties
998           var propText = JSON.stringify(elementMap);
999
1000           var svgXml = "";
1001           console.log(abootDiagram.saveSVG({
1002             format: true
1003           }, function(err, xml) {
1004
1005             if (err)
1006               console.log("error")
1007             else
1008               console.log(xml)
1009             svgXml = xml;
1010           }));
1011           console.log("cldsTemplatePerformAction: " +
1012             uiAction + " modelName=" + modelName);
1013           console.log("cldsTemplatePerformAction: " +
1014             uiAction + " controlNamePrefix=" +
1015             controlNamePrefix);
1016           console.log("cldsTemplatePerformAction: " +
1017             uiAction + " bpmnText=" + bpmnText);
1018           console.log("cldsTemplatePerformAction: " +
1019             uiAction + " propText=" + propText);
1020           cldsTemplateService
1021             .processAction(uiAction, modelName,
1022               controlNamePrefix, bpmnText,
1023               propText, svgXml)
1024             .then(
1025               function(pars) {
1026                 console
1027                   .log("processAction");
1028                 console
1029                   .log("cldsTemplatePerformAction: pars=" +
1030                     pars);
1031                 cldsTemplateService
1032                   .processActionResponse(
1033                     modelName,
1034                     pars);
1035               },
1036               function(data) {
1037
1038                 // alert("setModel failed: "
1039                 // + data);
1040               });
1041         };
1042
1043         $rootScope.cldsOpenModelProperties = function() {
1044
1045           var dlg = dialogs
1046             .create(
1047               'partials/portfolios/global_properties.html',
1048               'GlobalPropertiesCtrl', {}, {
1049                 size: 'lg',
1050                 keyboard: true,
1051                 backdrop: 'static',
1052                 windowClass: 'my-class'
1053               });
1054
1055           dlg.result.then(function(name) {}, function() {});
1056         };
1057
1058         $scope.cldsOpenModel = function() {
1059
1060           var dlg = dialogs
1061             .create(
1062               'partials/portfolios/clds_open_model.html',
1063               'CldsOpenModelCtrl', {
1064                 closable: true,
1065                 draggable: true
1066               }, {
1067                 size: 'lg',
1068                 keyboard: true,
1069                 backdrop: 'static',
1070                 windowClass: 'my-class'
1071               });
1072
1073           dlg.result.then(function(name) {
1074
1075             // $scope.name = name;
1076           }, function() {
1077
1078             // if(angular.equals($scope.name,''))
1079             // $scope.name = 'You did not enter in your
1080             // name!';
1081           });
1082         };
1083         $scope.cldsCreateModel = function() {
1084
1085           var dlg = dialogs
1086             .create(
1087               'partials/portfolios/clds_create_model_off_Template.html',
1088               'CldsOpenModelCtrl', {
1089                 closable: true,
1090                 draggable: true
1091               }, {
1092                 size: 'lg',
1093                 keyboard: true,
1094                 backdrop: 'static',
1095                 windowClass: 'my-class'
1096               });
1097
1098           dlg.result.then(function(name) {
1099
1100             // $scope.name = name;
1101           }, function() {
1102
1103             // if(angular.equals($scope.name,''))
1104             // $scope.name = 'You did not enter in your
1105             // name!';
1106           });
1107
1108         };
1109         $scope.extraUserInfo = function() {
1110
1111           var dlg = dialogs
1112             .create(
1113               'partials/portfolios/extra_user_info.html',
1114               'ExtraUserInfoCtrl', {
1115                 closable: true,
1116                 draggable: true
1117               }, {
1118                 size: 'lg',
1119                 keyboard: true,
1120                 backdrop: 'static',
1121                 windowClass: 'my-class'
1122               });
1123
1124           dlg.result.then(function(name) {}, function() {});
1125
1126         };
1127         $scope.cldsPerformAction = function(uiAction) {
1128
1129           var modelName = selected_model;
1130           var controlNamePrefix = "ClosedLoop-";
1131           var bpmnText = modelXML;
1132           // serialize model properties
1133           var propText = JSON.stringify(elementMap);
1134           var templateName = selected_template
1135
1136           var svgXml = "";
1137           console.log(abootDiagram.saveSVG({
1138             format: true
1139           }, function(err, xml) {
1140             if (err)
1141               console.log("error")
1142             else
1143               console.log(xml)
1144             svgXml = xml;
1145           }));
1146           console.log("cldsPerformAction: " + uiAction +
1147             " modelName=" + modelName);
1148           console.log("cldsPerformAction: " + uiAction +
1149             " controlNamePrefix=" +
1150             controlNamePrefix);
1151           console.log("cldsPerformAction: " + uiAction +
1152             " bpmnText=" + bpmnText);
1153           console.log("cldsPerformAction: " + uiAction +
1154             " propText=" + propText);
1155           console.log("cldsPerformAction: " + uiAction +
1156             " typeID=" + typeID);
1157           console.log("cldsPerformAction: " + uiAction +
1158             " deploymentId=" + deploymentId);
1159           cldsModelService
1160             .processAction(uiAction, modelName,
1161               controlNamePrefix, bpmnText,
1162               propText, svgXml, templateName,
1163               typeID, deploymentId)
1164             .then(
1165               function(pars) {
1166                 console
1167                   .log("cldsPerformAction: pars=" +
1168                     pars);
1169                 cldsModelService
1170                   .processRefresh(pars);
1171               },
1172               function(data) {
1173
1174                 // alert("setModel failed: "
1175                 // + data);
1176               });
1177         };
1178
1179         $scope.cldsConfirmPerformAction = function(uiAction) {
1180           var dlg = dialogs.confirm('Message',
1181             'Do you want to ' +
1182             uiAction.toLowerCase() +
1183             ' the closed loop?');
1184           dlg.result.then(function(btn) {
1185
1186             $scope.cldsPerformAction(uiAction);
1187           }, function(btn) {
1188
1189             // $modalInstance.close("closed");
1190           });
1191         };
1192
1193         $scope.cldsConfirmToggleDeployPerformAction = function(
1194           uiAction) {
1195
1196           var dlg = dialogs.confirm('Message',
1197             'Do you want to ' +
1198             uiAction.toLowerCase() +
1199             ' the closed loop?');
1200           dlg.result.then(function(btn) {
1201             cldsToggleDeploy(uiAction.toLowerCase());
1202           }, function(btn) {
1203
1204             // $modalInstance.close("closed");
1205           });
1206         };
1207
1208         function cldsToggleDeploy(uiAction) {
1209           var modelName = selected_model;
1210           var controlNamePrefix = "ClosedLoop-";
1211           var bpmnText = modelXML;
1212           // serialize model properties
1213           var propText = JSON.stringify(elementMap);
1214           var templateName = selected_template;
1215           var svgXml = "";
1216
1217           console.log(abootDiagram.saveSVG({
1218             format: true
1219           }, function(err, xml) {
1220             if (err)
1221               console.log("error")
1222             else
1223               console.log(xml)
1224             svgXml = xml;
1225           }));
1226           console.log("cldsPerformAction: " + uiAction +
1227             " modelName=" + modelName);
1228           console.log("cldsPerformAction: " + uiAction +
1229             " controlNamePrefix=" +
1230             controlNamePrefix);
1231           console.log("cldsPerformAction: " + uiAction +
1232             " bpmnText=" + bpmnText);
1233           console.log("cldsPerformAction: " + uiAction +
1234             " propText=" + propText);
1235           console.log("cldsPerformAction: " + uiAction +
1236             " modelEventService=" +
1237             modelEventService);
1238           console.log("cldsPerformAction: " + uiAction +
1239             " typeID=" + typeID);
1240           console.log("cldsPerformAction: " + uiAction +
1241             " deploymentId=" + deploymentId);
1242           cldsModelService
1243             .toggleDeploy(uiAction, modelName,
1244               controlNamePrefix, bpmnText,
1245               propText, svgXml, templateName,
1246               typeID, controlNameUuid,
1247               modelEventService, deploymentId)
1248             .then(
1249               function(pars) {
1250                 typeID = pars.typeId;
1251                 controlNameUuid = pars.controlNameUuid;
1252                 selected_template = pars.templateName;
1253                 modelEventService = pars.event;
1254                 // actionCd =
1255                 // pars.event.actionCd;
1256                 actionStateCd = pars.event.actionStateCd;
1257                 deploymentId = pars.deploymentId;
1258                 cldsModelService
1259                   .processActionResponse(
1260                     modelName,
1261                     pars);
1262
1263               },
1264               function(data) {
1265
1266               });
1267         }
1268         $scope.managePerformAction = function(action) {
1269           if (action.toLowerCase() === "delete") {
1270             cldsModelService
1271               .manageAction(
1272                 selected_model,
1273                 "805b9f83-261f-48d9-98c7-8011fc2cc8e8",
1274                 "ClosedLoop-ABCD-0000.yml")
1275               .then(function(pars) {
1276
1277               }, function(data) {
1278
1279                 // alert("setModel failed: " +
1280                 // data);
1281               });
1282           }
1283         };
1284         $scope.manageConfirmPerformAction = function(
1285           uiAction) {
1286
1287           var dlg = dialogs.confirm('Message',
1288             'Do you want to ' +
1289             uiAction.toLowerCase() +
1290             ' the closed loop?');
1291           dlg.result.then(function(btn) {
1292
1293             $scope.managePerformAction(uiAction);
1294           }, function(btn) {
1295
1296             // $modalInstance.close("closed");
1297           });
1298         };
1299         $scope.VesCollectorWindow = function(vesCollector) {
1300
1301           if (isTemplate) {
1302             var dlg = dialogs
1303               .create(
1304                 'partials/portfolios/Template_model.html',
1305                 'ImportSchemaCtrl',
1306                 vesCollector, {
1307                   closable: true,
1308                   draggable: true
1309                 }, {
1310                   size: 'lg',
1311                   keyboard: true,
1312                   backdrop: 'static',
1313                   windowClass: 'my-class'
1314                 });
1315             dlg.result.then(function(name) {
1316
1317             }, function() {
1318
1319
1320             });
1321           } else { // if (isTemplate)
1322
1323             var dlg = dialogs
1324               .create(
1325                 'partials/portfolios/vesCollector_properties.html',
1326                 'ImportSchemaCtrl', {
1327                   closable: true,
1328                   draggable: true
1329                 }, {
1330                   size: 'lg',
1331                   keyboard: true,
1332                   backdrop: 'static',
1333                   windowClass: 'my-class'
1334                 });
1335
1336             dlg.result.then(function(name) {
1337
1338             }, function() {
1339
1340             });
1341
1342           }
1343         };
1344
1345         $scope.HolmesWindow = function(holmes) {
1346
1347           if (isTemplate) {
1348             var partial = 'partials/portfolios/Template_model.html'
1349           } else {
1350             var partial = 'partials/portfolios/holmes_properties.html'
1351           }
1352
1353           var dlg = dialogs
1354             .create(
1355               partial,
1356               'ImportSchemaCtrl',
1357               holmes, {
1358                 closable: true,
1359                 draggable: true
1360               }, {
1361                 size: 'lg',
1362                 keyboard: true,
1363                 backdrop: 'static',
1364                 windowClass: 'my-class'
1365               });
1366         };
1367
1368         $scope.TCAWindow = function(tca) {
1369           if (isTemplate) {
1370             var dlg = dialogs
1371               .create(
1372                 'partials/portfolios/Template_model.html',
1373                 'ImportSchemaCtrl',
1374                 tca, {
1375                   closable: true,
1376                   draggable: true
1377                 }, {
1378                   size: 'lg',
1379                   keyboard: true,
1380                   backdrop: 'static',
1381                   windowClass: 'my-class'
1382                 });
1383             dlg.result.then(function(name) {}, function() {
1384               // if(angular.equals($scope.name,''))
1385               // $scope.name = 'You did not enter in
1386               // your name!';
1387             });
1388           } else {
1389             var dlg = dialogs
1390               .create(
1391                 'partials/portfolios/tca_properties.html',
1392                 'ImportSchemaCtrl', {
1393                   closable: true,
1394                   draggable: true
1395                 }, {
1396                   size: 'lg',
1397                   keyboard: true,
1398                   backdrop: 'static',
1399                   windowClass: 'my-class'
1400                 });
1401
1402             dlg.result.then(function(name) {
1403               // $scope.name = name;
1404             }, function() {
1405               // if(angular.equals($scope.name,''))
1406               // $scope.name = 'You did not enter in
1407               // your name!';
1408             });
1409           }
1410         };
1411
1412         $scope.PolicyWindow = function(policy) {
1413
1414           if (isTemplate) {
1415             var dlg = dialogs
1416               .create(
1417                 'partials/portfolios/Template_model.html',
1418                 'ImportSchemaCtrl',
1419                 policy, {
1420                   closable: true,
1421                   draggable: true
1422                 }, {
1423                   size: 'lg',
1424                   keyboard: true,
1425                   backdrop: 'static',
1426                   windowClass: 'my-class'
1427                 });
1428             dlg.result.then(function(name) {
1429
1430             }, function() {
1431
1432               // if(angular.equals($scope.name,''))
1433               // $scope.name = 'You did not enter in
1434               // your name!';
1435             });
1436           } else {
1437             var dlg = dialogs
1438               .create(
1439                 'partials/portfolios/PolicyWindow_properties.html',
1440                 'ImportSchemaCtrl', {
1441                   closable: true,
1442                   draggable: true
1443                 }, {
1444                   size: 'lg',
1445                   keyboard: true,
1446                   backdrop: 'static',
1447                   windowClass: 'my-class'
1448                 });
1449
1450             dlg.result.then(function(name) {
1451
1452               // $scope.name = name;
1453             }, function() {
1454
1455               // if(angular.equals($scope.name,''))
1456               // $scope.name = 'You did not enter in
1457               // your name!';
1458             });
1459
1460           }
1461         };
1462
1463       }
1464     ]);
1465
1466 app.service('MenuService', ['$http', '$q', function($http, $q) {
1467
1468   /*
1469    * this.generateMDTTestSet = function(utmMDTRequest, generateTestSetMDTURL){
1470    *
1471    * console.log("generateMDTTestSet"); //alert("In generateMDTTestSet :: " +
1472    * JSON.stringify(utmMDTRequest)); var def = $q.defer(); var sets = [];
1473    *
1474    * $http.post(generateTestSetMDTURL, utmMDTRequest) .success(function(data){
1475    * console.log("success"); sets = data; def.resolve(data); })
1476    * .error(function(data){ console.log("error");
1477    * def.reject("GenerateMDTTestSet not successful"); });
1478    *
1479    * return def.promise; };
1480    */
1481 }]);
1482
1483 app.directive('focus', function($timeout) {
1484
1485   return {
1486     scope: {
1487       trigger: '@focus'
1488     },
1489     link: function(scope, element) {
1490       scope.$watch('trigger', function(value) {
1491
1492         if (value === "true") {
1493           $timeout(function() {
1494
1495             element[0].focus();
1496           });
1497         }
1498       });
1499     }
1500   };
1501 });
1502 app.directive('draggable', function($document) {
1503
1504   return function(scope, element, attr) {
1505
1506     var startX = 0,
1507       startY = 0,
1508       x = 0,
1509       y = 0;
1510     element.css({
1511       position: 'relative',
1512
1513       backgroundColor: 'white',
1514       cursor: 'move',
1515       display: 'block',
1516
1517     });
1518     element.on('mousedown', function(event) {
1519
1520       // Prevent default dragging of selected content
1521       // event.preventDefault();
1522       startX = event.screenX - x;
1523       startY = event.screenY - y;
1524       $document.on('mousemove', mousemove);
1525       $document.on('mouseup', mouseup);
1526     });
1527
1528     function mousemove(event) {
1529
1530       y = event.screenY - startY;
1531       x = event.screenX - startX;
1532       element.css({
1533         top: y + 'px',
1534         left: x + 'px'
1535       });
1536     }
1537
1538     function mouseup() {
1539
1540       $document.off('mousemove', mousemove);
1541       $document.off('mouseup', mouseup);
1542     }
1543   };
1544 });
1545
1546 app.factory('myHttpInterceptor', function($q, $window) {
1547
1548   return function(promise) {
1549
1550     return promise.then(function(response) {
1551
1552       return response;
1553     }, function(response) {
1554
1555       return $q.reject(response);
1556     });
1557   };
1558 });
1559
1560 app.run(['$route', function($route) {
1561
1562   $route.reload();
1563 }]);
1564
1565 function TestCtrl($scope) {
1566
1567   $scope.msg = "Hello from a controller method.";
1568   $scope.returnHello = function() {
1569
1570     return $scope.msg;
1571   }
1572 }
1573
1574 function importshema() {
1575
1576   angular.element(document.getElementById('navbar')).scope().importSchema();
1577
1578 }
1579
1580 function VesCollectorWindow(vesCollectorWin) {
1581   angular.element(document.getElementById('navbar')).scope()
1582     .VesCollectorWindow(vesCollectorWin);
1583 }
1584
1585 function HolmesWindow(holmesWin) {
1586   angular.element(document.getElementById('navbar')).scope()
1587     .HolmesWindow(holmesWin);
1588 }
1589
1590 function F5Window() {
1591
1592   angular.element(document.getElementById('navbar')).scope().F5Window();
1593
1594 }
1595
1596 function TCAWindow(tca) {
1597
1598   angular.element(document.getElementById('navbar')).scope().TCAWindow(tca);
1599
1600 }
1601
1602 function GOCWindow() {
1603
1604   angular.element(document.getElementById('navbar')).scope().GOCWindow();
1605
1606 }
1607
1608 function PolicyWindow(PolicyWin) {
1609
1610   angular.element(document.getElementById('navbar')).scope().PolicyWindow(
1611     PolicyWin);
1612
1613 }
1614
1615 function pathDetails(bpmnElementID, bpmnElementName, pathIdentifiers) {
1616
1617   angular.element(document.getElementById('navbar')).scope().pathDetails(
1618     bpmnElementID, bpmnElementName, pathIdentifiers);
1619
1620 }
1621
1622 function setdefaultvalue() {
1623
1624   angular.element(document.getElementById('navbar')).scope()
1625     .setDefaultValue();
1626
1627 }
1628
1629 function upgradeSchemaVersion() {
1630
1631   angular.element(document.getElementById('navbar')).scope()
1632     .upgradeSchemaVersion();
1633
1634 }
1635
1636 function saveProject() {
1637
1638   angular.element(document.getElementById('navbar')).scope().saveProject();
1639
1640 }
1641
1642 function modifySchema() {
1643
1644   angular.element(document.getElementById('navbar')).scope().modifySchema();
1645
1646 }
1647
1648 function definePID() {
1649
1650   angular.element(document.getElementById('navbar')).scope().definePID();
1651
1652 }
1653
1654 function defineServiceAcronym() {
1655
1656   angular.element(document.getElementById('navbar')).scope()
1657     .defineServiceAcronym();
1658
1659 }
1660
1661 function errorProperty(msg) {
1662
1663   angular.element(document.getElementById('navbar')).scope()
1664     .propertyExplorerErrorMessage(msg);
1665 }
1666
1667 function invisiblepropertyExplorer() {
1668
1669   angular.element(document.getElementById('navbar')).scope()
1670     .invisibleproperty();
1671 }
1672
1673 function updateDecisionLabel(originalLabel, newLabel) {
1674
1675   angular.element(document.getElementById('navbar')).scope()
1676     .updateDecisionLabels(originalLabel, newLabel);
1677 }
1678
1679 // Used to logout the session , when browser window was closed
1680 window.onunload = function() {
1681   window.localStorage.removeItem("isAuth");
1682   window.localStorage.removeItem("loginuser");
1683 };