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

Insert project autocompleter in dyanmic forms

Benjamin Bädorf07630f31b086
diff --git a/frontend/src/app/features/invite-user-modal/invite-user-modal.module.ts b/frontend/src/app/features/invite-user-modal/invite-user-modal.module.ts
index 8355b33437a..f03573f0449 100644
--- a/frontend/src/app/features/invite-user-modal/invite-user-modal.module.ts
+++ b/frontend/src/app/features/invite-user-modal/invite-user-modal.module.ts
@@ -12,7 +12,6 @@ import { OPSharedModule } from 'core-app/shared/shared.module';
import { OpInviteUserModalService } from 'core-app/features/invite-user-modal/invite-user-modal.service';
import { InviteUserModalComponent } from './invite-user.component';
import { ProjectSelectionComponent } from './project-selection/project-selection.component';
-import { ProjectSearchComponent } from './project-selection/project-search.component';
import { PrincipalComponent } from './principal/principal.component';
import { PrincipalSearchComponent } from './principal/principal-search.component';
import { RoleComponent } from './role/role.component';
@@ -46,7 +45,6 @@ export function initializeServices(injector:Injector) {
declarations: [
InviteUserModalComponent,
ProjectSelectionComponent,
- ProjectSearchComponent,
PrincipalComponent,
PrincipalSearchComponent,
RoleComponent,
diff --git a/frontend/src/app/features/invite-user-modal/project-selection/project-search.component.html b/frontend/src/app/features/invite-user-modal/project-selection/project-search.component.html
deleted file mode 100644
index afbec63d4f3..00000000000
--- a/frontend/src/app/features/invite-user-modal/project-selection/project-search.component.html
+++ /dev/null
@@ -1,40 +0,0 @@
-<ng-select
- appendTo=".op-modal-overlay"
- [formControl]="projectFormControl"
- [typeahead]="input$"
- [items]="items$ | async"
- [clearable]="true"
- [clearOnBackspace]="false"
- [clearSearchOnAdd]="false"
- [compareWith]="compareWith"
- bindValue="project"
- autofocus
- #ngselect
->
- <ng-template ng-label-tmp let-item="item">
- {{ item.project?.name || item.name }}
- </ng-template>
-
- <ng-template ng-option-tmp let-item="item" let-search="searchTerm">
- <div
- *ngIf="item"
- class="ng-option-label"
- >
- <!--Selectable option-->
- <div [ngOptionHighlight]="search">{{ item.project.name }}</div>
-
- <!-- No invite rights -->
- <div
- *ngIf="item.disabled"
- class="ellipsis"
- >{{ text.noInviteRights }}</div>
- </div>
- </ng-template>
-
- <!--Nothing found -->
- <ng-template ng-notfound-tmp let-searchTerm="searchTerm">
- <div class="ng-option disabled">
- {{ text.noResultsFound }}
- </div>
- </ng-template>
-</ng-select>
diff --git a/frontend/src/app/features/invite-user-modal/project-selection/project-search.component.ts b/frontend/src/app/features/invite-user-modal/project-selection/project-search.component.ts
deleted file mode 100644
index a4f3ab67a88..00000000000
--- a/frontend/src/app/features/invite-user-modal/project-selection/project-search.component.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-import {
- Component,
- Input,
- OnInit,
- ElementRef,
-} from '@angular/core';
-import { FormControl } from '@angular/forms';
-import { BehaviorSubject, combineLatest } from 'rxjs';
-import { debounceTime, map, switchMap } from 'rxjs/operators';
-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
-import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
-import { ProjectResource } from 'core-app/features/hal/resources/project-resource';
-import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
-import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
-
-interface NgSelectProjectOption {
- project:ProjectResource,
- disabled:boolean;
-}
-
-@Component({
- selector: 'op-ium-project-search',
- templateUrl: './project-search.component.html',
-})
-export class ProjectSearchComponent extends UntilDestroyedMixin implements OnInit {
- @Input('opFormBinding') projectFormControl:FormControl;
-
- public text = {
- noResultsFound: this.I18n.t('js.invite_user_modal.project.no_results'),
- noInviteRights: this.I18n.t('js.invite_user_modal.project.no_invite_rights'),
- };
-
- public input$ = new BehaviorSubject<string|null>('');
-
- public items$ = combineLatest([
- this.input$.pipe(
- debounceTime(100),
- switchMap((searchTerm:string) => {
- const filters = new ApiV3FilterBuilder();
- filters.add('active', '=', true);
- if (searchTerm) {
- filters.add('name_and_identifier', '~', [searchTerm]);
- }
- return this.apiV3Service.projects
- .filtered(filters)
- .get()
- .pipe(map((collection) => collection.elements));
- }),
- ),
- this.currentUserService.capabilities$.pipe(
- map((capabilities) => capabilities.filter((c) => c.action.href.endsWith('/memberships/create'))),
- ),
- ])
- .pipe(
- this.untilDestroyed(),
- map(([projects, projectInviteCapabilities]) => {
- const mapped = projects.map((project:ProjectResource) => ({
- project,
- disabled: !projectInviteCapabilities.find((cap) => cap.context.id === project.id),
- }));
- mapped.sort(
- (a:NgSelectProjectOption, b:NgSelectProjectOption) => (a.disabled ? 1 : 0) - (b.disabled ? 1 : 0),
- );
- return mapped;
- }),
- );
-
- constructor(
- readonly I18n:I18nService,
- readonly elementRef:ElementRef,
- readonly apiV3Service:ApiV3Service,
- readonly currentUserService:CurrentUserService,
- ) {
- super();
- }
-
- ngOnInit() {
- // Make sure we have initial data
- setTimeout(() => this.input$.next(''));
- }
-
- compareWith = (a:NgSelectProjectOption, b:ProjectResource) => a.project.id === b.id;
-}
diff --git a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.html b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.html
index d5240d50ff6..31d9500e7ff 100644
--- a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.html
+++ b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.html
@@ -10,6 +10,7 @@
required
>
<op-project-autocompleter
+ formControlName="project"
slot="input"
[APIFilters]="APIFiltersForProjects"
[mapResultsFn]="projectFilterFn.bind(this)"
diff --git a/frontend/src/app/features/work-packages/components/filters/query-filter/query-filter.component.html b/frontend/src/app/features/work-packages/components/filters/query-filter/query-filter.component.html
index 4b77492b631..f9bdc9a52f2 100644
--- a/frontend/src/app/features/work-packages/components/filters/query-filter/query-filter.component.html
+++ b/frontend/src/app/features/work-packages/components/filters/query-filter/query-filter.component.html
@@ -1,10 +1,10 @@
<ng-container>
<!-- Name -->
<label
- for="operators-{{filter.id}}"
- class="advanced-filters--filter-name"
- [textContent]="filter.name"
- [attr.title]="filter.name"
+ for="operators-{{filter.id}}"
+ class="advanced-filters--filter-name"
+ [textContent]="filter.name"
+ [attr.title]="filter.name"
>
</label>
@@ -12,91 +12,95 @@
<div class="advanced-filters--filter-operator">
<label
- for="operators-{{filter.id}}"
- class="hidden-for-sighted"
+ for="operators-{{filter.id}}"
+ class="hidden-for-sighted"
>
{{ filter.name }}
{{ text.open_filter }}
</label>
<select
- required
- *ngIf="valueType !== '[1]Boolean'"
- class="advanced-filters--select"
- id="operators-{{filter.id}}"
- name="op[{{filter.id}}]"
- [(ngModel)]="filter.operator"
- (ngModelChange)="onFilterUpdated(filter)"
- [compareWith]="compareByHref"
- style="vertical-align: top;"
+ required
+ *ngIf="valueType !== '[1]Boolean'"
+ class="advanced-filters--select"
+ id="operators-{{filter.id}}"
+ name="op[{{filter.id}}]"
+ [(ngModel)]="filter.operator"
+ (ngModelChange)="onFilterUpdated(filter)"
+ [compareWith]="compareByHref"
+ style="vertical-align: top;"
>
<option
- *ngFor="let operator of availableOperators"
- [textContent]="operator.name"
- [ngValue]="operator"
+ *ngFor="let operator of availableOperators"
+ [textContent]="operator.name"
+ [ngValue]="operator"
>
</option>
</select>
<op-filter-boolean-value
- *ngIf="valueType == '[1]Boolean'"
- (filterChanged)="onFilterUpdated($event)"
- [shouldFocus]="shouldFocus"
- [filter]="filter"
+ *ngIf="valueType == '[1]Boolean'"
+ (filterChanged)="onFilterUpdated($event)"
+ [shouldFocus]="shouldFocus"
+ [filter]="filter"
></op-filter-boolean-value>
</div>
<!-- Values -->
<ng-container *ngIf="showValuesInput && valueType">
<div class="advanced-filters--filter-value" [ngSwitch]="valueType">
<op-filter-integer-value
- *ngSwitchCase="'[1]Integer'"
- (filterChanged)="onFilterUpdated($event)"
- [shouldFocus]="shouldFocus"
- [filter]="filter"
+ *ngSwitchCase="'[1]Integer'"
+ (filterChanged)="onFilterUpdated($event)"
+ [shouldFocus]="shouldFocus"
+ [filter]="filter"
></op-filter-integer-value>
<op-filter-date-value
- *ngSwitchCase="'[1]Date'"
- (filterChanged)="onFilterUpdated($event)"
- [shouldFocus]="shouldFocus"
- [filter]="filter"
+ *ngSwitchCase="'[1]Date'"
+ (filterChanged)="onFilterUpdated($event)"
+ [shouldFocus]="shouldFocus"
+ [filter]="filter"
></op-filter-date-value>
<op-filter-dates-value
- *ngSwitchCase="'[2]Date'"
- (filterChanged)="onFilterUpdated($event)"
- [shouldFocus]="shouldFocus"
- [filter]="filter"
+ *ngSwitchCase="'[2]Date'"
+ (filterChanged)="onFilterUpdated($event)"
+ [shouldFocus]="shouldFocus"
+ [filter]="filter"
></op-filter-dates-value>
<op-filter-date-time-value
- *ngSwitchCase="'[1]DateTime'"
- (filterChanged)="onFilterUpdated($event)"
- [shouldFocus]="shouldFocus"
- [filter]="filter"
+ *ngSwitchCase="'[1]DateTime'"
+ (filterChanged)="onFilterUpdated($event)"
+ [shouldFocus]="shouldFocus"
+ [filter]="filter"
></op-filter-date-time-value>
<op-filter-date-times-value
- *ngSwitchCase="'[2]DateTime'"
- [shouldFocus]="shouldFocus"
- (filterChanged)="onFilterUpdated($event)"
- [filter]="filter"
+ *ngSwitchCase="'[2]DateTime'"
+ [shouldFocus]="shouldFocus"
+ (filterChanged)="onFilterUpdated($event)"
+ [filter]="filter"
></op-filter-date-times-value>
<op-filter-string-value
- *ngSwitchCase="'[1]String'"
- (filterChanged)="onFilterUpdated($event)"
- [shouldFocus]="shouldFocus"
- [filter]="filter"
+ *ngSwitchCase="'[1]String'"
+ (filterChanged)="onFilterUpdated($event)"
+ [shouldFocus]="shouldFocus"
+ [filter]="filter"
></op-filter-string-value>
<op-filter-string-value
- *ngSwitchCase="'[1]Float'"
- (filterChanged)="onFilterUpdated($event)"
- [shouldFocus]="shouldFocus"
- [filter]="filter"
+ *ngSwitchCase="'[1]Float'"
+ (filterChanged)="onFilterUpdated($event)"
+ [shouldFocus]="shouldFocus"
+ [filter]="filter"
></op-filter-string-value>
+ <op-project-autocompleter
+ *ngSwitchCase="'[]Project'"
+ ></op-project-autocompleter>
+
<ng-container *ngSwitchDefault>
<op-filter-toggled-multiselect-value
*ngIf="filter.currentSchema.loadedAllowedValues()"
@@ -114,15 +118,17 @@
</div>
</ng-container>
- <div class="advanced-filters--filter-value" *ngIf="!showValuesInput">
- </div>
+ <div
+ class="advanced-filters--filter-value"
+ *ngIf="!showValuesInput"
+ ></div>
<div class="advanced-filters--remove-filter">
<button
- type="button"
- class="spot-link"
- [title]="text.button_delete"
- (click)="removeThisFilter()"
+ type="button"
+ class="spot-link"
+ [title]="text.button_delete"
+ (click)="removeThisFilter()"
>
<op-icon icon-classes="icon-close advanced-filters--remove-filter-icon"></op-icon>
</button>
diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
index 59c6fb187fe..511c82691fb 100644
--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
@@ -280,7 +280,7 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements OnI
this.cdRef.detectChanges();
const component = (this.ngSelectInstance) as any;
if (component && component.dropdownPanel) {
- component.dropdownPanel._updatePosition();
+ // component.dropdownPanel._updatePosition();
}
}, 25);
}
diff --git a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.html b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.html
index 2071a358e69..5e8b6ee3eb6 100644
--- a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.html
+++ b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.html
@@ -1,40 +1,34 @@
<op-autocompleter
[getOptionsFn]="getAvailableProjects.bind(this)"
- [(ngModel)]="value"
+ [model]="value"
[trackByFn]="projectTracker"
- placeholder="My placeholder"
- notFoundText="Nothing found"
+ (change)="onChange($event)"
bindLabel="name"
bindValue="id"
>
<ng-template
op-autocompleter-label-tmp
- let-item="item"
+ let-item
>
- This should show if it is actually working, no?
{{ item.name }}
</ng-template>
<ng-template
op-autocompleter-option-tmp
- let-item="item"
+ let-item
let-search="searchTerm"
>
- <div class="ng-option-label">
- <!--Selectable option-->
- <div
- class="ellipsis"
- [ngStyle]="{ 'padding-left.px': item.numberOfAncestors * 20 }"
- [ngOptionHighlight]="search"
- >{{ item.name }}</div>
-
- <!-- No invite rights -->
- <div
- *ngIf="item.disabled"
- class="ellipsis"
- >{{ text.noInviteRights }}</div>
- </div>
+ <div
+ class="ng-option-label ellipsis"
+ [ngStyle]="{ 'padding-left.px': item.numberOfAncestors * 20 }"
+ [ngOptionHighlight]="search"
+ >{{ item.name }}</div>
+ <div
+ *ngIf="item.disabledReason"
+ class="ng-option-label ellipsis"
+ [ngStyle]="{ 'padding-left.px': item.numberOfAncestors * 20 }"
+ >{{ item.disabledReason }}</div>
</ng-template>
</op-autocompleter>
diff --git a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts
index ea72dc7b646..54b1c30a21c 100644
--- a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts
+++ b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts
@@ -39,14 +39,9 @@ import { HalResourceService } from 'core-app/features/hal/services/hal-resource.
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { Observable } from 'rxjs';
-import { map } from 'rxjs/operators';
-import {
- DebouncedRequestSwitchmap,
- errorNotificationHandler,
-} from 'core-app/shared/helpers/rxjs/debounced-input-switchmap';
+import { map, tap } from 'rxjs/operators';
import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
-import { DatasetInputs } from 'core-app/shared/components/dataset-inputs.decorator';
import { ApiV3ListFilter, listParamsString } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
import { getPaginatedResults } from 'core-app/core/apiv3/helpers/get-paginated-results';
import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';
@@ -60,7 +55,6 @@ import { flattenProjectTree } from './flatten-project-tree';
export const projectsAutocompleterSelector = 'op-project-autocompleter';
-@DatasetInputs
@Component({
templateUrl: './project-autocompleter.component.html',
selector: projectsAutocompleterSelector,
@@ -72,7 +66,6 @@ export const projectsAutocompleterSelector = 'op-project-autocompleter';
})
export class ProjectAutocompleterComponent implements OnInit, ControlValueAccessor {
projectTracker = (item:IProjectAutocompleteItem) => {
- console.log(item);
return item.href || item.id;
}
@@ -95,7 +88,6 @@ export class ProjectAutocompleterComponent implements OnInit, ControlValueAccess
id: project.id,
href: project._links.self.href,
name: project.name,
- found: true,
disabled: false,
ancestors: project._links.ancestors,
children: [],
@@ -161,6 +153,10 @@ export class ProjectAutocompleterComponent implements OnInit, ControlValueAccess
);
}
+ change(val:any) {
+ this.value = val;
+ }
+
writeValue(value:string) {
this.value = value;
}
diff --git a/frontend/src/app/shared/components/dynamic-forms/dynamic-forms.module.ts b/frontend/src/app/shared/components/dynamic-forms/dynamic-forms.module.ts
index 5eb40ca1b41..e0516fa2925 100644
--- a/frontend/src/app/shared/components/dynamic-forms/dynamic-forms.module.ts
+++ b/frontend/src/app/shared/components/dynamic-forms/dynamic-forms.module.ts
@@ -1,13 +1,15 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
-import { TextInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/text-input/text-input.component';
+import { FormlyModule } from '@ngx-formly/core';
+import { NgOptionHighlightModule } from '@ng-select/ng-option-highlight';
+import { NgSelectModule } from '@ng-select/ng-select';
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
+import { ReactiveFormsModule } from '@angular/forms';
+import { ProjectAutocompleterComponent } from 'core-app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component';
+import { TextInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/text-input/text-input.component';
import { IntegerInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/integer-input/integer-input.component';
-import { FormlyModule } from '@ngx-formly/core';
import { SelectInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/select-input/select-input.component';
import { SelectProjectStatusInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/select-project-status-input/select-project-status-input.component';
-import { NgOptionHighlightModule } from '@ng-select/ng-option-highlight';
-import { NgSelectModule } from '@ng-select/ng-select';
import { DatePickerControlModule } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/date-input/components/date-picker-control/date-picker-control.module';
import { BooleanInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/boolean-input/boolean-input.component';
import { DynamicFormComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-form/dynamic-form.component';
@@ -17,7 +19,6 @@ import { InviteUserButtonModule } from 'core-app/features/invite-user-modal/butt
import { DateInputComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/date-input/date-input.component';
import { DynamicFieldGroupWrapperComponent } from 'core-app/shared/components/dynamic-forms/components/dynamic-field-group-wrapper/dynamic-field-group-wrapper.component';
import { OpenProjectHeaderInterceptor } from 'core-app/features/hal/http/openproject-header-interceptor';
-import { ReactiveFormsModule } from '@angular/forms';
import { FormattableControlModule } from 'core-app/shared/components/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/components/formattable-control/formattable-control.module';
import { OPSharedModule } from 'core-app/shared/shared.module';
@@ -32,7 +33,7 @@ import { OPSharedModule } from 'core-app/shared/shared.module';
{ name: 'textInput', component: TextInputComponent },
{ name: 'dateInput', component: DateInputComponent },
{ name: 'selectInput', component: SelectInputComponent },
- { name: 'projectInput', component: SelectInputComponent },
+ { name: 'projectInput', component: ProjectAutocompleterComponent },
{ name: 'selectProjectStatusInput', component: SelectProjectStatusInputComponent },
{ name: 'formattableInput', component: FormattableTextareaInputComponent },
],
diff --git a/frontend/src/app/shared/components/dynamic-forms/services/dynamic-fields/dynamic-fields.service.ts b/frontend/src/app/shared/components/dynamic-forms/services/dynamic-fields/dynamic-fields.service.ts
index 710e0fae8c3..8574f453101 100644
--- a/frontend/src/app/shared/components/dynamic-forms/services/dynamic-fields/dynamic-fields.service.ts
+++ b/frontend/src/app/shared/components/dynamic-forms/services/dynamic-fields/dynamic-fields.service.ts
@@ -100,14 +100,6 @@ export class DynamicFieldsService {
templateOptions: {
locale: this.I18n.locale,
bindLabel: 'name',
- searchable: true,
- virtualScroll: true,
- clearOnBackspace: false,
- clearSearchOnAdd: false,
- hideSelected: false,
- text: {
- add_new_action: this.I18n.t('js.label_create'),
- },
},
expressionProperties: {
'templateOptions.clearable': (model:any, formState:any, field:FormlyFieldConfig) => !field.templateOptions?.required,