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
Use combined schema for combined date field
ulferts8805ea74c9f1
diff --git a/frontend/src/app/components/filters/filter-integer-value/filter-integer-value.component.ts b/frontend/src/app/components/filters/filter-integer-value/filter-integer-value.component.tsindex 87e7d194c93..5231816a7ce 100644--- a/frontend/src/app/components/filters/filter-integer-value/filter-integer-value.component.ts+++ b/frontend/src/app/components/filters/filter-integer-value/filter-integer-value.component.ts@@ -34,6 +34,7 @@ import {I18nService} from 'core-app/modules/common/i18n/i18n.service';import {DebouncedEventEmitter} from 'core-components/angular/debounced-event-emitter';import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";import {componentDestroyed} from "@w11k/ngx-componentdestroyed";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";@Component({selector: 'filter-integer-value',@@ -44,7 +45,8 @@ export class FilterIntegerValueComponent extends UntilDestroyedMixin {@Input() public filter:QueryFilterInstanceResource;@Output() public filterChanged = new DebouncedEventEmitter<QueryFilterInstanceResource>(componentDestroyed(this));- constructor(readonly I18n:I18nService) {+ constructor(readonly I18n:I18nService,+ readonly schemaCache:SchemaCacheService) {super();}@@ -63,7 +65,7 @@ export class FilterIntegerValueComponent extends UntilDestroyedMixin {}public get unit() {- switch ((this.filter.schema.filter.allowedValues as QueryFilterResource[])[0].id) {+ switch ((this.schema.filter.allowedValues as QueryFilterResource[])[0].id) {case 'startDate':case 'dueDate':case 'updatedAt':@@ -73,4 +75,8 @@ export class FilterIntegerValueComponent extends UntilDestroyedMixin {return '';}}++ private get schema() {+ return this.schemaCache.of(this.filter);+ }}diff --git a/frontend/src/app/components/filters/query-filter/query-filter.component.ts b/frontend/src/app/components/filters/query-filter/query-filter.component.tsindex 0a143cfbd25..3a495b51053 100644--- a/frontend/src/app/components/filters/query-filter/query-filter.component.ts+++ b/frontend/src/app/components/filters/query-filter/query-filter.component.ts@@ -28,12 +28,12 @@import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';import {I18nService} from 'core-app/modules/common/i18n/i18n.service';-import {WorkPackageFiltersService} from 'core-components/filters/wp-filters/wp-filters.service';import {QueryFilterResource} from 'core-app/modules/hal/resources/query-filter-resource';import {AngularTrackingHelpers} from 'core-components/angular/tracking-functions';import {QueryFilterInstanceResource} from "core-app/modules/hal/resources/query-filter-instance-resource";import {BannersService} from "core-app/modules/common/enterprise/banners.service";import {WorkPackageViewFiltersService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";@Component({selector: '[query-filter]',@@ -61,7 +61,7 @@ export class QueryFilterComponent implements OnInit {};constructor(readonly wpTableFilters:WorkPackageViewFiltersService,- readonly wpFiltersService:WorkPackageFiltersService,+ readonly schemaCache:SchemaCacheService,readonly I18n:I18nService,readonly bannerService:BannersService) {}@@ -86,7 +86,7 @@ export class QueryFilterComponent implements OnInit {ngOnInit() {this.eeShowBanners = this.bannerService.eeShowBanners;- this.availableOperators = this.filter.schema.availableOperators;+ this.availableOperators = this.schemaCache.of(this.filter).availableOperators;this.showValuesInput = this.filter.currentSchema!.isValueRequired();}}diff --git a/frontend/src/app/components/filters/query-filters/query-filters.component.ts b/frontend/src/app/components/filters/query-filters/query-filters.component.tsindex 093e7f8a53d..c8e148d595a 100644--- a/frontend/src/app/components/filters/query-filters/query-filters.component.ts+++ b/frontend/src/app/components/filters/query-filters/query-filters.component.ts@@ -132,7 +132,7 @@ export class QueryFiltersComponent extends UntilDestroyedMixin implements OnInit}private updateFilterFocus(index:number) {- var activeFilterCount = this.currentFilterLength();+ let activeFilterCount = this.currentFilterLength();if (activeFilterCount === 0) {this.focusElementIndex = ADD_FILTER_SELECT_INDEX;diff --git a/frontend/src/app/components/schemas/schema-cache.service.ts b/frontend/src/app/components/schemas/schema-cache.service.tsindex cc9d2438fb4..18dfcb844b4 100644--- a/frontend/src/app/components/schemas/schema-cache.service.ts+++ b/frontend/src/app/components/schemas/schema-cache.service.ts@@ -25,16 +25,18 @@//// See docs/COPYRIGHT.rdoc for more details.// ++-import {InputState, MultiInputState, State} from 'reactivestates';+import {MultiInputState, State} from 'reactivestates';import {States} from '../states.service';import {HalResource} from "core-app/modules/hal/resources/hal-resource";import {Injectable} from '@angular/core';import {SchemaResource} from 'core-app/modules/hal/resources/schema-resource';import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';import {StateCacheService} from "core-components/states/state-cache.service";+import {ISchemaProxy, SchemaProxy} from "core-app/modules/hal/schemas/schema-proxy";+import {WorkPackageSchemaProxy} from "core-app/modules/hal/schemas/work-package-schema-proxy";@Injectable()-export class SchemaCacheService extends StateCacheService<SchemaResource>{+export class SchemaCacheService extends StateCacheService<SchemaResource> {constructor(readonly states:States,readonly halResourceService:HalResourceService) {@@ -42,15 +44,28 @@ export class SchemaCacheService extends StateCacheService<SchemaResource>{}public state(id:string|HalResource):State<SchemaResource> {- let href:string;+ return super.state(this.stateKey(id));+ }- if (id instanceof HalResource) {- href = this.getSchemaHref(id);- } else {- href = id;+ /**+ * Returns the schema of the provided resource.+ * This method assumes the schema is loaded and will fail if it is not.+ * @deprecated Assuming the schema to be loaded is deprecated. Rely on the states instead.+ * @param resource The HalResource for which the schema is to be returned+ * @return The schema for the HalResource+ */+ of(resource:HalResource):ISchemaProxy {+ let schema = this.state(resource).value;++ if (!schema) {+ throw `Schema for resource ${resource} was expected to be loaded but isn't.`;}- return super.state(href);+ if (resource._type === 'WorkPackage') {+ return WorkPackageSchemaProxy.create(schema, resource);+ } else {+ return SchemaProxy.create(schema, resource);+ }}public getSchemaHref(resource:HalResource):string {@@ -89,4 +104,22 @@ export class SchemaCacheService extends StateCacheService<SchemaResource>{protected get multiState():MultiInputState<SchemaResource> {return this.states.schemas;}++ /**+ * Places the schema in the schema state of the resource.+ * @param resource The resource for which the schema is to be updated+ * @param schema+ */+ update(resource:HalResource, schema:SchemaResource) {+ this.multiState.get(this.stateKey(resource)).putValue(schema);+ }++ private stateKey(id:string|HalResource):string {+ if (id instanceof HalResource) {+ return this.getSchemaHref(id);+ } else {+ return id;+ }+ }}+diff --git a/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.component.ts b/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.component.tsindex 1c1a05e97ca..5b6260e8840 100644--- a/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.component.ts+++ b/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.component.ts@@ -55,6 +55,8 @@ import {randomString} from "core-app/helpers/random-string";import {BrowserDetector} from "core-app/modules/common/browser/browser-detector.service";import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import {ISchemaProxy} from "core-app/modules/hal/schemas/schema-proxy";export interface FieldDescriptor {name:string;@@ -139,6 +141,7 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemenprotected halResourceService:HalResourceService,protected displayFieldService:DisplayFieldService,protected wpCacheService:WorkPackageCacheService,+ protected schemaCache:SchemaCacheService,protected hook:HookService,protected injector:Injector,protected cdRef:ChangeDetectorRef,@@ -192,11 +195,11 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen}if (isNew && !this.currentProject.inProjectContext) {- this.projectContext.field = this.getFields(resource, ['project']);+ this.projectContext.field = this.getFields(change, ['project']);}- const attributeGroups = resource.schema._attributeGroups;- this.groupedFields = this.rebuildGroupedFields(resource, attributeGroups);+ const attributeGroups = this.schema(resource)._attributeGroups;+ this.groupedFields = this.rebuildGroupedFields(change, attributeGroups);this.cdRef.detectChanges();}@@ -270,12 +273,7 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemenreturn this.workPackage.isNew && !this.browserDetector.isEdge;}- /**- *- * @param attributeGroups- * @returns {any}- */- private rebuildGroupedFields(resource:WorkPackageResource, attributeGroups:any) {+ private rebuildGroupedFields(change:WorkPackageChangeset, attributeGroups:any) {if (!attributeGroups) {return [];}@@ -287,7 +285,7 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemenreturn {name: group.name,id: groupId || randomString(16),- members: this.getFields(resource, group.attributes),+ members: this.getFields(change, group.attributes),type: group._type,isolated: false};@@ -309,21 +307,21 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen* Maps the grouped fields into their display fields.* May return multiple fields (for the date virtual field).*/- private getFields(resource:WorkPackageResource, fieldNames:string[]):FieldDescriptor[] {+ private getFields(change:WorkPackageChangeset, fieldNames:string[]):FieldDescriptor[] {const descriptors:FieldDescriptor[] = [];fieldNames.forEach((fieldName:string) => {if (fieldName === 'date') {- descriptors.push(this.getDateField(resource));+ descriptors.push(this.getDateField(change));return;}- if (!resource.schema[fieldName]) {+ if (!change.schema.ofProperty(fieldName)) {debugLog('Unknown field for current schema', fieldName);return;}- const field:DisplayField = this.displayField(resource, fieldName);+ const field:DisplayField = this.displayField(change, fieldName);descriptors.push({name: fieldName,label: field.label,@@ -341,18 +339,18 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen* 'date' field vs. all other types which should display a* combined 'start' and 'due' date field.*/- private getDateField(resource:WorkPackageResource):FieldDescriptor {+ private getDateField(change:WorkPackageChangeset):FieldDescriptor {let object:any = {label: this.I18n.t('js.work_packages.properties.date'),multiple: false};- if (resource.schema.hasOwnProperty('date')) {- object.field = this.displayField(resource, 'date');+ if (change.schema.ofProperty('date')) {+ object.field = this.displayField(change, 'date');object.name = 'date';} else {- object.field = this.displayField(resource, 'startDate');- object.name = 'startDate';+ object.field = this.displayField(change, 'combinedDate');+ object.name = 'combinedDate';}return object;@@ -367,7 +365,7 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen* @returns {SchemaContext}*/private contextFrom(workPackage:WorkPackageResource):ResourceContextChange {- let schema = workPackage.schema;+ let schema = this.schema(workPackage);let schemaHref:string|null = null;let projectHref:string|null = workPackage.project && workPackage.project.href;@@ -386,11 +384,11 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen};}- private displayField(resource:WorkPackageResource, name:string):DisplayField {+ private displayField(change:WorkPackageChangeset, name:string):DisplayField {return this.displayFieldService.getField(- resource,+ change.projectedResource,name,- resource.schema[name],+ change.schema.ofProperty(name),{ container: 'single-view', injector: this.injector, options: {} }) as DisplayField;}@@ -406,4 +404,12 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemenreturn '';}}++ private schema(resource:WorkPackageResource) {+ if (this.halEditing.typedState(resource).hasValue()) {+ return this.halEditing.typedState(this.workPackage).value!.schema;+ } else {+ return this.schemaCache.of(resource) as ISchemaProxy;+ }+ }}diff --git a/frontend/src/app/components/wp-buttons/wp-status-button/wp-status-button.component.ts b/frontend/src/app/components/wp-buttons/wp-status-button/wp-status-button.component.tsindex 1eebd796b74..6f1e7367396 100644--- a/frontend/src/app/components/wp-buttons/wp-status-button/wp-status-button.component.ts+++ b/frontend/src/app/components/wp-buttons/wp-status-button/wp-status-button.component.ts@@ -37,6 +37,8 @@ import {WorkPackageCacheService} from "core-components/work-packages/work-packagimport {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";import {concatAll} from "rxjs/operators";import {combineLatest} from "rxjs";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import {ISchemaProxy, SchemaProxy} from "core-app/modules/hal/schemas/schema-proxy";@Component({selector: 'wp-status-button',@@ -56,6 +58,7 @@ export class WorkPackageStatusButtonComponent extends UntilDestroyedMixin implemconstructor(readonly I18n:I18nService,readonly cdRef:ChangeDetectorRef,readonly wpCacheService:WorkPackageCacheService,+ readonly schemaCache:SchemaCacheService,readonly halEditing:HalResourceEditingService) {super();}@@ -79,9 +82,9 @@ export class WorkPackageStatusButtonComponent extends UntilDestroyedMixin implem}public get buttonTitle() {- if (this.workPackage.isReadonly) {+ if (this.schema.isReadonly) {return this.text.workPackageReadOnly;- } else if (this.workPackage.isEditable && !this.allowed) {+ } else if (this.schema.isEditable && !this.allowed) {return this.text.workPackageStatusBlocked;} else {return '';@@ -100,7 +103,19 @@ export class WorkPackageStatusButtonComponent extends UntilDestroyedMixin implemreturn this.workPackage.status;}+ public get isReadonly() {+ return this.schema.isReadonly;+ }+public get allowed() {- return this.workPackage.isAttributeEditable('status');+ return this.schema.isAttributeEditable('status');+ }++ private get schema() {+ if (this.halEditing.typedState(this.workPackage).hasValue()) {+ return this.halEditing.typedState(this.workPackage).value!.schema;+ } else {+ return this.schemaCache.of(this.workPackage) as ISchemaProxy;+ }}}diff --git a/frontend/src/app/components/wp-buttons/wp-status-button/wp-status-button.html b/frontend/src/app/components/wp-buttons/wp-status-button/wp-status-button.htmlindex c4f720560a9..95ce417b2f9 100644--- a/frontend/src/app/components/wp-buttons/wp-status-button/wp-status-button.html+++ b/frontend/src/app/components/wp-buttons/wp-status-button/wp-status-button.html@@ -9,7 +9,7 @@wpStatusDropdown[wpStatusDropdown-workPackage]="workPackage">- <span *ngIf="workPackage.isReadonly"+ <span *ngIf="isReadonly"class="button--text"><op-icon icon-classes="button--icon icon-locked"></op-icon></span>diff --git a/frontend/src/app/components/wp-edit-form/display-field-renderer.ts b/frontend/src/app/components/wp-edit-form/display-field-renderer.tsindex 4a2206ab388..cb031d7b03b 100644--- a/frontend/src/app/components/wp-edit-form/display-field-renderer.ts+++ b/frontend/src/app/components/wp-edit-form/display-field-renderer.ts@@ -10,6 +10,10 @@ import {ResourceChangeset} from "core-app/modules/fields/changeset/resource-chanimport {HalResource} from "core-app/modules/hal/resources/hal-resource";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";import {CombinedDateDisplayField} from "core-app/modules/fields/display/field-types/combined-date-display.field";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";+import {ISchemaProxy} from "core-app/modules/hal/schemas/schema-proxy";+import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";export const editableClassName = '-editable';export const requiredClassName = '-required';@@ -22,6 +26,8 @@ export const cellEmptyPlaceholder = '-';export class DisplayFieldRenderer<T extends HalResource = HalResource> {@InjectField() displayFieldService:DisplayFieldService;+ @InjectField() schemaCache:SchemaCacheService;+ @InjectField() halEditing:HalResourceEditingService;@InjectField() I18n:I18nService;/** We cache the previously used fields to avoid reinitialization */@@ -43,7 +49,7 @@ export class DisplayFieldRenderer<T extends HalResource = HalResource> {return span;}- this.setSpanAttributes(span, field, name, resource);+ this.setSpanAttributes(span, field, name, resource, change);return span;}@@ -53,8 +59,9 @@ export class DisplayFieldRenderer<T extends HalResource = HalResource> {change:ResourceChangeset<T>|null,placeholder?:string):[DisplayField|null, HTMLSpanElement] {const span = document.createElement('span');- const schemaName = this.getSchemaName(resource, change, name);- const fieldSchema = resource.schema[schemaName];+ const schema = this.schema(resource, change);+ const attributeName = this.attributeName(name, schema);+ const fieldSchema = schema.ofProperty(name);// If the resource does not have that field, return an empty// span (e.g., for the table).@@ -62,14 +69,14 @@ export class DisplayFieldRenderer<T extends HalResource = HalResource> {return [null, span];}- const field = this.getField(resource, fieldSchema, schemaName, change);+ const field = this.getField(resource, fieldSchema, attributeName, change);field.render(span, this.getText(field, fieldSchema, placeholder), fieldSchema.options);const title = field.title;if (title) {span.setAttribute('title', title);}- span.setAttribute('aria-label', this.getAriaLabel(field, resource));+ span.setAttribute('aria-label', this.getAriaLabel(field, schema));return [field, span];}@@ -104,7 +111,7 @@ export class DisplayFieldRenderer<T extends HalResource = HalResource> {}// In the single view, start and end date are shown in a combined date field- if (this.container === 'single-view' && (name === 'startDate')) {+ if (this.container === 'single-view' && (name === 'combinedDate')) {return new CombinedDateDisplayField(name, context) as DisplayField;}@@ -124,7 +131,7 @@ export class DisplayFieldRenderer<T extends HalResource = HalResource> {}}- private setSpanAttributes(span:HTMLElement, field:DisplayField, name:string, resource:T):void {+ private setSpanAttributes(span:HTMLElement, field:DisplayField, name:string, resource:T, change:ResourceChangeset<T>|null):void {span.classList.add(displayClassName, name);span.dataset['fieldName'] = name;@@ -139,7 +146,7 @@ export class DisplayFieldRenderer<T extends HalResource = HalResource> {span.classList.add(placeholderClassName);}- if (field.writable) {+ if (this.schema(resource, change).isAttributeEditable(name)) {span.classList.add(editableClassName);span.setAttribute('role', 'button');} else {@@ -147,7 +154,7 @@ export class DisplayFieldRenderer<T extends HalResource = HalResource> {}}- private getAriaLabel(field:DisplayField, resource:T):string {+ private getAriaLabel(field:DisplayField, schema:SchemaResource):string {let titleContent;let labelContent = this.getLabelContent(field);@@ -163,7 +170,7 @@ export class DisplayFieldRenderer<T extends HalResource = HalResource> {titleContent = labelContent;}- if (field.writable && resource.isAttributeEditable(field.name)) {+ if (field.writable && schema.isAttributeEditable(field.name)) {return this.I18n.t('js.inplace.button_edit', {attribute: `${field.displayName} ${titleContent}`});} else {return `${field.displayName} ${titleContent}`;@@ -179,23 +186,18 @@ export class DisplayFieldRenderer<T extends HalResource = HalResource> {}/**- * Get the schema name from either the changeset, the resource (if available) or+ * Get the attribute name from either the schema if the mappedName method is implemented or* return the attribute itself.*- * @param resource- * @param change- * @param name+ * @param schema+ * @param attribute*/- private getSchemaName(resource:T, change:ResourceChangeset<T>|null, name:string) {- if (change) {- return change.getSchemaName(name);- }-- if (!!resource.getSchemaName) {- return resource.getSchemaName(name);+ private attributeName(attribute:string, schema:SchemaResource) {+ if (schema.mappedName) {+ return schema.mappedName(attribute);+ } else {+ return attribute;}-- return name;}private getDefaultPlaceholder(fieldSchema:IFieldSchema):string {@@ -205,4 +207,14 @@ export class DisplayFieldRenderer<T extends HalResource = HalResource> {return cellEmptyPlaceholder;}++ private schema(resource:T, change:ResourceChangeset<T>|null) {+ if (!!change) {+ return change.schema;+ } else if (this.halEditing.typedState(resource).hasValue()) {+ return this.halEditing.typedState(resource).value!.schema;+ } else {+ return this.schemaCache.of(resource) as ISchemaProxy;+ }+ }}diff --git a/frontend/src/app/components/wp-edit/work-package-changeset.ts b/frontend/src/app/components/wp-edit/work-package-changeset.tsindex f0195c95b08..e0306009a49 100644--- a/frontend/src/app/components/wp-edit/work-package-changeset.ts+++ b/frontend/src/app/components/wp-edit/work-package-changeset.ts@@ -1,5 +1,7 @@import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";import {ResourceChangeset} from "core-app/modules/fields/changeset/resource-changeset";+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";+import { WorkPackageSchemaProxy } from 'core-app/modules/hal/schemas/work-package-schema-proxy';export class WorkPackageChangeset extends ResourceChangeset<WorkPackageResource> {@@ -31,5 +33,16 @@ export class WorkPackageChangeset extends ResourceChangeset<WorkPackageResource>super.setNewDefaultFor(key, val);}-+ /**+ * Get the best schema currently available, either the default resource schema (must exist).+ * If loaded, return the form schema, which provides better information on writable status+ * and contains available values.+ */+ public get schema():SchemaResource {+ if (this.form$.hasValue()) {+ return WorkPackageSchemaProxy.create(super.schema, this.projectedResource);+ } else {+ return super.schema;+ }+ }}diff --git a/frontend/src/app/components/wp-fast-table/builders/cell-builder.ts b/frontend/src/app/components/wp-fast-table/builders/cell-builder.tsindex 9d0fc943522..19a0c7cd543 100644--- a/frontend/src/app/components/wp-fast-table/builders/cell-builder.ts+++ b/frontend/src/app/components/wp-fast-table/builders/cell-builder.ts@@ -5,11 +5,15 @@ import {} from '../../wp-edit-form/display-field-renderer';import {Injector} from '@angular/core';import {QueryColumn} from "core-components/wp-query/query-column";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";export const tdClassName = 'wp-table--cell-td';export const editCellContainer = 'wp-table--cell-container';export class CellBuilder {+ @InjectField(SchemaCacheService) schemaCache:SchemaCacheService;+public fieldRenderer = new DisplayFieldRenderer(this.injector, 'table');constructor(public injector:Injector) {@@ -24,7 +28,7 @@ export class CellBuilder {td.classList.add('-max');}- const schema = workPackage.schema[attribute];+ const schema = this.schemaCache.of(workPackage).ofProperty(attribute);if (schema && schema.type === 'User') {td.classList.add('-contains-avatar');}diff --git a/frontend/src/app/components/wp-form-group/wp-attribute-group.component.ts b/frontend/src/app/components/wp-form-group/wp-attribute-group.component.tsindex 062974330fb..47f8f7cf462 100644--- a/frontend/src/app/components/wp-form-group/wp-attribute-group.component.ts+++ b/frontend/src/app/components/wp-form-group/wp-attribute-group.component.ts@@ -41,7 +41,7 @@ export class WorkPackageFormAttributeGroupComponent {@Input() public group:GroupDescriptor;constructor(readonly I18n:I18nService,- public wpeditForm:EditFormComponent,+ public wpEditForm:EditFormComponent,protected injector:Injector) {}@@ -55,6 +55,14 @@ export class WorkPackageFormAttributeGroupComponent {*/public shouldHideField(descriptor:FieldDescriptor) {const field = descriptor.field || descriptor.fields![0];- return this.wpeditForm.editMode && !field.writable;+ return this.wpEditForm.editMode && !field.writable;+ }++ public fieldName(name:string) {+ if (name === 'startDate') {+ return 'combinedDate';+ } else {+ return name;+ }}}diff --git a/frontend/src/app/components/wp-form-group/wp-attribute-group.template.html b/frontend/src/app/components/wp-form-group/wp-attribute-group.template.htmlindex d96fde77695..a8c38b424f8 100644--- a/frontend/src/app/components/wp-form-group/wp-attribute-group.template.html+++ b/frontend/src/app/components/wp-form-group/wp-attribute-group.template.html@@ -16,15 +16,10 @@<div *ngIf="!descriptor.multiple && descriptor.field"class="attributes-key-value--value-container">- <editable-attribute-field *ngIf="descriptor.field!.isFormattable"- class="wp-edit-formattable-field"- [resource]="workPackage"- [isDropTarget]="true"- [fieldName]="descriptor.name">- </editable-attribute-field>- <editable-attribute-field *ngIf="!descriptor.field.isFormattable"- [resource]="workPackage"- [fieldName]="descriptor.name">+ <editable-attribute-field [ngClass]="{'wp-edit-formattable-field': descriptor.field!.isFormattable }"+ [resource]="workPackage"+ [isDropTarget]="descriptor.field!.isFormattable"+ [fieldName]="fieldName(descriptor.name)"></editable-attribute-field></div></ng-template>diff --git a/frontend/src/app/components/wp-inline-create/wp-inline-create.component.ts b/frontend/src/app/components/wp-inline-create/wp-inline-create.component.tsindex a8309c3adae..6f7f470ea87 100644--- a/frontend/src/app/components/wp-inline-create/wp-inline-create.component.ts+++ b/frontend/src/app/components/wp-inline-create/wp-inline-create.component.ts@@ -58,6 +58,7 @@ import {WorkPackageChangeset} from "core-components/wp-edit/work-package-changesimport {EditForm} from "core-app/modules/fields/edit/edit-form/edit-form";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";import {componentDestroyed} from "@w11k/ngx-componentdestroyed";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";@Component({selector: '[wpInlineCreate]',@@ -89,7 +90,7 @@ export class WorkPackageInlineCreateComponent extends UntilDestroyedMixin implemconstructor(public readonly injector:Injector,protected readonly elementRef:ElementRef,- protected readonly FocusHelper:FocusHelperService,+ protected readonly schemaCache:SchemaCacheService,protected readonly I18n:I18nService,protected readonly querySpace:IsolatedQuerySpace,protected readonly cdRef:ChangeDetectorRef,@@ -228,7 +229,7 @@ export class WorkPackageInlineCreateComponent extends UntilDestroyedMixin implemif (!this.isActive) {this.insertRow(wp);} else {- this.currentWorkPackage!.overriddenSchema = form!.schema;+ this.schemaCache.update(this.currentWorkPackage!, form!.schema);this.refreshRow();}});diff --git a/frontend/src/app/components/wp-new/wp-create.service.ts b/frontend/src/app/components/wp-new/wp-create.service.tsindex 6174143246c..74a87508dc9 100644--- a/frontend/src/app/components/wp-new/wp-create.service.ts+++ b/frontend/src/app/components/wp-new/wp-create.service.ts@@ -46,6 +46,7 @@ import {FormResource} from "core-app/modules/hal/resources/form-resource";import {HalEventsService} from "core-app/modules/hal/services/hal-events.service";import {AuthorisationService} from "core-app/modules/common/model-auth/model-auth.service";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";export const newWorkPackageHref = '/api/v3/work_packages/new';@@ -63,6 +64,7 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {protected querySpace:IsolatedQuerySpace,protected authorisationService:AuthorisationService,protected halEditing:HalResourceEditingService,+ protected schemaCache:SchemaCacheService,protected workPackageDmService:WorkPackageDmService,protected halEvents:HalEventsService) {super();@@ -110,8 +112,7 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {}public fromCreateForm(form:FormResource):WorkPackageChangeset {- let wp = this.halResourceService.createHalResourceOfType<WorkPackageResource>('WorkPackage', form.payload.$plain());- wp.initializeNewResource(form);+ let wp = this.initializeNewResource(form);const change = this.halEditing.edit<WorkPackageResource, WorkPackageChangeset>(wp, form);@@ -139,10 +140,7 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {* @param form Work Package create form*/private copyFrom(form:FormResource) {- //let wp = fromCreateForm(form);- let wp = this.halResourceService.createHalResourceOfType<WorkPackageResource>('WorkPackage', form.payload.$plain());-- wp.initializeNewResource(form);+ let wp = this.initializeNewResource(form);return this.halEditing.edit(wp, form);}@@ -249,4 +247,40 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {filter.applyDefaultsFromFilters();}}++ /**+ * Assign values from the form for a newly created work package resource.+ * @param form+ */+ private initializeNewResource(form:FormResource) {+ let payload = form.payload.$plain();++ // maintain the reference to the schema+ payload['_links']['schema'] = { href: 'new' };++ let wp = this.halResourceService.createHalResourceOfType<WorkPackageResource>('WorkPackage', payload);++ wp.$source.id = 'new';++ // Ensure type is set to identify the resource+ wp._type = 'WorkPackage';++ // Since the ID will change upon saving, keep track of the WP+ // with the actual creation date+ wp.__initialized_at = Date.now();++ // Set update link to form+ wp['update'] = wp.$links.update = form.$links.self;+ // Use POST /work_packages for saving link+ wp['updateImmediately'] = wp.$links.updateImmediately = (payload) => {+ return this.workPackageDmService.createWorkPackage(payload);+ };++ // We need to provide the schema to the cache so that it is available in the html form to e.g. determine+ // the editability.+ // It would be better if the edit field could simply rely on the changeset if it exists.+ this.schemaCache.update(wp, form.schema);++ return wp;+ }}diff --git a/frontend/src/app/components/wp-query/query-filters.service.ts b/frontend/src/app/components/wp-query/query-filters.service.tsindex 6883c7f8118..3eb2613c038 100644--- a/frontend/src/app/components/wp-query/query-filters.service.ts+++ b/frontend/src/app/components/wp-query/query-filters.service.ts@@ -1,29 +1,45 @@import {Injectable} from "@angular/core";import {QueryFormResource} from "core-app/modules/hal/resources/query-form-resource";-import {QueryFilterInstanceSchemaResource} from "core-app/modules/hal/resources/query-filter-instance-schema-resource";+import {+ QueryFilterInstanceSchemaResource,+ QueryFilterInstanceSchemaResourceLinks+} from "core-app/modules/hal/resources/query-filter-instance-schema-resource";import {QueryResource} from "core-app/modules/hal/resources/query-resource";import {QueryFilterInstanceResource} from "core-app/modules/hal/resources/query-filter-instance-resource";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";@Injectable()export class QueryFiltersService {+ constructor(protected schemaCache:SchemaCacheService) {+ }/*** Get the matching schema of the filter resource* from the schema*/- public getFilterSchema(filter:QueryFilterInstanceResource, form:QueryFormResource):QueryFilterInstanceSchemaResource|undefined {+ private getFilterSchema(filter:QueryFilterInstanceResource, form:QueryFormResource):QueryFilterInstanceSchemaResource|undefined {const available = form.$embedded.schema.filtersSchemas.elements;return _.find(available, schema => schema.allowedFilterValue.href === filter.filter.href);}/**- * Map all filters of the query with the appropriate schema.+ * Prepares the schemas of each filter to be readily placed to make alterations+ * to the filter based on the filter e.g. when sending an updated filter to the backend.* @param query* @param form*/public mapSchemasIntoFilters(query:QueryResource, form:QueryFormResource) {query.filters.forEach(filter => {- filter.schema = this.getFilterSchema(filter, form)!;+ let schema = this.getFilterSchema(filter, form)!;+ filter.$links.schema = schema.$links.self;+ this.schemaCache.update(filter, schema);+ });+ }++ public setSchemas(schemas:CollectionResource<QueryFilterInstanceSchemaResource>) {+ schemas.elements.forEach(schema => {+ this.schemaCache.updateValue(schema.$links.self.href!, schema);});}}diff --git a/frontend/src/app/components/wp-relations/embedded/children/wp-children-inline-create.service.ts b/frontend/src/app/components/wp-relations/embedded/children/wp-children-inline-create.service.tsindex fc105df8677..7850516e9af 100644--- a/frontend/src/app/components/wp-relations/embedded/children/wp-children-inline-create.service.ts+++ b/frontend/src/app/components/wp-relations/embedded/children/wp-children-inline-create.service.ts@@ -32,12 +32,14 @@ import {WorkPackageRelationsHierarchyService} from "core-components/wp-relationsimport {WorkPackageInlineCreateService} from "core-components/wp-inline-create/wp-inline-create.service";import {WpRelationInlineCreateServiceInterface} from "core-components/wp-relations/embedded/wp-relation-inline-create.service.interface";import {WpRelationInlineAddExistingComponent} from "core-components/wp-relations/embedded/inline/add-existing/wp-relation-inline-add-existing.component";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";@Injectable()export class WpChildrenInlineCreateService extends WorkPackageInlineCreateService implements WpRelationInlineCreateServiceInterface {constructor(readonly injector:Injector,- protected readonly wpRelationsHierarchyService:WorkPackageRelationsHierarchyService) {+ protected readonly wpRelationsHierarchyService:WorkPackageRelationsHierarchyService,+ protected readonly schemaCache:SchemaCacheService) {super(injector);}@@ -79,8 +81,7 @@ export class WpChildrenInlineCreateService extends WorkPackageInlineCreateServic}public get canAddChild() {- const wp = this.referenceTarget;- return wp && !wp.isMilestone && wp.changeParent;+ return this.schema && !this.schema.isMilestone && this.referenceTarget!.changeParent;}/**@@ -90,4 +91,8 @@ export class WpChildrenInlineCreateService extends WorkPackageInlineCreateServicreference: this.I18n.t('js.relation_buttons.add_existing_child'),create: this.I18n.t('js.relation_buttons.add_new_child')};++ private get schema() {+ return this.referenceTarget && this.schemaCache.of(this.referenceTarget);+ }}diff --git a/frontend/src/app/components/wp-table/configuration-modal/wp-table-configuration-relation-selector.ts b/frontend/src/app/components/wp-table/configuration-modal/wp-table-configuration-relation-selector.tsindex d8843432ef8..6c2355e3fb4 100644--- a/frontend/src/app/components/wp-table/configuration-modal/wp-table-configuration-relation-selector.ts+++ b/frontend/src/app/components/wp-table/configuration-modal/wp-table-configuration-relation-selector.ts@@ -10,6 +10,7 @@ import {QueryFilterResource} from "core-app/modules/hal/resources/query-filter-rimport {QueryOperatorResource} from "core-app/modules/hal/resources/query-operator-resource";import {QueryFilterInstanceResource} from "core-app/modules/hal/resources/query-filter-instance-resource";import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";@Component({templateUrl: './wp-table-configuration-relation-selector.html',@@ -56,7 +57,8 @@ export class WpTableConfigurationRelationSelectorComponent implements OnInit {constructor(readonly injector:Injector,readonly I18n:I18nService,readonly wpTableFilters:WorkPackageViewFiltersService,- readonly ConfigurationService:ConfigurationService) {+ readonly ConfigurationService:ConfigurationService,+ readonly schemaCache:SchemaCacheService) {}ngOnInit() {@@ -106,7 +108,7 @@ export class WpTableConfigurationRelationSelectorComponent implements OnInit {}private getOperatorForId(filter:QueryFilterResource, id:string):QueryOperatorResource {- return _.find(filter.schema.availableOperators, { 'id': id}) as QueryOperatorResource;+ return _.find(this.schemaCache.of(filter).availableOperators, { 'id': id}) as QueryOperatorResource;}public compareRelationFilters(f1:undefined|QueryFilterResource, f2:undefined|QueryFilterResource):boolean {diff --git a/frontend/src/app/components/wp-table/drag-and-drop/actions/group-by-drag-action.service.ts b/frontend/src/app/components/wp-table/drag-and-drop/actions/group-by-drag-action.service.tsindex b519c12efe5..50e98dc0cae 100644--- a/frontend/src/app/components/wp-table/drag-and-drop/actions/group-by-drag-action.service.ts+++ b/frontend/src/app/components/wp-table/drag-and-drop/actions/group-by-drag-action.service.ts@@ -9,6 +9,7 @@ import {groupIdentifier} from "core-components/wp-fast-table/builders/modes/grouimport {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";import {HalEventsService} from "core-app/modules/hal/services/hal-events.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";export class GroupByDragActionService extends TableDragActionService {@@ -16,6 +17,7 @@ export class GroupByDragActionService extends TableDragActionService {@InjectField() halEditing:HalResourceEditingService;@InjectField() halEvents:HalEventsService;@InjectField() halNotification:HalResourceNotificationService;+ @InjectField() schemaCache:SchemaCacheService;public get applies() {return this.wpTableGroupBy.isEnabled;@@ -26,7 +28,7 @@ export class GroupByDragActionService extends TableDragActionService {*/public canPickup(workPackage:WorkPackageResource):boolean {const attribute = this.groupedAttribute;- return attribute !== null && workPackage.isAttributeEditable(attribute);+ return attribute !== null && this.schemaCache.of(workPackage).isAttributeEditable(attribute);}public handleDrop(workPackage:WorkPackageResource, el:HTMLElement):Promise<unknown> {diff --git a/frontend/src/app/components/wp-table/timeline/cells/timeline-cell-renderer.ts b/frontend/src/app/components/wp-table/timeline/cells/timeline-cell-renderer.tsindex 71f5ad95e1e..7536a168098 100644--- a/frontend/src/app/components/wp-table/timeline/cells/timeline-cell-renderer.ts+++ b/frontend/src/app/components/wp-table/timeline/cells/timeline-cell-renderer.ts@@ -31,6 +31,7 @@ import Moment = moment.Moment;import {WorkPackageViewTimelineService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-timeline.service";import {WorkPackageChangeset} from "core-components/wp-edit/work-package-changeset";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";export interface CellDateMovement {// Target values to move work package to@@ -45,6 +46,8 @@ export type LabelPosition = 'left'|'right'|'farRight';export class TimelineCellRenderer {@InjectField() wpTableTimeline:WorkPackageViewTimelineService;@InjectField() TimezoneService:TimezoneService;+ @InjectField() schemaCache:SchemaCacheService;+public fieldRenderer:DisplayFieldRenderer = new DisplayFieldRenderer(this.injector, 'timeline');protected dateDisplaysOnMouseMove:{ left?:HTMLElement; right?:HTMLElement } = {};@@ -58,7 +61,8 @@ export class TimelineCellRenderer {}public canMoveDates(wp:WorkPackageResource) {- return wp.schema.startDate.writable && wp.schema.dueDate.writable && wp.isAttributeEditable('startDate');+ const schema = this.schemaCache.of(wp);+ return schema.startDate.writable && schema.dueDate.writable && schema.isAttributeEditable('startDate');}public isEmpty(wp:WorkPackageResource) {diff --git a/frontend/src/app/components/wp-table/timeline/cells/timeline-milestone-cell-renderer.ts b/frontend/src/app/components/wp-table/timeline/cells/timeline-milestone-cell-renderer.tsindex 7a6e8ba6bea..5717c08504d 100644--- a/frontend/src/app/components/wp-table/timeline/cells/timeline-milestone-cell-renderer.ts+++ b/frontend/src/app/components/wp-table/timeline/cells/timeline-milestone-cell-renderer.ts@@ -31,7 +31,8 @@ export class TimelineMilestoneCellRenderer extends TimelineCellRenderer {}public canMoveDates(wp:WorkPackageResource) {- return wp.schema.date.writable && wp.isAttributeEditable('date');+ const schema = this.schemaCache.of(wp);+ return schema.date.writable && schema.isAttributeEditable('date');}public displayPlaceholderUnderCursor(ev:MouseEvent, renderInfo:RenderInfo):HTMLElement {diff --git a/frontend/src/app/components/wp-table/timeline/cells/wp-timeline-cell.ts b/frontend/src/app/components/wp-table/timeline/cells/wp-timeline-cell.tsindex 1cb3331f31e..1b4cd6917f1 100644--- a/frontend/src/app/components/wp-table/timeline/cells/wp-timeline-cell.ts+++ b/frontend/src/app/components/wp-table/timeline/cells/wp-timeline-cell.ts@@ -40,6 +40,7 @@ import {HalResourceEditingService} from "core-app/modules/fields/edit/services/himport {HalEventsService} from "core-app/modules/hal/services/hal-events.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";export const classNameLeftLabel = 'labelLeft';export const classNameRightContainer = 'containerRight';@@ -70,6 +71,7 @@ export class WorkPackageTimelineCell {@InjectField() notificationService:WorkPackageNotificationService;@InjectField() states:States;@InjectField() loadingIndicator:LoadingIndicatorService;+ @InjectField() schemaCache:SchemaCacheService;private wpElement:HTMLDivElement|null = null;@@ -108,7 +110,7 @@ export class WorkPackageTimelineCell {canConnectRelations():boolean {const wp = this.latestRenderInfo.workPackage;- if (wp.isMilestone) {+ if (this.schemaCache.of(wp).isMilestone) {return !_.isNil(wp.date);}@@ -178,7 +180,7 @@ export class WorkPackageTimelineCell {}private cellRenderer(workPackage:WorkPackageResource):TimelineCellRenderer {- if (workPackage.isMilestone) {+ if (this.schemaCache.of(workPackage).isMilestone) {return this.renderers.milestone;}diff --git a/frontend/src/app/modules/boards/board/board-list/board-list.component.ts b/frontend/src/app/modules/boards/board/board-list/board-list.component.tsindex fd762642994..e778ac79fe1 100644--- a/frontend/src/app/modules/boards/board/board-list/board-list.component.ts+++ b/frontend/src/app/modules/boards/board/board-list/board-list.component.ts@@ -56,6 +56,7 @@ import {BoardListCrossSelectionService} from "core-app/modules/boards/board/boarimport {debounceTime, filter, map} from "rxjs/operators";import {HalEvent, HalEventsService} from "core-app/modules/hal/services/hal-events.service";import {ChangeItem} from "core-app/modules/fields/changeset/changeset";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";export interface DisabledButtonPlaceholder {text:string;@@ -133,7 +134,6 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnInireadonly state:StateService,readonly cdRef:ChangeDetectorRef,readonly transitions:TransitionService,- readonly boardCache:BoardCacheService,readonly boardFilters:BoardFiltersService,readonly notifications:NotificationsService,readonly querySpace:IsolatedQuerySpace,@@ -149,6 +149,7 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnInireadonly halEditing:HalResourceEditingService,readonly loadingIndicator:LoadingIndicatorService,readonly wpCacheService:WorkPackageCacheService,+ readonly schemaCache:SchemaCacheService,readonly boardService:BoardService,readonly boardActionRegistry:BoardActionsRegistryService,readonly causedUpdates:CausedUpdatesService) {@@ -242,8 +243,7 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnInipublic canMove(workPackage:WorkPackageResource) {if (this.board.isAction) {- const fieldSchema = workPackage.schema[this.board.actionAttribute!] as IFieldSchema;- return this.canDragOutOf && fieldSchema.writable;+ return this.canDragOutOf && this.schema(workPackage).isAttributeEditable(this.board.actionAttribute!);} else {return this.canDragOutOf;}@@ -257,10 +257,6 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnInireturn this.boardService.canManage(this.board);}- //public get canDelete() {- // return this.canManage && !!this.query.delete;- //}-public get canRename() {return this.canManage &&!!this.query.updateImmediately &&@@ -474,4 +470,7 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIni);}}+ private schema(workPackage:WorkPackageResource) {+ return this.schemaCache.of(workPackage);+ }}diff --git a/frontend/src/app/modules/calendar/wp-calendar/wp-calendar.component.ts b/frontend/src/app/modules/calendar/wp-calendar/wp-calendar.component.tsindex a3349b04c2e..c71f2ddc506 100644--- a/frontend/src/app/modules/calendar/wp-calendar/wp-calendar.component.ts+++ b/frontend/src/app/modules/calendar/wp-calendar/wp-calendar.component.ts@@ -20,6 +20,7 @@ import {take} from 'rxjs/operators';import {ToolbarInput} from '@fullcalendar/core/types/input-types';import {ConfigurationService} from "core-app/modules/common/config/configuration.service";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";interface CalendarViewEvent {el:HTMLElement;@@ -53,6 +54,7 @@ export class WorkPackagesCalendarController extends UntilDestroyedMixin implemenreadonly wpListService:WorkPackagesListService,readonly querySpace:IsolatedQuerySpace,readonly wpListChecksumService:WorkPackagesListChecksumService,+ readonly schemaCache:SchemaCacheService,readonly titleService:OpTitleService,private element:ElementRef,readonly i18n:I18nService,@@ -332,7 +334,7 @@ export class WorkPackagesCalendarController extends UntilDestroyedMixin implemen}private eventDate(workPackage:WorkPackageResource, type:'start'|'due') {- if (workPackage.isMilestone) {+ if (this.schemaCache.of(workPackage).isMilestone) {return workPackage.date;} else {return workPackage[`${type}Date`];diff --git a/frontend/src/app/modules/common/path-helper/apiv3/queries/apiv3-queries-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/queries/apiv3-queries-paths.tsindex 41c27024d49..ce29398ab60 100644--- a/frontend/src/app/modules/common/path-helper/apiv3/queries/apiv3-queries-paths.ts+++ b/frontend/src/app/modules/common/path-helper/apiv3/queries/apiv3-queries-paths.ts@@ -31,6 +31,7 @@ import {SimpleResourceCollection} from 'core-app/modules/common/path-helper/apiv3/path-resources';import {Apiv3QueryPaths} from 'core-app/modules/common/path-helper/apiv3/queries/apiv3-query-paths';+import {Apiv3QueryFilterInstanceSchemaPaths} from "core-app/modules/common/path-helper/apiv3/queries/apiv3-query-filter-instance-schema-paths";export class Apiv3QueriesPaths extends SimpleResourceCollection<Apiv3QueryPaths> {constructor(basePath:string) {@@ -42,8 +43,13 @@ export class Apiv3QueriesPaths extends SimpleResourceCollection<Apiv3QueryPaths>readonly default = new SimpleResource(this.path, 'default');- // /api/v3/users/:userId- public id(userId:string|number):Apiv3QueryPaths {- return new Apiv3QueryPaths(this.path, userId);+ // /api/v3/queries/:id+ public id(id:string|number):Apiv3QueryPaths {+ return new Apiv3QueryPaths(this.path, id);+ }++ // /api/v3/queries/filter_instance_schemas/:id+ public filterInstanceSchema(id:string|number):Apiv3QueryFilterInstanceSchemaPaths {+ return new Apiv3QueryFilterInstanceSchemaPaths(`${this.path}/filter_instance_schemas`, id);}}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/queries/apiv3-query-filter-instance-schema-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/queries/apiv3-query-filter-instance-schema-paths.tsnew file mode 100644index 00000000000..efbedccc3cb--- /dev/null+++ b/frontend/src/app/modules/common/path-helper/apiv3/queries/apiv3-query-filter-instance-schema-paths.ts@@ -0,0 +1,35 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2020 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 docs/COPYRIGHT.rdoc for more details.+// ++++import {SimpleResource} from 'core-app/modules/common/path-helper/apiv3/path-resources';++export class Apiv3QueryFilterInstanceSchemaPaths extends SimpleResource {+ constructor(basePath:string, filterName:string|number) {+ super(basePath, filterName);+ }+}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entries-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entries-paths.tsindex 7db391517ac..4552c9200c7 100644--- a/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entries-paths.ts+++ b/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entries-paths.ts@@ -41,5 +41,6 @@ export class Apiv3TimeEntriesPaths extends SimpleResourceCollection {return new Apiv3TimeEntryPaths(this.path, timeEntryId);}+ // Static pathspublic readonly form = new SimpleResource(this.path, 'form');}diff --git a/frontend/src/app/modules/fields/changeset/resource-changeset.ts b/frontend/src/app/modules/fields/changeset/resource-changeset.tsindex 86822fd72b0..2e14556e772 100644--- a/frontend/src/app/modules/fields/changeset/resource-changeset.ts+++ b/frontend/src/app/modules/fields/changeset/resource-changeset.ts@@ -6,6 +6,9 @@ import {input, InputState} from "reactivestates";import {IFieldSchema} from "core-app/modules/fields/field.base";import {debugLog} from "core-app/helpers/debug_output";import {take} from "rxjs/operators";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import { Injector } from '@angular/core';+import {SchemaProxy} from "core-app/modules/hal/schemas/schema-proxy";export const PROXY_IDENTIFIER = '__is_changeset_proxy';@@ -19,7 +22,7 @@ export const PROXY_IDENTIFIER = '__is_changeset_proxy';* Provides access to:* - The projected resource with all changes applied as properties*/-export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } = HalResource> {+export class ResourceChangeset<T extends HalResource = HalResource> {/** Maintain a single change set while editing */protected changeset = new Changeset();@@ -35,13 +38,21 @@ export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } =/** Keep a reference to the original resource */protected _pristineResource:T;- /** The projected resource, which will proxy values from the change set */+ /** The projected resource, which will proxy values from the changeset */public projectedResource:T;+ /** The cache to all the schemas. Used to maintain the schema of the projectedResource which does not stem from a form.+ * The schema of the form is kept inside the changeset.+ * */+ protected schemaCache:SchemaCacheService;+constructor(pristineResource:T,public readonly state?:InputState<ResourceChangeset<T>>,loadedForm:FormResource|null = null) {this.updatePristineResource(pristineResource);++ this.schemaCache = (pristineResource.injector as Injector).get(SchemaCacheService);+if (loadedForm) {this.form$.putValue(loadedForm);}@@ -94,14 +105,6 @@ export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } =return this._pristineResource;}- public getSchemaName(attribute:string):string {- if (this.projectedResource.getSchemaName) {- return this.projectedResource.getSchemaName(attribute);- } else {- return attribute;- }- }-/*** Returns the cached form or loads it if necessary.*/@@ -199,7 +202,7 @@ export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } =* @param key*/public isWritable(key:string):boolean {- const fieldSchema = this.schema[key] as IFieldSchema|null;+ const fieldSchema = this.schema.ofProperty(key) as IFieldSchema|null;return !!(fieldSchema && fieldSchema.writable);}@@ -220,14 +223,9 @@ export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } =/*** Proxy getters to base or changeset.- * Special case for schema , which is overridden.* @param key*/private proxyGet(key:string) {- if (key === 'schema') {- return this.schema;- }-if (key === '__is_proxy') {return true;}@@ -310,7 +308,11 @@ export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } =* and contains available values.*/public get schema():SchemaResource {- return this.form$.getValueOr(this.pristineResource).schema;+ if (this.form$.hasValue()) {+ return SchemaProxy.create(this.form$.value!.schema, this.projectedResource);+ } else {+ return this.schemaCache.of(this.pristineResource);+ }}/**@@ -343,14 +345,14 @@ export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } =}_.each(this.changeset.all, (val:ChangeItem, key:string) => {- const fieldSchema:IFieldSchema|undefined = this.schema[key];- if (!(typeof (fieldSchema) === 'object' && fieldSchema.writable)) {+ const fieldSchema:IFieldSchema|null = this.schema.ofProperty(key);+ if (fieldSchema && !fieldSchema.writable) {debugLog(`Trying to write ${key} but is not writable in schema`);return;}// Override in _links if it is a linked property- if (reference._links[key]) {+ if (fieldSchema && reference._links[key]) {plainPayload._links[key] = this.getLinkedValue(val.to, fieldSchema);} else {plainPayload[key] = val.to;@@ -441,8 +443,8 @@ export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } =*/protected setNewDefaults(form:FormResource) {_.each(form.payload, (val:unknown, key:string) => {- const fieldSchema:IFieldSchema|undefined = this.schema[key];- if (!(typeof (fieldSchema) === 'object' && fieldSchema.writable)) {+ const fieldSchema:IFieldSchema|null = this.schema.ofProperty(key);+ if (!fieldSchema?.writable) {return;}diff --git a/frontend/src/app/modules/fields/display/field-types/combined-date-display.field.ts b/frontend/src/app/modules/fields/display/field-types/combined-date-display.field.tsindex 8fa32510d39..cdfef6108ad 100644--- a/frontend/src/app/modules/fields/display/field-types/combined-date-display.field.ts+++ b/frontend/src/app/modules/fields/display/field-types/combined-date-display.field.ts@@ -37,10 +37,10 @@ export class CombinedDateDisplayField extends DateDisplayField {};public render(element:HTMLElement, displayText:string):void {- var startDateElement = this.createDateDisplayField('startDate');- var dueDateElement = this.createDateDisplayField('dueDate');+ let startDateElement = this.createDateDisplayField('startDate');+ let dueDateElement = this.createDateDisplayField('dueDate');- var separator = document.createElement('span');+ let separator = document.createElement('span');separator.textContent = ' - ';element.appendChild(startDateElement);@@ -49,9 +49,9 @@ export class CombinedDateDisplayField extends DateDisplayField {}private createDateDisplayField(date:'dueDate'|'startDate'):HTMLElement {- var dateElement = document.createElement('span');- var dateDisplayField = new DateDisplayField(date, this.context);- var text = this.resource[date] ?+ let dateElement = document.createElement('span');+ let dateDisplayField = new DateDisplayField(date, this.context);+ let text = this.resource[date] ?this.timezoneService.formattedDate(this.resource[date]) :this.text.placeholder[date];diff --git a/frontend/src/app/modules/fields/edit/edit-field.component.ts b/frontend/src/app/modules/fields/edit/edit-field.component.tsindex 873e6a62038..9e901c5660d 100644--- a/frontend/src/app/modules/fields/edit/edit-field.component.ts+++ b/frontend/src/app/modules/fields/edit/edit-field.component.ts@@ -67,7 +67,7 @@ export abstract class EditFieldComponent extends Field implements OnInit, OnDestreadonly cdRef:ChangeDetectorRef,readonly injector:Injector) {super();- this.schema = this.schema || this.change.schema[this.name];+ this.schema = this.schema || this.change.schema.ofProperty(this.name);if (this.change.state) {this.change.state@@ -76,14 +76,14 @@ export abstract class EditFieldComponent extends Field implements OnInit, OnDestthis.untilDestroyed()).subscribe((change) => {- const fieldSchema = change.schema[this.name];+ const fieldSchema = change.schema.ofProperty(this.name);if (!fieldSchema) {return handler.deactivate(false);}this.change = change;- this.schema = change.schema[this.name];+ this.schema = change.schema.ofProperty(this.name);this.initialize();this.cdRef.markForCheck();});@@ -116,7 +116,7 @@ export abstract class EditFieldComponent extends Field implements OnInit, OnDestpublic get name() {// Get the mapped schema name, as this is not always the attribute// e.g., startDate in table for milestone => date attribute- return this.change.getSchemaName(this.handler.fieldName);+ return this.change.schema.mappedName(this.handler.fieldName);}public set value(value:any) {diff --git a/frontend/src/app/modules/fields/edit/edit-field.initializer.ts b/frontend/src/app/modules/fields/edit/edit-field.initializer.tsindex 081fc4861b1..e3fb29ecb98 100644--- a/frontend/src/app/modules/fields/edit/edit-field.initializer.ts+++ b/frontend/src/app/modules/fields/edit/edit-field.initializer.ts@@ -76,7 +76,9 @@ export function initializeCoreEditFields(editFieldService:EditFieldService, sele.addFieldType(WorkPackageCommentFieldComponent, '_comment', ['comment']);editFieldService- .addSpecificFieldType('WorkPackage', CombinedDateEditFieldComponent, 'date', ['startDate', 'dueDate', 'date'])+ .addSpecificFieldType('WorkPackage', CombinedDateEditFieldComponent,+ 'date',+ ['combinedDate', 'startDate', 'dueDate', 'date']).addSpecificFieldType('TimeEntry', PlainFormattableEditFieldComponent, 'comment', ['comment']).addSpecificFieldType('TimeEntry', TimeEntryWorkPackageEditFieldComponent, 'workPackage', ['WorkPackage']);diff --git a/frontend/src/app/modules/fields/edit/edit-form/edit-form.component.ts b/frontend/src/app/modules/fields/edit/edit-form/edit-form.component.tsindex dad1571bf1b..1bb2bcb32e5 100644--- a/frontend/src/app/modules/fields/edit/edit-form/edit-form.component.ts+++ b/frontend/src/app/modules/fields/edit/edit-form/edit-form.component.ts@@ -135,7 +135,7 @@ export class EditFormComponent extends EditForm<HalResource> implements OnInit,this.closeEditFields('all', reset);if (reset) {- this.halEditing.reset(this.change)+ this.halEditing.reset(this.change);}}diff --git a/frontend/src/app/modules/fields/edit/edit-form/edit-form.ts b/frontend/src/app/modules/fields/edit/edit-form/edit-form.tsindex 7273352cb06..0f3d51e83ef 100644--- a/frontend/src/app/modules/fields/edit/edit-form/edit-form.ts+++ b/frontend/src/app/modules/fields/edit/edit-form/edit-form.ts@@ -28,7 +28,6 @@import {Injector} from '@angular/core';import {ErrorResource} from 'core-app/modules/hal/resources/error-resource';-import {Subscription} from 'rxjs';import {States} from 'core-components/states.service';import {IFieldSchema} from "core-app/modules/fields/field.base";@@ -271,11 +270,9 @@ export abstract class EditForm<T extends HalResource = HalResource> {* @param fieldName*/private loadFieldSchema(fieldName:string, noWarnings:boolean = false):Promise<IFieldSchema> {- const schemaName = this.change.getSchemaName(fieldName);-return new Promise((resolve, reject) => {- this.loadFormAndCheck(schemaName, noWarnings);- const fieldSchema:IFieldSchema = this.change.schema[schemaName];+ this.loadFormAndCheck(fieldName, noWarnings);+ const fieldSchema:IFieldSchema = this.change.schema.ofProperty(fieldName);if (!fieldSchema) {throw new Error();@@ -287,18 +284,16 @@ export abstract class EditForm<T extends HalResource = HalResource> {/*** Ensure the form gets loaded and we show an error when the field cannot be opened- * @param schemaName+ * @param fieldName* @param noWarnings*/private loadFormAndCheck(fieldName:string, noWarnings:boolean = false) {- const schemaName = this.change.getSchemaName(fieldName);-// Ensure the form is being loaded if necessarythis.change.getForm()- .then((form) => {+ .then(() => {// Look up whether we're actually editable- const fieldSchema = form.schema[schemaName];+ const fieldSchema = this.change.schema.ofProperty(fieldName);if (!fieldSchema.writable && !noWarnings) {this.halNotification.showEditingBlockedError(fieldSchema.name || fieldName);this.closeEditFields([fieldName]);diff --git a/frontend/src/app/modules/fields/edit/field/editable-attribute-field.component.ts b/frontend/src/app/modules/fields/edit/field/editable-attribute-field.component.tsindex ae19b7ff8b9..f63015acdfc 100644--- a/frontend/src/app/modules/fields/edit/field/editable-attribute-field.component.ts+++ b/frontend/src/app/modules/fields/edit/field/editable-attribute-field.component.ts@@ -58,6 +58,8 @@ import {ClickPositionMapper} from "core-app/modules/common/set-click-position/seimport {EditFormComponent} from "core-app/modules/fields/edit/edit-form/edit-form.component";import {HalResource} from "core-app/modules/hal/resources/hal-resource";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import {ISchemaProxy} from "core-app/modules/hal/schemas/schema-proxy";@Component({selector: 'editable-attribute-field',@@ -90,6 +92,7 @@ export class EditableAttributeFieldComponent extends UntilDestroyedMixin implemeprotected opContextMenu:OPContextMenuService,protected halEditing:HalResourceEditingService,protected wpCacheService:WorkPackageCacheService,+ protected schemaCache:SchemaCacheService,// Get parent field group from injectorprotected editForm:EditFormComponent,protected NotificationsService:NotificationsService,@@ -150,8 +153,7 @@ export class EditableAttributeFieldComponent extends UntilDestroyedMixin impleme}public get isEditable() {- const fieldSchema = this.resource.schema[this.fieldName] as IFieldSchema;- return this.resource.isAttributeEditable(this.fieldName) && fieldSchema && fieldSchema.writable;+ return this.schema.isAttributeEditable(this.fieldName);}public activateIfEditable(event:JQuery.TriggeredEvent) {@@ -213,4 +215,11 @@ export class EditableAttributeFieldComponent extends UntilDestroyedMixin implemethis.deactivate();}+ private get schema() {+ if (this.halEditing.typedState(this.resource).hasValue()) {+ return this.halEditing.typedState(this.resource).value!.schema;+ } else {+ return this.schemaCache.of(this.resource) as ISchemaProxy;+ }+ }}diff --git a/frontend/src/app/modules/fields/field.base.ts b/frontend/src/app/modules/fields/field.base.tsindex 15249fc7087..c5393e0a41d 100644--- a/frontend/src/app/modules/fields/field.base.ts+++ b/frontend/src/app/modules/fields/field.base.ts@@ -63,7 +63,7 @@ export class Field extends UntilDestroyedMixin {}public get writable():boolean {- return this.schema.writable && this.resource.isAttributeEditable(this.name);+ return this.schema.writable;}public get hasDefault():boolean {diff --git a/frontend/src/app/modules/grids/widgets/custom-text/custom-text-changeset.ts b/frontend/src/app/modules/grids/widgets/custom-text/custom-text-changeset.tsdeleted file mode 100644index 07607925789..00000000000--- a/frontend/src/app/modules/grids/widgets/custom-text/custom-text-changeset.ts+++ /dev/null@@ -1,5 +0,0 @@-import {ResourceChangeset} from "core-app/modules/fields/changeset/resource-changeset";--export class CustomTextChangeset extends ResourceChangeset<{ [key:string]:unknown; }> {--}diff --git a/frontend/src/app/modules/grids/widgets/custom-text/custom-text-edit-field.service.ts b/frontend/src/app/modules/grids/widgets/custom-text/custom-text-edit-field.service.tsindex e227db579a0..8a74d161cca 100644--- a/frontend/src/app/modules/grids/widgets/custom-text/custom-text-edit-field.service.ts+++ b/frontend/src/app/modules/grids/widgets/custom-text/custom-text-edit-field.service.ts@@ -3,8 +3,11 @@ import {ElementRef, Injector, Injectable} from "@angular/core";import {IFieldSchema} from "core-app/modules/fields/field.base";import {BehaviorSubject} from "rxjs";import {GridWidgetResource} from "core-app/modules/hal/resources/grid-widget-resource";-import {CustomTextChangeset} from "core-app/modules/grids/widgets/custom-text/custom-text-changeset";import {UploadFile} from "core-components/api/op-file-upload/op-file-upload.service";+import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";+import {ResourceChangeset} from "core-app/modules/fields/changeset/resource-changeset";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";@Injectable()export class CustomTextEditFieldService extends EditFieldHandler {@@ -15,10 +18,12 @@ export class CustomTextEditFieldService extends EditFieldHandler {public valueChanged$:BehaviorSubject<string>;- public changeset:CustomTextChangeset;+ public changeset:ResourceChangeset;constructor(protected elementRef:ElementRef,- protected injector:Injector) {+ protected injector:Injector,+ protected halResource:HalResourceService,+ protected schemaCache:SchemaCacheService) {super();}@@ -29,12 +34,12 @@ export class CustomTextEditFieldService extends EditFieldHandler {}public initialize(value:GridWidgetResource) {- this.changeset = new CustomTextChangeset(this.newEditResource(value));+ this.initializeChangeset(value);this.valueChanged$ = new BehaviorSubject(value.options['text'] as string);}public reinitialize(value:GridWidgetResource) {- this.changeset = new CustomTextChangeset(this.newEditResource(value));+ this.initializeChangeset(value);}/**@@ -49,7 +54,7 @@ export class CustomTextEditFieldService extends EditFieldHandler {withText += '\n';}- this.changeset.setValue('text', { raw: withText });+ this.changeset.setValue(this.fieldName, { raw: withText });}public get schema():IFieldSchema {@@ -80,7 +85,7 @@ export class CustomTextEditFieldService extends EditFieldHandler {}public get textValue() {- return this.changeset.value('text');+ return this.changeset.value(this.fieldName);}public handleUserCancel() {@@ -121,10 +126,37 @@ export class CustomTextEditFieldService extends EditFieldHandler {return false;}- private newEditResource(value:GridWidgetResource) {- return { text: value.options.text,- getEditorTypeFor: () => 'full',- canAddAttachments: value.grid.canAddAttachments,- uploadAttachments: (files:UploadFile[]) => value.grid.uploadAttachments(files) };+ /**+ * Mimiks having a HalResource for the sake of the Changeset.+ * @param value+ */+ private initializeChangeset(value:GridWidgetResource) {+ let schemaHref = 'customtext-schema';+ let resourceSource = {+ text: value.options.text,+ getEditorTypeFor: () => 'full',+ canAddAttachments: value.grid.canAddAttachments,+ uploadAttachments: (files:UploadFile[]) => value.grid.uploadAttachments(files),+ _links: {+ schema: {+ href: schemaHref+ }+ }+ };++ let resource = this.halResource.createHalResource(resourceSource, true);++ let schemaSource = {+ text: this.schema,+ _links: {+ self: { href: schemaHref }+ }+ };++ let schema = this.halResource.createHalResource(schemaSource, true) as SchemaResource;++ this.schemaCache.update(resource, schema);++ this.changeset = new ResourceChangeset(resource);}}diff --git a/frontend/src/app/modules/hal/dm-services/payload-dm.service.ts b/frontend/src/app/modules/hal/dm-services/payload-dm.service.tsindex 336faf07e27..c17515483aa 100644--- a/frontend/src/app/modules/hal/dm-services/payload-dm.service.ts+++ b/frontend/src/app/modules/hal/dm-services/payload-dm.service.ts@@ -32,25 +32,25 @@ import {SchemaResource} from 'core-app/modules/hal/resources/schema-resource';@Injectable()export class PayloadDmService {- public extract<T extends HalResource=HalResource>(resource:T, schema:SchemaResource) {+ public extract<T extends HalResource = HalResource>(resource:T, schema:SchemaResource) {let payload:any = {'_links': {}- }+ };- var nonLinkProperties = [];+ let nonLinkProperties = [];- for(var key in schema) {- if (schema.hasOwnProperty(key) && schema[key].writable) {+ for (let key in schema) {+ if (schema.hasOwnProperty(key) && schema[key] && schema[key].writable) {if (resource.$links[key]) {if (Array.isArray(resource[key])) {payload['_links'][key] = _.map(resource[key], element => {- return { href: (element as HalResource).$href }+ return { href: (element as HalResource).$href };});} else {payload['_links'][key] = {href: (resource[key] && resource[key].$href)- }- };+ };+ }} else {nonLinkProperties.push(key);}@@ -62,7 +62,7 @@ export class PayloadDmService {if (Array.isArray(resource[property])) {payload[property] = _.map(resource[property], (element:any) => {if (element instanceof HalResource) {- return this.extract(element, element.currentSchema || element.schema)+ return this.extract(element, element.currentSchema || element.schema);} else {return element;}diff --git a/frontend/src/app/modules/hal/dm-services/query-form-dm.service.ts b/frontend/src/app/modules/hal/dm-services/query-form-dm.service.tsindex 817bb84a61f..74407a9f99b 100644--- a/frontend/src/app/modules/hal/dm-services/query-form-dm.service.ts+++ b/frontend/src/app/modules/hal/dm-services/query-form-dm.service.ts@@ -32,10 +32,13 @@ import {QueryResource} from 'core-app/modules/hal/resources/query-resource';import {QueryFormResource} from 'core-app/modules/hal/resources/query-form-resource';import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';import * as URI from 'urijs';+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import {QueryFiltersService} from "core-components/wp-query/query-filters.service";@Injectable()export class QueryFormDmService {constructor(readonly halResourceService:HalResourceService,+ protected readonly queryFilters:QueryFiltersService,protected pathHelper:PathHelperService) {}@@ -91,7 +94,12 @@ export class QueryFormDmService {return this.halResourceService.post<QueryFormResource>(href, payload)- .toPromise();+ .toPromise()+ .then(form => {+ this.queryFilters.setSchemas(form.$embedded.schema.$embedded.filtersSchemas);++ return form;+ });}public buildQueryResource(form:QueryFormResource):QueryResource {diff --git a/frontend/src/app/modules/hal/resources/grid-widget-resource.ts b/frontend/src/app/modules/hal/resources/grid-widget-resource.tsindex b26d421bbe0..fe2b5096fdd 100644--- a/frontend/src/app/modules/hal/resources/grid-widget-resource.ts+++ b/frontend/src/app/modules/hal/resources/grid-widget-resource.ts@@ -28,8 +28,12 @@import {HalResource} from 'core-app/modules/hal/resources/hal-resource';import {GridResource} from "core-app/modules/hal/resources/grid-resource";+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";export class GridWidgetResource extends HalResource {+ @InjectField() protected halResource:HalResourceService;public identifier:string;public startRow:number;public endRow:number;@@ -47,4 +51,8 @@ export class GridWidgetResource extends HalResource {}public grid:GridResource;++ public get schema():SchemaResource {+ return this.halResource.createHalResource({'_type': 'Schema' }, true);+ }}diff --git a/frontend/src/app/modules/hal/resources/hal-resource.ts b/frontend/src/app/modules/hal/resources/hal-resource.tsindex b2ed2ea5d02..3cdd5e41c60 100644--- a/frontend/src/app/modules/hal/resources/hal-resource.ts+++ b/frontend/src/app/modules/hal/resources/hal-resource.ts@@ -157,19 +157,6 @@ export class HalResource {return !!(this.id && this.id !== 'new');}- /**- * Return whether the resource is editable with the user's permission- * on the given resource package attribute.- * In order to be editable, there needs to be an update link on the resource and the schema for- * the attribute needs to indicate the writability.- *- * @param property- */- public isAttributeEditable(property:string):boolean {- const fieldSchema = this.schema[property];- return this.$links.update && fieldSchema && fieldSchema.writable;- }-/*** 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/modules/hal/resources/project-resource.ts b/frontend/src/app/modules/hal/resources/project-resource.tsindex 913aaa564fb..72489a6af2d 100644--- a/frontend/src/app/modules/hal/resources/project-resource.ts+++ b/frontend/src/app/modules/hal/resources/project-resource.ts@@ -27,13 +27,8 @@//++import {HalResource} from 'core-app/modules/hal/resources/hal-resource';-import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";-import {SchemaCacheService} from "core-components/schemas/schema-cache.service";-import {InjectField} from "core-app/helpers/angular/inject-field.decorator";export class ProjectResource extends HalResource {- @InjectField() private schemaCacheService:SchemaCacheService;-public get state() {return this.states.projects.get(this.id!) as any;}@@ -46,22 +41,6 @@ export class ProjectResource extends HalResource {return 'constrained';}- /**- * Get the schema of the project- * ensure that it's loaded- *- * TODO this is duplicating the WorkPackageResource#schema getter- */- public get schema():SchemaResource {- const state = this.schemaCacheService.state(this as any);-- if (!state.hasValue()) {- throw `Accessing schema of ${this.id} without it being loaded.`;- }-- return state.value!;- }-/*** Exclude the schema _link from the linkable Resources.*/diff --git a/frontend/src/app/modules/hal/resources/query-filter-instance-resource.ts b/frontend/src/app/modules/hal/resources/query-filter-instance-resource.tsindex 01f4b4ddff8..d0ed39dfbbd 100644--- a/frontend/src/app/modules/hal/resources/query-filter-instance-resource.ts+++ b/frontend/src/app/modules/hal/resources/query-filter-instance-resource.ts@@ -30,22 +30,23 @@ import {HalResource} from 'core-app/modules/hal/resources/hal-resource';import {QueryFilterResource} from 'core-app/modules/hal/resources/query-filter-resource';import {QueryFilterInstanceSchemaResource} from 'core-app/modules/hal/resources/query-filter-instance-schema-resource';import {QueryOperatorResource} from 'core-app/modules/hal/resources/query-operator-resource';+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";export class QueryFilterInstanceResource extends HalResource {public filter:QueryFilterResource;public operator:QueryOperatorResource;public values:HalResource[]|string[];- public schema:QueryFilterInstanceSchemaResource;private memoizedCurrentSchemas:{ [key:string]:QueryFilterInstanceSchemaResource } = {};- /**- * Create a copied filter, taking over the manually set schema instance.- */- public $copy<T extends HalResource = HalResource>():T {- let clone = super.$copy<T>() as any;- clone.schema = this.schema;+ @InjectField(SchemaCacheService) schemaCache:SchemaCacheService;+ @InjectField(PathHelperService) pathHelper:PathHelperService;++ public $initialize(source:any) {+ super.$initialize(source);- return clone;+ this.$links['schema'] = { href: this.pathHelper.api.v3.queries.filterInstanceSchema(this.filter.idFromLink).path };}public get id():string {@@ -64,14 +65,14 @@ export class QueryFilterInstanceResource extends HalResource {* Therefore, the schema differs based on the selected operator.*/public get currentSchema():QueryFilterInstanceSchemaResource|null {- if (!this.schema || !this.operator) {+ if (!this.operator) {return null;}let key = this.operator.href!.toString();if (this.memoizedCurrentSchemas[key] === undefined) {- this.memoizedCurrentSchemas[key] = this.schema.resultingSchema(this.operator);+ this.memoizedCurrentSchemas[key] = this.schemaCache.of(this).resultingSchema(this.operator);}return this.memoizedCurrentSchemas[key];@@ -82,6 +83,6 @@ export class QueryFilterInstanceResource extends HalResource {}public findOperator(operatorSymbol:string):QueryOperatorResource|undefined {- return _.find(this.schema.availableOperators, (operator:QueryOperatorResource) => operator.id === operatorSymbol) as QueryOperatorResource|undefined;+ return _.find(this.schemaCache.of(this).availableOperators, (operator:QueryOperatorResource) => operator.id === operatorSymbol) as QueryOperatorResource|undefined;}}diff --git a/frontend/src/app/modules/hal/resources/query-filter-instance-schema-resource.ts b/frontend/src/app/modules/hal/resources/query-filter-instance-schema-resource.tsindex 5f74ed6685f..cf7621644f2 100644--- a/frontend/src/app/modules/hal/resources/query-filter-instance-schema-resource.ts+++ b/frontend/src/app/modules/hal/resources/query-filter-instance-schema-resource.ts@@ -36,8 +36,10 @@ import {SchemaDependencyResource} from 'core-app/modules/hal/resources/schema-deimport {QueryOperatorResource} from 'core-app/modules/hal/resources/query-operator-resource';import {QueryFilterInstanceResource} from 'core-app/modules/hal/resources/query-filter-instance-resource';import {HalResource} from 'core-app/modules/hal/resources/hal-resource';+import {HalLink} from "core-app/modules/hal/hal-link/hal-link";export interface QueryFilterInstanceSchemaResourceLinks {+ self:HalLink;filter:QueryFilterResource;}@@ -84,7 +86,7 @@ export class QueryFilterInstanceSchemaResource extends SchemaResource {schema: this.$source._links.self,operator: operator.$source._links.self}- }+ };if (this.definesAllowedValues()) {source._links['values'] = [];@@ -92,11 +94,7 @@ export class QueryFilterInstanceSchemaResource extends SchemaResource {source['values'] = [];}- let newFilter = new QueryFilterInstanceResource(this.injector, source, true, this.halInitializer, 'QueryFilterInstance');-- newFilter.schema = this;-- return newFilter;+ return new QueryFilterInstanceResource(this.injector, source, true, this.halInitializer, 'QueryFilterInstance');}public isValueRequired():boolean {diff --git a/frontend/src/app/modules/hal/resources/query-filter-resource.ts b/frontend/src/app/modules/hal/resources/query-filter-resource.tsindex 0776575d41a..f6b2cceff6a 100644--- a/frontend/src/app/modules/hal/resources/query-filter-resource.ts+++ b/frontend/src/app/modules/hal/resources/query-filter-resource.ts@@ -35,7 +35,6 @@ export interface QueryFilterResourceEmbedded {export class QueryFilterResource extends HalResource {public $embedded:QueryFilterResourceEmbedded;- public schema:QueryFilterInstanceSchemaResource;public values:any[];public get id():string {diff --git a/frontend/src/app/modules/hal/resources/time-entry-resource.ts b/frontend/src/app/modules/hal/resources/time-entry-resource.tsindex 7160749bddb..a2d4b82eaf4 100644--- a/frontend/src/app/modules/hal/resources/time-entry-resource.ts+++ b/frontend/src/app/modules/hal/resources/time-entry-resource.ts@@ -32,37 +32,6 @@ import {SchemaCacheService} from "core-components/schemas/schema-cache.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";export class TimeEntryResource extends HalResource {- // TODO: extract the whole overridden Schema stuff into halresource or use the schemaCacheService- // to place it there- @InjectField() schemaCacheService:SchemaCacheService;-- public overriddenSchema:SchemaResource|undefined = undefined;-- /**- * Get the current schema, assuming it is either:- * 1. Overridden by the current loaded form- * 2. Available as a schema state- *- * If it is neither, an exception is raised.- */- public get schema():SchemaResource {- if (this.hasOverriddenSchema) {- return this.overriddenSchema!;- }-- const state = this.schemaCacheService.state(this as any);-- if (!state.hasValue()) {- throw `Accessing schema of ${this.id} without it being loaded.`;- }-- return state.value!;- }-- public get hasOverriddenSchema():boolean {- return this.overriddenSchema != null;- }-public get state() {return this.states.timeEntries.get(this.id!) as any;}diff --git a/frontend/src/app/modules/hal/resources/work-package-resource.ts b/frontend/src/app/modules/hal/resources/work-package-resource.tsindex 682b89e0f75..81cd21176f3 100644--- a/frontend/src/app/modules/hal/resources/work-package-resource.ts+++ b/frontend/src/app/modules/hal/resources/work-package-resource.ts@@ -36,10 +36,8 @@ import {OpenProjectFileUploadService,UploadFile} from 'core-components/api/op-file-upload/op-file-upload.service';-import {SchemaResource} from 'core-app/modules/hal/resources/schema-resource';import {States} from 'core-components/states.service';import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';-import {SchemaCacheService} from 'core-components/schemas/schema-cache.service';import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';import {NotificationsService} from 'core-app/modules/common/notifications/notifications.service';import {Attachable} from 'core-app/modules/hal/resources/mixins/attachable-mixin';@@ -76,6 +74,7 @@ export interface WorkPackageResourceEmbedded {// Only for milestonesdate:string;relatedBy:RelationResource|null;+ scheduleManually:boolean;}export interface WorkPackageResourceLinks extends WorkPackageResourceEmbedded {@@ -124,13 +123,11 @@ export class WorkPackageBaseResource extends HalResource {public activities:CollectionResource;public attachments:AttachmentCollectionResource;- public overriddenSchema:SchemaResource|undefined = undefined;@InjectField() I18n:I18nService;@InjectField() tates:States;@InjectField() wpActivity:WorkPackagesActivityService;@InjectField() workPackageDmService:WorkPackageDmService;@InjectField() wpCacheService:WorkPackageCacheService;- @InjectField() schemaCacheService:SchemaCacheService;@InjectField() NotificationsService:NotificationsService;@InjectField() workPackageNotificationService:WorkPackageNotificationService;@InjectField() pathHelper:PathHelperService;@@ -146,10 +143,6 @@ export class WorkPackageBaseResource extends HalResource {return ancestors.map((el:WorkPackageResource) => el.id!);}- public get isReadonly():boolean {- return this.status && this.status.isReadonly;- }-/*** Return "<type name>: <subject> (#<id>)" if type and id are known.*/@@ -170,25 +163,11 @@ export class WorkPackageBaseResource extends HalResource {return `${subject}${id}`;}- public get isMilestone():boolean {- return this.schema.hasOwnProperty('date');- }-public get isLeaf():boolean {- var children = this.$links.children;+ let children = this.$links.children;return !(children && children.length > 0);}- /**- * Return whether the user in general has permission to edit the work package.- * This check is required, but not sufficient to check all attribute restrictions.- *- * Use +isAttributeEditable(property)+ for this case.- */- public get isEditable() {- return this.isNew || !!this.$links.update;- }-public previewPath() {if (!this.isNew) {return this.pathHelper.api.v3.work_packages.id(this.id!).path;@@ -201,21 +180,6 @@ export class WorkPackageBaseResource extends HalResource {return fieldName === 'description' ? 'full' : 'constrained';}- /**- * Return whether the work package is editable with the user's permission- * on the given work package attribute.- *- * @param property- */- public isAttributeEditable(property:string):boolean {- const fieldSchema = this.schema[property];-- return this.isEditable &&- fieldSchema &&- fieldSchema.writable &&- (!this.isReadonly || property === 'status');- }-private performUpload(files:UploadFile[]) {let href = '';@@ -228,14 +192,6 @@ export class WorkPackageBaseResource extends HalResource {return this.opFileUpload.uploadAndMapResponse(href, files);}- public getSchemaName(name:string):string {- if (this.isMilestone && (name === 'startDate' || name === 'dueDate')) {- return 'date';- } else {- return name;- }- }-public isParentOf(otherWorkPackage:WorkPackageResource) {return otherWorkPackage.parent?.$links.self.$link.href === this.$links.self.$link.href;}@@ -263,29 +219,6 @@ export class WorkPackageBaseResource extends HalResource {return promise;}- /**- * Assign values from the form for a newly created work package resource.- * @param form- */- public initializeNewResource(form:FormResource) {- this.overriddenSchema = form.schema;- this.$source.id = 'new';-- // Ensure type is set to identify the resource- this._type = 'WorkPackage';-- // Since the ID will change upon saving, keep track of the WP- // with the actual creation date- this.__initialized_at = Date.now();-- // Set update link to form- this['update'] = this.$links.update = form.$links.self;- // Use POST /work_packages for saving link- this['updateImmediately'] = this.$links.updateImmediately = (payload) => {- return this.workPackageDmService.createWorkPackage(payload);- };- }-public $initialize(source:any) {super.$initialize(source);@@ -307,27 +240,6 @@ export class WorkPackageBaseResource extends HalResource {return _.without(super.$linkableKeys(), 'schema');}- /**- * Get the current schema, assuming it is either:- * 1. Overridden by the current loaded form- * 2. Available as a schema state- *- * If it is neither, an exception is raised.- */- public get schema():SchemaResource {- if (this.hasOverriddenSchema) {- return this.overriddenSchema!;- }-- const state = this.schemaCacheService.state(this as any);-- if (!state.hasValue()) {- throw `Accessing schema of ${this.id} without it being loaded.`;- }-- return state.value!;- }-/*** Return the associated state to this HAL resource, if any.*/@@ -348,10 +260,6 @@ export class WorkPackageBaseResource extends HalResource {return this.wpCacheService.updateWorkPackage(newValue as any);}-- public get hasOverriddenSchema():boolean {- return this.overriddenSchema != null;- }}export const WorkPackageResource = Attachable(WorkPackageBaseResource);diff --git a/frontend/src/app/modules/hal/schemas/schema-proxy.ts b/frontend/src/app/modules/hal/schemas/schema-proxy.tsnew file mode 100644index 00000000000..cd3b218cf3f--- /dev/null+++ b/frontend/src/app/modules/hal/schemas/schema-proxy.ts@@ -0,0 +1,130 @@+//-- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2020 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 docs/COPYRIGHT.rdoc for more details.+//++++import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {IFieldSchema} from "core-app/modules/fields/field.base";++export interface ISchemaProxy extends SchemaResource {+ ofProperty(property:string):IFieldSchema;+ isAttributeEditable(property:string):boolean;+ isEditable:boolean;+}++export class SchemaProxy implements ProxyHandler<SchemaResource> {+ constructor(protected schema:SchemaResource,+ protected resource:HalResource) {+ }++ static create(schema:SchemaResource, resource:HalResource) {+ return new Proxy(+ schema,+ new this(schema, resource)+ ) as ISchemaProxy;+ }++ get(schema:SchemaResource, property:PropertyKey, receiver:any):any {+ switch (property) {+ case 'ofProperty': {+ return this.proxyMethod(this.ofProperty);+ }+ case 'isAttributeEditable': {+ return this.proxyMethod(this.isAttributeEditable);+ }+ case 'mappedName': {+ return this.proxyMethod(this.mappedName);+ }+ case 'isEditable': {+ return this.isEditable;+ }+ default: {+ return Reflect.get(schema, property, receiver);+ }+ }+ }++ /**+ * Returns the part of the schema relevant for the provided property.+ *+ * We use it to support the virtual attribute 'combinedDate' which is the combination of the three+ * attributes 'startDate', 'dueDate' and 'scheduleManually'. That combination exists only in the front end+ * and not on the native schema. As a property needs to be writable for us to allow the user editing,+ * we need to mark the writability positively if any of the combined properties are writable.+ *+ * @param property the schema part is desired for+ */+ public ofProperty(property:string):IFieldSchema|null {+ let propertySchema = this.schema[this.mappedName(property)];++ if (propertySchema) {+ return Object.assign({}, propertySchema, { writable: this.isEditable && propertySchema && propertySchema.writable });+ } else {+ return null;+ }+ }++ /**+ * Return whether the resource is editable with the user's permission+ * on the given resource package attribute.+ * In order to be editable, there needs to be an update link on the resource and the schema for+ * the attribute needs to indicate the writability.+ *+ * @param property+ */+ public isAttributeEditable(property:string):boolean {+ let propertySchema = this.ofProperty(property);++ return !!propertySchema && propertySchema.writable;+ }++ /**+ * Return whether the user in general has permission to edit the resource.+ * This check is required, but not sufficient to check all attribute restrictions.+ *+ * Use +isAttributeEditable(property)+ for this case.+ */+ public get isEditable() {+ return this.resource.isNew || !!this.resource.$links.update;+ }++ public mappedName(property:string):string {+ return property;+ }++ private proxyMethod(method:Function) {+ const self = this;++ // Returning a Proxy here so that the call is bound+ // to the SchemaProxy instance.+ return new Proxy(method, {+ apply: function (_, __, argumentsList) {+ return method.apply(self, [argumentsList[0]]);+ }+ });+ }+}diff --git a/frontend/src/app/modules/hal/schemas/work-package-schema-proxy.ts b/frontend/src/app/modules/hal/schemas/work-package-schema-proxy.tsnew file mode 100644index 00000000000..3e5a919f6f6--- /dev/null+++ b/frontend/src/app/modules/hal/schemas/work-package-schema-proxy.ts@@ -0,0 +1,101 @@+//-- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2020 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 docs/COPYRIGHT.rdoc for more details.+//++++import {SchemaProxy} from "core-app/modules/hal/schemas/schema-proxy";+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";++export class WorkPackageSchemaProxy extends SchemaProxy {+ get(schema:SchemaResource, property:PropertyKey, receiver:any):any {+ switch (property) {+ case 'isMilestone': {+ return this.isMilestone;+ }+ case 'isReadonly': {+ return this.isReadonly;+ }+ default: {+ return super.get(schema, property, receiver);+ }+ }+ }++ /**+ * Returns the part of the schema relevant for the provided property.+ *+ * We use it to support the virtual attribute 'combinedDate' which is the combination of the three+ * attributes 'startDate', 'dueDate' and 'scheduleManually'. That combination exists only in the front end+ * and not on the native schema. As a property needs to be writable for us to allow the user editing,+ * we need to mark the writability positively if any of the combined properties are writable.+ *+ * @param property the schema part is desired for+ */+ public ofProperty(property:string) {+ if (property === 'combinedDate') {+ let propertySchema = super.ofProperty('startDate');++ if (!propertySchema) {+ return null;+ }++ propertySchema.writable = propertySchema.writable ||+ this.isAttributeEditable('dueDate') ||+ this.isAttributeEditable('scheduleManually');++ return propertySchema;+ } else {+ return super.ofProperty(property);+ }+ }++ public get isReadonly():boolean {+ return this.resource.status?.isReadonly;+ }++ /**+ * Return whether the work package is editable with the user's permission+ * on the given work package attribute.+ *+ * @param property+ */+ public isAttributeEditable(property:string):boolean {+ return super.isAttributeEditable(property) &&+ (!this.isReadonly || property === 'status');+ }++ public get isMilestone():boolean {+ return this.schema.hasOwnProperty('date');+ }++ public mappedName(property:string):string {+ if (this.isMilestone && (property === 'startDate' || property === 'dueDate')) {+ return 'date';+ } else {+ return property;+ }+ }+}diff --git a/frontend/src/app/modules/hal/services/hal-resource-notification.service.ts b/frontend/src/app/modules/hal/services/hal-resource-notification.service.tsindex d0fbc2fd89c..0b17510b276 100644--- a/frontend/src/app/modules/hal/services/hal-resource-notification.service.ts+++ b/frontend/src/app/modules/hal/services/hal-resource-notification.service.ts@@ -36,6 +36,7 @@ import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {HttpErrorResponse} from "@angular/common/http";import {HalResource} from "core-app/modules/hal/resources/hal-resource";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";@Injectable()export class HalResourceNotificationService {@@ -45,6 +46,7 @@ export class HalResourceNotificationService {@InjectField() protected halResourceService:HalResourceService;@InjectField() protected NotificationsService:NotificationsService;@InjectField() protected loadingIndicator:LoadingIndicatorService;+ @InjectField() protected schemaCache:SchemaCacheService;constructor(public injector:Injector) {}@@ -167,8 +169,9 @@ export class HalResourceNotificationService {if (errorResource.errorIdentifier === 'urn:openproject-org:api:v3:errors:PropertyFormatError') {- let attributeName = resource.schema[errorResource.details.attribute].name;- let attributeType = resource.schema[errorResource.details.attribute].type.toLowerCase();+ let schema = this.schemaCache.of(resource).ofProperty(errorResource.details.attribute);+ let attributeName = schema.name;+ let attributeType = schema.type.toLowerCase();let i18nString = 'js.hal.error.format.' + attributeType;if (this.I18n.lookup(i18nString) === undefined) {diff --git a/frontend/src/app/modules/time_entries/create/create.service.ts b/frontend/src/app/modules/time_entries/create/create.service.tsindex 6d1e44696f7..2755ecc361f 100644--- a/frontend/src/app/modules/time_entries/create/create.service.ts+++ b/frontend/src/app/modules/time_entries/create/create.service.ts@@ -11,6 +11,7 @@ import { HalResourceEditingService } from "core-app/modules/fields/edit/servicesimport { Moment } from 'moment';import { TimeEntryCreateModal } from "core-app/modules/time_entries/create/create.modal";import { WorkPackageResource } from 'core-app/modules/hal/resources/work-package-resource';+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";@Injectable()export class TimeEntryCreateService {@@ -19,6 +20,7 @@ export class TimeEntryCreateService {readonly injector:Injector,readonly halResource:HalResourceService,readonly timeEntryDm:TimeEntryDmService,+ readonly schemaCache:SchemaCacheService,protected halEditing:HalResourceEditingService,readonly i18n:I18nService) {}@@ -28,7 +30,7 @@ export class TimeEntryCreateService {this.createNewTimeEntry(date, wp).then(changeset => {- const modal = this.opModalService.show(TimeEntryCreateModal, this.injector, { entry: changeset.pristineResource, showWorkPackageField: showWorkPackageField });+ const modal = this.opModalService.show(TimeEntryCreateModal, this.injector, { changeset: changeset, showWorkPackageField: showWorkPackageField });modal.closingEvent@@ -40,7 +42,6 @@ export class TimeEntryCreateService {reject();}});-});});}@@ -72,8 +73,7 @@ export class TimeEntryCreateService {private initializeNewResource(form:FormResource) {let entry = this.halResource.createHalResourceOfType<TimeEntryResource>('TimeEntry', form.payload.$plain());- entry.$links['schema'] = form.schema;- entry.overriddenSchema = form.schema;+ entry.$links['schema'] = { href: 'new' };entry['_type'] = 'TimeEntry';entry['id'] = 'new';@@ -87,7 +87,11 @@ export class TimeEntryCreateService {};entry.state.putValue(entry);+ // We need to provide the schema to the cache so that it is available in the html form to e.g. determine+ // the editability.+ // It would be better if the edit field could simply rely on the changeset if it exists.+ this.schemaCache.update(entry, form.schema);return entry;}-}+}\ No newline at end of filediff --git a/frontend/src/app/modules/time_entries/edit/edit.service.ts b/frontend/src/app/modules/time_entries/edit/edit.service.tsindex 343cda4bdb3..44857b93abc 100644--- a/frontend/src/app/modules/time_entries/edit/edit.service.ts+++ b/frontend/src/app/modules/time_entries/edit/edit.service.ts@@ -6,34 +6,48 @@ import { TimeEntryResource } from 'core-app/modules/hal/resources/time-entry-resimport { TimeEntryEditModal } from './edit.modal';import { take } from 'rxjs/operators';import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";+import {ResourceChangeset} from "core-app/modules/fields/changeset/resource-changeset";+import {TimeEntryDmService} from "core-app/modules/hal/dm-services/time-entry-dm.service";@Injectable()export class TimeEntryEditService {constructor(readonly opModalService:OpModalService,readonly injector:Injector,+ readonly timeEntryDm:TimeEntryDmService,readonly halResource:HalResourceService,+ protected halEditing:HalResourceEditingService,readonly i18n:I18nService) {}public edit(entry:TimeEntryResource) {return new Promise<{entry:TimeEntryResource, action:'update'|'destroy'}>((resolve, reject) => {- const modal = this.opModalService.show(TimeEntryEditModal, this.injector, { entry: entry });+ this+ .createChangeset(entry)+ .then(changeset => {+ const modal = this.opModalService.show(TimeEntryEditModal, this.injector, { changeset: changeset });- modal- .closingEvent- .pipe(take(1))- .subscribe(() => {- if (modal.destroyedEntry) {- modal.destroyedEntry.delete().then(() => {- resolve({entry: modal.destroyedEntry, action: 'destroy'});+ modal+ .closingEvent+ .pipe(take(1))+ .subscribe(() => {+ if (modal.destroyedEntry) {+ modal.destroyedEntry.delete().then(() => {+ resolve({entry: modal.destroyedEntry, action: 'destroy'});+ });+ } else if (modal.modifiedEntry) {+ resolve({ entry: modal.modifiedEntry, action: 'update' });+ } else {+ reject();+ }});- } else if (modal.modifiedEntry) {- resolve({ entry: modal.modifiedEntry, action: 'update' });- } else {- reject();- }});});}++ public createChangeset(entry:TimeEntryResource) {+ return this.timeEntryDm.updateForm(entry).then(form => {+ return this.halEditing.edit<TimeEntryResource, ResourceChangeset<TimeEntryResource>>(entry, form);+ });+ }}diff --git a/frontend/src/app/modules/time_entries/edit/trigger-actions-entry.component.ts b/frontend/src/app/modules/time_entries/edit/trigger-actions-entry.component.tsindex 7c0953b987c..7b5af9a2da7 100644--- a/frontend/src/app/modules/time_entries/edit/trigger-actions-entry.component.ts+++ b/frontend/src/app/modules/time_entries/edit/trigger-actions-entry.component.ts@@ -5,6 +5,7 @@ import {TimeEntryCacheService} from "core-components/time-entries/time-entry-cacimport {I18nService} from "core-app/modules/common/i18n/i18n.service";import {TimeEntryDmService} from "core-app/modules/hal/dm-services/time-entry-dm.service";import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";+import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";export const triggerActionsEntryComponentSelector = 'time-entry--trigger-actions-entry';@@ -23,6 +24,10 @@ export const triggerActionsEntryComponentSelector = 'time-entry--trigger-actions</a>`,changeDetection: ChangeDetectionStrategy.OnPush,+ providers: [+ HalResourceEditingService,+ TimeEntryEditService+ ]})export class TriggerActionsEntryComponent {@InjectField() readonly timeEntryEditService:TimeEntryEditService;diff --git a/frontend/src/app/modules/time_entries/form/form.component.ts b/frontend/src/app/modules/time_entries/form/form.component.tsindex 370e8dbee98..7e1cb4bd9b8 100644--- a/frontend/src/app/modules/time_entries/form/form.component.ts+++ b/frontend/src/app/modules/time_entries/form/form.component.ts@@ -13,10 +13,10 @@ import {ViewChild,ViewEncapsulation} from '@angular/core';-import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";import {HalResource} from "core-app/modules/hal/resources/hal-resource";import {EditFormComponent} from 'core-app/modules/fields/edit/edit-form/edit-form.component';import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {ResourceChangeset} from "core-app/modules/fields/changeset/resource-changeset";@Component({templateUrl: './form.component.html',@@ -25,7 +25,7 @@ import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixichangeDetection: ChangeDetectionStrategy.OnPush,})export class TimeEntryFormComponent extends UntilDestroyedMixin implements OnInit, OnDestroy {- @Input() entry:TimeEntryResource;+ @Input() changeset:ResourceChangeset<TimeEntryResource>;@Input() showWorkPackageField:boolean = true;@Output() modifiedEntry = new EventEmitter<{ savedResource:TimeEntryResource, isInital:boolean }>();@@ -54,7 +54,7 @@ export class TimeEntryFormComponent extends UntilDestroyedMixin implements OnIningOnInit() {this.halEditing- .temporaryEditResource(this.entry)+ .temporaryEditResource(this.changeset.projectedResource).values$().pipe(this.untilDestroyed()@@ -66,10 +66,14 @@ export class TimeEntryFormComponent extends UntilDestroyedMixin implements OnIni}});- this.setCustomFields(this.entry.schema);+ this.setCustomFields();this.cdRef.detectChanges();}+ public get entry() {+ return this.changeset.projectedResource;+ }+public signalModifiedEntry($event:{ savedResource:HalResource, isInital:boolean }) {this.modifiedEntry.emit($event as { savedResource:TimeEntryResource, isInital:boolean });}@@ -90,15 +94,19 @@ export class TimeEntryFormComponent extends UntilDestroyedMixin implements OnIniif (field === 'workPackage') {return true;} else {- return this.entry.schema[field].required;+ return this.schema.ofProperty(field).required;}}- private setCustomFields(schema:SchemaResource) {- Object.entries(schema).forEach(([key, keySchema]) => {+ private setCustomFields() {+ Object.entries(this.schema).forEach(([key, keySchema]) => {if (key.match(/customField\d+/)) {this.customFields.push({ key: key, label: keySchema.name });}});}++ private get schema() {+ return this.changeset.schema;+ }}diff --git a/frontend/src/app/modules/time_entries/openproject-time-entries.module.ts b/frontend/src/app/modules/time_entries/openproject-time-entries.module.tsindex 06c9eff4669..6341ce92cb3 100644--- a/frontend/src/app/modules/time_entries/openproject-time-entries.module.ts+++ b/frontend/src/app/modules/time_entries/openproject-time-entries.module.ts@@ -34,6 +34,7 @@ import {TimeEntryEditModal} from "core-app/modules/time_entries/edit/edit.modal"import {TimeEntryFormComponent} from "core-app/modules/time_entries/form/form.component";import {TimeEntryEditService} from "core-app/modules/time_entries/edit/edit.service";import {TriggerActionsEntryComponent} from "core-app/modules/time_entries/edit/trigger-actions-entry.component";+import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";@NgModule({imports: [@@ -44,7 +45,7 @@ import {TriggerActionsEntryComponent} from "core-app/modules/time_entries/edit/tOpenprojectFieldsModule,],providers: [- TimeEntryEditService,+ TimeEntryEditService],declarations: [TimeEntryEditModal,diff --git a/frontend/src/app/modules/time_entries/shared/modal/base.modal.html b/frontend/src/app/modules/time_entries/shared/modal/base.modal.htmlindex 6849eb7cb76..3fc2a035edc 100644--- a/frontend/src/app/modules/time_entries/shared/modal/base.modal.html+++ b/frontend/src/app/modules/time_entries/shared/modal/base.modal.html@@ -15,7 +15,7 @@<div class="ngdialog-body op-modal--modal-body"><te-form #editForm- [entry]="entry"+ [changeset]="changeset"[showWorkPackageField]="showWorkPackageField"(modifiedEntry)="setModifiedEntry($event)"></te-form>diff --git a/frontend/src/app/modules/time_entries/shared/modal/base.modal.ts b/frontend/src/app/modules/time_entries/shared/modal/base.modal.tsindex 0ababbed75a..8f3f718593b 100644--- a/frontend/src/app/modules/time_entries/shared/modal/base.modal.ts+++ b/frontend/src/app/modules/time_entries/shared/modal/base.modal.ts@@ -35,8 +35,12 @@ export abstract class TimeEntryBaseModal extends OpModalComponent {public abstract setModifiedEntry($event:{savedResource:HalResource, isInital:boolean}):void;+ public get changeset() {+ return this.locals.changeset;+ }+public get entry() {- return this.locals.entry;+ return this.changeset.projectedResource;}public get showWorkPackageField() {diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service.tsindex b2ffdae34b5..859d855b658 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service.ts@@ -77,10 +77,8 @@ export class WorkPackageViewFiltersService extends WorkPackageQueryStateService<public initializeFilters(query:QueryResource, schema:QuerySchemaResource) {let filters = cloneHalResourceCollection<QueryFilterInstanceResource>(query.filters);- this.loadCurrentFiltersSchemas(filters).then(() => {- this.availableState.putValue(schema.filtersSchemas.elements);- this.pristineState.putValue(filters);- });+ this.availableState.putValue(schema.filtersSchemas.elements);+ this.pristineState.putValue(filters);}/**@@ -327,22 +325,4 @@ export class WorkPackageViewFiltersService extends WorkPackageQueryStateService<private get currentFilterResources():QueryFilterResource[] {return this.rawFilters.map((filter:QueryFilterInstanceResource) => filter.filter);}-- /**- * Ensure all filter schemas are loaded.- * @param filters- */- private loadCurrentFiltersSchemas(filters:QueryFilterInstanceResource[]):Promise<unknown> {- return Promise.all(filters.map((filter:QueryFilterInstanceResource) => {- const href = `/api/v3/queries/filter_instance_schemas/${filter.id}`;- if (filter.schema) {- return filter.schema.$load();- } else {- return this.states.schemas- .get(href)- .valuesPromise()- .then(schema => filter.schema = schema as QueryFilterInstanceSchemaResource);- }- }));- }}diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/work-package-single-view.base.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/work-package-single-view.base.tsindex 7d61e0e321c..397c33f5890 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/work-package-single-view.base.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/work-package-single-view.base.ts@@ -152,8 +152,4 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {public canViewWorkPackageWatchers() {return !!(this.workPackage && this.workPackage.watchers);}-- public get isEditable() {- return this.workPackage.isEditable;- }}diff --git a/spec/features/work_packages/details/date_editor_spec.rb b/spec/features/work_packages/details/date_editor_spec.rbindex 3f3dd5836dc..30dcafd6f38 100644--- a/spec/features/work_packages/details/date_editor_spec.rb+++ b/spec/features/work_packages/details/date_editor_spec.rb@@ -39,10 +39,10 @@ describe 'date inplace editor',let(:project) { FactoryBot.create :project_with_types, public: true }let(:work_package) { FactoryBot.create :work_package, project: project, start_date: '2016-01-01' }let(:user) { FactoryBot.create :admin }- let(:work_packages_page) { Pages::FullWorkPackage.new(work_package,project) }+ let(:work_packages_page) { Pages::FullWorkPackage.new(work_package, project) }let(:wp_table) { Pages::WorkPackagesTable.new(project) }- let(:start_date) { work_packages_page.edit_field(:startDate) }+ let(:start_date) { work_packages_page.edit_field(:combinedDate) }before dologin_as(user)diff --git a/spec/features/work_packages/details/query_groups/relation_query_group_spec.rb b/spec/features/work_packages/details/query_groups/relation_query_group_spec.rbindex 37e362385ca..422f53d4fa8 100644--- a/spec/features/work_packages/details/query_groups/relation_query_group_spec.rb+++ b/spec/features/work_packages/details/query_groups/relation_query_group_spec.rb@@ -141,11 +141,11 @@ describe 'Work package with relation query group', js: true, selenium: true domember_in_project: project,member_through_role: role)end- let!(:project2_member) {+ let!(:project2_member) domember = FactoryBot.build(:member, user: user, project: project2)member.roles = [role]member.save!- }+ endit 'can load the query and inline create' dofull_wp.visit!diff --git a/spec/features/work_packages/display_fields/date_field_display_spec.rb b/spec/features/work_packages/display_fields/date_field_display_spec.rbindex 5055080ef9e..f516723d83d 100644--- a/spec/features/work_packages/display_fields/date_field_display_spec.rb+++ b/spec/features/work_packages/display_fields/date_field_display_spec.rb@@ -60,14 +60,14 @@ describe 'Show the date of a Work Package', type: :feature, js: true doit 'should be highlighted only if the WP status is open (#33457)' do# Highlighted with an open status- expect(page).to have_selector('.inline-edit--display-field.startDate .__hl_date_overdue')+ expect(page).to have_selector('.inline-edit--display-field.combinedDate .__hl_date_overdue')# Change status to closedstatus_field = WorkPackageStatusField.new(page)status_field.update(closed_status.name)# Not highlighted with a closed status- expect(page).not_to have_selector('.inline-edit--display-field.startDate .__hl_date_overdue')+ expect(page).not_to have_selector('.inline-edit--display-field.combinedDate .__hl_date_overdue')endendenddiff --git a/spec/features/work_packages/edit_work_package_spec.rb b/spec/features/work_packages/edit_work_package_spec.rbindex b4fb2edd343..5a0a487dd81 100644--- a/spec/features/work_packages/edit_work_package_spec.rb+++ b/spec/features/work_packages/edit_work_package_spec.rb@@ -128,7 +128,7 @@ describe 'edit work package', js: true doit 'allows updating and seeing the results' dowp_page.update_attributes subject: 'a new subject',type: type2.name,- startDate: ['2013-03-04', '2013-03-20'],+ combinedDate: ['2013-03-04', '2013-03-20'],responsible: manager.name,assignee: manager.name,estimatedTime: '5',@@ -142,7 +142,7 @@ describe 'edit work package', js: true dowp_page.expect_attributes type: type2.name.upcase,responsible: manager.name,assignee: manager.name,- startDate: '03/04/2013 - 03/20/2013',+ combinedDate: '03/04/2013 - 03/20/2013',estimatedTime: '5',percentageDone: '30%',subject: 'a new subject',diff --git a/spec/features/work_packages/select/select_query_spec.rb b/spec/features/work_packages/select/select_query_spec.rbindex b59d02cdeef..8755a975d5c 100644--- a/spec/features/work_packages/select/select_query_spec.rb+++ b/spec/features/work_packages/select/select_query_spec.rb@@ -79,8 +79,8 @@ describe 'Query selection', type: :feature doit 'shows the saved filters', js: true dofilters.open- filters.expect_filter_by 'Assignee', 'is', ['me']- filters.expect_filter_by 'Progress (%)', '>=', ['10'], 'percentageDone'+ filters.expect_filter_by 'Assignee', 'is', ['me']+ filters.expect_filter_by 'Progress (%)', '>=', ['10'], 'percentageDone'endit 'shows filter count within toggle button', js: true do