Draft of React test
[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.loop_logs = [];
218             $rootScope.testSet = null;
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                     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             $rootScope.refreshLoopLog = function() {
474                 var newLogArray = [];
475                 if (getLoopLogsArray() != undefined) {
476                         newLogArray=getLoopLogsArray();
477                 }
478                 $rootScope.loop_logs.splice(0, $rootScope.loop_logs.length);
479                 for (var i=0;i<newLogArray.length;i++) {
480                         $rootScope.loop_logs.push(newLogArray[i]);
481                 }
482             }
483             $scope.extraUserInfo = function() {
484
485                     var dlg = dialogs.create(
486                     'partials/portfolios/extra_user_info.html', 'ExtraUserInfoCtrl', {
487                         closable : true,
488                         draggable : true
489                     }, {
490                         size : 'lg',
491                         keyboard : true,
492                         backdrop : 'static',
493                         windowClass : 'my-class'
494                     });
495                     dlg.result.then(function(name) {
496
497                     }, function() {
498
499                     });
500             };
501             $scope.cldsPerformAction = function(uiAction) {
502                     var modelName = selected_model;
503                     console.log("cldsPerformAction: " + uiAction + " modelName="
504                     + modelName);
505
506                     cldsModelService.processAction(uiAction, modelName).then(function(pars) {
507                             console.log("cldsPerformAction: pars=" + pars);
508                             cldsModelService.refreshStatus(modelName).then(function(pars) {
509                                 console.log("refreshStatus: pars=" + pars);
510                                 $rootScope.refreshLoopLog();
511                             }, function(data) {
512                             });
513                     }, function(data) {
514                     });
515             };
516             $scope.refreshStatus = function() {
517                     var modelName = selected_model;
518                     console.log("refreshStatus modelName=" + modelName);
519                     cldsModelService.refreshStatus(modelName).then(function(pars) {
520                         console.log("refreshStatus: pars=" + pars);
521                         $rootScope.refreshLoopLog();
522                     }, function(data) {
523
524                     });
525             };
526             $scope.cldsConfirmPerformAction = function(uiAction) {
527
528                     var dlg = dialogs.confirm('Message', 'Do you want to '
529                     + uiAction.toLowerCase() + ' the closed loop?');
530                     dlg.result.then(function(btn) {
531
532                             $scope.cldsPerformAction(uiAction);
533                     }, function(btn) {
534
535                     });
536             };
537             $scope.cldsAskDeployParametersPerformAction = function() {
538
539                     var dlg = dialogs.create(
540                     'partials/portfolios/deploy_parameters.html', 'DeploymentCtrl', {},
541                     {
542                         keyboard : true,
543                         backdrop : true,
544                         windowClass : 'deploy-parameters'
545                     });
546                     dlg.result.then(function() {
547
548                             var confirm = dialogs.confirm('Deploy',
549                             'Are you sure you want to deploy the closed loop?');
550                             confirm.result.then(function() {
551
552                                 $scope.cldsPerformAction("deploy");
553                             });
554                     });
555             };
556             $scope.cldsConfirmToggleDeployPerformAction = function(uiAction) {
557
558                     var dlg = dialogs.confirm('Message', 'Do you want to '
559                     + uiAction.toLowerCase() + ' the closed loop?');
560                     dlg.result.then(function(btn) {
561
562                         $scope.cldsPerformAction(uiAction.toLowerCase());
563                     }, function(btn) {
564
565                     });
566             };
567
568             $scope.ToscaModelWindow = function (tosca_model) {
569
570                 var dlg = dialogs.create('partials/portfolios/tosca_model_properties.html','ToscaModelCtrl',{closable:true,draggable:true},{size:'lg',keyboard: true,backdrop: 'static',windowClass: 'my-class'});
571                 dlg.result.then(function(name){
572                 },function(){
573                 });
574             };
575             $scope.PolicyWindow = function(policy) {
576
577                     var dlg = dialogs.create(
578                     'partials/portfolios/operational_policy_window.html',
579                     'operationalPolicyCtrl', {
580                         closable : true,
581                         draggable : true
582                     }, {
583                         size : 'lg',
584                         keyboard : true,
585                         backdrop : 'static',
586                         windowClass : 'my-class'
587                     });
588                     dlg.result.then(function(name) {
589
590                     }, function() {
591
592                     });
593             };
594     } ]);
595 app.service('MenuService', [ '$http', '$q', function($http, $q) {
596
597 } ]);
598 app.directive('focus', function($timeout) {
599
600         return {
601             scope : {
602                     trigger : '@focus'
603             },
604             link : function(scope, element) {
605
606                     scope.$watch('trigger', function(value) {
607
608                             if (value === "true") {
609                                     $timeout(function() {
610
611                                             element[0].focus();
612                                     });
613                             }
614                     });
615             }
616         };
617 });
618 app.directive('draggable', function($document) {
619
620         return function(scope, element, attr) {
621
622                 var startX = 0, startY = 0, x = 0, y = 0;
623                 element.css({
624                     position : 'relative',
625                     backgroundColor : 'white',
626                     cursor : 'move',
627                     display : 'block',
628                 });
629                 element.on('mousedown', function(event) {
630
631                         startX = event.screenX - x;
632                         startY = event.screenY - y;
633                         $document.on('mousemove', mousemove);
634                         $document.on('mouseup', mouseup);
635                 });
636                 function mousemove(event) {
637
638                         y = event.screenY - startY;
639                         x = event.screenX - startX;
640                         element.css({
641                             top : y + 'px',
642                             left : x + 'px'
643                         });
644                 }
645                 function mouseup() {
646
647                         $document.off('mousemove', mousemove);
648                         $document.off('mouseup', mouseup);
649                 }
650         };
651 });
652 app.factory('myHttpInterceptor', function($q, $window) {
653
654         return function(promise) {
655
656                 return promise.then(function(response) {
657
658                         return response;
659                 }, function(response) {
660
661                         return $q.reject(response);
662                 });
663         };
664 });
665 app.run([ '$route', function($route) {
666
667         $route.reload();
668 } ]);
669
670 function F5Window() {
671
672         angular.element(document.getElementById('navbar')).scope().F5Window();
673 }
674 function GOCWindow() {
675
676         angular.element(document.getElementById('navbar')).scope().GOCWindow();
677 }
678 function ToscaModelWindow() {
679     angular.element(document.getElementById('navbar')).scope().ToscaModelWindow();
680 }
681 function PolicyWindow(PolicyWin) {
682
683         angular.element(document.getElementById('navbar')).scope().PolicyWindow(
684         PolicyWin);
685 }
686 function pathDetails(bpmnElementID, bpmnElementName, pathIdentifiers) {
687
688         angular.element(document.getElementById('navbar')).scope().pathDetails(
689         bpmnElementID, bpmnElementName, pathIdentifiers);
690 }
691 function setdefaultvalue() {
692
693         angular.element(document.getElementById('navbar')).scope()
694         .setDefaultValue();
695 }
696 function saveProject() {
697
698         angular.element(document.getElementById('navbar')).scope().saveProject();
699 }
700
701 function defineServiceAcronym() {
702
703         angular.element(document.getElementById('navbar')).scope()
704         .defineServiceAcronym();
705 }
706 function errorProperty(msg) {
707
708         angular.element(document.getElementById('navbar')).scope()
709         .propertyExplorerErrorMessage(msg);
710 }
711 function invisiblepropertyExplorer() {
712
713         angular.element(document.getElementById('navbar')).scope()
714         .invisibleproperty();
715 }
716 function updateDecisionLabel(originalLabel, newLabel) {
717
718         angular.element(document.getElementById('navbar')).scope()
719         .updateDecisionLabels(originalLabel, newLabel);
720 }
721 // Used to logout the session , when browser window was closed
722 window.onunload = function() {
723
724         window.localStorage.removeItem("isAuth");
725         window.localStorage.removeItem("loginuser");
726         window.localStorage.removeItem("invalidUser");
727 };