10ccb9bfc8da97018dc302447700e90435421bca
[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, $state,items) {
25                 $scope.ngDialogData=items;
26                 let widgetId = $scope.ngDialogData.widgetId;
27                 $scope.modflag = false;
28                 $scope.isLoadingTable = false;
29                 $scope.messageInfo = false;
30                 
31                 widgetsCatalogService.getWidgetCatalogParameters(widgetId).then(res => {
32                         if(res.status == 'OK'){
33                                 $scope.isLoadingTable = true;
34                                 $scope.widgetParam = res.response;
35                         }else if(res.status == 'WARN'){
36                                 $scope.messageInfo = true;
37                         }
38              }).catch(err => {
39                  $log.error('WidgetParameterController::init error: ' + err);
40              })
41                 
42                  $scope.setEdit = function(index) {
43                         if($scope.modflag === false){
44                                 $scope.widgetParam[index].showEdit = true;
45                                 $scope.modflag = true;
46                         }
47                  }              
48                 
49                  $scope.resetDefault = function(index) {
50                         var widgetParamObject = {};
51                 widgetParamObject.user_value = $scope.widgetParam[parseInt(index)].default_value;
52                 widgetParamObject.paramId = $scope.widgetParam[parseInt(index)].param_id;
53                 widgetParamObject.widgetId = widgetId;
54                         widgetsCatalogService.saveWidgetParameter(widgetParamObject)
55                         .then(function(res){
56                                 if(res.status == 'OK'){
57                                         $scope.widgetParam[index].user_value = $scope.widgetParam[index].default_value;
58                                 }
59                         });
60                  }           
61                 
62                  $scope.modify = function(index) {
63                         
64                         var widgetParamObject = {};
65                         widgetParamObject.user_value = $scope.widgetParam[parseInt(index)].user_value;
66                         widgetParamObject.paramId = $scope.widgetParam[parseInt(index)].param_id;
67                         widgetParamObject.widgetId = widgetId;
68                         
69                         widgetsCatalogService.saveWidgetParameter(widgetParamObject)
70                         .then(function(res){
71                                 if(res.status == 'OK'){
72                                         $scope.modflag = false;
73                                         $scope.widgetParam[index].showEdit = false;
74                                         $state.reload();
75                                 }
76                         });
77                         
78                 };      
79         }           
80     }
81     WidgetParameterController.$inject = ['$scope', 'widgetsCatalogService', 'userProfileService', '$state','items'];
82     angular.module('ecompApp').controller('WidgetParameterController', WidgetParameterController); 
83 })();