fb9a254fac9d7518e440b6d1f59329d7678034c6
[portal.git] / ecomp-portal-FE-common / client / app / views / dashboard / dashboard-widget-parameters.controller.js
1 /*-
2  * ================================================================================
3  * ECOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 'use strict';
21
22 (function () {
23     class WidgetParameterController {
24         constructor($scope, widgetsCatalogService, userProfileService) {
25                 let widgetId = $scope.ngDialogData.widgetId;
26                 $scope.modflag = false;
27                 $scope.isLoadingTable = false;
28                 $scope.messageInfo = false;
29                 
30                 widgetsCatalogService.getWidgetCatalogParameters(widgetId).then(res => {
31                         if(res.status == 'OK'){
32                                 $scope.isLoadingTable = true;
33                                 $scope.widgetParam = res.response;
34                         }else if(res.status == 'WARN'){
35                                 $scope.messageInfo = true;
36                         }
37              }).catch(err => {
38                  $log.error('WidgetParameterController::init error: ' + err);
39              })
40                 
41                  $scope.setEdit = function(index) {
42                         if($scope.modflag === false){
43                                 $scope.widgetParam[index].showEdit = true;
44                                 $scope.modflag = true;
45                         }
46                  }              
47                 
48                  $scope.resetDefault = function(index) {
49                         var widgetParamObject = {};
50                 widgetParamObject.user_value = $scope.widgetParam[parseInt(index)].default_value;
51                 widgetParamObject.paramId = $scope.widgetParam[parseInt(index)].param_id;
52                 widgetParamObject.widgetId = widgetId;
53                         widgetsCatalogService.saveWidgetParameter(widgetParamObject)
54                         .then(function(res){
55                                 if(res.status == 'OK'){
56                                         $scope.widgetParam[index].user_value = $scope.widgetParam[index].default_value;
57                                 }
58                         });
59                  }           
60                 
61                  $scope.modify = function(index) {
62                         
63                         var widgetParamObject = {};
64                         widgetParamObject.user_value = $scope.widgetParam[parseInt(index)].user_value;
65                         widgetParamObject.paramId = $scope.widgetParam[parseInt(index)].param_id;
66                         widgetParamObject.widgetId = widgetId;
67                         
68                         widgetsCatalogService.saveWidgetParameter(widgetParamObject)
69                         .then(function(res){
70                                 if(res.status == 'OK'){
71                                         $scope.modflag = false;
72                                         $scope.widgetParam[index].showEdit = false;
73                                 }
74                         });
75                         
76                 };      
77         }           
78     }
79     WidgetParameterController.$inject = ['$scope', 'widgetsCatalogService', 'userProfileService'];
80     angular.module('ecompApp').controller('WidgetParameterController', WidgetParameterController); 
81 })();