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

Fix project status to allow a value of 'null' while using ngSelect.

Wieland Lindenthalc51682851f16
diff --git a/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.html b/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.html
index ba20b5b76fe..66cf9016674 100644
--- a/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.html
+++ b/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.html
@@ -1,22 +1,20 @@
-<div (keydown.escape)="handler.handleUserCancel()">
- <ng-select [items]="availableStatuses"
- [(ngModel)]="resource.status"
- bindLabel="name"
- bindValue="value"
- class="project-status"
- (open)="onOpen()"
- (close)="onClose()"
- (change)="handler.handleUserSubmit()"
- [appendTo]="hiddenOverflowContainer"
- [hideSelected]="true"
- [disabled]="inFlight">
- <ng-template ng-label-tmp let-item="item">
- <span class="project-status--bulb" [ngClass]="item.colorClass"></span>
- <span class="project-status--name" [ngClass]="item.colorClass">{{item.name}}</span>
- </ng-template>
- <ng-template ng-option-tmp let-item="item" let-index="index" let-search="searchTerm">
- <span class="project-status--bulb" [ngClass]="item.colorClass"></span>
- <span class="project-status--name" [ngClass]="item.colorClass">{{item.name}}</span>
- </ng-template>
- </ng-select>
-</div>
\ No newline at end of file
+<ng-select [items]="availableStatuses"
+ [(ngModel)]="currentStatusCode"
+ bindLabel="name"
+ bindValue="code"
+ class="project-status"
+ (open)="onOpen()"
+ (close)="onClose()"
+ (change)="onChange()"
+ [appendTo]="hiddenOverflowContainer"
+ [hideSelected]="true"
+ [disabled]="inFlight">
+ <ng-template ng-label-tmp let-item="item">
+ <span class="project-status--bulb" [ngClass]="item.colorClass"></span>
+ <span class="project-status--name" [ngClass]="item.colorClass">{{item.name}}</span>
+ </ng-template>
+ <ng-template ng-option-tmp let-item="item" let-index="index" let-search="searchTerm">
+ <span class="project-status--bulb" [ngClass]="item.colorClass"></span>
+ <span class="project-status--name" [ngClass]="item.colorClass">{{item.name}}</span>
+ </ng-template>
+</ng-select>
\ No newline at end of file
diff --git a/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.ts
index 33bd2ee05e8..81f0f86a59c 100644
--- a/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.ts
+++ b/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.ts
@@ -42,19 +42,21 @@ export class ProjectStatusEditFieldComponent extends EditFieldComponent implemen
readonly I18n:I18nService = this.injector.get(I18nService);
private _availableStatusCodes:string[] = ['not set', 'off track', 'at risk', 'on track'];
+ public currentStatusCode:string = 'not set';
public availableStatuses:any[] = this._availableStatusCodes.map((code:string):any => {
return {
code: code,
name: projectStatusI18n(code, this.I18n),
- colorClass: projectStatusCodeCssClass(code),
- value: code === 'not set' ? null : code,
+ colorClass: projectStatusCodeCssClass(code)
};
});
public hiddenOverflowContainer = '#content-wrapper';
ngOnInit() {
+ this.currentStatusCode = this.resource['status'] === null ? 'not set' : this.resource['status'];
+
// The timeout takes care that the opening is added to the end of the current call stack.
// Thus we can be sure that the select box is rendered and ready to be opened.
let that = this;
@@ -63,6 +65,11 @@ export class ProjectStatusEditFieldComponent extends EditFieldComponent implemen
}, 0);
}
+ public onChange() {
+ this.resource['status'] = this.currentStatusCode === 'not set' ? null : this.currentStatusCode;
+ this.handler.handleUserSubmit();
+ }
+
public onOpen() {
jQuery(this.hiddenOverflowContainer).one('scroll', () => {
this.ngSelectComponent.close();