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 persisted from HalResource (#9566)
Benjamin Bädorfc153906ba969
diff --git a/frontend/src/app/features/hal/helpers/is-persisted-resource.ts b/frontend/src/app/features/hal/helpers/is-persisted-resource.tsnew file mode 100644index 00000000000..e51d875c3d5--- /dev/null+++ b/frontend/src/app/features/hal/helpers/is-persisted-resource.ts@@ -0,0 +1,3 @@+export default function isPersistedResource(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 f43ef9eafbe..cdff507843a 100644--- a/frontend/src/app/features/hal/resources/hal-resource.ts+++ b/frontend/src/app/features/hal/resources/hal-resource.ts@@ -161,10 +161,6 @@ export class HalResource {return !this.id || this.id === 'new';}- public get persisted() {- 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,diff --git a/frontend/src/app/features/work-packages/components/wp-query/url-params-helper.ts b/frontend/src/app/features/work-packages/components/wp-query/url-params-helper.tsindex 2bd393d5055..9a9376241c7 100644--- a/frontend/src/app/features/work-packages/components/wp-query/url-params-helper.ts+++ b/frontend/src/app/features/work-packages/components/wp-query/url-params-helper.ts@@ -30,6 +30,7 @@ import { QueryResource } from 'core-app/features/hal/resources/query-resource';import { QuerySortByResource } from 'core-app/features/hal/resources/query-sort-by-resource';import { HalLink } from 'core-app/features/hal/hal-link/hal-link';import idFromLink from 'core-app/features/hal/helpers/id-from-link';+import isPersistedResource from 'core-app/features/hal/helpers/is-persisted-resource';import { Injectable } from '@angular/core';import { QueryFilterInstanceResource } from 'core-app/features/hal/resources/query-filter-instance-resource';import { ApiV3Filter, FilterOperator } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';@@ -100,7 +101,7 @@ export class UrlParamsHelperService {}private encodeHighlightingMode(paramsData:any, query:QueryResource) {- if (query.highlightingMode && (query.persisted || query.highlightingMode !== 'inline')) {+ if (query.highlightingMode && (isPersistedResource(query) || query.highlightingMode !== 'inline')) {paramsData.hl = query.highlightingMode;}return paramsData;diff --git a/frontend/src/app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts b/frontend/src/app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.tsindex 969041170cf..5a04667eec3 100644--- a/frontend/src/app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts+++ b/frontend/src/app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts@@ -46,6 +46,7 @@ import { I18nService } from 'core-app/core/i18n/i18n.service';import { OpModalService } from 'core-app/shared/components/modal/modal.service';import { InviteUserModalComponent } from 'core-app/features/invite-user-modal/invite-user.component';import { WorkPackageFilterContainerComponent } from 'core-app/features/work-packages/components/filters/filter-container/filter-container.directive';+import isPersistedResource from 'core-app/features/hal/helpers/is-persisted-resource';export interface DynamicComponentDefinition {component:ComponentType<any>;@@ -206,7 +207,7 @@ export class PartitionedQuerySpacePageComponent extends WorkPackagesViewBase imp}public changeChangesFromTitle(val:string) {- if (this.currentQuery && this.currentQuery.persisted) {+ if (this.currentQuery && isPersistedResource(this.currentQuery)) {this.updateTitleName(val);} else {this.wpListService@@ -230,7 +231,7 @@ export class PartitionedQuerySpacePageComponent extends WorkPackagesViewBase impreturn;}- if (query.persisted) {+ if (isPersistedResource(query)) {this.selectedTitle = query.name;} else {this.selectedTitle = this.wpStaticQueries.getStaticName(query);diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-order.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-order.service.tsindex a7b9adb54af..37c7b0e99c6 100644--- a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-order.service.ts+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-order.service.ts@@ -26,17 +26,18 @@// See docs/COPYRIGHT.rdoc for more details.//++-import { QueryResource } from 'core-app/features/hal/resources/query-resource';import { Injectable } from '@angular/core';+import { take } from 'rxjs/operators';+import { InputState } from 'reactivestates';+import { States } from 'core-app/core/states/states.service';import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';-import { States } from 'core-app/core/states/states.service';+import { QueryResource } from 'core-app/features/hal/resources/query-resource';import { QuerySchemaResource } from 'core-app/features/hal/resources/query-schema-resource';import { WorkPackageCollectionResource } from 'core-app/features/hal/resources/wp-collection-resource';+import isPersistedResource from 'core-app/features/hal/helpers/is-persisted-resource';import { MAX_ORDER, buildDelta } from 'core-app/shared/helpers/drag-and-drop/reorder-delta-builder';-import { take } from 'rxjs/operators';-import { InputState } from 'reactivestates';import { WorkPackageViewSortByService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-sort-by.service';import { CausedUpdatesService } from 'core-app/features/boards/board/caused-updates/caused-updates.service';import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';@@ -56,7 +57,7 @@ export class WorkPackageViewOrderService extends WorkPackageQueryStateService<Qupublic initialize(query:QueryResource, results:WorkPackageCollectionResource, schema?:QuerySchemaResource):Promise<unknown> {// Take over our current value if the query is not saved- if (!query.persisted && this.positions.hasValue()) {+ if (!isPersistedResource(query) && this.positions.hasValue()) {this.applyToQuery(query);}@@ -108,7 +109,7 @@ export class WorkPackageViewOrderService extends WorkPackageQueryStateService<Qu}public get applicable() {- return this.currentQuery.persisted;+ return isPersistedResource(this.currentQuery);}protected get currentQuery():QueryResource {@@ -140,7 +141,7 @@ export class WorkPackageViewOrderService extends WorkPackageQueryStateService<Quthis.positions.putValue({ ...current, ...delta });// Push the update if the query is saved- if (this.currentQuery.persisted) {+ if (isPersistedResource(this.currentQuery)) {const updatedAt = await this.apiV3Service.queries.id(this.currentQuery)@@ -164,7 +165,7 @@ export class WorkPackageViewOrderService extends WorkPackageQueryStateService<Qu* Initialize (or load if persisted) the order for the query space*/public withLoadedPositions():Promise<QueryOrder> {- if (this.currentQuery.persisted) {+ if (isPersistedResource(this.currentQuery)) {const { value } = this.positions;// Remove empty or stale values given we can reload them@@ -205,7 +206,7 @@ export class WorkPackageViewOrderService extends WorkPackageQueryStateService<Qu.elements.map((wp) => this.states.workPackages.get(wp.id!).getValueOr(wp));- if (this.currentQuery.persisted || this.positions.isPristine()) {+ if (isPersistedResource(this.currentQuery) || this.positions.isPristine()) {return upstreamOrder;}const positions = this.positions.value!;diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-sort-by.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-sort-by.service.tsindex fb2f72554ec..48c8d86d36e 100644--- a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-sort-by.service.ts+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-sort-by.service.ts@@ -26,14 +26,15 @@// See docs/COPYRIGHT.rdoc for more details.//++-import { States } from 'core-app/core/states/states.service';import { combine } from 'reactivestates';import { mapTo } from 'rxjs/operators';-import { QueryResource } from 'core-app/features/hal/resources/query-resource';-import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';import { Injectable } from '@angular/core';import { Observable } from 'rxjs';+import { QueryResource } from 'core-app/features/hal/resources/query-resource';+import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';+import { States } from 'core-app/core/states/states.service';import { QuerySortByResource } from 'core-app/features/hal/resources/query-sort-by-resource';+import isPersistedResource from 'core-app/features/hal/helpers/is-persisted-resource';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { QueryColumn } from 'core-app/features/work-packages/components/wp-query/query-column';import { WorkPackageQueryStateService } from './wp-view-base.service';@@ -122,7 +123,7 @@ export class WorkPackageViewSortByService extends WorkPackageQueryStateService<Qpublic switchToManualSorting(query:QueryResource):boolean {const { manualSortObject } = this;if (manualSortObject && !this.isManualSortingMode) {- if (query && query.persisted) {+ if (query && isPersistedResource(query)) {// Save the query if it is persistedquery.sortBy = [manualSortObject];return true;diff --git a/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts b/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.tsindex b20191886a4..04e4792eec0 100644--- a/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts+++ b/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts@@ -47,6 +47,7 @@ import { QuerySharingModalComponent } from 'core-app/shared/components/modals/shimport { WpTableExportModalComponent } from 'core-app/shared/components/modals/export-modal/wp-table-export.modal';import { SaveQueryModalComponent } from 'core-app/shared/components/modals/save-modal/save-query.modal';import { QueryFormResource } from 'core-app/features/hal/resources/query-form-resource';+import isPersistedResource from 'core-app/features/hal/helpers/is-persisted-resource';@Directive({selector: '[opSettingsContextMenu]',@@ -231,7 +232,7 @@ export class OpSettingsMenuDirective extends OpContextMenuTrigger {icon: 'icon-save',onClick: ($event:JQuery.TriggeredEvent) => {const { query } = this;- if (!query.persisted && this.allowQueryAction($event, 'updateImmediately')) {+ if (!isPersistedResource(query) && this.allowQueryAction($event, 'updateImmediately')) {this.opModalService.show(SaveQueryModalComponent, this.injector);} else if (query.id && this.allowQueryAction($event, 'updateImmediately')) {this.wpListService.save(query);