2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
38 import { Component, OnInit, Output, EventEmitter } from '@angular/core';
39 import { GlobalSearchService } from 'src/app/shared/services/global-search/global-search.service';
40 import { GlobalSearchItem } from 'src/app/shared/model/global-search-item.model';
41 import * as $ from 'jquery';
42 import { AddTabFunctionService } from 'src/app/shared/services/tab/add-tab-function.service';
43 import { Router } from '@angular/router';
44 import { environment } from 'src/environments/environment';
47 selector: 'app-global-search',
48 templateUrl: './global-search.component.html',
49 styleUrls: ['./global-search.component.scss']
51 export class GlobalSearchComponent implements OnInit {
52 searchResDialog: boolean = false;
55 api = environment.api;
56 constructor(private globalSearchService: GlobalSearchService, private addTabFuntionService: AddTabFunctionService, private router: Router) { }
61 showHideSearchSnippet() {
63 $('#mainSearchSnippet').click();
66 $('mainSearchText').focus();
70 mainSearchEvent = $('#mainSearchDiv').keyup((event) => {
71 if (event.keyCode == 13) {
73 this.getSearchResult(<string><any>$('#mainSearchText').val());
76 var popupDomObj = $("[content='searchSnippet.html']");
77 if (popupDomObj.length == 0) {
78 this.showHideSearchSnippet();
80 $('#mainSearchSnippet').click();
81 this.showHideSearchSnippet();
89 clickOutSide(event: any) {
91 this.searchResDialog = false;
94 searchDialogToggle(event: any) {
95 if (event.keyCode == 13) {
96 this.searchResDialog = true;
97 this.searchString = <string><any>$('#mainSearchText').val();
98 this.getSearchResult(<string><any>$('#mainSearchText').val());
102 getSearchResult(searchString: string) {
103 //console.log("getSearch Result");
104 this.globalSearchService.getSearchResults(searchString).subscribe(data => {
105 //console.log("Response data" + data);
106 this.items = data.response;
107 //console.log("search result data" + JSON.stringify(data));
110 console.log('getSearchResult Error Object' + error);
113 goToUrl(item: any, type?: any) {
114 //console.log('check goto');
115 //var a = { 'test1': 'value1', 'test2': 'value3', 'test3': 'value2' };
116 if (type == 'intra') {
118 var intraSearcLink = this.api.intraSearcLink;
119 var intraSpecSearcLink = intraSearcLink + encodeURIComponent(this.searchString);
120 window.open(intraSpecSearcLink, '_blank');
122 } else if (type == 'extra') {
123 var extraSearcLink = this.api.extraSearcLink;
124 var extraSpecSearcLink = extraSearcLink + encodeURIComponent(this.searchString);
125 window.open(extraSpecSearcLink, '_blank');
127 let url = item.target;
128 let restrictedApp = item.uuid;
129 let getAccessState = "getAccess"
130 console.log("item.target " + item.target + "item.uuid " + item.uuid);
132 this.router.navigate(['/' + getAccessState]);
133 //$log.info('No url found for this application, doing nothing..');
136 if (!restrictedApp) {
137 window.open(url, '_blank');
139 if (item.url == "root.access") {
140 this.router.navigate(['/' + item.url]);
141 var tabContent = { id: new Date(), title: 'Home', url: url };
142 // $cookies.putObject('addTab', tabContent );
143 this.addTabFuntionService.filter(tabContent);
145 var tabContentCtrl = { id: new Date(), title: item.name, url: url };
146 this.addTabFuntionService.filter(tabContentCtrl);