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

add a function to get the baseline state into the baseline helper

bsatarnejad9847fd8d4fde
diff --git a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts
index 3fd1ba4d18a..da9dd83b237 100644
--- a/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts
+++ b/frontend/src/app/features/work-packages/components/wp-baseline/baseline-helpers.ts
@@ -1,5 +1,10 @@
+import { IWorkPackageTimestamp } from 'core-app/features/hal/resources/work-package-timestamp-resource';
+import { ISchemaProxy } from 'core-app/features/hal/schemas/schema-proxy';
import { DEFAULT_TIMESTAMP } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service';
import * as moment from 'moment-timezone';
+import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
+import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
+import { WorkPackageViewColumnsService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-columns.service';
export type BaselineOption = 'oneDayAgo'|'lastWorkingDay'|'oneWeekAgo'|'oneMonthAgo'|'aSpecificDate'|'betweenTwoSpecificDates';
@@ -46,3 +51,32 @@ export function getPartsFromTimestamp(value:string):BaselineTimestamp|null {
return null;
}
+
+export function visibleAttributeChanged(base:IWorkPackageTimestamp, schema:ISchemaProxy, wpTableColumns:WorkPackageViewColumnsService):boolean {
+ return !!wpTableColumns
+ .getColumns()
+ .find((column) => {
+ const name = schema.mappedName(column.id);
+ return Object.prototype.hasOwnProperty.call(base, name) || Object.prototype.hasOwnProperty.call(base.$links, name);
+ });
+}
+
+export function getBaselineState(workPackage:WorkPackageResource, schemaService:SchemaCacheService, wpTableColumns:WorkPackageViewColumnsService):string {
+ let state = '';
+ const schema = schemaService.of(workPackage);
+ const timestamps = workPackage.attributesByTimestamp || [];
+ if (timestamps.length > 1) {
+ const base = timestamps[0];
+ const compare = timestamps[1];
+ if ((!base._meta.exists && compare._meta.exists) || (!base._meta.matchesFilters && compare._meta.matchesFilters)) {
+ state = 'added';
+ } else if ((base._meta.exists && !compare._meta.exists) || (base._meta.matchesFilters && !compare._meta.matchesFilters)) {
+ state = 'removed';
+ } else if (visibleAttributeChanged(base, schema, wpTableColumns)) {
+ state = 'updated';
+ }
+ } else {
+ state = '';
+ }
+ return state;
+}