Replace ecomp references
[portal.git] / ecomp-portal-FE-common / client / app / views / scheduler / scheduler.controller.js
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38
39 'use strict';
40 (function () {
41         class SchedulerCtrl {
42                 constructor($scope,$state,message,$modalInstance,widgetsCatalogService,$log,schedulerService,$filter,confirmBoxService,userProfileService,conf,$interval,$compile,$rootScope) {
43                         $scope.parentData = message;
44                         /****define fields****/
45                         $scope.widgetName= '';
46                         $scope.widgetData = [];
47                         
48
49                         /**** Functions for widgets *****/
50                         $scope.getWidgetData =function(widgetId){
51                                 $rootScope.showSpinner = true;
52                                 var script = document.createElement('script');
53                                 script.src =  conf.api.widgetCommon + "/" + widgetId + "/framework.js";
54                                 script.async = true;
55                                 var entry = document.getElementsByTagName('script')[0];
56                                 entry.parentNode.insertBefore(script, entry);                   
57                         }
58                         $scope.getUserWidgets = function(loginName){ 
59                                 this.isCommError = false;
60                                 widgetsCatalogService.getUserWidgets(loginName).then(res => {
61                                         if(!(res instanceof Array)){
62                                                 $rootScope.showSpinner = false;
63                                                 this.isCommError = true;
64                                                 return;
65                                         }
66                                         for(var i = 0; i < res.length; i++){    
67                                                 var widget_id = res[i][0];
68                                                 var widget_name = res[i][1];
69                                                 if(widget_name== $scope.widgetName){
70                                                         var data={
71                                                                 attr:'data-'+widget_id,
72                                                                 value:''
73                                                         };
74                                                         $scope.widgetData.push(data);
75                                                         $scope.getWidgetData(widget_id);
76                                                 }
77                                         }
78                                 }).catch(err => {
79                                         $rootScope.showSpinner = false;
80                                         $log.error('WidgetCatalogCtrl::getUserWidgets caught error', err);
81                                 })
82                         };
83                         
84
85                         $rootScope.closeModal = function(){
86                                 $modalInstance.dismiss('cancel');
87                         }
88                         $scope.getUserIdAndWidget = function(){
89                                 $rootScope.showSpinner = true;
90                                 userProfileService.getUserProfile()
91                                 .then(profile=> {
92                                         $scope.orgUserId = profile.orgUserId;
93                                         $scope.getUserWidgets($scope.orgUserId);  
94                                 })
95                         }
96                         
97                         $scope.activateThis = function(ele){
98                                 $compile(ele.contents())($scope);
99                                 $scope.$apply();
100             };
101             
102             /*Calling Scheduler UI controller in microservice*/
103             $scope.submit = function(){
104                 $scope.$broadcast('submit','');
105             }
106             
107             $scope.reject = function(){
108                 $scope.$broadcast('reject','');
109             }
110             
111             $scope.schedule = function(){
112                 $scope.$broadcast('schedule','');
113             }
114             
115             
116             /** init **/
117             var init = function () {                            
118                                 $rootScope.showSpinner = false;
119                                 $scope.widgetName = message.id;
120                                 $scope.getUserIdAndWidget(); //get logged in user id, then widget data                  
121
122                         };
123                         init();
124                 }
125         }
126         SchedulerCtrl.$inject = ['$scope','$state','message','$modalInstance','widgetsCatalogService','$log', 'schedulerService','$filter','confirmBoxService','userProfileService','conf','$interval','$compile','$rootScope'];
127         angular.module('ecompApp').controller('SchedulerCtrl', SchedulerCtrl);
128 })();