2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 2019 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;
47 console.log($scope.data);
49 console.log("failed");
52 PolicyAppService.getData('getDictionary/get_DescriptiveScopeByName').then(function(data) {
54 $scope.data = JSON.parse(j.data);
55 console.log($scope.data);
56 $scope.descriptiveScopeDictionaryDatas = JSON.parse($scope.data.descriptiveScopeDictionaryDatas);
58 console.log("failed");
61 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function(data) {
63 $scope.data = JSON.parse(j.data);
64 console.log($scope.data);
65 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
67 console.log("failed");
70 PolicyAppService.getData('getDictionary/get_VSCLActionDataByName').then(function(data) {
72 $scope.data = JSON.parse(j.data);
73 console.log($scope.data);
74 $scope.vsclActionDictionaryDatas = JSON.parse($scope.data.vsclActionDictionaryDatas);
76 console.log("failed");
79 PolicyAppService.getData('getDictionary/get_VNFTypeDataByName').then(function(data) {
81 $scope.data = JSON.parse(j.data);
82 console.log($scope.data);
83 $scope.vnfTypeDictionaryDatas = JSON.parse($scope.data.vnfTypeDictionaryDatas);
85 console.log("failed");
89 PolicyAppService.getData('get_UserRolesData').then(function (data) {
91 $scope.data = JSON.parse(j.data);
92 console.log($scope.data);
93 $scope.userRolesDatas = JSON.parse($scope.data.userRolesDatas);
94 console.log($scope.userRolesDatas);
95 if ($scope.userRolesDatas[0] == 'super-admin') {
96 $scope.superAdminId = true;
97 $scope.exportPolicyId = true;
98 $scope.importPolicyId = true;
99 } else if ($scope.userRolesDatas[0] == 'super-editor' || $scope.userRolesDatas[0] == 'editor' || $scope.userRolesDatas[0] == 'admin') {
100 $scope.exportPolicyId = true;
101 $scope.importPolicyId = true;
103 }, function (error) {
104 console.log("failed");
107 $scope.config = policyManagerConfig;
108 $scope.reverse = false;
109 $scope.predicate = ['model.type', 'model.name'];
110 $scope.order = function(predicate) {
111 $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false;
112 $scope.predicate[1] = predicate;
116 $scope.temp = new Item();
117 $scope.policyNavigator = new PolicyNavigator();
118 $scope.policyUploader = PolicyUploader;
119 $scope.uploadFileList = [];
121 $scope.setTemplate = function(name) {
122 $scope.viewTemplate = $cookies.viewTemplate = name;
125 $scope.touch = function(item) {
126 item = item instanceof Item ? item : new Item();
129 $scope.createScopeId = false;
130 $scope.deleteScopeId = false;
131 $scope.renameId = false;
132 $scope.createPolicyId = false;
133 $scope.cloneId = false;
134 $scope.editPolicyId = false;
135 $scope.switchVersionId = false;
136 $scope.describePolicyId = false;
137 $scope.viewPolicyId = false;
138 $scope.deletePolicyId = false;
139 if ($scope.temp.model.roleType == 'super-admin') {
140 $scope.createScopeId = true;
141 $scope.deleteScopeId = true;
142 $scope.renameId = true;
143 $scope.createPolicyId = true;
144 $scope.cloneId = true;
145 $scope.editPolicyId = true;
146 $scope.switchVersionId = true;
147 $scope.describePolicyId = true;
148 $scope.viewPolicyId = true;
149 $scope.deletePolicyId = true;
150 } else if ($scope.temp.model.roleType == 'super-editor' || $scope.temp.model.roleType == 'editor') {
151 $scope.cloneId = true;
152 $scope.editPolicyId = true;
153 $scope.createPolicyId = true;
154 $scope.switchVersionId = true;
155 $scope.describePolicyId = true;
156 $scope.viewPolicyId = true;
157 $scope.deletePolicyId = true;
158 } else if ($scope.temp.model.roleType == 'super-guest' || $scope.temp.model.roleType == 'guest') {
159 $scope.describePolicyId = true;
160 $scope.viewPolicyId = true;
161 } else if ($scope.temp.model.roleType == 'admin') {
162 $scope.createScopeId = true;
163 $scope.renameId = true;
164 $scope.createPolicyId = true;
165 $scope.cloneId = true;
166 $scope.editPolicyId = true;
167 $scope.switchVersionId = true;
168 $scope.describePolicyId = true;
169 $scope.viewPolicyId = true;
170 $scope.deletePolicyId = true;
174 $scope.smartClick = function(item) {
175 if (item.isFolder()) {
176 return $scope.policyNavigator.folderClick(item);
178 if (item.isEditable()) {
179 return $scope.openEditItem(item);
183 $scope.openEditItem = function(item) {
185 $scope.modal('createNewPolicy');
186 return $scope.touch(item);
189 $scope.modal = function(id, hide) {
190 return $('#' + id).modal(hide ? 'hide' : 'show');
193 $scope.isInThisPath = function(path) {
194 var currentPath = $scope.policyNavigator.currentPath.join('/');
195 return currentPath.indexOf(path) !== -1;
198 $scope.watchPolicy = function(item) {
199 var uuu = "watchPolicy";
200 var data = {name : item.model.name,
201 path : item.model.path};
202 var postData={watchData: data};
207 contentType: 'application/json',
208 data: JSON.stringify(postData),
209 success : function(data) {
210 $scope.$apply(function() {
211 $scope.watchData=data.watchData;});
212 Notification.success($scope.watchData);
213 console.log($scope.watchData);
215 error : function(data) {
216 Notification.error("Error while saving.");
221 $scope.refresh = function() {
222 $scope.policyNavigator.refresh();
225 $scope.switchVersion = function(item) {
226 if ($scope.policyNavigator.fileNameExists(item.tempModel.content.activeVersion)) {
227 item.error = 'Invalid filename or already exists, specify another name';
230 item.getSwitchVersionContent().then(function(){
231 $scope.policyNavigator.refresh();
232 $scope.modal('switchVersion', true);
236 $scope.copy = function(item) {
237 var samePath = item.tempModel.path.join() === item.model.path.join();
238 if (samePath && $scope.policyNavigator.fileNameExists(item.tempModel.name)) {
239 item.error = 'Invalid filename or already exists, specify another name';
242 item.copy().then(function() {
243 $scope.policyNavigator.refresh();
244 $scope.modal('copy', true);
248 $scope.remove = function(item) {
249 item.remove().then(function() {
250 $scope.policyNavigator.refresh();
251 $scope.modal('delete', true);
255 $scope.removePolicy = function(item) {
256 item.removePolicy().then(function() {
257 $scope.policyNavigator.refresh();
258 $scope.modal('deletePolicy', true);
262 $scope.rename = function(item) {
263 var samePath = item.tempModel.path.join() === item.model.path.join();
264 if (samePath && $scope.policyNavigator.fileNameExists(item.tempModel.name)) {
265 item.error = 'Invalid filename or already exists, specify another name';
268 item.rename().then(function() {
269 $scope.policyNavigator.refresh();
270 $scope.modal('rename', true);
274 $scope.move = function(item) {
275 var samePath = item.tempModel.path.join() === item.model.path.join();
276 if (samePath && $scope.policyNavigator.fileNameExists(item.tempModel.name)) {
277 item.error = 'Invalid filename or already exists, specify another name';
280 item.move().then(function() {
281 $scope.policyNavigator.refresh();
282 $scope.modal('move', true);
286 $scope.createFolder = function(item) {
287 var name = item.tempModel.name && item.tempModel.name.trim();
288 item.tempModel.type = 'dir';
289 item.tempModel.path = $scope.policyNavigator.currentPath;
290 if (name && !$scope.policyNavigator.fileNameExists(name)) {
291 item.createFolder().then(function() {
292 $scope.policyNavigator.refresh();
293 $scope.modal('newfolder', true);
296 item.error = 'Invalid filename or already exists, specify another name';
301 $scope.subScopeFolder = function(item) {
302 var name = item.tempModel.name +"\\" + item.tempModel.subScopename && item.tempModel.name.trim() + "\\"+item.tempModel.subScopename.trim() ;
303 item.tempModel.type = 'dir';
304 item.tempModel.path = $scope.policyNavigator.currentPath;
305 if (name && !$scope.policyNavigator.fileNameExists(name)) {
306 item.getScopeContent().then(function() {
307 $scope.policyNavigator.refresh();
308 $scope.modal('addSubScope', true);
311 item.error = 'Invalid filename or already exists, specify another name';
316 $scope.closefunction = function(fianlPath) {
317 $scope.policyNavigator.policyrefresh(fianlPath);
320 $scope.uploadFiles = function() {
321 $scope.policyUploader.upload($scope.uploadFileList, $scope.policyNavigator.currentPath).then(function() {
322 $scope.policyNavigator.refresh();
323 $scope.modal('uploadfile', true);
325 var errorMsg = data.result && data.result.error || 'Error Occured while Uploading....';
326 $scope.temp.error = errorMsg;
330 $scope.getQueryParam = function(param) {
332 window.location.search.substr(1).split('&').forEach(function(item) {
333 if (param === item.split('=')[0]) {
334 found = item.split('=')[1];
341 $scope.isWindows = $scope.getQueryParam('server') === 'Windows';
342 $scope.policyNavigator.refresh();