2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 2019-2020 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('PolicyManagerController', [
21 '$scope', '$q', '$window', '$cookies', 'policyManagerConfig', 'item', 'policyNavigator', 'policyUploader', 'Notification','PolicyAppService',
22 function($scope, $q, $Window, $cookies, policyManagerConfig, Item, PolicyNavigator, PolicyUploader, Notification, PolicyAppService ) {
24 $scope.isDisabled = true;
25 $scope.superAdminId = false;
26 $scope.exportPolicyId = false;
27 $scope.importPolicyId = false;
28 $scope.createScopeId = false;
29 $scope.deleteScopeId = false;
30 $scope.renameId = false;
31 $scope.createPolicyId = false;
32 $scope.cloneId = false;
33 $scope.editPolicyId = false;
34 $scope.switchVersionId = false;
35 $scope.describePolicyId = false;
36 $scope.viewPolicyId = false;
37 $scope.deletePolicyId = false;
38 PolicyAppService.getData('get_LockDownData').then(function(data) {
40 $scope.data = JSON.parse(j.data);
41 $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
42 if ($scope.lockdowndata[0].lockdown == true) {
43 $scope.isDisabled = true;
45 $scope.isDisabled = false;
50 PolicyAppService.getData('getDictionary/get_DescriptiveScopeByName').then(function(data) {
52 $scope.data = JSON.parse(j.data);
53 $scope.descriptiveScopeDictionaryDatas = JSON.parse($scope.data.descriptiveScopeDictionaryDatas);
56 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function(data) {
58 $scope.data = JSON.parse(j.data);
59 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
62 PolicyAppService.getData('getDictionary/get_VSCLActionDataByName').then(function(data) {
64 $scope.data = JSON.parse(j.data);
65 $scope.vsclActionDictionaryDatas = JSON.parse($scope.data.vsclActionDictionaryDatas);
68 PolicyAppService.getData('getDictionary/get_VNFTypeDataByName').then(function(data) {
70 $scope.data = JSON.parse(j.data);
71 $scope.vnfTypeDictionaryDatas = JSON.parse($scope.data.vnfTypeDictionaryDatas);
75 PolicyAppService.getData('get_UserRolesData').then(function (data) {
77 $scope.data = JSON.parse(j.data);
78 $scope.userRolesDatas = JSON.parse($scope.data.userRolesDatas);
79 if ($scope.userRolesDatas[0] == 'super-admin') {
80 $scope.superAdminId = true;
81 $scope.exportPolicyId = true;
82 $scope.importPolicyId = true;
83 } else if ($scope.userRolesDatas[0] == 'super-editor' || $scope.userRolesDatas[0] == 'editor' || $scope.userRolesDatas[0] == 'admin') {
84 $scope.exportPolicyId = true;
85 $scope.importPolicyId = true;
89 $scope.config = policyManagerConfig;
90 $scope.reverse = false;
91 $scope.predicate = ['model.type', 'model.name'];
92 $scope.order = function(predicate) {
93 $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false;
94 $scope.predicate[1] = predicate;
98 $scope.temp = new Item();
99 $scope.policyNavigator = new PolicyNavigator();
100 $scope.policyUploader = PolicyUploader;
101 $scope.uploadFileList = [];
103 $scope.setTemplate = function(name) {
104 $scope.viewTemplate = $cookies.viewTemplate = name;
107 $scope.touch = function(item) {
108 item = item instanceof Item ? item : new Item();
111 $scope.createScopeId = false;
112 $scope.deleteScopeId = false;
113 $scope.renameId = false;
114 $scope.createPolicyId = false;
115 $scope.cloneId = false;
116 $scope.editPolicyId = false;
117 $scope.switchVersionId = false;
118 $scope.describePolicyId = false;
119 $scope.viewPolicyId = false;
120 $scope.deletePolicyId = false;
121 if ($scope.temp.model.roleType == 'super-admin') {
122 $scope.createScopeId = true;
123 $scope.deleteScopeId = true;
124 $scope.renameId = true;
125 $scope.createPolicyId = true;
126 $scope.cloneId = true;
127 $scope.editPolicyId = true;
128 $scope.switchVersionId = true;
129 $scope.describePolicyId = true;
130 $scope.viewPolicyId = true;
131 $scope.deletePolicyId = true;
132 } else if ($scope.temp.model.roleType == 'super-editor' || $scope.temp.model.roleType == 'editor') {
133 $scope.cloneId = true;
134 $scope.editPolicyId = true;
135 $scope.createPolicyId = true;
136 $scope.switchVersionId = true;
137 $scope.describePolicyId = true;
138 $scope.viewPolicyId = true;
139 $scope.deletePolicyId = true;
140 } else if ($scope.temp.model.roleType == 'super-guest' || $scope.temp.model.roleType == 'guest') {
141 $scope.describePolicyId = true;
142 $scope.viewPolicyId = true;
143 } else if ($scope.temp.model.roleType == 'admin') {
144 $scope.createScopeId = true;
145 $scope.renameId = true;
146 $scope.createPolicyId = true;
147 $scope.cloneId = true;
148 $scope.editPolicyId = true;
149 $scope.switchVersionId = true;
150 $scope.describePolicyId = true;
151 $scope.viewPolicyId = true;
152 $scope.deletePolicyId = true;
156 $scope.smartClick = function(item) {
157 if (item.isFolder()) {
158 return $scope.policyNavigator.folderClick(item);
160 if (item.isEditable()) {
161 return $scope.openEditItem(item);
165 $scope.openEditItem = function(item) {
167 $scope.modal('createNewPolicy');
168 return $scope.touch(item);
171 $scope.modal = function(id, hide) {
172 return $('#' + id).modal(hide ? 'hide' : 'show');
175 $scope.isInThisPath = function(path) {
176 var currentPath = $scope.policyNavigator.currentPath.join('/');
177 return currentPath.indexOf(path) !== -1;
180 $scope.watchPolicy = function(item) {
181 var uuu = "watchPolicy";
182 var data = {name : item.model.name,
183 path : item.model.path};
184 var postData={watchData: data};
189 contentType: 'application/json',
190 data: JSON.stringify(postData),
191 success : function(data) {
192 $scope.$apply(function() {
193 $scope.watchData=data.watchData;});
194 Notification.success($scope.watchData);
196 error : function(data) {
197 Notification.error("Error while saving.");
202 $scope.refresh = function() {
203 $scope.policyNavigator.refresh();
206 $scope.switchVersion = function(item) {
207 if ($scope.policyNavigator.fileNameExists(item.tempModel.content.activeVersion)) {
208 item.error = 'Invalid filename or already exists, specify another name';
211 item.getSwitchVersionContent().then(function(){
212 $scope.policyNavigator.refresh();
213 $scope.modal('switchVersion', true);
217 $scope.copy = function(item) {
218 var samePath = item.tempModel.path.join() === item.model.path.join();
219 if (samePath && $scope.policyNavigator.fileNameExists(item.tempModel.name)) {
220 item.error = 'Invalid filename or already exists, specify another name';
223 item.copy().then(function() {
224 $scope.policyNavigator.refresh();
225 $scope.modal('copy', true);
229 $scope.remove = function(item) {
230 item.remove().then(function() {
231 $scope.policyNavigator.refresh();
232 $scope.modal('delete', true);
236 $scope.removePolicy = function(item) {
237 item.removePolicy().then(function() {
238 $scope.policyNavigator.refresh();
239 $scope.modal('deletePolicy', true);
243 $scope.rename = function(item) {
244 var samePath = item.tempModel.path.join() === item.model.path.join();
245 if (samePath && $scope.policyNavigator.fileNameExists(item.tempModel.name)) {
246 item.error = 'Invalid filename or already exists, specify another name';
249 item.rename().then(function() {
250 $scope.policyNavigator.refresh();
251 $scope.modal('rename', true);
255 $scope.move = function(item) {
256 var samePath = item.tempModel.path.join() === item.model.path.join();
257 if (samePath && $scope.policyNavigator.fileNameExists(item.tempModel.name)) {
258 item.error = 'Invalid filename or already exists, specify another name';
261 item.move().then(function() {
262 $scope.policyNavigator.refresh();
263 $scope.modal('move', true);
267 $scope.createFolder = function(item) {
268 var name = item.tempModel.name && item.tempModel.name.trim();
269 item.tempModel.type = 'dir';
270 item.tempModel.path = $scope.policyNavigator.currentPath;
271 if (name && !$scope.policyNavigator.fileNameExists(name)) {
272 item.createFolder().then(function() {
273 $scope.policyNavigator.refresh();
274 $scope.modal('newfolder', true);
277 item.error = 'Invalid filename or already exists, specify another name';
282 $scope.subScopeFolder = function(item) {
283 var name = item.tempModel.name +"\\" + item.tempModel.subScopename && item.tempModel.name.trim() + "\\"+item.tempModel.subScopename.trim() ;
284 item.tempModel.type = 'dir';
285 item.tempModel.path = $scope.policyNavigator.currentPath;
286 if (name && !$scope.policyNavigator.fileNameExists(name)) {
287 item.getScopeContent().then(function() {
288 $scope.policyNavigator.refresh();
289 $scope.modal('addSubScope', true);
292 item.error = 'Invalid filename or already exists, specify another name';
297 $scope.closefunction = function(fianlPath) {
298 $scope.policyNavigator.policyrefresh(fianlPath);
301 $scope.uploadFiles = function() {
302 $scope.policyUploader.upload($scope.uploadFileList, $scope.policyNavigator.currentPath).then(function() {
303 $scope.policyNavigator.refresh();
304 Notification.success('Policy Import Complete');
305 $scope.modal('uploadfile', true);
307 var errorMsg = data.result && data.result.error || 'Error Occured while Uploading....';
308 $scope.temp.error = errorMsg;
312 $scope.getQueryParam = function(param) {
314 window.location.search.substr(1).split('&').forEach(function(item) {
315 if (param === item.split('=')[0]) {
316 found = item.split('=')[1];
323 $scope.isWindows = $scope.getQueryParam('server') === 'Windows';
324 $scope.policyNavigator.refresh();