Replace ecomp references
[portal.git] / ecomp-portal-FE-os / client / src / views / search / search.controller.js
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 'use strict';
39 (function () {
40
41     class SearchCtrl {
42         constructor($log, $scope, $cookies, $timeout, userProfileService, sessionService, dashboardService) {
43             $scope.firstName="";
44             $scope.lastName="";
45             
46             function  showHideSearchSnippet() {
47                 
48                 setTimeout(function() {
49                                 jQuery("#mainSearchSnippet").click();
50                                 },500);
51                         
52                         setTimeout(function() {
53                                 jQuery("#mainSearchText").focus();
54                                 },1000);
55             }
56             
57             jQuery("#mainSearchDiv").keyup(function(event){
58                 if(event.keyCode == 13){
59                     // there is a watch on this variable which will trigger the database pull
60                         dashboardService.searchString = jQuery("#mainSearchText").val();
61                         
62                         // opens the popup
63                     var popupDomObj = jQuery("[content='searchSnippet.html']");
64                         if(popupDomObj.length == 0) {
65                                 showHideSearchSnippet();
66                         } else {
67                                 jQuery("#mainSearchSnippet").click();
68                                 showHideSearchSnippet();
69                         }
70                                                 
71                         
72                          
73                 }
74             });
75             
76             
77             
78         }
79         
80         
81     }
82     
83     
84     class SearchSnippetCtrl {
85         constructor($log, $scope, $cookies, $timeout, userProfileService, sessionService, dashboardService,applicationsService, $window, $state) {
86             $scope.firstName="";
87             $scope.lastName="";
88             $scope.goToUrl = goToUrl;
89             $scope.dService = dashboardService;
90             
91             $scope.searchResDialog = false;
92             $scope.searchDialogToggle = function($event){
93                 var keyCode = $event.which || $event.keyCode;
94                 if (keyCode === 13) {
95                         $scope.searchResDialog = true;               
96                         dashboardService.searchString = jQuery("#mainSearchText").val();
97                 }
98                 
99             }
100             
101             window.onclick = function() {
102                         if ($scope.searchResDialog) {
103                                 $scope.searchResDialog = false;
104                                 $scope.$apply();
105                         }
106                 };      
107             function goToUrl (item, type) {
108                 $log.info("goToUrl called")
109                 $log.info(item + "/" + type);
110                 
111                 
112                 if(type == 'intra') {
113                         
114                         var intraSearcLink = "";
115                         var intraSpecSearcLink = intraSearcLink + encodeURIComponent(dashboardService.searchString);
116                         $window.open(intraSpecSearcLink, '_blank');
117                         
118                 } else if (type == 'extra') {
119                         var extraSearcLink = "";
120                         var extraSpecSearcLink = extraSearcLink + encodeURIComponent(dashboardService.searchString);
121                         $window.open(extraSpecSearcLink, '_blank');
122                 }
123
124                 let url = item.target;
125                 let restrictedApp = item.uuid;
126                 let getAccessState =  "root.getAccess"
127                 if (!url) {
128                         
129                         applicationsService.goGetAccessAppName = item.name;
130                         if($state.current.name == getAccessState)
131                                 $state.reload();
132                         else
133                                 $state.go(getAccessState);
134                     //$log.info('No url found for this application, doing nothing..');
135                     return;
136                 }
137                 
138                 if (restrictedApp != "true") {
139                     $window.open(url, '_blank');
140                 } else {
141                         if(item.url=="root.access"){
142                                 $state.go(url);
143                                 var tabContent = { id: new Date(), title: 'Home', url: url };
144                         $cookies.putObject('addTab', tabContent );
145                         } else {
146                         var tabContent = { id: new Date(), title: item.name, url: url };
147                         $cookies.putObject('addTab', tabContent );
148                     }
149                 }
150
151             }
152             
153             function getItems(searchString) {
154                 
155                 var items;
156                 var itemMap = dashboardService.getSearchAllByStringResults(searchString)                
157                  .then(res => {
158                          $scope.items = res;
159                          
160                          
161                  }).catch(err => {
162                          $scope.items = [];
163                      $log.error('Couldnt get search results...', err)
164                  });
165
166             }
167             
168             $scope.$watch('dService.searchString', function(searchString) {
169                 if(searchString != undefined )
170                         getItems(searchString);
171
172             });
173             
174              
175             
176         }
177         
178         
179         
180     }
181     
182     
183
184     SearchCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout','userProfileService', 'sessionService', 'dashboardService'];
185     SearchSnippetCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout','userProfileService', 'sessionService', 'dashboardService','applicationsService', '$window','$state'];
186     angular.module('ecompApp').controller('searchCtrl', SearchCtrl); 
187     angular.module('ecompApp').controller('searchSnippetCtrl', SearchSnippetCtrl);
188     angular.module('ecompApp').directive('searchBox', function() {
189         return {
190             restrict: "E",
191             templateUrl: 'app/views/search/search.tpl.html',
192             link: function(scope, element) {
193                                 
194                 //var iframeId = "#tabframe-" + scope.$parent.tab.title.split(' ').join('-');
195                 // jQuery(iframeId).load(function() {
196                 //        alert("hello");
197                 //    }); //.attr("src",'{{tab.content | trusted}}' ); //src='{{tab.content | trusted}}'
198                 // jQuery(iframeId).attr('src', '{{tab.content | trusted}}');
199                  
200                 //element.childNodes[0].on('load', function() {
201                 //      alert('hello');
202                 //});
203             }
204         }
205     });
206     angular.module( 'ecompApp' ).config( [
207         '$compileProvider',
208         function( $compileProvider )
209         {   
210             $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension|qto):/);
211         }
212     ]);
213
214 })();
215
216