2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ============LICENSE_END=========================================================
20 app.controller('onapNameDictGridController', function ($scope, PolicyAppService, modalService, $modal, uiGridConstants,Grid){
21 $( "#dialog" ).hide();
23 PolicyAppService.getData('getDictionary/get_OnapNameData').then(function (data) {
25 $scope.data = JSON.parse(j.data);
26 console.log($scope.data);
27 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
28 console.log($scope.onapNameDictionaryDatas);
30 console.log("failed");
33 PolicyAppService.getData('get_LockDownData').then(function(data){
35 $scope.data = JSON.parse(j.data);
36 $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
37 if($scope.lockdowndata[0].lockdown == true){
38 $scope.onapNameDictionaryGrid.columnDefs[0].visible = false;
39 $scope.gridApi.grid.refresh();
41 $scope.onapNameDictionaryGrid.columnDefs[0].visible = true;
42 $scope.gridApi.grid.refresh();
45 console.log("failed");
48 $scope.onapNameDictionaryGrid = {
49 data : 'onapNameDictionaryDatas',
50 enableFiltering: true,
51 exporterCsvFilename: 'OnapName.csv',
53 enableSelectAll: true,
55 field: 'id', enableFiltering: false, headerCellTemplate: '' +
56 '<button id=\'New\' ng-click="grid.appScope.createNewOnapName()" class="btn btn-success">' + 'Create</button>',
58 '<button type="button" class="btn btn-primary" ng-click="grid.appScope.editOnapNameWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
59 '<button type="button" class="btn btn-danger" ng-click="grid.appScope.deleteOnapName(row.entity)" ><i class="fa fa-trash-o"></i></button> ', width: '8%'
61 { field: 'onapName', displayName : 'Onap Name', sort: { direction: 'asc', priority: 0 } },
62 { field: 'description', width: '20%' },
63 {field: 'userCreatedBy.userName', displayName : 'Created By'},
64 {field: 'userModifiedBy.userName', displayName : 'Modified By' },
65 {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''},
66 {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''}
68 exporterMenuPdf: false,
69 enableColumnResize : true,
70 exporterPdfDefaultStyle: {fontSize: 9},
71 exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
72 exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
73 exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
74 exporterPdfFooter: function ( currentPage, pageCount ) {
75 return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
77 exporterPdfCustomFormatter: function ( docDefinition ) {
78 docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
79 docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
82 exporterFieldCallback: function(grid, row, col, input) {
83 if( col.name == 'createdDate' || col.name == 'modifiedDate') {
84 var date = new Date(input);
85 return date.toString("yyyy-MM-dd HH:MM:ss a");
90 exporterPdfOrientation: 'portrait',
91 exporterPdfPageSize: 'LETTER',
92 exporterPdfMaxGridWidth: 500,
93 exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
94 onRegisterApi: function(gridApi){
95 $scope.gridApi = gridApi;
100 $scope.editOnapName = null;
101 $scope.createNewOnapName = function(){
102 $scope.editOnapName = null;
103 var modalInstance = $modal.open({
104 backdrop: 'static', keyboard: false,
105 templateUrl : 'add_onapName_popup.html',
106 controller: 'editOnapNameController',
108 message: function () {
110 onapNameDictionaryDatas: $scope.editOnapName
116 modalInstance.result.then(function(response){
117 console.log('response', response);
118 $scope.onapNameDictionaryDatas=response.onapNameDictionaryDatas;
122 $scope.editOnapNameWindow = function(onapNameDictionaryData) {
123 $scope.editOnapName = onapNameDictionaryData;
124 var modalInstance = $modal.open({
125 backdrop: 'static', keyboard: false,
126 templateUrl : 'add_onapName_popup.html',
127 controller: 'editOnapNameController',
129 message: function () {
131 onapNameDictionaryData: $scope.editOnapName
137 modalInstance.result.then(function(response){
138 console.log('response', response);
139 $scope.onapNameDictionaryDatas = response.onapNameDictionaryDatas;
143 $scope.deleteOnapName = function(data) {
144 var uuu = "searchDictionary";
145 var postData={data: data, type: "onapName"};
146 var searchString = "\n";
151 contentType: 'application/json',
152 data: JSON.stringify(postData),
153 success : function(resultList){
154 $scope.$apply(function(){
155 $scope.list =resultList.result;});
156 $scope.searchData = JSON.stringify(resultList.result);
157 $scope.searchDatas = JSON.parse($scope.searchData);
158 $scope.success = true;
160 if($scope.searchDatas.length > 0){
161 for(i = 0 ; i < $scope.searchDatas.length; i++){
162 searchString += $scope.searchDatas[i] + "\n";
165 searchString += "No Policies is Using this Value"
168 console.log($scope.list);
170 modalService.popupConfirmWin("Confirm","You are about to delete the Onap Name "+data.onapName+".\n "+searchString+" \n Do you want to continue?",
172 var uuu = "deleteDictionary/onap_dictionary/remove_onap";
173 var postData={data: data};
178 contentType: 'application/json',
179 data: JSON.stringify(postData),
180 success : function(data){
181 $scope.$apply(function(){$scope.onapNameDictionaryDatas=data.onapNameDictionaryDatas;});
183 error : function(data){
185 modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
191 error : function(data){
192 alert("Error while Searching.");