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('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 $scope.createScopeId = true;
100 $scope.deleteScopeId = true;
101 $scope.renameId = true;
102 $scope.createPolicyId = true;
103 $scope.cloneId = true;
104 $scope.editPolicyId = true;
105 $scope.switchVersionId = true;
106 $scope.describePolicyId = true;
107 $scope.viewPolicyId = true;
108 $scope.deletePolicyId = true;
109 }else if($scope.userRolesDatas[0] == 'super-editor' || $scope.userRolesDatas[0] == 'editor'){
110 $scope.exportPolicyId = true;
111 $scope.importPolicyId = true;
112 $scope.cloneId = true;
113 $scope.editPolicyId = true;
114 $scope.createPolicyId = true;
115 $scope.cloneId = true;
116 $scope.editPolicyId = true;
117 $scope.switchVersionId = true;
118 $scope.describePolicyId = true;
119 $scope.viewPolicyId = true;
120 $scope.deletePolicyId = true;
121 }else if($scope.userRolesDatas[0] == 'super-guest' || $scope.userRolesDatas[0] == 'guest'){
122 $scope.describePolicyId = true;
123 $scope.viewPolicyId = true;
124 }else if($scope.userRolesDatas[0] == 'admin'){
125 $scope.exportPolicyId = true;
126 $scope.importPolicyId = true;
127 $scope.createScopeId = true;
128 $scope.renameId = true;
129 $scope.createPolicyId = true;
130 $scope.cloneId = true;
131 $scope.editPolicyId = true;
132 $scope.switchVersionId = true;
133 $scope.describePolicyId = true;
134 $scope.viewPolicyId = true;
135 $scope.deletePolicyId = true;
137 }, function (error) {
138 console.log("failed");
141 $scope.config = policyManagerConfig;
142 $scope.reverse = false;
143 $scope.predicate = ['model.type', 'model.name'];
144 $scope.order = function(predicate) {
145 $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false;
146 $scope.predicate[1] = predicate;
150 $scope.temp = new Item();
151 $scope.policyNavigator = new PolicyNavigator();
152 $scope.policyUploader = PolicyUploader;
153 $scope.uploadFileList = [];
155 $scope.setTemplate = function(name) {
156 $scope.viewTemplate = $cookies.viewTemplate = name;
159 $scope.touch = function(item) {
160 item = item instanceof Item ? item : new Item();
165 $scope.smartClick = function(item) {
166 if (item.isFolder()) {
167 return $scope.policyNavigator.folderClick(item);
169 if (item.isEditable()) {
170 return $scope.openEditItem(item);
174 $scope.openEditItem = function(item) {
176 $scope.modal('createNewPolicy');
177 return $scope.touch(item);
180 $scope.modal = function(id, hide) {
181 return $('#' + id).modal(hide ? 'hide' : 'show');
184 $scope.isInThisPath = function(path) {
185 var currentPath = $scope.policyNavigator.currentPath.join('/');
186 return currentPath.indexOf(path) !== -1;
189 $scope.watchPolicy = function(item){
190 var uuu = "watchPolicy";
191 var data = {name : item.model.name,
192 path : item.model.path};
193 var postData={watchData: data};
198 contentType: 'application/json',
199 data: JSON.stringify(postData),
200 success : function(data){
201 $scope.$apply(function(){
202 $scope.watchData=data.watchData;});
203 Notification.success($scope.watchData);
204 console.log($scope.watchData);
206 error : function(data){
207 alert("Error while saving.");
213 $scope.refresh = function(){
214 $scope.policyNavigator.refresh();
217 $scope.switchVersion = function(item){
218 if ($scope.policyNavigator.fileNameExists(item.tempModel.content.activeVersion)) {
219 item.error = 'Invalid filename or already exists, specify another name';
222 item.getSwitchVersionContent().then(function(){
223 $scope.policyNavigator.refresh();
224 $scope.modal('switchVersion', true);
228 $scope.copy = function(item) {
229 var samePath = item.tempModel.path.join() === item.model.path.join();
230 if (samePath && $scope.policyNavigator.fileNameExists(item.tempModel.name)) {
231 item.error = 'Invalid filename or already exists, specify another name';
234 item.copy().then(function() {
235 $scope.policyNavigator.refresh();
236 $scope.modal('copy', true);
240 $scope.remove = function(item) {
241 item.remove().then(function() {
242 $scope.policyNavigator.refresh();
243 $scope.modal('delete', true);
247 $scope.removePolicy = function(item) {
248 item.removePolicy().then(function() {
249 $scope.policyNavigator.refresh();
250 $scope.modal('deletePolicy', true);
254 $scope.rename = function(item) {
255 var samePath = item.tempModel.path.join() === item.model.path.join();
256 if (samePath && $scope.policyNavigator.fileNameExists(item.tempModel.name)) {
257 item.error = 'Invalid filename or already exists, specify another name';
260 item.rename().then(function() {
261 $scope.policyNavigator.refresh();
262 $scope.modal('rename', true);
266 $scope.move = function(item) {
267 var samePath = item.tempModel.path.join() === item.model.path.join();
268 if (samePath && $scope.policyNavigator.fileNameExists(item.tempModel.name)) {
269 item.error = 'Invalid filename or already exists, specify another name';
272 item.move().then(function() {
273 $scope.policyNavigator.refresh();
274 $scope.modal('move', true);
278 $scope.createFolder = function(item) {
279 var name = item.tempModel.name && item.tempModel.name.trim();
280 item.tempModel.type = 'dir';
281 item.tempModel.path = $scope.policyNavigator.currentPath;
282 if (name && !$scope.policyNavigator.fileNameExists(name)) {
283 item.createFolder().then(function() {
284 $scope.policyNavigator.refresh();
285 $scope.modal('newfolder', true);
288 item.error = 'Invalid filename or already exists, specify another name';
293 $scope.subScopeFolder = function(item) {
294 var name = item.tempModel.name +"\\" + item.tempModel.subScopename && item.tempModel.name.trim() + "\\"+item.tempModel.subScopename.trim() ;
295 item.tempModel.type = 'dir';
296 item.tempModel.path = $scope.policyNavigator.currentPath;
297 if (name && !$scope.policyNavigator.fileNameExists(name)) {
298 item.getScopeContent().then(function() {
299 $scope.policyNavigator.refresh();
300 $scope.modal('addSubScope', true);
303 item.error = 'Invalid filename or already exists, specify another name';
308 $scope.closefunction = function(fianlPath){
309 $scope.policyNavigator.policyrefresh(fianlPath);
312 $scope.uploadFiles = function() {
313 $scope.policyUploader.upload($scope.uploadFileList, $scope.policyNavigator.currentPath).then(function() {
314 $scope.policyNavigator.refresh();
315 $scope.modal('uploadfile', true);
317 var errorMsg = data.result && data.result.error || 'Error Occured while Uploading....';
318 $scope.temp.error = errorMsg;
322 $scope.getQueryParam = function(param) {
324 window.location.search.substr(1).split('&').forEach(function(item) {
325 if (param === item.split('=')[0]) {
326 found = item.split('=')[1];
333 $scope.isWindows = $scope.getQueryParam('server') === 'Windows';
334 $scope.policyNavigator.refresh();