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=========================================================
21 (function(window, angular, $) {
23 angular.module('abs').controller('FileManagerCtrl', [
24 '$scope', '$q', '$window', '$translate', '$cookies', 'fileManagerConfig', 'item', 'fileNavigator', 'fileUploader', 'AdminTabService', 'RolesService', 'Notification', 'PolicyDictionaryService', 'PapUrlService',
25 function($scope, $q, $Window, $translate, $cookies, fileManagerConfig, Item, FileNavigator, FileUploader, AdminTabService, RolesService, Notification, PolicyDictionaryService, PapUrlService ) {
27 $scope.isDisabled = true;
28 $scope.superAdminId = false;
29 $scope.exportPolicyId = false;
30 $scope.importPolicyId = false;
31 $scope.createScopeId = false;
32 $scope.deleteScopeId = false;
33 $scope.renameId = false;
34 $scope.createPolicyId = false;
35 $scope.cloneId = false;
36 $scope.editPolicyId = false;
37 $scope.switchVersionId = false;
38 $scope.describePolicyId = false;
39 $scope.viewPolicyId = false;
40 $scope.deletePolicyId = false;
41 AdminTabService.getData().then(function(data){
43 $scope.data = JSON.parse(j.data);
44 $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
45 if($scope.lockdowndata[0].lockdown == true){
46 $scope.isDisabled = true;
48 $scope.isDisabled = false;
50 console.log($scope.data);
52 console.log("failed");
55 PapUrlService.getPapUrl().then(function(data) {
57 papUrl = config.PAP_URL;
59 PolicyDictionaryService.getDescriptiveDictionaryData(papUrl).then(function(data){
61 $scope.data = JSON.parse(j.data);
62 console.log($scope.data);
63 $scope.descriptiveScopeDictionaryDatas = JSON.parse($scope.data.descriptiveScopeDictionaryDatas);
65 console.log("failed");
68 PolicyDictionaryService.getEcompDictionaryData(papUrl).then(function(data){
70 $scope.data = JSON.parse(j.data);
71 console.log($scope.data);
72 $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
74 console.log("failed");
77 PolicyDictionaryService.getVSCLActionDictionaryData(papUrl).then(function(data){
79 $scope.data = JSON.parse(j.data);
80 console.log($scope.data);
81 $scope.vsclActionDictionaryDatas = JSON.parse($scope.data.vsclActionDictionaryDatas);
83 console.log("failed");
86 PolicyDictionaryService.getVnfTypeDictionaryData(papUrl).then(function(data){
88 $scope.data = JSON.parse(j.data);
89 console.log($scope.data);
90 $scope.vnfTypeDictionaryDatas = JSON.parse($scope.data.vnfTypeDictionaryDatas);
92 console.log("failed");
96 RolesService.getRolesData().then(function (data) {
98 $scope.data = JSON.parse(j.data);
99 console.log($scope.data);
100 $scope.userRolesDatas = JSON.parse($scope.data.userRolesDatas);
101 console.log($scope.userRolesDatas);
102 if($scope.userRolesDatas[0] == 'super-admin'){
103 $scope.superAdminId = true;
104 $scope.exportPolicyId = true;
105 $scope.importPolicyId = true;
106 $scope.createScopeId = true;
107 $scope.deleteScopeId = true;
108 $scope.renameId = true;
109 $scope.createPolicyId = true;
110 $scope.cloneId = true;
111 $scope.editPolicyId = true;
112 $scope.switchVersionId = true;
113 $scope.describePolicyId = true;
114 $scope.viewPolicyId = true;
115 $scope.deletePolicyId = true;
116 }else if($scope.userRolesDatas[0] == 'super-editor' || $scope.userRolesDatas[0] == 'editor'){
117 $scope.exportPolicyId = true;
118 $scope.importPolicyId = true;
119 $scope.cloneId = true;
120 $scope.editPolicyId = true;
121 $scope.createPolicyId = true;
122 $scope.cloneId = true;
123 $scope.editPolicyId = true;
124 $scope.switchVersionId = true;
125 $scope.describePolicyId = true;
126 $scope.viewPolicyId = true;
127 $scope.deletePolicyId = true;
128 }else if($scope.userRolesDatas[0] == 'super-guest' || $scope.userRolesDatas[0] == 'guest'){
129 $scope.describePolicyId = true;
130 $scope.viewPolicyId = true;
131 }else if($scope.userRolesDatas[0] == 'admin'){
132 $scope.exportPolicyId = true;
133 $scope.importPolicyId = true;
134 $scope.createScopeId = true;
135 $scope.renameId = true;
136 $scope.createPolicyId = true;
137 $scope.cloneId = true;
138 $scope.editPolicyId = true;
139 $scope.switchVersionId = true;
140 $scope.describePolicyId = true;
141 $scope.viewPolicyId = true;
142 $scope.deletePolicyId = true;
144 }, function (error) {
145 console.log("failed");
148 $scope.config = fileManagerConfig;
149 $scope.reverse = false;
150 $scope.predicate = ['model.type', 'model.name'];
151 $scope.order = function(predicate) {
152 $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false;
153 $scope.predicate[1] = predicate;
157 $scope.temp = new Item();
158 $scope.fileNavigator = new FileNavigator();
159 $scope.fileUploader = FileUploader;
160 $scope.uploadFileList = [];
161 $scope.viewTemplate = $cookies.viewTemplate || 'main-table.html';
163 $scope.setTemplate = function(name) {
164 $scope.viewTemplate = $cookies.viewTemplate = name;
167 $scope.changeLanguage = function (locale) {
169 return $translate.use($cookies.language = locale);
171 $translate.use($cookies.language || fileManagerConfig.defaultLang);
174 $scope.touch = function(item) {
175 item = item instanceof Item ? item : new Item();
180 $scope.smartClick = function(item) {
181 if (item.isFolder()) {
182 return $scope.fileNavigator.folderClick(item);
184 if (item.isImage()) {
185 return $scope.openImagePreview(item);
187 if (item.isEditable()) {
188 return $scope.openEditItem(item);
192 $scope.openImagePreview = function(item) {
193 item.inprocess = true;
194 $scope.modal('imagepreview')
195 .find('#imagepreview-target')
196 .attr('src', item.getUrl(true))
197 .unbind('load error')
198 .on('load error', function() {
199 item.inprocess = false;
202 return $scope.touch(item);
205 $scope.openEditItem = function(item) {
207 $scope.modal('createNewPolicy');
208 return $scope.touch(item);
211 $scope.modal = function(id, hide) {
212 return $('#' + id).modal(hide ? 'hide' : 'show');
215 $scope.isInThisPath = function(path) {
216 var currentPath = $scope.fileNavigator.currentPath.join('/');
217 return currentPath.indexOf(path) !== -1;
220 $scope.edit = function(item) {
221 item.edit().then(function() {
222 $scope.modal('createNewPolicy', true);
226 $scope.createNewPolicy = function(item) {
227 item.createNewPolicy().then(function() {
228 $scope.modal('createNewPolicy', true);
232 $scope.watch = function(item){
233 var uuu = "watchPolicy";
234 var data = {name : item.model.name,
235 path : item.model.path};
236 var postData={watchData: data};
241 contentType: 'application/json',
242 data: JSON.stringify(postData),
243 success : function(data){
244 $scope.$apply(function(){
245 $scope.watchData=data.watchData;});
246 Notification.success($scope.watchData);
247 console.log($scope.watchData);
249 error : function(data){
250 alert("Error while saving.");
255 $scope.Search = function(search){
256 var deferred = $q.defer();
257 var uuu = "searchPolicy";
258 var postData = {searchdata : search};
263 contentType: 'application/json',
264 data: JSON.stringify(postData),
265 success : function(data){
266 $scope.$apply(function(){
267 $scope.searchdata=data.result;});
268 if($scope.searchdata[0].error != undefined){
269 Notification.info($scope.searchdata[0].error);
272 $scope.data = JSON.stringify(data.result);
273 $scope.searchDatas = JSON.parse($scope.data);
274 var searchString = "Policies List" + "<br>";
276 for(i = 0 ; i < $scope.searchDatas.length; i++){
277 searchString += $scope.searchDatas[i].name + ".xml" + "<br>";
279 var myWindow = window.open("", "MsgWindow", "width=500,height=500");
280 myWindow.document.write("<p>Search List</p>");
281 myWindow.document.write("<p>"+searchString+"</p>");
284 error : function(data){
285 alert("Error while Searching.");
291 $scope.describePolicy = function(item){
292 item.describePolicy().then(function(){
293 $scope.modal('describePolicy', true);
297 $scope.exportPolicy = function(item){
298 item.exportPolicy().then(function(){
299 $scope.modal('exportPolicy', true);
303 $scope.switchVersion = function(item){
304 if ($scope.fileNavigator.fileNameExists(item.tempModel.content.activeVersion)) {
305 item.error = $translate.instant('error_invalid_filename');
308 item.getSwitchVersionContent().then(function(){
309 $scope.fileNavigator.refresh();
310 $scope.modal('switchVersion', true);
315 $scope.viewPolicy = function(item){
316 item.viewPolicy().then(function(){
317 $scope.modal('createNewPolicy', true);
321 $scope.copy = function(item) {
322 var samePath = item.tempModel.path.join() === item.model.path.join();
323 if (samePath && $scope.fileNavigator.fileNameExists(item.tempModel.name)) {
324 item.error = $translate.instant('error_invalid_filename');
327 item.copy().then(function() {
328 $scope.fileNavigator.refresh();
329 $scope.modal('copy', true);
333 $scope.remove = function(item) {
334 item.remove().then(function() {
335 $scope.fileNavigator.refresh();
336 $scope.modal('delete', true);
340 $scope.removePolicy = function(item) {
341 item.removePolicy().then(function() {
342 $scope.fileNavigator.refresh();
343 $scope.modal('deletePolicy', true);
347 $scope.rename = function(item) {
348 var samePath = item.tempModel.path.join() === item.model.path.join();
349 if (samePath && $scope.fileNavigator.fileNameExists(item.tempModel.name)) {
350 item.error = $translate.instant('error_invalid_filename');
353 item.rename().then(function() {
354 $scope.fileNavigator.refresh();
355 $scope.modal('rename', true);
359 $scope.move = function(item) {
360 var samePath = item.tempModel.path.join() === item.model.path.join();
361 if (samePath && $scope.fileNavigator.fileNameExists(item.tempModel.name)) {
362 item.error = $translate.instant('error_invalid_filename');
365 item.move().then(function() {
366 $scope.fileNavigator.refresh();
367 $scope.modal('move', true);
371 $scope.createFolder = function(item) {
372 var name = item.tempModel.name && item.tempModel.name.trim();
373 item.tempModel.type = 'dir';
374 item.tempModel.path = $scope.fileNavigator.currentPath;
375 if (name && !$scope.fileNavigator.fileNameExists(name)) {
376 item.createFolder().then(function() {
377 $scope.fileNavigator.refresh();
378 $scope.modal('newfolder', true);
381 item.error = $translate.instant('error_invalid_filename');
386 $scope.subScopeFolder = function(item) {
387 var name = item.tempModel.name +"\\" + item.tempModel.subScopename && item.tempModel.name.trim() + "\\"+item.tempModel.subScopename.trim() ;
388 item.tempModel.type = 'dir';
389 item.tempModel.path = $scope.fileNavigator.currentPath;
390 if (name && !$scope.fileNavigator.fileNameExists(name)) {
391 item.getScopeContent().then(function() {
392 $scope.fileNavigator.refresh();
393 $scope.modal('addSubScope', true);
396 item.error = $translate.instant('error_invalid_filename');
401 $scope.uploadFiles = function() {
402 $scope.fileUploader.upload($scope.uploadFileList, $scope.fileNavigator.currentPath).then(function() {
403 $scope.fileNavigator.refresh();
404 $scope.modal('uploadfile', true);
406 var errorMsg = data.result && data.result.error || $translate.instant('error_uploading_files');
407 $scope.temp.error = errorMsg;
411 $scope.getQueryParam = function(param) {
413 window.location.search.substr(1).split('&').forEach(function(item) {
414 if (param === item.split('=')[0]) {
415 found = item.split('=')[1];
422 $scope.changeLanguage($scope.getQueryParam('lang'));
423 $scope.isWindows = $scope.getQueryParam('server') === 'Windows';
424 $scope.fileNavigator.refresh();
426 })(window, angular, jQuery);