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