|
@@ -7,6 +7,7 @@ import $ from 'jquery';
|
|
|
import coreModule from '../../core_module';
|
|
import coreModule from '../../core_module';
|
|
|
|
|
|
|
|
export class SearchCtrl {
|
|
export class SearchCtrl {
|
|
|
|
|
+ isOpen: boolean;
|
|
|
query: any;
|
|
query: any;
|
|
|
giveSearchFocus: number;
|
|
giveSearchFocus: number;
|
|
|
selectedIndex: number;
|
|
selectedIndex: number;
|
|
@@ -15,16 +16,34 @@ export class SearchCtrl {
|
|
|
tagsMode: boolean;
|
|
tagsMode: boolean;
|
|
|
showImport: boolean;
|
|
showImport: boolean;
|
|
|
dismiss: any;
|
|
dismiss: any;
|
|
|
|
|
+ ignoreClose: any;
|
|
|
|
|
|
|
|
/** @ngInject */
|
|
/** @ngInject */
|
|
|
- constructor(private $scope, private $location, private $timeout, private backendSrv, private contextSrv) {
|
|
|
|
|
|
|
+ constructor(private $scope, private $location, private $timeout, private backendSrv, private contextSrv, private $rootScope) {
|
|
|
|
|
+ $rootScope.onAppEvent('show-dash-search', this.openSearch.bind(this), $scope);
|
|
|
|
|
+ $rootScope.onAppEvent('hide-dash-search', this.closeSearch.bind(this), $scope);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ closeSearch() {
|
|
|
|
|
+ this.isOpen = this.ignoreClose;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ openSearch() {
|
|
|
|
|
+ if (this.isOpen) {
|
|
|
|
|
+ this.isOpen = false;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.isOpen = true;
|
|
|
this.giveSearchFocus = 0;
|
|
this.giveSearchFocus = 0;
|
|
|
this.selectedIndex = -1;
|
|
this.selectedIndex = -1;
|
|
|
this.results = [];
|
|
this.results = [];
|
|
|
this.query = { query: '', tag: [], starred: false };
|
|
this.query = { query: '', tag: [], starred: false };
|
|
|
this.currentSearchId = 0;
|
|
this.currentSearchId = 0;
|
|
|
|
|
+ this.ignoreClose = true;
|
|
|
|
|
|
|
|
- $timeout(() => {
|
|
|
|
|
|
|
+ this.$timeout(() => {
|
|
|
|
|
+ this.ignoreClose = false;
|
|
|
this.giveSearchFocus = this.giveSearchFocus + 1;
|
|
this.giveSearchFocus = this.giveSearchFocus + 1;
|
|
|
this.query.query = '';
|
|
this.query.query = '';
|
|
|
this.search();
|
|
this.search();
|
|
@@ -33,7 +52,7 @@ export class SearchCtrl {
|
|
|
|
|
|
|
|
keyDown(evt) {
|
|
keyDown(evt) {
|
|
|
if (evt.keyCode === 27) {
|
|
if (evt.keyCode === 27) {
|
|
|
- this.dismiss();
|
|
|
|
|
|
|
+ this.closeSearch();
|
|
|
}
|
|
}
|
|
|
if (evt.keyCode === 40) {
|
|
if (evt.keyCode === 40) {
|
|
|
this.moveSelection(1);
|
|
this.moveSelection(1);
|
|
@@ -141,10 +160,7 @@ export function searchDirective() {
|
|
|
controller: SearchCtrl,
|
|
controller: SearchCtrl,
|
|
|
bindToController: true,
|
|
bindToController: true,
|
|
|
controllerAs: 'ctrl',
|
|
controllerAs: 'ctrl',
|
|
|
- scope: {
|
|
|
|
|
- dismiss: '&'
|
|
|
|
|
- },
|
|
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-coreModule.directive('search', searchDirective);
|
|
|
|
|
|
|
+coreModule.directive('dashboardSearch', searchDirective);
|