2a2994ab44c9f728d44f77e2a6dc04e434552fcb
[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 'use strict';
24 /* App Module */
25 var app = angular
26 .module(
27 'clds-app',
28 [ 'ngRoute', 'ngResource', 'ui.bootstrap', 'angular-loading-bar', 'ngAnimate',
29     'dialogs.main', 'ngSanitize', 'ngCookies', 'ui.bootstrap.modal' ])
30 .config([ 'cfpLoadingBarProvider', function(cfpLoadingBarProvider) {
31
32         cfpLoadingBarProvider.includeBar = true;
33         cfpLoadingBarProvider.includeSpinner = true;
34 } ])
35 .config(function($httpProvider) {
36
37         $httpProvider.interceptors.push('myHttpInterceptor');
38         var spinnerFunction = function spinnerFunction(data, headersGetter) {
39
40                 return data;
41         };
42         $httpProvider.defaults.transformRequest.push(spinnerFunction);
43 })
44 .config(
45 [
46     '$routeProvider',
47     '$locationProvider',
48     '$compileProvider',
49     'cfpLoadingBarProvider',
50     function($routeProvider, $locationProvider, cfpLoadingBarProvider,
51              $timeout, dialogs, $cookies) {
52
53             $locationProvider.html5Mode(false);
54             $routeProvider.when('/otherwise', {
55                 templateUrl : 'please_wait.html',
56                 controller : 'QueryParamsHandlerCtrl'
57             }).when('/dashboard', {
58                 templateUrl : 'partials/portfolios/clds_modelling.html',
59                 controller : 'DashboardCtrl'
60             }).when('/activity_modelling', {
61                 templateUrl : 'partials/portfolios/clds_modelling.html',
62                 controller : 'DashboardCtrl'
63             }).when('/authenticate', {
64                 templateUrl : 'authenticate.html',
65                 controller : 'AuthenticateCtrl'
66             }).when('/invalidlogin', {
67                 templateUrl : 'invalid_login.html',
68                 controller : 'PageUnderConstructionCtrl'
69             }).otherwise({
70                     redirectTo : '/otherwise'
71             });
72     } ])
73 .controller(
74 'dialogCtrl',
75 function($scope, $rootScope, $timeout, dialogs) {
76
77         // -- Variables --//
78         $scope.lang = 'en-US';
79         $scope.language = 'English';
80         var _progress = 100;
81         $scope.name = '';
82         $scope.confirmed = 'No confirmation yet!';
83         $scope.custom = {
84                 val : 'Initial Value'
85         };
86         // -- Listeners & Watchers --//
87         $scope.$watch('lang', function(val, old) {
88
89                 switch (val) {
90                         case 'en-US':
91                                 $scope.language = 'English';
92                                 break;
93                         case 'es':
94                                 $scope.language = 'Spanish';
95                                 break;
96                 }
97         });
98         // -- Methods --//
99         $rootScope.testCaseRequirements = [];
100         $rootScope.validTestRequirements = [];
101         $scope.setLanguage = function(lang) {
102
103                 $scope.lang = lang;
104                 $translate.use(lang);
105         };
106         $rootScope.launch = function(which) {
107
108                 switch (which) {
109                         case 'error':
110                                 dialogs.error();
111                                 break;
112                         case 'wait':
113                                 break;
114                         case 'customwait':
115                                 break;
116                         case 'notify':
117                                 dialogs.notify();
118                                 break;
119                         case 'confirm':
120                                 var dlg = dialogs.confirm();
121                                 dlg.result.then(function(btn) {
122
123                                         $scope.confirmed = 'You confirmed "Yes."';
124                                 }, function(btn) {
125
126                                         $scope.confirmed = 'You confirmed "No."';
127                                 });
128                                 break;
129                         case 'custom':
130                                 var dlg = dialogs.create('/dialogs/custom.html',
131                                 'customDialogCtrl', {}, {
132                                     size : 'lg',
133                                     keyboard : true,
134                                     backdrop : 'static',
135                                     windowClass : 'my-class'
136                                 });
137                                 dlg.result.then(function(name) {
138
139                                         $scope.name = name;
140                                 }, function() {
141
142                                         if (angular.equals($scope.name, ''))
143                                                 $scope.name = 'You did not enter in your name!';
144                                 });
145                                 break;
146                         case 'custom2':
147                                 var dlg = dialogs.create('/dialogs/custom2.html',
148                                 'customDialogCtrl2', $scope.custom, {
149                                         size : 'lg'
150                                 });
151                                 break;
152                         case 'custom3':
153                                 var dlg = dialogs
154                                 .notify(
155                                 'Message',
156                                 'All is not supported, Please select interface(s)/version(s) to fetch real time federated coverage report.');
157                                 break;
158                         case 'custom4':
159                                 var dlg = dialogs
160                                 .confirm(
161                                 'Message',
162                                 'You are about to fetch real time federated coverage report.This may take sometime!!!.');
163                                 dlg.result.then(function(btn) {
164
165                                         $scope.confirmed = 'You confirmed "Yes."';
166                                 }, function(btn) {
167
168                                         $scope.confirmed = 'You confirmed "No."';
169                                 });
170                                 break;
171                         case 'custom5':
172                                 var dlg = dialogs.notify('Success',
173                                 'Request has been successfully processed.');
174                                 break;
175                         case 'custom6':
176                                 var dlg = dialogs.notify('Message',
177                                 'Please type Testscenario Name');
178                                 break;
179                 }
180         }; // end launch
181         var _fakeWaitProgress = function() {
182
183                 $timeout(function() {
184
185                         if (_progress < 100) {
186                                 _progress += 33;
187                                 $rootScope.$broadcast('dialogs.wait.progress', {
188                                         'progress' : _progress
189                                 });
190                                 _fakeWaitProgress();
191                         } else {
192                                 $rootScope.$broadcast('dialogs.wait.complete');
193                                 _progress = 0;
194                         }
195                 }, 1000);
196         };
197 })
198 .controller(
199 'MenuCtrl',
200 [
201     '$scope',
202     '$rootScope',
203     '$timeout',
204     'dialogs',
205     '$location',
206     'MenuService',
207     'Datafactory',
208     'userPreferencesService',
209     'cldsModelService',
210     'extraUserInfoService',
211     function($scope, $rootScope, $timeout, dialogs, $location, MenuService,
212              Datafactory, userPreferencesService, cldsModelService,
213              extraUserInfoService) {
214
215             console.log("MenuCtrl");
216             $rootScope.screenName = "Universal Test Modeler";
217             $rootScope.testSet = null;
218             var testingType = "";
219             $rootScope.contactUs = function() {
220
221                     console.log("contactUs");
222                     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.";
223                     window.location.href = link;
224             };
225             extraUserInfoService.getUserInfo().then(function(pars) {
226
227                     $scope.userInfo = pars;
228                     if (!($scope.userInfo["permissionUpdateCl"])) {
229                             readMOnly = true;
230                     }
231                     ;
232             });
233             $scope.emptyMenuClick = function(value, name) {
234
235                     if ($rootScope.isNewClosed
236                     && name != "Close Model" && name != "Properties CL") {
237                             saveConfirmationNotificationPopUp();
238                     } else {
239                             isSaveCheck(name);
240                     }
241                     function saveConfirmationNotificationPopUp() {
242
243                             $scope.saveConfirmationNotificationPopUp(function(data) {
244
245                                     if (data) {
246                                             $rootScope.isNewClosed = false;
247                                     } else {
248                                             return false;
249                                     }
250                             });
251                     }
252                     function isSaveCheck(name) {
253
254                             if (name == "User Info") {
255                                     $scope.extraUserInfo();
256                             } else if (name == "Wiki") {
257                                     window.open(value);
258                             } else if (name == "Contact Us") {
259                                     $rootScope.contactUs();
260                             } else if (name == "Close Model") {
261                                     $scope.cldsClose();
262                             } else if (name == "Open CL") {
263                                     $scope.cldsOpenModel();
264                             } else if (name == "Submit") {
265                                     $scope.cldsConfirmPerformAction("SUBMIT");
266                             } else if (name == "Update") {
267                                     $scope.cldsConfirmPerformAction("UPDATE");
268                             } else if (name == "Delete") {
269                                     $scope.cldsConfirmPerformAction("DELETE");
270                             } else if (name == "Stop") {
271                                     $scope.cldsConfirmPerformAction("STOP");
272                             } else if (name == "Restart") {
273                                     $scope.cldsConfirmPerformAction("RESTART");
274                             } else if (name == "Refresh Status") {
275                                     $scope.refreshStatus();
276                             } else if (name == "Properties CL") {
277                                     $scope.cldsOpenModelProperties();
278                             } else if (name == "Deploy") {
279                                     $scope.cldsAskDeployParametersPerformAction();
280                             } else if (name == "UnDeploy") {
281                                     $scope.cldsConfirmToggleDeployPerformAction("UnDeploy");
282                             } else {
283                                     $rootScope.screenName = name;
284                                     $scope.updatebreadcrumb(value);
285                                     $location.path(value);
286                             }
287                     }
288             };
289             $rootScope.impAlerts = function() {
290
291             };
292             $scope.tabs = {
293                 "Closed Loop" : [ {
294                     link : "/cldsOpenModel",
295                     name : "Open CL"
296                 }, {
297                     link : "/cldsOpenModelProperties",
298                     name : "Properties CL"
299                 }, {
300                     link : "/Close",
301                     name : "Close Model"
302                 } ],
303                 "Manage" : [ {
304                     link : "/cldsSubmit",
305                     name : "Submit"
306                 }, {
307                 // disabled for Dublin since Policy doesn't support updating in this release
308                     //   link : "/cldsUpdate",
309                 //    name : "Update"
310                 //}, {
311                     link : "/cldsStop",
312                     name : "Stop"
313                 }, {
314                     link : "/cldsRestart",
315                     name : "Restart"
316                 }, {
317                     link : "/cldsDelete",
318                     name : "Delete"
319                 }, {
320                     link : "/cldsDeploy",
321                     name : "Deploy"
322                 }, {
323                     link : "/cldsUnDeploy",
324                     name : "UnDeploy"
325                 } ],
326                 "View" : [ {
327                     link : "/refreshStatus",
328                     name : "Refresh Status"
329                 } ],
330                 "Help" : [ {
331                     link : "http://wiki.onap.org",
332                     name : "Wiki"
333                 }, {
334                     link : "/contact_us",
335                     name : "Contact Us"
336                 }, {
337                     link : "/extraUserInfo",
338                     name : "User Info"
339                 } ]
340             };
341             if (!Object.keys) {
342                     Object.keys = function(obj) {
343
344                             var keys = [];
345                             for ( var i in obj) {
346                                     if (obj.hasOwnProperty(i)) {
347                                             keys.push(i);
348                                     }
349                             }
350                             return keys;
351                     };
352                     $scope.keyList = Object.keys($scope.tabs);
353             } else {
354                     $scope.keyList = Object.keys($scope.tabs);
355             }
356             $scope.updatebreadcrumb = function(path) {
357
358                     var currentURL = $location.path();
359                     if (path != undefined) {
360                             currentURL = path;
361                     }
362                     if (currentURL == "/dashboard") {
363                             $rootScope.screenName = "Universal Test Modeler";
364                             $rootScope.parentMenu = "Home";
365                             $rootScope.rightTabName = "UTM Build Configuration";
366                     } else {
367                             var found = false;
368                             angular.forEach($scope.keyList, function(value, key) {
369
370                                     if (!found) {
371                                             $rootScope.parentMenu = value;
372                                             angular.forEach($scope.tabs[value],
373                                             function(value, key) {
374
375                                                     if (currentURL == value.link) {
376                                                             $rootScope.screenName = value.name;
377                                                             found = true;
378                                                     }
379                                             });
380                                     }
381                             });
382                     }
383             };
384             $scope.updatebreadcrumb();
385             $scope.homePage = function() {
386
387                     $location.path('/dashboard');
388             };
389             $scope.propertyExplorerErrorMessage = function(msg) {
390
391                     var dlg = dialogs.notify('Error', msg);
392             }
393             $scope.activityModelling = function() {
394
395             };
396             $scope.cldsClose = function() {
397
398                     var dlg = dialogs.create(
399                     'partials/portfolios/confirmation_window.html',
400                     'CldsOpenModelCtrl', {
401                         closable : true,
402                         draggable : true
403                     }, {
404                         size : 'lg',
405                         keyboard : true,
406                         backdrop : 'static',
407                         windowClass : 'my-class'
408                     });
409                     dlg.result.then(function(name) {
410
411                             // $scope.name = name;
412                     }, function() {
413
414                             // if(angular.equals($scope.name,''))
415                             // $scope.name = 'You did not enter in your
416                             // name!';
417                     });
418             };
419             $scope.saveConfirmationNotificationPopUp = function(callBack) {
420
421                     var dlg = dialogs.create(
422                     'partials/portfolios/save_confirmation.html',
423                     'saveConfirmationModalPopUpCtrl', {
424                         closable : true,
425                         draggable : true
426                     }, {
427                         size : 'lg',
428                         keyboard : true,
429                         backdrop : 'static',
430                         windowClass : 'my-class'
431                     });
432                     dlg.result.then(function(name) {
433
434                             callBack("OK");
435                     }, function() {
436
437                             callBack(null);
438                     });
439             };
440             $rootScope.cldsOpenModelProperties = function() {
441
442                     var dlg = dialogs.create(
443                     'partials/portfolios/global_properties.html',
444                     'GlobalPropertiesCtrl', {}, {
445                         size : 'lg',
446                         keyboard : true,
447                         backdrop : 'static',
448                         windowClass : 'my-class'
449                     });
450                     dlg.result.then(function(name) {
451
452                     }, function() {
453
454                     });
455             };
456             $scope.cldsOpenModel = function() {
457
458                     var dlg = dialogs.create(
459                     'partials/portfolios/clds_open_model.html', 'CldsOpenModelCtrl', {
460                         closable : true,
461                         draggable : true
462                     }, {
463                         size : 'lg',
464                         keyboard : true,
465                         backdrop : 'static',
466                         windowClass : 'my-class'
467                     });
468                     dlg.result.then(function(name) {
469
470                     }, function() {
471
472                     });
473             };
474             $scope.extraUserInfo = function() {
475
476                     var dlg = dialogs.create(
477                     'partials/portfolios/extra_user_info.html', 'ExtraUserInfoCtrl', {
478                         closable : true,
479                         draggable : true
480                     }, {
481                         size : 'lg',
482                         keyboard : true,
483                         backdrop : 'static',
484                         windowClass : 'my-class'
485                     });
486                     dlg.result.then(function(name) {
487
488                     }, function() {
489
490                     });
491             };
492             $scope.cldsPerformAction = function(uiAction) {
493                     var modelName = selected_model;
494                     console.log("cldsPerformAction: " + uiAction + " modelName="
495                     + modelName);
496
497                     cldsModelService.processAction(uiAction, modelName).then(function(pars) {
498                             console.log("cldsPerformAction: pars=" + pars);
499                     }, function(data) {
500
501                     });
502             };
503             $scope.refreshStatus = function() {
504                     var modelName = selected_model;
505                     console.log("refreStatus modelName=" + modelName);
506                     cldsModelService.getModel(modelName).then(function(pars) {
507                             console.log("refreStatus: pars=" + pars);
508                             cldsModelService.processRefresh();
509                     }, function(data) {
510
511                     });
512             };
513             $scope.cldsConfirmPerformAction = function(uiAction) {
514
515                     var dlg = dialogs.confirm('Message', 'Do you want to '
516                     + uiAction.toLowerCase() + ' the closed loop?');
517                     dlg.result.then(function(btn) {
518
519                             $scope.cldsPerformAction(uiAction);
520                     }, function(btn) {
521
522                     });
523             };
524             $scope.cldsAskDeployParametersPerformAction = function() {
525
526                     var dlg = dialogs.create(
527                     'partials/portfolios/deploy_parameters.html', 'DeploymentCtrl', {},
528                     {
529                         keyboard : true,
530                         backdrop : true,
531                         windowClass : 'deploy-parameters'
532                     });
533                     dlg.result.then(function() {
534
535                             var confirm = dialogs.confirm('Deploy',
536                             'Are you sure you want to deploy the closed loop?');
537                             confirm.result.then(function() {
538
539                                     cldsToggleDeploy("deploy");
540                             });
541                     });
542             };
543             $scope.cldsConfirmToggleDeployPerformAction = function(uiAction) {
544
545                     var dlg = dialogs.confirm('Message', 'Do you want to '
546                     + uiAction.toLowerCase() + ' the closed loop?');
547                     dlg.result.then(function(btn) {
548
549                             cldsToggleDeploy(uiAction.toLowerCase());
550                     }, function(btn) {
551
552                     });
553             };
554             function cldsToggleDeploy(uiAction) {
555                     console.log("cldsPerformAction: " + uiAction + " modelName="
556                         + selected_model);
557                     cldsModelService.toggleDeploy(uiAction, selected_model).then(
558                     function(pars) {
559                     }, function(data) {
560
561                     });
562             }
563             $scope.ToscaModelWindow = function (tosca_model) {
564
565                 var dlg = dialogs.create('partials/portfolios/tosca_model_properties.html','ToscaModelCtrl',{closable:true,draggable:true},{size:'lg',keyboard: true,backdrop: 'static',windowClass: 'my-class'});
566                 dlg.result.then(function(name){
567                 },function(){
568                 });
569             };
570             $scope.PolicyWindow = function(policy) {
571
572                     var dlg = dialogs.create(
573                     'partials/portfolios/operational_policy_window.html',
574                     'operationalPolicyCtrl', {
575                         closable : true,
576                         draggable : true
577                     }, {
578                         size : 'lg',
579                         keyboard : true,
580                         backdrop : 'static',
581                         windowClass : 'my-class'
582                     });
583                     dlg.result.then(function(name) {
584
585                     }, function() {
586
587                     });
588             };
589     } ]);
590 app.service('MenuService', [ '$http', '$q', function($http, $q) {
591
592 } ]);
593 app.directive('focus', function($timeout) {
594
595         return {
596             scope : {
597                     trigger : '@focus'
598             },
599             link : function(scope, element) {
600
601                     scope.$watch('trigger', function(value) {
602
603                             if (value === "true") {
604                                     $timeout(function() {
605
606                                             element[0].focus();
607                                     });
608                             }
609                     });
610             }
611         };
612 });
613 app.directive('draggable', function($document) {
614
615         return function(scope, element, attr) {
616
617                 var startX = 0, startY = 0, x = 0, y = 0;
618                 element.css({
619                     position : 'relative',
620                     backgroundColor : 'white',
621                     cursor : 'move',
622                     display : 'block',
623                 });
624                 element.on('mousedown', function(event) {
625
626                         startX = event.screenX - x;
627                         startY = event.screenY - y;
628                         $document.on('mousemove', mousemove);
629                         $document.on('mouseup', mouseup);
630                 });
631                 function mousemove(event) {
632
633                         y = event.screenY - startY;
634                         x = event.screenX - startX;
635                         element.css({
636                             top : y + 'px',
637                             left : x + 'px'
638                         });
639                 }
640                 function mouseup() {
641
642                         $document.off('mousemove', mousemove);
643                         $document.off('mouseup', mouseup);
644                 }
645         };
646 });
647 app.factory('myHttpInterceptor', function($q, $window) {
648
649         return function(promise) {
650
651                 return promise.then(function(response) {
652
653                         return response;
654                 }, function(response) {
655
656                         return $q.reject(response);
657                 });
658         };
659 });
660 app.run([ '$route', function($route) {
661
662         $route.reload();
663 } ]);
664
665 function F5Window() {
666
667         angular.element(document.getElementById('navbar')).scope().F5Window();
668 }
669 function GOCWindow() {
670
671         angular.element(document.getElementById('navbar')).scope().GOCWindow();
672 }
673 function ToscaModelWindow() {
674     angular.element(document.getElementById('navbar')).scope().ToscaModelWindow();
675 }
676 function PolicyWindow(PolicyWin) {
677
678         angular.element(document.getElementById('navbar')).scope().PolicyWindow(
679         PolicyWin);
680 }
681 function pathDetails(bpmnElementID, bpmnElementName, pathIdentifiers) {
682
683         angular.element(document.getElementById('navbar')).scope().pathDetails(
684         bpmnElementID, bpmnElementName, pathIdentifiers);
685 }
686 function setdefaultvalue() {
687
688         angular.element(document.getElementById('navbar')).scope()
689         .setDefaultValue();
690 }
691 function saveProject() {
692
693         angular.element(document.getElementById('navbar')).scope().saveProject();
694 }
695
696 function defineServiceAcronym() {
697
698         angular.element(document.getElementById('navbar')).scope()
699         .defineServiceAcronym();
700 }
701 function errorProperty(msg) {
702
703         angular.element(document.getElementById('navbar')).scope()
704         .propertyExplorerErrorMessage(msg);
705 }
706 function invisiblepropertyExplorer() {
707
708         angular.element(document.getElementById('navbar')).scope()
709         .invisibleproperty();
710 }
711 function updateDecisionLabel(originalLabel, newLabel) {
712
713         angular.element(document.getElementById('navbar')).scope()
714         .updateDecisionLabels(originalLabel, newLabel);
715 }
716 // Used to logout the session , when browser window was closed
717 window.onunload = function() {
718
719         window.localStorage.removeItem("isAuth");
720         window.localStorage.removeItem("loginuser");
721         window.localStorage.removeItem("invalidUser");
722 };