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('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;
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.createPolicyId = true;
82 $scope.editPolicyId = true;
83 $scope.describePolicyId = true;
84 $scope.viewPolicyId = true;
85 }else if($scope.userRolesDatas[0] == 'super-editor' || $scope.userRolesDatas[0] == 'editor' || $scope.userRolesDatas[0] == 'admin'){
86 $scope.editPolicyId = true;
87 $scope.createPolicyId = true;
88 $scope.describePolicyId = true;
89 $scope.viewPolicyId = true;
90 }else if($scope.userRolesDatas[0] == 'super-guest' || $scope.userRolesDatas[0] == 'guest'){
91 $scope.describePolicyId = true;
92 $scope.viewPolicyId = true;
96 $scope.config = policyManagerConfig;
97 $scope.reverse = false;
98 $scope.predicate = ['model.type', 'model.name'];
99 $scope.order = function(predicate) {
100 $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false;
101 $scope.predicate[1] = predicate;
105 $scope.temp = new Item();
106 $scope.policyNavigator = new PolicyNavigator();
108 $scope.setTemplate = function(name) {
109 $scope.viewTemplate = $cookies.viewTemplate = name;
112 $scope.touch = function(item) {
113 item = item instanceof Item ? item : new Item();
118 $scope.smartClick = function(item) {
119 if (item.isFolder()) {
120 return $scope.policyNavigator.folderClick(item);
122 if (item.isEditable()) {
123 return $scope.openEditItem(item);
127 $scope.openEditItem = function(item) {
129 $scope.modal('createNewPolicy');
130 return $scope.touch(item);
133 $scope.modal = function(id, hide) {
134 return $('#' + id).modal(hide ? 'hide' : 'show');
137 $scope.isInThisPath = function(path) {
138 var currentPath = $scope.policyNavigator.currentPath.join('/');
139 return currentPath.indexOf(path) !== -1;
142 $scope.searchPolicy = function(searchContent){
143 if(searchContent != undefined){
144 var uuu = "searchPolicy";
145 var postData = {searchdata : searchContent};
150 contentType: 'application/json',
151 data: JSON.stringify(postData),
152 success : function(data){
153 $scope.$apply(function(){
154 var searchdata = data.result;
155 if(searchdata.length > 0){
156 if(searchdata[0] == "Exception"){
157 Notification.error(searchdata[1]);
159 $scope.policyNavigator.searchrefresh(searchdata);
162 Notification.info("No Matches Found with your Search");
166 error : function(data){
167 Notification.error("Error while Searching.");
171 Notification.error("No data has been entered or selected to search");
175 $scope.refresh = function(searchData){
176 $scope.policyNavigator.searchrefresh(null);
179 $scope.getQueryParam = function(param) {
181 window.location.search.substr(1).split('&').forEach(function(item) {
182 if (param === item.split('=')[0]) {
183 found = item.split('=')[1];
190 $scope.isWindows = $scope.getQueryParam('server') === 'Windows';
191 $scope.policyNavigator.searchrefresh(null);
192 $scope.policyNavigator.setSearchModalActiveStatus();