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

Project status display field with extracted helper methods

Wieland Lindenthal680cff7e6590
diff --git a/frontend/src/app/modules/fields/display/field-types/project-status-display-field.module.ts b/frontend/src/app/modules/fields/display/field-types/project-status-display-field.module.ts
index 4ac6292c1e9..36d6c8fb338 100644
--- a/frontend/src/app/modules/fields/display/field-types/project-status-display-field.module.ts
+++ b/frontend/src/app/modules/fields/display/field-types/project-status-display-field.module.ts
@@ -28,31 +28,16 @@
import {DisplayField} from "core-app/modules/fields/display/display-field.module";
import {I18nService} from "core-app/modules/common/i18n/i18n.service";
+import {projectStatusCodeCssClass, projectStatusI18n} from "core-app/modules/fields/helpers/project-status-helper";
+
export class ProjectStatusDisplayField extends DisplayField {
- readonly I18n:I18nService = this.$injector.get(I18nService);
public render(element:HTMLElement, displayText:string):void {
const code = this.value;
element.innerHTML = `
- <span class="bulb ${this.projectStatusCodeCssClass(code)}"></span>
- <span class="status-name ${this.projectStatusCodeCssClass(code)}">${this.projectStatusI18n(code)}</span>
+ <span class="bulb ${projectStatusCodeCssClass(code)}"></span>
+ <span class="status-name ${projectStatusCodeCssClass(code)}">${projectStatusI18n(code, this.I18n)}</span>
`;
}
-
- private projectStatusCodeCssClass(code:string|null|undefined):string {
- code = this.ensureDefaultCode(code);
-
- return '-' + code.replace(' ', '-');
- }
-
- private projectStatusI18n(code:string|null|undefined):string {
- code = this.ensureDefaultCode(code);
-
- return this.I18n.t('js.grid.widgets.project_status.' + code.replace(' ', '_'));
- }
-
- private ensureDefaultCode(code:string|null|undefined):string {
- return code ? code : 'not set';
- }
}
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 a53800d98e2..536424fc0a6 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
@@ -205,21 +205,21 @@ export class ProjectStatusEditFieldComponent extends EditFieldComponent implemen
private loadValues() {
let allowedValues = this.schema.allowedValues;
- if (Array.isArray(allowedValues)) {
- this.setValues(allowedValues);
- } else if (this.schema.allowedValues) {
- return this.schema.allowedValues.$load().then((values:CollectionResource) => {
- // The select options of the project shall be sorted
- if (values.count > 0 && (values.elements[0] as any)._type === 'Project') {
- this.setValues(values.elements, true);
- } else {
- this.setValues(values.elements);
- }
- });
- } else {
- this.setValues([]);
- }
- return Promise.resolve();
+ // if (Array.isArray(allowedValues)) {
+ // this.setValues(allowedValues);
+ // } else if (this.schema.allowedValues) {
+ // return this.schema.allowedValues.$load().then((values:CollectionResource) => {
+ // // The select options of the project shall be sorted
+ // if (values.count > 0 && (values.elements[0] as any)._type === 'Project') {
+ // this.setValues(values.elements, true);
+ // } else {
+ // this.setValues(values.elements);
+ // }
+ // });
+ // } else {
+ // this.setValues([]);
+ // }
+ // return Promise.resolve();
}
}
diff --git a/frontend/src/app/modules/fields/helpers/project-status-helper.ts b/frontend/src/app/modules/fields/helpers/project-status-helper.ts
new file mode 100644
index 00000000000..ad1b38e5d7c
--- /dev/null
+++ b/frontend/src/app/modules/fields/helpers/project-status-helper.ts
@@ -0,0 +1,17 @@
+import {I18nService} from "core-app/modules/common/i18n/i18n.service";
+
+export function projectStatusCodeCssClass(code:string|null|undefined):string {
+ code = ensureDefaultCode(code);
+
+ return '-' + code.replace(' ', '-');
+}
+
+export function projectStatusI18n(code:string|null|undefined, I18n:I18nService):string {
+ code = ensureDefaultCode(code);
+
+ return I18n.t('js.grid.widgets.project_status.' + code.replace(' ', '_'));
+}
+
+function ensureDefaultCode(code:string|null|undefined):string {
+ return code ? code : 'not set';
+}
\ No newline at end of file