5cba449e2bb2bf0ab728d755f29c96b7b84d060b
[portal.git] / ecomp-portal-FE-common / client / app / views / dashboard / dashboard-widget-parameters.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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 'use strict';
39
40 (function () {
41     class WidgetParameterController {
42         constructor($scope, widgetsCatalogService, userProfileService, $state,items) {
43                 $scope.ngDialogData=items;
44                 let widgetId = $scope.ngDialogData.widgetId;
45                 $scope.modflag = false;
46                 $scope.isLoadingTable = false;
47                 $scope.messageInfo = false;
48                 
49                 widgetsCatalogService.getWidgetCatalogParameters(widgetId).then(res => {
50                         if(res.status == 'OK'){
51                                 $scope.isLoadingTable = true;
52                                 $scope.widgetParam = res.response;
53                         }else if(res.status == 'WARN'){
54                                 $scope.messageInfo = true;
55                         }
56              }).catch(err => {
57                  $log.error('WidgetParameterController::init error: ' + err);
58              })
59                 
60                  $scope.setEdit = function(index) {
61                         if($scope.modflag === false){
62                                 $scope.widgetParam[index].showEdit = true;
63                                 $scope.modflag = true;
64                         }
65                  }              
66                 
67                  $scope.resetDefault = function(index) {
68                         var widgetParamObject = {};
69                 widgetParamObject.user_value = $scope.widgetParam[parseInt(index)].default_value;
70                 widgetParamObject.paramId = $scope.widgetParam[parseInt(index)].param_id;
71                 widgetParamObject.widgetId = widgetId;
72                         widgetsCatalogService.saveWidgetParameter(widgetParamObject)
73                         .then(function(res){
74                                 if(res.status == 'OK'){
75                                         $scope.widgetParam[index].user_value = $scope.widgetParam[index].default_value;
76                                 }
77                         });
78                  }           
79                 
80                  $scope.modify = function(index) {
81                         
82                         var widgetParamObject = {};
83                         widgetParamObject.user_value = $scope.widgetParam[parseInt(index)].user_value;
84                         widgetParamObject.paramId = $scope.widgetParam[parseInt(index)].param_id;
85                         widgetParamObject.widgetId = widgetId;
86                         
87                         widgetsCatalogService.saveWidgetParameter(widgetParamObject)
88                         .then(function(res){
89                                 if(res.status == 'OK'){
90                                         $scope.modflag = false;
91                                         $scope.widgetParam[index].showEdit = false;
92                                         $state.reload();
93                                 }
94                         });
95                         
96                 };      
97         }           
98     }
99     WidgetParameterController.$inject = ['$scope', 'widgetsCatalogService', 'userProfileService', '$state','items'];
100     angular.module('ecompApp').controller('WidgetParameterController', WidgetParameterController); 
101 })();