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('PolicySearchController', [
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.createPolicyId = true;
98 $scope.editPolicyId = true;
99 $scope.describePolicyId = true;
100 $scope.viewPolicyId = true;
101 }else if($scope.userRolesDatas[0] == 'super-editor' || $scope.userRolesDatas[0] == 'editor' || $scope.userRolesDatas[0] == 'admin'){
102 $scope.editPolicyId = true;
103 $scope.createPolicyId = true;
104 $scope.describePolicyId = true;
105 $scope.viewPolicyId = true;
106 }else if($scope.userRolesDatas[0] == 'super-guest' || $scope.userRolesDatas[0] == 'guest'){
107 $scope.describePolicyId = true;
108 $scope.viewPolicyId = true;
110 }, function (error) {
111 console.log("failed");
114 $scope.config = policyManagerConfig;
115 $scope.reverse = false;
116 $scope.predicate = ['model.type', 'model.name'];
117 $scope.order = function(predicate) {
118 $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false;
119 $scope.predicate[1] = predicate;
123 $scope.temp = new Item();
124 $scope.policyNavigator = new PolicyNavigator();
126 $scope.setTemplate = function(name) {
127 $scope.viewTemplate = $cookies.viewTemplate = name;
130 $scope.touch = function(item) {
131 item = item instanceof Item ? item : new Item();
136 $scope.smartClick = function(item) {
137 if (item.isFolder()) {
138 return $scope.policyNavigator.folderClick(item);
140 if (item.isEditable()) {
141 return $scope.openEditItem(item);
145 $scope.openEditItem = function(item) {
147 $scope.modal('createNewPolicy');
148 return $scope.touch(item);
151 $scope.modal = function(id, hide) {
152 return $('#' + id).modal(hide ? 'hide' : 'show');
155 $scope.isInThisPath = function(path) {
156 var currentPath = $scope.policyNavigator.currentPath.join('/');
157 return currentPath.indexOf(path) !== -1;
160 $scope.searchPolicy = function(searchContent){
161 var deferred = $q.defer();
162 var uuu = "searchPolicy";
163 var postData = {searchdata : searchContent};
168 contentType: 'application/json',
169 data: JSON.stringify(postData),
170 success : function(data){
171 $scope.$apply(function(){
172 var searchdata = data.result;
173 if(searchdata.length > 0){
174 if(searchdata[0] == "Elastic Search Server is down"){
175 alert("Elastic Search Server is down.");
177 $scope.policyNavigator.searchrefresh(searchdata);
180 Notification.info("No Matches Found with your Search");
184 error : function(data){
185 alert("Error while Searching.");
190 $scope.refresh = function(searchData){
191 $scope.policyNavigator.searchrefresh(null);
194 $scope.getQueryParam = function(param) {
196 window.location.search.substr(1).split('&').forEach(function(item) {
197 if (param === item.split('=')[0]) {
198 found = item.split('=')[1];
205 $scope.isWindows = $scope.getQueryParam('server') === 'Windows';
206 $scope.policyNavigator.searchrefresh(null);
207 $scope.policyNavigator.setSearchModalActiveStatus();