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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Remove isNew from HalResource (#9563)
Benjamin Bädorf64f2074484fd
diff --git a/frontend/src/app/core/apiv3/endpoints/work_packages/work-package.cache.ts b/frontend/src/app/core/apiv3/endpoints/work_packages/work-package.cache.tsindex e2e6e386673..6134701983c 100644--- a/frontend/src/app/core/apiv3/endpoints/work_packages/work-package.cache.ts+++ b/frontend/src/app/core/apiv3/endpoints/work_packages/work-package.cache.ts@@ -33,6 +33,7 @@ import { debugLog } from 'core-app/shared/helpers/debug_output';import { StateCacheService } from 'core-app/core/apiv3/cache/state-cache.service';import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';@Injectable()export class WorkPackageCache extends StateCacheService<WorkPackageResource> {@@ -51,22 +52,22 @@ export class WorkPackageCache extends StateCacheService<WorkPackageResource> {}updateWorkPackage(wp:WorkPackageResource, immediate = false):Promise<WorkPackageResource> {- if (immediate || wp.isNew) {+ if (immediate || isNewResource(wp)) {return super.updateValue(wp.id!, wp);}return this.updateValue(wp.id!, wp);}updateWorkPackageList(list:WorkPackageResource[], skipOnIdentical = true) {- for (const i of list) {+ list.forEach((i) => {const wp = i;const workPackageId = wp.id!;const state = this.multiState.get(workPackageId);// If the work package is new, ignore the schema- if (wp.isNew) {+ if (isNewResource(wp)) {state.putValue(wp);- continue;+ return;}// Ensure the schema is loaded@@ -80,6 +81,6 @@ export class WorkPackageCache extends StateCacheService<WorkPackageResource> {state.putValue(wp);});- }+ });}}diff --git a/frontend/src/app/features/bim/bcf/bcf-wp-attribute-group/bcf-new-wp-attribute-group.component.ts b/frontend/src/app/features/bim/bcf/bcf-wp-attribute-group/bcf-new-wp-attribute-group.component.tsindex c6302ece102..c16d29bba4a 100644--- a/frontend/src/app/features/bim/bcf/bcf-wp-attribute-group/bcf-new-wp-attribute-group.component.ts+++ b/frontend/src/app/features/bim/bcf/bcf-wp-attribute-group/bcf-new-wp-attribute-group.component.ts@@ -5,6 +5,7 @@ import { WorkPackageResource } from 'core-app/features/hal/resources/work-packagimport { forkJoin } from 'rxjs';import { BcfViewpointInterface } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint.interface';import { BcfViewpointItem } from 'core-app/features/bim/bcf/api/viewpoints/bcf-viewpoint-item.interface';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';@Component({templateUrl: './bcf-wp-attribute-group.component.html',@@ -19,7 +20,7 @@ export class BcfNewWpAttributeGroupComponent extends BcfWpAttributeGroupComponensuper.ngAfterViewInit();// Save any leftover viewpoints when saving the work package- if (this.workPackage.isNew) {+ if (isNewResource(this.workPackage)) {this.observeCreation();}}diff --git a/frontend/src/app/features/bim/bcf/openproject-bcf.module.ts b/frontend/src/app/features/bim/bcf/openproject-bcf.module.tsindex 8a27c6a83af..f27dc77194e 100644--- a/frontend/src/app/features/bim/bcf/openproject-bcf.module.ts+++ b/frontend/src/app/features/bim/bcf/openproject-bcf.module.ts@@ -45,6 +45,7 @@ import { BcfNewWpAttributeGroupComponent } from 'core-app/features/bim/bcf/bcf-wimport { RevitBridgeService } from 'core-app/features/bim/revit_add_in/revit-bridge.service';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';import { OpenProjectHeaderInterceptor } from 'core-app/features/hal/http/openproject-header-interceptor';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';import { RefreshButtonComponent } from 'core-app/features/bim/ifc_models/toolbar/import-export-bcf/refresh-button.component';/**@@ -118,7 +119,7 @@ export class OpenprojectBcfModule {return;}- if (workPackage.isNew) {+ if (isNewResource(workPackage)) {return BcfNewWpAttributeGroupComponent;}return BcfWpAttributeGroupComponent;diff --git a/frontend/src/app/features/hal/helpers/is-new-resource.ts b/frontend/src/app/features/hal/helpers/is-new-resource.tsnew file mode 100644index 00000000000..d7f29ef0e23--- /dev/null+++ b/frontend/src/app/features/hal/helpers/is-new-resource.ts@@ -0,0 +1,3 @@+export default function isNewResource(resource:{ id:string|null }):boolean {+ return !resource.id || resource.id === 'new';+}diff --git a/frontend/src/app/features/hal/resources/hal-resource.ts b/frontend/src/app/features/hal/resources/hal-resource.tsindex cdff507843a..91da5ed02a1 100644--- a/frontend/src/app/features/hal/resources/hal-resource.ts+++ b/frontend/src/app/features/hal/resources/hal-resource.ts@@ -34,6 +34,7 @@ import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decoraimport { HalLinkInterface } from 'core-app/features/hal/hal-link/hal-link';import { ICKEditorContext } from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';import idFromLink from 'core-app/features/hal/helpers/id-from-link';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';export interface HalResourceClass<T extends HalResource = HalResource> {new(injector:Injector,@@ -157,10 +158,6 @@ export class HalResource {this.$source.id = val;}- public get isNew():boolean {- return !this.id || this.id === 'new';- }-/*** Retain the internal tracking identifier from the given other work package.* This is due to us needing to identify a work package beyond its actual ID,@@ -227,7 +224,7 @@ export class HalResource {}public previewPath():string|undefined {- if (this.isNew && this.project) {+ if (isNewResource(this) && this.project) {return this.project.href;}diff --git a/frontend/src/app/features/hal/resources/mixins/attachable-mixin.ts b/frontend/src/app/features/hal/resources/mixins/attachable-mixin.tsindex ee5f98594a6..94f730b330a 100644--- a/frontend/src/app/features/hal/resources/mixins/attachable-mixin.ts+++ b/frontend/src/app/features/hal/resources/mixins/attachable-mixin.ts@@ -36,6 +36,7 @@ import { OpenProjectDirectFileUploadService } from 'core-app/core/file-upload/opimport { OpenProjectFileUploadService, UploadFile } from 'core-app/core/file-upload/op-file-upload.service';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { AttachmentCollectionResource } from 'core-app/features/hal/resources/attachment-collection-resource';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';type Constructor<T = {}> = new (...args:any[]) => T;@@ -70,7 +71,7 @@ export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {* adding attachments is allowed.*/public get canAddAttachments():boolean {- return !!this.$links.addAttachment || this.isNew;+ return !!this.$links.addAttachment || isNewResource(this);}/**@@ -182,7 +183,7 @@ export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {if (href) {return this.opDirectFileUpload.uploadAndMapResponse(href, files);- } if (this.isNew || !this.id || !this.attachmentsBackend) {+ } if (isNewResource(this) || !this.id || !this.attachmentsBackend) {href = this.apiV3Service.attachments.path;} else {href = this.addAttachment.$link.href;@@ -196,7 +197,7 @@ export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {return this.$links.prepareAttachment.href;}- if (this.isNew) {+ if (isNewResource(this)) {return this.config.prepareAttachmentURL;}return null;diff --git a/frontend/src/app/features/hal/resources/work-package-resource.spec.ts b/frontend/src/app/features/hal/resources/work-package-resource.spec.tsindex 1e12a3b0a94..5504c01054b 100644--- a/frontend/src/app/features/hal/resources/work-package-resource.spec.ts+++ b/frontend/src/app/features/hal/resources/work-package-resource.spec.ts@@ -48,6 +48,7 @@ import { TimezoneService } from 'core-app/core/datetime/timezone.service';import { AttachmentCollectionResource } from 'core-app/features/hal/resources/attachment-collection-resource';import { OpenprojectHalModule } from 'core-app/features/hal/openproject-hal.module';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';describe('WorkPackage', () => {let halResourceService:HalResourceService;@@ -107,8 +108,8 @@ describe('WorkPackage', () => {expect(workPackage.attachments).toEqual(jasmine.any(AttachmentCollectionResource));});- it('should return true for `isNew`', () => {- expect(workPackage.isNew).toBeTruthy();+ it('should return true for `isNewResource`', () => {+ expect(isNewResource(workPackage)).toBeTruthy();});});diff --git a/frontend/src/app/features/hal/resources/work-package-resource.ts b/frontend/src/app/features/hal/resources/work-package-resource.tsindex a43f60b5fcf..2848c033871 100644--- a/frontend/src/app/features/hal/resources/work-package-resource.ts+++ b/frontend/src/app/features/hal/resources/work-package-resource.ts@@ -44,6 +44,7 @@ import { RelationResource } from 'core-app/features/hal/resources/relation-resouimport { 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';export interface WorkPackageResourceEmbedded {activities:CollectionResource;@@ -167,7 +168,7 @@ export class WorkPackageBaseResource extends HalResource {* Return "<subject> (#<id>)" if the id is known.*/public subjectWithId(truncateSubject = 40):string {- const id = this.isNew ? '' : ` (#${this.id})`;+ const id = isNewResource(this) ? '' : ` (#${this.id})`;const subject = _.truncate(this.subject, { length: truncateSubject });return `${subject}${id}`;@@ -179,7 +180,7 @@ export class WorkPackageBaseResource extends HalResource {}public previewPath() {- if (!this.isNew) {+ if (!isNewResource(this)) {return this.apiV3Service.work_packages.id(this.id!).path;}return super.previewPath();diff --git a/frontend/src/app/features/hal/schemas/schema-proxy.ts b/frontend/src/app/features/hal/schemas/schema-proxy.tsindex 5c69e2c02be..43cc31b8159 100644--- a/frontend/src/app/features/hal/schemas/schema-proxy.ts+++ b/frontend/src/app/features/hal/schemas/schema-proxy.ts@@ -29,6 +29,7 @@import { SchemaResource } from 'core-app/features/hal/resources/schema-resource';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { IFieldSchema } from 'core-app/shared/components/fields/field.base';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';export interface ISchemaProxy extends SchemaResource {ofProperty(property:string):IFieldSchema;@@ -108,7 +109,7 @@ export class SchemaProxy implements ProxyHandler<SchemaResource> {* Use +isAttributeEditable(property)+ for this case.*/public get isEditable() {- return this.resource.isNew || !!this.resource.$links.update;+ return isNewResource(this.resource) || !!this.resource.$links.update;}public mappedName(property:string):string {diff --git a/frontend/src/app/features/work-packages/components/wp-card-view/services/wp-card-drag-and-drop.service.ts b/frontend/src/app/features/work-packages/components/wp-card-view/services/wp-card-drag-and-drop.service.tsindex 3ba0e3f5442..1513999d41d 100644--- a/frontend/src/app/features/work-packages/components/wp-card-view/services/wp-card-drag-and-drop.service.ts+++ b/frontend/src/app/features/work-packages/components/wp-card-view/services/wp-card-drag-and-drop.service.ts@@ -11,6 +11,7 @@ import { WorkPackageChangeset } from 'core-app/features/work-packages/componentsimport { APIV3Service } from 'core-app/core/apiv3/api-v3.service';import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';@Injectable()export class WorkPackageCardDragAndDropService {@@ -110,7 +111,7 @@ export class WorkPackageCardDragAndDropService {*/public set workPackages(workPackages:WorkPackageResource[]) {if (this.activeInlineCreateWp) {- const existingNewWp = this._workPackages.find((o) => o.isNew);+ const existingNewWp = this._workPackages.find((o) => isNewResource(o));// If there is already a card for a new WP,// we have to replace this one by the new activeInlineCreateWp@@ -130,7 +131,7 @@ export class WorkPackageCardDragAndDropService {*/private get currentOrder():string[] {return this.workPackages- .filter((wp) => wp && !wp.isNew)+ .filter((wp) => wp && !isNewResource(wp)).map((el) => el.id!);}@@ -196,7 +197,7 @@ export class WorkPackageCardDragAndDropService {this.workPackages.splice(index, 1);this.activeInlineCreateWp = undefined;- if (!wp.isNew) {+ if (!isNewResource(wp)) {const newOrder = this.reorderService.remove(this.currentOrder, wp.id!);this.updateOrder(newOrder);}diff --git a/frontend/src/app/features/work-packages/components/wp-card-view/wp-card-view.component.html b/frontend/src/app/features/work-packages/components/wp-card-view/wp-card-view.component.htmlindex ec9996cd1e6..89f0c8a3e72 100644--- a/frontend/src/app/features/work-packages/components/wp-card-view/wp-card-view.component.html+++ b/frontend/src/app/features/work-packages/components/wp-card-view/wp-card-view.component.html@@ -11,7 +11,7 @@<ng-container *ngFor="let wp of workPackages; trackBy:trackByHref"><wp-single-card [workPackage]="wp"- [attr.data-is-new]="wp.isNew || undefined"+ [attr.data-is-new]="isNewResource(wp) || undefined"[attr.data-work-package-id]="wp.id"[attr.data-class-identifier]="cardView.classIdentifier(wp)"[showInfoButton]="showInfoButton"diff --git a/frontend/src/app/features/work-packages/components/wp-card-view/wp-card-view.component.ts b/frontend/src/app/features/work-packages/components/wp-card-view/wp-card-view.component.tsindex 10a0111f26d..a75099bd3db 100644--- a/frontend/src/app/features/work-packages/components/wp-card-view/wp-card-view.component.ts+++ b/frontend/src/app/features/work-packages/components/wp-card-view/wp-card-view.component.ts@@ -40,6 +40,7 @@ import { QueryColumn } from 'core-app/features/work-packages/components/wp-queryimport { QueryResource } from 'core-app/features/hal/resources/query-resource';import { HalEventsService } from 'core-app/features/hal/services/hal-events.service';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';export type CardViewOrientation = 'horizontal'|'vertical';@@ -117,6 +118,8 @@ export class WorkPackageCardViewComponent extends UntilDestroyedMixin implementsonReferenced: (wp:WorkPackageResource) => this.cardDragDrop.addWorkPackageToQuery(wp, 0),};+ isNewResource = isNewResource;+constructor(readonly querySpace:IsolatedQuerySpace,readonly states:States,readonly injector:Injector,diff --git a/frontend/src/app/features/work-packages/components/wp-card-view/wp-single-card/wp-single-card.component.html b/frontend/src/app/features/work-packages/components/wp-card-view/wp-single-card/wp-single-card.component.htmlindex 87925de6c9c..b80701c1543 100644--- a/frontend/src/app/features/work-packages/components/wp-card-view/wp-single-card/wp-single-card.component.html+++ b/frontend/src/app/features/work-packages/components/wp-card-view/wp-single-card/wp-single-card.component.html@@ -15,7 +15,7 @@type="button"class="op-link op-wp-single-card--details-button"data-qa-selector="op-wp-single-card--details-button"- *ngIf="!workPackage.isNew && showInfoButton"+ *ngIf="!isNewResource(workPackage) && showInfoButton"[title]="text.detailsView"(click)="emitStateLinkClicked($event, workPackage, true)"><op-icon icon-classes="icon icon-info2"></op-icon>@@ -23,16 +23,16 @@<buttonclass="op-link op-wp-single-card--inline-cancel-button"data-qa-selector="op-wp-single-card--inline-cancel-button"- *ngIf="workPackage.isNew || showRemoveButton"- [class.-show]="workPackage.isNew"+ *ngIf="isNewResource(workPackage) || showRemoveButton"+ [class.-show]="isNewResource(workPackage)"[title]="text.removeCard"(click)="onRemoved(workPackage)"><op-icon icon-classes="icon icon-close"></op-icon></button></div><edit-form [resource]="workPackage"- [inEditMode]="workPackage.isNew"- *ngIf="workPackage.isNew">+ [inEditMode]="isNewResource(workPackage)"+ *ngIf="isNewResource(workPackage)"><div class="op-wp-single-card-content -new"><editable-attribute-field [resource]="workPackage"[wrapperClasses]="'work-packages--type-selector'"@@ -46,7 +46,7 @@</div></edit-form>- <div *ngIf="!workPackage.isNew"+ <div *ngIf="!isNewResource(workPackage)"class="op-wp-single-card--content"><span [textContent]="wpProjectName(workPackage)"class="op-wp-single-card--content-project-name">diff --git a/frontend/src/app/features/work-packages/components/wp-card-view/wp-single-card/wp-single-card.component.ts b/frontend/src/app/features/work-packages/components/wp-card-view/wp-single-card/wp-single-card.component.tsindex c0204e80451..bbb6edfda88 100644--- a/frontend/src/app/features/work-packages/components/wp-card-view/wp-single-card/wp-single-card.component.ts+++ b/frontend/src/app/features/work-packages/components/wp-card-view/wp-single-card/wp-single-card.component.ts@@ -20,6 +20,7 @@ import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destrimport { WorkPackageViewFocusService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-focus.service';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';import { isClickedWithModifier } from 'core-app/shared/helpers/link-handling/link-handling';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';@Component({selector: 'wp-single-card',@@ -55,6 +56,8 @@ export class WorkPackageSingleCardComponent extends UntilDestroyedMixin implemendetailsView: this.I18n.t('js.button_open_details'),};+ isNewResource = isNewResource;+constructor(readonly pathHelper:PathHelperService,readonly I18n:I18nService,readonly $state:StateService,@@ -97,7 +100,7 @@ export class WorkPackageSingleCardComponent extends UntilDestroyedMixin implemenconst base = 'op-wp-single-card'let classes = this.isSelected(this.workPackage) ? checkedClassName : '';classes += this.draggable ? ` ${base}_draggable` : '';- classes += this.workPackage.isNew ? ` ${base}_new` : '';+ classes += isNewResource(this.workPackage) ? ` ${base}_new` : '';classes += ` ${base}-${this.workPackage.id}`;classes += ` ${base}_${this.orientation}`;classes += this.shrinkOnMobile ? ` ${base}_shrink` : '';diff --git a/frontend/src/app/features/work-packages/components/wp-edit/work-package-changeset.ts b/frontend/src/app/features/work-packages/components/wp-edit/work-package-changeset.tsindex dbf558329f4..c3951ee57a6 100644--- a/frontend/src/app/features/work-packages/components/wp-edit/work-package-changeset.ts+++ b/frontend/src/app/features/work-packages/components/wp-edit/work-package-changeset.ts@@ -2,6 +2,7 @@ import { WorkPackageResource } from 'core-app/features/hal/resources/work-packagimport { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';import { SchemaResource } from 'core-app/features/hal/resources/schema-resource';import { WorkPackageSchemaProxy } from 'core-app/features/hal/schemas/work-package-schema-proxy';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';export class WorkPackageChangeset extends ResourceChangeset<WorkPackageResource> {public setValue(key:string, val:any) {@@ -24,7 +25,7 @@ export class WorkPackageChangeset extends ResourceChangeset<WorkPackageResource>protected setNewDefaultFor(key:string, val:unknown) {// Special handling for taking over the description// to the pristine resource- if (key === 'description' && this.pristineResource.isNew) {+ if (key === 'description' && isNewResource(this.pristineResource)) {this.pristineResource.description = val;return;}diff --git a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.ts b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.tsindex f43ee20f0a4..270901c4777 100644--- a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.ts+++ b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.ts@@ -50,6 +50,7 @@ import { randomString } from 'core-app/shared/helpers/random-string';import { BrowserDetector } from 'core-app/core/browser/browser-detector.service';import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';import idFromLink from 'core-app/features/hal/helpers/id-from-link';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';import { States } from 'core-app/core/states/states.service';@@ -132,6 +133,8 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen$element:JQuery;+ isNewResource = isNewResource;+constructor(readonly I18n:I18nService,protected currentProject:CurrentProjectService,protected PathHelper:PathHelperService,@@ -180,7 +183,7 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemenprivate refresh(change:WorkPackageChangeset) {// Prepare the fields that are required always- const { isNew } = this.workPackage;+ const isNew = isNewResource(this.workPackage);const resource = change.projectedResource;if (!resource.project) {@@ -210,7 +213,7 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemenconst isEmpty = group.members.length === 0;// Is a query in a new screen- const queryInNew = this.workPackage.isNew && !!group.query;+ const queryInNew = isNewResource(this.workPackage) && !!group.query;return isEmpty || queryInNew;}diff --git a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.html b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.htmlindex a2b3f1779a1..42fb7b622ff 100644--- a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.html+++ b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.html@@ -2,22 +2,22 @@class="work-package--single-view"[ngClass]="{'-can-have-columns' : enableTwoColumnLayout }"><div class="wp-new--subject-wrapper"- *ngIf="workPackage.isNew">+ *ngIf="isNewResource(workPackage)"><editable-attribute-field [resource]="workPackage"[wrapperClasses]="'-no-label'"[fieldName]="'subject'"></editable-attribute-field></div><div class="wp-info-wrapper">- <wp-status-button *ngIf="!workPackage.isNew"+ <wp-status-button *ngIf="!isNewResource(workPackage)"[workPackage]="workPackage"></wp-status-button><attribute-help-text [attribute]="'status'"[attributeScope]="'WorkPackage'"- *ngIf="!workPackage.isNew"></attribute-help-text>+ *ngIf="!isNewResource(workPackage)"></attribute-help-text><div class="work-packages--info-row"- *ngIf="!workPackage.isNew">+ *ngIf="!isNewResource(workPackage)"><span [textContent]="idLabel"></span>:<span [textContent]="text.infoRow.createdBy"></span><!-- The space has to be in an extra span@@ -58,7 +58,10 @@</div></div>- <div class="attributes-group -project-context hide-when-print" *ngIf="!workPackage.isNew && projectContext && !projectContext.matches">+ <div+ class="attributes-group -project-context hide-when-print"+ *ngIf="!isNewResource(workPackage) && projectContext && !projectContext.matches"+ ><div><p><span [innerHTML]="projectContextText"></span>diff --git a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts b/frontend/src/app/features/work-packages/openproject-work-packages.module.tsindex 127098fcfc9..e6ec03a6d91 100644--- a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts+++ b/frontend/src/app/features/work-packages/openproject-work-packages.module.ts@@ -171,6 +171,7 @@ import { WorkPackageFilterByTextInputComponent } from 'core-app/features/work-paimport { FilterIntegerValueComponent } from 'core-app/features/work-packages/components/filters/filter-integer-value/filter-integer-value.component';import { WorkPackageFilterContainerComponent } from 'core-app/features/work-packages/components/filters/filter-container/filter-container.directive';import { FilterBooleanValueComponent } from 'core-app/features/work-packages/components/filters/filter-boolean-value/filter-boolean-value.component';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';@NgModule({imports: [@@ -445,9 +446,9 @@ export class OpenprojectWorkPackagesModule {hookService.register('attributeGroupComponent', (group:GroupDescriptor, workPackage:WorkPackageResource) => {if (group.type === 'WorkPackageFormAttributeGroup') {return WorkPackageFormAttributeGroupComponent;- } if (!workPackage.isNew && group.type === 'WorkPackageFormChildrenQueryGroup') {+ } if (!isNewResource(workPackage) && group.type === 'WorkPackageFormChildrenQueryGroup') {return WorkPackageChildrenQueryComponent;- } if (!workPackage.isNew && group.type === 'WorkPackageFormRelationQueryGroup') {+ } if (!isNewResource(workPackage) && group.type === 'WorkPackageFormRelationQueryGroup') {return WorkPackageRelationQueryComponent;}return null;diff --git a/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts b/frontend/src/app/shared/components/fields/changeset/resource-changeset.tsindex 1f048da1be4..ed3bfb7b233 100644--- a/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts+++ b/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts@@ -8,6 +8,7 @@ import { debugLog } from 'core-app/shared/helpers/debug_output';import { take } from 'rxjs/operators';import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';import { SchemaProxy } from 'core-app/features/hal/schemas/schema-proxy';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';export const PROXY_IDENTIFIER = '__is_changeset_proxy';@@ -368,7 +369,7 @@ export class ResourceChangeset<T extends HalResource = HalResource> {protected buildPayloadFromChanges() {let payload;- if (this.pristineResource.isNew) {+ if (isNewResource(this.pristineResource)) {// If the resource is new, we need to pass the entire form payload// to let all default values be transmitted (type, status, etc.)// We clone the object to avoid later manipulations to affect the original resource.diff --git a/frontend/src/app/shared/components/fields/display/field-types/id-display-field.module.ts b/frontend/src/app/shared/components/fields/display/field-types/id-display-field.module.tsindex 74532065c8a..a28c94e0a87 100644--- a/frontend/src/app/shared/components/fields/display/field-types/id-display-field.module.ts+++ b/frontend/src/app/shared/components/fields/display/field-types/id-display-field.module.ts@@ -27,6 +27,7 @@//++import { DisplayField } from 'core-app/shared/components/fields/display/display-field.module';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';export class IdDisplayField extends DisplayField {public text = {@@ -34,7 +35,7 @@ export class IdDisplayField extends DisplayField {};public get value() {- if (this.resource.isNew) {+ if (isNewResource(this.resource)) {return null;}return this.resource[this.name];diff --git a/frontend/src/app/shared/components/fields/edit/edit-form/edit-form.ts b/frontend/src/app/shared/components/fields/edit/edit-form/edit-form.tsindex 976761809c6..9f7a331c029 100644--- a/frontend/src/app/shared/components/fields/edit/edit-form/edit-form.ts+++ b/frontend/src/app/shared/components/fields/edit/edit-form/edit-form.ts@@ -40,6 +40,7 @@ import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/rimport { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';import { ErrorResource } from 'core-app/features/hal/resources/error-resource';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';export const activeFieldContainerClassName = 'inline-edit--active-field';export const activeFieldClassName = 'inline-edit--field';@@ -159,7 +160,7 @@ export abstract class EditForm<T extends HalResource = HalResource> {* @return {any}*/public async submit():Promise<T> {- if (this.change.isEmpty() && !this.resource.isNew) {+ if (this.change.isEmpty() && !isNewResource(this.resource)) {this.closeEditFields();return Promise.resolve(this.resource);}diff --git a/frontend/src/app/shared/components/fields/edit/field-types/formattable-edit-field/formattable-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/formattable-edit-field/formattable-edit-field.component.tsindex 68f052ed98d..75e30f17dc5 100644--- a/frontend/src/app/shared/components/fields/edit/field-types/formattable-edit-field/formattable-edit-field.component.ts+++ b/frontend/src/app/shared/components/fields/edit/field-types/formattable-edit-field/formattable-edit-field.component.ts@@ -34,6 +34,7 @@ import {ICKEditorContext,ICKEditorInstance,} from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';@Component({templateUrl: './formattable-edit-field.component.html',@@ -77,7 +78,7 @@ export class FormattableEditFieldComponent extends EditFieldComponent implements}public onCkeditorSetup(editor:ICKEditorInstance):void {- if (!this.resource.isNew) {+ if (!isNewResource(this.resource)) {setTimeout(() => editor.editing.view.focus());}}@@ -137,7 +138,7 @@ export class FormattableEditFieldComponent extends EditFieldComponent implementsprotected initialize():void {this.initialContent = this.rawValue;- if (this.resource.isNew && this.editor) {+ if (isNewResource(this.resource) && this.editor) {// Reset CKEditor when reloading after type/form changesthis.reset();}diff --git a/frontend/src/app/shared/components/fields/edit/services/hal-resource-editing.service.ts b/frontend/src/app/shared/components/fields/edit/services/hal-resource-editing.service.tsindex d5cd0d8455c..54da9ce69d4 100644--- a/frontend/src/app/shared/components/fields/edit/services/hal-resource-editing.service.ts+++ b/frontend/src/app/shared/components/fields/edit/services/hal-resource-editing.service.ts@@ -39,6 +39,7 @@ import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { HookService } from 'core-app/features/plugins/hook-service';import { HalEventsService } from 'core-app/features/hal/services/hal-events.service';import { StateCacheService } from 'core-app/core/apiv3/cache/state-cache.service';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';class ChangesetStates extends StatesGroup {name = 'Changesets';@@ -81,7 +82,7 @@ export class ResourceChangesetCommit<T extends HalResource = HalResource> {*/constructor(change:ResourceChangeset<T>, saved:T) {this.id = saved.id!.toString();- this.wasNew = change.pristineResource.isNew;+ this.wasNew = isNewResource(change.pristineResource);this.resource = saved;this.changes = change.changeMap;}diff --git a/frontend/src/app/shared/components/op-context-menu/handlers/wp-status-dropdown-menu.directive.ts b/frontend/src/app/shared/components/op-context-menu/handlers/wp-status-dropdown-menu.directive.tsindex 856b88bbe9a..f163d3498f5 100644--- a/frontend/src/app/shared/components/op-context-menu/handlers/wp-status-dropdown-menu.directive.ts+++ b/frontend/src/app/shared/components/op-context-menu/handlers/wp-status-dropdown-menu.directive.ts@@ -40,6 +40,7 @@ import { I18nService } from 'core-app/core/i18n/i18n.service';import { NotificationsService } from 'core-app/shared/components/notifications/notifications.service';import { HalEventsService } from 'core-app/features/hal/services/hal-events.service';import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';@Directive({selector: '[wpStatusDropdown]',@@ -85,7 +86,7 @@ export class WorkPackageStatusDropdownDirective extends OpContextMenuTrigger {const change = this.halEditing.changeFor(this.workPackage);change.projectedResource.status = status;- if (!this.workPackage.isNew) {+ if (!isNewResource(this.workPackage)) {this.halEditing.save(change).then(() => {diff --git a/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive.ts b/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive.tsindex 93b8fc576f6..c7437ca3e82 100644--- a/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive.ts+++ b/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-view-context-menu.directive.ts@@ -20,6 +20,7 @@ import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decoraimport { TimeEntryCreateService } from 'core-app/shared/components/time_entries/create/create.service';import { splitViewRoute } from 'core-app/features/work-packages/routing/split-view-routes.helper';import { WpDestroyModalComponent } from 'core-app/shared/components/modals/wp-destroy-modal/wp-destroy.modal';+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';export class WorkPackageViewContextMenu extends OpContextMenuHandler {@InjectField() protected states!:States;@@ -167,7 +168,7 @@ export class WorkPackageViewContextMenu extends OpContextMenuHandler {},}));- if (!this.workPackage.isNew) {+ if (!isNewResource(this.workPackage)) {items.unshift({disabled: false,icon: 'icon-view-fullscreen',