Update css file name in conf.py
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / policy-models / Editor / js / controllers / policySearchManager.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
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 ) {
23         
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){
39         var j = 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;
44         }else{
45             $scope.isDisabled = false;
46         }
47     },function(error){
48     });
49     
50     PolicyAppService.getData('getDictionary/get_DescriptiveScopeByName').then(function(data){
51         var j = data;
52         $scope.data = JSON.parse(j.data);
53         $scope.descriptiveScopeDictionaryDatas = JSON.parse($scope.data.descriptiveScopeDictionaryDatas);    
54     });
55
56     PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function(data){
57         var j = data;
58         $scope.data = JSON.parse(j.data);
59         $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);    
60     });
61
62     PolicyAppService.getData('getDictionary/get_VSCLActionDataByName').then(function(data){
63         var j = data;
64         $scope.data = JSON.parse(j.data);
65         $scope.vsclActionDictionaryDatas = JSON.parse($scope.data.vsclActionDictionaryDatas);    
66     });
67
68     PolicyAppService.getData('getDictionary/get_VNFTypeDataByName').then(function(data){
69         var j = data;
70         $scope.data = JSON.parse(j.data);
71         $scope.vnfTypeDictionaryDatas = JSON.parse($scope.data.vnfTypeDictionaryDatas);    
72     });
73
74     
75     PolicyAppService.getData('get_UserRolesData').then(function (data) {
76         var j = 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;
93         }
94     });
95     
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;
102     };
103
104     $scope.query = '';
105     $scope.temp = new Item();
106     $scope.policyNavigator = new PolicyNavigator();
107
108     $scope.setTemplate = function(name) {
109     $scope.viewTemplate = $cookies.viewTemplate = name;
110     };
111
112     $scope.touch = function(item) {
113     item = item instanceof Item ? item : new Item();
114     item.revert();
115     $scope.temp = item;
116     };
117
118     $scope.smartClick = function(item) {
119     if (item.isFolder()) {
120     return $scope.policyNavigator.folderClick(item);
121     }
122     if (item.isEditable()) {
123     return $scope.openEditItem(item);
124     }
125     };
126
127     $scope.openEditItem = function(item) {
128     item.getContent();
129     $scope.modal('createNewPolicy');
130     return $scope.touch(item);
131     };
132
133     $scope.modal = function(id, hide) {
134     return $('#' + id).modal(hide ? 'hide' : 'show');
135     };
136
137     $scope.isInThisPath = function(path) {
138     var currentPath = $scope.policyNavigator.currentPath.join('/');
139     return currentPath.indexOf(path) !== -1;
140     };
141        
142     $scope.searchPolicy = function(searchContent){
143         if(searchContent != undefined){
144             var uuu = "searchPolicy";
145             var postData = {searchdata : searchContent};
146             $.ajax({
147                 type : 'POST',
148                 url : uuu,
149                 dataType: 'json',
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]);
158                             }else{
159                                 $scope.policyNavigator.searchrefresh(searchdata);  
160                             }
161                         }else{
162                             Notification.info("No Matches Found with your Search");
163                         }
164                     });     
165                 },
166                 error : function(data){
167                     Notification.error("Error while Searching.");
168                 }
169             });
170         }else{
171             Notification.error("No data has been entered or selected to search");
172         }
173     };
174        
175        $scope.refresh = function(searchData){
176            $scope.policyNavigator.searchrefresh(null);
177        };
178      
179     $scope.getQueryParam = function(param) {
180     var found;
181     window.location.search.substr(1).split('&').forEach(function(item) {
182     if (param ===  item.split('=')[0]) {
183         found = item.split('=')[1];
184         return false;
185     }
186     });
187     return found;
188     };
189
190     $scope.isWindows = $scope.getQueryParam('server') === 'Windows';
191     $scope.policyNavigator.searchrefresh(null);
192     $scope.policyNavigator.setSearchModalActiveStatus();
193     }]);