Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

bind a method to close event

bsatarnejadf29868d7e8f5
diff --git a/frontend/src/app/core/global_search/input/global-search-input.component.html b/frontend/src/app/core/global_search/input/global-search-input.component.html
index 232ac732392..222a31175e4 100644
--- a/frontend/src/app/core/global_search/input/global-search-input.component.html
+++ b/frontend/src/app/core/global_search/input/global-search-input.component.html
@@ -27,7 +27,7 @@
(blur)="onFocusOut()"
(search)="search($event)"
(open)="openCloseMenu(currentValue)"
- (close)="select.searchTerm = currentValue"
+ (close)="onClose()"
(change)="followItem($event)"
(keydown.enter)="onEnterBeforeResultsLoaded()"
(keydown.escape)="blur()"
diff --git a/frontend/src/app/core/global_search/input/global-search-input.component.ts b/frontend/src/app/core/global_search/input/global-search-input.component.ts
index 507efda81e1..1c05175781c 100644
--- a/frontend/src/app/core/global_search/input/global-search-input.component.ts
+++ b/frontend/src/app/core/global_search/input/global-search-input.component.ts
@@ -57,6 +57,11 @@ import { ApiV3Service } from '../../apiv3/api-v3.service';
export const globalSearchSelector = 'global-search-input';
+interface SearchResultItems {
+ items:[];
+ term:string;
+}
+
interface SearchResultItem {
id:string;
subject:string;
@@ -138,7 +143,8 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {
ngAfterViewInit():void {
// check searchterm on init, expand / collapse search bar and set correct classes
- this.ngSelectComponent.ngSelectInstance.searchTerm = this.currentValue = this.globalSearchService.searchTerm;
+ this.ngSelectComponent.ngSelectInstance.searchTerm = this.globalSearchService.searchTerm;
+ this.currentValue = this.globalSearchService.searchTerm;
this.expanded = (this.ngSelectComponent.ngSelectInstance.searchTerm.length > 0);
this.toggleTopMenuClass();
}
@@ -192,7 +198,7 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {
return Highlighting.inlineClass(property, id);
}
- public search($event:any) {
+ public search($event:SearchResultItems) {
this.currentValue = this.ngSelectComponent.ngSelectInstance.searchTerm;
this.openCloseMenu($event.term);
}
@@ -217,8 +223,13 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {
}
}
+ public onClose() {
+ this.ngSelectComponent.ngSelectInstance.searchTerm = this.currentValue;
+ }
+
public clearSearch() {
- this.currentValue = this.ngSelectComponent.ngSelectInstance.searchTerm = '';
+ this.currentValue = '';
+ this.ngSelectComponent.ngSelectInstance.searchTerm = '';
this.openCloseMenu(this.currentValue);
}
@@ -237,10 +248,6 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {
return Highlighting.inlineClass('status', statusId);
}
- private get isDirectHit() {
- return this.selectedItem && this.selectedItem.hasOwnProperty('id');
- }
-
public followItem(item:WorkPackageResource|SearchOptionItem) {
this.selectedItem = item;
if (item instanceof HalResource) {
@@ -259,7 +266,7 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {
}
// return all project scope items and all items which contain the search term
- public customSearchFn(term:string, item:any):boolean {
+ public customSearchFn(term:string, item:SearchResultItem):boolean {
return item.id === undefined || item.subject.toLowerCase().indexOf(term.toLowerCase()) !== -1;
}