nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / views / search / search.controller.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
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  * ================================================================================
19  */
20 'use strict';
21 (function () {
22
23     class SearchCtrl {
24         constructor($log, $scope, $cookies, $timeout, userProfileService, sessionService, dashboardService) {
25             $scope.firstName="";
26             $scope.lastName="";
27             
28             function  showHideSearchSnippet() {
29                 
30                 setTimeout(function() {
31                                 jQuery("#mainSearchSnippet").click();
32                                 },500);
33                         
34                         setTimeout(function() {
35                                 jQuery("#mainSearchText").focus();
36                                 },1000);
37             }
38             
39             jQuery("#mainSearchDiv").keyup(function(event){
40                 if(event.keyCode == 13){
41                     // there is a watch on this variable which will trigger the database pull
42                         dashboardService.searchString = jQuery("#mainSearchText").val();
43                         
44                         // opens the popup
45                     var popupDomObj = jQuery("[content='searchSnippet.html']");
46                         if(popupDomObj.length == 0) {
47                                 showHideSearchSnippet();
48                         } else {
49                                 jQuery("#mainSearchSnippet").click();
50                                 showHideSearchSnippet();
51                         }
52                                                 
53                         
54                          
55                 }
56             });
57             
58             
59             
60         }
61         
62         
63     }
64     
65     
66     class SearchSnippetCtrl {
67         constructor($log, $scope, $cookies, $timeout, userProfileService, sessionService, dashboardService,applicationsService, $window, $state) {
68             $scope.firstName="";
69             $scope.lastName="";
70             $scope.goToUrl = goToUrl;
71             $scope.dService = dashboardService;
72
73             
74             
75             function goToUrl (item, type) {
76                 $log.info("goToUrl called")
77                 $log.info(item + "/" + type);
78                 
79                 
80                 if(type == 'intra') {
81                         
82                         var intraSearcLink = "http://to_do_link.com";
83                         var intraSpecSearcLink = intraSearcLink + encodeURIComponent(dashboardService.searchString);
84                         $window.open(intraSpecSearcLink, '_blank');
85                         
86                 } else if (type == 'extra') {
87                         var extraSearcLink = "https://to_do_link.com";
88                         var extraSpecSearcLink = extraSearcLink + encodeURIComponent(dashboardService.searchString);
89                         $window.open(extraSpecSearcLink, '_blank');
90                 }
91
92                 let url = item.target;
93                 let restrictedApp = item.uuid;
94                 let getAccessState =  "root.getAccess"
95                 if (!url) {
96                         
97                         applicationsService.goGetAccessAppName = item.name;
98                         if($state.current.name == getAccessState)
99                                 $state.reload();
100                         else
101                                 $state.go(getAccessState);
102                     //$log.info('No url found for this application, doing nothing..');
103                     return;
104                 }
105                 
106                 if (restrictedApp != "true") {
107                     $window.open(url, '_blank');
108                 } else {
109                         if(item.url=="root.access"){
110                                 $state.go(url);
111                                 var tabContent = { id: new Date(), title: 'Home', url: url };
112                         $cookies.putObject('addTab', tabContent );
113                         } else {
114                         var tabContent = { id: new Date(), title: item.name, url: url };
115                         $cookies.putObject('addTab', tabContent );
116                     }
117                 }
118
119             }
120             
121             function getItems(searchString) {
122                 
123                 var items;
124                 var itemMap = dashboardService.getSearchAllByStringResults(searchString)                
125                  .then(res => {
126                          $scope.items = res;
127                          
128                          
129                  }).catch(err => {
130                          $scope.items = [];
131                      $log.error('Couldnt get search results...', err)
132                  });
133
134             }
135             
136             $scope.$watch('dService.searchString', function(searchString) {
137                 if(searchString != undefined )
138                         getItems(searchString);
139
140             });
141             
142              
143             
144         }
145         
146         
147         
148     }
149     
150     
151
152     SearchCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout','userProfileService', 'sessionService', 'dashboardService'];
153     SearchSnippetCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout','userProfileService', 'sessionService', 'dashboardService','applicationsService', '$window','$state'];
154     angular.module('ecompApp').controller('searchCtrl', SearchCtrl); 
155     angular.module('ecompApp').controller('searchSnippetCtrl', SearchSnippetCtrl);
156     angular.module('ecompApp').directive('searchBox', function() {
157         return {
158             restrict: "E",
159             templateUrl: 'app/views/search/search.tpl.html',
160             link: function(scope, element) {
161                                 
162                 //var iframeId = "#tabframe-" + scope.$parent.tab.title.split(' ').join('-');
163                 // jQuery(iframeId).load(function() {
164                 //        alert("hello");
165                 //    }); //.attr("src",'{{tab.content | trusted}}' ); //src='{{tab.content | trusted}}'
166                 // jQuery(iframeId).attr('src', '{{tab.content | trusted}}');
167                  
168                 //element.childNodes[0].on('load', function() {
169                 //      alert('hello');
170                 //});
171             }
172         }
173     });
174     angular.module( 'ecompApp' ).config( [
175         '$compileProvider',
176         function( $compileProvider )
177         {   
178             $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension|qto):/);
179         }
180     ]);
181
182 })();
183
184