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

Implement cell rendering

Oliver Günther19ab5ace5da8
diff --git a/frontend/src/app/core/schemas/schema-cache.service.ts b/frontend/src/app/core/schemas/schema-cache.service.ts
index 64f95174372..9c2a71fdcff 100644
--- a/frontend/src/app/core/schemas/schema-cache.service.ts
+++ b/frontend/src/app/core/schemas/schema-cache.service.ts
@@ -69,10 +69,11 @@ export class SchemaCacheService extends StateCacheService<SchemaResource> {
}
public getSchemaHref(resource:HalResource):string {
- const href = resource.$links.schema?.href;
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ const href = resource.$links.schema?.href as string|undefined;
if (!href) {
- throw new Error(`Resource ${resource} has no schema to load.`);
+ throw new Error(`Resource ${resource.toString()} has no schema to load.`);
}
return href;
diff --git a/frontend/src/app/features/hal/resources/work-package-resource.ts b/frontend/src/app/features/hal/resources/work-package-resource.ts
index 8e51d78d41c..f7a07c49f41 100644
--- a/frontend/src/app/features/hal/resources/work-package-resource.ts
+++ b/frontend/src/app/features/hal/resources/work-package-resource.ts
@@ -48,7 +48,7 @@ import { FormResource } from 'core-app/features/hal/resources/form-resource';
import { Attachable } from 'core-app/features/hal/resources/mixins/attachable-mixin';
import { ICKEditorContext } from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';
import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
-import { IHalResourceLink } from 'core-app/core/state/hal-resource';
+import { IWorkPackageTimestamp } from 'core-app/features/hal/resources/work-package-timestamp-resource';
export interface WorkPackageResourceEmbedded {
activities:CollectionResource;
@@ -116,29 +116,6 @@ export interface WorkPackageLinksObject extends WorkPackageResourceLinks {
schema:HalResource;
}
-export interface IWorkPackageTimestampMeta {
- exists:boolean;
- matchesFilters:boolean;
- timestamp:string;
-}
-
-export interface IWorkPackageTimestamp {
- startDate?:string;
- dueDate?:string;
- date?:string;
- _meta:IWorkPackageTimestampMeta;
- $links:{
- self:IHalResourceLink;
- status?:IHalResourceLink;
- assignee?:IHalResourceLink;
- accountable?:IHalResourceLink;
- project?:IHalResourceLink;
- type?:IHalResourceLink;
- priority?:IHalResourceLink;
- version?:IHalResourceLink;
- }
-}
-
export class WorkPackageBaseResource extends HalResource {
public $embedded:WorkPackageResourceEmbedded;
diff --git a/frontend/src/app/features/hal/resources/work-package-timestamp-resource.ts b/frontend/src/app/features/hal/resources/work-package-timestamp-resource.ts
new file mode 100644
index 00000000000..532b9008f49
--- /dev/null
+++ b/frontend/src/app/features/hal/resources/work-package-timestamp-resource.ts
@@ -0,0 +1,53 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2023 the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See COPYRIGHT and LICENSE files for more details.
+//++
+
+import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+
+export interface IWorkPackageTimestampMeta {
+ exists:boolean;
+ matchesFilters:boolean;
+ timestamp:string;
+}
+
+export class IWorkPackageTimestamp extends HalResource {
+ startDate?:string;
+ dueDate?:string;
+ date?:string;
+ _meta:IWorkPackageTimestampMeta;
+ $links:{
+ schema?:HalResource;
+ self:HalResource;
+ status?:HalResource;
+ assignee?:HalResource;
+ accountable?:HalResource;
+ project?:HalResource;
+ type?:HalResource;
+ priority?:HalResource;
+ version?:HalResource;
+ }
+}
diff --git a/frontend/src/app/features/work-packages/components/wp-fast-table/builders/baseline/baseline-column-builder.ts b/frontend/src/app/features/work-packages/components/wp-fast-table/builders/baseline/baseline-column-builder.ts
index 9b50d1effd4..f8ae0486b48 100644
--- a/frontend/src/app/features/work-packages/components/wp-fast-table/builders/baseline/baseline-column-builder.ts
+++ b/frontend/src/app/features/work-packages/components/wp-fast-table/builders/baseline/baseline-column-builder.ts
@@ -1,6 +1,5 @@
import { Injector } from '@angular/core';
import {
- IWorkPackageTimestamp,
WorkPackageResource,
} from 'core-app/features/hal/resources/work-package-resource';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
@@ -13,6 +12,7 @@ import { WorkPackageViewColumnsService } from 'core-app/features/work-packages/r
import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
import { ISchemaProxy } from 'core-app/features/hal/schemas/schema-proxy';
import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { IWorkPackageTimestamp } from 'core-app/features/hal/resources/work-package-timestamp-resource';
export const baselineCellName = 'wp-table--baseline-cell-td';
diff --git a/frontend/src/app/features/work-packages/components/wp-fast-table/builders/cell-builder.ts b/frontend/src/app/features/work-packages/components/wp-fast-table/builders/cell-builder.ts
index d3f2eb197f2..a7da3f804cd 100644
--- a/frontend/src/app/features/work-packages/components/wp-fast-table/builders/cell-builder.ts
+++ b/frontend/src/app/features/work-packages/components/wp-fast-table/builders/cell-builder.ts
@@ -1,4 +1,6 @@
-import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
+import {
+ WorkPackageResource,
+} from 'core-app/features/hal/resources/work-package-resource';
import {
DisplayFieldRenderer,
editFieldContainerClass,
@@ -7,6 +9,8 @@ import { Injector } from '@angular/core';
import { QueryColumn } from 'core-app/features/work-packages/components/wp-query/query-column';
import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
+import { IWorkPackageTimestamp } from 'core-app/features/hal/resources/work-package-timestamp-resource';
+import { WorkPackageViewBaselineService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service';
export const tdClassName = 'wp-table--cell-td';
export const editCellContainer = 'wp-table--cell-container';
@@ -14,6 +18,8 @@ export const editCellContainer = 'wp-table--cell-container';
export class CellBuilder {
@InjectField(SchemaCacheService) schemaCache:SchemaCacheService;
+ @InjectField(WorkPackageViewBaselineService) wpTableBaseline:WorkPackageViewBaselineService;
+
public fieldRenderer = new DisplayFieldRenderer(this.injector, 'table');
constructor(public injector:Injector) {
@@ -28,17 +34,23 @@ export class CellBuilder {
td.classList.add('-max');
}
- if ([ 'startDate', 'dueDate', 'duration' ].indexOf(attribute) !== -1) {
+ if (['startDate', 'dueDate', 'duration'].indexOf(attribute) !== -1) {
td.classList.add('-no-ellipsis');
}
- const schema = this.schemaCache.of(workPackage).ofProperty(attribute);
- if (schema && schema.type === 'User') {
+ const schema = this.schemaCache.of(workPackage);
+ const fieldSchema = schema.ofProperty(attribute);
+ if (fieldSchema && fieldSchema.type === 'User') {
td.classList.add('-contains-avatar');
}
const container = document.createElement('span');
container.classList.add(editCellContainer, editFieldContainerClass, attribute);
+
+ if (attribute !== 'id' && this.wpTableBaseline.isActive()) {
+ this.prependChanges(container, workPackage, schema.mappedName(attribute));
+ }
+
const displayElement = this.fieldRenderer.render(workPackage, attribute, null);
container.appendChild(displayElement);
@@ -53,4 +65,24 @@ export class CellBuilder {
container.innerHTML = '';
container.appendChild(displayElement);
}
+
+ private prependChanges(
+ container:HTMLElement,
+ workPackage:WorkPackageResource,
+ attribute:string,
+ ):void {
+ const timestamps = workPackage.attributesByTimestamp || [];
+ if (timestamps.length <= 1) {
+ return;
+ }
+
+ const base = timestamps[0];
+ if (base[attribute as keyof IWorkPackageTimestamp]) {
+ base.$links.schema = workPackage.$links.schema;
+ const span = this.fieldRenderer.render(base, attribute, null);
+ span.classList.add('op-table-baseline--old-value');
+ container.classList.add('op-table-baseline--cell');
+ container.appendChild(span);
+ }
+ }
}
diff --git a/frontend/src/app/features/work-packages/components/wp-table/wp-table.directive.html b/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html
similarity index 100%
rename from frontend/src/app/features/work-packages/components/wp-table/wp-table.directive.html
rename to frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html
diff --git a/frontend/src/app/features/work-packages/components/wp-table/wp-table.styles.sass b/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.sass
similarity index 100%
rename from frontend/src/app/features/work-packages/components/wp-table/wp-table.styles.sass
rename to frontend/src/app/features/work-packages/components/wp-table/wp-table.component.sass
diff --git a/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts b/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts
index 367ef8bbba9..8d6b5aa3106 100644
--- a/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts
+++ b/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts
@@ -26,13 +26,20 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import { input, InputState } from '@openproject/reactivestates';
+import {
+ input,
+ InputState,
+} from '@openproject/reactivestates';
import { take } from 'rxjs/operators';
import { SchemaResource } from 'core-app/features/hal/resources/schema-resource';
import { FormResource } from 'core-app/features/hal/resources/form-resource';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
-import { ChangeItem, ChangeMap, Changeset } from 'core-app/shared/components/fields/changeset/changeset';
+import {
+ ChangeItem,
+ ChangeMap,
+ Changeset,
+} from 'core-app/shared/components/fields/changeset/changeset';
import { IFieldSchema } from 'core-app/shared/components/fields/field.base';
import { debugLog } from 'core-app/shared/helpers/debug_output';
import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
@@ -77,9 +84,11 @@ export class ResourceChangeset<T extends HalResource = HalResource> {
* */
protected schemaCache:SchemaCacheService;
- constructor(pristineResource:T,
+ constructor(
+ pristineResource:T,
public readonly state?:InputState<ResourceChangeset<T>>,
- loadedForm:FormResource|null = null) {
+ loadedForm:FormResource|null = null,
+ ) {
this.updatePristineResource(pristineResource);
this.schemaCache = (pristineResource.injector).get(SchemaCacheService);
diff --git a/frontend/src/global_styles/layout/work_packages/_table_baseline.sass b/frontend/src/global_styles/layout/work_packages/_table_baseline.sass
index 5c72b43590f..e18475c53e9 100644
--- a/frontend/src/global_styles/layout/work_packages/_table_baseline.sass
+++ b/frontend/src/global_styles/layout/work_packages/_table_baseline.sass
@@ -32,3 +32,13 @@
&--icon-changed
color: #54AFE0
+
+ &--old-value
+ color: var(--body-font-color) !important
+ text-decoration: line-through
+
+ &--cell
+ background-color: #f3f3f3
+ display: flex !important
+ flex-direction: column
+