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

adding footer to component and another posibilities for its data source

bsatarnejad473e43416f3f
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 1f7d145de25..e43deaf7ee9 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -673,6 +673,11 @@ en:
placeholder: "Type to search"
parent_placeholder: "Choose new parent or press escape to cancel."
+ autocompleter:
+ placeholder: "Type to search"
+ notFoundText: "No items found"
+ typeToSearchText: "Type to search"
+
repositories:
select_tag: 'Select tag'
select_branch: 'Select branch'
diff --git a/frontend/src/app/modules/autocompleter/op-autocompleter/directives/op-autocompleter-footer-template.directive.ts b/frontend/src/app/modules/autocompleter/op-autocompleter/directives/op-autocompleter-footer-template.directive.ts
new file mode 100644
index 00000000000..89a0a81855f
--- /dev/null
+++ b/frontend/src/app/modules/autocompleter/op-autocompleter/directives/op-autocompleter-footer-template.directive.ts
@@ -0,0 +1,11 @@
+import { Directive } from "@angular/core";
+
+@Directive({
+ selector: "[op-autocompleter-footer-tmp]"
+})
+ // A Directive to be used on the option template of
+ // ng-select (what will be shown in each row of drop down)
+ // it is used when you want to inject a different template
+export class OpAutocompleterFooterTemplateDirective {
+
+}
\ No newline at end of file
diff --git a/frontend/src/app/modules/autocompleter/op-autocompleter/op-autocompleter.component.html b/frontend/src/app/modules/autocompleter/op-autocompleter/op-autocompleter.component.html
index aec0ad1132c..e6dea35901f 100644
--- a/frontend/src/app/modules/autocompleter/op-autocompleter/op-autocompleter.component.html
+++ b/frontend/src/app/modules/autocompleter/op-autocompleter/op-autocompleter.component.html
@@ -66,15 +66,20 @@
</ng-container>
</ng-template>
- <ng-template ng-label-tmp let-item="item">
- <ng-container [ngTemplateOutlet]="labelTemplate ? labelTemplate : defaultLabel" [ngTemplateOutletContext]="{$implicit:item}">
- </ng-container>
- </ng-template>
+ <ng-template ng-label-tmp let-item="item">
+ <ng-container [ngTemplateOutlet]="labelTemplate ? labelTemplate : defaultLabel" [ngTemplateOutletContext]="{$implicit:item}">
+ </ng-container>
+ </ng-template>
- <ng-template ng-option-tmp let-item="item" let-index="index" let-search="searchTerm">
- <ng-container [ngTemplateOutlet]="optionTemplate ? optionTemplate : defaultOption" [ngTemplateOutletContext]="{$implicit:item}">
- </ng-container>
- </ng-template>
+ <ng-template ng-option-tmp let-item="item" let-index="index" let-search="searchTerm">
+ <ng-container [ngTemplateOutlet]="optionTemplate ? optionTemplate : defaultOption" [ngTemplateOutletContext]="{$implicit:item}">
+ </ng-container>
+ </ng-template>
+
+ <ng-template ng-footer-tmp *ngIf="footerTemplate">
+ <ng-container [ngTemplateOutlet]="footerTemplate" [ngTemplateOutletContext]="{$implicit:item}">
+ </ng-container>
+ </ng-template>
</ng-select>
</div>
@@ -124,7 +129,7 @@
</ng-container>
- <ng-container *ngSwitchCase="resource ==='subproject' || resource ==='version' || resource ==='status'">
+ <ng-container *ngSwitchCase="resource ==='subproject' || resource ==='version' || resource ==='status' || resource ==='default'">
{{ item.name }}
</ng-container>
</ng-template>
diff --git a/frontend/src/app/modules/autocompleter/op-autocompleter/op-autocompleter.component.ts b/frontend/src/app/modules/autocompleter/op-autocompleter/op-autocompleter.component.ts
index f7ab4e2e9da..321b609a86f 100644
--- a/frontend/src/app/modules/autocompleter/op-autocompleter/op-autocompleter.component.ts
+++ b/frontend/src/app/modules/autocompleter/op-autocompleter/op-autocompleter.component.ts
@@ -5,7 +5,7 @@ import {AngularTrackingHelpers} from 'core-components/angular/tracking-functions
import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';
import {HalResourceSortingService} from 'core-app/modules/hal/services/hal-resource-sorting.service';
import {DropdownPosition, NgSelectComponent} from '@ng-select/ng-select';
-import { Observable, Subject } from 'rxjs';
+import { Observable, of, Subject } from 'rxjs';
import { HalResourceNotificationService } from 'core-app/modules/hal/services/hal-resource-notification.service';
import { CurrentProjectService } from 'core-app/components/projects/current-project.service';
import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
@@ -14,6 +14,7 @@ import { GroupValueFn } from '@ng-select/ng-select/lib/ng-select.component';
import { OpAutocompleterOptionTemplateDirective } from "./directives/op-autocompleter-option-template.directive";
import { OpAutocompleterLabelTemplateDirective } from "./directives/op-autocompleter-label-template.directive";
import { OpAutocompleterHeaderTemplateDirective } from "./directives/op-autocompleter-header-template.directive";
+import { OpAutocompleterFooterTemplateDirective } from "./directives/op-autocompleter-footer-template.directive";
import { OpAutocompleterService } from "./services/op-autocompleter.service";
import {Highlighting} from "core-components/wp-fast-table/builders/highlighting/highlighting.functions";
@@ -30,10 +31,10 @@ import {Highlighting} from "core-components/wp-fast-table/builders/highlighting/
// you also can change the value of ng-select default options by changing @inputs and @outputs
export class OpAutocompleterComponent extends UntilDestroyedMixin implements AfterViewInit{
- @Input() public filters?:IAPIFilter[];
+ @Input() public filters?:IAPIFilter[] = [];
@Input() public resource:resource;
@Input() public model?:any;
- @Input() public searchKey?:string;
+ @Input() public searchKey?:string = '';
@Input() public defaulData?:boolean = false;
@Input() public name?:string;
@Input() public required?:boolean = false;
@@ -41,6 +42,8 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
@Input() public searchable?:boolean = true;
@Input() public clearable?:boolean = true;
@Input() public addTag?:boolean = false;
+ @Input() public configOptions?:IOPAutocompleterOptions[];
+
@Input() public clearSearchOnAdd?:boolean = true;
@Input() public classes?:string;
@@ -49,9 +52,9 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
@Input() public bindLabel?:string;
@Input() public bindValue?:string;
@Input() public markFirst ? = true;
- @Input() public placeholder?:string;
- @Input() public notFoundText?:string;
- @Input() public typeToSearchText?:string;
+ @Input() public placeholder?:string = this.I18n.t('js.autocompleter.placeholder');
+ @Input() public notFoundText?:string = this.I18n.t('js.autocompleter.notFoundText');
+ @Input() public typeToSearchText?:string = this.I18n.t('js.autocompleter.typeToSearchText');
@Input() public addTagText?:string;
@Input() public loadingText?:string;
@Input() public clearAllText?:string;
@@ -119,10 +122,14 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
@ContentChild(OpAutocompleterHeaderTemplateDirective, { read: TemplateRef })
headerTemplate:TemplateRef<any>;
+ @ContentChild(OpAutocompleterFooterTemplateDirective, { read: TemplateRef })
+ footerTemplate:TemplateRef<any>;
+
constructor(
readonly opAutocompleterService:OpAutocompleterService,
readonly cdRef:ChangeDetectorRef,
readonly ngZone:NgZone,
+ private readonly I18n:I18nService
) {
super();
}
@@ -136,18 +143,23 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
this.typeToSearchText = this.typeToSearchText ? this.typeToSearchText : this.placeholder;
this.ngZone.runOutsideAngular(() => {
setTimeout(() => {
- this.results$ = this.defaulData ? (this.searchInput$.pipe(
+
+ this.results$ = this.configOptions ? (this.searchInput$.pipe(
debounceTime(250),
distinctUntilChanged(),
- switchMap(queryString => this.opAutocompleterService.loadData(queryString, this.resource, this.filters, this.searchKey))
+ switchMap(queryString => this.getOptionsItems(queryString))
+ )) : this.defaulData ? (this.searchInput$.pipe(
+ debounceTime(250),
+ distinctUntilChanged(),
+ switchMap(queryString => this.opAutocompleterService.loadData(queryString, this.resource, this.filters, this.searchKey))
)) : (this.searchInput$.pipe(
- debounceTime(250),
- distinctUntilChanged(),
- switchMap(queryString => this.getOptionsFn(queryString))
- ));
+ debounceTime(250),
+ distinctUntilChanged(),
+ switchMap(queryString => this.getOptionsFn(queryString))
+ ));
- this.ngSelectInstance.focus();
- this.repositionDropdown();
+ this.ngSelectInstance.focus();
+ this.repositionDropdown();
}, 25);
});
@@ -172,13 +184,25 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
this.results$ = this.defaulData
? (this.opAutocompleterService.loadData('', this.resource, this.filters, this.searchKey))
: (this.getOptionsFn(''));
- this.repositionDropdown();
}
+ this.repositionDropdown();
this.open.emit();
}
+
+ public getOptionsItems(searchKey :string):Observable<any>{
+ return of(this.configOptions?.filter(element => element.name.includes(searchKey))) ;
+ }
public closeSelect() {
this.ngSelectInstance && this.ngSelectInstance.close();
}
+
+ public focusSelect() {
+ this.ngZone.runOutsideAngular(() => {
+ setTimeout(() => {
+ this.ngSelectInstance.focus();
+ }, 25);
+ });
+ }
public closed(val:any) {
this.close.emit();
@@ -193,7 +217,6 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
public focused(val:any) {
- this.ngSelectInstance.focus();
this.focus.emit(val);
}
diff --git a/frontend/src/app/modules/autocompleter/op-autocompleter/typings.d.ts b/frontend/src/app/modules/autocompleter/op-autocompleter/typings.d.ts
index 8ad619a20ce..568113f453d 100644
--- a/frontend/src/app/modules/autocompleter/op-autocompleter/typings.d.ts
+++ b/frontend/src/app/modules/autocompleter/op-autocompleter/typings.d.ts
@@ -4,4 +4,9 @@ interface IAPIFilter {
values:unknown[]|boolean;
};
+interface IOPAutocompleterOptions {
+ id: number;
+ name:string;
+};
+
type resource = 'work_packages' | 'users';
\ No newline at end of file
diff --git a/frontend/src/app/modules/autocompleter/openproject-autocompleter.module.ts b/frontend/src/app/modules/autocompleter/openproject-autocompleter.module.ts
index 299a93babfa..27fcce19bb0 100644
--- a/frontend/src/app/modules/autocompleter/openproject-autocompleter.module.ts
+++ b/frontend/src/app/modules/autocompleter/openproject-autocompleter.module.ts
@@ -18,6 +18,7 @@ import {OpAutocompleterComponent} from "core-app/modules/autocompleter/op-autoco
import {OpAutocompleterOptionTemplateDirective} from "core-app/modules/autocompleter/op-autocompleter/directives/op-autocompleter-option-template.directive";
import {OpAutocompleterLabelTemplateDirective} from "core-app/modules/autocompleter/op-autocompleter/directives/op-autocompleter-label-template.directive";
import {OpAutocompleterHeaderTemplateDirective} from "core-app/modules/autocompleter/op-autocompleter/directives/op-autocompleter-header-template.directive";
+import {OpAutocompleterFooterTemplateDirective} from "core-app/modules/autocompleter/op-autocompleter/directives/op-autocompleter-footer-template.directive";
export const OPENPROJECT_AUTOCOMPLETE_COMPONENTS = [
CreateAutocompleterComponent,
@@ -32,6 +33,7 @@ export const OPENPROJECT_AUTOCOMPLETE_COMPONENTS = [
OpAutocompleterOptionTemplateDirective,
OpAutocompleterLabelTemplateDirective,
OpAutocompleterHeaderTemplateDirective,
+ OpAutocompleterFooterTemplateDirective,
];
@NgModule({