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
Extract all access of APIv3 calls into APIv3Service (#8521)
Oliver Güntherdfa6bdb45614
diff --git a/frontend/src/app/components/enterprise/enterprise-trial.service.ts b/frontend/src/app/components/enterprise/enterprise-trial.service.tsindex 9ce8b4666bd..d7b868f4bb9 100644--- a/frontend/src/app/components/enterprise/enterprise-trial.service.ts+++ b/frontend/src/app/components/enterprise/enterprise-trial.service.ts@@ -121,7 +121,7 @@ export class EnterpriseTrialService {// extract token from resend linklet trialKey = resendlink.split('/')[6];return this.http.post(- this.pathHelper.api.v3.appBasePath + '/admin/enterprise/save_trial_key',+ this.pathHelper.appBasePath + '/admin/enterprise/save_trial_key',{ trial_key: trialKey },{ withCredentials: true })@@ -134,7 +134,7 @@ export class EnterpriseTrialService {// save received token in controllerprivate saveToken(token:string) {return this.http.post(- this.pathHelper.api.v3.appBasePath + '/admin/enterprise',+ this.pathHelper.appBasePath + '/admin/enterprise',{ enterprise_token: { encoded_token: token } },{ withCredentials: true })@@ -152,7 +152,7 @@ export class EnterpriseTrialService {// Without this deletion, we run into an endless loop of an confirmed mail, but no saved token.this.http.delete(- this.pathHelper.api.v3.appBasePath + '/admin/enterprise/delete_trial_key',+ this.pathHelper.api.v3.apiV3Base + '/admin/enterprise/delete_trial_key',{ withCredentials: true }).toPromise();diff --git a/frontend/src/app/components/filters/filter-container/filter-container.directive.ts b/frontend/src/app/components/filters/filter-container/filter-container.directive.tsindex 75abb539b94..0d1f20d4315 100644--- a/frontend/src/app/components/filters/filter-container/filter-container.directive.ts+++ b/frontend/src/app/components/filters/filter-container/filter-container.directive.ts@@ -79,7 +79,8 @@ export class WorkPackageFilterContainerComponent extends UntilDestroyedMixin imp}public replaceIfComplete(filters:QueryFilterInstanceResource[]) {- this.wpTableFilters.replaceIfComplete(filters);- this.filtersChanged.emit(this.filters);+ let available = filters.filter(el => this.wpTableFilters.isAvailable(el));+ this.wpTableFilters.replaceIfComplete(available);+ this.filtersChanged.emit(available);}}diff --git a/frontend/src/app/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component.ts b/frontend/src/app/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component.tsindex b3a0b0f6627..3a7b77df887 100644--- a/frontend/src/app/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component.ts+++ b/frontend/src/app/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component.ts@@ -31,7 +31,6 @@ import {UserResource} from 'core-app/modules/hal/resources/user-resource';import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';import {RootResource} from 'core-app/modules/hal/resources/root-resource';import {QueryFilterInstanceResource} from 'core-app/modules/hal/resources/query-filter-instance-resource';-import {RootDmService} from 'core-app/modules/hal/dm-services/root-dm.service';import {AfterViewInit,ChangeDetectionStrategy,@@ -49,6 +48,8 @@ import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.serimport {HalResourceSortingService} from "core-app/modules/hal/services/hal-resource-sorting.service";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {NgSelectComponent} from "@ng-select/ng-select";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {CurrentUserService} from "core-components/user/current-user.service";@Component({selector: 'filter-toggled-multiselect-value',@@ -71,10 +72,11 @@ export class FilterToggledMultiselectValueComponent implements OnInit, AfterViewplaceholder: this.I18n.t('js.placeholders.selection'),};- constructor(readonly RootDm:RootDmService,- readonly halResourceService:HalResourceService,+ constructor(readonly halResourceService:HalResourceService,readonly halSorting:HalResourceSortingService,readonly PathHelper:PathHelperService,+ readonly apiV3Service:APIV3Service,+ readonly currentUser:CurrentUserService,readonly cdRef:ChangeDetectorRef,readonly I18n:I18nService) {}@@ -145,7 +147,7 @@ export class FilterToggledMultiselectValueComponent implements OnInit, AfterView// copy will have it's name altered to 'me' and will then be// prepended to the list.if (this.isUserResource) {- loadingPromises.push(this.RootDm.load());+ loadingPromises.push(this.apiV3Service.root.get().toPromise());}Promise.all(loadingPromises)@@ -169,7 +171,7 @@ export class FilterToggledMultiselectValueComponent implements OnInit, AfterView{_links: {self: {- href: this.PathHelper.api.v3.users.me,+ href: this.apiV3Service.users.me,title: this.I18n.t('js.label_me')}}diff --git a/frontend/src/app/components/filters/quick-filter-by-text-input/quick-filter-by-text-input.component.ts b/frontend/src/app/components/filters/quick-filter-by-text-input/quick-filter-by-text-input.component.tsindex dc1678a154b..ffd5a397025 100644--- a/frontend/src/app/components/filters/quick-filter-by-text-input/quick-filter-by-text-input.component.ts+++ b/frontend/src/app/components/filters/quick-filter-by-text-input/quick-filter-by-text-input.component.ts@@ -29,13 +29,13 @@import {Component, EventEmitter, Output} from '@angular/core';import {I18nService} from "app/modules/common/i18n/i18n.service";import {WorkPackageViewFiltersService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service";-import {WorkPackageCacheService} from "app/components/work-packages/work-package-cache.service";import {Subject} from "rxjs";import {debounceTime, distinctUntilChanged, map, tap} from "rxjs/operators";import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";import {input} from "reactivestates";import {QueryFilterResource} from "core-app/modules/hal/resources/query-filter-resource";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'wp-filter-by-text-input',@@ -60,8 +60,7 @@ export class WorkPackageFilterByTextInputComponent extends UntilDestroyedMixin {constructor(readonly I18n:I18nService,readonly querySpace:IsolatedQuerySpace,- readonly wpTableFilters:WorkPackageViewFiltersService,- readonly wpCacheService:WorkPackageCacheService) {+ readonly wpTableFilters:WorkPackageViewFiltersService) {super();this.wpTableFiltersdiff --git a/frontend/src/app/components/forms/forms-cache.service.ts b/frontend/src/app/components/forms/forms-cache.service.tsdeleted file mode 100644index 3d0aa0b1002..00000000000--- a/frontend/src/app/components/forms/forms-cache.service.ts+++ /dev/null@@ -1,58 +0,0 @@-import {Injectable} from '@angular/core';-import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-// -- 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 {multiInput, MultiInputState} from 'reactivestates';-import {FormResource} from "core-app/modules/hal/resources/form-resource";-import {StateCacheService} from "core-components/states/state-cache.service";--@Injectable({ providedIn: 'root' })-export class FormsCacheService extends StateCacheService<FormResource> {-- private $formCache = multiInput<FormResource>();-- constructor(private readonly halResourceService:HalResourceService) {- super();- }-- protected load(href:string):Promise<FormResource> {- return this.halResourceService- .post<FormResource>(href, {})- .toPromise();- }-- protected loadAll(ids:string[]):Promise<undefined> {- return Promise- .all(ids.map(id => this.load(id)))- .then(_ => undefined);- }-- protected get multiState():MultiInputState<FormResource> {- return this.$formCache;- }-}diff --git a/frontend/src/app/components/modals/editor/macro-wp-button-modal/wp-button-macro.modal.ts b/frontend/src/app/components/modals/editor/macro-wp-button-modal/wp-button-macro.modal.tsindex 8f416a58c85..1fdb3c7a05d 100644--- a/frontend/src/app/components/modals/editor/macro-wp-button-modal/wp-button-macro.modal.ts+++ b/frontend/src/app/components/modals/editor/macro-wp-button-modal/wp-button-macro.modal.ts@@ -40,7 +40,8 @@ import {OpModalLocalsMap} from "core-components/op-modals/op-modal.types";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {TypeResource} from "core-app/modules/hal/resources/type-resource";import {CurrentProjectService} from "core-components/projects/current-project.service";-import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {FormResource} from "core-app/modules/hal/resources/form-resource";@Component({templateUrl: './wp-button-macro.modal.html'@@ -75,7 +76,7 @@ export class WpButtonMacroModal extends OpModalComponent implements AfterViewIniconstructor(readonly elementRef:ElementRef,@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,protected currentProject:CurrentProjectService,- readonly workPackageDmService:WorkPackageDmService,+ protected apiV3Service:APIV3Service,readonly cdRef:ChangeDetectorRef,readonly I18n:I18nService) {@@ -84,9 +85,13 @@ export class WpButtonMacroModal extends OpModalComponent implements AfterViewInithis.classes = this.locals.classes;this.buttonStyle = this.classes === 'button';- this.workPackageDmService- .emptyCreateForm({}, this.currentProject.identifier)- .then((form:any) => {+ this+ .apiV3Service+ .withOptionalProject(this.currentProject.identifier)+ .work_packages+ .form+ .post({})+ .subscribe((form:FormResource) => {this.availableTypes = form.schema.type.allowedValues;});}diff --git a/frontend/src/app/components/modals/preview-modal/wp-preview-modal/wp-preview.modal.ts b/frontend/src/app/components/modals/preview-modal/wp-preview-modal/wp-preview.modal.tsindex 3d50e66973e..354d1debdc0 100644--- a/frontend/src/app/components/modals/preview-modal/wp-preview-modal/wp-preview.modal.ts+++ b/frontend/src/app/components/modals/preview-modal/wp-preview-modal/wp-preview.modal.ts@@ -33,7 +33,7 @@ import {OpModalLocalsMap} from "core-components/op-modals/op-modal.types";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";import {HalResource} from "core-app/modules/hal/resources/hal-resource";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './wp-preview.modal.html',@@ -51,7 +51,7 @@ export class WpPreviewModal extends OpModalComponent implements OnInit {@Inject(OpModalLocalsToken) readonly locals:OpModalLocalsMap,readonly cdRef:ChangeDetectorRef,readonly i18n:I18nService,- readonly wpCacheService:WorkPackageCacheService,+ readonly apiV3Service:APIV3Service,readonly opModalService:OpModalService) {super(locals, cdRef, elementRef);}@@ -61,8 +61,12 @@ export class WpPreviewModal extends OpModalComponent implements OnInit {const workPackageLink = this.locals.workPackageLink;const workPackageId = HalResource.idFromLink(workPackageLink);- this.wpCacheService.require(workPackageId)- .then((workPackage:WorkPackageResource) => {+ this+ .apiV3Service+ .work_packages+ .id(workPackageId)+ .requireAndStream()+ .subscribe((workPackage:WorkPackageResource) => {this.workPackage = workPackage;this.cdRef.detectChanges();diff --git a/frontend/src/app/components/op-context-menu/handlers/op-types-context-menu.directive.ts b/frontend/src/app/components/op-context-menu/handlers/op-types-context-menu.directive.tsindex 7d8ad0a5c3f..2777fae2169 100644--- a/frontend/src/app/components/op-context-menu/handlers/op-types-context-menu.directive.ts+++ b/frontend/src/app/components/op-context-menu/handlers/op-types-context-menu.directive.ts@@ -29,7 +29,7 @@import {OpContextMenuItem} from 'core-components/op-context-menu/op-context-menu.types';import {StateService} from '@uirouter/core';import {OPContextMenuService} from "core-components/op-context-menu/op-context-menu.service";-import {Directive, ElementRef, Input} from "@angular/core";+import {Directive, ElementRef, Input, OnInit} from "@angular/core";import {LinkHandling} from "core-app/modules/common/link-handling/link-handling";import {OpContextMenuTrigger} from "core-components/op-context-menu/handlers/op-context-menu-trigger.directive";import {TypeResource} from 'core-app/modules/hal/resources/type-resource';@@ -45,8 +45,6 @@ export class OpTypesContextMenuDirective extends OpContextMenuTrigger {@Input('stateName') public stateName:string;@Input('dropdownActive') active:boolean;- private loadingPromise:Promise<any>;-constructor(readonly elementRef:ElementRef,readonly opContextMenu:OPContextMenuService,readonly browserDetector:BrowserDetector,@@ -66,21 +64,18 @@ export class OpTypesContextMenuDirective extends OpContextMenuTrigger {if (this.browserDetector.isMobile) {this.stateName = 'work-packages.new';}+ }- this.loadingPromise = this+ protected open(evt:JQuery.TriggeredEvent) {+ this.wpCreate.getEmptyForm(this.projectIdentifier).then(form => {- return this.buildItems(form.schema.type.allowedValues);+ this.buildItems(form.schema.type.allowedValues);+ this.opContextMenu.show(this, evt);});}- protected open(evt:JQuery.TriggeredEvent) {- this.loadingPromise.then(() => {- this.opContextMenu.show(this, evt);- });- }-public get locals():{ showAnchorRight?:boolean, contextMenuId?:string, items:OpContextMenuItem[] } {return {items: this.items,diff --git a/frontend/src/app/components/projects/current-project.service.spec.ts b/frontend/src/app/components/projects/current-project.service.spec.tsindex e1ad4094ce8..111d802ec83 100644--- a/frontend/src/app/components/projects/current-project.service.spec.ts+++ b/frontend/src/app/components/projects/current-project.service.spec.ts@@ -35,8 +35,16 @@ describe('currentProject service', function() {let element:JQuery;let currentProject:CurrentProjectService;+ let apiV3Stub:any = {+ projects: {+ id: (id:string) => {+ return { toString: () => '/api/v3/projects/' + id };+ }+ }+ };+beforeEach(() => {- currentProject = new CurrentProjectService(new PathHelperService());+ currentProject = new CurrentProjectService(new PathHelperService(), apiV3Stub);});describe('with no meta present', () => {diff --git a/frontend/src/app/components/projects/current-project.service.ts b/frontend/src/app/components/projects/current-project.service.tsindex 1c289014152..db55570692f 100644--- a/frontend/src/app/components/projects/current-project.service.ts+++ b/frontend/src/app/components/projects/current-project.service.ts@@ -28,12 +28,14 @@import {Injectable} from "@angular/core";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable({ providedIn: 'root' })export class CurrentProjectService {private current:{ id:string, identifier:string, name:string };- constructor(private PathHelper:PathHelperService) {+ constructor(private PathHelper:PathHelperService,+ private apiV3Service:APIV3Service) {this.detect();}@@ -51,7 +53,7 @@ export class CurrentProjectService {public get apiv3Path():string|null {if (this.current) {- return this.PathHelper.api.v3.projects.id(this.current.id).toString();+ return this.apiV3Service.projects.id(this.current.id).toString();}return null;diff --git a/frontend/src/app/components/projects/project-cache.service.ts b/frontend/src/app/components/projects/project-cache.service.tsdeleted file mode 100644index ad6411208c9..00000000000--- a/frontend/src/app/components/projects/project-cache.service.ts+++ /dev/null@@ -1,71 +0,0 @@-// -- 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 {MultiInputState} from 'reactivestates';-import {States} from '../states.service';-import {StateCacheService} from '../states/state-cache.service';-import {Injectable} from '@angular/core';-import {ProjectResource} from 'core-app/modules/hal/resources/project-resource';-import {ProjectDmService} from 'core-app/modules/hal/dm-services/project-dm.service';-import {SchemaCacheService} from "core-components/schemas/schema-cache.service";--@Injectable({ providedIn: 'root' })-export class ProjectCacheService extends StateCacheService<ProjectResource> {-- constructor(readonly states:States,- readonly schemaCacheService:SchemaCacheService,- readonly projectDmService:ProjectDmService) {- super();- }-- protected loadAll(ids:string[]):Promise<undefined> {- return Promise- .all(ids.map(id => this.load(id)))- .then(_ => undefined);- }-- updateValue(id:string, val:ProjectResource) {- this.schemaCacheService.ensureLoaded(val).then(() => {- super.updateValue(id, val);- });- }-- protected load(id:string):Promise<ProjectResource> {- return this- .projectDmService- .one(parseInt(id))- .then((project) => {- return this.schemaCacheService.ensureLoaded(project).then(() => project);- });- }-- protected get multiState():MultiInputState<ProjectResource> {- return this.states.projects;- }--}diff --git a/frontend/src/app/components/schemas/schema-cache.service.ts b/frontend/src/app/components/schemas/schema-cache.service.tsindex 18dfcb844b4..23bcf180989 100644--- a/frontend/src/app/components/schemas/schema-cache.service.ts+++ b/frontend/src/app/components/schemas/schema-cache.service.ts@@ -31,16 +31,18 @@ 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";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {Observable} from "rxjs";+import {take} from "rxjs/operators";@Injectable()export class SchemaCacheService extends StateCacheService<SchemaResource> {constructor(readonly states:States,readonly halResourceService:HalResourceService) {- super();+ super(states.schemas);}public state(id:string|HalResource):State<SchemaResource> {@@ -83,28 +85,54 @@ export class SchemaCacheService extends StateCacheService<SchemaResource> {* @param resource The resource with a schema property or a string to the schema href.* @return A promise with the loaded schema.*/- ensureLoaded(resource:HalResource):Promise<SchemaResource> {- return this.require(this.getSchemaHref(resource));+ ensureLoaded(resource:HalResource|string):Promise<SchemaResource> {+ let href = resource instanceof HalResource ? this.getSchemaHref(resource) : resource;++ return this+ .requireAndStream(href)+ .pipe(+ take(1)+ )+ .toPromise();+ }++ /**+ * Require the value to be loaded either when forced or the value is stale+ * according to the cache interval specified for this service.+ *+ * Returns an observable to the values stream of the state.+ *+ * @param id The state to require+ * @param force Load the value anyway.+ */+ public requireAndStream(href:string, force:boolean = false):Observable<SchemaResource> {+ // Refresh when stale or being forced+ if (this.stale(href) || force) {+ this.clearAndLoad(+ href,+ this.load(href)+ );+ }++ return this.state(href).values$();}/*** Load the associated schema for the given work package, if needed.*/- load(href:string, forceUpdate = false):Promise<SchemaResource> {+ protected load(href:string):Observable<SchemaResource> {return this.halResourceService.get<SchemaResource>(href)- .toPromise();+ .pipe(+ take(1)+ );}protected loadAll(hrefs:string[]):Promise<unknown|undefined> {return Promise.all(hrefs.map(href => this.load(href)));}- 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 updateddiff --git a/frontend/src/app/components/states.service.ts b/frontend/src/app/components/states.service.tsindex b0949e8510b..d379e498c53 100644--- a/frontend/src/app/components/states.service.ts+++ b/frontend/src/app/components/states.service.ts@@ -53,16 +53,22 @@ export class States extends StatesGroup {changes = new GlobalStateChanges();// Additional state map that can be dynamically registered.- additional:{ [id:string]:MultiInputState<HalResource> } = {};+ additional:{ [id:string]:MultiInputState<unknown> } = {};- forResource(resource:HalResource):InputState<HalResource>|undefined {- const stateName = _.camelCase(resource._type) + 's';+ forType<T>(stateName:string):MultiInputState<T> {let state = (this as any)[stateName] || this.additional[stateName];if (!state) {- state = this.additional[stateName] = multiInput<HalResource>();+ state = this.additional[stateName] = multiInput<T>();}+ return state as any;+ }++ forResource<T extends HalResource = HalResource>(resource:T):InputState<T>|undefined {+ const stateName = _.camelCase(resource._type) + 's';+ let state = this.forType<T>(stateName);+return state && state.get(resource.id!);}diff --git a/frontend/src/app/components/statuses/status-cache.service.ts b/frontend/src/app/components/statuses/status-cache.service.tsdeleted file mode 100644index 3b725979b51..00000000000--- a/frontend/src/app/components/statuses/status-cache.service.ts+++ /dev/null@@ -1,54 +0,0 @@-// -- 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 {MultiInputState} from "reactivestates";-import {Injectable} from '@angular/core';-import {StateCacheService} from 'core-components/states/state-cache.service';-import {States} from 'core-components/states.service';-import {StatusDmService} from "core-app/modules/hal/dm-services/status-dm.service";-import {StatusResource} from "core-app/modules/hal/resources/status-resource";--@Injectable({ providedIn: 'root' })-export class StatusCacheService extends StateCacheService<StatusResource> {-- constructor(readonly states:States,- readonly statusDm:StatusDmService) {- super();- }-- protected load(id:number|string):Promise<StatusResource> {- return this.statusDm.one(id);- }-- protected loadAll(ids:string[]):Promise<unknown> {- return this.statusDm.list();- }-- protected get multiState():MultiInputState<StatusResource> {- return this.states.statuses;- }-}diff --git a/frontend/src/app/components/table-pagination/pagination-service.ts b/frontend/src/app/components/table-pagination/pagination-service.tsindex 8e3d215c9a4..9f8d4ff3c90 100644--- a/frontend/src/app/components/table-pagination/pagination-service.ts+++ b/frontend/src/app/components/table-pagination/pagination-service.ts@@ -41,6 +41,12 @@ export interface IPaginationOptions {optionsTruncationSize:number;}+export interface PaginationObject {+ pageSize:number;+ offset:number;+}++@Injectable()export class PaginationService {private paginationOptions:IPaginationOptions;diff --git a/frontend/src/app/components/user/current-user.service.ts b/frontend/src/app/components/user/current-user.service.tsindex e84bb265376..3949df4d4ff 100644--- a/frontend/src/app/components/user/current-user.service.ts+++ b/frontend/src/app/components/user/current-user.service.ts@@ -38,6 +38,10 @@ export class CurrentUserService {return this.userMeta.data('id');}+ public get href() {+ return `/api/v3/users/${this.userId}`;+ }+public get name() {return this.userMeta.data('name');}diff --git a/frontend/src/app/components/user/user-avatar/user-avatar-renderer.service.ts b/frontend/src/app/components/user/user-avatar/user-avatar-renderer.service.tsindex a4e7713e265..810bf575e1b 100644--- a/frontend/src/app/components/user/user-avatar/user-avatar-renderer.service.ts+++ b/frontend/src/app/components/user/user-avatar/user-avatar-renderer.service.ts@@ -1,6 +1,7 @@import {Injectable} from "@angular/core";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {ColorsService} from "core-app/modules/common/colors/colors.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export interface UserLike {name:string;@@ -11,6 +12,7 @@ export interface UserLike {export class UserAvatarRendererService {constructor(private pathHelper:PathHelperService,+ private apiV3Service:APIV3Service,private colors:ColorsService) {}@@ -72,7 +74,7 @@ export class UserAvatarRendererService {const image = new Image();image.className = classes;image.classList.add('avatar--fallback');- image.src = this.pathHelper.api.v3.users.id(user.id).avatar.toString();+ image.src = this.apiV3Service.users.id(user.id).avatar.toString();image.title = user.name;image.alt = user.name;image.onload = function () {diff --git a/frontend/src/app/components/user/user-avatar/user-avatar.component.spec.ts b/frontend/src/app/components/user/user-avatar/user-avatar.component.spec.tsindex 562b76830dc..cfcf5b75180 100644--- a/frontend/src/app/components/user/user-avatar/user-avatar.component.spec.ts+++ b/frontend/src/app/components/user/user-avatar/user-avatar.component.spec.ts@@ -29,6 +29,8 @@import {async, ComponentFixture, TestBed} from '@angular/core/testing';import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';import {UserAvatarComponent} from "core-components/user/user-avatar/user-avatar.component";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {States} from "core-components/states.service";describe('UserAvatar component test', () => {let app:UserAvatarComponent;@@ -44,6 +46,8 @@ describe('UserAvatar component test', () => {UserAvatarComponent],providers: [+ States,+ APIV3Service,PathHelperService]}).compileComponents();diff --git a/frontend/src/app/components/user/user-cache.service.ts b/frontend/src/app/components/user/user-cache.service.tsdeleted file mode 100644index 1a9ed351571..00000000000--- a/frontend/src/app/components/user/user-cache.service.ts+++ /dev/null@@ -1,55 +0,0 @@-// -- 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 {MultiInputState} from "reactivestates";-import {Injectable} from '@angular/core';-import {UserResource} from 'core-app/modules/hal/resources/user-resource';-import {StateCacheService} from 'core-components/states/state-cache.service';-import {UserDmService} from 'core-app/modules/hal/dm-services/user-dm.service';-import {States} from 'core-components/states.service';--@Injectable({ providedIn: 'root' })-export class UserCacheService extends StateCacheService<UserResource> {-- constructor(readonly states:States,- readonly userDmService:UserDmService) {- super();- }-- protected load(id:number|string):Promise<UserResource> {- return this.userDmService.load(id);- }-- protected loadAll(ids:string[]):Promise<undefined> {- const promises = ids.map(id => this.load(id));- return Promise.all(promises).then(() => undefined);- }-- protected get multiState():MultiInputState<UserResource> {- return this.states.users;- }-}diff --git a/frontend/src/app/components/work-packages/work-package-cache.service.ts b/frontend/src/app/components/work-packages/work-package-cache.service.tsdeleted file mode 100644index 066884a9abc..00000000000--- a/frontend/src/app/components/work-packages/work-package-cache.service.ts+++ /dev/null@@ -1,159 +0,0 @@-// -- 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 {MultiInputState, State} from 'reactivestates';-import {States} from '../states.service';-import {StateCacheService} from '../states/state-cache.service';-import {SchemaCacheService} from './../schemas/schema-cache.service';-import {WorkPackageCollectionResource} from 'core-app/modules/hal/resources/wp-collection-resource';-import {SchemaResource} from 'core-app/modules/hal/resources/schema-resource';-import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';-import {Injectable} from '@angular/core';-import {debugLog} from "core-app/helpers/debug_output";-import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";--function getWorkPackageId(id:string|null):string {- return (id || 'new').toString();-}--@Injectable()-export class WorkPackageCacheService extends StateCacheService<WorkPackageResource> {-- /*@ngInject*/- constructor(private states:States,- private schemaCacheService:SchemaCacheService,- private workPackageDmService:WorkPackageDmService) {- super();- }-- public updateValue(id:string, val:WorkPackageResource) {- this.updateWorkPackageList([val], false);- }-- updateWorkPackage(wp:WorkPackageResource, immediate:boolean = false):Promise<void> {- const wpId = getWorkPackageId(wp.id!);-- if (immediate || wp.isNew) {- this.multiState.get(wpId).putValue(wp);- return Promise.resolve();- } else {- return this.schemaCacheService.ensureLoaded(wp).then(() => {- this.multiState.get(wpId).putValue(wp);- });- }- }-- updateWorkPackageList(list:WorkPackageResource[], skipOnIdentical = true) {- for (var i of list) {- const wp = i;- const workPackageId = getWorkPackageId(wp.id!);- const state = this.multiState.get(workPackageId);-- // If the work package is new, ignore the schema- if (wp.isNew) {- state.putValue(wp);- continue;- }-- // Ensure the schema is loaded- // so that no consumer needs to call schema#$load manually- this.schemaCacheService.ensureLoaded(wp).then(() => {- // Check if the work package has changed- if (skipOnIdentical && state.hasValue() && _.isEqual(state.value!.$source, wp.$source)) {- debugLog('Skipping identical work package from updating');- return;- }-- this.multiState.get(workPackageId).putValue(wp);- });- }- }-- /**- * Wrapper around `require(id)`.- *- * @deprecated- */- loadWorkPackage(workPackageId:string, forceUpdate = false):State<WorkPackageResource> {- const state = this.state(workPackageId);-- // Several services involved in the creation of work packages- // use this method to resolve the latest created work package,- // so let them just subscribe.- if (workPackageId === 'new') {- return state;- }-- this.require(workPackageId, forceUpdate);- return state;- }-- protected loadAll(ids:string[]) {- return new Promise<undefined>((resolve, reject) => {- this.workPackageDmService- .loadWorkPackagesCollectionsFor(_.uniq(ids))- .then((pagedResults:WorkPackageCollectionResource[]) => {- _.each(pagedResults, (results) => {- if (results.schemas) {- _.each(results.schemas.elements, (schema:SchemaResource) => {- this.states.schemas.get(schema.href as string).putValue(schema);- });- }-- if (results.elements) {- this.updateWorkPackageList(results.elements);- }-- resolve(undefined);- });- }, reject);- });- }-- protected load(id:string) {- return new Promise<WorkPackageResource>((resolve, reject) => {-- const errorAndReject = (error:any) => {- reject(error);- };-- this.workPackageDmService.loadWorkPackageById(id, true)- .then((workPackage:WorkPackageResource) => {- this.schemaCacheService.ensureLoaded(workPackage).then(() => {- this.multiState.get(id).putValue(workPackage);- resolve(workPackage);- }, errorAndReject);- }, errorAndReject);- });- }-- protected get multiState():MultiInputState<WorkPackageResource> {- return this.states.workPackages;- }--}diff --git a/frontend/src/app/components/work-packages/work-package-comment/work-package-comment.component.ts b/frontend/src/app/components/work-packages/work-package-comment/work-package-comment.component.tsindex 73d39f8976c..bf13348d7d7 100644--- a/frontend/src/app/components/work-packages/work-package-comment/work-package-comment.component.ts+++ b/frontend/src/app/components/work-packages/work-package-comment/work-package-comment.component.ts@@ -28,7 +28,6 @@import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {ErrorResource} from 'core-app/modules/hal/resources/error-resource';-import {WorkPackageCacheService} from '../work-package-cache.service';import {WorkPackagesActivityService} from 'core-components/wp-single-view-tabs/activity-panel/wp-activity.service';import {LoadingIndicatorService} from "core-app/modules/common/loading-indicator/loading-indicator.service";import {CommentService} from "core-components/wp-activity/comment-service";@@ -51,6 +50,7 @@ import {NotificationsService} from "core-app/modules/common/notifications/notifiimport {I18nService} from "core-app/modules/common/i18n/i18n.service";import {WorkPackageCommentFieldHandler} from "core-components/work-packages/work-package-comment/work-package-comment-field-handler";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'work-package-comment',@@ -81,7 +81,7 @@ export class WorkPackageCommentComponent extends WorkPackageCommentFieldHandlerprotected wpLinkedActivities:WorkPackagesActivityService,protected ConfigurationService:ConfigurationService,protected loadingIndicator:LoadingIndicatorService,- protected wpCacheService:WorkPackageCacheService,+ protected apiV3Service:APIV3Service,protected workPackageNotificationService:WorkPackageNotificationService,protected NotificationsService:NotificationsService,protected cdRef:ChangeDetectorRef,@@ -151,7 +151,11 @@ export class WorkPackageCommentComponent extends WorkPackageCommentFieldHandlerthis.NotificationsService.addSuccess(this.I18n.t('js.work_packages.comment_added'));this.wpLinkedActivities.require(this.workPackage, true);- this.wpCacheService.updateWorkPackage(this.workPackage);+ this+ .apiV3Service+ .work_packages+ .cache+ .updateWorkPackage(this.workPackage);this.inFlight = false;this.deactivate(true);})diff --git a/frontend/src/app/components/work-packages/wp-relations-count/wp-relations-count.component.ts b/frontend/src/app/components/work-packages/wp-relations-count/wp-relations-count.component.tsindex fca07dda33e..99380376750 100644--- a/frontend/src/app/components/work-packages/wp-relations-count/wp-relations-count.component.ts+++ b/frontend/src/app/components/work-packages/wp-relations-count/wp-relations-count.component.ts@@ -1,8 +1,8 @@import {Component, Input, OnInit} from '@angular/core';import {WorkPackageRelationsService} from '../../wp-relations/wp-relations.service';-import {WorkPackageCacheService} from '../../work-packages/work-package-cache.service';import {combineLatest} from 'rxjs';import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './wp-relations-count.html',@@ -12,7 +12,7 @@ export class WorkPackageRelationsCountComponent extends UntilDestroyedMixin impl@Input('wpId') wpId:string;public count:number = 0;- constructor(protected wpCacheService:WorkPackageCacheService,+ constructor(protected apiV3Service:APIV3Service,protected wpRelations:WorkPackageRelationsService) {super();}@@ -20,10 +20,17 @@ export class WorkPackageRelationsCountComponent extends UntilDestroyedMixin implngOnInit():void {this.wpRelations.require(this.wpId.toString());- combineLatest(- this.wpRelations.state(this.wpId.toString()).values$(),- this.wpCacheService.loadWorkPackage(this.wpId.toString()).values$()- ).pipe(+ combineLatest([+ this+ .wpRelations+ .state(this.wpId.toString())+ .values$(),+ this+ .apiV3Service+ .work_packages+ .id(this.wpId)+ .requireAndStream()+ ]).pipe(this.untilDestroyed()).subscribe(([relations, workPackage]) => {let relationCount = _.size(relations);diff --git a/frontend/src/app/components/work-packages/wp-relations-count/wp-watchers-count.component.ts b/frontend/src/app/components/work-packages/wp-relations-count/wp-watchers-count.component.tsindex 257ab4747d3..b20508b7114 100644--- a/frontend/src/app/components/work-packages/wp-relations-count/wp-watchers-count.component.ts+++ b/frontend/src/app/components/work-packages/wp-relations-count/wp-watchers-count.component.ts@@ -1,30 +1,38 @@-import {Component, Input, OnInit} from '@angular/core';-import {WorkPackageCacheService} from '../../work-packages/work-package-cache.service';+import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit} from '@angular/core';import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";-import { WorkPackageWatchersService } from 'core-app/components/wp-single-view-tabs/watchers-tab/wp-watchers.service';-import { HalResource } from 'core-app/modules/hal/resources/hal-resource';+import {WorkPackageWatchersService} from 'core-app/components/wp-single-view-tabs/watchers-tab/wp-watchers.service';+import {HalResource} from 'core-app/modules/hal/resources/hal-resource';+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './wp-relations-count.html',selector: 'wp-watchers-count',+ changeDetection: ChangeDetectionStrategy.OnPush})export class WorkPackageWatchersCountComponent extends UntilDestroyedMixin implements OnInit {@Input('wpId') wpId:string;public count:number = 0;- constructor(protected wpCacheService:WorkPackageCacheService,- protected wpWatcherService:WorkPackageWatchersService) {+ constructor(protected apiV3Service:APIV3Service,+ protected wpWatcherService:WorkPackageWatchersService,+ protected cdRef:ChangeDetectorRef) {super();}ngOnInit():void {- this.wpCacheService.loadWorkPackage(this.wpId.toString()).values$()+ this+ .apiV3Service+ .work_packages+ .id(this.wpId)+ .requireAndStream().pipe(this.untilDestroyed()).subscribe((workPackage) => {- this.wpWatcherService.require(workPackage)+ this.wpWatcherService+ .require(workPackage).then((watchers:HalResource[]) => {this.count = watchers.length;+ this.cdRef.detectChanges();});});}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 5b6260e8840..5757d32c866 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@@ -44,7 +44,6 @@ import {States} from '../../states.service';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";-import {WorkPackageCacheService} from '../work-package-cache.service';import {DisplayFieldService} from 'core-app/modules/fields/display/display-field.service';import {DisplayField} from 'core-app/modules/fields/display/display-field.module';import {QueryResource} from 'core-app/modules/hal/resources/query-resource';@@ -57,6 +56,7 @@ import {HalResourceService} from "core-app/modules/hal/services/hal-resource.serimport {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";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export interface FieldDescriptor {name:string;@@ -140,7 +140,6 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemenprotected halEditing:HalResourceEditingService,protected halResourceService:HalResourceService,protected displayFieldService:DisplayFieldService,- protected wpCacheService:WorkPackageCacheService,protected schemaCache:SchemaCacheService,protected hook:HookService,protected injector:Injector,diff --git a/frontend/src/app/components/work-packages/wp-subject/wp-subject.component.ts b/frontend/src/app/components/work-packages/wp-subject/wp-subject.component.tsindex b7a218d4256..4d1736afa02 100644--- a/frontend/src/app/components/work-packages/wp-subject/wp-subject.component.ts+++ b/frontend/src/app/components/work-packages/wp-subject/wp-subject.component.ts@@ -29,9 +29,9 @@import {Component, Input, OnInit} from '@angular/core';import {UIRouterGlobals} from '@uirouter/core';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';-import {WorkPackageCacheService} from '../work-package-cache.service';import {randomString} from "core-app/helpers/random-string";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'wp-subject',@@ -43,14 +43,17 @@ export class WorkPackageSubjectComponent extends UntilDestroyedMixin implementspublic readonly uniqueElementIdentifier = `work-packages--subject-type-row-${randomString(16)}`;constructor(protected uiRouterGlobals:UIRouterGlobals,- protected wpCacheService:WorkPackageCacheService) {+ protected apiV3Service:APIV3Service) {super();}ngOnInit() {if (!this.workPackage) {- this.wpCacheService.loadWorkPackage(this.uiRouterGlobals.params['workPackageId'])- .values$()+ this+ .apiV3Service+ .work_packages+ .id(this.uiRouterGlobals.params['workPackageId'])+ .requireAndStream().pipe(this.untilDestroyed())diff --git a/frontend/src/app/components/work-packages/wp-watcher-button/wp-watcher-button.component.ts b/frontend/src/app/components/work-packages/wp-watcher-button/wp-watcher-button.component.tsindex db6f5b72d3d..e5995a96c9b 100644--- a/frontend/src/app/components/work-packages/wp-watcher-button/wp-watcher-button.component.ts+++ b/frontend/src/app/components/work-packages/wp-watcher-button/wp-watcher-button.component.ts@@ -27,15 +27,16 @@// ++import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';-import {WorkPackageCacheService} from '../work-package-cache.service';-import {Component, Input, OnInit} from '@angular/core';+import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit} from '@angular/core';import {I18nService} from 'core-app/modules/common/i18n/i18n.service';import {WorkPackageWatchersService} from 'core-components/wp-single-view-tabs/watchers-tab/wp-watchers.service';import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'wp-watcher-button',- templateUrl: './wp-watcher-button.html'+ templateUrl: './wp-watcher-button.html',+ changeDetection: ChangeDetectionStrategy.OnPush})export class WorkPackageWatcherButtonComponent extends UntilDestroyedMixin implements OnInit {@Input('workPackage') public workPackage:WorkPackageResource;@@ -50,19 +51,24 @@ export class WorkPackageWatcherButtonComponent extends UntilDestroyedMixin impleconstructor(readonly I18n:I18nService,readonly wpWatchersService:WorkPackageWatchersService,- readonly wpCacheService:WorkPackageCacheService) {+ readonly apiV3Service:APIV3Service,+ readonly cdRef:ChangeDetectorRef) {super();}ngOnInit() {- this.wpCacheService.loadWorkPackage(this.workPackage.id!)- .values$()+ this+ .apiV3Service+ .work_packages+ .id(this.workPackage)+ .requireAndStream().pipe(this.untilDestroyed()).subscribe((wp:WorkPackageResource) => {this.workPackage = wp;this.setWatchStatus();+ this.cdRef.detectChanges();});}@@ -79,7 +85,11 @@ export class WorkPackageWatcherButtonComponent extends UntilDestroyedMixin impletoggleLink(toggleLink.$link.payload).then(() => {this.wpWatchersService.clear(this.workPackage.id!);- this.wpCacheService.loadWorkPackage(this.workPackage.id!, true);+ this+ .apiV3Service+ .work_packages+ .id(this.workPackage)+ .refresh();});}diff --git a/frontend/src/app/components/wp-activity/revision/revision-activity.component.ts b/frontend/src/app/components/wp-activity/revision/revision-activity.component.tsindex 20bfc87c0f2..af2e70c356f 100644--- a/frontend/src/app/components/wp-activity/revision/revision-activity.component.ts+++ b/frontend/src/app/components/wp-activity/revision/revision-activity.component.ts@@ -28,11 +28,11 @@import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit} from "@angular/core";import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";-import {UserCacheService} from "core-components/user/user-cache.service";import {UserResource} from "core-app/modules/hal/resources/user-resource";import {ProjectResource} from "core-app/modules/hal/resources/project-resource";import {TimezoneService} from "core-components/datetime/timezone.service";import {I18nService} from "core-app/modules/common/i18n/i18n.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'revision-activity',@@ -60,7 +60,7 @@ export class RevisionActivityComponent implements OnInit {constructor(readonly I18n:I18nService,readonly timezoneService:TimezoneService,readonly cdRef:ChangeDetectorRef,- readonly userCacheService:UserCacheService) {+ readonly apiV3Service:APIV3Service) {}ngOnInit() {@@ -92,9 +92,12 @@ export class RevisionActivityComponent implements OnInit {if (this.activity.author === undefined) {this.userName = this.activity.authorName;} else {- this.userCacheService- .require(this.activity.author.idFromLink)- .then((user:UserResource) => {+ this+ .apiV3Service+ .users+ .id(this.activity.author.idFromLink)+ .get()+ .subscribe((user:UserResource) => {this.userId = user.id!;this.userName = user.name;this.userActive = user.isActive;diff --git a/frontend/src/app/components/wp-activity/user/user-activity.component.ts b/frontend/src/app/components/wp-activity/user/user-activity.component.tsindex da258caa133..f56a5ccebc9 100644--- a/frontend/src/app/components/wp-activity/user/user-activity.component.ts+++ b/frontend/src/app/components/wp-activity/user/user-activity.component.ts@@ -27,7 +27,6 @@//++import {UserResource} from 'core-app/modules/hal/resources/user-resource';-import {WorkPackageCacheService} from '../../work-packages/work-package-cache.service';import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';import {ConfigurationService} from 'core-app/modules/common/config/configuration.service';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';@@ -42,12 +41,12 @@ import {Input,OnInit} from "@angular/core";-import {UserCacheService} from "core-components/user/user-cache.service";import {CommentService} from "core-components/wp-activity/comment-service";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {WorkPackageCommentFieldHandler} from "core-components/work-packages/work-package-comment/work-package-comment-field-handler";import {DomSanitizer, SafeHtml} from "@angular/platform-browser";import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'user-activity',@@ -89,9 +88,8 @@ export class UserActivityComponent extends WorkPackageCommentFieldHandler implemreadonly PathHelper:PathHelperService,readonly wpLinkedActivities:WorkPackagesActivityService,readonly commentService:CommentService,- readonly wpCacheService:WorkPackageCacheService,readonly ConfigurationService:ConfigurationService,- readonly userCacheService:UserCacheService,+ readonly apiV3Service:APIV3Service,readonly cdRef:ChangeDetectorRef,readonly I18n:I18nService) {super(elementRef, injector);@@ -116,9 +114,12 @@ export class UserActivityComponent extends WorkPackageCommentFieldHandler implemthis.details.push(detail.html);});- this.userCacheService- .require(this.activity.user.idFromLink)- .then((user:UserResource) => {+ this+ .apiV3Service+ .users+ .id(this.activity.user.idFromLink)+ .get()+ .subscribe((user:UserResource) => {this.user = user;this.userId = user.id!;this.userName = user.name;@@ -170,7 +171,11 @@ export class UserActivityComponent extends WorkPackageCommentFieldHandler implemthis.activity = newActivity;this.updateCommentText();this.wpLinkedActivities.require(this.workPackage, true);- this.wpCacheService.updateWorkPackage(this.workPackage);+ this+ .apiV3Service+ .work_packages+ .cache+ .updateWorkPackage(this.workPackage);}).finally(() => {this.deactivate(true); this.inFlight = false;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 6f1e7367396..5ba595bd1e2 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@@ -33,12 +33,9 @@ import {ChangeDetectorRef, Component, Input, OnInit} from '@angular/core';import {I18nService} from 'core-app/modules/common/i18n/i18n.service';import {Highlighting} from "core-components/wp-fast-table/builders/highlighting/highlighting.functions";import {HalResource} from "core-app/modules/hal/resources/hal-resource";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {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";+import {ISchemaProxy} from "core-app/modules/hal/schemas/schema-proxy";@Component({selector: 'wp-status-button',@@ -57,7 +54,6 @@ export class WorkPackageStatusButtonComponent extends UntilDestroyedMixin implemconstructor(readonly I18n:I18nService,readonly cdRef:ChangeDetectorRef,- readonly wpCacheService:WorkPackageCacheService,readonly schemaCache:SchemaCacheService,readonly halEditing:HalResourceEditingService) {super();diff --git a/frontend/src/app/components/wp-card-view/services/wp-card-drag-and-drop.service.ts b/frontend/src/app/components/wp-card-view/services/wp-card-drag-and-drop.service.tsindex be97d42eced..c929c5da8ab 100644--- a/frontend/src/app/components/wp-card-view/services/wp-card-drag-and-drop.service.ts+++ b/frontend/src/app/components/wp-card-view/services/wp-card-drag-and-drop.service.ts@@ -9,8 +9,8 @@ import {DragAndDropService} from "core-app/modules/common/drag-and-drop/drag-andimport {DragAndDropHelpers} from "core-app/modules/common/drag-and-drop/drag-and-drop.helpers";import {WorkPackageCardViewComponent} from "core-components/wp-card-view/wp-card-view.component";import {WorkPackageChangeset} from "core-components/wp-edit/work-package-changeset";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable()export class WorkPackageCardDragAndDropService {@@ -29,7 +29,7 @@ export class WorkPackageCardDragAndDropService {readonly reorderService:WorkPackageViewOrderService,readonly wpCreate:WorkPackageCreateService,readonly notificationService:WorkPackageNotificationService,- readonly wpCacheService:WorkPackageCacheService,+ readonly apiV3Service:APIV3Service,readonly currentProject:CurrentProjectService,@Optional() readonly dragService:DragAndDropService,readonly wpInlineCreate:WorkPackageInlineCreateService) {@@ -82,7 +82,12 @@ export class WorkPackageCardDragAndDropService {const wpId:string = card.dataset.workPackageId!;const toIndex = DragAndDropHelpers.findIndex(card);- const workPackage = await this.wpCacheService.require(wpId);+ const workPackage = await this+ .apiV3Service+ .work_packages+ .id(wpId)+ .get()+ .toPromise();const result = await this.addWorkPackageToQuery(workPackage, toIndex);if (card.parentElement) {@@ -138,7 +143,14 @@ export class WorkPackageCardDragAndDropService {newOrder = _.uniq(newOrder);Promise- .all(newOrder.map(id => this.wpCacheService.require(id)))+ .all(newOrder.map(id =>+ this+ .apiV3Service+ .work_packages+ .id(id)+ .get()+ .toPromise()+ )).then((workPackages:WorkPackageResource[]) => {this.workPackages = workPackages;this.cardView.cdRef.detectChanges();diff --git a/frontend/src/app/components/wp-copy/wp-copy.controller.ts b/frontend/src/app/components/wp-copy/wp-copy.controller.tsindex ecfc757d52b..e1ac277b2c3 100644--- a/frontend/src/app/components/wp-copy/wp-copy.controller.ts+++ b/frontend/src/app/components/wp-copy/wp-copy.controller.ts@@ -64,8 +64,11 @@ export class WorkPackageCopyController extends WorkPackageCreateComponent {protected createdWorkPackage() {this.copiedWorkPackageId = this.stateParams.copiedFromWorkPackageId;return new Promise<WorkPackageChangeset>((resolve, reject) => {- this.wpCacheService.loadWorkPackage(this.copiedWorkPackageId)- .values$()+ this+ .apiV3Service+ .work_packages+ .id(this.copiedWorkPackageId)+ .get().pipe(take(1))@@ -87,7 +90,12 @@ export class WorkPackageCopyController extends WorkPackageCreateComponent {.then((copyChangeset:WorkPackageChangeset) => {this.__initialized_at = copyChangeset.pristineResource.__initialized_at;- this.wpCacheService.updateWorkPackage(copyChangeset.pristineResource);+ this+ .apiV3Service+ .work_packages+ .cache+ .updateWorkPackage(copyChangeset.pristineResource, true);+this.halEditing.updateValue('new', copyChangeset);return copyChangeset;diff --git a/frontend/src/app/components/wp-custom-actions/wp-custom-actions/wp-custom-action.component.ts b/frontend/src/app/components/wp-custom-actions/wp-custom-actions/wp-custom-action.component.tsindex fe541ad2bb8..b52aec4b95e 100644--- a/frontend/src/app/components/wp-custom-actions/wp-custom-actions/wp-custom-action.component.ts+++ b/frontend/src/app/components/wp-custom-actions/wp-custom-actions/wp-custom-action.component.ts@@ -29,7 +29,6 @@import {Component, HostListener, Input} from '@angular/core';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';-import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';import {CustomActionResource} from 'core-app/modules/hal/resources/custom-action-resource';import {WorkPackagesActivityService} from 'core-components/wp-single-view-tabs/activity-panel/wp-activity.service';@@ -38,6 +37,7 @@ import {HalResourceEditingService} from "core-app/modules/fields/edit/services/himport {SchemaCacheService} from "core-components/schemas/schema-cache.service";import {HalEventsService} from "core-app/modules/hal/services/hal-events.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'wp-custom-action',@@ -49,7 +49,7 @@ export class WpCustomActionComponent {@Input() action:CustomActionResource;constructor(private halResourceService:HalResourceService,- private wpCacheService:WorkPackageCacheService,+ private apiV3Service:APIV3Service,private wpSchemaCacheService:SchemaCacheService,private wpActivity:WorkPackagesActivityService,private notificationService:WorkPackageNotificationService,@@ -75,22 +75,22 @@ export class WpCustomActionComponent {}};- this.halResourceService.post<WorkPackageResource>(this.action.href + '/execute', payload)- .toPromise()- .then((savedWp:WorkPackageResource) => {- this.notificationService.showSave(savedWp, false);- this.workPackage = savedWp;- this.wpActivity.clear(this.workPackage.id!);- // Loading the schema might be necessary in cases where the button switches- // project or type.- this.wpSchemaCacheService.ensureLoaded(savedWp).then(() => {- this.wpCacheService.updateWorkPackage(savedWp, true);- this.halEditing.stopEditing(savedWp);- this.halEvents.push(savedWp, { eventType: "updated" });- });- }).catch((errorResource:any) => {- this.notificationService.handleRawError(errorResource, this.workPackage);- });+ this.halResourceService+ .post<WorkPackageResource>(this.action.href + '/execute', payload)+ .subscribe(+ (savedWp:WorkPackageResource) => {+ this.notificationService.showSave(savedWp, false);+ this.workPackage = savedWp;+ this.wpActivity.clear(this.workPackage.id!);+ // Loading the schema might be necessary in cases where the button switches+ // project or type.+ this.apiV3Service.work_packages.cache.updateWorkPackage(savedWp).then(() => {+ this.halEditing.stopEditing(savedWp);+ this.halEvents.push(savedWp, { eventType: "updated" });+ });+ },+ (errorResource:any) => this.notificationService.handleRawError(errorResource, this.workPackage)+ );}@HostListener('mouseenter') onMouseEnter() {diff --git a/frontend/src/app/components/wp-edit-form/table-edit-form.ts b/frontend/src/app/components/wp-edit-form/table-edit-form.tsindex 185aee86c55..4092e73e5b7 100644--- a/frontend/src/app/components/wp-edit-form/table-edit-form.ts+++ b/frontend/src/app/components/wp-edit-form/table-edit-form.ts@@ -40,15 +40,15 @@ import {WorkPackageTable} from "core-components/wp-fast-table/wp-fast-table";import {EditForm} from "core-app/modules/fields/edit/edit-form/edit-form";import {editModeClassName} from "core-app/modules/fields/edit/edit-field.component";import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export const activeFieldContainerClassName = 'inline-edit--active-field';export const activeFieldClassName = 'inline-edit--field';export class TableEditForm extends EditForm<WorkPackageResource> {@InjectField() public wpTableColumns:WorkPackageViewColumnsService;- @InjectField() public wpCacheService:WorkPackageCacheService;+ @InjectField() public apiV3Service:APIV3Service;@InjectField() public states:States;@InjectField() public FocusHelper:FocusHelperService;@InjectField() public editingPortalService:EditingPortalService;@@ -57,8 +57,11 @@ export class TableEditForm extends EditForm<WorkPackageResource> {private cellBuilder = new CellBuilder(this.injector);// Subscription- private resourceSubscription:Subscription = this.wpCacheService- .requireAndStream(this.workPackageId)+ private resourceSubscription:Subscription = this+ .apiV3Service+ .work_packages+ .id(this.workPackageId)+ .requireAndStream().subscribe((wp) => this.resource = wp);constructor(public injector:Injector,diff --git a/frontend/src/app/components/wp-edit-form/work-package-filter-values.spec.ts b/frontend/src/app/components/wp-edit-form/work-package-filter-values.spec.tsindex 7c28eaed4b0..35038b99a1c 100644--- a/frontend/src/app/components/wp-edit-form/work-package-filter-values.spec.ts+++ b/frontend/src/app/components/wp-edit-form/work-package-filter-values.spec.ts@@ -30,7 +30,6 @@ import {TestBed} from "@angular/core/testing";import {CurrentUserService} from "core-components/user/current-user.service";import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";import {Injector} from "@angular/core";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {SchemaCacheService} from "core-components/schemas/schema-cache.service";import {WorkPackageFilterValues} from "core-components/wp-edit-form/work-package-filter-values";import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";@@ -47,7 +46,6 @@ import {NotificationsService} from "core-app/modules/common/notifications/notifiimport {ConfigurationService} from "core-app/modules/common/config/configuration.service";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {UIRouterModule} from "@uirouter/angular";-import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";import {LoadingIndicatorService} from "core-app/modules/common/loading-indicator/loading-indicator.service";import {OpenProjectFileUploadService} from "core-components/api/op-file-upload/op-file-upload.service";import {HookService} from "core-app/modules/plugins/hook-service";@@ -55,7 +53,6 @@ import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isoimport {HalEventsService} from "core-app/modules/hal/services/hal-events.service";import {TimezoneService} from "core-components/datetime/timezone.service";import {WorkPackageChangeset} from "core-components/wp-edit/work-package-changeset";-import {ConfigurationDmService} from "core-app/modules/hal/dm-services/configuration-dm.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";describe('WorkPackageFilterValues', () => {@@ -83,18 +80,15 @@ describe('WorkPackageFilterValues', () => {TimezoneService,PathHelperService,ConfigurationService,- ConfigurationDmService,CurrentUserService,HookService,OpenProjectFileUploadService,LoadingIndicatorService,- WorkPackageDmService,HalResourceService,NotificationsService,HalResourceNotificationService,SchemaCacheService,WorkPackageNotificationService,- WorkPackageCacheService,WorkPackageCreateService,HalResourceEditingService,WorkPackagesActivityService,@@ -173,7 +167,7 @@ describe('WorkPackageFilterValues', () => {expect(changeset.changedAttributes.length).toEqual(0);expect(changeset.value('type').href).toEqual('/api/v3/types/2');}));- })+ });});});diff --git a/frontend/src/app/components/wp-fast-table/builders/drag-and-drop/drag-drop-handle-render-pass.ts b/frontend/src/app/components/wp-fast-table/builders/drag-and-drop/drag-drop-handle-render-pass.tsindex fefa3dbfc7a..4a515bb30d4 100644--- a/frontend/src/app/components/wp-fast-table/builders/drag-and-drop/drag-drop-handle-render-pass.ts+++ b/frontend/src/app/components/wp-fast-table/builders/drag-and-drop/drag-drop-handle-render-pass.ts@@ -3,9 +3,9 @@ import {PrimaryRenderPass, RowRenderInfo} from '../primary-render-pass';import {DragDropHandleBuilder} from "core-components/wp-fast-table/builders/drag-and-drop/drag-drop-handle-builder";import {WorkPackageTable} from "core-components/wp-fast-table/wp-fast-table";import {WorkPackageViewOrderService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-order.service";-import {QueryOrder} from "core-app/modules/hal/dm-services/query-order-dm.service";import {WorkPackageViewColumnsService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-columns.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {QueryOrder} from "core-app/modules/apiv3/endpoints/queries/apiv3-query-order";export class DragDropHandleRenderPass {diff --git a/frontend/src/app/components/wp-fast-table/builders/modes/hierarchy/hierarchy-render-pass.ts b/frontend/src/app/components/wp-fast-table/builders/modes/hierarchy/hierarchy-render-pass.tsindex 4d061cfbb21..383ec4eaee3 100644--- a/frontend/src/app/components/wp-fast-table/builders/modes/hierarchy/hierarchy-render-pass.ts+++ b/frontend/src/app/components/wp-fast-table/builders/modes/hierarchy/hierarchy-render-pass.ts@@ -1,5 +1,4 @@import {Injector} from '@angular/core';-import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';import {additionalHierarchyRowClassName, SingleHierarchyRowBuilder} from './single-hierarchy-row-builder';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {PrimaryRenderPass, RowRenderInfo} from "core-components/wp-fast-table/builders/primary-render-pass";@@ -14,12 +13,13 @@ import {WorkPackageViewHierarchies} from "core-app/modules/work_packages/routingimport {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";import {WorkPackageViewHierarchiesService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-hierarchy.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export class HierarchyRenderPass extends PrimaryRenderPass {@InjectField() querySpace:IsolatedQuerySpace;@InjectField() states:States;- @InjectField() wpCacheService:WorkPackageCacheService;+ @InjectField() apiV3Service:APIV3Service;@InjectField() wpTableHierarchies:WorkPackageViewHierarchiesService;// Remember which rows were already rendered@@ -49,7 +49,7 @@ export class HierarchyRenderPass extends PrimaryRenderPass {this.hierarchies = this.wpTableHierarchies.current;- _.each(this.workPackageTable.originalRowIndex, (row,) => {+ _.each(this.workPackageTable.originalRowIndex, (row, ) => {row.object.ancestors.forEach((ancestor:WorkPackageResource) => {this.parentsWithVisibleChildren[ancestor.id!] = true;});@@ -126,7 +126,7 @@ export class HierarchyRenderPass extends PrimaryRenderPass {let elements = this.deferred[parent.id!] || [];// Append to them the child and all children belowlet newElements:WorkPackageResource[] = ancestorChain.slice(i + 1, ancestorChain.length);- newElements = newElements.map(child => this.wpCacheService.state(child.id!).value!);+ newElements = newElements.map(child => this.apiV3Service.work_packages.cache.state(child.id!).value!);// Append all new elementselements = elements.concat(newElements);// Remove duplicates (Regression #29652)diff --git a/frontend/src/app/components/wp-fast-table/builders/timeline/timeline-row-builder.ts b/frontend/src/app/components/wp-fast-table/builders/timeline/timeline-row-builder.tsindex 376f36f69cb..f466b2e8eaf 100644--- a/frontend/src/app/components/wp-fast-table/builders/timeline/timeline-row-builder.ts+++ b/frontend/src/app/components/wp-fast-table/builders/timeline/timeline-row-builder.ts@@ -1,10 +1,10 @@import {Injector} from '@angular/core';import {States} from '../../../states.service';-import {WorkPackageCacheService} from '../../../work-packages/work-package-cache.service';import {WorkPackageTable} from '../../wp-fast-table';import {commonRowClassName} from '../rows/single-row-builder';import {WorkPackageViewTimelineService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-timeline.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export const timelineCellClassName = 'wp-timeline-cell';@@ -12,7 +12,6 @@ export class TimelineRowBuilder {@InjectField() public states:States;@InjectField() public wpTableTimeline:WorkPackageViewTimelineService;- @InjectField() public wpCacheService:WorkPackageCacheService;constructor(public readonly injector:Injector,protected workPackageTable:WorkPackageTable) {diff --git a/frontend/src/app/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts b/frontend/src/app/components/wp-fast-table/handlers/state/drag-and-drop-transformer.tsindex a81da083a43..d04602e619e 100644--- a/frontend/src/app/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts+++ b/frontend/src/app/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts@@ -14,9 +14,9 @@ import {DragAndDropHelpers} from "core-app/modules/common/drag-and-drop/drag-andimport {WorkPackageViewOrderService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-order.service";import {RenderedWorkPackage} from "core-app/modules/work_packages/render-info/rendered-work-package.type";import {BrowserDetector} from "core-app/modules/common/browser/browser-detector.service";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {WorkPackagesListService} from "core-components/wp-list/wp-list.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export class DragAndDropTransformer {@@ -27,7 +27,7 @@ export class DragAndDropTransformer {@InjectField() private readonly wpTableSortBy:WorkPackageViewSortByService;@InjectField() private readonly wpTableOrder:WorkPackageViewOrderService;@InjectField() private readonly browserDetector:BrowserDetector;- @InjectField() private readonly wpCacheService:WorkPackageCacheService;+ @InjectField() private readonly apiV3Service:APIV3Service;@InjectField() private readonly wpListService:WorkPackagesListService;@InjectField() private readonly dragActionRegistry:TableDragActionsRegistryService;@InjectField(DragAndDropService, null) private readonly dragService:DragAndDropService|null;@@ -72,7 +72,7 @@ export class DragAndDropTransformer {const rowIndex = this.findRowIndex(el);try {- const workPackage = await this.wpCacheService.require(wpId);+ const workPackage = await this.apiV3Service.work_packages.id(wpId).get().toPromise();const newOrder = await this.wpTableOrder.move(this.currentOrder, wpId, rowIndex);await this.actionService.handleDrop(workPackage, el);this.updateRenderedOrder(newOrder);@@ -97,7 +97,7 @@ export class DragAndDropTransformer {},onAdded: async (el:HTMLElement) => {const wpId:string = el.dataset.workPackageId!;- const workPackage = await this.wpCacheService.require(wpId);+ const workPackage = await this.apiV3Service.work_packages.id(wpId).get().toPromise();const rowIndex = this.findRowIndex(el);return this.actionService@@ -114,7 +114,7 @@ export class DragAndDropTransformer {onCloned: async (clone:HTMLElement, original:HTMLElement) => {// Replace clone with one TD of the subjectconst wpId:string = original.dataset.workPackageId!;- const workPackage = await this.wpCacheService.require(wpId);+ const workPackage = await this.apiV3Service.work_packages.id(wpId).get().toPromise();const colspan = clone.children.length;const td = document.createElement('td');@@ -144,7 +144,11 @@ export class DragAndDropTransformer {private async updateRenderedOrder(order:string[]) {order = _.uniq(order);- const mappedOrder = await Promise.all(order.map(id => this.wpCacheService.require(id)));+ const mappedOrder = await Promise.all(+ order.map(+ wpId => this.apiV3Service.work_packages.id(wpId).get().toPromise()+ )+ );/** Re-render the table */this.table.initialSetup(mappedOrder);diff --git a/frontend/src/app/components/wp-fast-table/wp-fast-table.ts b/frontend/src/app/components/wp-fast-table/wp-fast-table.tsindex a8b5a6ecdf4..2492212fd39 100644--- a/frontend/src/app/components/wp-fast-table/wp-fast-table.ts+++ b/frontend/src/app/components/wp-fast-table/wp-fast-table.ts@@ -5,7 +5,6 @@ import {debugLog} from '../../helpers/debug_output';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {States} from '../states.service';-import {WorkPackageCacheService} from '../work-packages/work-package-cache.service';import {WorkPackageTimelineTableController} from '../wp-table/timeline/container/wp-timeline-container.directive';import {GroupedRowsBuilder} from './builders/modes/grouped/grouped-rows-builder';import {HierarchyRowsBuilder} from './builders/modes/hierarchy/hierarchy-rows-builder';@@ -18,11 +17,12 @@ import {WorkPackageTableRow} from './wp-table.interfaces';import {WorkPackageTableConfiguration} from 'core-app/components/wp-table/wp-table-configuration';import {RenderedWorkPackage} from "core-app/modules/work_packages/render-info/rendered-work-package.type";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export class WorkPackageTable {@InjectField() querySpace:IsolatedQuerySpace;- @InjectField() wpCacheService:WorkPackageCacheService;+ @InjectField() apiV3Service:APIV3Service;@InjectField() states:States;@InjectField() I18n:I18nService;@@ -77,7 +77,7 @@ export class WorkPackageTable {let wpId = wp.id!;// Ensure we get the latest version- wp = this.wpCacheService.current(wpId, wp)!;+ wp = this.apiV3Service.work_packages.cache.current(wpId, wp)!;this.originalRowIndex[wpId] = <WorkPackageTableRow>{ object: wp, workPackageId: wpId, position: i };return wpId;diff --git a/frontend/src/app/components/wp-list/wp-list-invalid-query.service.ts b/frontend/src/app/components/wp-list/wp-list-invalid-query.service.tsindex 65146fafe23..711da9a23cf 100644--- a/frontend/src/app/components/wp-list/wp-list-invalid-query.service.ts+++ b/frontend/src/app/components/wp-list/wp-list-invalid-query.service.ts@@ -36,28 +36,25 @@ import {QueryFilterInstanceSchemaResource} from 'core-app/modules/hal/resources/import {QueryColumn} from '../wp-query/query-column';import {Injectable} from '@angular/core';import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {QueryFormDmService} from "core-app/modules/hal/dm-services/query-form-dm.service";@Injectable()export class WorkPackagesListInvalidQueryService {- constructor(protected halResourceService:HalResourceService,- protected queryFormDm:QueryFormDmService) {}+ constructor(protected halResourceService:HalResourceService) {+ }public restoreQuery(query:QueryResource, form:QueryFormResource) {- let payload = this.queryFormDm.buildQueryResource(form);-- this.restoreFilters(query, payload, form.schema);- this.restoreColumns(query, payload, form.schema);- this.restoreSortBy(query, payload, form.schema);- this.restoreGroupBy(query, payload, form.schema);- this.restoreOtherProperties(query, payload);+ this.restoreFilters(query, form.payload, form.schema);+ this.restoreColumns(query, form.payload, form.schema);+ this.restoreSortBy(query, form.payload, form.schema);+ this.restoreGroupBy(query, form.payload, form.schema);+ this.restoreOtherProperties(query, form.payload);}private restoreFilters(query:QueryResource, payload:QueryResource, querySchema:SchemaResource) {let filters = _.map((payload.filters), filter => {let filterInstanceSchema = _.find(querySchema.filtersSchemas.elements, (schema:QueryFilterInstanceSchemaResource) => {return (schema.filter.allowedValues as QueryFilterResource[])[0].$href === filter.filter.$href;- })+ });if (!filterInstanceSchema) {return null;@@ -73,7 +70,7 @@ export class WorkPackagesListInvalidQueryService {recreatedFilter.operator = operator;}- recreatedFilter.values.length = 0+ recreatedFilter.values.length = 0;_.each(filter.values, value => recreatedFilter.values.push(value));return recreatedFilter;diff --git a/frontend/src/app/components/wp-list/wp-list.service.ts b/frontend/src/app/components/wp-list/wp-list.service.tsindex 708b96dce3a..7ec27fe7def 100644--- a/frontend/src/app/components/wp-list/wp-list.service.ts+++ b/frontend/src/app/components/wp-list/wp-list.service.ts@@ -37,17 +37,21 @@ import {AuthorisationService} from 'core-app/modules/common/model-auth/model-autimport {StateService} from '@uirouter/core';import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";import {Injectable} from '@angular/core';-import {QueryFormDmService} from 'core-app/modules/hal/dm-services/query-form-dm.service';-import {PaginationObject, QueryDmService} from 'core-app/modules/hal/dm-services/query-dm.service';import {UrlParamsHelperService} from 'core-components/wp-query/url-params-helper';import {NotificationsService} from 'core-app/modules/common/notifications/notifications.service';import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {from, Observable, of} from 'rxjs';import {input} from "reactivestates";import {catchError, mergeMap, share, switchMap, take} from "rxjs/operators";-import {WorkPackageViewPaginationService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-pagination.service";+import {+ PaginationUpdateObject,+ WorkPackageViewPaginationService+} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-pagination.service";import {ConfigurationService} from "core-app/modules/common/config/configuration.service";import {PaginationService} from "core-components/table-pagination/pagination-service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {APIv3QueriesPaths} from "core-app/modules/apiv3/endpoints/queries/apiv3-queries-paths";+import {APIv3QueryPaths} from "core-app/modules/apiv3/endpoints/queries/apiv3-query-paths";export interface QueryDefinition {queryParams:{ query_id?:string, query_props?:string };@@ -90,8 +94,7 @@ export class WorkPackagesListService {protected UrlParamsHelper:UrlParamsHelperService,protected authorisationService:AuthorisationService,protected $state:StateService,- protected QueryDm:QueryDmService,- protected QueryFormDm:QueryFormDmService,+ protected apiV3Service:APIV3Service,protected states:States,protected querySpace:IsolatedQuerySpace,protected pagination:PaginationService,@@ -111,7 +114,10 @@ export class WorkPackagesListService {private streamQueryRequest(queryParams:{ query_id?:string, query_props?:string }, projectIdentifier ?:string):Observable<QueryResource> {const decodedProps = this.getCurrentQueryProps(queryParams);const queryData = this.UrlParamsHelper.buildV3GetQueryFromJsonParams(decodedProps);- const stream = this.QueryDm.stream(queryData, queryParams.query_id, projectIdentifier);+ const stream = this+ .apiV3Service+ .queries+ .find(queryData, queryParams.query_id, projectIdentifier);return stream.pipe(catchError((error) => {@@ -176,28 +182,25 @@ export class WorkPackagesListService {}/**- * Update the list from an existing query object.+ * Update the query from an existing (probably unsaved) query.+ *+ * Will choose the correct path:+ * - If the query is unsaved, use `/api/v3(/projects/:identifier)/queries/default`+ * - If the query is saved, use `/api/v3/queries/:id`+ **/- public loadResultsList(query:QueryResource, additionalParams:PaginationObject):Promise<WorkPackageCollectionResource> {- return this.QueryDm- .loadResults(query, additionalParams)- .then((loadedQuery) => {-- this.wpStatesInitialization.updateQuerySpace(loadedQuery, loadedQuery.results);- this.wpStatesInitialization.updateChecksum(loadedQuery, loadedQuery.results);- return query.results;- });- }+ public loadQueryFromExisting(query:QueryResource, additionalParams:Object, projectIdentifier?:string):Observable<QueryResource> {+ const params = this.UrlParamsHelper.buildV3GetQueryFromQueryResource(query, additionalParams);- /**- * Reload the list of work packages for the current query keeping the- * pagination options.- */- public reloadCurrentResultsList():Promise<WorkPackageCollectionResource> {- let pagination = this.getPaginationInfo();- let query = this.currentQuery;+ let path:APIv3QueriesPaths|APIv3QueryPaths;- return this.loadResultsList(query, pagination);+ if (query.id) {+ path = this.apiV3Service.queries.id(query.id);+ } else {+ path = this.apiV3Service.withOptionalProject(projectIdentifier).queries;+ }++ return path.parameterised(params);}/**@@ -210,11 +213,17 @@ export class WorkPackagesListService {}public loadForm(query:QueryResource):Promise<QueryFormResource> {- return this.QueryFormDm.load(query).then((form:QueryFormResource) => {- this.wpStatesInitialization.updateStatesFromForm(query, form);-- return form;- });+ return this+ .apiV3Service+ .queries+ .form+ .load(query)+ .toPromise()+ .then(([form, _]) => {+ this.wpStatesInitialization.updateStatesFromForm(query, form);++ return form;+ });}/**@@ -226,7 +235,11 @@ export class WorkPackagesListService {query.name = name;- let promise = this.QueryDm.create(query, form);+ let promise = this+ .apiV3Service+ .queries+ .post(query, form)+ .toPromise();promise.then(query => {@@ -249,7 +262,12 @@ export class WorkPackagesListService {public delete() {let query = this.currentQuery;- let promise = this.QueryDm.delete(query);+ let promise = this+ .apiV3Service+ .queries+ .id(query)+ .delete()+ .toPromise();promise.then(() => {@@ -274,7 +292,12 @@ export class WorkPackagesListService {let form = this.querySpace.queryForm.value!;- let promise = this.QueryDm.update(query, form).toPromise();+ let promise = this+ .apiV3Service+ .queries+ .id(query)+ .patch(query, form)+ .toPromise();promise.then(() => {@@ -291,7 +314,10 @@ export class WorkPackagesListService {}public toggleStarred(query:QueryResource):Promise<any> {- let promise = this.QueryDm.toggleStarred(query);+ let promise = this+ .apiV3Service+ .queries+ .toggleStarred(query);promise.then((query:QueryResource) => {this.querySpace.query.putValue(query);@@ -304,7 +330,7 @@ export class WorkPackagesListService {return promise;}- private getPaginationInfo() {+ public getPaginationInfo() {return this.wpTablePagination.paginationObject;}@@ -334,9 +360,18 @@ export class WorkPackagesListService {this.NotificationsService.addError(this.I18n.t('js.work_packages.faulty_query.description'), error.message);return new Promise((resolve, reject) => {- this.QueryFormDm.loadWithParams(queryProps, queryId, projectIdentifier)- .then(form => {- this.QueryDm.findDefault({ pageSize: 0 }, projectIdentifier)+ this+ .apiV3Service+ .queries+ .form+ .loadWithParams(queryProps, queryId, projectIdentifier)+ .toPromise()+ .then(([form, _]) => {+ this+ .apiV3Service+ .queries+ .find({ pageSize: 0}, undefined, projectIdentifier)+ .toPromise().then((query:QueryResource) => {this.wpListInvalidQueryService.restoreQuery(query, form);diff --git a/frontend/src/app/components/wp-list/wp-states-initialization.service.ts b/frontend/src/app/components/wp-list/wp-states-initialization.service.tsindex b72f4465d5a..e6421d9c82d 100644--- a/frontend/src/app/components/wp-list/wp-states-initialization.service.ts+++ b/frontend/src/app/components/wp-list/wp-states-initialization.service.ts@@ -3,7 +3,6 @@ import {QueryResource} from 'core-app/modules/hal/resources/query-resource';import {WorkPackageCollectionResource} from 'core-app/modules/hal/resources/wp-collection-resource';import {SchemaResource} from 'core-app/modules/hal/resources/schema-resource';import {QueryFormResource} from 'core-app/modules/hal/resources/query-form-resource';-import {WorkPackageCacheService} from '../work-packages/work-package-cache.service';import {WorkPackagesListChecksumService} from './wp-list-checksum.service';import {AuthorisationService} from 'core-app/modules/common/model-auth/model-auth.service';import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";@@ -23,6 +22,7 @@ import {WorkPackageViewTimelineService} from "core-app/modules/work_packages/rouimport {WorkPackageViewGroupByService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-group-by.service";import {WorkPackageViewFiltersService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service";import {WorkPackageViewRelationColumnsService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-relation-columns.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable()export class WorkPackageStatesInitializationService {@@ -40,7 +40,7 @@ export class WorkPackageStatesInitializationService {protected wpTablePagination:WorkPackageViewPaginationService,protected wpTableOrder:WorkPackageViewOrderService,protected wpTableAdditionalElements:WorkPackageViewAdditionalElementsService,- protected wpCacheService:WorkPackageCacheService,+ protected apiV3Service:APIV3Service,protected wpListChecksumService:WorkPackagesListChecksumService,protected authorisationService:AuthorisationService,protected wpDisplayRepresentation:WorkPackageViewDisplayRepresentationService) {@@ -104,7 +104,7 @@ export class WorkPackageStatesInitializationService {this.authorisationService.initModelAuth('work_packages', results.$links);- results.elements.forEach(wp => this.wpCacheService.updateWorkPackage(wp, true));+ results.elements.forEach(wp => this.apiV3Service.work_packages.cache.updateWorkPackage(wp, true));this.querySpace.results.putValue(results);diff --git a/frontend/src/app/components/wp-new/wp-create.component.ts b/frontend/src/app/components/wp-new/wp-create.component.tsindex 6755598aea3..3834d431a26 100644--- a/frontend/src/app/components/wp-new/wp-create.component.ts+++ b/frontend/src/app/components/wp-new/wp-create.component.ts@@ -32,10 +32,8 @@ import {PathHelperService} from 'core-app/modules/common/path-helper/path-helperimport {States} from '../states.service';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {RootResource} from 'core-app/modules/hal/resources/root-resource';-import {WorkPackageCacheService} from '../work-packages/work-package-cache.service';import {WorkPackageCreateService} from './wp-create.service';import {takeWhile} from 'rxjs/operators';-import {RootDmService} from 'core-app/modules/hal/dm-services/root-dm.service';import {OpTitleService} from 'core-components/html/op-title.service';import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {WorkPackageViewFiltersService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-filters.service";@@ -46,6 +44,7 @@ import {WorkPackageNotificationService} from "core-app/modules/work_packages/notimport * as URI from 'urijs';import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";import {splitViewRoute} from "core-app/modules/work_packages/routing/split-view-routes.helper";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Directive()export class WorkPackageCreateComponent extends UntilDestroyedMixin implements OnInit {@@ -78,10 +77,9 @@ export class WorkPackageCreateComponent extends UntilDestroyedMixin implements Oprotected readonly wpCreate:WorkPackageCreateService,protected readonly wpViewFocus:WorkPackageViewFocusService,protected readonly wpTableFilters:WorkPackageViewFiltersService,- protected readonly wpCacheService:WorkPackageCacheService,protected readonly pathHelper:PathHelperService,- protected readonly cdRef:ChangeDetectorRef,- protected readonly RootDm:RootDmService) {+ protected readonly apiV3Service:APIV3Service,+ protected readonly cdRef:ChangeDetectorRef) {super();}@@ -126,14 +124,17 @@ export class WorkPackageCreateComponent extends UntilDestroyedMixin implements Oif (this.stateParams['parent_id']) {changeset.setValue('parent',- { href: this.pathHelper.api.v3.work_packages.id(this.stateParams['parent_id']).path }+ { href: this.apiV3Service.work_packages.id(this.stateParams['parent_id']).path });}// Load the parent simply to display the type name :-/if (this.stateParams['parent_id']) {- this.wpCacheService.loadWorkPackage(this.stateParams['parent_id'])- .values$()+ this+ .apiV3Service+ .work_packages+ .id(this.stateParams['parent_id'])+ .get().pipe(this.untilDestroyed())@@ -145,7 +146,7 @@ export class WorkPackageCreateComponent extends UntilDestroyedMixin implements O}).catch((error:any) => {if (error.errorIdentifier === 'urn:openproject-org:api:v3:errors:MissingPermission') {- this.RootDm.load().then((root:RootResource) => {+ this.apiV3Service.root.get().subscribe((root:RootResource) => {if (!root.user) {// Not logged inlet url = URI(this.pathHelper.loginPath());diff --git a/frontend/src/app/components/wp-new/wp-create.service.ts b/frontend/src/app/components/wp-new/wp-create.service.tsindex 74a87508dc9..dfe45cb03f9 100644--- a/frontend/src/app/components/wp-new/wp-create.service.ts+++ b/frontend/src/app/components/wp-new/wp-create.service.ts@@ -27,7 +27,6 @@// ++import {Injectable, Injector} from '@angular/core';-import {WorkPackageCacheService} from '../work-packages/work-package-cache.service';import {Observable, Subject} from 'rxjs';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';@@ -41,12 +40,13 @@ import {import {WorkPackageChangeset} from "core-components/wp-edit/work-package-changeset";import {filter} from "rxjs/operators";import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";-import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";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";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {Form} from "@angular/forms";export const newWorkPackageHref = '/api/v3/work_packages/new';@@ -59,18 +59,17 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {constructor(protected injector:Injector,protected hooks:HookService,- protected wpCacheService:WorkPackageCacheService,+ protected apiV3Service:APIV3Service,protected halResourceService:HalResourceService,protected querySpace:IsolatedQuerySpace,protected authorisationService:AuthorisationService,protected halEditing:HalResourceEditingService,protected schemaCache:SchemaCacheService,- protected workPackageDmService:WorkPackageDmService,protected halEvents:HalEventsService) {super();this.halEditing- .comittedChanges+ .committedChanges.pipe(this.untilDestroyed(),filter(commit => commit.resource._type === 'WorkPackage' && commit.wasNew)@@ -99,14 +98,21 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {return this.newWorkPackageCreatedSubject.asObservable();}- public createNewWorkPackage(projectIdentifier:string|undefined|null) {+ public createNewWorkPackage(projectIdentifier:string|undefined|null):Promise<WorkPackageChangeset> {return this.getEmptyForm(projectIdentifier).then(form => {return this.fromCreateForm(form);});}- public createNewTypedWorkPackage(projectIdentifier:string|undefined|null, type:number) {- return this.workPackageDmService.typedCreateForm(type, projectIdentifier).then(form => {+ public createNewTypedWorkPackage(projectIdentifier:string|undefined|null, type:number):Promise<WorkPackageChangeset> {+ return this+ .apiV3Service+ .withOptionalProject(projectIdentifier)+ .work_packages+ .form+ .forType(type)+ .toPromise()+ .then((form:FormResource) => {return this.fromCreateForm(form);});}@@ -128,7 +134,13 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {// Ideally we would make an empty request before to get the create schema (cannot use the update schema of the source changeset)// to get all the writable attributes and only send those.// But as this would require an additional request, we don't.- return this.workPackageDmService.emptyCreateForm(request).then(form => {+ return this+ .apiV3Service+ .work_packages+ .form+ .post(request)+ .toPromise()+ .then((form:FormResource) => {let changeset = this.fromCreateForm(form);return changeset;@@ -148,10 +160,16 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {public getEmptyForm(projectIdentifier:string|null|undefined):Promise<FormResource> {if (!this.form) {- this.form = this.workPackageDmService.emptyCreateForm({}, projectIdentifier);+ this.form = this+ .apiV3Service+ .withOptionalProject(projectIdentifier)+ .work_packages+ .form+ .post({})+ .toPromise();}- return this.form;+ return this.form as Promise<FormResource>;}public cancelCreation() {@@ -176,14 +194,22 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {return changePromise.then((change:WorkPackageChangeset) => {this.authorisationService.initModelAuth('work_package', change.pristineResource);this.halEditing.updateValue(newWorkPackageHref, change);- this.wpCacheService.updateWorkPackage(change.pristineResource);+ this+ .apiV3Service+ .work_packages+ .cache+ .updateWorkPackage(change.pristineResource, true);return change;});}protected reset() {- this.wpCacheService.clearSome('new');+ this+ .apiV3Service+ .work_packages+ .cache+ .clearSome('new');this.form = undefined;}@@ -273,7 +299,7 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {wp['update'] = wp.$links.update = form.$links.self;// Use POST /work_packages for saving linkwp['updateImmediately'] = wp.$links.updateImmediately = (payload) => {- return this.workPackageDmService.createWorkPackage(payload);+ return this.apiV3Service.work_packages.post(payload).toPromise();};// We need to provide the schema to the cache so that it is available in the html form to e.g. determinediff --git a/frontend/src/app/components/wp-query-select/wp-query-select-dropdown.component.ts b/frontend/src/app/components/wp-query-select/wp-query-select-dropdown.component.tsindex 5d0b59bb9f5..e93a1524f89 100644--- a/frontend/src/app/components/wp-query-select/wp-query-select-dropdown.component.ts+++ b/frontend/src/app/components/wp-query-select/wp-query-select-dropdown.component.ts@@ -30,7 +30,6 @@ import {CollectionResource} from 'core-app/modules/hal/resources/collection-resoimport {States} from '../states.service';import {StateService, TransitionService} from '@uirouter/core';import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, OnInit, ViewChild} from "@angular/core";-import {QueryDmService} from 'core-app/modules/hal/dm-services/query-dm.service';import {LoadingIndicatorService} from "core-app/modules/common/loading-indicator/loading-indicator.service";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';@@ -42,6 +41,7 @@ import {keyCodes} from 'core-app/modules/common/keyCodes.enum';import {MainMenuToggleService} from "core-components/main-menu/main-menu-toggle.service";import {MainMenuNavigationService} from "core-components/main-menu/main-menu-navigation.service";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export type QueryCategory = 'starred'|'public'|'private'|'default';@@ -107,7 +107,7 @@ export class WorkPackageQuerySelectDropdownComponent extends UntilDestroyedMixinconstructor(readonly ref:ChangeDetectorRef,readonly element:ElementRef,- readonly QueryDm:QueryDmService,+ readonly apiV3Service:APIV3Service,readonly $state:StateService,readonly $transitions:TransitionService,readonly I18n:I18nService,@@ -219,8 +219,11 @@ export class WorkPackageQuerySelectDropdownComponent extends UntilDestroyedMixin}private loadQueries() {- return this.loadingPromise = this.QueryDm- .listNonHidden(this.CurrentProject.identifier)+ return this.loadingPromise = this+ .apiV3Service+ .queries+ .filterNonHidden(this.CurrentProject.identifier)+ .toPromise().then(collection => {// Update the complete collectiondiff --git a/frontend/src/app/components/wp-relations/embedded/children/wp-children-query.component.ts b/frontend/src/app/components/wp-relations/embedded/children/wp-children-query.component.tsindex fda212f1af1..6ee5f70b58d 100644--- a/frontend/src/app/components/wp-relations/embedded/children/wp-children-query.component.ts+++ b/frontend/src/app/components/wp-relations/embedded/children/wp-children-query.component.ts@@ -37,17 +37,17 @@ import {OpTableActionFactory} from 'core-components/wp-table/table-actions/tableimport {WorkPackageInlineCreateService} from "core-components/wp-inline-create/wp-inline-create.service";import {WorkPackageRelationQueryBase} from "core-components/wp-relations/embedded/wp-relation-query.base";import {WpChildrenInlineCreateService} from "core-components/wp-relations/embedded/children/wp-children-inline-create.service";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {filter} from "rxjs/operators";import {QueryResource} from "core-app/modules/hal/resources/query-resource";import {GroupDescriptor} from "core-components/work-packages/wp-single-view/wp-single-view.component";import {HalEventsService} from "core-app/modules/hal/services/hal-events.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'wp-children-query',templateUrl: '../wp-relation-query.html',providers: [- { provide: WorkPackageInlineCreateService, useClass: WpChildrenInlineCreateService }+ { provide: WorkPackageInlineCreateService, useClass: WpChildrenInlineCreateService },]})export class WorkPackageChildrenQueryComponent extends WorkPackageRelationQueryBase implements OnInit {@@ -73,7 +73,7 @@ export class WorkPackageChildrenQueryComponent extends WorkPackageRelationQueryBprotected PathHelper:PathHelperService,protected wpInlineCreate:WorkPackageInlineCreateService,protected halEvents:HalEventsService,- protected wpCacheService:WorkPackageCacheService,+ protected apiV3Service:APIV3Service,protected queryUrlParamsHelper:UrlParamsHelperService,readonly I18n:I18nService) {super(queryUrlParamsHelper);@@ -100,8 +100,11 @@ export class WorkPackageChildrenQueryComponent extends WorkPackageRelationQueryB});// Refresh table when work package is refreshed- this.wpCacheService- .observe(this.workPackage.id!)+ this+ .apiV3Service+ .work_packages+ .id(this.workPackage)+ .observe().pipe(filter(() => this.embeddedTable && this.embeddedTable.isInitialized),this.untilDestroyed()diff --git a/frontend/src/app/components/wp-relations/embedded/inline/add-existing/wp-relation-inline-add-existing.component.ts b/frontend/src/app/components/wp-relations/embedded/inline/add-existing/wp-relation-inline-add-existing.component.tsindex 0648c3b2680..6969d633b5b 100644--- a/frontend/src/app/components/wp-relations/embedded/inline/add-existing/wp-relation-inline-add-existing.component.ts+++ b/frontend/src/app/components/wp-relations/embedded/inline/add-existing/wp-relation-inline-add-existing.component.ts@@ -31,7 +31,6 @@ import {I18nService} from 'core-app/modules/common/i18n/i18n.service';import {WorkPackageInlineCreateService} from "core-components/wp-inline-create/wp-inline-create.service";import {WorkPackageInlineCreateComponent} from "core-components/wp-inline-create/wp-inline-create.component";import {WorkPackageRelationsService} from "core-components/wp-relations/wp-relations.service";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {WpRelationInlineCreateServiceInterface} from "core-components/wp-relations/embedded/wp-relation-inline-create.service.interface";import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";@@ -40,6 +39,7 @@ import {UrlParamsHelperService} from "core-components/wp-query/url-params-helperimport {RelationResource} from "core-app/modules/hal/resources/relation-resource";import {HalEventsService} from "core-app/modules/hal/services/hal-events.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './wp-relation-inline-add-existing.component.html'@@ -56,7 +56,7 @@ export class WpRelationInlineAddExistingComponent {constructor(protected readonly parent:WorkPackageInlineCreateComponent,@Inject(WorkPackageInlineCreateService) protected readonly wpInlineCreate:WpRelationInlineCreateServiceInterface,- protected wpCacheService:WorkPackageCacheService,+ protected apiV3Service:APIV3Service,protected wpRelations:WorkPackageRelationsService,protected notificationService:WorkPackageNotificationService,protected halEvents:HalEventsService,@@ -75,7 +75,11 @@ export class WpRelationInlineAddExistingComponent {this.wpInlineCreate.add(this.workPackage, newRelationId).then(() => {- this.wpCacheService.loadWorkPackage(this.workPackage.id!, true);+ this+ .apiV3Service+ .work_packages+ .id(this.workPackage)+ .refresh();this.halEvents.push(this.workPackage, {eventType: 'association',diff --git a/frontend/src/app/components/wp-relations/wp-relation-row/wp-relation-row.component.ts b/frontend/src/app/components/wp-relations/wp-relation-row/wp-relation-row.component.tsindex 6facdcd4641..07b20c759c5 100644--- a/frontend/src/app/components/wp-relations/wp-relation-row/wp-relation-row.component.ts+++ b/frontend/src/app/components/wp-relations/wp-relation-row/wp-relation-row.component.ts@@ -1,4 +1,3 @@-import {WorkPackageCacheService} from '../../work-packages/work-package-cache.service';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {WorkPackageRelationsService} from '../wp-relations.service';import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';@@ -8,6 +7,7 @@ import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {HalEventsService} from "core-app/modules/hal/services/hal-events.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({@@ -55,7 +55,7 @@ export class WorkPackageRelationRowComponent extends UntilDestroyedMixin impleme}};- constructor(protected wpCacheService:WorkPackageCacheService,+ constructor(protected apiV3Service:APIV3Service,protected notificationService:WorkPackageNotificationService,protected wpRelations:WorkPackageRelationsService,protected halEvents:HalEventsService,@@ -73,8 +73,11 @@ export class WorkPackageRelationRowComponent extends UntilDestroyedMixin implemethis.selectedRelationType = _.find(this.availableRelationTypes,{ 'name': this.relation.normalizedType(this.workPackage) })!;- this.wpCacheService- .observe(this.relatedWorkPackage.id!)+ this+ .apiV3Service+ .work_packages+ .id(this.relatedWorkPackage)+ .requireAndStream().pipe(this.untilDestroyed()).subscribe((wp) => {@@ -176,7 +179,12 @@ export class WorkPackageRelationRowComponent extends UntilDestroyedMixin implemerelationType: this.relation.normalizedType(this.workPackage)});- this.wpCacheService.updateWorkPackage(this.relatedWorkPackage);+ this+ .apiV3Service+ .work_packages+ .cache+ .updateWorkPackage(this.relatedWorkPackage);+this.notificationService.showSave(this.relatedWorkPackage);}).catch((err:any) => this.notificationService.handleRawError(err,diff --git a/frontend/src/app/components/wp-relations/wp-relations-create/wp-relations-create.component.ts b/frontend/src/app/components/wp-relations/wp-relations-create/wp-relations-create.component.tsindex 1f1dd931ec0..331d228de73 100644--- a/frontend/src/app/components/wp-relations/wp-relations-create/wp-relations-create.component.ts+++ b/frontend/src/app/components/wp-relations/wp-relations-create/wp-relations-create.component.ts@@ -1,6 +1,5 @@import {RelationResource} from 'core-app/modules/hal/resources/relation-resource';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';-import {WorkPackageCacheService} from '../../work-packages/work-package-cache.service';import {WorkPackageRelationsService} from '../wp-relations.service';import {Component, Input} from "@angular/core";import {I18nService} from "core-app/modules/common/i18n/i18n.service";@@ -30,8 +29,7 @@ export class WorkPackageRelationsCreateComponent {constructor(readonly I18n:I18nService,protected wpRelations:WorkPackageRelationsService,protected notificationService:WorkPackageNotificationService,- protected halEvents:HalEventsService,- protected wpCacheService:WorkPackageCacheService) {+ protected halEvents:HalEventsService) {}diff --git a/frontend/src/app/components/wp-relations/wp-relations-hierarchy/wp-relations-hierarchy.directive.ts b/frontend/src/app/components/wp-relations/wp-relations-hierarchy/wp-relations-hierarchy.directive.tsindex 14dd0f09487..e5b915c89b4 100644--- a/frontend/src/app/components/wp-relations/wp-relations-hierarchy/wp-relations-hierarchy.directive.ts+++ b/frontend/src/app/components/wp-relations/wp-relations-hierarchy/wp-relations-hierarchy.directive.ts@@ -32,8 +32,8 @@ import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-rimport {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';import {WorkPackageRelationsHierarchyService} from 'core-components/wp-relations/wp-relations-hierarchy/wp-relations-hierarchy.service';import {take} from 'rxjs/operators';-import {WorkPackageCacheService} from '../../work-packages/work-package-cache.service';import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'wp-relations-hierarchy',@@ -52,7 +52,7 @@ export class WorkPackageRelationsHierarchyComponent extends UntilDestroyedMixinpublic childrenQueryProps:any;constructor(protected wpRelationsHierarchyService:WorkPackageRelationsHierarchyService,- protected wpCacheService:WorkPackageCacheService,+ protected apiV3Service:APIV3Service,protected PathHelper:PathHelperService,readonly I18n:I18nService) {super();@@ -74,27 +74,32 @@ export class WorkPackageRelationsHierarchyComponent extends UntilDestroyedMixinshowHierarchies: false};- this.wpCacheService.loadWorkPackage(this.workPackage.id!).values$()+ this+ .apiV3Service+ .work_packages+ .id(this.workPackage)+ .requireAndStream().pipe(this.untilDestroyed()).subscribe((wp:WorkPackageResource) => {this.workPackage = wp;- let toLoad:string[] = [];let parentId = this.workPackage.parent?.id?.toString();if (parentId) {- toLoad.push(parentId.toString());-- this.wpCacheService- .require(parentId)- .then((parent:WorkPackageResource) => {+ this+ .apiV3Service+ .work_packages+ .id(parentId)+ .get()+ .pipe(+ take(1)+ )+ .subscribe((parent:WorkPackageResource) => {this.workPackage.parent = parent;});}-- this.wpCacheService.requireAll(toLoad);});}}diff --git a/frontend/src/app/components/wp-relations/wp-relations-hierarchy/wp-relations-hierarchy.service.ts b/frontend/src/app/components/wp-relations/wp-relations-hierarchy/wp-relations-hierarchy.service.tsindex d70c54a81ee..d540d6dab7d 100644--- a/frontend/src/app/components/wp-relations/wp-relations-hierarchy/wp-relations-hierarchy.service.ts+++ b/frontend/src/app/components/wp-relations/wp-relations-hierarchy/wp-relations-hierarchy.service.ts@@ -26,7 +26,6 @@// See docs/COPYRIGHT.rdoc for more details.//++-import {WorkPackageCacheService} from '../../work-packages/work-package-cache.service';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {States} from '../../states.service';import {StateService} from '@uirouter/core';@@ -34,6 +33,7 @@ import {Injectable} from '@angular/core';import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';import {HalEventsService} from "core-app/modules/hal/services/hal-events.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable()export class WorkPackageRelationsHierarchyService {@@ -42,7 +42,7 @@ export class WorkPackageRelationsHierarchyService {protected halEvents:HalEventsService,protected notificationService:WorkPackageNotificationService,protected pathHelper:PathHelperService,- protected wpCacheService:WorkPackageCacheService) {+ protected apiV3Service:APIV3Service) {}@@ -54,7 +54,7 @@ export class WorkPackageRelationsHierarchyService {if (parentId) {payload['_links'] = {parent: {- href: this.pathHelper.api.v3.work_packages.id(parentId).toString()+ href: this.apiV3Service.work_packages.id(parentId).path}};} else {@@ -68,7 +68,11 @@ export class WorkPackageRelationsHierarchyService {return workPackage.changeParent(payload).then((wp:WorkPackageResource) => {- this.wpCacheService.updateWorkPackage(wp);+ this+ .apiV3Service+ .work_packages+ .cache+ .updateWorkPackage(wp);this.notificationService.showSave(wp);this.halEvents.push(workPackage, {eventType: 'association',@@ -89,12 +93,22 @@ export class WorkPackageRelationsHierarchyService {}public addExistingChildWp(workPackage:WorkPackageResource, childWpId:string):Promise<WorkPackageResource> {- return this.wpCacheService- .require(childWpId)+ return this+ .apiV3Service+ .work_packages+ .id(childWpId)+ .get()+ .toPromise().then((wpToBecomeChild:WorkPackageResource|undefined) => {return this.changeParent(wpToBecomeChild!, workPackage.id!).then(wp => {- this.wpCacheService.loadWorkPackage(workPackage.id!, true);+ // Reload work package+ this+ .apiV3Service+ .work_packages+ .id(workPackage)+ .refresh();+this.halEvents.push(workPackage, {eventType: 'association',relatedWorkPackage: wpToBecomeChild!.id!,@@ -136,15 +150,25 @@ export class WorkPackageRelationsHierarchyService {lockVersion: childWorkPackage.lockVersion}).then(wp => {if (parentWorkPackage) {- this.wpCacheService.require(parentWorkPackage.id!, true).then((wp) => {- this.halEvents.push(wp, {- eventType: 'association',- relatedWorkPackage: null,- relationType: 'child'+ this+ .apiV3Service+ .work_packages+ .id(parentWorkPackage)+ .refresh()+ .then((wp) => {+ this.halEvents.push(wp, {+ eventType: 'association',+ relatedWorkPackage: null,+ relationType: 'child'});});}- this.wpCacheService.updateWorkPackage(wp);++ this+ .apiV3Service+ .work_packages+ .cache+ .updateWorkPackage(wp);}).catch((error) => {this.notificationService.handleRawError(error, childWorkPackage);diff --git a/frontend/src/app/components/wp-relations/wp-relations.component.ts b/frontend/src/app/components/wp-relations/wp-relations.component.tsindex 5d9c3eaa7f2..10fa5483678 100644--- a/frontend/src/app/components/wp-relations/wp-relations.component.ts+++ b/frontend/src/app/components/wp-relations/wp-relations.component.ts@@ -33,11 +33,11 @@ import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-rimport {Observable, zip} from 'rxjs';import {take, takeUntil} from 'rxjs/operators';-import {WorkPackageCacheService} from '../work-packages/work-package-cache.service';import {RelatedWorkPackagesGroup} from './wp-relations.interfaces';import {RelationsStateValue, WorkPackageRelationsService} from './wp-relations.service';import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";import {componentDestroyed} from "@w11k/ngx-componentdestroyed";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({@@ -63,14 +63,16 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implementconstructor(private I18n:I18nService,private wpRelations:WorkPackageRelationsService,private cdRef:ChangeDetectorRef,- private wpCacheService:WorkPackageCacheService) {+ private apiV3Service:APIV3Service) {super();}ngOnInit() {this.canAddRelation = !!this.workPackage.addRelation;- this.wpRelations.state(this.workPackage.id!).values$()+ this.wpRelations+ .state(this.workPackage.id!)+ .values$().pipe(takeUntil(componentDestroyed(this)))@@ -81,7 +83,11 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implementthis.wpRelations.require(this.workPackage.id!);// Listen for changes to this WP.- this.wpCacheService.loadWorkPackage(this.workPackage.id!).values$()+ this+ .apiV3Service+ .work_packages+ .id(this.workPackage)+ .requireAndStream().pipe(takeUntil(componentDestroyed(this)))@@ -91,9 +97,13 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implement}private getRelatedWorkPackages(workPackageIds:string[]):Observable<WorkPackageResource[]> {- let observablesToGetZipped:Observable<WorkPackageResource>[] = workPackageIds.map(wpId => {- return this.wpCacheService.loadWorkPackage(wpId).values$();- });+ let observablesToGetZipped:Observable<WorkPackageResource>[] = workPackageIds.map(wpId =>+ this+ .apiV3Service+ .work_packages+ .id(wpId)+ .get()+ );return zip(...observablesToGetZipped);}diff --git a/frontend/src/app/components/wp-relations/wp-relations.service.ts b/frontend/src/app/components/wp-relations/wp-relations.service.tsindex a23f0e4736e..9786618c86a 100644--- a/frontend/src/app/components/wp-relations/wp-relations.service.ts+++ b/frontend/src/app/components/wp-relations/wp-relations.service.ts@@ -1,11 +1,14 @@-import {RelationsDmService} from 'core-app/modules/hal/dm-services/relations-dm.service';import {RelationResource} from 'core-app/modules/hal/resources/relation-resource';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';import {multiInput, MultiInputState, StatesGroup} from 'reactivestates';-import {StateCacheService} from '../states/state-cache.service';import {Injectable} from "@angular/core";import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {Observable} from "rxjs";+import {map, take, tap} from "rxjs/operators";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";export type RelationsStateValue = { [relationId:string]:RelationResource };@@ -23,40 +26,74 @@ export class RelationStateGroup extends StatesGroup {@Injectable()export class WorkPackageRelationsService extends StateCacheService<RelationsStateValue> {- private relationStates:RelationStateGroup;-- /*@ngInject*/- constructor(private relationsDm:RelationsDmService,- private PathHelper:PathHelperService,+ constructor(private PathHelper:PathHelperService,+ private apiV3Service:APIV3Service,private halResource:HalResourceService) {- super();- this.relationStates = new RelationStateGroup();+ super(new RelationStateGroup().relations);}- protected get multiState() {- return this.relationStates.relations;+ /**+ * Require the value to be loaded either when forced or the value is stale+ * according to the cache interval specified for this service.+ *+ * Returns a single promise to one loaded value+ *+ * @param id The state to require+ * @param force Load the value anyway.+ */+ public require(id:string, force:boolean = false):Promise<RelationsStateValue> {+ return this+ .requireAndStream(id, force)+ .pipe(+ take(1)+ )+ .toPromise();+ }++ /**+ * Require the value to be loaded either when forced or the value is stale+ * according to the cache interval specified for this service.+ *+ * Returns an observable to the values stream of the state.+ *+ * @param id The state to require+ * @param force Load the value anyway.+ */+ public requireAndStream(id:string, force:boolean = false):Observable<RelationsStateValue> {+ // Refresh when stale or being forced+ if (this.stale(id) || force) {+ this.clearAndLoad(+ id,+ this.load(id)+ );+ }++ return this.state(id).values$();}/*** Load a set of work package ids into the states, regardless of them being loaded* @param workPackageIds*/- protected load(id:string):Promise<RelationsStateValue> {- return new Promise<RelationsStateValue>((resolve, reject) => {- this.relationsDm- .load(id)- .then(elements => {- this.updateRelationsStateTo(id, elements);- resolve(this.state(id).value!);- })- .catch(reject);- });+ protected load(id:string):Observable<RelationsStateValue> {+ return this+ .apiV3Service+ .work_packages+ .id(id)+ .relations+ .get()+ .pipe(+ map(collection => this.relationsStateValue(id, collection.elements))+ );}- protected loadAll(ids:string[]) {+ public requireAll(ids:string[]):Promise<void> {return new Promise<undefined>((resolve, reject) => {- this.relationsDm+ this+ .apiV3Service+ .relations.loadInvolved(ids)+ .toPromise().then((elements:RelationResource[]) => {this.clearSome(...ids);this.accumulateRelationsFromInvolved(ids, elements);@@ -101,8 +138,8 @@ export class WorkPackageRelationsService extends StateCacheService<RelationsStatpublic updateRelationType(from:WorkPackageResource, to:WorkPackageResource, relation:RelationResource, type:string) {const params = {_links: {- from: {href: from.href},- to: {href: to.href}+ from: { href: from.href },+ to: { href: to.href }},type: type};@@ -110,7 +147,7 @@ export class WorkPackageRelationsService extends StateCacheService<RelationsStatreturn this.updateRelation(relation, params);}- public updateRelation(relation:RelationResource, params:{[key:string]:any}) {+ public updateRelation(relation:RelationResource, params:{ [key:string]:any }) {return relation.updateImmediately(params).then((savedRelation:RelationResource) => {this.insertIntoStates(savedRelation);@@ -123,20 +160,20 @@ export class WorkPackageRelationsService extends StateCacheService<RelationsStatrelatedWpId:string) {const params = {_links: {- from: {href: this.PathHelper.api.v3.work_packages.id(fromId).toString() },- to: {href: this.PathHelper.api.v3.work_packages.id(relatedWpId).toString() }+ from: { href: this.apiV3Service.work_packages.id(fromId).toString() },+ to: { href: this.apiV3Service.work_packages.id(relatedWpId).toString() }},type: relationType};- const path = this.PathHelper.api.v3.work_packages.id(fromId).relations.toString();+ const path = this.apiV3Service.work_packages.id(fromId).relations.toString();return this.halResource.post<RelationResource>(path, params).toPromise().then((relation:RelationResource) => {- this.insertIntoStates(relation);- return relation;- });+ this.insertIntoStates(relation);+ return relation;+ });}/**@@ -172,17 +209,14 @@ export class WorkPackageRelationsService extends StateCacheService<RelationsStat}/**- * Given a set of complete relations for this work packge, fill- * the associated relations state+ * Given a set of complete relations for this work packge,+ * returns the RelationsStateValue** @param wpId The wpId the relations belong to* @param relations The relation resource array.*/- private updateRelationsStateTo(wpId:string, relations:RelationResource[]) {- const state = this.multiState.get(wpId);- const relationsToInsert = _.keyBy(relations, r => r.id!);-- state.putValue(relationsToInsert, 'Overriding relations state.');+ private relationsStateValue(wpId:string, relations:RelationResource[]):RelationsStateValue {+ return _.keyBy(relations, r => r.id!);}/**@@ -193,9 +227,11 @@ export class WorkPackageRelationsService extends StateCacheService<RelationsStat* We need to group relevant relations for work packages based on their to/from filter.*/private accumulateRelationsFromInvolved(involved:string[], relations:RelationResource[]) {- involved.forEach(id => {- const relevant = relations.filter(r => r.isInvolved(id));- this.updateRelationsStateTo(id, relevant);+ involved.forEach(wpId => {+ const relevant = relations.filter(r => r.isInvolved(wpId));+ const value = this.relationsStateValue(wpId, relevant);++ this.updateValue(wpId, value);});}diff --git a/frontend/src/app/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts b/frontend/src/app/components/wp-single-view-tabs/activity-panel/activity-base.controller.tsindex 578a142f0a7..767623ee742 100644--- a/frontend/src/app/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts+++ b/frontend/src/app/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts@@ -31,10 +31,10 @@ import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-rimport {HalResource} from 'core-app/modules/hal/resources/hal-resource';import {ActivityEntryInfo} from 'core-components/wp-single-view-tabs/activity-panel/activity-entry-info';import {WorkPackagesActivityService} from 'core-components/wp-single-view-tabs/activity-panel/wp-activity.service';-import {WorkPackageCacheService} from '../../work-packages/work-package-cache.service';import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {Transition} from "@uirouter/core";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Directive()export class ActivityPanelBaseController extends UntilDestroyedMixin implements OnInit {@@ -57,7 +57,7 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implementsshowAll: this.I18n.t('js.label_activity_show_all')};- constructor(readonly wpCacheService:WorkPackageCacheService,+ constructor(readonly apiV3Service:APIV3Service,readonly I18n:I18nService,readonly cdRef:ChangeDetectorRef,readonly $transition:Transition,@@ -69,8 +69,11 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implements}ngOnInit() {- this.wpCacheService- .observe(this.workPackageId)+ this+ .apiV3Service+ .work_packages+ .id(this.workPackageId)+ .requireAndStream().pipe(this.untilDestroyed())diff --git a/frontend/src/app/components/wp-single-view-tabs/activity-panel/activity-tab.html b/frontend/src/app/components/wp-single-view-tabs/activity-panel/activity-tab.htmlindex 5fd563818c1..40f079a838d 100644--- a/frontend/src/app/components/wp-single-view-tabs/activity-panel/activity-tab.html+++ b/frontend/src/app/components/wp-single-view-tabs/activity-panel/activity-tab.html@@ -1,4 +1,4 @@-<work-package-comment [workPackage]="workPackage">+<work-package-comment *ngIf="workPackage" [workPackage]="workPackage"><ng-template><div class="detail-activity"><div class="work-package-details-activities-list">diff --git a/frontend/src/app/components/wp-single-view-tabs/overview-tab/overview-tab.component.ts b/frontend/src/app/components/wp-single-view-tabs/overview-tab/overview-tab.component.tsindex cb112910cf0..2960ffb9e93 100644--- a/frontend/src/app/components/wp-single-view-tabs/overview-tab/overview-tab.component.ts+++ b/frontend/src/app/components/wp-single-view-tabs/overview-tab/overview-tab.component.ts@@ -28,10 +28,10 @@import {Component} from '@angular/core';import {StateService} from '@uirouter/core';-import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {I18nService} from 'core-app/modules/common/i18n/i18n.service';import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './overview-tab.html',@@ -44,12 +44,16 @@ export class WorkPackageOverviewTabComponent extends UntilDestroyedMixin {public constructor(readonly I18n:I18nService,readonly $state:StateService,- readonly wpCacheService:WorkPackageCacheService) {+ readonly apiV3Service:APIV3Service) {super();this.workPackageId = this.$state.params.workPackageId;- wpCacheService.loadWorkPackage(this.workPackageId)- .values$()++ this+ .apiV3Service+ .work_packages+ .id(this.workPackageId)+ .requireAndStream().pipe(this.untilDestroyed())diff --git a/frontend/src/app/components/wp-single-view-tabs/relations-tab/relations-tab.component.ts b/frontend/src/app/components/wp-single-view-tabs/relations-tab/relations-tab.component.tsindex a49b34c5518..9d18323027b 100644--- a/frontend/src/app/components/wp-single-view-tabs/relations-tab/relations-tab.component.ts+++ b/frontend/src/app/components/wp-single-view-tabs/relations-tab/relations-tab.component.ts@@ -27,11 +27,11 @@// ++import {Transition} from '@uirouter/core';-import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';import {Component, Input, OnInit} from '@angular/core';import {I18nService} from 'core-app/modules/common/i18n/i18n.service';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './relations-tab.html',@@ -43,14 +43,17 @@ export class WorkPackageRelationsTabComponent extends UntilDestroyedMixin implempublic constructor(readonly I18n:I18nService,readonly $transition:Transition,- readonly wpCacheService:WorkPackageCacheService) {+ readonly apiV3Service:APIV3Service) {super();}ngOnInit() {const wpId = this.workPackageId || this.$transition.params('to').workPackageId;- this.wpCacheService.loadWorkPackage(wpId)- .values$()+ this+ .apiV3Service+ .work_packages+ .id(wpId)+ .requireAndStream().pipe(this.untilDestroyed())diff --git a/frontend/src/app/components/wp-single-view-tabs/watchers-tab/watchers-tab.component.ts b/frontend/src/app/components/wp-single-view-tabs/watchers-tab/watchers-tab.component.tsindex 43c7f7f9a28..3f54c758215 100644--- a/frontend/src/app/components/wp-single-view-tabs/watchers-tab/watchers-tab.component.ts+++ b/frontend/src/app/components/wp-single-view-tabs/watchers-tab/watchers-tab.component.ts@@ -31,13 +31,13 @@ import {Transition} from '@uirouter/core';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {HalResource} from 'core-app/modules/hal/resources/hal-resource';import {LoadingIndicatorService} from 'core-app/modules/common/loading-indicator/loading-indicator.service';-import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';import {I18nService} from 'core-app/modules/common/i18n/i18n.service';import {WorkPackageWatchersService} from 'core-components/wp-single-view-tabs/watchers-tab/wp-watchers.service';import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {AngularTrackingHelpers} from "core-components/angular/tracking-functions";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './watchers-tab.html',@@ -72,9 +72,9 @@ export class WorkPackageWatchersTabComponent extends UntilDestroyedMixin implemereadonly $transition:Transition,readonly notificationService:WorkPackageNotificationService,readonly loadingIndicator:LoadingIndicatorService,- readonly wpCacheService:WorkPackageCacheService,readonly cdRef:ChangeDetectorRef,- readonly pathHelper:PathHelperService) {+ readonly pathHelper:PathHelperService,+ readonly apiV3Service:APIV3Service) {super();}@@ -82,8 +82,11 @@ export class WorkPackageWatchersTabComponent extends UntilDestroyedMixin implemethis.$element = jQuery(this.elementRef.nativeElement);this.workPackageId = this.$transition.params('to').workPackageId;- this.wpCacheService.loadWorkPackage(this.workPackageId)- .values$()+ this+ .apiV3Service+ .work_packages+ .id(this.workPackageId)+ .requireAndStream().pipe(this.untilDestroyed())@@ -92,7 +95,7 @@ export class WorkPackageWatchersTabComponent extends UntilDestroyedMixin implemethis.loadCurrentWatchers();});- this.availableWatchersPath = this.pathHelper.api.v3.work_packages.id(this.workPackageId).available_watchers;+ this.availableWatchersPath = this.apiV3Service.work_packages.id(this.workPackageId).available_watchers.path;}public loadCurrentWatchers() {@@ -127,7 +130,12 @@ export class WorkPackageWatchersTabComponent extends UntilDestroyedMixin impleme// Forcefully reload the resource to update the watch/unwatch links// should the current user have been addedthis.wpWatchersService.require(this.workPackage, true);- this.wpCacheService.loadWorkPackage(this.workPackage.id!, true);+ this+ .apiV3Service+ .work_packages+ .id(this.workPackage)+ .refresh();+this.cdRef.detectChanges();}).catch((error:any) => this.notificationService.showError(error, this.workPackage));@@ -143,7 +151,11 @@ export class WorkPackageWatchersTabComponent extends UntilDestroyedMixin impleme// Forcefully reload the resource to update the watch/unwatch links// should the current user have been removedthis.wpWatchersService.require(this.workPackage, true);- this.wpCacheService.loadWorkPackage(this.workPackage.id!, true);+ this+ .apiV3Service+ .work_packages+ .id(this.workPackage)+ .refresh();this.cdRef.detectChanges();}).catch((error:any) => this.notificationService.showError(error, this.workPackage));diff --git a/frontend/src/app/components/wp-table/configuration-modal/wp-table-configuration.modal.ts b/frontend/src/app/components/wp-table/configuration-modal/wp-table-configuration.modal.tsindex d11f862e4a6..ff6907f9fa4 100644--- a/frontend/src/app/components/wp-table/configuration-modal/wp-table-configuration.modal.ts+++ b/frontend/src/app/components/wp-table/configuration-modal/wp-table-configuration.modal.ts@@ -24,7 +24,6 @@ import {TabInterface,TabPortalOutlet} from 'core-components/wp-table/configuration-modal/tab-portal-outlet';-import {QueryFormDmService} from 'core-app/modules/hal/dm-services/query-form-dm.service';import {WorkPackageStatesInitializationService} from 'core-components/wp-list/wp-states-initialization.service';import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";import {QueryFormResource} from 'core-app/modules/hal/resources/query-form-resource';@@ -33,6 +32,7 @@ import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {OpModalLocalsToken} from "core-components/op-modals/op-modal.service";import {ComponentType} from "@angular/cdk/portal";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export const WpTableConfigurationModalPrependToken = new InjectionToken<ComponentType<any>>('WpTableConfigurationModalPrependComponent');@@ -83,8 +83,8 @@ export class WpTableConfigurationModalComponent extends OpModalComponent implemereadonly componentFactoryResolver:ComponentFactoryResolver,readonly loadingIndicator:LoadingIndicatorService,readonly querySpace:IsolatedQuerySpace,- readonly queryFormDm:QueryFormDmService,readonly wpStatesInitialization:WorkPackageStatesInitializationService,+ readonly apiV3Service:APIV3Service,readonly notificationService:WorkPackageNotificationService,readonly wpTableColumns:WorkPackageViewColumnsService,readonly cdRef:ChangeDetectorRef,@@ -153,9 +153,13 @@ export class WpTableConfigurationModalComponent extends OpModalComponent implemeprotected loadForm() {const query = this.querySpace.query.value!;- return this.queryFormDm+ return this+ .apiV3Service+ .queries+ .form.load(query)- .then((form:QueryFormResource) => {+ .toPromise()+ .then(([form, _]) => {this.wpStatesInitialization.updateStatesFromForm(query, form);return form;diff --git a/frontend/src/app/components/wp-table/drag-and-drop/actions/hierarchy-drag-action.service.ts b/frontend/src/app/components/wp-table/drag-and-drop/actions/hierarchy-drag-action.service.tsindex 1f41da034af..feb867ec168 100644--- a/frontend/src/app/components/wp-table/drag-and-drop/actions/hierarchy-drag-action.service.ts+++ b/frontend/src/app/components/wp-table/drag-and-drop/actions/hierarchy-drag-action.service.ts@@ -6,15 +6,15 @@ import {hierarchyGroupClass,hierarchyRootClass} from "core-components/wp-fast-table/helpers/wp-table-hierarchy-helpers";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {relationRowClass} from "core-components/wp-fast-table/helpers/wp-table-row-helpers";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export class HierarchyDragActionService extends TableDragActionService {@InjectField() private wpTableHierarchies:WorkPackageViewHierarchiesService;@InjectField() private relationHierarchyService:WorkPackageRelationsHierarchyService;- @InjectField() private wpCacheService:WorkPackageCacheService;+ @InjectField() private apiV3Service:APIV3Service;public get applies() {return this.wpTableHierarchies.isEnabled;@@ -91,7 +91,12 @@ export class HierarchyDragActionService extends TableDragActionService {}private loadParentOfWP(wpId:string):Promise<string|null> {- return this.wpCacheService.require(wpId)+ return this+ .apiV3Service+ .work_packages+ .id(wpId)+ .get()+ .toPromise().then((wp:WorkPackageResource) => {return Promise.resolve(wp.parent?.id || null);});diff --git a/frontend/src/app/components/wp-table/embedded/wp-embedded-base.component.ts b/frontend/src/app/components/wp-table/embedded/wp-embedded-base.component.tsindex 73705f5fc76..b3706e0a40d 100644--- a/frontend/src/app/components/wp-table/embedded/wp-embedded-base.component.ts+++ b/frontend/src/app/components/wp-table/embedded/wp-embedded-base.component.ts@@ -6,13 +6,13 @@ import {WorkPackageTableConfigurationObject} from 'core-components/wp-table/wp-table-configuration';import {LoadingIndicatorService} from 'core-app/modules/common/loading-indicator/loading-indicator.service';-import {QueryDmService} from 'core-app/modules/hal/dm-services/query-dm.service';import {UrlParamsHelperService} from 'core-components/wp-query/url-params-helper';import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";import {WorkPackagesViewBase} from "core-app/modules/work_packages/routing/wp-view-base/work-packages-view.base";import {QueryResource} from "core-app/modules/hal/resources/query-resource";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Directive()export abstract class WorkPackageEmbeddedBaseComponent extends WorkPackagesViewBase implements AfterViewInit {@@ -27,7 +27,7 @@ export abstract class WorkPackageEmbeddedBaseComponent extends WorkPackagesViewBprotected initialized:boolean = false;- @InjectField() QueryDm:QueryDmService;+ @InjectField() apiV3Service:APIV3Service;@InjectField() querySpace:IsolatedQuerySpace;@InjectField() I18n:I18nService;@InjectField() urlParamsHelper:UrlParamsHelperService;@@ -84,8 +84,13 @@ export abstract class WorkPackageEmbeddedBaseComponent extends WorkPackagesViewBpagination.offset = 1;}- const promise = this.QueryDm.loadResults(query, pagination)- .then((query) => this.wpStatesInitialization.updateQuerySpace(query, query.results));+ const params = this.urlParamsHelper.buildV3GetQueryFromQueryResource(query, pagination);+ const promise =+ this+ .wpListService+ .loadQueryFromExisting(query, params, this.queryProjectScope)+ .toPromise()+ .then((query) => this.wpStatesInitialization.updateQuerySpace(query, query.results));if (visible) {this.loadingIndicator = promise;diff --git a/frontend/src/app/components/wp-table/embedded/wp-embedded-table.component.ts b/frontend/src/app/components/wp-table/embedded/wp-embedded-table.component.tsindex 65fc3348efb..f6c270a7f9e 100644--- a/frontend/src/app/components/wp-table/embedded/wp-embedded-table.component.ts+++ b/frontend/src/app/components/wp-table/embedded/wp-embedded-table.component.ts@@ -4,15 +4,14 @@ import {WorkPackageViewPaginationService} from 'core-app/modules/work_packages/rimport {OpTableActionFactory} from 'core-components/wp-table/table-actions/table-action';import {OpTableActionsService} from 'core-components/wp-table/table-actions/table-actions.service';import {QueryResource} from 'core-app/modules/hal/resources/query-resource';-import {QueryDmService} from 'core-app/modules/hal/dm-services/query-dm.service';import {WpTableConfigurationModalComponent} from 'core-components/wp-table/configuration-modal/wp-table-configuration.modal';import {OpModalService} from 'core-components/op-modals/op-modal.service';import {WorkPackageEmbeddedBaseComponent} from "core-components/wp-table/embedded/wp-embedded-base.component";import {QueryFormResource} from "core-app/modules/hal/resources/query-form-resource";-import {QueryFormDmService} from "core-app/modules/hal/dm-services/query-form-dm.service";import {distinctUntilChanged, map, take, withLatestFrom} from "rxjs/operators";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";import {KeepTabService} from "core-components/wp-single-view-tabs/keep-tab/keep-tab.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'wp-embedded-table',@@ -30,12 +29,11 @@ export class WorkPackageEmbeddedTableComponent extends WorkPackageEmbeddedBaseCo/** Inform about loaded query */@Output() public onQueryLoaded = new EventEmitter<QueryResource>();- @InjectField() QueryDm:QueryDmService;+ @InjectField() apiv3Service:APIV3Service;@InjectField() opModalService:OpModalService;@InjectField() tableActionsService:OpTableActionsService;@InjectField() wpTableTimeline:WorkPackageViewTimelineService;@InjectField() wpTablePagination:WorkPackageViewPaginationService;- @InjectField() QueryFormDm:QueryFormDmService;@InjectField() keepTab:KeepTabService;// Cache the form promise@@ -67,9 +65,15 @@ export class WorkPackageEmbeddedTableComponent extends WorkPackageEmbeddedBaseCothis.untilDestroyed(),withLatestFrom(this.querySpace.query.values$())).subscribe(([_, query]) => {- this.loadingIndicator = this.QueryDm- .loadResults(query, this.wpTablePagination.paginationObject)- .then((query) => this.initializeStates(query));+ const pagination = this.wpTablePagination.paginationObject;+ const params = this.urlParamsHelper.buildV3GetQueryFromQueryResource(query, pagination);++ this.loadingIndicator =+ this+ .wpListService+ .loadQueryFromExisting(query, params, this.queryProjectScope)+ .toPromise()+ .then((query) => this.initializeStates(query));});}@@ -93,6 +97,7 @@ export class WorkPackageEmbeddedTableComponent extends WorkPackageEmbeddedBaseCosuper.initializeStates(query);+this.querySpace.initialized.values$()@@ -113,13 +118,19 @@ export class WorkPackageEmbeddedTableComponent extends WorkPackageEmbeddedBaseCoreturn this.formPromise;}- return this.formPromise = this.QueryFormDm- .load(query)- .then((form:QueryFormResource) => {- this.wpStatesInitialization.updateStatesFromForm(query, form);- return form;- })- .catch(() => this.formPromise = undefined);+ return this.formPromise =+ this+ .apiv3Service+ .withOptionalProject(this.projectIdentifier)+ .queries+ .form+ .load(query)+ .toPromise()+ .then(([form, _]) => {+ this.wpStatesInitialization.updateStatesFromForm(query, form);+ return form;+ })+ .catch(() => this.formPromise = undefined);}public loadQuery(visible:boolean = true, firstPage:boolean = false):Promise<QueryResource> {@@ -145,12 +156,15 @@ export class WorkPackageEmbeddedTableComponent extends WorkPackageEmbeddedBaseCo}this.error = null;- const promise = this.QueryDm+ const promise = this+ .apiv3Service+ .queries.find(this.queryProps,this.queryId,this.queryProjectScope)+ .toPromise().then((query:QueryResource) => {this.initializeStates(query);this.onQueryLoaded.emit(query);diff --git a/frontend/src/app/components/wp-table/table-pagination/wp-table-pagination.component.spec.ts b/frontend/src/app/components/wp-table/table-pagination/wp-table-pagination.component.spec.tsindex 177415285dd..f268a570c96 100644--- a/frontend/src/app/components/wp-table/table-pagination/wp-table-pagination.component.spec.ts+++ b/frontend/src/app/components/wp-table/table-pagination/wp-table-pagination.component.spec.ts@@ -42,7 +42,6 @@ import {OpenProject} from "core-app/globals/openproject";import {OpIcon} from "core-app/modules/common/icon/op-icon";import {WorkPackageViewSortByService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-sort-by.service";import {ConfigurationService} from "core-app/modules/common/config/configuration.service";-import {ConfigurationDmService} from "core-app/modules/hal/dm-services/configuration-dm.service";function setupMocks(paginationService:PaginationService) {const options:IPaginationOptions = {@@ -91,7 +90,6 @@ describe('wpTablePagination Directive', () => {WorkPackageViewPaginationService,HalResourceService,ConfigurationService,- ConfigurationDmService,IsolatedQuerySpace,I18nService]diff --git a/frontend/src/app/components/wp-table/timeline/cells/wp-timeline-cell-mouse-handler.ts b/frontend/src/app/components/wp-table/timeline/cells/wp-timeline-cell-mouse-handler.tsindex cef137981f2..ad157c6328a 100644--- a/frontend/src/app/components/wp-table/timeline/cells/wp-timeline-cell-mouse-handler.ts+++ b/frontend/src/app/components/wp-table/timeline/cells/wp-timeline-cell-mouse-handler.ts@@ -28,13 +28,11 @@import {Injector} from '@angular/core';import * as moment from 'moment';-import {WorkPackageCacheService} from '../../../work-packages/work-package-cache.service';import {WorkPackageTimelineTableController} from '../container/wp-timeline-container.directive';import {RenderInfo} from '../wp-timeline';import {TimelineCellRenderer} from './timeline-cell-renderer';import {WorkPackageCellLabels} from './wp-timeline-cell';import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";-import {QueryDmService} from 'core-app/modules/hal/dm-services/query-dm.service';import {keyCodes} from 'core-app/modules/common/keyCodes.enum';import {LoadingIndicatorService} from "core-app/modules/common/loading-indicator/loading-indicator.service";@@ -45,6 +43,7 @@ import Moment = moment.Moment;import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";import {take} from "rxjs/operators";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export const classNameBar = 'bar';export const classNameLeftHandle = 'leftHandle';@@ -56,7 +55,6 @@ export function registerWorkPackageMouseHandler(this:void,injector:Injector,getRenderInfo:() => RenderInfo,workPackageTimeline:WorkPackageTimelineTableController,- wpCacheService:WorkPackageCacheService,halEditing:HalResourceEditingService,halEvents:HalEventsService,notificationService:WorkPackageNotificationService,@@ -69,7 +67,7 @@ export function registerWorkPackageMouseHandler(this:void,const querySpace:IsolatedQuerySpace = injector.get(IsolatedQuerySpace);- let mouseDownStartDay:number | null = null; // also flag to signal active drag'n'drop+ let mouseDownStartDay:number|null = null; // also flag to signal active drag'n'droprenderInfo.change = halEditing.changeFor(renderInfo.workPackage) as WorkPackageChangeset;let dateStates:any;@@ -242,7 +240,7 @@ export function registerWorkPackageMouseHandler(this:void,}function saveWorkPackage(change:WorkPackageChangeset) {- const queryDm:QueryDmService = injector.get(QueryDmService);+ const apiv3Service:APIV3Service = injector.get(APIV3Service);const querySpace:IsolatedQuerySpace = injector.get(IsolatedQuerySpace);// Remember the time before saving the work package to know which work packages to update@@ -253,12 +251,15 @@ export function registerWorkPackageMouseHandler(this:void,.then((result) => {notificationService.showSave(result.resource);const ids = _.map(querySpace.tableRendered.value!, row => row.workPackageId);- return queryDm.loadIdsUpdatedSince(ids, updatedAt).then(workPackageCollection => {- wpCacheService.updateWorkPackageList(workPackageCollection.elements);-- halEvents.push(result.resource, { eventType: 'updated' });- return querySpace.timelineRendered.pipe(take(1)).toPromise();- });+ return apiv3Service+ .work_packages+ .filterUpdatedSince(ids, updatedAt)+ .get()+ .toPromise()+ .then(() => {+ halEvents.push(result.resource, { eventType: 'updated' });+ return querySpace.timelineRendered.pipe(take(1)).toPromise();+ });}).catch((error) => {notificationService.handleRawError(error, renderInfo.workPackage);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 1b4cd6917f1..2bad08a1786 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@@ -27,7 +27,6 @@// ++import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {States} from '../../../states.service';-import {WorkPackageCacheService} from '../../../work-packages/work-package-cache.service';import {WorkPackageTimelineTableController} from '../container/wp-timeline-container.directive';import {RenderInfo} from '../wp-timeline';import {TimelineCellRenderer} from './timeline-cell-renderer';@@ -41,6 +40,7 @@ import {HalEventsService} from "core-app/modules/hal/services/hal-events.serviceimport {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";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export const classNameLeftLabel = 'labelLeft';export const classNameRightContainer = 'containerRight';@@ -65,7 +65,6 @@ export class WorkPackageCellLabels {}export class WorkPackageTimelineCell {- @InjectField() wpCacheService:WorkPackageCacheService;@InjectField() halEditing:HalResourceEditingService;@InjectField() halEvents:HalEventsService;@InjectField() notificationService:WorkPackageNotificationService;@@ -164,7 +163,6 @@ export class WorkPackageTimelineCell {this.injector,() => this.latestRenderInfo,this.workPackageTimeline,- this.wpCacheService,this.halEditing,this.halEvents,this.notificationService,diff --git a/frontend/src/app/components/wp-table/wp-table-sums-row/wp-table-sums-row.directive.ts b/frontend/src/app/components/wp-table/wp-table-sums-row/wp-table-sums-row.directive.tsindex 0ce14bb4c2b..13b864b018d 100644--- a/frontend/src/app/components/wp-table/wp-table-sums-row/wp-table-sums-row.directive.ts+++ b/frontend/src/app/components/wp-table/wp-table-sums-row/wp-table-sums-row.directive.ts@@ -83,7 +83,9 @@ export class WorkPackageTableSumsRowController implements AfterViewInit {).subscribe(([columns, sum, resource]) => {if (sum && resource.sumsSchema) {- this.schemaCache.require(resource.sumsSchema.$href!).then((schema:SchemaResource) => {+ this.schemaCache+ .ensureLoaded(resource.sumsSchema.$href!)+ .then((schema:SchemaResource) => {this.refresh(columns, resource, schema);});} else {diff --git a/frontend/src/app/components/wp-table/wp-table.component.ts b/frontend/src/app/components/wp-table/wp-table.component.tsindex 70885a6e574..8ce7cb6acfc 100644--- a/frontend/src/app/components/wp-table/wp-table.component.ts+++ b/frontend/src/app/components/wp-table/wp-table.component.ts@@ -174,6 +174,7 @@ export class WorkPackagesTableComponent extends UntilDestroyedMixin implements Othis.untilDestroyed()).subscribe(([results, groupBy, columns, timelines, sort]) => {this.query = this.querySpace.query.value!;+this.results = results;this.groupBy = groupBy;diff --git a/frontend/src/app/modules/common/path-helper/path-helper.service.spec.ts b/frontend/src/app/modules/apiv3/api-v3.service.spec.tssimilarity index 67%rename from frontend/src/app/modules/common/path-helper/path-helper.service.spec.tsrename to frontend/src/app/modules/apiv3/api-v3.service.spec.tsindex 29db9e06eb5..1f5cf0c1453 100644--- a/frontend/src/app/modules/common/path-helper/path-helper.service.spec.ts+++ b/frontend/src/app/modules/apiv3/api-v3.service.spec.ts@@ -26,10 +26,28 @@// See docs/COPYRIGHT.rdoc for more details.// ++-import {PathHelperService} from './path-helper.service';+import {async, TestBed} from "@angular/core/testing";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";+import {States} from "core-components/states.service";-describe('PathHelper', function() {- var PathHelper:PathHelperService = new PathHelperService();+describe('APIv3Service', function() {+ let service:APIV3Service;++ beforeEach(async(() => {+ // noinspection JSIgnoredPromiseFromCall+ TestBed.configureTestingModule({+ providers: [+ States,+ PathHelperService,+ APIV3Service+ ]+ })+ .compileComponents()+ .then(() => {+ service = TestBed.inject(APIV3Service);+ });+ }));function encodeParams(object:any) {return new URLSearchParams(object).toString();@@ -39,23 +57,7 @@ describe('PathHelper', function() {var projectIdentifier = 'majora';it('should provide the project\'s path', function() {- expect(PathHelper.api.v3.projects.id(projectIdentifier).path).toEqual('/api/v3/projects/majora');- });-- it('should provide a path to the project\'s mentionable principals', function() {- var projectId = '1';- var term = 'Maria';-- let params = {- filters: '[{"status":{"operator":"!","values":["3"]}},{"member":{"operator":"=","values":["1"]}},{"type":{"operator":"=","values":["User","Group"]}},{"id":{"operator":"!","values":["me"]}},{"name":{"operator":"~","values":["Maria"]}}]',- sortBy: '[["name","asc"]]',- offset: '1',- pageSize: '10'- };-- expect(- PathHelper.api.v3.principals(projectId, term)- ).toEqual('/api/v3/principals?' + encodeParams(params));+ expect(service.projects.id(projectIdentifier).path).toEqual('/api/v3/projects/majora');});it('should provide a path to work package query on subject or ID ', function() {@@ -67,7 +69,7 @@ describe('PathHelper', function() {};expect(- PathHelper.api.v3.wpBySubjectOrId("bogus")+ service.work_packages.filterBySubjectOrId("bogus").path).toEqual('/api/v3/work_packages?' + encodeParams(params));params = {@@ -77,7 +79,7 @@ describe('PathHelper', function() {pageSize: '10'};expect(- PathHelper.api.v3.wpBySubjectOrId("1234", true)+ service.work_packages.filterBySubjectOrId("1234", true).path).toEqual('/api/v3/work_packages?' + encodeParams(params));});});diff --git a/frontend/src/app/modules/apiv3/api-v3.service.ts b/frontend/src/app/modules/apiv3/api-v3.service.tsnew file mode 100644index 00000000000..39b1c84e71e--- /dev/null+++ b/frontend/src/app/modules/apiv3/api-v3.service.ts@@ -0,0 +1,156 @@+// -- 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 {Injectable, Injector} from "@angular/core";+import {+ APIv3GettableResource,+ APIv3ResourceCollection,+ APIv3ResourcePath+} from "core-app/modules/apiv3/paths/apiv3-resource";+import {Constructor} from "@angular/cdk/table";+import {Apiv3GridsPaths} from "core-app/modules/apiv3/endpoints/grids/apiv3-grids-paths";+import {Apiv3TimeEntriesPaths} from "core-app/modules/apiv3/endpoints/time-entries/apiv3-time-entries-paths";+import {Apiv3MembershipsPaths} from "core-app/modules/apiv3/endpoints/memberships/apiv3-memberships-paths";+import {Apiv3UsersPaths} from "core-app/modules/apiv3/endpoints/users/apiv3-users-paths";+import {APIv3TypesPaths} from "core-app/modules/apiv3/endpoints/types/apiv3-types-paths";+import {APIv3QueriesPaths} from "core-app/modules/apiv3/endpoints/queries/apiv3-queries-paths";+import {APIv3ProjectsPaths} from "core-app/modules/apiv3/endpoints/projects/apiv3-projects-paths";+import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";+import {APIV3WorkPackagesPaths} from "core-app/modules/apiv3/endpoints/work_packages/api-v3-work-packages-paths";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {APIv3ProjectPaths} from "core-app/modules/apiv3/endpoints/projects/apiv3-project-paths";+import {RootResource} from "core-app/modules/hal/resources/root-resource";+import {APIv3StatusesPaths} from "core-app/modules/apiv3/endpoints/statuses/apiv3-statuses-paths";+import {APIv3VersionsPaths} from "core-app/modules/apiv3/endpoints/versions/apiv3-versions-paths";+import {Apiv3RelationsPaths} from "core-app/modules/apiv3/endpoints/relations/apiv3-relations-paths";+import {Apiv3NewsPaths} from "core-app/modules/apiv3/endpoints/news/apiv3-news-paths";+import {Apiv3HelpTextsPaths} from "core-app/modules/apiv3/endpoints/help_texts/apiv3-help-texts-paths";+import {Apiv3ConfigurationPath} from "core-app/modules/apiv3/endpoints/configuration/apiv3-configuration-path";+import {ProjectResource} from "core-app/modules/hal/resources/project-resource";+import * as ts from "typescript/lib/tsserverlibrary";+import Project = ts.server.Project;+import {Apiv3BoardsPaths} from "core-app/modules/apiv3/virtual/apiv3-boards-paths";++@Injectable({ providedIn: 'root' })+export class APIV3Service {+ // /api/v3/attachments+ public readonly attachments = this.apiV3CollectionEndpoint('attachments');++ // /api/v3/configuration+ public readonly configuration = this.apiV3CustomEndpoint(Apiv3ConfigurationPath);++ // /api/v3/documents+ public readonly documents = this.apiV3CollectionEndpoint('documents');++ // /api/v3/grids+ public readonly grids = this.apiV3CustomEndpoint(Apiv3GridsPaths);++ // /api/v3/groups+ public readonly groups = this.apiV3CollectionEndpoint('groups');++ // /api/v3/root+ public readonly root = this.apiV3SingularEndpoint<RootResource>('');++ // /api/v3/statuses+ public readonly statuses = this.apiV3CustomEndpoint(APIv3StatusesPaths);++ // /api/v3/relations+ public readonly relations = this.apiV3CustomEndpoint(Apiv3RelationsPaths);++ // /api/v3/priorities+ public readonly priorities = this.apiV3CollectionEndpoint('priorities');++ // /api/v3/time_entries+ public readonly time_entries = this.apiV3CustomEndpoint(Apiv3TimeEntriesPaths);++ // /api/v3/memberships+ public readonly memberships = this.apiV3CustomEndpoint(Apiv3MembershipsPaths);++ // /api/v3/news+ public readonly news = this.apiV3CustomEndpoint(Apiv3NewsPaths);++ // /api/v3/types+ public readonly types = this.apiV3CustomEndpoint(APIv3TypesPaths);++ // /api/v3/versions+ public readonly versions = this.apiV3CustomEndpoint(APIv3VersionsPaths);++ // /api/v3/work_packages+ public readonly work_packages = this.apiV3CustomEndpoint(APIV3WorkPackagesPaths);++ // /api/v3/queries+ public readonly queries = this.apiV3CustomEndpoint(APIv3QueriesPaths);++ // /api/v3/projects+ public readonly projects = this.apiV3CustomEndpoint(APIv3ProjectsPaths);++ // /api/v3/users+ public readonly users = this.apiV3CustomEndpoint(Apiv3UsersPaths);++ // /api/v3/help_texts+ public readonly help_texts = this.apiV3CustomEndpoint(Apiv3HelpTextsPaths);++ // /api/v3/job_statuses+ public readonly job_statuses = this.apiV3CollectionEndpoint('job_statuses');++ // VIRTUAL boards are /api/v3/grids + a scope filter+ public readonly boards = this.apiV3CustomEndpoint(Apiv3BoardsPaths);++ constructor(readonly injector:Injector,+ readonly pathHelper:PathHelperService) {+ }++ /**+ * Returns the part of the API that exists both+ * - WITHIN a project scope /api/v3/projects/*+ * - GLOBALLY /api/v3/*+ *+ * The available API endpoints are being restricted automatically by typescript.+ *+ * @param projectIdentifier+ */+ public withOptionalProject(projectIdentifier:string|number|null|undefined):APIv3ProjectPaths|this {+ if (_.isNil(projectIdentifier)) {+ return this;+ } else {+ return this.projects.id(projectIdentifier);+ }+ }++ private apiV3CollectionEndpoint<V extends HalResource, T extends APIv3GettableResource<V>>(segment:string, resource?:Constructor<T>) {+ return new APIv3ResourceCollection<V, T>(this, this.pathHelper.api.v3.apiV3Base, segment, resource);+ }++ private apiV3CustomEndpoint<T>(cls:Constructor<T>):T {+ return new cls(this, this.pathHelper.api.v3.apiV3Base);+ }++ private apiV3SingularEndpoint<T extends HalResource = HalResource>(segment:string):APIv3GettableResource<T> {+ return new APIv3GettableResource<T>(this, this.pathHelper.api.v3.apiV3Base, segment);+ }+}diff --git a/frontend/src/app/modules/apiv3/cache/cachable-apiv3-collection.ts b/frontend/src/app/modules/apiv3/cache/cachable-apiv3-collection.tsnew file mode 100644index 00000000000..5604af49bc3--- /dev/null+++ b/frontend/src/app/modules/apiv3/cache/cachable-apiv3-collection.ts@@ -0,0 +1,85 @@+// -- 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 {APIv3GettableResource, APIv3ResourceCollection} from "core-app/modules/apiv3/paths/apiv3-resource";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {States} from "core-components/states.service";+import {HasId, StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {Observable} from "rxjs";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {tap} from "rxjs/operators";++export abstract class CachableAPIV3Collection<+ T extends HasId = HalResource,+ V extends APIv3GettableResource<T> = APIv3GettableResource<T>,+ X extends StateCacheService<T> = StateCacheService<T>+ >+ extends APIv3ResourceCollection<T, V> {+ @InjectField() states:States;++ readonly cache:X = this.createCache();++ /**+ * Observe all value changes of the cache+ */+ public observeAll():Observable<T[]> {+ return this.cache.observeAll();+ }++ /**+ * Inserts a collection or single response to cache as an rxjs tap function+ */+ protected cacheResponse<R>():(source:Observable<R>) => Observable<R> {+ return (source$) => {+ return source$.pipe(+ tap(+ (response:R) => {+ if (response instanceof CollectionResource) {+ response.elements.forEach(this.touch.bind(this));+ } else if (response instanceof HalResource) {+ this.touch(response as any);+ }+ }+ )+ );+ };+ }++ /**+ * Update a single resource+ */+ protected touch(resource:T):void {+ this.cache.updateFor(resource);+ }++ /**+ * Creates the cache state instance+ */+ protected abstract createCache():X;+}diff --git a/frontend/src/app/modules/apiv3/cache/cachable-apiv3-resource.ts b/frontend/src/app/modules/apiv3/cache/cachable-apiv3-resource.tsnew file mode 100644index 00000000000..082cb22d2fb--- /dev/null+++ b/frontend/src/app/modules/apiv3/cache/cachable-apiv3-resource.ts@@ -0,0 +1,175 @@+// -- 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 {APIv3GettableResource} from "core-app/modules/apiv3/paths/apiv3-resource";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {States} from "core-components/states.service";+import {HasId, StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {concat, from, merge, Observable, of} from "rxjs";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {mapTo, publish, share, switchMap, take, tap} from "rxjs/operators";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";++export abstract class CachableAPIV3Resource<T extends HasId = HalResource>+ extends APIv3GettableResource<T> {+ @InjectField() states:States;+ @InjectField() schemaCache:SchemaCacheService;++ readonly cache = this.createCache();++ /**+ * Require the value to be loaded either when forced or the value is stale+ * according to the cache interval specified for this service.+ *+ * Returns an observable to the values stream of the state.+ *+ * @param force Load the value anyway.+ */+ public requireAndStream(force:boolean = false):Observable<T> {+ const id = this.id.toString();++ // Refresh when stale or being forced+ if (this.cache.stale(id) || force) {+ const observable = this+ .load()+ .pipe(+ take(1),+ share()+ );++ this.cache.clearAndLoad(+ id,+ observable+ );++ // Return concat of the loading observable+ // for error handling and the like,+ // but then continue with the streamed cache+ return merge<T>(+ observable,+ this.cache.state(id).values$()+ );+ }++ return this.cache.state(id).values$();+ }+++ /**+ * Observe the values of this resource,+ * but do not request it actively.+ */+ public observe():Observable<T> {+ return this+ .cache+ .observe(this.id.toString());+ }+++ /**+ * Returns a (potentially cached) observable.+ *+ * Only observes one value.+ *+ * Accesses or modifies the global store for this resource.+ */+ get():Observable<T> {+ return this+ .requireAndStream(false)+ .pipe(+ take(1)+ );+ }++ /**+ * Returns a freshly loaded value but ensuring the value+ * is also updated in the cache.+ *+ * Only observes one value.+ *+ * Accesses or modifies the global store for this resource.+ */+ refresh():Promise<T> {+ return this+ .requireAndStream(true)+ .pipe(+ take(1),+ )+ // Use a promise to ensure this fires+ // even if caller isn't subscribing.+ .toPromise();+ }++ /**+ * Perform a request to the HalResourceService with the current path+ */+ protected load():Observable<T> {+ return this+ .halResourceService+ .get(this.path)+ .pipe(+ switchMap((resource) => {+ if (resource.$links.schema) {+ return this.schemaCache+ .requireAndStream(resource.$links.schema.href)+ .pipe(+ take(1),+ mapTo(resource),+ );+ } else {+ return of(resource);+ }+ })+ ) as any; // T does not extend HalResource for virtual endpoints such as board, thus we need to cast here+ }++ /**+ * Update a single resource+ */+ protected touch(resource:T):void {+ this.cache.updateFor(resource);+ }++ /**+ * Inserts a collection response to cache as an rxjs tap function+ */+ protected cacheResponse():(source:Observable<T>) => Observable<T> {+ return (source$:Observable<T>) => {+ return source$.pipe(+ tap(+ (resource:T) => this.touch(resource)+ )+ );+ };+ }++ /**+ * Creates the cache state instance+ */+ protected abstract createCache():StateCacheService<T>;+}diff --git a/frontend/src/app/components/states/state-cache.service.ts b/frontend/src/app/modules/apiv3/cache/state-cache.service.tssimilarity index 54%rename from frontend/src/app/components/states/state-cache.service.tsrename to frontend/src/app/modules/apiv3/cache/state-cache.service.tsindex 35619967998..38b02cc36b1 100644--- a/frontend/src/app/components/states/state-cache.service.ts+++ b/frontend/src/app/modules/apiv3/cache/state-cache.service.ts@@ -26,14 +26,21 @@// See docs/COPYRIGHT.rdoc for more details.// ++-import {InputState, MultiInputState, State} from 'reactivestates';+import {MultiInputState, State} from 'reactivestates';import {Observable} from "rxjs";-import {auditTime, map, startWith} from "rxjs/operators";+import {auditTime, map, share, startWith, take} from "rxjs/operators";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";-export abstract class StateCacheService<T> {- private cacheDurationInMs:number;+export interface HasId {+ id:string|null;+}++export class StateCacheService<T> {+ protected cacheDurationInMs:number;+ protected multiState:MultiInputState<T>;- constructor(private holdValuesForSeconds:number = 3600) {+ constructor(state:MultiInputState<T>, holdValuesForSeconds:number = 3600) {+ this.multiState = state;this.cacheDurationInMs = holdValuesForSeconds * 1000;}@@ -56,16 +63,47 @@ export abstract class StateCacheService<T> {return this.state(id).getValueOr(fallback);}+ /**+ * Sets a promise to the state+ */+ public clearAndLoad(id:string, loader:Observable<T>):Observable<T> {+ const observable =+ loader+ .pipe(+ take(1),+ share()+ );++ this+ .multiState.get(id)+ .clearAndPutFromPromise(observable.toPromise());++ return observable;+ }+/*** Update the value due to application changes.** @param id The value's identifier.* @param val<T> The value.+ *+ * @return a promise of the value when it was inserted into cache*/- public updateValue(id:string, val:T) {- this.multiState.get(id).putValue(val);+ public updateValue(id:string, val:T):Promise<T> {+ this.putValue(id, val);+ return Promise.resolve(val);}+ /**+ * Update the value due to application changes.+ *+ * @param resource<T> The value.+ */+ public updateFor(resource:HasId):Promise<T> {+ return this.updateValue(resource.id!, resource as any);+ }++/*** Observe the value of the given id*/@@ -110,76 +148,14 @@ export abstract class StateCacheService<T> {ids.forEach(id => this.multiState.get(id).clear());}- /**- * Require the value to be loaded either when forced or the value is stale- * according to the cache interval specified for this service.- *- * @param id The value's identifier.- * @param force Load the value anyway.- */- public require(id:string, force:boolean = false):Promise<T> {- const state = this.multiState.get(id);-- // Refresh when stale or being forced- if (this.stale(state) || force) {- let promise = this.load(id);- state.clearAndPutFromPromise(promise);- return promise;- }-- return state.valuesPromise() as Promise<T>;- }-- /**- * Require the value to be loaded either when forced or the value is stale- * according to the cache interval specified for this service.- *- * Returns an observable to the values stream of the state.- *- * @param id The value's identifier.- * @param force Load the value anyway.- */- public requireAndStream(id:string, force:boolean = false):Observable<T> {- const state = this.multiState.get(id);-- // Refresh when stale or being forced- if (this.stale(state) || force) {- state.clear();- state.putFromPromiseIfPristine(() => this.load(id));- }-- return state.values$();- }-- /**- * Require the states of the given ids to be loaded if they're empty or stale,- * or all when force is given.- * @param ids Ids to require- * @param force Load the values anyway- * @return {Promise<undefined>} An empty promise to mark when the set of states is filled.- */- public requireAll(ids:string[], force:boolean = false):Promise<unknown> {- let idsToRequest:string[];-- if (force) {- idsToRequest = ids;- } else {- idsToRequest = ids.filter((id:string) => this.stale(this.multiState.get(id)));- }-- if (idsToRequest.length === 0) {- return Promise.resolve(undefined);- }-- return this.loadAll(idsToRequest);- }-/*** Returns whether the state- * @param state+ * @param id ID of the state* @return {boolean}*/- protected stale(state:InputState<T>):boolean {+ public stale(id:string):boolean {+ const state = this.multiState.get(id);+// If there is an active request that is still pendingif (state.hasActivePromiseRequest()) {return false;@@ -189,20 +165,13 @@ export abstract class StateCacheService<T> {}/**- * Returns the internal state object- */- protected abstract get multiState():MultiInputState<T>;-- /**- * Load a single value into the cache state.- * Subclassses need to ensure it gets loaded and resolve or reject the promise- * @param id The identifier of the value object of type T.- */- protected abstract load(id:string):Promise<T>;-- /**- * Load a set of required values, fill the results into the appropriate states- * and return a promise when all values are inserted.+ * Actually insert the value in the state right now.+ *+ * @param id+ * @param val*/- protected abstract loadAll(ids:string[]):Promise<undefined|unknown>;+ protected putValue(id:string, val:T) {+ this.multiState.get(id).putValue(val);+ }}+diff --git a/frontend/src/app/modules/hal/dm-services/configuration-dm.service.ts b/frontend/src/app/modules/apiv3/endpoints/configuration/apiv3-configuration-path.tssimilarity index 66%rename from frontend/src/app/modules/hal/dm-services/configuration-dm.service.tsrename to frontend/src/app/modules/apiv3/endpoints/configuration/apiv3-configuration-path.tsindex 6b544c7cad6..8957b517073 100644--- a/frontend/src/app/modules/hal/dm-services/configuration-dm.service.ts+++ b/frontend/src/app/modules/apiv3/endpoints/configuration/apiv3-configuration-path.ts@@ -1,4 +1,4 @@-//-- copyright+// -- copyright// OpenProject is an open source project management software.// Copyright (C) 2012-2020 the OpenProject GmbH//@@ -24,30 +24,33 @@// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.//// See docs/COPYRIGHT.rdoc for more details.-//+++// ++-import {Injectable} from '@angular/core';-import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {ConfigurationResource} from 'core-app/modules/hal/resources/configuration-resource';-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';-import {shareReplay} from "rxjs/operators";+import {APIv3GettableResource, APIv3ResourceCollection} from "core-app/modules/apiv3/paths/apiv3-resource";+import {GridResource} from "core-app/modules/hal/resources/grid-resource";+import {APIv3FormResource} from "core-app/modules/apiv3/forms/apiv3-form-resource";+import {ConfigurationResource} from "core-app/modules/hal/resources/configuration-resource";import {Observable} from "rxjs";+import {shareReplay} from "rxjs/operators";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";++export class Apiv3ConfigurationPath extends APIv3GettableResource<ConfigurationResource> {+ private $configuration:Observable<ConfigurationResource>;-@Injectable()-export class ConfigurationDmService {- constructor(protected halResourceService:HalResourceService,- protected pathHelper:PathHelperService) {+ constructor(protected apiRoot:APIV3Service,+ readonly basePath:string) {+ super(apiRoot, basePath, 'configuration');}- private $configuration:Observable<ConfigurationResource>;- public load():Observable<ConfigurationResource> {++ public get():Observable<ConfigurationResource> {if (this.$configuration) {return this.$configuration;}return this.$configuration = this.halResourceService- .get<ConfigurationResource>(this.pathHelper.api.v3.configuration.toString())+ .get<ConfigurationResource>(this.path).pipe(shareReplay());diff --git a/frontend/src/app/modules/apiv3/endpoints/grids/apiv3-grid-form.ts b/frontend/src/app/modules/apiv3/endpoints/grids/apiv3-grid-form.tsnew file mode 100644index 00000000000..77a230b04c3--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/grids/apiv3-grid-form.ts@@ -0,0 +1,81 @@+// -- 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 {APIv3FormResource} from "core-app/modules/apiv3/forms/apiv3-form-resource";+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";+import {HalPayloadHelper} from "core-app/modules/hal/schemas/hal-payload.helper";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {GridWidgetResource} from "core-app/modules/hal/resources/grid-widget-resource";++export class Apiv3GridForm extends APIv3FormResource {++ /**+ * We need to override the grid widget extraction+ * to pass the correct payload to the API.+ *+ * @param resource+ * @param schema+ */+ public static extractPayload(resource:HalResource|Object, schema:SchemaResource|null = null):Object {+ if (resource instanceof HalResource && schema) {+ let grid = resource as HalResource;+ let payload = HalPayloadHelper.extractPayloadFromSchema(grid, schema);++ // The widget only states the type of the widget resource but does not explain+ // the widget itself. We therefore have to do that by hand.+ if (payload.widgets) {+ payload.widgets = grid.widgets.map((widget:GridWidgetResource) => {+ return {+ id: widget.id,+ startRow: widget.startRow,+ endRow: widget.endRow,+ startColumn: widget.startColumn,+ endColumn: widget.endColumn,+ identifier: widget.identifier,+ options: widget.options+ };+ });+ }++ return payload;+ }++ return resource || {};+ }++ /**+ * Extract payload for the form from the request and optional schema.+ *+ * @param request+ * @param schema+ */+ public extractPayload(request:HalResource|Object, schema:SchemaResource|null = null) {+ return Apiv3GridForm.extractPayload(request, schema);+ }++}diff --git a/frontend/src/app/modules/hal/dm-services/project-dm.service.ts b/frontend/src/app/modules/apiv3/endpoints/grids/apiv3-grid-paths.tssimilarity index 57%rename from frontend/src/app/modules/hal/dm-services/project-dm.service.tsrename to frontend/src/app/modules/apiv3/endpoints/grids/apiv3-grid-paths.tsindex b02e97c394f..337695d357c 100644--- a/frontend/src/app/modules/hal/dm-services/project-dm.service.ts+++ b/frontend/src/app/modules/apiv3/endpoints/grids/apiv3-grid-paths.ts@@ -1,4 +1,4 @@-//-- copyright+// -- copyright// OpenProject is an open source project management software.// Copyright (C) 2012-2020 the OpenProject GmbH//@@ -24,31 +24,37 @@// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.//// See docs/COPYRIGHT.rdoc for more details.-//+++// ++-import {Injectable} from '@angular/core';-import {ProjectResource} from 'core-app/modules/hal/resources/project-resource';+import {APIv3GettableResource} from "core-app/modules/apiv3/paths/apiv3-resource";+import {GridResource} from "core-app/modules/hal/resources/grid-resource";import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";-import {Apiv3ProjectsPaths} from "core-app/modules/common/path-helper/apiv3/projects/apiv3-projects-paths";-import {AbstractDmService} from "core-app/modules/hal/dm-services/abstract-dm.service";+import {Observable} from "rxjs";+import {Apiv3GridForm} from "core-app/modules/apiv3/endpoints/grids/apiv3-grid-form";-@Injectable()-export class ProjectDmService extends AbstractDmService<ProjectResource> {- public schema():Promise<SchemaResource> {- return this.halResourceService- .get<SchemaResource>(this.projectsPath.schema)- .toPromise();- }+export class Apiv3GridPaths extends APIv3GettableResource<GridResource> {+ // Static paths+ readonly form = this.subResource('form', Apiv3GridForm);- protected listUrl():string {- return this.projectsPath.toString();- }+ /**+ * Update a grid resource or payload+ * @param resource+ * @param schema+ */+ public patch(resource:GridResource|Object, schema:SchemaResource|null = null):Observable<GridResource> {+ let payload = this.form.extractPayload(resource, schema);- protected oneUrl(id:number|string):string {- return this.projectsPath.id(id).toString();+ return this+ .halResourceService+ .patch<GridResource>(this.path, payload);}- private get projectsPath():Apiv3ProjectsPaths {- return this.pathHelper.api.v3.projects;+ /**+ * Delete a grid resource+ */+ public delete():Observable<unknown> {+ return this+ .halResourceService+ .delete(this.path);}}diff --git a/frontend/src/app/modules/apiv3/endpoints/grids/apiv3-grids-paths.ts b/frontend/src/app/modules/apiv3/endpoints/grids/apiv3-grids-paths.tsnew file mode 100644index 00000000000..0fa6a97e4b0--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/grids/apiv3-grids-paths.ts@@ -0,0 +1,77 @@+// -- 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 {APIv3ResourceCollection} from "core-app/modules/apiv3/paths/apiv3-resource";+import {Apiv3GridPaths} from "core-app/modules/apiv3/endpoints/grids/apiv3-grid-paths";+import {GridResource} from "core-app/modules/hal/resources/grid-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";+import {Apiv3GridForm} from "core-app/modules/apiv3/endpoints/grids/apiv3-grid-form";+import {Observable} from "rxjs";+import {+ Apiv3ListParameters,+ Apiv3ListResourceInterface,+ listParamsString+} from "core-app/modules/apiv3/paths/apiv3-list-resource.interface";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";++export class Apiv3GridsPaths+ extends APIv3ResourceCollection<GridResource, Apiv3GridPaths>+ implements Apiv3ListResourceInterface<GridResource> {+ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'grids', Apiv3GridPaths);+ }++ readonly form = this.subResource('form', Apiv3GridForm);++ /**+ * Load a list of grids with a given list parameter filter+ * @param params+ */+ public list(params?:Apiv3ListParameters):Observable<CollectionResource<GridResource>> {+ return this+ .halResourceService+ .get<CollectionResource<GridResource>>(this.path + listParamsString(params));+ }++ /**+ * Create a new GridResource+ *+ * @param resource+ * @param schema+ */+ public post(resource:GridResource, schema:SchemaResource|null = null):Observable<GridResource> {+ return this+ .halResourceService+ .post<GridResource>(+ this.path,+ this.form.extractPayload(resource, schema)+ );+ }+}diff --git a/frontend/src/app/modules/hal/dm-services/dm.service.interface.ts b/frontend/src/app/modules/apiv3/endpoints/help_texts/apiv3-help-texts-paths.tssimilarity index 60%rename from frontend/src/app/modules/hal/dm-services/dm.service.interface.tsrename to frontend/src/app/modules/apiv3/endpoints/help_texts/apiv3-help-texts-paths.tsindex 0c939cc7b04..623a7715751 100644--- a/frontend/src/app/modules/hal/dm-services/dm.service.interface.ts+++ b/frontend/src/app/modules/apiv3/endpoints/help_texts/apiv3-help-texts-paths.ts@@ -1,4 +1,4 @@-//-- copyright+// -- copyright// OpenProject is an open source project management software.// Copyright (C) 2012-2020 the OpenProject GmbH//@@ -24,17 +24,28 @@// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.//// See docs/COPYRIGHT.rdoc for more details.-//+++// +++import {APIv3GettableResource, APIv3ResourceCollection} from "core-app/modules/apiv3/paths/apiv3-resource";import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";-import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {Observable} from "rxjs";+import {HelpTextResource} from "core-app/modules/hal/resources/help-text-resource";-export interface DmListParameter {- filters?:[string, FilterOperator, string[]][];- sortBy?:[string, string][];- pageSize?:number;-}+export class Apiv3HelpTextsPaths+ extends APIv3ResourceCollection<HelpTextResource, APIv3GettableResource<HelpTextResource>> {+ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'help_texts');+ }-export interface DmServiceInterface {- list(params:DmListParameter):Promise<CollectionResource>;+ /**+ * Load a list of membership entries with a given list parameter filter+ * @param params+ */+ public get():Observable<CollectionResource<HelpTextResource>> {+ return this+ .halResourceService+ .get<CollectionResource<HelpTextResource>>(this.path);+ }}diff --git a/frontend/src/app/modules/apiv3/endpoints/memberships/apiv3-memberships-paths.ts b/frontend/src/app/modules/apiv3/endpoints/memberships/apiv3-memberships-paths.tsnew file mode 100644index 00000000000..b2143d01598--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/memberships/apiv3-memberships-paths.ts@@ -0,0 +1,63 @@+// -- 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 {APIv3GettableResource, APIv3ResourceCollection} from "core-app/modules/apiv3/paths/apiv3-resource";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {ProjectResource} from "core-app/modules/hal/resources/project-resource";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {Apiv3AvailableProjectsPaths} from "core-app/modules/apiv3/endpoints/projects/apiv3-available-projects-paths";+import {+ Apiv3ListParameters,+ Apiv3ListResourceInterface, listParamsString+} from "core-app/modules/apiv3/paths/apiv3-list-resource.interface";+import {Observable} from "rxjs";+import {MembershipResource} from "core-app/modules/hal/resources/membership-resource";++export class Apiv3MembershipsPaths+ extends APIv3ResourceCollection<MembershipResource, APIv3GettableResource<MembershipResource>>+ implements Apiv3ListResourceInterface<MembershipResource> {+ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'memberships');+ }++ /**+ * Load a list of membership entries with a given list parameter filter+ * @param params+ */+ public list(params?:Apiv3ListParameters):Observable<CollectionResource<MembershipResource>> {+ return this+ .halResourceService+ .get<CollectionResource<MembershipResource>>(this.path + listParamsString(params));+ }+++ // /api/v3/memberships/available_projects+ readonly available_projects = this.subResource('available_projects', Apiv3AvailableProjectsPaths);+}diff --git a/frontend/src/app/modules/hal/dm-services/news-dm.service.ts b/frontend/src/app/modules/apiv3/endpoints/news/apiv3-news-paths.tssimilarity index 52%rename from frontend/src/app/modules/hal/dm-services/news-dm.service.tsrename to frontend/src/app/modules/apiv3/endpoints/news/apiv3-news-paths.tsindex 6f6ae86ad60..ee14a137c58 100644--- a/frontend/src/app/modules/hal/dm-services/news-dm.service.ts+++ b/frontend/src/app/modules/apiv3/endpoints/news/apiv3-news-paths.ts@@ -1,4 +1,4 @@-//-- copyright+// -- copyright// OpenProject is an open source project management software.// Copyright (C) 2012-2020 the OpenProject GmbH//@@ -24,19 +24,36 @@// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.//// See docs/COPYRIGHT.rdoc for more details.-//+++// ++-import {Injectable} from '@angular/core';-import {AbstractDmService} from "core-app/modules/hal/dm-services/abstract-dm.service";++import {APIv3GettableResource, APIv3ResourceCollection} from "core-app/modules/apiv3/paths/apiv3-resource";+import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {Observable} from "rxjs";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {+ Apiv3ListParameters,+ Apiv3ListResourceInterface,+ listParamsString+} from "core-app/modules/apiv3/paths/apiv3-list-resource.interface";import {NewsResource} from "core-app/modules/hal/resources/news-resource";-@Injectable()-export class NewsDmService extends AbstractDmService<NewsResource> {- protected listUrl() {- return this.pathHelper.api.v3.news.toString();+export class Apiv3NewsPaths+ extends APIv3ResourceCollection<NewsResource, APIv3GettableResource<NewsResource>>+ implements Apiv3ListResourceInterface<NewsResource> {+ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'news');}- protected oneUrl(id:number|string) {- return this.pathHelper.api.v3.news.id(id).toString();+ /**+ * Load a list of time entries with a given list parameter filter+ * @param params+ */+ public list(params?:Apiv3ListParameters):Observable<CollectionResource<NewsResource>> {+ return this+ .halResourceService+ .get<CollectionResource<TimeEntryResource>>(this.path + listParamsString(params));}}diff --git a/frontend/src/app/modules/apiv3/endpoints/projects/apiv3-available-projects-paths.ts b/frontend/src/app/modules/apiv3/endpoints/projects/apiv3-available-projects-paths.tsnew file mode 100644index 00000000000..785105bfd11--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/projects/apiv3-available-projects-paths.ts@@ -0,0 +1,75 @@+// -- 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 {ProjectResource} from "core-app/modules/hal/resources/project-resource";+import {APIv3GettableResource} from "core-app/modules/apiv3/paths/apiv3-resource";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {buildApiV3Filter} from "core-components/api/api-v3/api-v3-filter-builder";+import {Observable} from "rxjs";+import {map} from "rxjs/operators";+import {+ Apiv3ListParameters,+ Apiv3ListResourceInterface, listParamsString+} from "core-app/modules/apiv3/paths/apiv3-list-resource.interface";++export class Apiv3AvailableProjectsPaths+ extends APIv3GettableResource<CollectionResource<ProjectResource>>+ implements Apiv3ListResourceInterface<ProjectResource> {++ /**+ * Load a list of available projects with a given list parameter filter+ * @param params+ */+ public list(params?:Apiv3ListParameters):Observable<CollectionResource<ProjectResource>> {+ return this+ .halResourceService+ .get<CollectionResource<ProjectResource>>(this.path + listParamsString(params));+ }++ /**+ * Performs a request against the available_projects endpoint+ * to see whether this is contained+ *+ * Returns whether the given id exists in the set+ * of available projects+ *+ * @param projectId+ */+ public exists(projectId:string):Observable<boolean> {+ return this+ .halResourceService+ .get<CollectionResource<ProjectResource>>(+ this.path,+ { filters: buildApiV3Filter('id', '=', [projectId]).toJson() }+ )+ .pipe(+ map(collection => collection.count > 0)+ );+ }++}diff --git a/frontend/src/app/modules/apiv3/endpoints/projects/apiv3-project-paths.ts b/frontend/src/app/modules/apiv3/endpoints/projects/apiv3-project-paths.tsnew file mode 100644index 00000000000..d7a6838e157--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/projects/apiv3-project-paths.ts@@ -0,0 +1,58 @@+// -- 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 {APIv3QueriesPaths} from "core-app/modules/apiv3/endpoints/queries/apiv3-queries-paths";+import {APIv3TypesPaths} from "core-app/modules/apiv3/endpoints/types/apiv3-types-paths";+import {APIV3WorkPackagesPaths} from "core-app/modules/apiv3/endpoints/work_packages/api-v3-work-packages-paths";+import {ProjectResource} from "core-app/modules/hal/resources/project-resource";+import {CachableAPIV3Resource} from "core-app/modules/apiv3/cache/cachable-apiv3-resource";+import {MultiInputState} from "reactivestates";+import {APIv3VersionsPaths} from "core-app/modules/apiv3/endpoints/versions/apiv3-versions-paths";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {APIv3ProjectsPaths} from "core-app/modules/apiv3/endpoints/projects/apiv3-projects-paths";++export class APIv3ProjectPaths extends CachableAPIV3Resource<ProjectResource> {+ // /api/v3/projects/:project_id/available_assignees+ public readonly available_assignees = this.subResource('available_assignees');++ // /api/v3/projects/:project_id/queries+ public readonly queries = new APIv3QueriesPaths(this.apiRoot, this.path);++ // /api/v3/projects/:project_id/types+ public readonly types = new APIv3TypesPaths(this.apiRoot, this.path);++ // /api/v3/projects/:project_id/work_packages+ public readonly work_packages = new APIV3WorkPackagesPaths(this.apiRoot, this.path);++ // /api/v3/projects/:project_id/versions+ public readonly versions = new APIv3VersionsPaths(this.apiRoot, this.path);++ protected createCache():StateCacheService<ProjectResource> {+ return (this.parent as APIv3ProjectsPaths).cache;+ }+}diff --git a/frontend/src/app/modules/apiv3/endpoints/projects/apiv3-projects-paths.ts b/frontend/src/app/modules/apiv3/endpoints/projects/apiv3-projects-paths.tsnew file mode 100644index 00000000000..2f704e93167--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/projects/apiv3-projects-paths.ts@@ -0,0 +1,72 @@+// -- 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 {APIv3ProjectPaths} from "core-app/modules/apiv3/endpoints/projects/apiv3-project-paths";+import {ProjectResource} from "core-app/modules/hal/resources/project-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";+import {+ Apiv3ListParameters,+ Apiv3ListResourceInterface,+ listParamsString+} from "core-app/modules/apiv3/paths/apiv3-list-resource.interface";+import {Observable} from "rxjs";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {CachableAPIV3Collection} from "core-app/modules/apiv3/cache/cachable-apiv3-collection";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {ProjectCache} from "core-app/modules/apiv3/endpoints/projects/project.cache";++export class APIv3ProjectsPaths+ extends CachableAPIV3Collection<ProjectResource, APIv3ProjectPaths>+ implements Apiv3ListResourceInterface<ProjectResource> {+ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'projects', APIv3ProjectPaths);+ }++ // /api/v3/projects/schema+ public readonly schema = this.subResource<SchemaResource>('schema');++ /**+ * Load a list of project with a given list parameter filter+ *+ * @param params+ */+ public list(params?:Apiv3ListParameters):Observable<CollectionResource<ProjectResource>> {+ return this+ .halResourceService+ .get<CollectionResource<ProjectResource>>(this.path + listParamsString(params))+ .pipe(+ this.cacheResponse()+ );+ }++ protected createCache():StateCacheService<ProjectResource> {+ return new ProjectCache(this.injector, this.states.projects);+ }+}diff --git a/frontend/src/app/modules/hal/dm-services/membership-dm.service.ts b/frontend/src/app/modules/apiv3/endpoints/projects/project.cache.tssimilarity index 57%rename from frontend/src/app/modules/hal/dm-services/membership-dm.service.tsrename to frontend/src/app/modules/apiv3/endpoints/projects/project.cache.tsindex 8a65115f296..9b6e2a0907e 100644--- a/frontend/src/app/modules/hal/dm-services/membership-dm.service.ts+++ b/frontend/src/app/modules/apiv3/endpoints/projects/project.cache.ts@@ -1,4 +1,4 @@-//-- copyright+// -- copyright// OpenProject is an open source project management software.// Copyright (C) 2012-2020 the OpenProject GmbH//@@ -24,30 +24,30 @@// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.//// See docs/COPYRIGHT.rdoc for more details.-//+++// ++-import {Injectable} from '@angular/core';-import {AbstractDmService} from "core-app/modules/hal/dm-services/abstract-dm.service";-import {MembershipResource} from "core-app/modules/hal/resources/membership-resource";-import {DmListParameter} from "core-app/modules/hal/dm-services/dm.service.interface";-import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {MultiInputState} from 'reactivestates';+import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';+import {Injectable, Injector} from '@angular/core';+import {debugLog} from "core-app/helpers/debug_output";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";import {ProjectResource} from "core-app/modules/hal/resources/project-resource";@Injectable()-export class MembershipDmService extends AbstractDmService<MembershipResource> {- public listAvailableProjects(params:DmListParameter|null) {- return this.listRequest(this.availableProjectsUrl(), params) as Promise<CollectionResource<ProjectResource>>;- }-- protected listUrl() {- return this.pathHelper.api.v3.memberships.toString();- }+export class ProjectCache extends StateCacheService<ProjectResource> {+ @InjectField() private schemaCacheService:SchemaCacheService;- protected oneUrl(id:number|string) {- return this.pathHelper.api.v3.memberships.id(id).toString();+ constructor(readonly injector:Injector,+ state:MultiInputState<ProjectResource>) {+ super(state);}- protected availableProjectsUrl() {- return this.pathHelper.api.v3.memberships.available_projects.toString();+ updateValue(id:string, val:ProjectResource):Promise<ProjectResource> {+ return this.schemaCacheService.ensureLoaded(val).then(() => {+ this.putValue(id, val);+ return val;+ });}}diff --git a/frontend/src/app/modules/apiv3/endpoints/queries/apiv3-queries-paths.ts b/frontend/src/app/modules/apiv3/endpoints/queries/apiv3-queries-paths.tsnew file mode 100644index 00000000000..1259a9c9ba2--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/queries/apiv3-queries-paths.ts@@ -0,0 +1,158 @@+// -- 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 {APIv3GettableResource, APIv3ResourceCollection} from "core-app/modules/apiv3/paths/apiv3-resource";+import {APIv3QueryPaths} from "core-app/modules/apiv3/endpoints/queries/apiv3-query-paths";+import {QueryResource} from "core-app/modules/hal/resources/query-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {Apiv3QueryForm} from "core-app/modules/apiv3/endpoints/queries/apiv3-query-form";+import {Observable} from "rxjs";+import {QueryFormResource} from "core-app/modules/hal/resources/query-form-resource";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {Apiv3ListParameters, listParamsString} from "core-app/modules/apiv3/paths/apiv3-list-resource.interface";+import {QueryFiltersService} from "core-components/wp-query/query-filters.service";+import {HalPayloadHelper} from "core-app/modules/hal/schemas/hal-payload.helper";++export class APIv3QueriesPaths extends APIv3ResourceCollection<QueryResource, APIv3QueryPaths> {+ @InjectField() private queryFilters:QueryFiltersService;++ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'queries', APIv3QueryPaths);+ }++ // Static paths+ // /api/v3/queries/form+ readonly form = this.subResource('form', Apiv3QueryForm);++ // /api/v3/queries/default+ readonly default = this.subResource<APIv3GettableResource<QueryResource>>('default');++ // /api/v3/queries/filter_instance_schemas/:id+ readonly filter_instance_schemas = new APIv3ResourceCollection(this.apiRoot, this.path, 'filter_instance_schemas');++ /**+ * Load a list of queries with a given list parameter filter+ * @param params+ */+ public list(params?:Apiv3ListParameters):Observable<CollectionResource<QueryResource>> {+ return this+ .halResourceService+ .get<CollectionResource<QueryResource>>(this.path + listParamsString(params));+ }++ /**+ * Locate a query for the response for the given query request.+ * This might be the default query or an existing query identified by its ID.+ * @param queryData+ * @param queryId+ * @param projectIdentifier+ */+ public find(queryData:Object, queryId?:string, projectIdentifier?:string|null|undefined):Observable<QueryResource> {+ let path:string;++ if (queryId) {+ path = this.apiRoot.queries.id(queryId).toString();+ } else {+ path = this.apiRoot.withOptionalProject(projectIdentifier).queries.default.toString();+ }++ return this+ .halResourceService+ .get<QueryResource>(path, queryData);+ }+++ /**+ * Stream the response for the given query request+ *+ * @param params+ */+ public parameterised(params:Object):Observable<QueryResource> {+ return this.halResourceService+ .get<QueryResource>(+ this.default.path,+ params+ );+ }++ /**+ * Create a new query resource+ *+ * @param payload Payload object or query HAL resource+ * @param form Form resource, needed when QueryResource is passed+ */+ public post(payload:QueryResource|Object, form?:QueryFormResource):Observable<QueryResource> {+ if (payload instanceof QueryResource && form) {+ // Extracting requires having the filter schemas loaded as the dependencies+ this.queryFilters.mapSchemasIntoFilters(payload, form);+ payload = HalPayloadHelper.extractPayloadFromSchema(payload, form.schema);+ }++ return this+ .halResourceService+ .post<QueryResource>(+ this.apiRoot.queries.path, payload+ );+ }++ /**+ * Invert the starred state of the given query+ *+ * @param query+ */+ public toggleStarred(query:QueryResource):Promise<unknown> {+ if (query.starred) {+ return query.unstar();+ } else {+ return query.star();+ }+ }++ /**+ * Filter for non-hidden queries+ *+ * @param projectIdentifier+ */+ public filterNonHidden(projectIdentifier?:string|null):Observable<CollectionResource<QueryResource>> {+ let listParams:Apiv3ListParameters = {+ filters: [['hidden', '=', ['f']]]+ };++ if (projectIdentifier) {+ // all queries with the provided projectIdentifier+ listParams.filters!.push(['project_identifier', '=', [projectIdentifier]]);+ } else {+ // all queries having no project (i.e. being global)+ listParams.filters!.push(['project', '!*', []]);+ }++ return this.list(listParams);+ }+}diff --git a/frontend/src/app/modules/hal/dm-services/query-form-dm.service.ts b/frontend/src/app/modules/apiv3/endpoints/queries/apiv3-query-form.tssimilarity index 63%rename from frontend/src/app/modules/hal/dm-services/query-form-dm.service.tsrename to frontend/src/app/modules/apiv3/endpoints/queries/apiv3-query-form.tsindex 74407a9f99b..5d1f1b710fc 100644--- a/frontend/src/app/modules/hal/dm-services/query-form-dm.service.ts+++ b/frontend/src/app/modules/apiv3/endpoints/queries/apiv3-query-form.ts@@ -1,4 +1,4 @@-//-- copyright+// -- copyright// OpenProject is an open source project management software.// Copyright (C) 2012-2020 the OpenProject GmbH//@@ -24,29 +24,25 @@// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.//// See docs/COPYRIGHT.rdoc for more details.-//+++// ++-import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {Injectable} from '@angular/core';-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 {QueryResource} from "core-app/modules/hal/resources/query-resource";+import {APIv3FormResource} from "core-app/modules/apiv3/forms/apiv3-form-resource";+import {QueryFormResource} from "core-app/modules/hal/resources/query-form-resource";+import {Observable} from "rxjs";+import * as URI from "urijs";+import {map, tap} from "rxjs/operators";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";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) {- }+export class Apiv3QueryForm extends APIv3FormResource<QueryFormResource> {+ @InjectField() private queryFilters:QueryFiltersService;/*** Load the query form for the given existing (or new) query resource* @param query*/- public load(query:QueryResource):Promise<QueryFormResource> {+ public load(query:QueryResource):Observable<[QueryFormResource, QueryResource]> {// We need a valid payload so that we// can check whether form saving is possible.// The query needs a name to be valid.@@ -62,7 +58,13 @@ export class QueryFormDmService {};}- return query.$links.update(payload);+ let path = this.apiRoot.queries.withOptionalId(query.id).form.path;+ return this.halResourceService+ .post<QueryFormResource>(path, payload)+ .pipe(+ tap(form => this.queryFilters.setSchemas(form.$embedded.schema.$embedded.filtersSchemas)),+ map(form => [form, this.buildQueryResource(form)])+ );}/**@@ -73,7 +75,7 @@ export class QueryFormDmService {* @param projectIdentifier* @param payload*/- public loadWithParams(params:{[key:string]:unknown}, queryId:string|undefined, projectIdentifier:string|undefined|null, payload:any = {}):Promise<QueryFormResource> {+ public loadWithParams(params:{[key:string]:unknown}, queryId:string|undefined, projectIdentifier:string|undefined|null, payload:any = {}):Observable<[QueryFormResource, QueryResource]> {// We need a valid payload so that we// can check whether form saving is possible.// The query needs a name to be valid.@@ -84,25 +86,22 @@ export class QueryFormDmService {if (projectIdentifier) {payload._links = payload._links || {};payload._links.project = {- 'href': this.pathHelper.api.v3.projects.id(projectIdentifier).toString()+ 'href': this.apiRoot.projects.id(projectIdentifier).toString()};}- let href:string = this.pathHelper.api.v3.queries.optionalId(queryId).form.toString();- href = URI(href).search(params).toString();-+ let path = this.apiRoot.queries.withOptionalId(queryId).form.path;+ const href = URI(path).search(params).toString();return this.halResourceService.post<QueryFormResource>(href, payload)- .toPromise()- .then(form => {- this.queryFilters.setSchemas(form.$embedded.schema.$embedded.filtersSchemas);-- return form;- });+ .pipe(+ tap(form => this.queryFilters.setSchemas(form.$embedded.schema.$embedded.filtersSchemas)),+ map(form => [form, this.buildQueryResource(form)])+ );}- public buildQueryResource(form:QueryFormResource):QueryResource {+ protected buildQueryResource(form:QueryFormResource):QueryResource {return this.halResourceService.createHalResourceOfType<QueryResource>('Query', form.payload);}}diff --git a/frontend/src/app/modules/hal/dm-services/query-order-dm.service.ts b/frontend/src/app/modules/apiv3/endpoints/queries/apiv3-query-order.tssimilarity index 72%rename from frontend/src/app/modules/hal/dm-services/query-order-dm.service.tsrename to frontend/src/app/modules/apiv3/endpoints/queries/apiv3-query-order.tsindex 1110524c6b1..bc7963ccbf2 100644--- a/frontend/src/app/modules/hal/dm-services/query-order-dm.service.ts+++ b/frontend/src/app/modules/apiv3/endpoints/queries/apiv3-query-order.ts@@ -1,4 +1,4 @@-//-- copyright+// -- copyright// OpenProject is an open source project management software.// Copyright (C) 2012-2020 the OpenProject GmbH//@@ -24,33 +24,37 @@// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.//// See docs/COPYRIGHT.rdoc for more details.-//+++// ++-import {Injectable} from '@angular/core';-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';+import {Injector} from "@angular/core";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";import {HttpClient} from "@angular/common/http";+import {SimpleResource} from "core-app/modules/apiv3/paths/path-resources";export type QueryOrder = { [wpId:string]:number };-@Injectable()-export class QueryOrderDmService {- constructor(protected http:HttpClient,- protected pathHelper:PathHelperService) {+export class APIV3QueryOrder extends SimpleResource {+ @InjectField() http:HttpClient;++ constructor(readonly injector:Injector,+ readonly basePath:string,+ readonly id:string|number) {+ super(basePath, id);}- public get(id:string):Promise<QueryOrder> {+ public get():Promise<QueryOrder> {return this.http.get<QueryOrder>(- this.orderPath(id)+ this.path).toPromise().then(result => result || {});}- public update(id:string, delta:QueryOrder):Promise<string> {+ public update(delta:QueryOrder):Promise<string> {return this.http.patch(- this.orderPath(id),+ this.path,{ delta: delta },{ withCredentials: true })@@ -59,13 +63,9 @@ export class QueryOrderDmService {}public delete(id:string, ...wpIds:string[]) {- let delta:QueryOrder = {}+ let delta:QueryOrder = {};wpIds.forEach(id => delta[id] = -1);- return this.update(id, delta);- }-- protected orderPath(id:string) {- return this.pathHelper.api.v3.queries.id(id).order.toString();+ return this.update(delta);}}diff --git a/frontend/src/app/modules/apiv3/endpoints/queries/apiv3-query-paths.ts b/frontend/src/app/modules/apiv3/endpoints/queries/apiv3-query-paths.tsnew file mode 100644index 00000000000..391592c483a--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/queries/apiv3-query-paths.ts@@ -0,0 +1,92 @@+// -- 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 {APIv3GettableResource} from "core-app/modules/apiv3/paths/apiv3-resource";+import {QueryResource} from "core-app/modules/hal/resources/query-resource";+import {APIV3QueryOrder} from "core-app/modules/apiv3/endpoints/queries/apiv3-query-order";+import {Apiv3QueryForm} from "core-app/modules/apiv3/endpoints/queries/apiv3-query-form";+import {Observable} from "rxjs";+import {QueryFormResource} from "core-app/modules/hal/resources/query-form-resource";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {QueryFiltersService} from "core-components/wp-query/query-filters.service";+import {PaginationObject} from "core-components/table-pagination/pagination-service";+import {HalPayloadHelper} from "core-app/modules/hal/schemas/hal-payload.helper";++export class APIv3QueryPaths extends APIv3GettableResource<QueryResource> {+ @InjectField() private queryFilters:QueryFiltersService;++ // Static paths+ readonly form = this.subResource('form', Apiv3QueryForm);++ // Order path+ readonly order = new APIV3QueryOrder(this.injector, this.path, 'order');++ /**+ * Stream the response for the given query request+ * @param queryData+ */+ public parameterised(params:Object):Observable<QueryResource> {+ return this.halResourceService+ .get<QueryResource>(this.path, params);+ }++ /**+ * Update the given query+ * @param query+ * @param form+ */+ public patch(payload:QueryResource|Object, form?:QueryFormResource):Observable<QueryResource> {+ if (payload instanceof QueryResource && form) {+ // Extracting requires having the filter schemas loaded as the dependencies+ this.queryFilters.mapSchemasIntoFilters(payload, form);+ payload = HalPayloadHelper.extractPayloadFromSchema(payload, form.schema);+ }++ return this+ .halResourceService+ .patch<QueryResource>(this.path, payload);+ }++ /**+ * Delete the query+ */+ public delete() {+ return this+ .halResourceService+ .delete(this.path);+ }++ /**+ * Reload with a given pagination+ * @param pagination+ */+ public paginated(pagination:PaginationObject):Observable<QueryResource> {+ return this.parameterised(pagination);+ }++}diff --git a/frontend/src/app/modules/apiv3/endpoints/relations/apiv3-relations-paths.ts b/frontend/src/app/modules/apiv3/endpoints/relations/apiv3-relations-paths.tsnew file mode 100644index 00000000000..b8a461d0e49--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/relations/apiv3-relations-paths.ts@@ -0,0 +1,71 @@+// -- 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 {APIv3GettableResource, APIv3ResourceCollection} from "core-app/modules/apiv3/paths/apiv3-resource";+import {VersionResource} from "core-app/modules/hal/resources/version-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {APIv3FormResource} from "core-app/modules/apiv3/forms/apiv3-form-resource";+import {from, NEVER, Observable} from "rxjs";+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {Apiv3AvailableProjectsPaths} from "core-app/modules/apiv3/endpoints/projects/apiv3-available-projects-paths";+import {APIv3VersionPaths} from "core-app/modules/apiv3/endpoints/versions/apiv3-version-paths";+import {RelationResource} from "core-app/modules/hal/resources/relation-resource";+import {buildApiV3Filter} from "core-components/api/api-v3/api-v3-filter-builder";+import {map} from "rxjs/operators";++export class Apiv3RelationsPaths extends APIv3ResourceCollection<RelationResource, APIv3GettableResource<RelationResource>> {+ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'relations');+ }++ /**+ * Get all versions+ */+ public get():Observable<CollectionResource<RelationResource>> {+ return this+ .halResourceService+ .get<CollectionResource<RelationResource>>(this.path);+ }++ public loadInvolved(workPackageIds:string[]):Observable<RelationResource[]> {+ let validIds = _.filter(workPackageIds, id => /\d+/.test(id));++ if (validIds.length === 0) {+ return from([]);+ }++ return this+ .filtered(buildApiV3Filter('involved', '=', validIds))+ .get()+ .pipe(+ map(collection => collection.elements)+ );+ }+}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/groups/apiv3-groups-path.ts b/frontend/src/app/modules/apiv3/endpoints/statuses/apiv3-status-paths.tssimilarity index 72%rename from frontend/src/app/modules/common/path-helper/apiv3/groups/apiv3-groups-path.tsrename to frontend/src/app/modules/apiv3/endpoints/statuses/apiv3-status-paths.tsindex 7a53caef0f1..9d191e30b93 100644--- a/frontend/src/app/modules/common/path-helper/apiv3/groups/apiv3-groups-path.ts+++ b/frontend/src/app/modules/apiv3/endpoints/statuses/apiv3-status-paths.ts@@ -26,16 +26,13 @@// See docs/COPYRIGHT.rdoc for more details.// ++-import {- SimpleResourceCollection-} from 'core-app/modules/common/path-helper/apiv3/path-resources';+import {StatusResource} from "core-app/modules/hal/resources/status-resource";+import {CachableAPIV3Resource} from "core-app/modules/apiv3/cache/cachable-apiv3-resource";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";-export class Apiv3GroupsPaths extends SimpleResourceCollection {- constructor(basePath:string) {- super(basePath, 'groups');- }+export class APIv3StatusPaths extends CachableAPIV3Resource<StatusResource> {- public toString():string {- throw 'Backend does not yet offer this end point';+ protected createCache():StateCacheService<StatusResource> {+ return new StateCacheService<StatusResource>(this.states.statuses);}}diff --git a/frontend/src/app/modules/hal/dm-services/status-dm.service.ts b/frontend/src/app/modules/apiv3/endpoints/statuses/apiv3-statuses-paths.tssimilarity index 55%rename from frontend/src/app/modules/hal/dm-services/status-dm.service.tsrename to frontend/src/app/modules/apiv3/endpoints/statuses/apiv3-statuses-paths.tsindex 2eafdfe1263..df43e7a0dbe 100644--- a/frontend/src/app/modules/hal/dm-services/status-dm.service.ts+++ b/frontend/src/app/modules/apiv3/endpoints/statuses/apiv3-statuses-paths.ts@@ -1,4 +1,4 @@-//-- copyright+// -- copyright// OpenProject is an open source project management software.// Copyright (C) 2012-2020 the OpenProject GmbH//@@ -24,31 +24,37 @@// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.//// See docs/COPYRIGHT.rdoc for more details.-//+++// ++-import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {Injectable} from '@angular/core';-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';+import {APIv3ResourceCollection, APIv3ResourcePath} from "core-app/modules/apiv3/paths/apiv3-resource";+import {Injector} from "@angular/core";import {StatusResource} from "core-app/modules/hal/resources/status-resource";+import {APIv3StatusPaths} from "core-app/modules/apiv3/endpoints/statuses/apiv3-status-paths";+import {Observable} from "rxjs";import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {tap} from "rxjs/operators";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";-@Injectable()-export class StatusDmService {- constructor(protected halResourceService:HalResourceService,- protected pathHelper:PathHelperService) {+export class APIv3StatusesPaths extends APIv3ResourceCollection<StatusResource, APIv3StatusPaths> {+ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'statuses', APIv3StatusPaths);}- public one(id:string|number):Promise<StatusResource> {- return this.halResourceService- .get<StatusResource>(this.pathHelper.api.v3.statuses.id(id).toString())- .toPromise();+ /**+ * Perform a request to the HalResourceService with the current path+ */+ public get():Observable<CollectionResource<StatusResource>> {+ return this+ .halResourceService+ .get<CollectionResource<StatusResource>>(this.path)+ .pipe(+ tap(collection => {+ collection.elements.forEach((resource, id) => {+ this.id(resource.id!).cache.updateValue(resource.id!, resource);+ });+ })+ );}- public list():Promise<CollectionResource<StatusResource>> {- return this.halResourceService- .get<CollectionResource<StatusResource>>(this.pathHelper.api.v3.statuses.toString())- .toPromise();- }--}diff --git a/frontend/src/app/modules/apiv3/endpoints/time-entries/apiv3-time-entries-paths.ts b/frontend/src/app/modules/apiv3/endpoints/time-entries/apiv3-time-entries-paths.tsnew file mode 100644index 00000000000..17badf43199--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/time-entries/apiv3-time-entries-paths.ts@@ -0,0 +1,86 @@+// -- 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 {Apiv3TimeEntryPaths} from "core-app/modules/apiv3/endpoints/time-entries/apiv3-time-entry-paths";+import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {APIv3FormResource} from "core-app/modules/apiv3/forms/apiv3-form-resource";+import {Observable} from "rxjs";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {CachableAPIV3Collection} from "core-app/modules/apiv3/cache/cachable-apiv3-collection";+import {MultiInputState} from "reactivestates";+import {+ Apiv3ListParameters,+ Apiv3ListResourceInterface,+ listParamsString+} from "core-app/modules/apiv3/paths/apiv3-list-resource.interface";+import {TimeEntryCacheService} from "core-app/modules/apiv3/endpoints/time-entries/time-entry-cache.service";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";++export class Apiv3TimeEntriesPaths+ extends CachableAPIV3Collection<TimeEntryResource, Apiv3TimeEntryPaths>+ implements Apiv3ListResourceInterface<TimeEntryResource> {+ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'time_entries', Apiv3TimeEntryPaths);+ }++ // Static paths+ public readonly form = this.subResource('form', APIv3FormResource);++ /**+ * Load a list of time entries with a given list parameter filter+ * @param params+ */+ public list(params?:Apiv3ListParameters):Observable<CollectionResource<TimeEntryResource>> {+ return this+ .halResourceService+ .get<CollectionResource<TimeEntryResource>>(this.path + listParamsString(params))+ .pipe(+ this.cacheResponse()+ );+ }++ /**+ * Create a time entry resource from the given payload+ * @param payload+ */+ public post(payload:Object):Observable<TimeEntryResource> {+ return this+ .halResourceService+ .post<TimeEntryResource>(this.path, payload)+ .pipe(+ this.cacheResponse()+ );+ }++ protected createCache():StateCacheService<TimeEntryResource> {+ return new TimeEntryCacheService(this.injector, this.states.timeEntries);+ }+}diff --git a/frontend/src/app/modules/apiv3/endpoints/time-entries/apiv3-time-entry-paths.ts b/frontend/src/app/modules/apiv3/endpoints/time-entries/apiv3-time-entry-paths.tsnew file mode 100644index 00000000000..ffdc528b52a--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/time-entries/apiv3-time-entry-paths.ts@@ -0,0 +1,94 @@+// -- 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 {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";+import {CachableAPIV3Resource} from "core-app/modules/apiv3/cache/cachable-apiv3-resource";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {MultiInputState} from "reactivestates";+import {APIv3FormResource} from "core-app/modules/apiv3/forms/apiv3-form-resource";+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {Observable} from "rxjs";+import {tap} from "rxjs/operators";+import {Apiv3TimeEntriesPaths} from "core-app/modules/apiv3/endpoints/time-entries/apiv3-time-entries-paths";+import {HalPayloadHelper} from "core-app/modules/hal/schemas/hal-payload.helper";++export class Apiv3TimeEntryPaths extends CachableAPIV3Resource<TimeEntryResource> {+ // Static paths+ readonly form = this.subResource('form', APIv3FormResource);++ /**+ * Update the time entry with the given payload.+ *+ * In case of updating from the hal resource, a schema resource is needed+ * to identify the writable attributes.+ * @param payload+ * @param schema+ */+ public patch(payload:Object, schema:SchemaResource|null = null):Observable<TimeEntryResource> {+ return this+ .halResourceService+ .patch<TimeEntryResource>(this.path, this.extractPayload(payload, schema))+ .pipe(+ tap(resource => this.touch(resource))+ );+ }++ /**+ * Delete the time entry under the current path+ */+ public delete():Observable<unknown> {+ return this+ .halResourceService+ .delete<TimeEntryResource>(this.path)+ .pipe(+ tap(() => this.cache.clearSome(this.id.toString()))+ );+ }++ protected createCache():StateCacheService<TimeEntryResource> {+ return (this.parent as Apiv3TimeEntriesPaths).cache;+ }++ /**+ * Extract payload from the given request with schema.+ * This will ensure we will only write writable attributes and so on.+ *+ * @param resource+ * @param schema+ */+ protected extractPayload(resource:HalResource|Object|null, schema:SchemaResource|null = null) {+ if (resource instanceof HalResource && schema) {+ return HalPayloadHelper.extractPayloadFromSchema(resource, schema);+ } else if (!(resource instanceof HalResource)) {+ return resource;+ } else {+ return {};+ }+ }+}diff --git a/frontend/src/app/components/time-entries/time-entry-cache.service.ts b/frontend/src/app/modules/apiv3/endpoints/time-entries/time-entry-cache.service.tssimilarity index 56%rename from frontend/src/app/components/time-entries/time-entry-cache.service.tsrename to frontend/src/app/modules/apiv3/endpoints/time-entries/time-entry-cache.service.tsindex fc9e70ba84b..016265abaa7 100644--- a/frontend/src/app/components/time-entries/time-entry-cache.service.ts+++ b/frontend/src/app/modules/apiv3/endpoints/time-entries/time-entry-cache.service.ts@@ -26,46 +26,28 @@// See doc/COPYRIGHT.rdoc for more details.// ++-import {MultiInputState} from 'reactivestates';-import {States} from '../states.service';-import {StateCacheService} from '../states/state-cache.service';-import {Injectable} from '@angular/core';-import {SchemaCacheService} from "core-components/schemas/schema-cache.service";import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";-import {TimeEntryDmService} from "core-app/modules/hal/dm-services/time-entry-dm.service";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import {States} from "core-components/states.service";+import {Injector} from "@angular/core";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {MultiInputState} from "reactivestates";-@Injectable({ providedIn: 'root' })export class TimeEntryCacheService extends StateCacheService<TimeEntryResource> {+ @InjectField() readonly states:States;+ @InjectField() readonly schemaCache:SchemaCacheService;- constructor(readonly states:States,- readonly schemaCacheService:SchemaCacheService,- readonly timeEntryDm:TimeEntryDmService) {- super();+ constructor(readonly injector:Injector, state:MultiInputState<TimeEntryResource>) {+ super(state);}- protected loadAll(ids:string[]):Promise<undefined> {- return Promise- .all(ids.map(id => this.load(id)))- .then(_ => undefined);- }-- updateValue(id:string, val:TimeEntryResource) {- this.schemaCacheService.ensureLoaded(val).then(() => {- super.updateValue(id, val);- });- }-- protected load(id:string):Promise<TimeEntryResource> {- return this- .timeEntryDm- .one(parseInt(id))- .then((timeEntry) => {- return this.schemaCacheService.ensureLoaded(timeEntry).then(() => timeEntry);+ updateValue(id:string, val:TimeEntryResource):Promise<TimeEntryResource> {+ return this.schemaCache+ .ensureLoaded(val)+ .then(() => {+ this.putValue(id, val);+ return val;});}-- protected get multiState():MultiInputState<TimeEntryResource> {- return this.states.timeEntries;- }-}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/grids/apiv3-grids-paths.ts b/frontend/src/app/modules/apiv3/endpoints/types/apiv3-type-paths.tssimilarity index 70%rename from frontend/src/app/modules/common/path-helper/apiv3/grids/apiv3-grids-paths.tsrename to frontend/src/app/modules/apiv3/endpoints/types/apiv3-type-paths.tsindex 57f65a19313..ef5b0e45fcb 100644--- a/frontend/src/app/modules/common/path-helper/apiv3/grids/apiv3-grids-paths.ts+++ b/frontend/src/app/modules/apiv3/endpoints/types/apiv3-type-paths.ts@@ -26,22 +26,14 @@// See docs/COPYRIGHT.rdoc for more details.// ++-import {- SimpleResource,- SimpleResourceCollection-} from 'core-app/modules/common/path-helper/apiv3/path-resources';-import {Apiv3GridPaths} from "core-app/modules/common/path-helper/apiv3/grids/apiv3-grid-paths";+import {TypeResource} from "core-app/modules/hal/resources/type-resource";+import {CachableAPIV3Resource} from "core-app/modules/apiv3/cache/cachable-apiv3-resource";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {APIv3TypesPaths} from "core-app/modules/apiv3/endpoints/types/apiv3-types-paths";-export class Apiv3GridsPaths extends SimpleResourceCollection {- constructor(basePath:string) {- super(basePath, 'grids');- }-- public id(gridId:string|number) {- return new Apiv3GridPaths(this.path, gridId);- }+export class APIv3TypePaths extends CachableAPIV3Resource<TypeResource> {- public form() {- return new SimpleResource(this.path, 'form');+ protected createCache():StateCacheService<TypeResource> {+ return (this.parent as APIv3TypesPaths).cache;}}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/news/apiv3-newses-paths.ts b/frontend/src/app/modules/apiv3/endpoints/types/apiv3-types-paths.tssimilarity index 59%rename from frontend/src/app/modules/common/path-helper/apiv3/news/apiv3-newses-paths.tsrename to frontend/src/app/modules/apiv3/endpoints/types/apiv3-types-paths.tsindex a74f4abe187..f979b2f565c 100644--- a/frontend/src/app/modules/common/path-helper/apiv3/news/apiv3-newses-paths.ts+++ b/frontend/src/app/modules/apiv3/endpoints/types/apiv3-types-paths.ts@@ -26,17 +26,20 @@// See docs/COPYRIGHT.rdoc for more details.// ++-import {- SimpleResourceCollection-} from 'core-app/modules/common/path-helper/apiv3/path-resources';-import {Apiv3NewsPaths} from "core-app/modules/common/path-helper/apiv3/news/apiv3-news-paths";+import {APIv3ResourceCollection} from "core-app/modules/apiv3/paths/apiv3-resource";+import {TypeResource} from "core-app/modules/hal/resources/type-resource";+import {APIv3TypePaths} from "core-app/modules/apiv3/endpoints/types/apiv3-type-paths";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {CachableAPIV3Collection} from "core-app/modules/apiv3/cache/cachable-apiv3-collection";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";-export class Apiv3NewsesPaths extends SimpleResourceCollection {- constructor(basePath:string) {- super(basePath, 'news');+export class APIv3TypesPaths extends CachableAPIV3Collection<TypeResource, APIv3TypePaths> {+ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'types', APIv3TypePaths);}- public id(gridId:string|number) {- return new Apiv3NewsPaths(this.path, gridId);+ protected createCache():StateCacheService<TypeResource> {+ return new StateCacheService<TypeResource>(this.states.types);}}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/users/apiv3-user-paths.ts b/frontend/src/app/modules/apiv3/endpoints/users/apiv3-user-paths.tssimilarity index 69%rename from frontend/src/app/modules/common/path-helper/apiv3/users/apiv3-user-paths.tsrename to frontend/src/app/modules/apiv3/endpoints/users/apiv3-user-paths.tsindex f4add192ff7..5dab1cd1ef0 100644--- a/frontend/src/app/modules/common/path-helper/apiv3/users/apiv3-user-paths.ts+++ b/frontend/src/app/modules/apiv3/endpoints/users/apiv3-user-paths.ts@@ -26,14 +26,16 @@// See docs/COPYRIGHT.rdoc for more details.// ++-import {SimpleResource} from 'core-app/modules/common/path-helper/apiv3/path-resources';+import {UserResource} from "core-app/modules/hal/resources/user-resource";+import {MultiInputState} from "reactivestates";+import {CachableAPIV3Resource} from "core-app/modules/apiv3/cache/cachable-apiv3-resource";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";-export class ApiV3UserPaths extends SimpleResource {- constructor(basePath:string, readonly userId:string|number) {- super(basePath, userId);- }+export class APIv3UserPaths extends CachableAPIV3Resource<UserResource> {- // /api/v3/users/(:userId)/avatar- public readonly avatar = this.path + '/avatar';+ readonly avatar = this.subResource('avatar');+ protected createCache():StateCacheService<UserResource> {+ return new StateCacheService<UserResource>(this.states.users);+ }}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/users/apiv3-users-paths.ts b/frontend/src/app/modules/apiv3/endpoints/users/apiv3-users-paths.tssimilarity index 70%rename from frontend/src/app/modules/common/path-helper/apiv3/users/apiv3-users-paths.tsrename to frontend/src/app/modules/apiv3/endpoints/users/apiv3-users-paths.tsindex ba2ea5d2bd9..439b5cb147d 100644--- a/frontend/src/app/modules/common/path-helper/apiv3/users/apiv3-users-paths.ts+++ b/frontend/src/app/modules/apiv3/endpoints/users/apiv3-users-paths.ts@@ -26,23 +26,19 @@// See docs/COPYRIGHT.rdoc for more details.// ++-import {- SimpleResourceCollection-} from 'core-app/modules/common/path-helper/apiv3/path-resources';-import {ApiV3UserPaths} from "core-app/modules/common/path-helper/apiv3/users/apiv3-user-paths";+import {APIv3ResourceCollection} from "core-app/modules/apiv3/paths/apiv3-resource";+import {APIv3UserPaths} from "core-app/modules/apiv3/endpoints/users/apiv3-user-paths";+import {UserResource} from "core-app/modules/hal/resources/user-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";-export class Apiv3UsersPaths extends SimpleResourceCollection {- constructor(basePath:string) {- super(basePath, 'users');+export class Apiv3UsersPaths extends APIv3ResourceCollection<UserResource, APIv3UserPaths> {+ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'users', APIv3UserPaths);}// Static paths// /api/v3/users/mepublic readonly me = this.path + '/me';-- // /api/v3/users/:userId- public id(userId:string|number) {- return new ApiV3UserPaths(this.path, userId);- }}diff --git a/frontend/src/app/components/versions/version-cache.service.ts b/frontend/src/app/modules/apiv3/endpoints/versions/apiv3-version-paths.tssimilarity index 62%rename from frontend/src/app/components/versions/version-cache.service.tsrename to frontend/src/app/modules/apiv3/endpoints/versions/apiv3-version-paths.tsindex ef237a59996..ebee3329e33 100644--- a/frontend/src/app/components/versions/version-cache.service.ts+++ b/frontend/src/app/modules/apiv3/endpoints/versions/apiv3-version-paths.ts@@ -25,30 +25,35 @@//// See docs/COPYRIGHT.rdoc for more details.// ++-import {MultiInputState} from "reactivestates";-import {Injectable} from '@angular/core';-import {StateCacheService} from 'core-components/states/state-cache.service';-import {States} from 'core-components/states.service';-import {VersionResource} from "core-app/modules/hal/resources/version-resource";-import {VersionDmService} from "core-app/modules/hal/dm-services/version-dm.service";-@Injectable({ providedIn: 'root' })-export class VersionCacheService extends StateCacheService<VersionResource> {-- constructor(readonly states:States,- readonly versionDm:VersionDmService) {- super();- }+import {VersionResource} from "core-app/modules/hal/resources/version-resource";+import {Observable} from "rxjs";+import {CachableAPIV3Resource} from "core-app/modules/apiv3/cache/cachable-apiv3-resource";+import {MultiInputState} from "reactivestates";+import {tap} from "rxjs/operators";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";- protected load(id:number|string):Promise<VersionResource> {- return this.versionDm.one(id);- }+export class APIv3VersionPaths extends CachableAPIV3Resource<VersionResource> {- protected loadAll(ids:string[]):Promise<unknown> {- return this.versionDm.list();+ /**+ * Update a version resource with the given payload+ *+ * @param resource+ * @param payload+ */+ public patch(payload:Object):Observable<VersionResource> {+ return this+ .halResourceService+ .patch<VersionResource>(+ this.path,+ payload+ )+ .pipe(+ tap(version => this.touch(version))+ );}- protected get multiState():MultiInputState<VersionResource> {- return this.states.versions;+ protected createCache():StateCacheService<VersionResource> {+ return new StateCacheService<VersionResource>(this.states.versions);}}diff --git a/frontend/src/app/modules/apiv3/endpoints/versions/apiv3-versions-paths.ts b/frontend/src/app/modules/apiv3/endpoints/versions/apiv3-versions-paths.tsnew file mode 100644index 00000000000..bb1ba489817--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/versions/apiv3-versions-paths.ts@@ -0,0 +1,70 @@+// -- 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 {APIv3GettableResource, APIv3ResourceCollection} from "core-app/modules/apiv3/paths/apiv3-resource";+import {VersionResource} from "core-app/modules/hal/resources/version-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {APIv3FormResource} from "core-app/modules/apiv3/forms/apiv3-form-resource";+import {Observable} from "rxjs";+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {Apiv3AvailableProjectsPaths} from "core-app/modules/apiv3/endpoints/projects/apiv3-available-projects-paths";+import {APIv3VersionPaths} from "core-app/modules/apiv3/endpoints/versions/apiv3-version-paths";++export class APIv3VersionsPaths extends APIv3ResourceCollection<VersionResource, APIv3VersionPaths> {+ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'versions', APIv3VersionPaths);+ }++ // /api/v3/versions/form+ public readonly form = this.subResource('form', APIv3FormResource);++ public readonly available_projects = this.subResource('available_projects', Apiv3AvailableProjectsPaths);++ /**+ * Get all versions+ */+ public get():Observable<CollectionResource<VersionResource>> {+ return this+ .halResourceService+ .get<CollectionResource<VersionResource>>(this.path);+ }++ /**+ * Create a version from the given payload+ *+ * @param payload+ * @return {Promise<WorkPackageResource>}+ */+ public post(payload:Object):Observable<VersionResource> {+ return this+ .halResourceService+ .post<VersionResource>(this.path, payload);+ }+}diff --git a/frontend/src/app/modules/apiv3/endpoints/work_packages/api-v3-work-package-cached-subresource.ts b/frontend/src/app/modules/apiv3/endpoints/work_packages/api-v3-work-package-cached-subresource.tsnew file mode 100644index 00000000000..d37258e1c81--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/work_packages/api-v3-work-package-cached-subresource.ts@@ -0,0 +1,55 @@+// -- 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 {APIv3GettableResource, APIv3ResourcePath} from "core-app/modules/apiv3/paths/apiv3-resource";+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";+import {Apiv3RelationsPaths} from "core-app/modules/apiv3/endpoints/relations/apiv3-relations-paths";+import {WorkPackageCollectionResource} from "core-app/modules/hal/resources/wp-collection-resource";+import {Observable} from "rxjs";+import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder";+import {CachableAPIV3Resource} from "core-app/modules/apiv3/cache/cachable-apiv3-resource";+import {APIV3WorkPackagesPaths} from "core-app/modules/apiv3/endpoints/work_packages/api-v3-work-packages-paths";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {tap} from "rxjs/operators";+import {WorkPackageCache} from "core-app/modules/apiv3/endpoints/work_packages/work-package.cache";++export class ApiV3WorkPackageCachedSubresource extends APIv3ResourcePath<WorkPackageCollectionResource> {++ public get() {+ return this+ .halResourceService+ .get(this.path)+ .pipe(+ tap(collection => this.cache.updateWorkPackageList(collection.elements))+ );+ }++ protected get cache():WorkPackageCache {+ return (this.parent as APIV3WorkPackagesPaths).cache;+ }+}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/work_packages/apiv3-work-package-paths.ts b/frontend/src/app/modules/apiv3/endpoints/work_packages/api-v3-work-package-paths.tssimilarity index 53%rename from frontend/src/app/modules/common/path-helper/apiv3/work_packages/apiv3-work-package-paths.tsrename to frontend/src/app/modules/apiv3/endpoints/work_packages/api-v3-work-package-paths.tsindex 5c884bca50e..99fb93d6082 100644--- a/frontend/src/app/modules/common/path-helper/apiv3/work_packages/apiv3-work-package-paths.ts+++ b/frontend/src/app/modules/apiv3/endpoints/work_packages/api-v3-work-package-paths.ts@@ -26,26 +26,34 @@// See docs/COPYRIGHT.rdoc for more details.// ++-import {SimpleResource} from 'core-app/modules/common/path-helper/apiv3/path-resources';--export class ApiV3WorkPackagePaths extends SimpleResource {- constructor(basePath:string, readonly workPackageId:string|number) {- super(basePath, workPackageId);- }+import {APIv3GettableResource, APIv3ResourcePath} from "core-app/modules/apiv3/paths/apiv3-resource";+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";+import {Apiv3RelationsPaths} from "core-app/modules/apiv3/endpoints/relations/apiv3-relations-paths";+import {WorkPackageCollectionResource} from "core-app/modules/hal/resources/wp-collection-resource";+import {Observable} from "rxjs";+import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder";+import {CachableAPIV3Resource} from "core-app/modules/apiv3/cache/cachable-apiv3-resource";+import {APIV3WorkPackagesPaths} from "core-app/modules/apiv3/endpoints/work_packages/api-v3-work-packages-paths";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";++export class APIV3WorkPackagePaths extends CachableAPIV3Resource<WorkPackageResource> {// /api/v3/(?:projectPath)/work_packages/(:workPackageId)/relations- public readonly relations = this.path + '/relations';+ public readonly relations = this.subResource('relations', Apiv3RelationsPaths);// /api/v3/(?:projectPath)/work_packages/(:workPackageId)/revisions- public readonly revisions = this.path + '/revisions';+ public readonly revisions = this.subResource('revisions');// /api/v3/(?:projectPath)/work_packages/(:workPackageId)/activities- public readonly activities = this.path + '/activities';+ public readonly activities = this.subResource('activities');// /api/v3/(?:projectPath)/work_packages/(:workPackageId)/available_watchers- public readonly available_watchers = this.path + '/available_watchers';+ public readonly available_watchers = this.subResource('available_watchers');// /api/v3/(?:projectPath)/work_packages/(:workPackageId)/available_projects- public readonly available_projects = this.path + '/available_projects';+ public readonly available_projects = this.subResource('available_projects');+ protected createCache():StateCacheService<WorkPackageResource> {+ return (this.parent as APIV3WorkPackagesPaths).cache;+ }}diff --git a/frontend/src/app/modules/apiv3/endpoints/work_packages/api-v3-work-packages-paths.ts b/frontend/src/app/modules/apiv3/endpoints/work_packages/api-v3-work-packages-paths.tsnew file mode 100644index 00000000000..be26f779f6e--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/work_packages/api-v3-work-packages-paths.ts@@ -0,0 +1,166 @@+// -- 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 {APIV3WorkPackagePaths} from "core-app/modules/apiv3/endpoints/work_packages/api-v3-work-package-paths";+import {ApiV3FilterBuilder, buildApiV3Filter} from "core-components/api/api-v3/api-v3-filter-builder";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";+import {WorkPackageCollectionResource} from "core-app/modules/hal/resources/wp-collection-resource";+import {Observable} from "rxjs";+import {APIv3WorkPackageForm} from "core-app/modules/apiv3/endpoints/work_packages/apiv3-work-package-form";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {CachableAPIV3Collection} from "core-app/modules/apiv3/cache/cachable-apiv3-collection";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";+import {WorkPackageCache} from "core-app/modules/apiv3/endpoints/work_packages/work-package.cache";+import {APIv3GettableResource} from "core-app/modules/apiv3/paths/apiv3-resource";+import {ApiV3WorkPackageCachedSubresource} from "core-app/modules/apiv3/endpoints/work_packages/api-v3-work-package-cached-subresource";++export class APIV3WorkPackagesPaths extends CachableAPIV3Collection<WorkPackageResource, APIV3WorkPackagePaths, WorkPackageCache> {+ // Base path+ public readonly path:string;++ constructor(readonly apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'work_packages', APIV3WorkPackagePaths);+ }++ // Static paths++ // /api/v3/(projects/:projectIdentifier)/work_packages/form+ public readonly form:APIv3WorkPackageForm = this.subResource('form', APIv3WorkPackageForm);++ /**+ *+ * Load a collection of work packages and put them all into cache+ *+ * @param ids+ */+ public requireAll(ids:string[]):Promise<unknown> {+ return new Promise<undefined>((resolve, reject) => {+ this+ .loadCollectionsFor(_.uniq(ids))+ .then((pagedResults:WorkPackageCollectionResource[]) => {+ _.each(pagedResults, (results) => {+ if (results.schemas) {+ _.each(results.schemas.elements, (schema:SchemaResource) => {+ this.states.schemas.get(schema.href as string).putValue(schema);+ });+ }++ if (results.elements) {+ this.cache.updateWorkPackageList(results.elements);+ }++ });++ resolve(undefined);+ }, reject);+ });+ }++ /**+ * Create a work package from a form payload+ *+ * @param payload+ * @return {Promise<WorkPackageResource>}+ */+ public post(payload:Object):Observable<WorkPackageResource> {+ return this+ .halResourceService+ .post<WorkPackageResource>(this.path, payload)+ .pipe(+ this.cacheResponse()+ );+ }++ /**+ * Shortcut to filter work packages by subject or ID+ * @param term+ * @param idOnly+ */+ public filterBySubjectOrId(term:string, idOnly:boolean = false):ApiV3WorkPackageCachedSubresource {+ let filters:ApiV3FilterBuilder = new ApiV3FilterBuilder();++ if (idOnly) {+ filters.add('id', '=', [term]);+ } else {+ filters.add('subjectOrId', '**', [term]);+ }++ let params = {+ sortBy: '[["updatedAt","desc"]]',+ offset: '1',+ pageSize: '10'+ };++ return this.filtered(filters, params, ApiV3WorkPackageCachedSubresource);+ }++ /**+ * Returns work packages within the ids array to be updated since <timestamp>+ * @param ids work package IDs to filter for+ * @param timestamp The timestamp to clip at+ */+ public filterUpdatedSince(ids:(string|null)[], timestamp:unknown):ApiV3WorkPackageCachedSubresource {+ let filters = new ApiV3FilterBuilder()+ .add('id', '=', ids.filter((n:String|null) => n)) // no null values+ .add('updatedAt', '<>d', [timestamp, '']);++ let params = {+ offset: '1',+ pageSize: '10'+ };++ return this+ .filtered(filters, params, ApiV3WorkPackageCachedSubresource);+ }++ /**+ * Loads the work packages collection for the given work package IDs.+ * Returns a WP Collection with schemas and results embedded.+ *+ * @param ids+ * @return {WorkPackageCollectionResource[]}+ */+ protected loadCollectionsFor(ids:string[]):Promise<WorkPackageCollectionResource[]> {+ return this+ .halResourceService+ .getAllPaginated<WorkPackageCollectionResource[]>(+ this.path,+ ids.length,+ {+ filters: buildApiV3Filter('id', '=', ids).toJson(),+ }+ );+ }++ protected createCache():WorkPackageCache {+ return new WorkPackageCache(this.injector, this.states.workPackages);+ }+}diff --git a/frontend/src/app/modules/apiv3/endpoints/work_packages/apiv3-work-package-form.ts b/frontend/src/app/modules/apiv3/endpoints/work_packages/apiv3-work-package-form.tsnew file mode 100644index 00000000000..b5bb7534d1f--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/work_packages/apiv3-work-package-form.ts@@ -0,0 +1,21 @@+import {APIv3FormResource} from "core-app/modules/apiv3/forms/apiv3-form-resource";+import {FormResource} from "core-app/modules/hal/resources/form-resource";+import {Observable} from "rxjs";++export class APIv3WorkPackageForm extends APIv3FormResource {+ /**+ * Returns a promise to post `/api/v3/work_packages/form` where the+ * type has already been set to the one provided.+ *+ * @param typeId: The id of the type to initialize the form with+ * @returns An empty work package form resource.+ */+ public forType(typeId:number):Observable<FormResource> {++ const typeUrl = this.apiRoot.types.id(typeId).path;+ const request = { _links: { type: { href: typeUrl } } };++ return this.post(request);+ }+}+diff --git a/frontend/src/app/components/work-packages/work-package-cache.service.spec.ts b/frontend/src/app/modules/apiv3/endpoints/work_packages/work-package-cache.spec.tssimilarity index 76%rename from frontend/src/app/components/work-packages/work-package-cache.service.spec.tsrename to frontend/src/app/modules/apiv3/endpoints/work_packages/work-package-cache.spec.tsindex 7a07b832463..6c342ac97e4 100644--- a/frontend/src/app/components/work-packages/work-package-cache.service.spec.ts+++ b/frontend/src/app/modules/apiv3/endpoints/work_packages/work-package-cache.spec.ts@@ -37,20 +37,18 @@ import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.serimport {OpenProjectFileUploadService} from 'core-components/api/op-file-upload/op-file-upload.service';import {SchemaCacheService} from 'core-components/schemas/schema-cache.service';import {States} from 'core-components/states.service';-import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";import {take, takeWhile} from 'rxjs/operators';-import {WorkPackageCreateService} from '../wp-new/wp-create.service';-import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";import {WorkPackagesActivityService} from "core-components/wp-single-view-tabs/activity-panel/wp-activity.service";import {TimezoneService} from "core-components/datetime/timezone.service";import {ConfigurationService} from "core-app/modules/common/config/configuration.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";+import {WorkPackageCache} from "core-app/modules/apiv3/endpoints/work_packages/work-package.cache";-describe('WorkPackageCacheService', () => {+describe('WorkPackageCache', () => {let injector:Injector;- let wpCacheService:WorkPackageCacheService;- let workPackageDmService:WorkPackageDmService;+ let states:States;+ let workPackageCache:WorkPackageCache;let schemaCacheService:SchemaCacheService;let dummyWorkPackages:WorkPackageResource[] = [];@@ -64,14 +62,11 @@ describe('WorkPackageCacheService', () => {HalResourceService,TimezoneService,WorkPackagesActivityService,- WorkPackageCacheService,SchemaCacheService,- WorkPackageDmService,+ PathHelperService,{provide: ConfigurationService, useValue: {}},- {provide: PathHelperService, useValue: {}},{provide: I18nService, useValue: {t: (...args:any[]) => 'translation'}},{provide: WorkPackageResource, useValue: {}},- {provide: WorkPackageCreateService, useValue: {}},{provide: NotificationsService, useValue: {}},{provide: HalResourceNotificationService, useValue: {handleRawError: () => false}},{provide: WorkPackageNotificationService, useValue: {}},@@ -79,13 +74,10 @@ describe('WorkPackageCacheService', () => {]});- injector = TestBed.get(Injector);- wpCacheService = TestBed.get(WorkPackageCacheService);- schemaCacheService = TestBed.get(SchemaCacheService);- workPackageDmService = TestBed.get(WorkPackageDmService);-- // sinon.stub(WorkPackageDmService, 'loadWorkPackageById').returns(Promise.resolve(true));- spyOn(workPackageDmService, 'loadWorkPackageById').and.returnValue(Promise.resolve(true as any));+ injector = TestBed.inject(Injector);+ states = TestBed.inject(States);+ schemaCacheService = TestBed.inject(SchemaCacheService);+ workPackageCache = new WorkPackageCache(injector, states.workPackages);// sinon.stub(schemaCacheService, 'ensureLoaded').returns(Promise.resolve(true));spyOn(schemaCacheService, 'ensureLoaded').and.returnValue(Promise.resolve(true as any));@@ -108,7 +100,7 @@ describe('WorkPackageCacheService', () => {});it('returns a work package after the list has been initialized', function (done:any) {- wpCacheService.loadWorkPackage('1').values$()+ workPackageCache.state('1').values$().pipe(take(1))@@ -117,13 +109,13 @@ describe('WorkPackageCacheService', () => {done();});- wpCacheService.updateWorkPackageList(dummyWorkPackages);+ workPackageCache.updateWorkPackageList(dummyWorkPackages);});it('should return/stream a work package every time it gets updated', (done:any) => {let count = 0;- wpCacheService.loadWorkPackage('1').values$()+ workPackageCache.state('1').values$().pipe(takeWhile((wp) => count < 2))@@ -136,9 +128,9 @@ describe('WorkPackageCacheService', () => {}});- wpCacheService.updateWorkPackageList([dummyWorkPackages[0]], false);- wpCacheService.updateWorkPackageList([dummyWorkPackages[0]], false);- wpCacheService.updateWorkPackageList([dummyWorkPackages[0]], false);+ workPackageCache.updateWorkPackageList([dummyWorkPackages[0]], false);+ workPackageCache.updateWorkPackageList([dummyWorkPackages[0]], false);+ workPackageCache.updateWorkPackageList([dummyWorkPackages[0]], false);});});diff --git a/frontend/src/app/modules/apiv3/endpoints/work_packages/work-package.cache.ts b/frontend/src/app/modules/apiv3/endpoints/work_packages/work-package.cache.tsnew file mode 100644index 00000000000..0aa981a11c9--- /dev/null+++ b/frontend/src/app/modules/apiv3/endpoints/work_packages/work-package.cache.ts@@ -0,0 +1,86 @@+// -- 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 {MultiInputState} from 'reactivestates';+import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';+import {Injectable, Injector} from '@angular/core';+import {debugLog} from "core-app/helpers/debug_output";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {SchemaCacheService} from "core-components/schemas/schema-cache.service";++@Injectable()+export class WorkPackageCache extends StateCacheService<WorkPackageResource> {+ @InjectField() private schemaCacheService:SchemaCacheService;++ constructor(readonly injector:Injector,+ state:MultiInputState<WorkPackageResource>) {+ super(state);+ }++ updateValue(id:string, val:WorkPackageResource):Promise<WorkPackageResource> {+ return this.schemaCacheService.ensureLoaded(val).then(() => {+ this.putValue(id, val);+ return val;+ });+ }++ updateWorkPackage(wp:WorkPackageResource, immediate:boolean = false):Promise<WorkPackageResource> {+ if (immediate || wp.isNew) {+ return super.updateValue(wp.id!, wp);+ } else {+ return this.updateValue(wp.id!, wp);+ }+ }++ updateWorkPackageList(list:WorkPackageResource[], skipOnIdentical = true) {+ for (var i of list) {+ const wp = i;+ const workPackageId = wp.id!;+ const state = this.multiState.get(workPackageId);++ // If the work package is new, ignore the schema+ if (wp.isNew) {+ state.putValue(wp);+ continue;+ }++ // Ensure the schema is loaded+ // so that no consumer needs to call schema#$load manually+ this.schemaCacheService.ensureLoaded(wp).then(() => {+ // Check if the work package has changed+ if (skipOnIdentical && state.hasValue() && _.isEqual(state.value!.$source, wp.$source)) {+ debugLog('Skipping identical work package from updating');+ return;+ }++ state.putValue(wp);+ });+ }+ }+}diff --git a/frontend/src/app/modules/apiv3/forms/apiv3-form-resource.ts b/frontend/src/app/modules/apiv3/forms/apiv3-form-resource.tsnew file mode 100644index 00000000000..f487de21e9b--- /dev/null+++ b/frontend/src/app/modules/apiv3/forms/apiv3-form-resource.ts@@ -0,0 +1,30 @@+import {APIv3ResourcePath} from "core-app/modules/apiv3/paths/apiv3-resource";+import {FormResource} from "core-app/modules/hal/resources/form-resource";+import {Observable} from "rxjs";+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";+import {HalPayloadHelper} from "core-app/modules/hal/schemas/hal-payload.helper";++export class APIv3FormResource<T extends FormResource = FormResource> extends APIv3ResourcePath<T> {+ /**+ * POST to the form resource identified by this path+ * @param request The request payload+ */+ public post(request:Object = {}, schema:SchemaResource|null = null):Observable<T> {+ return this+ .halResourceService+ .post<T>(+ this.path,+ this.extractPayload(request, schema)+ );+ }++ /**+ * Extract payload for the form from the request and optional schema.+ *+ * @param request+ * @param schema+ */+ public extractPayload(request:T|Object, schema:SchemaResource|null = null) {+ return HalPayloadHelper.extractPayload(request, schema);+ }+}\ No newline at end of filediff --git a/frontend/src/app/modules/common/path-helper/apiv3/grids/apiv3-grid-paths.ts b/frontend/src/app/modules/apiv3/openproject-api-v3.module.tssimilarity index 77%rename from frontend/src/app/modules/common/path-helper/apiv3/grids/apiv3-grid-paths.tsrename to frontend/src/app/modules/apiv3/openproject-api-v3.module.tsindex 31ea53dd1a4..dc1c7724bdc 100644--- a/frontend/src/app/modules/common/path-helper/apiv3/grids/apiv3-grid-paths.ts+++ b/frontend/src/app/modules/apiv3/openproject-api-v3.module.ts@@ -26,15 +26,16 @@// See docs/COPYRIGHT.rdoc for more details.// ++-import {- SimpleResource-} from 'core-app/modules/common/path-helper/apiv3/path-resources';+import {OpenprojectCommonModule} from 'core-app/modules/common/openproject-common.module';+import {NgModule} from '@angular/core';+import {OpenprojectHalModule} from "core-app/modules/hal/openproject-hal.module";-export class Apiv3GridPaths extends SimpleResource {- constructor(basePath:string, gridId:string|number) {- super(basePath, gridId);- }-- // Static paths- readonly form = new SimpleResource(this.path, 'form');+@NgModule({+ imports: [+ // Commons+ OpenprojectCommonModule,+ OpenprojectHalModule,+ ]+})+export class OpenprojectApiV3Module {}diff --git a/frontend/src/app/modules/apiv3/paths/apiv3-list-resource.interface.ts b/frontend/src/app/modules/apiv3/paths/apiv3-list-resource.interface.tsnew file mode 100644index 00000000000..f94a7ec0bca--- /dev/null+++ b/frontend/src/app/modules/apiv3/paths/apiv3-list-resource.interface.ts@@ -0,0 +1,72 @@+//-- 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 {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {ApiV3FilterBuilder, FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";+import {Observable} from "rxjs";++export interface Apiv3ListParameters {+ filters?:[string, FilterOperator, string[]][];+ sortBy?:[string, string][];+ pageSize?:number;+}++export interface Apiv3ListResourceInterface<T> {+ list(params:Apiv3ListParameters):Observable<CollectionResource<T>>;+}++export function listParamsString(params?:Apiv3ListParameters):string {+ let queryProps = [];++ if (params && params.sortBy) {+ queryProps.push(`sortBy=${JSON.stringify(params.sortBy)}`);+ }++ // 0 should not be treated as false+ if (params && params.pageSize !== undefined) {+ queryProps.push(`pageSize=${params.pageSize}`);+ }++ if (params && params.filters) {+ let filters = new ApiV3FilterBuilder();++ params.filters.forEach((filterParam) => {+ filters.add(...filterParam);+ });++ queryProps.push(filters.toParams());+ }++ let queryPropsString = '';++ if (queryProps.length) {+ queryPropsString = `?${queryProps.join('&')}`;+ }++ return queryPropsString;+}diff --git a/frontend/src/app/modules/apiv3/paths/apiv3-resource.ts b/frontend/src/app/modules/apiv3/paths/apiv3-resource.tsnew file mode 100644index 00000000000..c294bf5c540--- /dev/null+++ b/frontend/src/app/modules/apiv3/paths/apiv3-resource.ts@@ -0,0 +1,113 @@+import {Constructor} from "@angular/cdk/table";+import {SimpleResource, SimpleResourceCollection} from "core-app/modules/apiv3/paths/path-resources";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";+import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {Observable} from "rxjs";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";++export class APIv3ResourcePath<T = HalResource> extends SimpleResource {+ readonly injector = this.apiRoot.injector;+ @InjectField() halResourceService:HalResourceService;++ constructor(protected apiRoot:APIV3Service,+ readonly basePath:string,+ readonly id:string|number,+ protected parent?:APIv3ResourcePath|APIv3ResourceCollection<any, any>) {+ super(basePath, id);+ }+++ /**+ * Build a singular resource from the current segment+ *+ * @param segment Additional segment to add to the current path+ */+ protected subResource<R = APIv3GettableResource>(segment:string, cls:Constructor<R> = APIv3GettableResource as any):R {+ return new cls(this.apiRoot, this.path, segment, this);+ }+}+++export class APIv3GettableResource<T = HalResource> extends APIv3ResourcePath<T> {+ /**+ * Perform a request to the HalResourceService with the current path+ */+ public get():Observable<T> {+ return this+ .halResourceService+ .get(this.path) as any;+ }+}++export class APIv3ResourceCollection<V, T extends APIv3GettableResource<V>> extends SimpleResourceCollection {+ readonly injector = this.apiRoot.injector;+ @InjectField() halResourceService:HalResourceService;++ constructor(protected apiRoot:APIV3Service,+ protected basePath:string,+ segment:string,+ protected resource?:Constructor<T>) {+ super(basePath, segment, resource);+ }++ /**+ * Returns an instance of T for the given singular resource ID.+ *+ * @param id Identifier of the resource, may be a string or number, or a HalResource with id property.+ */+ public id(input:string|number|{ id:string|null }):T {+ let id:string;+ if (typeof input === 'string' || typeof input === 'number') {+ id = input.toString();+ } else {+ id = input.id!;+ }++ return new (this.resource || APIv3GettableResource)(this.apiRoot, this.path, id, this) as T;+ }+++ public withOptionalId(id?:string|number|null):this|T {+ if (_.isNil(id)) {+ return this;+ } else {+ return this.id(id);+ }+ }++ /**+ * Returns the path string to the requested endpoint.+ */+ public toString():string {+ return this.path;+ }++ /**+ * Returns the path string to the requested endpoint.+ */+ public toPath():string {+ return this.path;+ }++ /**+ * Returns a new resource with the path extended with a URL query+ * to match the filters.+ *+ * @param filters filter object to filter with+ * @param params additional URL params to append+ */+ public filtered<R = APIv3GettableResource<V>>(filters:ApiV3FilterBuilder, params:{ [key:string]:string } = {}, resourceClass?:Constructor<R>):R {+ return this.subResource<R>('?' + filters.toParams(params), resourceClass) as R;+ }++ /**+ * Build a singular resource from the current segment+ *+ * @param segment Additional segment to add to the current path+ */+ protected subResource<R = APIv3GettableResource<HalResource>>(segment:string, cls:Constructor<R> = APIv3GettableResource as any):R {+ return new cls(this.apiRoot, this.path, segment, this);+ }+}\ No newline at end of filediff --git a/frontend/src/app/modules/common/path-helper/apiv3/path-resources.ts b/frontend/src/app/modules/apiv3/paths/path-resources.tssimilarity index 55%rename from frontend/src/app/modules/common/path-helper/apiv3/path-resources.tsrename to frontend/src/app/modules/apiv3/paths/path-resources.tsindex 43e9f159891..05c6a5b7c28 100644--- a/frontend/src/app/modules/common/path-helper/apiv3/path-resources.ts+++ b/frontend/src/app/modules/apiv3/paths/path-resources.ts@@ -1,6 +1,10 @@import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder";import {Constructor} from "@angular/cdk/table";+/**+ * Simple resource collection to construct paths for RESTful resources.+ * Base class for APIV3 and BCF API helpers+ */export class SimpleResourceCollection<T = SimpleResource> {// Base pathpublic readonly path:string;@@ -13,7 +17,16 @@ export class SimpleResourceCollection<T = SimpleResource> {return new (this.resource || SimpleResource)(this.path, id) as T;}- public optionalId(id?:string|number):this|T {+ /**+ * Returns either the collection itself, or the resource+ * located by the ID when present.+ *+ * TypeScript will reduce available endpoints to anything available+ * in this collection AND the resource.+ *+ * @param id+ */+ public withOptionalId(id?:string|number):this|T {if (_.isNil(id)) {return this;} else {@@ -28,17 +41,17 @@ export class SimpleResourceCollection<T = SimpleResource> {public toPath():string {return this.path;}-- public filtered(filters:ApiV3FilterBuilder) {- return this.toString() + '/?' + filters.toParams();- }}+/**+ * Singular RESTful resource object identified by a base path and ID+ */export class SimpleResource {public readonly path:string;- constructor(protected basePath:string, readonly id:string|number) {- this.path = `${this.basePath}/${id}`;+ constructor(readonly basePath:string, readonly segment:string|number) {+ let separator = segment.toString().startsWith('?') ? '' : '/';+ this.path = `${this.basePath}${separator}${segment}`;}public toString() {diff --git a/frontend/src/app/modules/apiv3/virtual/apiv3-board-path.ts b/frontend/src/app/modules/apiv3/virtual/apiv3-board-path.tsnew file mode 100644index 00000000000..44036e60d09--- /dev/null+++ b/frontend/src/app/modules/apiv3/virtual/apiv3-board-path.ts@@ -0,0 +1,102 @@+// -- 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 {Board} from "core-app/modules/boards/board/board";+import {Observable} from "rxjs";+import {map, switchMap, tap} from "rxjs/operators";+import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";+import {CachableAPIV3Resource} from "core-app/modules/apiv3/cache/cachable-apiv3-resource";+import {MultiInputState} from "reactivestates";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";+import {Apiv3BoardsPaths} from "core-app/modules/apiv3/virtual/apiv3-boards-paths";++export class APIv3BoardPath extends CachableAPIV3Resource<Board> {++ /**+ * Perform a request to the HalResourceService with the current path+ */+ protected load():Observable<Board> {+ return this+ .apiRoot+ .grids+ .id(this.id)+ .get()+ .pipe(+ map(grid => new Board(grid))+ );+ }++ /**+ * Save the changes to the board+ */+ public save(board:Board):Observable<Board> {+ return this+ .fetchSchema(board)+ .pipe(+ switchMap((schema:SchemaResource) => this+ .apiRoot+ .grids+ .id(board.grid)+ .patch(board.grid, schema)+ ),+ map(grid => {+ board.grid = grid;+ board.sortWidgets();+ return board;+ }),+ this.cacheResponse()+ );+ }++ public delete():Observable<unknown> {+ return this+ .apiRoot+ .grids+ .id(this.id)+ .delete()+ .pipe(+ tap(() => this.cache.clearSome(this.id.toString()))+ );+ }++ private fetchSchema(board:Board):Observable<SchemaResource> {+ return this+ .apiRoot+ .grids+ .id(board.grid)+ .form+ .post({})+ .pipe(+ map(form => form.schema)+ );+ }++ protected createCache():StateCacheService<Board> {+ return (this.parent as Apiv3BoardsPaths).cache;+ }+}diff --git a/frontend/src/app/modules/apiv3/virtual/apiv3-boards-paths.ts b/frontend/src/app/modules/apiv3/virtual/apiv3-boards-paths.tsnew file mode 100644index 00000000000..7c1b422409f--- /dev/null+++ b/frontend/src/app/modules/apiv3/virtual/apiv3-boards-paths.ts@@ -0,0 +1,141 @@+// -- 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 {Constructor} from "@angular/cdk/table";+import {GridResource} from "core-app/modules/hal/resources/grid-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {Observable} from "rxjs";+import {Apiv3ListParameters, listParamsString} from "core-app/modules/apiv3/paths/apiv3-list-resource.interface";+import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";+import {Board, BoardType} from "core-app/modules/boards/board/board";+import {map, switchMap, tap} from "rxjs/operators";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {CurrentProjectService} from "core-components/projects/current-project.service";+import {AuthorisationService} from "core-app/modules/common/model-auth/model-auth.service";+import {CachableAPIV3Collection} from "core-app/modules/apiv3/cache/cachable-apiv3-collection";+import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";+import {MultiInputState} from "reactivestates";+import {APIv3BoardPath} from "core-app/modules/apiv3/virtual/apiv3-board-path";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";++export class Apiv3BoardsPaths extends CachableAPIV3Collection<Board, APIv3BoardPath> {++ @InjectField() private authorisationService:AuthorisationService;+ @InjectField() private PathHelper:PathHelperService;++ constructor(protected apiRoot:APIV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'grids', APIv3BoardPath);+ }++ /**+ * Load a list of grids with a given list parameter filter+ * @param params+ */+ public list(params?:Apiv3ListParameters):Observable<Board[]> {+ return this+ .halResourceService+ .get<CollectionResource<GridResource>>(this.path + listParamsString(params))+ .pipe(+ tap(collection => this.authorisationService.initModelAuth('boards', collection.$links)),+ map(collection =>+ collection.elements.map(grid => {+ let board = new Board(grid);+ board.sortWidgets();+ this.touch(board);++ return board;+ })+ )+ );+ }++ /**+ * Return all boards in the current scope of the project+ *+ * @param projectIdentifier+ */+ public allInScope(projectIdentifier:string):Observable<Board[]> {+ const path = this.boardPath(projectIdentifier);+ return this.list({ filters: [['scope', '=', [path]]] });+ }++ /**+ * Create a new board+ * @param type+ * @param name+ * @param projectIdentifier+ */+ public create(type:BoardType, name:string, projectIdentifier:string, actionAttribute?:string):Observable<Board> {+ const scope = this.boardPath(projectIdentifier);+ return this+ .createGrid(type, name, scope, actionAttribute)+ .pipe(+ map(grid => new Board(grid))+ );+ }++ /**+ * Retrieve the board path identifier for looking up grids.+ *+ * @param projectIdentifier The current project identifier+ */+ public boardPath(projectIdentifier:string) {+ return this.PathHelper.projectBoardsPath(projectIdentifier);+ }++ protected createCache():StateCacheService<Board> {+ let state = this.states.forType<Board>('boards');+ return new StateCacheService<Board>(state);+ }++ private createGrid(type:BoardType, name:string, scope:string, actionAttribute?:string):Observable<GridResource> {+ let payload:any = _.set({ name: name }, '_links.scope.href', scope);+ payload.options = {+ type: type,+ };++ if (actionAttribute) {+ payload.options.attribute = actionAttribute;+ }++ return this+ .apiRoot+ .grids+ .form+ .post(payload)+ .pipe(+ switchMap((form) => {+ return this+ .apiRoot+ .grids+ .post(form.payload.$source);+ })+ );+ }+}diff --git a/frontend/src/app/modules/bim/bcf/api/bcf-path-resources.ts b/frontend/src/app/modules/bim/bcf/api/bcf-path-resources.tsindex b3d155880f0..8422091ea8f 100644--- a/frontend/src/app/modules/bim/bcf/api/bcf-path-resources.ts+++ b/frontend/src/app/modules/bim/bcf/api/bcf-path-resources.ts@@ -1,11 +1,11 @@-import {SimpleResource, SimpleResourceCollection} from "core-app/modules/common/path-helper/apiv3/path-resources";import {Injector} from "@angular/core";import {Constructor} from "@angular/cdk/table";+import {SimpleResource, SimpleResourceCollection} from "core-app/modules/apiv3/paths/path-resources";export class BcfResourcePath extends SimpleResource {constructor(readonly injector:Injector,basePath:string,- id:string|number) {+ readonly id:string|number) {super(basePath, id);}}diff --git a/frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.ts b/frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.tsindex cf0a87e0d09..fa8debcedb7 100644--- a/frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.ts+++ b/frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.ts@@ -13,14 +13,13 @@ import {NgxGalleryComponent, NgxGalleryOptions} from '@kolkov/ngx-gallery';import {HalLink} from "core-app/modules/hal/hal-link/hal-link";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {ViewerBridgeService} from "core-app/modules/bim/bcf/bcf-viewer-bridge/viewer-bridge.service";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";import {WorkPackageCreateService} from "core-components/wp-new/wp-create.service";import {BcfAuthorizationService} from "core-app/modules/bim/bcf/api/bcf-authorization.service";import {ViewpointsService} from "core-app/modules/bim/bcf/helper/viewpoints.service";import {BcfViewpointItem} from "core-app/modules/bim/bcf/api/viewpoints/bcf-viewpoint-item.interface";-+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({@@ -108,12 +107,12 @@ export class BcfWpAttributeGroupComponent extends UntilDestroyedMixin implementscreateAllowed:boolean = false;// Currently, this is static. Need observable if this changes over timeviewerVisible = this.viewerBridge.viewerVisible();- projectId: string;+ projectId:string;constructor(readonly state:StateService,readonly bcfAuthorization:BcfAuthorizationService,readonly viewerBridge:ViewerBridgeService,- readonly wpCache:WorkPackageCacheService,+ readonly apiV3Service:APIV3Service,readonly wpCreate:WorkPackageCreateService,readonly notifications:NotificationsService,readonly cdRef:ChangeDetectorRef,@@ -128,26 +127,29 @@ export class BcfWpAttributeGroupComponent extends UntilDestroyedMixin implements}protected observeChanges() {- this.wpCache- .observe(this.workPackage.id!)- .pipe(this.untilDestroyed())- .subscribe(async wp => {- this.workPackage = wp;-- if (!this.projectId) {- await this.initialize(this.workPackage);- }-- if (wp.bcfViewpoints) {- this.refreshViewpoints(wp.bcfViewpoints);- }- });+ this+ .apiV3Service+ .work_packages+ .id(this.workPackage)+ .requireAndStream()+ .pipe(this.untilDestroyed())+ .subscribe(async wp => {+ this.workPackage = wp;++ if (!this.projectId) {+ await this.initialize(this.workPackage);+ }++ if (wp.bcfViewpoints) {+ this.refreshViewpoints(wp.bcfViewpoints);+ }+ });}async initialize(workPackage:WorkPackageResource) {this.projectId = workPackage.project.idFromLink;this.viewAllowed = await this.bcfAuthorization.isAllowedTo(this.projectId, 'project_actions', 'viewTopic');- this.createAllowed = await this.bcfAuthorization.isAllowedTo(this.projectId, 'topic_actions', 'createViewpoint');+ this.createAllowed = await this.bcfAuthorization.isAllowedTo(this.projectId, 'topic_actions', 'createViewpoint');this.loadViewpointFromRoute(workPackage);this.cdRef.detectChanges();@@ -169,20 +171,20 @@ export class BcfWpAttributeGroupComponent extends UntilDestroyedMixin implements}this.viewpointsService- .deleteViewPoint$(workPackage, index)- .subscribe(data => {- this.notifications.addSuccess(this.text.notice_successful_delete);- this.gallery.preview.close();- });+ .deleteViewPoint$(workPackage, index)+ .subscribe(data => {+ this.notifications.addSuccess(this.text.notice_successful_delete);+ this.gallery.preview.close();+ });}public saveViewpoint(workPackage:WorkPackageResource) {this.viewpointsService- .saveViewpoint$(workPackage)- .subscribe(viewpoint => {- this.notifications.addSuccess(this.text.notice_successful_create);- this.showIndex = this.viewpoints.length;- });+ .saveViewpoint$(workPackage)+ .subscribe(viewpoint => {+ this.notifications.addSuccess(this.text.notice_successful_create);+ this.showIndex = this.viewpoints.length;+ });}protected loadViewpointFromRoute(workPackage:WorkPackageResource) {@@ -206,7 +208,7 @@ export class BcfWpAttributeGroupComponent extends UntilDestroyedMixin implementsreturn [{icon: 'icon-view-model',- onClick: (evt: any, index: number) => this.showViewpoint(this.workPackage, index),+ onClick: (evt:any, index:number) => this.showViewpoint(this.workPackage, index),titleText: this.text.show_viewpoint},{diff --git a/frontend/src/app/modules/bim/bcf/helper/viewpoints.service.ts b/frontend/src/app/modules/bim/bcf/helper/viewpoints.service.tsindex 031f84981a0..971c12b3ab3 100644--- a/frontend/src/app/modules/bim/bcf/helper/viewpoints.service.ts+++ b/frontend/src/app/modules/bim/bcf/helper/viewpoints.service.ts@@ -8,7 +8,7 @@ import {switchMap, map, tap} from 'rxjs/operators';import {of, forkJoin, Observable} from 'rxjs';import {BcfViewpointInterface} from "core-app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.interface";import {BcfTopicResource} from "core-app/modules/bim/bcf/api/topics/bcf-topic.resource";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable()@@ -17,7 +17,7 @@ export class ViewpointsService {@InjectField() bcfApi:BcfApiService;@InjectField() viewerBridge:ViewerBridgeService;- @InjectField() wpCache:WorkPackageCacheService;+ @InjectField() apiV3Service:APIV3Service;constructor(readonly injector:Injector) {}@@ -40,11 +40,11 @@ export class ViewpointsService {.delete().pipe(// Update the work package to reload the viewpoints- tap(() => this.wpCache.require(workPackage.id!, true))+ tap(() => this.apiV3Service.work_packages.id(workPackage).requireAndStream(true)));}- public saveViewpoint$(workPackage:WorkPackageResource, viewpoint?:BcfViewpointInterface): Observable<BcfViewpointInterface> {+ public saveViewpoint$(workPackage:WorkPackageResource, viewpoint?:BcfViewpointInterface):Observable<BcfViewpointInterface> {const wpProjectId = workPackage.project.idFromLink;const topicUUID$ = this.setBcfTopic$(workPackage);// Default to the current viewer's viewpoint@@ -62,11 +62,12 @@ export class ViewpointsService {.projects.id(wpProjectId).topics.id(results.topicUUID as (string | number)).viewpoints- .post(results.viewpoint)+ .post(results.viewpoint);}),// Update the work package to reload the viewpoints- tap((results) => this.wpCache.require(workPackage.id!, true))+ tap((results) =>+ this.apiV3Service.work_packages.id(workPackage).requireAndStream(true)));}@@ -78,7 +79,7 @@ export class ViewpointsService {const topicUUID$ = topicHref ?of(this.bcfApi.parse<BcfViewpointPaths>(topicHref)!.id) :this.createBcfTopic$(workPackage);-+return topicUUID$.pipe(map(topicUUID => this.topicUUID = topicUUID));}}diff --git a/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.component.ts b/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.component.tsindex d6402a3fd37..3ddc19f0c0f 100644--- a/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.component.ts+++ b/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.component.ts@@ -34,7 +34,6 @@ import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {Board} from "core-app/modules/boards/board/board";import {StateService} from "@uirouter/core";import {BoardService} from "core-app/modules/boards/board/board.service";-import {BoardCacheService} from "core-app/modules/boards/board/board-cache.service";import {BoardActionsRegistryService} from "core-app/modules/boards/board/board-actions/board-actions-registry.service";import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";import {HalResource} from "core-app/modules/hal/resources/hal-resource";@@ -103,7 +102,6 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {readonly boardActions:BoardActionsRegistryService,readonly state:StateService,readonly boardService:BoardService,- readonly boardCache:BoardCacheService,readonly I18n:I18nService) {super(locals, cdRef, elementRef);@@ -139,11 +137,10 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {this.inFlight = true;this.actionService.addActionQuery(this.board, this.selectedAttribute!)- .then(board => this.boardService.save(board))+ .then(board => this.boardService.save(board).toPromise()).then((board) => {this.inFlight = false;this.closeMe();- this.boardCache.update(board);this.state.go('boards.partitioned.show', { board_id: board.id, isNew: true });}).catch(() => this.inFlight = false);diff --git a/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.tsindex b02c2a32f11..27c77dfb3ad 100644--- a/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.ts@@ -17,20 +17,21 @@ import {input} from "reactivestates";import {take} from "rxjs/operators";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";-import {ProjectDmService} from "core-app/modules/hal/dm-services/project-dm.service";import {ProjectResource} from "core-app/modules/hal/resources/project-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {APIv3GettableResource} from "core-app/modules/apiv3/paths/apiv3-resource";@Injectable()export class BoardAssigneeActionService implements BoardActionService {private assignees = input<HalResource[]>();- @InjectField() public projectDmService:ProjectDmService;constructor(protected boardListsService:BoardListsService,protected I18n:I18nService,protected halResourceService:HalResourceService,protected pathHelper:PathHelperService,+ protected apiV3Service:APIV3Service,protected currentProject:CurrentProjectService,readonly injector:Injector) {}@@ -131,8 +132,12 @@ export class BoardAssigneeActionService implements BoardActionService {public warningTextWhenNoOptionsAvailable() {let text = this.I18n.t('js.boards.add_list_modal.warning.assignee');- return this.projectDmService- .one(parseInt(this.currentProject.id!))+ return this+ .apiV3Service+ .projects+ .id(this.currentProject.id!)+ .get()+ .toPromise().then((project:ProjectResource) => {if (project.memberships) {text = text.concat(@@ -147,10 +152,13 @@ export class BoardAssigneeActionService implements BoardActionService {}private getAssignees():Promise<HalResource[]> {- const projectIdentifier = this.currentProject.identifier!;this.assignees.putFromPromiseIfPristine(() =>- this.halResourceService- .get(this.pathHelper.api.v3.projects.id(projectIdentifier).available_assignees)+ this+ .apiV3Service+ .projects+ .id(this.currentProject.identifier!)+ .available_assignees+ .get().toPromise().then((collection:CollectionResource<UserResource>) => collection.elements));diff --git a/frontend/src/app/modules/boards/board/board-actions/status/status-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/status/status-action.service.tsindex 6446a9dbac1..b47857c1ba2 100644--- a/frontend/src/app/modules/boards/board/board-actions/status/status-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/status/status-action.service.ts@@ -1,7 +1,6 @@import {Injectable} from "@angular/core";import {BoardListsService} from "core-app/modules/boards/board/board-list/board-lists.service";import {Board} from "core-app/modules/boards/board/board";-import {StatusDmService} from "core-app/modules/hal/dm-services/status-dm.service";import {StatusResource} from "core-app/modules/hal/resources/status-resource";import {QueryResource} from "core-app/modules/hal/resources/query-resource";import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";@@ -10,15 +9,14 @@ import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";import {CreateAutocompleterComponent} from "core-app/modules/common/autocomplete/create-autocompleter.component";import {OpContextMenuItem} from "core-components/op-context-menu/op-context-menu.types";-import {StatusCacheService} from "core-components/statuses/status-cache.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable()export class BoardStatusActionService implements BoardActionService {constructor(protected boardListsService:BoardListsService,protected I18n:I18nService,- protected statusCache:StatusCacheService,- protected statusDm:StatusDmService) {+ protected apiV3Service:APIV3Service) {}public get localizedName() {@@ -50,7 +48,11 @@ export class BoardStatusActionService implements BoardActionService {if (href) {const id = HalResource.idFromLink(href);- return this.statusCache.require(id);+ return this+ .apiV3Service+ .statuses.id(id)+ .get()+ .toPromise();} else {return Promise.resolve(undefined);}@@ -131,8 +133,11 @@ export class BoardStatusActionService implements BoardActionService {}private getStatuses():Promise<StatusResource[]> {- return this.statusDm- .list()+ return this+ .apiV3Service+ .statuses+ .get()+ .toPromise().then(collection => collection.elements);}diff --git a/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-action.service.tsnew file mode 100644index 00000000000..e69de29bb2ddiff --git a/frontend/src/app/modules/boards/board/board-actions/version/version-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/version/version-action.service.tsindex a3b2cd89d14..eccd9501f7e 100644--- a/frontend/src/app/modules/boards/board/board-actions/version/version-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/version/version-action.service.ts@@ -7,7 +7,6 @@ import {HalResource} from "core-app/modules/hal/resources/hal-resource";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";import {VersionResource} from "core-app/modules/hal/resources/version-resource";-import {VersionDmService} from "core-app/modules/hal/dm-services/version-dm.service";import {CurrentProjectService} from "core-components/projects/current-project.service";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {VersionAutocompleterComponent} from "core-app/modules/common/autocomplete/version-autocompleter.component";@@ -15,22 +14,22 @@ import {OpContextMenuItem} from "core-components/op-context-menu/op-context-menuimport {LinkHandling} from "core-app/modules/common/link-handling/link-handling";import {StateService} from "@uirouter/core";import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";-import {VersionCacheService} from "core-components/versions/version-cache.service";import {VersionBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/version/version-board-header.component";import {FormResource} from "core-app/modules/hal/resources/form-resource";-import {FormsCacheService} from "core-components/forms/forms-cache.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {BehaviorSubject} from "rxjs";@Injectable()export class BoardVersionActionService implements BoardActionService {+ private writable$:Promise<boolean>;+constructor(protected boardListsService:BoardListsService,protected I18n:I18nService,- protected versionDm:VersionDmService,- protected versionCache:VersionCacheService,+ protected apiv3Service:APIV3Service,protected currentProject:CurrentProjectService,protected halNotification:HalResourceNotificationService,protected state:StateService,- protected formCache:FormsCacheService,protected pathHelper:PathHelperService) {}@@ -63,7 +62,10 @@ export class BoardVersionActionService implements BoardActionService {if (href) {const id = HalResource.idFromLink(href);- return this.versionCache.require(id);+ return this+ .apiv3Service+ .versions.id(id)+ .get().toPromise();} else {return Promise.resolve(undefined);}@@ -76,9 +78,12 @@ export class BoardVersionActionService implements BoardActionService {return Promise.resolve(false);}- return this.formCache- .require(formLink)- .then((form:FormResource) => form.schema.version.writable);+ if (!this.writable$) {+ this.writable$ = query.results.createWorkPackage()+ .then((form:FormResource) => form.schema.version.writable);+ }++ return this.writable$;}public addActionQueries(board:Board):Promise<Board> {@@ -175,19 +180,27 @@ export class BoardVersionActionService implements BoardActionService {return Promise.resolve([]);}- return this.versionDm- .listForProject(this.currentProject.id)+ return this+ .apiv3Service+ .projects+ .id(this.currentProject.id!)+ .versions+ .get()+ .toPromise().then(collection => collection.elements);}private patchVersionStatus(version:VersionResource, newStatus:'open'|'closed'|'locked') {- this.versionDm- .patch(version, { status: newStatus })- .then((version) => {- this.versionCache.updateValue(version.id!, version);+ this.apiv3Service+ .versions+ .id(version)+ .patch({ status: newStatus })+ .subscribe(+ version => {this.state.go('.', {}, { reload: true });- })- .catch(error => this.halNotification.handleRawError(error));+ },+ error => this.halNotification.handleRawError(error)+ );}private buildItemsForVersion(version:VersionResource):OpContextMenuItem[] {diff --git a/frontend/src/app/modules/boards/board/board-cache.service.ts b/frontend/src/app/modules/boards/board/board-cache.service.tsdeleted file mode 100644index eb1869a0b6f..00000000000--- a/frontend/src/app/modules/boards/board/board-cache.service.ts+++ /dev/null@@ -1,40 +0,0 @@-import {Injectable} from "@angular/core";-import {StateCacheService} from "core-components/states/state-cache.service";-import {multiInput, MultiInputState} from "reactivestates";-import {Board} from "core-app/modules/boards/board/board";-import {BoardDmService} from "core-app/modules/boards/board/board-dm.service";--@Injectable({ providedIn: 'root' })-export class BoardCacheService extends StateCacheService<Board> {-- protected _state = multiInput<Board>();-- constructor(protected boardDm:BoardDmService) {- super();- }-- protected load(id:string):Promise<Board> {- return this.boardDm- .one(parseInt(id))- .toPromise()- .then((board:Board) => {- this.updateValue(id, board);- return board;- });-- }-- protected loadAll(ids:string[] = []):Promise<undefined> {- return Promise- .all(ids.map(id => this.load(id)))- .then(() => undefined);- }-- protected get multiState():MultiInputState<Board> {- return this._state;- }-- update(board:Board) {- this.updateValue(board.id!, board);- }-}diff --git a/frontend/src/app/modules/boards/board/board-dm.service.ts b/frontend/src/app/modules/boards/board/board-dm.service.tsdeleted file mode 100644index 6244567d590..00000000000--- a/frontend/src/app/modules/boards/board/board-dm.service.ts+++ /dev/null@@ -1,113 +0,0 @@-import {Injectable} from "@angular/core";-import {from, Observable} from "rxjs";-import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";-import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";-import {GridDmService} from "core-app/modules/hal/dm-services/grid-dm.service";-import {CurrentProjectService} from "core-components/projects/current-project.service";-import {GridResource} from "core-app/modules/hal/resources/grid-resource";-import {map, tap} from "rxjs/operators";-import {Board, BoardType} from "core-app/modules/boards/board/board";-import {AuthorisationService} from "core-app/modules/common/model-auth/model-auth.service";--@Injectable({ providedIn: 'root' })-export class BoardDmService {-- constructor(protected GridDm:GridDmService,- protected PathHelper:PathHelperService,- protected authorisationService:AuthorisationService,- protected CurrentProject:CurrentProjectService,- protected halResourceService:HalResourceService) {- }-- /**- * Return all boards in the current scope of the project- *- * @param projectIdentifier- */- public allInScope(projectIdentifier:string|null = this.CurrentProject.identifier) {- const path = this.boardPath(projectIdentifier);-- return from(- this.GridDm.list({ filters: [['scope', '=', [path]]] })- )- .pipe(- tap(collection => this.authorisationService.initModelAuth('boards', collection.$links)),- map(collection => collection.elements.map(grid => new Board(grid)))- );- }-- /**- * Load one board based on ID- */- public one(id:number):Observable<Board> {- return from(this.GridDm.one(id))- .pipe(- map(grid => new Board(grid))- );- }-- /**- * Save the changes to the board- */- public save(board:Board) {- return this.fetchSchema(board)- .then(schema => this.GridDm.update(board.grid, schema))- .then(grid => {- board.grid = grid;- return board;- });- }-- private fetchSchema(board:Board) {- return this.GridDm.updateForm(board.grid)- .then((form) => form.schema);- }-- /**- * Retrieve the board path identifier for looking up grids.- *- * @param projectIdentifier The current project identifier- */- public boardPath(projectIdentifier:string|null = this.CurrentProject.identifier) {- return this.PathHelper.projectBoardsPath(projectIdentifier);- }-- /**- * Create a new board- * @param type- * @param name- */- public async create(type:BoardType, name:string, actionAttribute?:string):Promise<Board> {- return this.createGrid(type, name, actionAttribute)- .then(grid => new Board(grid));- }-- public delete(board:Board):Promise<unknown> {- if (!board.grid.delete) {- return Promise.reject("Deletion not possible");- }-- return board.grid.delete();- }--- private createGrid(type:BoardType, name:string, actionAttribute?:string):Promise<GridResource> {- const path = this.boardPath();- let payload:any = _.set({ name: name }, '_links.scope.href', path);- payload.options = {- type: type,- };-- if (actionAttribute) {- payload.options.attribute = actionAttribute;- }-- return this.GridDm- .createForm(payload)- .then((form) => {- let resource = this.halResourceService.createHalResource<GridResource>(form.payload.$source);- return this.GridDm.create(resource, form.schema);- });- }--}diff --git a/frontend/src/app/modules/boards/board/board-filter/board-filter.component.ts b/frontend/src/app/modules/boards/board/board-filter/board-filter.component.tsindex 454822ca112..ddb067e2b91 100644--- a/frontend/src/app/modules/boards/board/board-filter/board-filter.component.ts+++ b/frontend/src/app/modules/boards/board/board-filter/board-filter.component.ts@@ -1,7 +1,6 @@import {AfterViewInit, Component, Input} from "@angular/core";import {Board} from "core-app/modules/boards/board/board";import {CurrentProjectService} from "core-components/projects/current-project.service";-import {QueryFormDmService} from "core-app/modules/hal/dm-services/query-form-dm.service";import {WorkPackageStatesInitializationService} from "core-components/wp-list/wp-states-initialization.service";import {QueryFormResource} from "core-app/modules/hal/resources/query-form-resource";import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";@@ -15,6 +14,7 @@ import {debounceTime, skip, take} from "rxjs/internal/operators";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";import {Observable} from "rxjs";import {BoardFiltersService} from "core-app/modules/boards/board/board-filter/board-filters.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'board-filter',@@ -28,13 +28,13 @@ export class BoardFilterComponent extends UntilDestroyedMixin implements AfterViconstructor(private readonly currentProjectService:CurrentProjectService,private readonly querySpace:IsolatedQuerySpace,+ private readonly apiV3Service:APIV3Service,private readonly halResourceService:HalResourceService,private readonly wpStatesInitialization:WorkPackageStatesInitializationService,private readonly wpTableFilters:WorkPackageViewFiltersService,private readonly urlParamsHelper:UrlParamsHelperService,private readonly boardFilters:BoardFiltersService,- private readonly $state:StateService,- private readonly queryFormDm:QueryFormDmService) {+ private readonly $state:StateService) {super();}@@ -80,18 +80,16 @@ export class BoardFilterComponent extends UntilDestroyedMixin implements AfterVi}private loadQueryForm() {- this.queryFormDm+ this+ .apiV3Service+ .queries+ .form.loadWithParams({ filters: JSON.stringify(this.boardFilters.current) },undefined,this.currentProjectService.id)- .then((form:QueryFormResource) => {- const query:QueryResource = this.halResourceService.createHalResourceOfClass(- QueryResource,- form.payload.$source- );-+ .subscribe(([form, query]) => {this.querySpace.query.putValue(query);this.wpStatesInitialization.updateStatesFromForm(query, form);});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 e778ac79fe1..e3acd0790fc 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@@ -11,7 +11,6 @@ import {Output,ViewChild} from "@angular/core";-import {QueryDmService} from "core-app/modules/hal/dm-services/query-dm.service";import {LoadingIndicatorService,withLoadingIndicator@@ -21,7 +20,6 @@ import {WorkPackageInlineCreateService} from "core-components/wp-inline-create/wimport {BoardInlineCreateService} from "core-app/modules/boards/board/board-list/board-inline-create.service";import {AbstractWidgetComponent} from "core-app/modules/grids/widgets/abstract-widget.component";import {I18nService} from "core-app/modules/common/i18n/i18n.service";-import {BoardCacheService} from "core-app/modules/boards/board/board-cache.service";import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";import {Board} from "core-app/modules/boards/board/board";@@ -36,12 +34,10 @@ import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-rimport {WorkPackageFilterValues} from "core-components/wp-edit-form/work-package-filter-values";import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";import {BoardActionsRegistryService} from "core-app/modules/boards/board/board-actions/board-actions-registry.service";import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";import {ComponentType} from "@angular/cdk/portal";-import {IFieldSchema} from "core-app/modules/fields/field.base";import {CausedUpdatesService} from "core-app/modules/boards/board/caused-updates/caused-updates.service";import {BoardListMenuComponent} from "core-app/modules/boards/board/board-list/board-list-menu.component";import {debugLog} from "core-app/helpers/debug_output";@@ -57,6 +53,7 @@ import {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";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export interface DisabledButtonPlaceholder {text:string;@@ -129,7 +126,7 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnInipublic buttonPlaceholder:DisabledButtonPlaceholder|undefined;- constructor(readonly QueryDm:QueryDmService,+ constructor(readonly apiv3Service:APIV3Service,readonly I18n:I18nService,readonly state:StateService,readonly cdRef:ChangeDetectorRef,@@ -148,7 +145,6 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnInireadonly injector:Injector,readonly halEditing:HalResourceEditingService,readonly loadingIndicator:LoadingIndicatorService,- readonly wpCacheService:WorkPackageCacheService,readonly schemaCache:SchemaCacheService,readonly boardService:BoardService,readonly boardActionRegistry:BoardActionsRegistryService,@@ -278,22 +274,29 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnInireturn;}- this.QueryDm- .delete(query)- .then(() => this.onRemove.emit());+ this+ .apiv3Service+ .queries+ .id(query)+ .delete()+ .subscribe(() => this.onRemove.emit());}public renameQuery(query:QueryResource, value:string) {this.inFlight = true;this.query.name = value;- this.QueryDm- .patch(this.query.id!, { name: value })- .toPromise()- .then(() => {- this.inFlight = false;- this.notifications.addSuccess(this.text.updateSuccessful);- })- .catch(() => this.inFlight = false);+ this+ .apiv3Service+ .queries+ .id(this.query)+ .patch({ name: value })+ .subscribe(+ () => {+ this.inFlight = false;+ this.notifications.addSuccess(this.text.updateSuccessful);+ },+ (_error) => this.inFlight = false,+ );}private boardListActionColorClass(value?:HalResource):string {@@ -384,7 +387,7 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIniif (changeset.isEmpty()) {// Ensure work package and its schema is loaded- return this.wpCacheService.updateWorkPackage(workPackage);+ return this.apiv3Service.work_packages.cache.updateWorkPackage(workPackage);} else {// Save changes to the work package, which reloads it as wellreturn this.halEditing.save(changeset);@@ -396,7 +399,10 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIni}private loadQuery(visibly = true) {- let observable = this.QueryDm.stream(this.columnsQueryProps, this.queryId);+ let observable = this+ .apiv3Service+ .queries+ .find(this.columnsQueryProps, this.queryId);// Spread arguments on pipe does not work:// https://github.com/ReactiveX/rxjs/issues/3989diff --git a/frontend/src/app/modules/boards/board/board-list/board-lists.service.ts b/frontend/src/app/modules/boards/board/board-list/board-lists.service.tsindex e1d2b2951b2..6f08e77369d 100644--- a/frontend/src/app/modules/boards/board/board-list/board-lists.service.ts+++ b/frontend/src/app/modules/boards/board/board-list/board-lists.service.ts@@ -1,8 +1,6 @@import {Injectable} from "@angular/core";import {CurrentProjectService} from "core-components/projects/current-project.service";-import {QueryFormDmService} from "core-app/modules/hal/dm-services/query-form-dm.service";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";-import {QueryDmService} from "core-app/modules/hal/dm-services/query-dm.service";import {QueryResource} from "core-app/modules/hal/resources/query-resource";import {Board} from "core-app/modules/boards/board/board";import {GridWidgetResource} from "core-app/modules/hal/resources/grid-widget-resource";@@ -10,17 +8,17 @@ import {HalResourceService} from "core-app/modules/hal/services/hal-resource.serimport {ApiV3Filter} from "core-components/api/api-v3/api-v3-filter-builder";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable({ providedIn: 'root' })export class BoardListsService {- private readonly v3 = this.pathHelper.api.v3;+ private v3 = this.pathHelper.api.v3;constructor(private readonly CurrentProject:CurrentProjectService,private readonly pathHelper:PathHelperService,- private readonly QueryDm:QueryDmService,+ private readonly apiV3Service:APIV3Service,private readonly halResourceService:HalResourceService,- private readonly QueryFormDm:QueryFormDmService,private readonly notifications:NotificationsService,private readonly I18n:I18nService) {@@ -29,7 +27,10 @@ export class BoardListsService {private create(params:Object, filters:ApiV3Filter[]):Promise<QueryResource> {let filterJson = JSON.stringify(filters);- return this.QueryFormDm+ return this+ .apiV3Service+ .queries+ .form.loadWithParams({pageSize: 0,@@ -39,12 +40,16 @@ export class BoardListsService {this.CurrentProject.identifier,this.buildQueryRequest(params),)- .then(form => {+ .toPromise()+ .then(([form, query]) => {// When the permission to create public queries is missing, throw an error.// Otherwise private queries would be created.if (form.schema['public'].writable) {- const query = this.QueryFormDm.buildQueryResource(form);- return this.QueryDm.create(query, form);+ return this+ .apiV3Service+ .queries+ .post(query, form)+ .toPromise();} else {throw new Error(this.I18n.t('js.boards.error_permission_missing'));}@@ -97,8 +102,8 @@ export class BoardListsService {public: true,"_links": {"sortBy": [- { "href": this.v3.resource("/queries/sort_bys/manualSorting-asc") },- { "href": this.v3.resource("/queries/sort_bys/id-asc") },+ { "href": this.v3.apiV3Base + "/queries/sort_bys/manualSorting-asc" },+ { "href": this.v3.apiV3Base + "/queries/sort_bys/id-asc" },]},...paramsdiff --git a/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts b/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.tsindex 635b440596e..dbf5fed4378 100644--- a/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts+++ b/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts@@ -7,7 +7,6 @@ import {NotificationsService} from "core-app/modules/common/notifications/notifiimport {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";import {BoardListsService} from "core-app/modules/boards/board/board-list/board-lists.service";import {OpModalService} from "core-components/op-modals/op-modal.service";-import {BoardCacheService} from "core-app/modules/boards/board/board-cache.service";import {BoardService} from "core-app/modules/boards/board/board.service";import {BannersService} from "core-app/modules/common/enterprise/banners.service";import {DragAndDropService} from "core-app/modules/common/drag-and-drop/drag-and-drop.service";@@ -21,6 +20,7 @@ import {AddListModalComponent} from "core-app/modules/boards/board/add-list-modaimport {I18nService} from "core-app/modules/common/i18n/i18n.service";import {BoardListCrossSelectionService} from "core-app/modules/boards/board/board-list/board-list-cross-selection.service";import {filter} from "rxjs/operators";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './board-list-container.component.html',@@ -76,7 +76,7 @@ export class BoardListContainerComponent extends UntilDestroyedMixin implementsreadonly BoardList:BoardListsService,readonly opModalService:OpModalService,readonly injector:Injector,- readonly BoardCache:BoardCacheService,+ readonly apiV3Service:APIV3Service,readonly Boards:BoardService,readonly Banner:BannersService,readonly boardListCrossSelectionService:BoardListCrossSelectionService,@@ -88,7 +88,12 @@ export class BoardListContainerComponent extends UntilDestroyedMixin implementsngOnInit():void {const id:string = this.state.params.board_id.toString();- this.board$ = this.BoardCache.observe(id);+ this.board$ = this+ .apiV3Service+ .boards+ .id(id)+ .requireAndStream();+this.Boards.currentBoard$.next(id);this.board$@@ -125,10 +130,7 @@ export class BoardListContainerComponent extends UntilDestroyedMixin implementsif (board.isFree) {return this.BoardList.addFreeQuery(board, { name: this.text.unnamed_list })- .then(board => this.Boards.save(board))- .then(saved => {- this.BoardCache.update(saved);- })+ .then(board => this.Boards.save(board).toPromise()).catch(error => this.showError(error));} else {const active = this.getActionFiltersFromWidget(board);diff --git a/frontend/src/app/modules/boards/board/board-partitioned-page/board-partitioned-page.component.ts b/frontend/src/app/modules/boards/board/board-partitioned-page/board-partitioned-page.component.tsindex 9f7f9b19afb..e690ddac8b2 100644--- a/frontend/src/app/modules/boards/board/board-partitioned-page/board-partitioned-page.component.ts+++ b/frontend/src/app/modules/boards/board/board-partitioned-page/board-partitioned-page.component.ts@@ -9,22 +9,21 @@ import {BoardFilterComponent} from "core-app/modules/boards/board/board-filter/bimport {Board} from "core-app/modules/boards/board/board";import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";-import {BoardCacheService} from "core-app/modules/boards/board/board-cache.service";import {BoardService} from "core-app/modules/boards/board/board.service";import {DragAndDropService} from "core-app/modules/common/drag-and-drop/drag-and-drop.service";import {WorkPackageFilterButtonComponent} from "core-components/wp-buttons/wp-filter-button/wp-filter-button.component";import {ZenModeButtonComponent} from "core-components/wp-buttons/zen-mode-toggle-button/zen-mode-toggle-button.component";import {BoardsMenuButtonComponent} from "core-app/modules/boards/board/toolbar-menu/boards-menu-button.component";import {RequestSwitchmap} from "core-app/helpers/rxjs/request-switchmap";-import {from} from "rxjs";import {componentDestroyed} from "@w11k/ngx-componentdestroyed";-import {take} from "rxjs/operators";+import {finalize, take} from "rxjs/operators";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";import {QueryResource} from "core-app/modules/hal/resources/query-resource";import {Ng2StateDeclaration} from "@uirouter/angular";import {BoardFiltersService} from "core-app/modules/boards/board/board-filter/board-filters.service";import {CardViewHandlerRegistry} from "core-components/wp-card-view/event-handler/card-view-handler-registry";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export function boardCardViewHandlerFactory(injector:Injector) {return new CardViewHandlerRegistry(injector);@@ -59,7 +58,11 @@ export class BoardPartitionedPageComponent extends UntilDestroyedMixin {};/** Board observable */- board$ = this.BoardCache.observe(this.state.params.board_id.toString());+ board$ = this+ .apiV3Service+ .boards+ .id(this.state.params.board_id.toString())+ .observe();/** Whether this is a new board just created */isNew:boolean = !!this.state.params.isNew;@@ -104,18 +107,11 @@ export class BoardPartitionedPageComponent extends UntilDestroyedMixin {boardSaver = new RequestSwitchmap((board:Board) => {this.toolbarDisabled = true;- const promise = this.Boards+ return this.Boards.save(board)- .then(board => {- this.toolbarDisabled = false;- return board;- })- .catch((error) => {- this.toolbarDisabled = false;- throw error;- });-- return from(promise);+ .pipe(+ finalize(() => this.toolbarDisabled = false)+ );});@@ -145,7 +141,7 @@ export class BoardPartitionedPageComponent extends UntilDestroyedMixin {readonly notifications:NotificationsService,readonly halNotification:HalResourceNotificationService,readonly injector:Injector,- readonly BoardCache:BoardCacheService,+ readonly apiV3Service:APIV3Service,readonly boardFilters:BoardFiltersService,readonly Boards:BoardService) {super();@@ -159,7 +155,6 @@ export class BoardPartitionedPageComponent extends UntilDestroyedMixin {.observe(componentDestroyed(this)).subscribe((board:Board) => {- this.BoardCache.update(board);this.notifications.addSuccess(this.text.updateSuccessful);},(error:unknown) => this.halNotification.handleRawError(error)@@ -169,7 +164,7 @@ export class BoardPartitionedPageComponent extends UntilDestroyedMixin {const toState = transition.to();const params = transition.params('to');- this.showToolbarSaveButton = !!params.query_props+ this.showToolbarSaveButton = !!params.query_props;this.setPartition(toState);this.cdRef.detectChanges();});diff --git a/frontend/src/app/modules/boards/board/board.service.ts b/frontend/src/app/modules/boards/board/board.service.tsindex dbeadac996d..98e2537f3d5 100644--- a/frontend/src/app/modules/boards/board/board.service.ts+++ b/frontend/src/app/modules/boards/board/board.service.ts@@ -4,12 +4,11 @@ import {HalResourceService} from "core-app/modules/hal/services/hal-resource.serimport {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {CurrentProjectService} from "core-components/projects/current-project.service";import {Board, BoardType} from "core-app/modules/boards/board/board";-import {BoardDmService} from "core-app/modules/boards/board/board-dm.service";-import {BoardCacheService} from "core-app/modules/boards/board/board-cache.service";import {GridWidgetResource} from "core-app/modules/hal/resources/grid-widget-resource";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {BoardActionsRegistryService} from "core-app/modules/boards/board/board-actions/board-actions-registry.service";-import {BehaviorSubject} from "rxjs";+import {BehaviorSubject, Observable} from "rxjs";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export interface CreateBoardParams {type:BoardType;@@ -27,15 +26,14 @@ export class BoardService {private text = {unnamed_board: this.I18n.t('js.boards.label_unnamed_board'),action_board: (attr:string) => this.I18n.t('js.boards.board_type.action_by_attribute',- { attribute: this.I18n.t('js.boards.board_type.action_type.' + attr )}),+ { attribute: this.I18n.t('js.boards.board_type.action_type.' + attr) }),unnamed_list: this.I18n.t('js.boards.label_unnamed_list'),};- constructor(protected boardDm:BoardDmService,+ constructor(protected apiV3Service:APIV3Service,protected PathHelper:PathHelperService,protected CurrentProject:CurrentProjectService,protected halResourceService:HalResourceService,- protected boardCache:BoardCacheService,protected boardActions:BoardActionsRegistryService,protected I18n:I18nService,protected boardsList:BoardListsService) {@@ -51,13 +49,11 @@ export class BoardService {return this.loadAllPromise;}- return this.loadAllPromise = this.boardDm- .allInScope()- .toPromise()- .then((boards) => {- boards.forEach(b => this.buildOrderAndUpdate(b));- return boards;- });+ return this.loadAllPromise = this+ .apiV3Service+ .boards+ .allInScope(projectIdentifier!)+ .toPromise();}/**@@ -71,14 +67,13 @@ export class BoardService {/*** Save the changes to the board*/- public save(board:Board) {+ public save(board:Board):Observable<Board> {this.reorderWidgets(board);- return this.boardDm.save(board)- .then(board => {- board.sortWidgets();- this.boardCache.update(board);- return board;- });+ return this+ .apiV3Service+ .boards+ .id(board)+ .save(board);}/**@@ -86,7 +81,10 @@ export class BoardService {* @param name*/public async create(params:CreateBoardParams):Promise<Board> {- const board = await this.boardDm.create(params.type, this.boardName(params), params.attribute);+ const board = await this+ .apiV3Service+ .boards+ .create(params.type, this.boardName(params), this.CurrentProject.identifier!, params.attribute).toPromise();if (params.type === 'free') {await this.boardsList.addFreeQuery(board, { name: this.text.unnamed_list });@@ -94,15 +92,18 @@ export class BoardService {await this.boardActions.get(params.attribute!).addActionQueries(board);}- await this.save(board);+ await this.save(board).toPromise();return board;}- public delete(board:Board):Promise<void> {- return this.boardDm- .delete(board)- .then(() => this.boardCache.clearSome(board.id!));+ public delete(board:Board):Promise<unknown> {+ return this+ .apiV3Service+ .boards+ .id(board)+ .delete()+ .toPromise();}/**@@ -132,12 +133,4 @@ export class BoardService {return el;});}-- /**- * Put the board widgets in correct order and update cache- */- private buildOrderAndUpdate(board:Board) {- board.sortWidgets();- this.boardCache.update(board);- }}diff --git a/frontend/src/app/modules/boards/board/configuration-modal/board-configuration.modal.ts b/frontend/src/app/modules/boards/board/configuration-modal/board-configuration.modal.tsindex 825b10e45f1..3f291b6765e 100644--- a/frontend/src/app/modules/boards/board/configuration-modal/board-configuration.modal.ts+++ b/frontend/src/app/modules/boards/board/configuration-modal/board-configuration.modal.ts@@ -23,7 +23,6 @@ import {OpModalLocalsToken} from "core-components/op-modals/op-modal.service";import {BoardConfigurationService} from "core-app/modules/boards/board/configuration-modal/board-configuration.service";import {BoardService} from "core-app/modules/boards/board/board.service";import {Board} from "core-app/modules/boards/board/board";-import {BoardCacheService} from "core-app/modules/boards/board/board-cache.service";@Component({@@ -53,7 +52,6 @@ export class BoardConfigurationModal extends OpModalComponent implements OnInit,constructor(@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,readonly I18n:I18nService,readonly boardService:BoardService,- readonly boardCache:BoardCacheService,readonly boardConfigurationService:BoardConfigurationService,readonly injector:Injector,readonly appRef:ApplicationRef,@@ -104,8 +102,7 @@ export class BoardConfigurationModal extends OpModalComponent implements OnInit,const board = this.locals.board as Board;this.boardService.save(board)- .then(board => {- this.boardCache.update(board);+ .subscribe(board => {this.service.close();});diff --git a/frontend/src/app/modules/boards/board/inline-add/board-inline-add-autocompleter.component.ts b/frontend/src/app/modules/boards/board/inline-add/board-inline-add-autocompleter.component.tsindex b14cd1c7270..4ecb7ed3515 100644--- a/frontend/src/app/modules/boards/board/inline-add/board-inline-add-autocompleter.component.ts+++ b/frontend/src/app/modules/boards/board/inline-add/board-inline-add-autocompleter.component.ts@@ -51,6 +51,7 @@ import {SchemaCacheService} from "core-components/schemas/schema-cache.service";import {WorkPackageCardDragAndDropService} from "core-components/wp-card-view/services/wp-card-drag-and-drop.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";import {UrlParamsHelperService} from "core-components/wp-query/url-params-helper";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'board-inline-add-autocompleter',@@ -87,6 +88,7 @@ export class BoardInlineAddAutocompleterComponent implements AfterViewInit {constructor(private readonly querySpace:IsolatedQuerySpace,private readonly pathHelper:PathHelperService,+ private readonly apiV3Service:APIV3Service,private readonly urlParamsHelper:UrlParamsHelperService,private readonly notificationService:WorkPackageNotificationService,private readonly CurrentProject:CurrentProjectService,@@ -132,7 +134,6 @@ export class BoardInlineAddAutocompleterComponent implements AfterViewInit {return of([]);}- const path = this.pathHelper.api.v3.withOptionalProject(this.CurrentProject.id).work_packages;const filters:ApiV3FilterBuilder = new ApiV3FilterBuilder();const results = this.querySpace.results.value;@@ -149,8 +150,12 @@ export class BoardInlineAddAutocompleterComponent implements AfterViewInit {filters.merge(currentFilters, 'subprojectId');}- return this.halResourceService- .get<WorkPackageCollectionResource>(path.filtered(filters))+ return this+ .apiV3Service+ .withOptionalProject(this.CurrentProject.id)+ .work_packages+ .filtered(filters)+ .get().pipe(map(collection => collection.elements),catchError((error:unknown) => {diff --git a/frontend/src/app/modules/boards/board/query-updated/query-updated.service.ts b/frontend/src/app/modules/boards/board/query-updated/query-updated.service.tsindex d3917475b50..1ab00b4094a 100644--- a/frontend/src/app/modules/boards/board/query-updated/query-updated.service.ts+++ b/frontend/src/app/modules/boards/board/query-updated/query-updated.service.ts@@ -1,37 +1,43 @@import {Injectable} from "@angular/core";import {interval} from 'rxjs';import {startWith, switchMap, filter} from 'rxjs/operators';-import {QueryDmService} from "core-app/modules/hal/dm-services/query-dm.service";import {ActiveWindowService} from "core-app/modules/common/active-window/active-window.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";const POLLING_INTERVAL = 2000;@Injectable()export class QueryUpdatedService {- constructor(readonly queryDm:QueryDmService,- readonly activeWindow:ActiveWindowService) {}+ constructor(readonly activeWindow:ActiveWindowService,+ readonly apiV3Service:APIV3Service) {+ }public monitor(ids:string[]) {let time = new Date();return interval(POLLING_INTERVAL)- .pipe(- startWith(0),- filter(() => this.activeWindow.isActive),- switchMap(() => {- let result = this.queryForUpdates(ids, time);-- time = new Date();-- return result;- }),- filter((collection) => collection.count > 0)- );+ .pipe(+ startWith(0),+ filter(() => this.activeWindow.isActive),+ switchMap(() => {+ let result = this.queryForUpdates(ids, time);++ time = new Date();++ return result;+ }),+ filter((collection) => collection.count > 0)+ );}private queryForUpdates(ids:string[], updatedAfter:Date) {- return this.queryDm.list({filters: [["id", "=", ids],- ["updatedAt", "<>d", [updatedAfter.toISOString()]]]});+ return this+ .apiV3Service+ .queries+ .list({+ filters: [["id", "=", ids],+ ["updatedAt", "<>d", [updatedAfter.toISOString()]]]+ });}}diff --git a/frontend/src/app/modules/boards/board/toolbar-menu/boards-toolbar-menu.directive.ts b/frontend/src/app/modules/boards/board/toolbar-menu/boards-toolbar-menu.directive.tsindex fd4ab77dcd4..4939ea671e0 100644--- a/frontend/src/app/modules/boards/board/toolbar-menu/boards-toolbar-menu.directive.ts+++ b/frontend/src/app/modules/boards/board/toolbar-menu/boards-toolbar-menu.directive.ts@@ -36,7 +36,6 @@ import {BoardConfigurationModal} from "core-app/modules/boards/board/configuratiimport {BoardService} from "core-app/modules/boards/board/board.service";import {StateService} from "@uirouter/core";import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";-import {BoardCacheService} from "core-app/modules/boards/board/board-cache.service";import {triggerEditingEvent} from "core-app/modules/common/editable-toolbar-title/editable-toolbar-title.component";@Directive({@@ -53,7 +52,6 @@ export class BoardsToolbarMenuDirective extends OpContextMenuTrigger {readonly opContextMenu:OPContextMenuService,readonly opModalService:OpModalService,readonly boardService:BoardService,- readonly BoardCache:BoardCacheService,readonly Notifications:NotificationsService,readonly State:StateService,readonly injector:Injector,@@ -109,7 +107,6 @@ export class BoardsToolbarMenuDirective extends OpContextMenuTrigger {this.boardService.delete(this.board).then(() => {- this.BoardCache.clearSome(this.board.id!);this.State.go('^', { flash_message: { type: 'success', message: this.text.deleteSuccessful } });});}diff --git a/frontend/src/app/modules/boards/boards-sidebar/boards-menu.component.ts b/frontend/src/app/modules/boards/boards-sidebar/boards-menu.component.tsindex 95f72ac9b1a..531d2a4b78f 100644--- a/frontend/src/app/modules/boards/boards-sidebar/boards-menu.component.ts+++ b/frontend/src/app/modules/boards/boards-sidebar/boards-menu.component.ts@@ -2,12 +2,12 @@ import {Component, OnInit} from "@angular/core";import {Observable} from "rxjs";import {BoardService} from "core-app/modules/boards/board/board.service";import {Board} from "core-app/modules/boards/board/board";-import {BoardCacheService} from "core-app/modules/boards/board/board-cache.service";import {AngularTrackingHelpers} from "core-components/angular/tracking-functions";import {MainMenuNavigationService} from "core-components/main-menu/main-menu-navigation.service";import {map} from "rxjs/operators";import {CurrentProjectService} from "core-components/projects/current-project.service";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export const boardsMenuSelector = 'boards-menu';@@ -23,22 +23,26 @@ export class BoardsMenuComponent extends UntilDestroyedMixin implements OnInit {selectedBoardId:string;- public boards$:Observable<Board[]> = this.boardCache.observeAll().pipe(- map((boards:Board[]) => {- return boards.sort(function (a, b) {- if (a.name < b.name) {- return -1;- }- if (a.name > b.name) {- return 1;- }- return 0;- });- })- );+ public boards$:Observable<Board[]> = this+ .apiV3Service+ .boards+ .observeAll()+ .pipe(+ map((boards:Board[]) => {+ return boards.sort(function (a, b) {+ if (a.name < b.name) {+ return -1;+ }+ if (a.name > b.name) {+ return 1;+ }+ return 0;+ });+ })+ );constructor(private readonly boardService:BoardService,- private readonly boardCache:BoardCacheService,+ private readonly apiV3Service:APIV3Service,private readonly currentProject:CurrentProjectService,private readonly mainMenuService:MainMenuNavigationService) {super();diff --git a/frontend/src/app/modules/boards/index-page/boards-index-page.component.ts b/frontend/src/app/modules/boards/index-page/boards-index-page.component.tsindex 2a4a5fa09f6..f8b22c1b38f 100644--- a/frontend/src/app/modules/boards/index-page/boards-index-page.component.ts+++ b/frontend/src/app/modules/boards/index-page/boards-index-page.component.ts@@ -3,7 +3,6 @@ import {Observable} from "rxjs";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {BoardService} from "core-app/modules/boards/board/board.service";import {Board} from "core-app/modules/boards/board/board";-import {BoardCacheService} from "core-app/modules/boards/board/board-cache.service";import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";import {OpModalService} from "core-components/op-modals/op-modal.service";import {NewBoardModalComponent} from "core-app/modules/boards/new-board-modal/new-board-modal.component";@@ -15,6 +14,7 @@ import {DomSanitizer} from "@angular/platform-browser";import {boardTeaserVideoURL} from "core-app/modules/boards/board-constants.const";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";import {componentDestroyed} from "@w11k/ngx-componentdestroyed";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './boards-index-page.component.html',@@ -44,12 +44,15 @@ export class BoardsIndexPageComponent extends UntilDestroyedMixin implements OnIpublic canAdd = false;- public boards$:Observable<Board[]> = this.boardCache.observeAll();+ public boards$:Observable<Board[]> = this+ .apiV3Service+ .boards+ .observeAll();teaserVideoURL = this.domSanitizer.bypassSecurityTrustResourceUrl(boardTeaserVideoURL);constructor(private readonly boardService:BoardService,- private readonly boardCache:BoardCacheService,+ private readonly apiV3Service:APIV3Service,private readonly I18n:I18nService,private readonly notifications:NotificationsService,private readonly opModalService:OpModalService,@@ -86,7 +89,6 @@ export class BoardsIndexPageComponent extends UntilDestroyedMixin implements OnIthis.boardService.delete(board).then(() => {- this.boardCache.clearSome(board.id!);this.notifications.addSuccess(this.text.deleteSuccessful);}).catch((error) => this.notifications.addError("Deletion failed: " + error));diff --git a/frontend/src/app/modules/boards/new-board-modal/new-board-modal.component.ts b/frontend/src/app/modules/boards/new-board-modal/new-board-modal.component.tsindex 283ad095a39..65d0abf195e 100644--- a/frontend/src/app/modules/boards/new-board-modal/new-board-modal.component.ts+++ b/frontend/src/app/modules/boards/new-board-modal/new-board-modal.component.ts@@ -34,7 +34,6 @@ import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {BoardType} from "core-app/modules/boards/board/board";import {StateService} from "@uirouter/core";import {BoardService} from "core-app/modules/boards/board/board.service";-import {BoardCacheService} from "core-app/modules/boards/board/board-cache.service";import {BoardActionsRegistryService} from "core-app/modules/boards/board/board-actions/board-actions-registry.service";import {LoadingIndicatorService} from "core-app/modules/common/loading-indicator/loading-indicator.service";import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";@@ -71,7 +70,6 @@ export class NewBoardModalComponent extends OpModalComponent {readonly state:StateService,readonly boardService:BoardService,readonly boardActions:BoardActionsRegistryService,- readonly boardCache:BoardCacheService,readonly halNotification:HalResourceNotificationService,readonly loadingIndicatorService:LoadingIndicatorService,readonly I18n:I18nService) {@@ -95,7 +93,6 @@ export class NewBoardModalComponent extends OpModalComponent {.then((board) => {this.inFlight = false;this.closeMe();- this.boardCache.update(board);this.state.go('boards.partitioned.show', { board_id: board.id, isNew: true });}).catch((error:unknown) => {diff --git a/frontend/src/app/modules/calendar/te-calendar/te-calendar.component.ts b/frontend/src/app/modules/calendar/te-calendar/te-calendar.component.tsindex f0953c27f59..ba46a218d1d 100644--- a/frontend/src/app/modules/calendar/te-calendar/te-calendar.component.ts+++ b/frontend/src/app/modules/calendar/te-calendar/te-calendar.component.ts@@ -24,12 +24,10 @@ import {Duration, EventApi, EventInput, View} from '@fullcalendar/core';import {EventSourceError} from '@fullcalendar/core/structs/event-source';import {ToolbarInput} from '@fullcalendar/core/types/input-types';import {ConfigurationService} from "core-app/modules/common/config/configuration.service";-import {TimeEntryDmService} from "core-app/modules/hal/dm-services/time-entry-dm.service";import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";import {TimezoneService} from "core-components/datetime/timezone.service";import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";-import {TimeEntryCacheService} from "core-components/time-entries/time-entry-cache.service";import interactionPlugin from '@fullcalendar/interaction';import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";import {TimeEntryEditService} from "core-app/modules/time_entries/edit/edit.service";@@ -37,6 +35,7 @@ import {TimeEntryCreateService} from "core-app/modules/time_entries/create/creatimport {ColorsService} from "core-app/modules/common/colors/colors.service";import {BrowserDetector} from "core-app/modules/common/browser/browser-detector.service";import {HalResourceNotificationService} from 'core-app/modules/hal/services/hal-resource-notification.service';+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";interface CalendarViewEvent {el:HTMLElement;@@ -117,7 +116,7 @@ export class TimeEntryCalendarComponent implements OnInit, AfterViewInit {};constructor(readonly states:States,- readonly timeEntryDm:TimeEntryDmService,+ readonly apiV3Service:APIV3Service,readonly $state:StateService,private element:ElementRef,readonly i18n:I18nService,@@ -128,7 +127,6 @@ export class TimeEntryCalendarComponent implements OnInit, AfterViewInit {private timezone:TimezoneService,private timeEntryEdit:TimeEntryEditService,private timeEntryCreate:TimeEntryCreateService,- private timeEntryCache:TimeEntryCacheService,private colors:ColorsService,private browserDetector:BrowserDetector) {}@@ -172,13 +170,13 @@ export class TimeEntryCalendarComponent implements OnInit, AfterViewInit {this.memoizedTimeEntries.start.getTime() !== start.getTime() ||this.memoizedTimeEntries.end.getTime() !== end.getTime()) {let promise = this- .timeEntryDm+ .apiV3Service+ .time_entries.list({ filters: this.dmFilters(start, end), pageSize: 500 })+ .toPromise().then(collection => {this.memoizedCreateAllowed = !!collection.createTimeEntry;- collection.elements.forEach(timeEntry => this.timeEntryCache.updateValue(timeEntry.id!, timeEntry));-return collection;});@@ -387,16 +385,19 @@ export class TimeEntryCalendarComponent implements OnInit, AfterViewInit {// on the day before by fullcalendar.entry.spentOn = moment(event.event.end!).format('YYYY-MM-DD');+this- .timeEntryDm- .update(entry, entry.schema)- .then(event => {- this.updateEventSet(event, 'update');- })- .catch((e) => {- this.notifications.handleRawError(e);- event.revert();- });+ .apiV3Service+ .time_entries+ .id(entry)+ .patch(entry, entry.schema)+ .subscribe(+ event => this.updateEventSet(event, 'update'),+ e => {+ this.notifications.handleRawError(e);+ event.revert();+ }+ );}public addEventToday() {@@ -431,7 +432,12 @@ export class TimeEntryCalendarComponent implements OnInit, AfterViewInit {collection.elements.splice(foundIndex, 1);break;case 'create':- this.timeEntryCache.updateValue(event.id!, event);+ this+ .apiV3Service+ .time_entries+ .cache+ .updateFor(event);+collection.elements.push(event);break;}diff --git a/frontend/src/app/modules/common/autocomplete/user-autocompleter.component.ts b/frontend/src/app/modules/common/autocomplete/user-autocompleter.component.tsindex 9261ae41b24..9dd102dfa01 100644--- a/frontend/src/app/modules/common/autocomplete/user-autocompleter.component.ts+++ b/frontend/src/app/modules/common/autocomplete/user-autocompleter.component.ts@@ -37,6 +37,7 @@ import {DebouncedRequestSwitchmap, errorNotificationHandler} from "core-app/helpimport {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";import {NgSelectComponent} from "@ng-select/ng-select";import {UserResource} from "core-app/modules/hal/resources/user-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export const usersAutocompleterSelector = 'user-autocompleter';@@ -52,7 +53,7 @@ export class UserAutocompleterComponent implements OnInit {@Input() public clearAfterSelection:boolean = false;// Load all users as default- @Input() public url:string = this.pathHelper.api.v3.users.path;+ @Input() public url:string = this.apiV3Service.users.path;@Input() public allowEmpty:boolean = false;@Input() public appendTo:string = '';@Input() public multiple:boolean = false;@@ -75,6 +76,7 @@ export class UserAutocompleterComponent implements OnInit {protected I18n:I18nService,protected halNotification:HalResourceNotificationService,readonly pathHelper:PathHelperService,+ readonly apiV3Service:APIV3Service,readonly injector:Injector) {}diff --git a/frontend/src/app/modules/common/autocomplete/version-autocompleter.component.ts b/frontend/src/app/modules/common/autocomplete/version-autocompleter.component.tsindex cd58af8e42b..94a15c3d732 100644--- a/frontend/src/app/modules/common/autocomplete/version-autocompleter.component.ts+++ b/frontend/src/app/modules/common/autocomplete/version-autocompleter.component.ts@@ -27,13 +27,13 @@// ++import {AfterViewInit, ChangeDetectorRef, Component, EventEmitter, Input, Output} from '@angular/core';-import {VersionDmService} from "core-app/modules/hal/dm-services/version-dm.service";import {CurrentProjectService} from "core-components/projects/current-project.service";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {VersionResource} from "core-app/modules/hal/resources/version-resource";import {CreateAutocompleterComponent} from "core-app/modules/common/autocomplete/create-autocompleter.component";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './create-autocompleter.component.html',@@ -47,7 +47,7 @@ export class VersionAutocompleterComponent extends CreateAutocompleterComponentreadonly currentProject:CurrentProjectService,readonly cdRef:ChangeDetectorRef,readonly pathHelper:PathHelperService,- readonly versionDm:VersionDmService,+ readonly apiV3Service:APIV3Service,readonly halNotification:HalResourceNotificationService) {super(I18n, cdRef, currentProject, pathHelper);}@@ -73,20 +73,26 @@ export class VersionAutocompleterComponent extends CreateAutocompleterComponentreturn Promise.resolve(false);}- return this.versionDm- .canCreateVersionInProject(this.currentProject.id!)+ return this+ .apiV3Service+ .versions+ .available_projects+ .exists(this.currentProject.id!)+ .toPromise().catch(() => false);}protected createNewVersion(name:string) {- this.versionDm.createVersion(this.getVersionPayload(name))- .then((version) => {- this.onCreate.emit(version);- })- .catch(error => {- this.closeSelect();- this.halNotification.handleRawError(error);- });+ this+ .apiV3Service+ .versions+ .post(this.getVersionPayload(name))+ .subscribe(+ version => this.onCreate.emit(version),+ error => {+ this.closeSelect();+ this.halNotification.handleRawError(error);+ });}private getVersionPayload(name:string) {@@ -94,7 +100,7 @@ export class VersionAutocompleterComponent extends CreateAutocompleterComponentpayload['name'] = name;payload['_links'] = {definingProject: {- href: this.pathHelper.api.v3.projects.id(this.currentProject.id!).path+ href: this.apiV3Service.projects.id(this.currentProject.id!).path}};diff --git a/frontend/src/app/modules/common/config/configuration.service.ts b/frontend/src/app/modules/common/config/configuration.service.tsindex 9d4ea60cec0..9b8d4c46133 100644--- a/frontend/src/app/modules/common/config/configuration.service.ts+++ b/frontend/src/app/modules/common/config/configuration.service.ts@@ -28,9 +28,9 @@import {Injectable} from '@angular/core';import {I18nService} from 'core-app/modules/common/i18n/i18n.service';-import {ConfigurationDmService} from "core-app/modules/hal/dm-services/configuration-dm.service";import {ConfigurationResource} from "core-app/modules/hal/resources/configuration-resource";import * as moment from "moment";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable({ providedIn: 'root' })export class ConfigurationService {@@ -41,7 +41,7 @@ export class ConfigurationService {public initialized:Promise<Boolean>;public constructor(readonly I18n:I18nService,- readonly configurationDm:ConfigurationDmService) {+ readonly apiV3Service:APIV3Service) {this.initialized = this.loadConfiguration().then(() => true).catch(() => false);}@@ -57,11 +57,11 @@ export class ConfigurationService {return this.userPreference('autoHidePopups');}- public isTimezoneSet() {+ public isTimezoneSet() {return !!this.timezone();}- public timezone() {+ public timezone() {return this.userPreference('timeZone');}@@ -73,27 +73,27 @@ export class ConfigurationService {return this.systemPreference('perPageOptions');}- public dateFormatPresent() {+ public dateFormatPresent() {return !!this.systemPreference('dateFormat');}- public dateFormat() {+ public dateFormat() {return this.systemPreference('dateFormat');}- public timeFormatPresent() {+ public timeFormatPresent() {return !!this.systemPreference('timeFormat');}- public timeFormat() {+ public timeFormat() {return this.systemPreference('timeFormat');}- public startOfWeekPresent() {+ public startOfWeekPresent() {return !!this.systemPreference('startOfWeek');}- public startOfWeek() {+ public startOfWeek() {if (this.startOfWeekPresent()) {return this.systemPreference('startOfWeek');} else {@@ -102,9 +102,14 @@ export class ConfigurationService {}private loadConfiguration() {- return this.configurationDm.load().toPromise().then((configuration) => {- this.configuration = configuration;- });+ return this+ .apiV3Service+ .configuration+ .get()+ .toPromise()+ .then((configuration) => {+ this.configuration = configuration;+ });}private userPreference(pref:string) {diff --git a/frontend/src/app/modules/common/drag-and-drop/reorder-delta-builder.spec.ts b/frontend/src/app/modules/common/drag-and-drop/reorder-delta-builder.spec.tsindex ab9ba255070..ff9c05544ab 100644--- a/frontend/src/app/modules/common/drag-and-drop/reorder-delta-builder.spec.ts+++ b/frontend/src/app/modules/common/drag-and-drop/reorder-delta-builder.spec.ts@@ -26,12 +26,12 @@// See docs/COPYRIGHT.rdoc for more details.// ++-import {QueryOrder} from "core-app/modules/hal/dm-services/query-order-dm.service";import {DEFAULT_ORDER,MAX_ORDER,ReorderDeltaBuilder} from "core-app/modules/common/drag-and-drop/reorder-delta-builder";+import {QueryOrder} from "core-app/modules/apiv3/endpoints/queries/apiv3-query-order";describe('ReorderDeltaBuilder', () => {const work_packages:string[] = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];diff --git a/frontend/src/app/modules/common/drag-and-drop/reorder-delta-builder.ts b/frontend/src/app/modules/common/drag-and-drop/reorder-delta-builder.tsindex 489df5386fc..1cf7a6b0257 100644--- a/frontend/src/app/modules/common/drag-and-drop/reorder-delta-builder.ts+++ b/frontend/src/app/modules/common/drag-and-drop/reorder-delta-builder.ts@@ -1,5 +1,5 @@-import {QueryOrder} from "core-app/modules/hal/dm-services/query-order-dm.service";import {debugLog, timeOutput} from "core-app/helpers/debug_output";+import {QueryOrder} from "core-app/modules/apiv3/endpoints/queries/apiv3-query-order";// min allowed positionexport const MIN_ORDER = -2147483647;diff --git a/frontend/src/app/modules/common/help-texts/attribute-help-text.component.ts b/frontend/src/app/modules/common/help-texts/attribute-help-text.component.tsindex a60485d6536..6af037ea383 100644--- a/frontend/src/app/modules/common/help-texts/attribute-help-text.component.ts+++ b/frontend/src/app/modules/common/help-texts/attribute-help-text.component.ts@@ -27,7 +27,6 @@// ++import {AttributeHelpTextsService} from './attribute-help-text.service';-import {HelpTextDmService} from 'core-app/modules/hal/dm-services/help-text-dm.service';import {ChangeDetectionStrategy,ChangeDetectorRef,@@ -67,7 +66,6 @@ export class AttributeHelpTextComponent implements OnInit {};constructor(protected elementRef:ElementRef,- protected helpTextDm:HelpTextDmService,protected attributeHelpTexts:AttributeHelpTextsService,protected opModalService:OpModalService,protected cdRef:ChangeDetectorRef,@@ -105,7 +103,7 @@ export class AttributeHelpTextComponent implements OnInit {private load() {if (this.helpTextId) {- return this.helpTextDm.load(this.helpTextId);+ return this.attributeHelpTexts.requireById(this.helpTextId);} else {return this.attributeHelpTexts.require(this.attribute, this.attributeScope);}diff --git a/frontend/src/app/modules/common/help-texts/attribute-help-text.service.ts b/frontend/src/app/modules/common/help-texts/attribute-help-text.service.tsindex 31e5aebac4a..1f9bbf85656 100644--- a/frontend/src/app/modules/common/help-texts/attribute-help-text.service.ts+++ b/frontend/src/app/modules/common/help-texts/attribute-help-text.service.ts@@ -28,15 +28,21 @@import {input} from 'reactivestates';import {HelpTextResource} from 'core-app/modules/hal/resources/help-text-resource';-import {HelpTextDmService} from 'core-app/modules/hal/dm-services/help-text-dm.service';import {Injectable} from '@angular/core';import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {Observable} from "rxjs";+import {APIv3ResourceCollection} from "core-app/modules/apiv3/paths/apiv3-resource";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {ProjectResource} from "core-app/modules/hal/resources/project-resource";+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";+import {take} from "rxjs/operators";@Injectable({ providedIn: 'root' })export class AttributeHelpTextsService {private helpTexts = input<HelpTextResource[]>();- constructor(private helpTextDm:HelpTextDmService) {+ constructor(private apiV3Service:APIV3Service) {}/**@@ -46,11 +52,7 @@ export class AttributeHelpTextsService {* @param scope*/public require(attribute:string, scope:string):Promise<HelpTextResource|undefined> {- this.helpTexts.putFromPromiseIfPristine(() =>- this.helpTextDm- .loadAll()- .then((resources:CollectionResource<HelpTextResource>) => resources.elements)- );+ this.load();return new Promise<HelpTextResource|undefined>((resolve, reject) => {this.helpTexts@@ -59,6 +61,37 @@ export class AttributeHelpTextsService {});}+ /**+ * Search for a given attribute help text+ *+ */+ public requireById(id:string):Promise<HelpTextResource|undefined> {+ this.load();++ return this+ .helpTexts+ .values$()+ .pipe(+ take(1)+ )+ .toPromise()+ .then(() => {+ const value = this.helpTexts.getValueOr([]);+ return _.find(value, element => element.id.toString() === id);+ });+ }++ private load():void {+ this.helpTexts.putFromPromiseIfPristine(() =>+ this.apiV3Service+ .help_texts+ .get()+ .toPromise()+ .then((resources:CollectionResource<HelpTextResource>) => resources.elements)+ );++ }+private find(attribute:string, scope:string):HelpTextResource|undefined {const value = this.helpTexts.getValueOr([]);return _.find(value, (element) => element.scope === scope && element.attribute === attribute);diff --git a/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.tsdeleted file mode 100644index 84ba50d6dde..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts+++ /dev/null@@ -1,181 +0,0 @@-// -- 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 {ApiV3WorkPackagesPaths} from 'core-app/modules/common/path-helper/apiv3/work_packages/apiv3-work-packages-paths';-import {Apiv3UsersPaths} from 'core-app/modules/common/path-helper/apiv3/users/apiv3-users-paths';-import {Apiv3ProjectsPaths} from 'core-app/modules/common/path-helper/apiv3/projects/apiv3-projects-paths';-import {- SimpleResource,- SimpleResourceCollection-} from 'core-app/modules/common/path-helper/apiv3/path-resources';-import {Apiv3QueriesPaths} from 'core-app/modules/common/path-helper/apiv3/queries/apiv3-queries-paths';-import {Apiv3ProjectPaths} from 'core-app/modules/common/path-helper/apiv3/projects/apiv3-project-paths';-import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder";-import {Apiv3TypesPaths} from "core-app/modules/common/path-helper/apiv3/types/apiv3-types-paths";-import {Apiv3GridsPaths} from "core-app/modules/common/path-helper/apiv3/grids/apiv3-grids-paths";-import {Apiv3NewsesPaths} from "core-app/modules/common/path-helper/apiv3/news/apiv3-newses-paths";-import {Apiv3TimeEntriesPaths} from "core-app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entries-paths";-import {Apiv3VersionPaths} from "core-app/modules/common/path-helper/apiv3/versions/apiv3-version-paths";-import {Apiv3MembershipsPaths} from "core-app/modules/common/path-helper/apiv3/memberships/apiv3-memberships-paths";-import {Apiv3GroupsPaths} from "core-app/modules/common/path-helper/apiv3/groups/apiv3-groups-path";--export class ApiV3Paths {- // Base path- public readonly apiV3Base = this.appBasePath + '/api/v3';-- // /api/v3/attachments- public readonly attachments = new SimpleResource(this.apiV3Base, 'attachments');-- // /api/v3/configuration- public readonly configuration = new SimpleResource(this.apiV3Base, 'configuration');-- // /api/v3/root- public readonly root = new SimpleResource(this.apiV3Base, '');-- // /api/v3/statuses- public readonly statuses = new SimpleResourceCollection(this.apiV3Base, 'statuses');-- // /api/v3/relations- public readonly relations = new SimpleResourceCollection(this.apiV3Base, 'relations');-- // /api/v3/priorities- public readonly priorities = new SimpleResourceCollection(this.apiV3Base, 'priorities');-- // /api/v3/time_entries- public readonly time_entries = new Apiv3TimeEntriesPaths(this.apiV3Base);-- // /api/v3/memberships- public readonly memberships = new Apiv3MembershipsPaths(this.apiV3Base);-- // /api/v3/news- public readonly news = new Apiv3NewsesPaths(this.apiV3Base);-- // /api/v3/types- public readonly types = new Apiv3TypesPaths(this.apiV3Base);-- // /api/v3/versions- public readonly versions = new Apiv3VersionPaths(this.apiV3Base);-- // /api/v3/work_packages- public readonly work_packages = new ApiV3WorkPackagesPaths(this.apiV3Base);-- // /api/v3/queries- public readonly queries = new Apiv3QueriesPaths(this.apiV3Base);-- // /api/v3/projects- public readonly projects = new Apiv3ProjectsPaths(this.apiV3Base);-- // /api/v3/users- public readonly users = new Apiv3UsersPaths(this.apiV3Base);-- // /api/v3/help_texts- public readonly help_texts = new SimpleResourceCollection(this.apiV3Base, 'help_texts');-- // /api/v3/grids- public readonly grids = new Apiv3GridsPaths(this.apiV3Base);-- // /api/v3/groups- public readonly groups = new Apiv3GroupsPaths(this.apiV3Base);-- // /api/v3/job_statuses- public readonly job_statuses = new SimpleResourceCollection(this.apiV3Base, 'job_statuses');-- constructor(readonly appBasePath:string) {- }-- /**- * Returns possible subpaths either in this api root or below /projects/:id/- *- * @param {string | number} projectIdentifier- * @returns {Apiv3ProjectPaths | this}- */- public withOptionalProject(projectIdentifier:string|number|null|undefined):Apiv3ProjectPaths|this {- if (_.isNil(projectIdentifier)) {- return this;- } else {- return this.projects.id(projectIdentifier);- }- }-- /**- * returns a resource segment from (/base)/api/v3/(resource)- * @param segment- */- public resource(segment:string) {- if (!segment.startsWith('/')) {- segment = '/' + segment;- }-- return this.apiV3Base + segment;- }-- public previewMarkup(context:string) {- let base = this.apiV3Base + '/render/markdown';-- if (context) {- return base + `?context=${context}`;- } else {- return base;- }- }-- public principals(projectId:string|number, term:string|null) {- let filters:ApiV3FilterBuilder = new ApiV3FilterBuilder();- // Only real and activated users:- filters.add('status', '!', ['3']);- // that are members of that project:- filters.add('member', '=', [projectId.toString()]);- // That are users:- filters.add('type', '=', ['User', 'Group']);- // That are not the current user:- filters.add('id', '!', ['me']);-- if (term && term.length > 0) {- // Containing the that substring:- filters.add('name', '~', [term]);- }-- return this.apiV3Base +- '/principals?' +- filters.toParams({ sortBy: '[["name","asc"]]', offset: '1', pageSize: '10' });- }-- public wpBySubjectOrId(term:string, idOnly:boolean = false) {- let filters:ApiV3FilterBuilder = new ApiV3FilterBuilder();-- if (idOnly) {- filters.add('id', '=', [term]);- } else {- filters.add('subjectOrId', '**', [term]);- }-- return this.apiV3Base +- '/work_packages?' +- filters.toParams({ sortBy: '[["updatedAt","desc"]]', offset: '1', pageSize: '10' });- }-}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/memberships/apiv3-memberships-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/memberships/apiv3-memberships-paths.tsdeleted file mode 100644index 8571e6236fd..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/memberships/apiv3-memberships-paths.ts+++ /dev/null@@ -1,39 +0,0 @@-// -- 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 {SimpleResourceCollection} from 'core-app/modules/common/path-helper/apiv3/path-resources';--export class Apiv3MembershipsPaths extends SimpleResourceCollection {- constructor(basePath:string) {- super(basePath, 'memberships');- }-- // /api/v3/memberships/available_projects- public readonly available_projects = this.path + '/available_projects';--}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/news/apiv3-news-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/news/apiv3-news-paths.tsdeleted file mode 100644index 0574bb48b55..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/news/apiv3-news-paths.ts+++ /dev/null@@ -1,37 +0,0 @@-// -- 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 Apiv3NewsPaths extends SimpleResource {- constructor(basePath:string, newsId:string|number) {- super(basePath, newsId);- }-}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/projects/apiv3-project-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/projects/apiv3-project-paths.tsdeleted file mode 100644index b2a29eb9a7b..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/projects/apiv3-project-paths.ts+++ /dev/null@@ -1,53 +0,0 @@-// -- 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';-import {Apiv3QueriesPaths} from 'core-app/modules/common/path-helper/apiv3/queries/apiv3-queries-paths';-import {Apiv3TypesPaths} from "core-app/modules/common/path-helper/apiv3/types/apiv3-types-paths";-import {ApiV3WorkPackagesPaths} from "core-app/modules/common/path-helper/apiv3/work_packages/apiv3-work-packages-paths";-import {Apiv3VersionPaths} from "core-app/modules/common/path-helper/apiv3/versions/apiv3-version-paths";--export class Apiv3ProjectPaths extends SimpleResource {- // Base path- public readonly path:string;-- constructor(projectPath:string, readonly projectId:string|number) {- super(projectPath, projectId);- }-- // /api/v3/projects/:project_id/available_assignees- public readonly available_assignees = this.path + '/available_assignees';-- public readonly queries = new Apiv3QueriesPaths(this.path);-- public readonly types = new Apiv3TypesPaths(this.path);-- public readonly work_packages = new ApiV3WorkPackagesPaths(this.path);-- public readonly versions = new Apiv3VersionPaths(this.path);-}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/projects/apiv3-projects-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/projects/apiv3-projects-paths.tsdeleted file mode 100644index 9fefe7ae56a..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/projects/apiv3-projects-paths.ts+++ /dev/null@@ -1,44 +0,0 @@-// -- 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 {SimpleResourceCollection} from 'core-app/modules/common/path-helper/apiv3/path-resources';-import {Apiv3ProjectPaths} from 'core-app/modules/common/path-helper/apiv3/projects/apiv3-project-paths';--export class Apiv3ProjectsPaths extends SimpleResourceCollection<Apiv3ProjectPaths> {- constructor(basePath:string) {- super(basePath, 'projects');- }-- // /api/v3/projects/:projectIdentifier- public id(projectIdentifier:string|number):Apiv3ProjectPaths {- return new Apiv3ProjectPaths(this.path, projectIdentifier);- }-- // /api/v3/projects/schema- public readonly schema = this.path + '/schema';-}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.tsdeleted file mode 100644index ce29398ab60..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/queries/apiv3-queries-paths.ts+++ /dev/null@@ -1,55 +0,0 @@-// -- 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,- 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) {- super(basePath, 'queries');- }-- // Static paths- readonly form = new SimpleResource(this.path, 'form');-- readonly default = new SimpleResource(this.path, 'default');-- // /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.tsdeleted file mode 100644index efbedccc3cb..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/queries/apiv3-query-filter-instance-schema-paths.ts+++ /dev/null@@ -1,35 +0,0 @@-// -- 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/queries/apiv3-query-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/queries/apiv3-query-paths.tsdeleted file mode 100644index 9cd0966e308..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/queries/apiv3-query-paths.ts+++ /dev/null@@ -1,41 +0,0 @@-// -- 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 Apiv3QueryPaths extends SimpleResource {- constructor(basePath:string, queryId:string|number) {- super(basePath, queryId);- }-- // Static paths- readonly form = new SimpleResource(this.path, 'form');-- // Order path- readonly order = new SimpleResource(this.path, 'order');-}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.tsdeleted file mode 100644index 4552c9200c7..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entries-paths.ts+++ /dev/null@@ -1,46 +0,0 @@-// -- 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,- SimpleResourceCollection-} from 'core-app/modules/common/path-helper/apiv3/path-resources';-import {Apiv3TimeEntryPaths} from "core-app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entry-paths";--export class Apiv3TimeEntriesPaths extends SimpleResourceCollection {- constructor(basePath:string) {- super(basePath, 'time_entries');- }-- public id(timeEntryId:string|number) {- return new Apiv3TimeEntryPaths(this.path, timeEntryId);- }-- // Static paths- public readonly form = new SimpleResource(this.path, 'form');-}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entry-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entry-paths.tsdeleted file mode 100644index b1b0104dc35..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/time-entries/apiv3-time-entry-paths.ts+++ /dev/null@@ -1,40 +0,0 @@-// -- 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 Apiv3TimeEntryPaths extends SimpleResource {- constructor(basePath:string, newsId:string|number) {- super(basePath, newsId);- }-- // Static paths- readonly form = new SimpleResource(this.path, 'form');-}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/types/apiv3-types-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/types/apiv3-types-paths.tsdeleted file mode 100644index 95547394586..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/types/apiv3-types-paths.ts+++ /dev/null@@ -1,38 +0,0 @@-// -- 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 {- 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';--export class Apiv3TypesPaths extends SimpleResourceCollection<Apiv3QueryPaths> {- constructor(basePath:string) {- super(basePath, 'types');- }-}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/versions/apiv3-version-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/versions/apiv3-version-paths.tsdeleted file mode 100644index 82591e747c9..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/versions/apiv3-version-paths.ts+++ /dev/null@@ -1,45 +0,0 @@-// -- 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,- SimpleResourceCollection-} from 'core-app/modules/common/path-helper/apiv3/path-resources';--export class Apiv3VersionPaths extends SimpleResourceCollection {- // Base path- public readonly path:string;- // /api/v3/versions/form- public readonly form = new SimpleResource(this.path, 'form');-- public readonly availableProjects = new SimpleResource(this.path, 'available_projects');-- constructor(basePath:string) {- super(basePath, 'versions');- }-}diff --git a/frontend/src/app/modules/common/path-helper/apiv3/work_packages/apiv3-work-packages-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/work_packages/apiv3-work-packages-paths.tsdeleted file mode 100644index 40504aa2e08..00000000000--- a/frontend/src/app/modules/common/path-helper/apiv3/work_packages/apiv3-work-packages-paths.ts+++ /dev/null@@ -1,52 +0,0 @@-// -- 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 {ApiV3WorkPackagePaths} from 'core-app/modules/common/path-helper/apiv3/work_packages/apiv3-work-package-paths';-import {- SimpleResource,- SimpleResourceCollection-} from 'core-app/modules/common/path-helper/apiv3/path-resources';--export class ApiV3WorkPackagesPaths extends SimpleResourceCollection<ApiV3WorkPackagePaths> {- // Base path- public readonly path:string;-- constructor(basePath:string) {- super(basePath, 'work_packages');- }-- // Static paths-- // /api/v3/(projects/:projectIdentifier)/work_packages/form- public readonly form = new SimpleResource(this.path, 'form');-- // /api/v3/(projects/:projectIdentifier)/work_packages/:workPackageId- public id(workPackageId:string|number):ApiV3WorkPackagePaths {- return new ApiV3WorkPackagePaths(this.path, workPackageId);- }-}diff --git a/frontend/src/app/modules/common/path-helper/path-helper.service.ts b/frontend/src/app/modules/common/path-helper/path-helper.service.tsindex aba5e9596c4..0891da9900d 100644--- a/frontend/src/app/modules/common/path-helper/path-helper.service.ts+++ b/frontend/src/app/modules/common/path-helper/path-helper.service.ts@@ -26,21 +26,71 @@// See docs/COPYRIGHT.rdoc for more details.// ++-import {ApiV3Paths} from 'core-app/modules/common/path-helper/apiv3/apiv3-paths';import {Injectable} from '@angular/core';+import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder";-@Injectable({ providedIn: 'root' })-export class PathHelperService {- public readonly appBasePath:string;- public readonly api:{ v3:ApiV3Paths };+class Apiv3Paths {+ readonly apiV3Base:string;++ constructor(basePath:string) {+ this.apiV3Base = basePath + '/api/v3';+ }++ /**+ * Preview markup path+ *+ * Primarily used from ckeditor+ * https://github.com/opf/commonmark-ckeditor-build/+ *+ * @param context+ */+ public previewMarkup(context:string) {+ let base = this.apiV3Base + '/render/markdown';++ if (context) {+ return base + `?context=${context}`;+ } else {+ return base;+ }+ }++ /**+ * Principals autocompleter path+ *+ * Primarily used from ckeditor+ * https://github.com/opf/commonmark-ckeditor-build/+ *+ */+ public principals(projectId:string|number, term:string|null) {+ let filters:ApiV3FilterBuilder = new ApiV3FilterBuilder();+ // Only real and activated users:+ filters.add('status', '!', ['3']);+ // that are members of that project:+ filters.add('member', '=', [projectId.toString()]);+ // That are users:+ filters.add('type', '=', ['User', 'Group']);+ // That are not the current user:+ filters.add('id', '!', ['me']);++ if (term && term.length > 0) {+ // Containing the that substring:+ filters.add('name', '~', [term]);+ }- constructor() {- this.appBasePath = window.appBasePath ? window.appBasePath : '';- this.api = {- v3: new ApiV3Paths(this.appBasePath)- };+ return this.apiV3Base ++ '/principals?' ++ filters.toParams({ sortBy: '[["name","asc"]]', offset: '1', pageSize: '10' });}+}++@Injectable({ providedIn: 'root' })+export class PathHelperService {+ public readonly appBasePath = window.appBasePath ? window.appBasePath : '';+ public readonly api = {+ v3: new Apiv3Paths(this.appBasePath)+ };+public get staticBase() {return this.appBasePath;}diff --git a/frontend/src/app/modules/fields/display/field-types/date-display-field.module.ts b/frontend/src/app/modules/fields/display/field-types/date-display-field.module.tsindex 0052d34e1f4..339a03807bf 100644--- a/frontend/src/app/modules/fields/display/field-types/date-display-field.module.ts+++ b/frontend/src/app/modules/fields/display/field-types/date-display-field.module.ts@@ -30,11 +30,11 @@ import {TimezoneService} from 'core-components/datetime/timezone.service';import {Highlighting} from "core-components/wp-fast-table/builders/highlighting/highlighting.functions";import {HighlightableDisplayField} from "core-app/modules/fields/display/field-types/highlightable-display-field.module";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";-import {StatusCacheService} from "core-components/statuses/status-cache.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export class DateDisplayField extends HighlightableDisplayField {@InjectField() timezoneService:TimezoneService;- @InjectField() statusCache:StatusCacheService;+ @InjectField() apiV3Service:APIV3Service;public render(element:HTMLElement, displayText:string):void {super.render(element, displayText);@@ -52,7 +52,13 @@ export class DateDisplayField extends HighlightableDisplayField {if (this.shouldHighlight && this.canOverdue) {const diff = this.timezoneService.daysFromToday(this.value);- this.statusCache.require(this.resource.status.id).then((status) => {+ this+ .apiV3Service+ .statuses+ .id(this.resource.status.id)+ .get()+ .toPromise()+ .then((status) => {if (!status.isClosed) {element.classList.add(Highlighting.overdueDate(diff));}diff --git a/frontend/src/app/modules/fields/display/field-types/wp-spent-time-display-field.module.ts b/frontend/src/app/modules/fields/display/field-types/wp-spent-time-display-field.module.tsindex 7d00c96f52c..a15f4bf740c 100644--- a/frontend/src/app/modules/fields/display/field-types/wp-spent-time-display-field.module.ts+++ b/frontend/src/app/modules/fields/display/field-types/wp-spent-time-display-field.module.ts@@ -28,12 +28,12 @@import { DurationDisplayField } from './duration-display-field.module';import { PathHelperService } from 'core-app/modules/common/path-helper/path-helper.service';-import { ProjectCacheService } from "core-components/projects/project-cache.service";import { ProjectResource } from "core-app/modules/hal/resources/project-resource";import { InjectField } from "core-app/helpers/angular/inject-field.decorator";import * as URI from 'urijs';import { TimeEntryCreateService } from 'core-app/modules/time_entries/create/create.service';import { WorkPackageResource } from "core-app/modules/hal/resources/work-package-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export class WorkPackageSpentTimeDisplayField extends DurationDisplayField {public text = {@@ -42,8 +42,8 @@ export class WorkPackageSpentTimeDisplayField extends DurationDisplayField {};@InjectField() PathHelper:PathHelperService;- @InjectField() projectCacheService:ProjectCacheService;@InjectField() timeEntryCreateService:TimeEntryCreateService;+ @InjectField() apiV3Service:APIV3Service;public render(element:HTMLElement, displayText:string):void {if (!this.value) {@@ -57,9 +57,12 @@ export class WorkPackageSpentTimeDisplayField extends DurationDisplayField {if (this.resource.project) {const wpID = this.resource.id.toString();- this.projectCacheService- .require(this.resource.project.idFromLink)- .then((project:ProjectResource) => {+ this+ .apiV3Service+ .projects+ .id(this.resource.project)+ .get()+ .subscribe((project:ProjectResource) => {const href = URI(this.PathHelper.projectTimeEntriesPath(project.identifier)).search({ work_package_id: wpID }).toString();diff --git a/frontend/src/app/modules/fields/edit/field-types/te-work-package-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/te-work-package-edit-field.component.tsindex 9772c8cac37..cad61f2c7ad 100644--- a/frontend/src/app/modules/fields/edit/field-types/te-work-package-edit-field.component.ts+++ b/frontend/src/app/modules/fields/edit/field-types/te-work-package-edit-field.component.ts@@ -28,7 +28,6 @@import {Component} from "@angular/core";import {WorkPackageEditFieldComponent} from "core-app/modules/fields/edit/field-types/work-package-edit-field.component";-import {TimeEntryDmService} from "core-app/modules/hal/dm-services/time-entry-dm.service";import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder";import {TimeEntryWorkPackageAutocompleterComponent,@@ -36,6 +35,7 @@ import {} from "core-app/modules/common/autocomplete/te-work-package-autocompleter.component";import {HalResource} from "core-app/modules/hal/resources/hal-resource";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";const RECENT_TIME_ENTRIES_MAGIC_NUMBER = 30;@@ -43,7 +43,7 @@ const RECENT_TIME_ENTRIES_MAGIC_NUMBER = 30;templateUrl: './work-package-edit-field.component.html'})export class TimeEntryWorkPackageEditFieldComponent extends WorkPackageEditFieldComponent {- @InjectField() public timeEntryDm:TimeEntryDmService;+ @InjectField() apiV3Service:APIV3Service;private recentWorkPackageIds:string[];@@ -85,8 +85,10 @@ export class TimeEntryWorkPackageEditFieldComponent extends WorkPackageEditFieldprotected loadAllowedValues(query?:string) {if (!this.recentWorkPackageIds) {return this- .timeEntryDm+ .apiV3Service+ .time_entries.list({ filters: [['user_id', '=', ['me']]], sortBy: [["updated_on", "desc"]], pageSize: RECENT_TIME_ENTRIES_MAGIC_NUMBER })+ .toPromise().then(collection => {this.recentWorkPackageIds = collection.elementsdiff --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 c5b07699467..949426dc997 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@@ -26,8 +26,6 @@// See docs/COPYRIGHT.rdoc for more details.// ++-import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';-import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";import {States} from 'core-components/states.service';import {displayClassName,@@ -86,11 +84,9 @@ export class EditableAttributeFieldComponent extends UntilDestroyedMixin implemeconstructor(protected states:States,protected injector:Injector,protected elementRef:ElementRef,- protected halNotification:HalResourceNotificationService,protected ConfigurationService:ConfigurationService,protected opContextMenu:OPContextMenuService,protected halEditing:HalResourceEditingService,- protected wpCacheService:WorkPackageCacheService,protected schemaCache:SchemaCacheService,// Get parent field group from injectorprotected editForm:EditFormComponent,diff --git a/frontend/src/app/modules/fields/edit/services/hal-resource-editing.service.ts b/frontend/src/app/modules/fields/edit/services/hal-resource-editing.service.tsindex 8014f43f93a..fb83635c0a2 100644--- a/frontend/src/app/modules/fields/edit/services/hal-resource-editing.service.ts+++ b/frontend/src/app/modules/fields/edit/services/hal-resource-editing.service.ts@@ -34,9 +34,9 @@ import {FormResource} from "core-app/modules/hal/resources/form-resource";import {ChangeMap} from "core-app/modules/fields/changeset/changeset";import {ResourceChangeset} from "core-app/modules/fields/changeset/resource-changeset";import {HalResource} from "core-app/modules/hal/resources/hal-resource";-import {StateCacheService} from "core-components/states/state-cache.service";import {HookService} from "core-app/modules/plugins/hook-service";import {HalEventsService} from "core-app/modules/hal/services/hal-events.service";+import {StateCacheService} from "core-app/modules/apiv3/cache/state-cache.service";class ChangesetStates extends StatesGroup {name = 'Changesets';@@ -93,15 +93,12 @@ export interface ResourceChangesetClass {export class HalResourceEditingService extends StateCacheService<ResourceChangeset> {/** Committed / saved changes to work packages observable */- public comittedChanges = new Subject<ResourceChangesetCommit>();-- /** State group of changes to wrap */- private stateGroup = new ChangesetStates();+ public committedChanges = new Subject<ResourceChangesetCommit>();constructor(protected readonly injector:Injector,protected readonly halEvents:HalEventsService,protected readonly hook:HookService) {- super();+ super(new ChangesetStates().changesets);}public async save<V extends HalResource, T extends ResourceChangeset<V>>(change:T):Promise<ResourceChangesetCommit<V>> {@@ -124,7 +121,7 @@ export class HalResourceEditingService extends StateCacheService<ResourceChanges*/private complete<V extends HalResource, T extends ResourceChangeset<V>>(change:T, saved:V):ResourceChangesetCommit<V> {const commit = new ResourceChangesetCommit<V>(change, saved);- this.comittedChanges.next(commit);+ this.committedChanges.next(commit);this.reset(change);const eventType = commit.wasNew ? 'created' : 'updated';@@ -177,8 +174,7 @@ export class HalResourceEditingService extends StateCacheService<ResourceChanges/*** Start or continue editing the work package with a given edit context- * @param {resource} Hal resource to edit- * @param {form:FormResource} Initialize with an existing form+ * @param fallback Fallback resource to use* @return {ResourceChangeset} Change object to work on*/public changeFor<V extends HalResource, T extends ResourceChangeset<V>>(fallback:V):T {@@ -243,10 +239,6 @@ export class HalResourceEditingService extends StateCacheService<ResourceChangesthis.multiState.get(resource.href!).clear();}- protected load(href:string):Promise<ResourceChangeset> {- return Promise.reject('Loading not applicable for changesets.') as any;- }-protected onSaved(saved:HalResource):Promise<unknown> {if (saved.state) {return saved.push(saved);@@ -254,13 +246,5 @@ export class HalResourceEditingService extends StateCacheService<ResourceChangesreturn Promise.resolve();}-- protected loadAll(hrefs:string[]) {- return Promise.all(hrefs.map(href => this.load(href))) as any;- }-- protected get multiState():MultiInputState<ResourceChangeset> {- return this.stateGroup.changesets;- }}diff --git a/frontend/src/app/modules/global_search/input/global-search-input.component.ts b/frontend/src/app/modules/global_search/input/global-search-input.component.tsindex 4cf30c60f99..440d1f878c0 100644--- a/frontend/src/app/modules/global_search/input/global-search-input.component.ts+++ b/frontend/src/app/modules/global_search/input/global-search-input.component.ts@@ -53,6 +53,7 @@ import {map, tap, take, filter} from "rxjs/internal/operators";import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";import {DebouncedRequestSwitchmap, errorNotificationHandler} from "core-app/helpers/rxjs/debounced-input-switchmap";import {LinkHandling} from "core-app/modules/common/link-handling/link-handling";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export const globalSearchSelector = 'global-search-input';@@ -115,6 +116,7 @@ export class GlobalSearchInputComponent implements OnInit, OnDestroy {constructor(readonly elementRef:ElementRef,readonly I18n:I18nService,+ readonly apiV3Service:APIV3Service,readonly PathHelperService:PathHelperService,readonly halResourceService:HalResourceService,readonly globalSearchService:GlobalSearchService,@@ -265,7 +267,9 @@ export class GlobalSearchInputComponent implements OnInit, OnDestroy {let hashFreeQuery = this.queryWithoutHash(query);- return this.fetchSearchResults(hashFreeQuery, hashFreeQuery !== query)+ return this+ .fetchSearchResults(hashFreeQuery, hashFreeQuery !== query)+ .get().pipe(map((collection) => {return this.searchResultsToOptions(collection.elements, hashFreeQuery);@@ -283,11 +287,10 @@ export class GlobalSearchInputComponent implements OnInit, OnDestroy {}private fetchSearchResults(query:string, idOnly:boolean) {- let href:string = this.PathHelperService.api.v3.wpBySubjectOrId(query, idOnly);-- return this.halResourceService- .get<CollectionResource<WorkPackageResource>>(href);-+ return this+ .apiV3Service+ .work_packages+ .filterBySubjectOrId(query, idOnly);}private searchResultsToOptions(results:WorkPackageResource[], query:string) {diff --git a/frontend/src/app/modules/global_search/services/global-search.service.spec.ts b/frontend/src/app/modules/global_search/services/global-search.service.spec.tsindex 0659bb0de22..0e46baf8d89 100644--- a/frontend/src/app/modules/global_search/services/global-search.service.spec.ts+++ b/frontend/src/app/modules/global_search/services/global-search.service.spec.ts@@ -33,6 +33,8 @@ import {GlobalSearchService} from "core-app/modules/global_search/services/globaimport {I18nService} from "core-app/modules/common/i18n/i18n.service";import {async, TestBed} from "@angular/core/testing";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";+import {States} from "core-components/states.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";describe('Global search service', function() {let service:GlobalSearchService;@@ -45,6 +47,8 @@ describe('Global search service', function() {providers: [I18nService,PathHelperService,+ States,+ APIV3Service,CurrentProjectService,GlobalSearchService,]diff --git a/frontend/src/app/modules/grids/grid/area.service.ts b/frontend/src/app/modules/grids/grid/area.service.tsindex 9d0ff4b90a2..6a8b2324be2 100644--- a/frontend/src/app/modules/grids/grid/area.service.ts+++ b/frontend/src/app/modules/grids/grid/area.service.ts@@ -2,7 +2,6 @@ import {Injectable} from '@angular/core';import {GridWidgetArea} from "app/modules/grids/areas/grid-widget-area";import {GridArea} from "core-app/modules/grids/areas/grid-area";import {GridGap} from "core-app/modules/grids/areas/grid-gap";-import {GridDmService} from "core-app/modules/hal/dm-services/grid-dm.service";import {GridResource} from "core-app/modules/hal/resources/grid-resource";import {GridWidgetResource} from "core-app/modules/hal/resources/grid-widget-resource";import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";@@ -10,6 +9,9 @@ import {WidgetChangeset} from "core-app/modules/grids/widgets/widget-changeset";import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import { BehaviorSubject } from 'rxjs';+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {Apiv3GridForm} from "core-app/modules/apiv3/endpoints/grids/apiv3-grid-form";+import {map} from "rxjs/operators";@Injectable()export class GridAreaService {@@ -27,7 +29,7 @@ export class GridAreaService {public $mousedOverArea = new BehaviorSubject(this.mousedOverArea);public helpMode = false;- constructor (private gridDm:GridDmService,+ constructor (private apiV3Service:APIV3Service,private notification:NotificationsService,private i18n:I18nService) { }@@ -102,7 +104,7 @@ export class GridAreaService {}public saveWidgetChangeset(changeset:WidgetChangeset) {- let payload = this.gridDm.extractPayload(this.resource, this.schema);+ let payload:any = Apiv3GridForm.extractPayload(this.resource, this.schema);let payloadWidget = payload.widgets.find((w:any) => w.id === changeset.pristineResource.id);Object.assign(payloadWidget, changeset.changes);@@ -143,9 +145,11 @@ export class GridAreaService {private saveGrid(resource:GridWidgetResource|any, schema?:SchemaResource) {this- .gridDm- .update(resource, schema)- .then(updatedGrid => {+ .apiV3Service+ .grids+ .id(resource)+ .patch(resource, schema)+ .subscribe(updatedGrid => {this.assignAreasWidget(updatedGrid);this.notification.addSuccess(this.i18n.t('js.notice_successful_update'));});@@ -369,10 +373,13 @@ export class GridAreaService {}private fetchSchema() {- this.gridDm.updateForm(this.resource)- .then((form) => {- this.schema = form.schema;- });+ this+ .apiV3Service+ .grids+ .id(this.resource)+ .form+ .post({})+ .subscribe(form => this.schema = form.schema);}public removeWidget(removedWidget:GridWidgetResource) {diff --git a/frontend/src/app/modules/grids/grid/initialization.service.ts b/frontend/src/app/modules/grids/grid/initialization.service.tsindex 8e3c347472a..e35e3dc81f0 100644--- a/frontend/src/app/modules/grids/grid/initialization.service.ts+++ b/frontend/src/app/modules/grids/grid/initialization.service.ts@@ -1,12 +1,14 @@import {Injectable} from '@angular/core';import {GridResource} from "core-app/modules/hal/resources/grid-resource";import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";-import {GridDmService} from "core-app/modules/hal/dm-services/grid-dm.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {switchMap} from "rxjs/operators";@Injectable()export class GridInitializationService {- constructor(readonly gridDm:GridDmService,- readonly halResourceService:HalResourceService) {}+ constructor(readonly apiV3Service:APIV3Service,+ readonly halResourceService:HalResourceService) {+ }// If a page with the current page exists (scoped to the current user by the backend)// that page will be used to initialized the grid.@@ -14,8 +16,10 @@ export class GridInitializationService {// The created resource is then used to initialize the grid.public initialize(path:string) {return this- .gridDm+ .apiV3Service+ .grids.list({ filters: [['scope', '=', [path]]] })+ .toPromise().then(collection => {if (collection.total === 0) {return this.myPageForm(path);@@ -26,21 +30,22 @@ export class GridInitializationService {}private myPageForm(path:string):Promise<GridResource> {- return new Promise<GridResource>((resolve, reject) => {- let payload = {- '_links': {- 'scope': {- 'href': path- }+ let payload = {+ '_links': {+ 'scope': {+ 'href': path}- };+ }+ };- this- .gridDm- .createForm(payload)- .then((form) => {+ return this+ .apiV3Service+ .grids+ .form+ .post(payload)+ .pipe(+ switchMap(form => {let source = form.payload.$source;-let resource = this.halResourceService.createHalResource(source) as GridResource;if (resource.widgets.length === 0) {@@ -48,14 +53,12 @@ export class GridInitializationService {resource.columnCount = 1;}- this.gridDm.create(resource, form.schema)- .then((resource) => {- resolve(resource);- })- .catch(() => {- reject();- });- });- });+ return this+ .apiV3Service+ .grids+ .post(resource, form.schema);+ })+ )+ .toPromise();}}diff --git a/frontend/src/app/modules/grids/widgets/documents/documents.component.ts b/frontend/src/app/modules/grids/widgets/documents/documents.component.tsindex a672d184875..529167e7fbd 100644--- a/frontend/src/app/modules/grids/widgets/documents/documents.component.ts+++ b/frontend/src/app/modules/grids/widgets/documents/documents.component.ts@@ -8,6 +8,7 @@ import {PathHelperService} from "core-app/modules/common/path-helper/path-helperimport {TimezoneService} from "core-components/datetime/timezone.service";import {DomSanitizer} from '@angular/platform-browser';import {CurrentProjectService} from "core-components/projects/current-project.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './documents.component.html',@@ -23,6 +24,7 @@ export class WidgetDocumentsComponent extends AbstractWidgetComponent implementsconstructor(readonly halResource:HalResourceService,readonly pathHelper:PathHelperService,+ readonly apiV3Service:APIV3Service,readonly i18n:I18nService,readonly timezone:TimezoneService,readonly domSanitizer:DomSanitizer,@@ -67,7 +69,7 @@ export class WidgetDocumentsComponent extends AbstractWidgetComponent implementspublic get documentsUrl() {let orders = JSON.stringify([['updated_at', 'desc']]);- let url = `${this.pathHelper.api.v3.apiV3Base}/documents?sortBy=${orders}&pageSize=10`;+ let url = this.apiV3Service.documents.toPath() + `?sortBy=${orders}&pageSize=10`;if (this.currentProject.id) {let filters = JSON.stringify([{project_id: { operator: '=', values: [this.currentProject.id.toString()]}}]);diff --git a/frontend/src/app/modules/grids/widgets/members/members.component.ts b/frontend/src/app/modules/grids/widgets/members/members.component.tsindex e331d8bdeb7..abeab2378b6 100644--- a/frontend/src/app/modules/grids/widgets/members/members.component.ts+++ b/frontend/src/app/modules/grids/widgets/members/members.component.ts@@ -4,10 +4,10 @@ import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {UserResource} from "core-app/modules/hal/resources/user-resource";import {CurrentProjectService} from "core-components/projects/current-project.service";-import {DmListParameter} from "core-app/modules/hal/dm-services/dm.service.interface";import {MembershipResource} from "core-app/modules/hal/resources/membership-resource";-import {MembershipDmService} from "core-app/modules/hal/dm-services/membership-dm.service";import {RoleResource} from "core-app/modules/hal/resources/role-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {Apiv3ListParameters} from "core-app/modules/apiv3/paths/apiv3-list-resource.interface";const DISPLAYED_MEMBERS_LIMIT = 100;@@ -29,18 +29,20 @@ export class WidgetMembersComponent extends AbstractWidgetComponent implements Opublic membersAddable:boolean = false;constructor(readonly pathHelper:PathHelperService,+ readonly apiV3Service:APIV3Service,readonly i18n:I18nService,protected readonly injector:Injector,- readonly membershipDm:MembershipDmService,readonly currentProject:CurrentProjectService,readonly cdr:ChangeDetectorRef) {super(i18n, injector);}ngOnInit() {- this.membershipDm+ this+ .apiV3Service+ .memberships.list(this.listMembersParams)- .then(collection => {+ .subscribe(collection => {this.partitionEntriesByRole(collection.elements);this.sortUsersByName();this.totalMembers = collection.total;@@ -49,14 +51,12 @@ export class WidgetMembersComponent extends AbstractWidgetComponent implements Othis.cdr.detectChanges();});- this.membershipDm- .listAvailableProjects(this.listAvailableProjectsParams)- .then(collection => {+ this.apiV3Service+ .memberships+ .available_projects+ .list(this.listAvailableProjectsParams)+ .subscribe(collection => {this.membersAddable = collection.total > 0;- })- .catch(() => {- // nothing bad, the user is just not allowed to add members to the project-});}@@ -96,7 +96,7 @@ export class WidgetMembersComponent extends AbstractWidgetComponent implements O}public isGroup(principal:UserResource) {- return this.pathHelper.api.v3.groups.id(principal.id!).toString() === principal.href;+ return this.apiV3Service.groups.id(principal.id!).toString() === principal.href;}private partitionEntriesByRole(memberships:MembershipResource[]) {@@ -120,7 +120,7 @@ export class WidgetMembersComponent extends AbstractWidgetComponent implements O}private get listMembersParams() {- let params:DmListParameter = { sortBy: [['created_on', 'desc']], pageSize: DISPLAYED_MEMBERS_LIMIT };+ let params:Apiv3ListParameters = { sortBy: [['created_on', 'desc']], pageSize: DISPLAYED_MEMBERS_LIMIT };if (this.currentProject.id) {params['filters'] = [['project_id', '=', [this.currentProject.id]]];@@ -132,7 +132,7 @@ export class WidgetMembersComponent extends AbstractWidgetComponent implements Oprivate get listAvailableProjectsParams() {// It would make sense to set the pageSize but the backend for projects// returns an upaginated list which does not support that.- let params:DmListParameter = {};+ let params:Apiv3ListParameters = {};if (this.currentProject.id) {params['filters'] = [['id', '=', [this.currentProject.id]]];diff --git a/frontend/src/app/modules/grids/widgets/news/news.component.spec.ts b/frontend/src/app/modules/grids/widgets/news/news.component.spec.tsindex 65544860082..f3aa059d704 100644--- a/frontend/src/app/modules/grids/widgets/news/news.component.spec.ts+++ b/frontend/src/app/modules/grids/widgets/news/news.component.spec.ts@@ -1,14 +1,14 @@-import { NewsDmService } from "core-app/modules/hal/dm-services/news-dm.service";import { ComponentFixture, fakeAsync, TestBed, tick, async } from '@angular/core/testing';import { WidgetNewsComponent } from './news.component';import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';import { TimezoneService } from 'core-app/components/datetime/timezone.service';import { ConfigurationService } from 'core-app/modules/common/config/configuration.service';import { States } from 'core-app/components/states.service';-import { UserDmService } from 'core-app/modules/hal/dm-services/user-dm.service';import { HalResourceService } from "core-app/modules/hal/services/hal-resource.service";import { HttpClientModule } from "@angular/common/http";import { By } from '@angular/platform-browser';+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {of} from "rxjs";describe('shows news', () => {let app:WidgetNewsComponent;@@ -32,9 +32,11 @@ describe('shows news', () => {updatedAt: '2020-03-26T10:42:14Z',};- let newsDmServiceStub = {- list: (_params:any) => {- return Promise.resolve({ elements: [newsStub] });+ let apiv3ServiceStub = {+ news: {+ list: (_params:any) => {+ return of({ elements: [newsStub] });+ }}};@@ -51,8 +53,7 @@ describe('shows news', () => {TimezoneService,{ provide: ConfigurationService, useValue: configurationServiceStub },States,- UserDmService,- { provide: NewsDmService, useValue: newsDmServiceStub },+ { provide: APIV3Service, useValue: apiv3ServiceStub },HalResourceService,],imports: [HttpClientModule],diff --git a/frontend/src/app/modules/grids/widgets/news/news.component.ts b/frontend/src/app/modules/grids/widgets/news/news.component.tsindex 20059e6f1dd..fc6f5b1e413 100644--- a/frontend/src/app/modules/grids/widgets/news/news.component.ts+++ b/frontend/src/app/modules/grids/widgets/news/news.component.ts@@ -4,9 +4,9 @@ import { I18nService } from "core-app/modules/common/i18n/i18n.service";import { PathHelperService } from "core-app/modules/common/path-helper/path-helper.service";import { TimezoneService } from "core-components/datetime/timezone.service";import { NewsResource } from "core-app/modules/hal/resources/news-resource";-import { NewsDmService } from "core-app/modules/hal/dm-services/news-dm.service";import { CurrentProjectService } from "core-components/projects/current-project.service";-import { DmListParameter } from "core-app/modules/hal/dm-services/dm.service.interface";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {Apiv3ListParameters} from "core-app/modules/apiv3/paths/apiv3-list-resource.interface";@Component({templateUrl: './news.component.html',@@ -29,17 +29,19 @@ export class WidgetNewsComponent extends AbstractWidgetComponent implements OnInreadonly i18n:I18nService,protected readonly injector:Injector,readonly timezone:TimezoneService,- readonly newsDm:NewsDmService,readonly currentProject:CurrentProjectService,+ readonly apiV3Service:APIV3Service,readonly cdr:ChangeDetectorRef) {super(i18n, injector);}ngOnInit() {- this.newsDm+ this+ .apiV3Service+ .news.list(this.newsDmParams)- .then(collection => this.setupNews(collection.elements));+ .subscribe(collection => this.setupNews(collection.elements));}public setupNews(news:any[]) {@@ -84,7 +86,7 @@ export class WidgetNewsComponent extends AbstractWidgetComponent implements OnIn}private get newsDmParams() {- let params:DmListParameter = {+ let params:Apiv3ListParameters = {sortBy: [['created_at', 'desc']],pageSize: 3};diff --git a/frontend/src/app/modules/grids/widgets/project-description/project-description.component.ts b/frontend/src/app/modules/grids/widgets/project-description/project-description.component.tsindex 88f562f1a2e..e45143c6d2f 100644--- a/frontend/src/app/modules/grids/widgets/project-description/project-description.component.ts+++ b/frontend/src/app/modules/grids/widgets/project-description/project-description.component.ts@@ -30,10 +30,10 @@ import {Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef, Injector}import {AbstractWidgetComponent} from "app/modules/grids/widgets/abstract-widget.component";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {CurrentProjectService} from "core-components/projects/current-project.service";-import {ProjectCacheService} from "core-components/projects/project-cache.service";import {Observable} from "rxjs";import {ProjectResource} from "core-app/modules/hal/resources/project-resource";import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './project-description.component.html',@@ -47,14 +47,19 @@ export class WidgetProjectDescriptionComponent extends AbstractWidgetComponent iconstructor(protected readonly i18n:I18nService,protected readonly injector:Injector,- protected readonly projectCache:ProjectCacheService,+ protected readonly apiV3Service:APIV3Service,protected readonly currentProject:CurrentProjectService,protected readonly cdRef:ChangeDetectorRef) {super(i18n, injector);}ngOnInit() {- this.project$ = this.projectCache.requireAndStream(this.currentProject.id!);+ this.project$ = this+ .apiV3Service+ .projects+ .id(this.currentProject.id!)+ .get();+this.cdRef.detectChanges();}diff --git a/frontend/src/app/modules/grids/widgets/project-details/project-details.component.ts b/frontend/src/app/modules/grids/widgets/project-details/project-details.component.tsindex eaa7ccb443a..061b32a4578 100644--- a/frontend/src/app/modules/grids/widgets/project-details/project-details.component.ts+++ b/frontend/src/app/modules/grids/widgets/project-details/project-details.component.ts@@ -37,13 +37,12 @@ import {} from '@angular/core';import {AbstractWidgetComponent} from "app/modules/grids/widgets/abstract-widget.component";import {I18nService} from "core-app/modules/common/i18n/i18n.service";-import {ProjectDmService} from "core-app/modules/hal/dm-services/project-dm.service";import {CurrentProjectService} from "core-components/projects/current-project.service";import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";-import {ProjectCacheService} from "core-components/projects/project-cache.service";import {Observable} from "rxjs";import {ProjectResource} from "core-app/modules/hal/resources/project-resource";import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './project-details.component.html',@@ -60,8 +59,7 @@ export class WidgetProjectDetailsComponent extends AbstractWidgetComponent impleconstructor(protected readonly i18n:I18nService,protected readonly injector:Injector,- protected readonly projectDm:ProjectDmService,- protected readonly projectCache:ProjectCacheService,+ protected readonly apiV3Service:APIV3Service,protected readonly currentProject:CurrentProjectService,protected readonly cdRef:ChangeDetectorRef) {super(i18n, injector);@@ -69,7 +67,11 @@ export class WidgetProjectDetailsComponent extends AbstractWidgetComponent implengOnInit() {this.loadAndRender();- this.project$ = this.projectCache.requireAndStream(this.currentProject.id!);+ this.project$ = this+ .apiV3Service+ .projects+ .id(this.currentProject.id!)+ .requireAndStream();}public get isEditable() {@@ -86,7 +88,12 @@ export class WidgetProjectDetailsComponent extends AbstractWidgetComponent imple}private loadProjectSchema() {- return this.projectDm.schema();+ return this+ .apiV3Service+ .projects+ .schema+ .get()+ .toPromise();}private setCustomFields(schema:SchemaResource) {diff --git a/frontend/src/app/modules/grids/widgets/project-status/project-status.component.ts b/frontend/src/app/modules/grids/widgets/project-status/project-status.component.tsindex 32572ba0f91..a31fc090998 100644--- a/frontend/src/app/modules/grids/widgets/project-status/project-status.component.ts+++ b/frontend/src/app/modules/grids/widgets/project-status/project-status.component.ts@@ -37,14 +37,13 @@ import {} from '@angular/core';import {AbstractWidgetComponent} from "app/modules/grids/widgets/abstract-widget.component";import {I18nService} from "core-app/modules/common/i18n/i18n.service";-import {ProjectDmService} from "core-app/modules/hal/dm-services/project-dm.service";import {CurrentProjectService} from "core-components/projects/current-project.service";import {ProjectResource} from "core-app/modules/hal/resources/project-resource";import {WorkPackageViewHighlightingService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-highlighting.service";import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";-import {ProjectCacheService} from "core-components/projects/project-cache.service";import {Observable} from "rxjs";import {HalResourceEditingService} from "core-app/modules/fields/edit/services/hal-resource-editing.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({templateUrl: './project-status.component.html',@@ -65,15 +64,19 @@ export class WidgetProjectStatusComponent extends AbstractWidgetComponent implemconstructor(protected readonly i18n:I18nService,protected readonly injector:Injector,- protected readonly projectDm:ProjectDmService,- protected readonly projectCache:ProjectCacheService,+ protected readonly apiV3Service:APIV3Service,protected readonly currentProject:CurrentProjectService,protected readonly cdRef:ChangeDetectorRef) {super(i18n, injector);}ngOnInit() {- this.project$ = this.projectCache.requireAndStream(this.currentProject.id!);+ this.project$ = this+ .apiV3Service+ .projects+ .id(this.currentProject.id!)+ .get();+this.cdRef.detectChanges();}diff --git a/frontend/src/app/modules/grids/widgets/subprojects/subprojects.component.ts b/frontend/src/app/modules/grids/widgets/subprojects/subprojects.component.tsindex e229762b2d1..400ee376ee3 100644--- a/frontend/src/app/modules/grids/widgets/subprojects/subprojects.component.ts+++ b/frontend/src/app/modules/grids/widgets/subprojects/subprojects.component.ts@@ -5,9 +5,9 @@ import {HalResourceService} from "core-app/modules/hal/services/hal-resource.serimport {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {TimezoneService} from "core-components/datetime/timezone.service";import {CurrentProjectService} from "core-components/projects/current-project.service";-import {DmListParameter} from "core-app/modules/hal/dm-services/dm.service.interface";-import {ProjectDmService} from "core-app/modules/hal/dm-services/project-dm.service";import {ProjectResource} from "core-app/modules/hal/resources/project-resource";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {Apiv3ListParameters} from "core-app/modules/apiv3/paths/apiv3-list-resource.interface";@Component({templateUrl: './subprojects.component.html',@@ -25,7 +25,7 @@ export class WidgetSubprojectsComponent extends AbstractWidgetComponent implemenreadonly i18n:I18nService,protected readonly injector:Injector,readonly timezone:TimezoneService,- readonly projectDm:ProjectDmService,+ readonly apiV3Service:APIV3Service,readonly currentProject:CurrentProjectService,readonly cdr:ChangeDetectorRef) {super(i18n, injector);@@ -33,9 +33,10 @@ export class WidgetSubprojectsComponent extends AbstractWidgetComponent implemenngOnInit() {this- .projectDm- .list(this.projectDmParams)- .then((collection) => {+ .apiV3Service+ .projects+ .list(this.projectListParams)+ .subscribe((collection) => {this.projects = collection.elements as ProjectResource[];this.cdr.detectChanges();@@ -58,7 +59,7 @@ export class WidgetSubprojectsComponent extends AbstractWidgetComponent implemenreturn this.projects && !this.projects.length;}- private get projectDmParams():DmListParameter {+ private get projectListParams():Apiv3ListParameters {return { sortBy: [['name', 'asc']],filters: [['parent_id', '=', [this.currentProject.id!]]] };}diff --git a/frontend/src/app/modules/grids/widgets/time-entries/list/time-entries-list.component.ts b/frontend/src/app/modules/grids/widgets/time-entries/list/time-entries-list.component.tsindex d744c6e1209..9ce8213a978 100644--- a/frontend/src/app/modules/grids/widgets/time-entries/list/time-entries-list.component.ts+++ b/frontend/src/app/modules/grids/widgets/time-entries/list/time-entries-list.component.ts@@ -1,7 +1,6 @@import {ChangeDetectorRef, Injector, OnInit} from "@angular/core";import {AbstractWidgetComponent} from "core-app/modules/grids/widgets/abstract-widget.component";import {I18nService} from "core-app/modules/common/i18n/i18n.service";-import {TimeEntryDmService} from "core-app/modules/hal/dm-services/time-entry-dm.service";import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";import {TimezoneService} from "core-components/datetime/timezone.service";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";@@ -9,7 +8,7 @@ import {ConfirmDialogService} from "core-components/modals/confirm-dialog/confirimport {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";import {TimeEntryEditService} from "core-app/modules/time_entries/edit/edit.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";-import {TimeEntryCacheService} from "core-components/time-entries/time-entry-cache.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetComponent implements OnInit {public text = {@@ -30,10 +29,9 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompopublic rows:{ date:string, sum?:string, entry?:TimeEntryResource}[] = [];@InjectField() public readonly timeEntryEditService:TimeEntryEditService;- @InjectField() public readonly timeEntryCache:TimeEntryCacheService;+ @InjectField() public readonly apiV3Service:APIV3Service;- constructor(readonly timeEntryDm:TimeEntryDmService,- readonly injector:Injector,+ constructor(readonly injector:Injector,readonly timezone:TimezoneService,readonly i18n:I18nService,readonly pathHelper:PathHelperService,@@ -43,8 +41,11 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo}ngOnInit() {- this.timeEntryDm.list({ filters: this.dmFilters(), pageSize: 500 })- .then((collection) => {+ this+ .apiV3Service+ .time_entries+ .list({ filters: this.dmFilters(), pageSize: 500 })+ .subscribe((collection) => {this.buildEntries(collection.elements);this.entriesLoaded = true;@@ -97,7 +98,12 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo}public editTimeEntry(entry:TimeEntryResource) {- this.timeEntryCache.require(entry.id!).then((loadedEntry) => {+ this+ .apiV3Service+ .time_entries+ .id(entry.id!)+ .get()+ .subscribe((loadedEntry) => {this.timeEntryEditService.edit(loadedEntry).then((changedEntry) => {diff --git a/frontend/src/app/modules/grids/widgets/time-entries/project/time-entries-project.component.ts b/frontend/src/app/modules/grids/widgets/time-entries/project/time-entries-project.component.tsindex 07702369b2e..c35b6b92b2d 100644--- a/frontend/src/app/modules/grids/widgets/time-entries/project/time-entries-project.component.ts+++ b/frontend/src/app/modules/grids/widgets/time-entries/project/time-entries-project.component.ts@@ -1,7 +1,6 @@import {Component, OnInit, Injector, ChangeDetectorRef} from "@angular/core";import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";import {WidgetTimeEntriesListComponent} from "core-app/modules/grids/widgets/time-entries/list/time-entries-list.component";-import {TimeEntryDmService} from "core-app/modules/hal/dm-services/time-entry-dm.service";import {TimezoneService} from "core-components/datetime/timezone.service";import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";@@ -12,15 +11,14 @@ import {CurrentProjectService} from "core-components/projects/current-project.setemplateUrl: '../list/time-entries-list.component.html',})export class WidgetTimeEntriesProjectComponent extends WidgetTimeEntriesListComponent implements OnInit {- constructor(readonly timeEntryDm:TimeEntryDmService,- readonly injector:Injector,+ constructor(readonly injector:Injector,readonly timezone:TimezoneService,readonly i18n:I18nService,readonly pathHelper:PathHelperService,readonly confirmDialog:ConfirmDialogService,protected readonly cdr:ChangeDetectorRef,protected readonly currentProject:CurrentProjectService) {- super(timeEntryDm, injector, timezone, i18n, pathHelper, confirmDialog, cdr);+ super(injector, timezone, i18n, pathHelper, confirmDialog, cdr);}protected dmFilters():Array<[string, FilterOperator, [string]]> {return [['spentOn', '>t-', ['7']] as [string, FilterOperator, [string]],diff --git a/frontend/src/app/modules/grids/widgets/wp-table/wp-table.component.ts b/frontend/src/app/modules/grids/widgets/wp-table/wp-table.component.tsindex bf6b1f8e6d0..857b41436ec 100644--- a/frontend/src/app/modules/grids/widgets/wp-table/wp-table.component.ts+++ b/frontend/src/app/modules/grids/widgets/wp-table/wp-table.component.ts@@ -5,12 +5,11 @@ import {QueryResource} from "core-app/modules/hal/resources/query-resource";import {WorkPackageTableConfiguration} from "core-components/wp-table/wp-table-configuration";import {Observable} from 'rxjs';import {I18nService} from "core-app/modules/common/i18n/i18n.service";-import {QueryFormDmService} from "core-app/modules/hal/dm-services/query-form-dm.service";import {UrlParamsHelperService} from "core-components/wp-query/url-params-helper";-import {QueryDmService} from "core-app/modules/hal/dm-services/query-dm.service";import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";import {StateService} from '@uirouter/core';-import {skip} from 'rxjs/operators';+import {finalize, publish, skip} from 'rxjs/operators';+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({selector: 'widget-wp-table',@@ -35,9 +34,8 @@ export class WidgetWpTableComponent extends AbstractWidgetComponent {protected readonly injector:Injector,protected urlParamsHelper:UrlParamsHelperService,protected readonly state:StateService,- protected readonly queryDm:QueryDmService,protected readonly querySpace:IsolatedQuerySpace,- protected readonly queryFormDm:QueryFormDmService) {+ protected readonly apiV3Service:APIV3Service) {super(i18n, injector);}@@ -80,27 +78,32 @@ export class WidgetWpTableComponent extends AbstractWidgetComponent {private ensureFormAndSaveQuery(query:QueryResource) {if (this.queryForm) {- this.saveQuery(query);+ this.saveQuery(query, this.queryForm);} else {- this.queryFormDm.load(query).then((form) => {- this.queryForm = form;- this.saveQuery(query);- });+ this+ .apiV3Service+ .queries+ .form+ .load(query)+ .subscribe(([form, _]) => {+ this.queryForm = form;+ this.saveQuery(query, form);+ });}}- private saveQuery(query:QueryResource) {+ private saveQuery(query:QueryResource, form:QueryFormResource) {this.inFlight = true;this- .queryDm- .update(query, this.queryForm)- .toPromise()- .then((query) => {- this.inFlight = false;- return query;- })- .catch(() => this.inFlight = false);+ .apiV3Service+ .queries+ .id(query)+ .patch(query, this.queryForm)+ .subscribe(+ () => this.inFlight = false,+ () => this.inFlight = false,+ );}private createInitial():Promise<QueryResource> {@@ -108,21 +111,28 @@ export class WidgetWpTableComponent extends AbstractWidgetComponent {let initializationProps = this.resource.options.queryProps;let queryProps = Object.assign({ pageSize: 0 }, initializationProps);- return this.queryFormDm+ return this+ .apiV3Service+ .queries+ .form.loadWithParams(queryProps,undefined,projectIdentifier,this.queryCreationParams())- .then(form => {- const query = this.queryFormDm.buildQueryResource(form);-- return this.queryDm.create(query, form).then((query) => {- delete this.resource.options.queryProps;-- return query;- });+ .toPromise()+ .then(([form, query]) => {+ return this+ .apiV3Service+ .queries+ .post(query, form)+ .toPromise()+ .then((query) => {+ delete this.resource.options.queryProps;++ return query;+ });});}diff --git a/frontend/src/app/modules/hal/dm-services/abstract-dm.service.ts b/frontend/src/app/modules/hal/dm-services/abstract-dm.service.tsdeleted file mode 100644index 7cd32f24661..00000000000--- a/frontend/src/app/modules/hal/dm-services/abstract-dm.service.ts+++ /dev/null@@ -1,91 +0,0 @@-//-- 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 {DmListParameter, DmServiceInterface} from "core-app/modules/hal/dm-services/dm.service.interface";-import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";-import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";-import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";-import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder";-import {HalResource} from "core-app/modules/hal/resources/hal-resource";-import {Injectable} from '@angular/core';--// This only needs to be Injectable for the tests to work-@Injectable()-export abstract class AbstractDmService<T extends HalResource> implements DmServiceInterface {- constructor(protected halResourceService:HalResourceService,- protected pathHelper:PathHelperService) {- }-- public list(params:DmListParameter|null):Promise<CollectionResource<T>> {- return this.listRequest(this.listUrl(), params) as Promise<CollectionResource<T>>;- }--- public one(id:number):Promise<T> {- return this.halResourceService.get<T>(this.oneUrl(id).toString()).toPromise();- }-- protected listRequest(url:string, params:DmListParameter|null) {- return this.halResourceService.get(url + this.listParamsString(params)).toPromise();- }-- protected listParamsString(params:DmListParameter|null):string {- let queryProps = [];-- if (params && params.sortBy) {- queryProps.push(`sortBy=${JSON.stringify(params.sortBy)}`);- }-- // 0 should not be treated as false- if (params && params.pageSize !== undefined) {- queryProps.push(`pageSize=${params.pageSize}`);- }-- if (params && params.filters) {- let filters = new ApiV3FilterBuilder();-- params.filters.forEach((filterParam) => {- filters.add(...filterParam);- });-- queryProps.push(filters.toParams());- }-- let queryPropsString = '';-- if (queryProps.length) {- queryPropsString = `?${queryProps.join('&')}`;- }-- return queryPropsString;- }--- protected abstract listUrl():string;- protected abstract oneUrl(id:number|string):string;-}diff --git a/frontend/src/app/modules/hal/dm-services/grid-dm.service.ts b/frontend/src/app/modules/hal/dm-services/grid-dm.service.tsdeleted file mode 100644index 4fa175bd1c8..00000000000--- a/frontend/src/app/modules/hal/dm-services/grid-dm.service.ts+++ /dev/null@@ -1,111 +0,0 @@-//-- 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 {Injectable} from '@angular/core';-import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';-import {GridResource} from "core-app/modules/hal/resources/grid-resource";-import {FormResource} from "core-app/modules/hal/resources/form-resource";-import {PayloadDmService} from "core-app/modules/hal/dm-services/payload-dm.service";-import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";-import {HalResource} from "core-app/modules/hal/resources/hal-resource";-import {AbstractDmService} from "core-app/modules/hal/dm-services/abstract-dm.service";--@Injectable()-export class GridDmService extends AbstractDmService<GridResource> {- constructor(protected halResourceService:HalResourceService,- protected pathHelper:PathHelperService,- protected payloadDm:PayloadDmService) {- super(halResourceService,- pathHelper);- }-- public createForm(resource:GridResource|null|any = null, schema:SchemaResource|null = null) {- let payload = this.extractPayload(resource, schema);-- return this.halResourceService.post<FormResource>(this.pathHelper.api.v3.grids.form().toString(),- payload).toPromise();- }-- public create(resource:GridResource, schema:SchemaResource|null = null):Promise<GridResource> {- let payload = this.extractPayload(resource, schema);-- return this.halResourceService.post<GridResource>(this.pathHelper.api.v3.grids.path,- payload).toPromise();- }-- public update(resource:GridResource, schema:SchemaResource|null = null):Promise<GridResource> {- let payload = this.extractPayload(resource, schema);-- return this.halResourceService.patch<GridResource>(this.pathHelper.api.v3.grids.id(resource.id!).toString(),- payload).toPromise();- }-- public updateForm(resource:GridResource, schema:SchemaResource|null = null) {- let payload = this.extractPayload(resource, schema);-- return this.halResourceService.post<FormResource>(this.pathHelper.api.v3.grids.id(resource.idFromLink).form.toString(),- payload).toPromise();- }-- public extractPayload(resource:GridResource|null = null, schema:SchemaResource|null = null) {- if (resource && schema) {- let payload = this.payloadDm.extract(resource, schema);-- // The widget only states the type of the widget resource but does not explain- // the widget itself. We therefore have to do that by hand.- if (payload.widgets) {- payload.widgets = resource.widgets.map((widget) => {- return {- id: widget.id,- startRow: widget.startRow,- endRow: widget.endRow,- startColumn: widget.startColumn,- endColumn: widget.endColumn,- identifier: widget.identifier,- options: widget.options- };- });- }-- return payload;- } else if (!(resource instanceof HalResource)) {- return resource;- } else {- return {};- }- }-- protected listUrl() {- return this.pathHelper.api.v3.grids.toString();- }-- protected oneUrl(id:number|string) {- return this.pathHelper.api.v3.grids.id(id).toString();- }-}diff --git a/frontend/src/app/modules/hal/dm-services/help-text-dm.service.ts b/frontend/src/app/modules/hal/dm-services/help-text-dm.service.tsdeleted file mode 100644index 89293b7c137..00000000000--- a/frontend/src/app/modules/hal/dm-services/help-text-dm.service.ts+++ /dev/null@@ -1,52 +0,0 @@-//-- 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 {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';-import {HelpTextResource} from 'core-app/modules/hal/resources/help-text-resource';-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';-import {Injectable} from '@angular/core';--@Injectable()-export class HelpTextDmService {- constructor(protected halResourceService:HalResourceService,- protected pathHelper:PathHelperService) {- }-- public loadAll():Promise<CollectionResource<HelpTextResource>> {- return this.halResourceService- .get<CollectionResource<HelpTextResource>>(this.pathHelper.api.v3.help_texts.toString())- .toPromise();- }-- public load(helpTextId:string):Promise<HelpTextResource> {- return this.halResourceService- .get<HelpTextResource>(this.pathHelper.api.v3.help_texts.id(helpTextId).toString())- .toPromise();- }-}diff --git a/frontend/src/app/modules/hal/dm-services/query-dm.service.ts b/frontend/src/app/modules/hal/dm-services/query-dm.service.tsdeleted file mode 100644index 59e9f433b8c..00000000000--- a/frontend/src/app/modules/hal/dm-services/query-dm.service.ts+++ /dev/null@@ -1,191 +0,0 @@-//-- 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 {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {PayloadDmService} from 'core-app/modules/hal/dm-services/payload-dm.service';-import {QueryResource} from 'core-app/modules/hal/resources/query-resource';-import {WorkPackageCollectionResource} from 'core-app/modules/hal/resources/wp-collection-resource';-import {QueryFormResource} from 'core-app/modules/hal/resources/query-form-resource';-import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';-import {Injectable} from '@angular/core';-import {UrlParamsHelperService} from 'core-components/wp-query/url-params-helper';-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';-import {Observable} from "rxjs";-import {QueryFiltersService} from "core-components/wp-query/query-filters.service";-import {DmListParameter} from "core-app/modules/hal/dm-services/dm.service.interface";-import {AbstractDmService} from "core-app/modules/hal/dm-services/abstract-dm.service";-import {HttpClient} from "@angular/common/http";-import * as URI from 'urijs';--export interface PaginationObject {- pageSize:number;- offset:number;-}--@Injectable()-export class QueryDmService extends AbstractDmService<QueryResource> {- constructor(protected halResourceService:HalResourceService,- protected http:HttpClient,- protected pathHelper:PathHelperService,- protected UrlParamsHelper:UrlParamsHelperService,- protected QueryFilters:QueryFiltersService,- protected PayloadDm:PayloadDmService) {- super(halResourceService,- pathHelper);- }-- /**- * Stream the response for the given query request- * @param queryData- * @param queryId- * @param projectIdentifier- */- public stream(queryData:Object, queryId?:string, projectIdentifier?:string|null):Observable<QueryResource> {- let path:string;-- if (queryId) {- path = this.pathHelper.api.v3.queries.id(queryId).toString();- } else {- path = this.pathHelper.api.v3.withOptionalProject(projectIdentifier).queries.default.toString();- }-- return this.halResourceService- .get<QueryResource>(path, queryData);- }-- public find(queryData:Object, queryId?:string, projectIdentifier?:string|null):Promise<QueryResource> {- return this.stream(queryData, queryId, projectIdentifier).toPromise();- }-- public findDefault(queryData:Object, projectIdentifier?:string|null):Promise<QueryResource> {- return this.find(queryData, undefined, projectIdentifier);- }-- public reload(query:QueryResource, pagination:PaginationObject):Promise<QueryResource> {- let path = this.pathHelper.api.v3.queries.id(query.id!).toString();-- return this.halResourceService- .get<QueryResource>(path, pagination)- .toPromise();- }-- public loadResults(query:QueryResource, pagination:PaginationObject):Promise<QueryResource> {- if (!query.results) {- throw 'No results embedded when expected';- }-- let queryData = this.UrlParamsHelper.buildV3GetQueryFromQueryResource(query, pagination);- let url = URI(query.href!).path();-- return this.halResourceService- .get<QueryResource>(url, queryData)- .toPromise();- }-- public loadIdsUpdatedSince(ids:any, timestamp:any):Promise<WorkPackageCollectionResource> {- const filters = [- {- id: {- operator: '=',- values: ids.filter((n:String|null) => n) // no null values- },- },- {- updatedAt: {- operator: '<>d',- values: [timestamp, '']- }- }- ];-- return this.halResourceService- .get<WorkPackageCollectionResource>(this.pathHelper.api.v3.work_packages.toString(), { filters: JSON.stringify(filters) })- .toPromise();- }-- public update(query:QueryResource, form:QueryFormResource):Observable<QueryResource> {- const payload = this.extractPayload(query, form);- return this.patch(query.id!, payload);- }-- public patch(id:string, payload:{ [key:string]:unknown }):Observable<QueryResource> {- let path:string = this.pathHelper.api.v3.queries.id(id).toString();- return this.halResourceService- .patch<QueryResource>(path, payload);- }-- public create(query:QueryResource, form:QueryFormResource):Promise<QueryResource> {- const payload:any = this.extractPayload(query, form);- let path:string = this.pathHelper.api.v3.queries.toString();-- return this.halResourceService- .post<QueryResource>(path, payload)- .toPromise();- }-- public delete(query:QueryResource) {- return query.delete();- }-- public toggleStarred(query:QueryResource) {- if (query.starred) {- return query.unstar();- } else {- return query.star();- }- }-- public listNonHidden(projectIdentifier:string|null|undefined):Promise<CollectionResource<QueryResource>> {- let listParams:DmListParameter = {- filters: [['hidden', '=', ['f']]]- };-- if (projectIdentifier) {- // all queries with the provided projectIdentifier- listParams.filters!.push(['project_identifier', '=', [projectIdentifier]]);- } else {- // all queries having no project (i.e. being global)- listParams.filters!.push(['project', '!*', []]);- }- return this.list(listParams);- }-- private extractPayload(query:QueryResource, form:QueryFormResource):QueryResource {- // Extracting requires having the filter schemas loaded as the dependencies- this.QueryFilters.mapSchemasIntoFilters(query, form);- return this.PayloadDm.extract<QueryResource>(query, form.schema);- }-- protected listUrl():string {- return this.pathHelper.api.v3.queries.toString();- }-- protected oneUrl(id:number|string):string {- return this.pathHelper.api.v3.queries.id(id).toString();- }-}diff --git a/frontend/src/app/modules/hal/dm-services/relations-dm.service.ts b/frontend/src/app/modules/hal/dm-services/relations-dm.service.tsdeleted file mode 100644index 55c9bb4085f..00000000000--- a/frontend/src/app/modules/hal/dm-services/relations-dm.service.ts+++ /dev/null@@ -1,66 +0,0 @@-//-- 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 {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {Injectable} from '@angular/core';-import {RelationResource} from 'core-app/modules/hal/resources/relation-resource';-import {buildApiV3Filter} from 'core-app/components/api/api-v3/api-v3-filter-builder';-import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';--@Injectable()-export class RelationsDmService {-- constructor(private halResourceService:HalResourceService,- private pathHelper:PathHelperService) {-- }-- public load(workPackageId:string):Promise<RelationResource[]> {- return this.halResourceService.get<CollectionResource<RelationResource>>(- this.pathHelper.api.v3.work_packages.id(workPackageId).relations, {})- .toPromise()- .then((collection:CollectionResource<RelationResource>) => collection.elements);- }-- public loadInvolved(workPackageIds:string[]):Promise<RelationResource[]> {- let validIds = _.filter(workPackageIds, id => /\d+/.test(id));-- if (validIds.length === 0) {- return Promise.resolve([]);- }-- return this.halResourceService.get<CollectionResource<RelationResource>>(- this.pathHelper.api.v3.relations.toPath(),- {- filters: buildApiV3Filter('involved', '=', validIds).toJson()- })- .toPromise()- .then((collection:CollectionResource<RelationResource>) => collection.elements);- }-}diff --git a/frontend/src/app/modules/hal/dm-services/root-dm.service.ts b/frontend/src/app/modules/hal/dm-services/root-dm.service.tsdeleted file mode 100644index a241a73e75f..00000000000--- a/frontend/src/app/modules/hal/dm-services/root-dm.service.ts+++ /dev/null@@ -1,45 +0,0 @@-//-- 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 {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {Injectable} from '@angular/core';-import {RootResource} from 'core-app/modules/hal/resources/root-resource';-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';--@Injectable()-export class RootDmService {- constructor(protected halResourceService:HalResourceService,- protected pathHelper:PathHelperService) {- }-- public load():Promise<RootResource> {- return this.halResourceService- .get<RootResource>(this.pathHelper.api.v3.root.toString())- .toPromise();- }-}diff --git a/frontend/src/app/modules/hal/dm-services/time-entry-dm.service.ts b/frontend/src/app/modules/hal/dm-services/time-entry-dm.service.tsdeleted file mode 100644index 4bba2b7b3f1..00000000000--- a/frontend/src/app/modules/hal/dm-services/time-entry-dm.service.ts+++ /dev/null@@ -1,93 +0,0 @@-//-- 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 {Injectable} from '@angular/core';-import {AbstractDmService} from "core-app/modules/hal/dm-services/abstract-dm.service";-import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";-import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";-import {FormResource} from "core-app/modules/hal/resources/form-resource";-import {HalResource} from "core-app/modules/hal/resources/hal-resource";-import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";-import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";-import {PayloadDmService} from "core-app/modules/hal/dm-services/payload-dm.service";--@Injectable()-export class TimeEntryDmService extends AbstractDmService<TimeEntryResource> {- constructor(protected halResourceService:HalResourceService,- protected pathHelper:PathHelperService,- protected payloadDm:PayloadDmService) {- super(halResourceService, pathHelper);- }-- protected listUrl() {- return this.pathHelper.api.v3.time_entries.toString();- }-- protected oneUrl(id:number|string) {- return this.pathHelper.api.v3.time_entries.id(id).toString();- }-- public update(resource:TimeEntryResource, schema:SchemaResource|null = null) {- let payload = this.extractPayload(resource, schema);-- return this.halResourceService.patch<TimeEntryResource>(resource.updateImmediately.$link.href, payload).toPromise();- }-- public updateForm(resource:TimeEntryResource, schema:SchemaResource|null = null) {- let payload = this.extractPayload(resource, schema);-- return this.halResourceService.post<FormResource>(this.pathHelper.api.v3.time_entries.id(resource.idFromLink).form.toString(),- payload).toPromise();- }-- public createForm(payload:{}) {- return this.halResourceService.post<FormResource>(this.pathHelper.api.v3.time_entries.form.toString(), payload).toPromise();- }-- public create(payload:{}):Promise<TimeEntryResource> {- return this.halResourceService- .post<TimeEntryResource>(this.pathHelper.api.v3.time_entries.path, payload)- .toPromise();- }-- public delete(resource:TimeEntryResource) {- return this.halResourceService- .delete<TimeEntryResource>(this.pathHelper.api.v3.time_entries.id(resource.idFromLink).toString())- .toPromise();- }-- public extractPayload(resource:TimeEntryResource|null = null, schema:SchemaResource|null = null) {- if (resource && schema) {- return this.payloadDm.extract(resource, schema);- } else if (!(resource instanceof HalResource)) {- return resource;- } else {- return {};- }- }-}diff --git a/frontend/src/app/modules/hal/dm-services/type-dm.service.ts b/frontend/src/app/modules/hal/dm-services/type-dm.service.tsdeleted file mode 100644index e0650a30127..00000000000--- a/frontend/src/app/modules/hal/dm-services/type-dm.service.ts+++ /dev/null@@ -1,62 +0,0 @@-//-- 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 {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {Injectable} from '@angular/core';-import {RootResource} from 'core-app/modules/hal/resources/root-resource';-import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';-import {TypeResource} from 'core-app/modules/hal/resources/type-resource';-import {States} from 'core-app/components/states.service';-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';--@Injectable()-export class TypeDmService {- constructor(protected halResourceService:HalResourceService,- protected states:States,- protected pathHelper:PathHelperService) {- }-- public loadAll(projectIdentifier:string|undefined):Promise<TypeResource[]> {- const typeUrl = this.pathHelper.api.v3.withOptionalProject(projectIdentifier).types.toString();-- return this.halResourceService- .get<CollectionResource<TypeResource>>(typeUrl)- .toPromise()- .then((result:CollectionResource<TypeResource>) => {- // TODO move into a TypeCacheService- _.each(result.elements, (type) => this.states.types.get(type.href!).putValue(type));- return result.elements;- });- }-- public load():Promise<RootResource> {- return this.halResourceService- .get<RootResource>(this.pathHelper.api.v3.root.toString())- .toPromise();- }-}diff --git a/frontend/src/app/modules/hal/dm-services/user-dm.service.ts b/frontend/src/app/modules/hal/dm-services/user-dm.service.tsdeleted file mode 100644index 0e629b6c314..00000000000--- a/frontend/src/app/modules/hal/dm-services/user-dm.service.ts+++ /dev/null@@ -1,47 +0,0 @@-//-- 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 {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {Injectable} from '@angular/core';-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';-import {UserResource} from 'core-app/modules/hal/resources/user-resource';--@Injectable()-export class UserDmService {- constructor(protected halResourceService:HalResourceService,- protected pathHelper:PathHelperService) {- }-- public load(id:number|string):Promise<UserResource> {- const path = this.pathHelper.api.v3.users.id(id).toString();-- return this.halResourceService- .get<UserResource>(path)- .toPromise();- }-}diff --git a/frontend/src/app/modules/hal/dm-services/version-dm.service.ts b/frontend/src/app/modules/hal/dm-services/version-dm.service.tsdeleted file mode 100644index dbb9fe5ea79..00000000000--- a/frontend/src/app/modules/hal/dm-services/version-dm.service.ts+++ /dev/null@@ -1,100 +0,0 @@-//-- 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 {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {Injectable} from '@angular/core';-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';-import {VersionResource} from "core-app/modules/hal/resources/version-resource";-import {CollectionResource} from "core-app/modules/hal/resources/collection-resource";-import {HalResource} from "core-app/modules/hal/resources/hal-resource";-import {ProjectResource} from "core-app/modules/hal/resources/project-resource";-import {buildApiV3Filter} from "core-components/api/api-v3/api-v3-filter-builder";--@Injectable()-export class VersionDmService {- constructor(protected halResourceService:HalResourceService,- protected pathHelper:PathHelperService) {- }-- public createVersion(payload:any):Promise<VersionResource> {- return this.halResourceService- .post<VersionResource>(this.pathHelper.api.v3.versions.path, payload)- .toPromise();- }-- public emptyCreateForm(payload:any):Promise<HalResource> {- return this.halResourceService- .post<VersionResource>(this.pathHelper.api.v3.versions.form.toString(), payload)- .toPromise();- }--- public one(id:string|number):Promise<VersionResource> {- return this.halResourceService- .get<VersionResource>(this.pathHelper.api.v3.versions.id(id).toString())- .toPromise();- }-- public list():Promise<CollectionResource<VersionResource>> {- return this.halResourceService- .get<CollectionResource<VersionResource>>(this.pathHelper.api.v3.versions.toString())- .toPromise();- }-- public listForProject(projectId:string):Promise<CollectionResource<VersionResource>> {- return this.halResourceService- .get<CollectionResource<VersionResource>>(this.pathHelper.api.v3.projects.id(projectId).versions.toString())- .toPromise();- }-- public canCreateVersionInProject(id:string):Promise<boolean> {- return this.halResourceService- .get<CollectionResource<ProjectResource>>(- this.pathHelper.api.v3.versions.availableProjects.toString(),- { filters: buildApiV3Filter('id', '=', [id]).toJson() }- )- .toPromise()- .then((collection) => {- return collection.elements.length === 1;- });- }-- public listProjectsAvailableForVersions():Promise<CollectionResource<ProjectResource>> {- return this.halResourceService- .get<CollectionResource<ProjectResource>>(this.pathHelper.api.v3.versions.availableProjects.toString())- .toPromise();- }-- public patch(resource:VersionResource, payload:Object):Promise<VersionResource> {- return this.halResourceService- .patch<VersionResource>(- this.pathHelper.api.v3.versions.id(resource.id!).toString(),- payload)- .toPromise();- }-}diff --git a/frontend/src/app/modules/hal/dm-services/work-package-dm.service.ts b/frontend/src/app/modules/hal/dm-services/work-package-dm.service.tsdeleted file mode 100644index 057d655fd46..00000000000--- a/frontend/src/app/modules/hal/dm-services/work-package-dm.service.ts+++ /dev/null@@ -1,123 +0,0 @@-//-- 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 {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';-import {WorkPackageCollectionResource} from 'core-app/modules/hal/resources/wp-collection-resource';-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';-import {Injectable} from "@angular/core";-import {States} from "core-components/states.service";-import {buildApiV3Filter} from "core-components/api/api-v3/api-v3-filter-builder";-import {FormResource} from "core-app/modules/hal/resources/form-resource";--@Injectable()-export class WorkPackageDmService {- constructor(protected halResourceService:HalResourceService,- protected pathHelper:PathHelperService,- protected states:States) {- }-- /**- * Loads a WorkPackage.- *- * @param id The ID of the WorkPackage.- * @param force Bypass any cached value?- * @returns {IPromise<any>|IPromise<WorkPackageResource>} A promise for the WorkPackage.- */- public loadWorkPackageById(id:string, force = false) {- const url = this.pathHelper.api.v3.work_packages.id(id).toString();-- return this.halResourceService.get<WorkPackageResource>(url).toPromise();- }-- /**- * Loads the work packages collection for the given work package IDs.- * Returns a WP Collection with schemas and results embedded.- *- * @param ids- * @return {WorkPackageCollectionResource[]}- */- public loadWorkPackagesCollectionsFor(ids:string[]):Promise<WorkPackageCollectionResource[]> {- return this.halResourceService.getAllPaginated(- this.pathHelper.api.v3.work_packages.toString(),- ids.length,- {- filters: buildApiV3Filter('id', '=', ids).toJson(),- }- ) as any; // WorkPackageCollectionResource does not satisfy constraint HalResource[]- }-- /**- * Returns a promise to post `/api/v3/work_packages/form`.- *- * @returns An empty work package form resource.- */- public emptyCreateForm(request:any, projectIdentifier?:string|null):Promise<FormResource> {- return this.halResourceService- .post<FormResource>(this.workPackagesFormPath(projectIdentifier), request)- .toPromise();- }-- /**- * Returns a promise to post `/api/v3/work_packages/form` where the- * type has already been set to the one provided.- *- * @param typeId: The id of the type to initialize the form with- * @param projectIdentifier: The project to which the work package is initialized- * @returns An empty work package form resource.- */- public typedCreateForm(typeId:number, projectIdentifier:string|undefined|null):Promise<FormResource> {-- const typeUrl = this.pathHelper.api.v3.types.id(typeId).toString();- const request = { _links: { type: { href: typeUrl } } };-- return this.halResourceService- .post<FormResource>(this.workPackagesFormPath(projectIdentifier), request)- .toPromise();- }-- /**- * Create a work package from a form payload- *- * @param payload- * @return {Promise<WorkPackageResource>}- */- public createWorkPackage(payload:any):Promise<WorkPackageResource> {- return this.halResourceService- .post<WorkPackageResource>(this.pathHelper.api.v3.work_packages.path, payload)- .toPromise();- }-- private workPackagesFormPath(projectIdentifier:string|null|undefined):string {- if (projectIdentifier) {- return this.pathHelper.api.v3.projects.id(projectIdentifier).work_packages.form.toString();- } else {- return this.pathHelper.api.v3.work_packages.form.toString();- }- }-}diff --git a/frontend/src/app/modules/hal/openproject-hal.module.ts b/frontend/src/app/modules/hal/openproject-hal.module.tsindex a3a3760ed1a..30f20c16e43 100644--- a/frontend/src/app/modules/hal/openproject-hal.module.ts+++ b/frontend/src/app/modules/hal/openproject-hal.module.ts@@ -30,25 +30,8 @@ import {APP_INITIALIZER, ErrorHandler, NgModule} from '@angular/core';import {HTTP_INTERCEPTORS, HttpClientModule} from '@angular/common/http';import {initializeHalResourceConfig} from 'core-app/modules/hal/services/hal-resource.config';import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {ConfigurationDmService} from 'core-app/modules/hal/dm-services/configuration-dm.service';-import {HelpTextDmService} from 'core-app/modules/hal/dm-services/help-text-dm.service';-import {PayloadDmService} from 'core-app/modules/hal/dm-services/payload-dm.service';-import {QueryDmService} from 'core-app/modules/hal/dm-services/query-dm.service';-import {QueryFormDmService} from 'core-app/modules/hal/dm-services/query-form-dm.service';-import {RelationsDmService} from 'core-app/modules/hal/dm-services/relations-dm.service';-import {RootDmService} from 'core-app/modules/hal/dm-services/root-dm.service';-import {TypeDmService} from 'core-app/modules/hal/dm-services/type-dm.service';import {OpenProjectHeaderInterceptor} from 'core-app/modules/hal/http/openproject-header-interceptor';-import {UserDmService} from 'core-app/modules/hal/dm-services/user-dm.service';-import {ProjectDmService} from 'core-app/modules/hal/dm-services/project-dm.service';-import {GridDmService} from "core-app/modules/hal/dm-services/grid-dm.service";-import {TimeEntryDmService} from './dm-services/time-entry-dm.service';import {CommonModule} from "@angular/common";-import {NewsDmService} from './dm-services/news-dm.service';-import {StatusDmService} from "core-app/modules/hal/dm-services/status-dm.service";-import {VersionDmService} from "core-app/modules/hal/dm-services/version-dm.service";-import {QueryOrderDmService} from "core-app/modules/hal/dm-services/query-order-dm.service";-import {MembershipDmService} from "core-app/modules/hal/dm-services/membership-dm.service";import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";import {HalAwareErrorHandler} from "core-app/modules/hal/services/hal-aware-error-handler";@@ -61,23 +44,6 @@ import {HalAwareErrorHandler} from "core-app/modules/hal/services/hal-aware-erro{ provide: ErrorHandler, useClass: HalAwareErrorHandler },{ provide: HTTP_INTERCEPTORS, useClass: OpenProjectHeaderInterceptor, multi: true },{ provide: APP_INITIALIZER, useFactory: initializeHalResourceConfig, deps: [HalResourceService], multi: true },- ConfigurationDmService,- GridDmService,- HelpTextDmService,- MembershipDmService,- NewsDmService,- PayloadDmService,- ProjectDmService,- QueryDmService,- QueryOrderDmService,- QueryFormDmService,- RelationsDmService,- RootDmService,- TimeEntryDmService,- TypeDmService,- UserDmService,- StatusDmService,- VersionDmService,HalResourceNotificationService]})diff --git a/frontend/src/app/modules/hal/resources/hal-resource.spec.ts b/frontend/src/app/modules/hal/resources/hal-resource.spec.tsindex 95527e8a30a..4fea40c4da4 100644--- a/frontend/src/app/modules/hal/resources/hal-resource.spec.ts+++ b/frontend/src/app/modules/hal/resources/hal-resource.spec.ts@@ -29,7 +29,6 @@import {Injector} from '@angular/core';import {async, TestBed} from '@angular/core/testing';import {I18nService} from 'core-app/modules/common/i18n/i18n.service';-import {TypeDmService} from 'core-app/modules/hal/dm-services/type-dm.service';import {HalLink, HalLinkInterface} from 'core-app/modules/hal/hal-link/hal-link';import {OpenprojectHalModule} from 'core-app/modules/hal/openproject-hal.module';import {HalResource} from 'core-app/modules/hal/resources/hal-resource';@@ -57,7 +56,6 @@ describe('HalResource', () => {providers: [HalResourceService,States,- TypeDmService,I18nService,]})diff --git a/frontend/src/app/modules/hal/resources/mixins/attachable-mixin.ts b/frontend/src/app/modules/hal/resources/mixins/attachable-mixin.tsindex 29c4f33b3c5..df07cf0e6c3 100644--- a/frontend/src/app/modules/hal/resources/mixins/attachable-mixin.ts+++ b/frontend/src/app/modules/hal/resources/mixins/attachable-mixin.ts@@ -33,6 +33,7 @@ import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';import {NotificationsService} from 'core-app/modules/common/notifications/notifications.service';import {HttpErrorResponse} from "@angular/common/http";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";type Constructor<T = {}> = new (...args:any[]) => T;@@ -44,6 +45,7 @@ export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {private halNotification:HalResourceNotificationService;private opFileUpload:OpenProjectFileUploadService;private pathHelper:PathHelperService;+ private apiV3Service:APIV3Service;/*** Can be used in the mixed in class to disable@@ -169,7 +171,7 @@ export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {let href = '';if (this.isNew || !this.id || !this.attachmentsBackend) {- href = this.pathHelper.api.v3.attachments.path;+ href = this.apiV3Service.attachments.path;} else {href = this.addAttachment.$link.href;}@@ -198,6 +200,10 @@ export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {this.pathHelper = this.injector.get(PathHelperService);}+ if (!this.apiV3Service) {+ this.apiV3Service = this.injector.get(APIV3Service);+ }+super.$initialize(source);let attachments = this.attachments || {$source: {}, elements: []};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 d0ed39dfbbd..44276ae8058 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@@ -46,7 +46,9 @@ export class QueryFilterInstanceResource extends HalResource {public $initialize(source:any) {super.$initialize(source);- this.$links['schema'] = { href: this.pathHelper.api.v3.queries.filterInstanceSchema(this.filter.idFromLink).path };+ this.$links['schema'] = {+ href: this.pathHelper.api.v3.apiV3Base + '/queries/filter_instance_schemas/' + this.filter.idFromLink+ };}public get id():string {@@ -72,7 +74,11 @@ export class QueryFilterInstanceResource extends HalResource {let key = this.operator.href!.toString();if (this.memoizedCurrentSchemas[key] === undefined) {- this.memoizedCurrentSchemas[key] = this.schemaCache.of(this).resultingSchema(this.operator);+ try {+ this.memoizedCurrentSchemas[key] = this.schemaCache.of(this).resultingSchema(this.operator);+ } catch(e) {+ console.error("Failed to access filter schema" + e);+ }}return this.memoizedCurrentSchemas[key];diff --git a/frontend/src/app/modules/hal/resources/query-resource.ts b/frontend/src/app/modules/hal/resources/query-resource.tsindex 0f3f0824c60..12bdfe6e1ae 100644--- a/frontend/src/app/modules/hal/resources/query-resource.ts+++ b/frontend/src/app/modules/hal/resources/query-resource.ts@@ -34,7 +34,7 @@ import {QueryFilterInstanceResource} from 'core-app/modules/hal/resources/query-import {HalResource} from 'core-app/modules/hal/resources/hal-resource';import {WorkPackageCollectionResource} from 'core-app/modules/hal/resources/wp-collection-resource';import {HighlightingMode} from "core-components/wp-fast-table/builders/highlighting/highlighting-mode.const";-import {QueryOrder} from "core-app/modules/hal/dm-services/query-order-dm.service";+import {QueryOrder} from "core-app/modules/apiv3/endpoints/queries/apiv3-query-order";export interface QueryResourceEmbedded {results:WorkPackageCollectionResource;diff --git a/frontend/src/app/modules/hal/resources/work-package-resource.spec.ts b/frontend/src/app/modules/hal/resources/work-package-resource.spec.tsindex e33a0ddcb74..a0cd64a9ed8 100644--- a/frontend/src/app/modules/hal/resources/work-package-resource.spec.ts+++ b/frontend/src/app/modules/hal/resources/work-package-resource.spec.ts@@ -31,13 +31,11 @@ import {OpenprojectHalModule} from 'core-app/modules/hal/openproject-hal.module'import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';import {Injector} from '@angular/core';import {States} from 'core-components/states.service';-import {TypeDmService} from 'core-app/modules/hal/dm-services/type-dm.service';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {NotificationsService} from 'core-app/modules/common/notifications/notifications.service';import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";import {SchemaCacheService} from 'core-components/schemas/schema-cache.service';import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';-import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';import {AttachmentCollectionResource} from 'core-app/modules/hal/resources/attachment-collection-resource';import {LoadingIndicatorService} from 'core-app/modules/common/loading-indicator/loading-indicator.service';import {ConfigurationService} from 'core-app/modules/common/config/configuration.service';@@ -45,15 +43,14 @@ import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {StateService} from "@uirouter/core";import {OpenProjectFileUploadService} from "core-components/api/op-file-upload/op-file-upload.service";import {WorkPackageCreateService} from 'core-app/components/wp-new/wp-create.service';-import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";import {WorkPackagesActivityService} from "core-components/wp-single-view-tabs/activity-panel/wp-activity.service";import {TimezoneService} from "core-components/datetime/timezone.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";describe('WorkPackage', () => {let halResourceService:HalResourceService;let injector:Injector;- let wpCacheService:WorkPackageCacheService;let notificationsService:NotificationsService;let halResourceNotification:HalResourceNotificationService;@@ -74,8 +71,6 @@ describe('WorkPackage', () => {providers: [HalResourceService,States,- TypeDmService,- WorkPackageCacheService,TimezoneService,WorkPackagesActivityService,NotificationsService,@@ -84,9 +79,9 @@ describe('WorkPackage', () => {LoadingIndicatorService,PathHelperService,I18nService,+ APIV3Service,{ provide: HalResourceNotificationService, useValue: { handleRawError: () => false } },{ provide: WorkPackageNotificationService, useValue: {} as any },- { provide: WorkPackageDmService, useValue: {} },{ provide: WorkPackageCreateService, useValue: {} },{ provide: StateService, useValue: {} },{ provide: SchemaCacheService, useValue: {} },@@ -96,7 +91,6 @@ describe('WorkPackage', () => {.then(() => {halResourceService = TestBed.get(HalResourceService);injector = TestBed.get(Injector);- wpCacheService = injector.get(WorkPackageCacheService);notificationsService = injector.get(NotificationsService);halResourceNotification = injector.get(HalResourceNotificationService);diff --git a/frontend/src/app/modules/hal/resources/work-package-resource.ts b/frontend/src/app/modules/hal/resources/work-package-resource.tsindex 81cd21176f3..27eb7d7816e 100644--- a/frontend/src/app/modules/hal/resources/work-package-resource.ts+++ b/frontend/src/app/modules/hal/resources/work-package-resource.ts@@ -37,16 +37,15 @@ import {UploadFile} from 'core-components/api/op-file-upload/op-file-upload.service';import {States} from 'core-components/states.service';-import {WorkPackageCacheService} from 'core-components/work-packages/work-package-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';-import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";import {FormResource} from "core-app/modules/hal/resources/form-resource";import {InputState} from "reactivestates";import {WorkPackagesActivityService} from "core-components/wp-single-view-tabs/activity-panel/wp-activity.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 {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export interface WorkPackageResourceEmbedded {activities:CollectionResource;@@ -124,10 +123,9 @@ export class WorkPackageBaseResource extends HalResource {public attachments:AttachmentCollectionResource;@InjectField() I18n:I18nService;- @InjectField() tates:States;+ @InjectField() states:States;@InjectField() wpActivity:WorkPackagesActivityService;- @InjectField() workPackageDmService:WorkPackageDmService;- @InjectField() wpCacheService:WorkPackageCacheService;+ @InjectField() apiV3Service:APIV3Service;@InjectField() NotificationsService:NotificationsService;@InjectField() workPackageNotificationService:WorkPackageNotificationService;@InjectField() pathHelper:PathHelperService;@@ -170,7 +168,7 @@ export class WorkPackageBaseResource extends HalResource {public previewPath() {if (!this.isNew) {- return this.pathHelper.api.v3.work_packages.id(this.id!).path;+ return this.apiV3Service.work_packages.id(this.id!).path;} else {return super.previewPath();}@@ -184,7 +182,7 @@ export class WorkPackageBaseResource extends HalResource {let href = '';if (this.isNew) {- href = this.pathHelper.api.v3.attachments.path;+ href = this.apiV3Service.attachments.path;} else {href = this.attachments.$href!;}@@ -255,10 +253,10 @@ export class WorkPackageBaseResource extends HalResource {// If there is a parent, its view has to be updated as wellif (newValue.parent) {- this.wpCacheService.require(newValue.parent.id!, true);+ this.apiV3Service.work_packages.id(newValue.parent).refresh();}- return this.wpCacheService.updateWorkPackage(newValue as any);+ return this.apiV3Service.work_packages.cache.updateWorkPackage(newValue as any);}}diff --git a/frontend/src/app/modules/hal/dm-services/payload-dm.service.ts b/frontend/src/app/modules/hal/schemas/hal-payload.helper.tssimilarity index 67%rename from frontend/src/app/modules/hal/dm-services/payload-dm.service.tsrename to frontend/src/app/modules/hal/schemas/hal-payload.helper.tsindex c17515483aa..e2bbf3c5fcb 100644--- a/frontend/src/app/modules/hal/dm-services/payload-dm.service.ts+++ b/frontend/src/app/modules/hal/schemas/hal-payload.helper.ts@@ -26,13 +26,38 @@// See docs/COPYRIGHT.rdoc for more details.//++-import {Injectable} from '@angular/core';import {HalResource} from 'core-app/modules/hal/resources/hal-resource';import {SchemaResource} from 'core-app/modules/hal/resources/schema-resource';-@Injectable()-export class PayloadDmService {- public extract<T extends HalResource = HalResource>(resource:T, schema:SchemaResource) {+export class HalPayloadHelper {++ /**+ * Extract payload from the given request with schema.+ * This will ensure we will only write writable attributes and so on.+ *+ * @param resource+ * @param schema+ */+ static extractPayload<T extends HalResource = HalResource>(resource:T|Object|null, schema:SchemaResource|null = null):Object {+ if (resource instanceof HalResource && schema) {+ return this.extractPayloadFromSchema(resource, schema);+ } else if (resource && !(resource instanceof HalResource)) {+ return resource;+ } else {+ return {};+ }+ }++ /**+ * Extract writable payload from a HAL resource class to be used for API calls.+ *+ * The schema contains writable information about attributes, which is what this method+ * iterates in order to build the HAL-compatible object.+ *+ * @param resource A HalResource to extract payload from+ * @param schema The associated schema to determine writable state of attributes+ */+ static extractPayloadFromSchema<T extends HalResource = HalResource>(resource:T, schema:SchemaResource) {let payload:any = {'_links': {}};@@ -62,7 +87,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.extractPayloadFromSchema(element, element.currentSchema || element.schema);} else {return element;}diff --git a/frontend/src/app/modules/hal/services/hal-resource.service.ts b/frontend/src/app/modules/hal/services/hal-resource.service.tsindex ad19ea586bd..94333552545 100644--- a/frontend/src/app/modules/hal/services/hal-resource.service.ts+++ b/frontend/src/app/modules/hal/services/hal-resource.service.ts@@ -133,14 +133,14 @@ export class HalResourceService {// Current offset pagelet page = 1;// Accumulated results- const allResults:CollectionResource[] = [];+ const allResults:T = [] as any;// If possible, request all at once.params.pageSize = expected;while (retrieved < expected) {params.offset = page;- const promise = this.request<CollectionResource>('get', href, this.toEprops(params), headers).toPromise();+ const promise = this.request('get', href, this.toEprops(params), headers).toPromise();const results = await promise;if (results.count === 0) {diff --git a/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.tsindex 0855de1d9a8..e6ceae6da0c 100644--- a/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts+++ b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts@@ -13,6 +13,7 @@ import {import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {JobStatusEnum, JobStatusInterface} from "core-app/modules/job-status/job-status.interface";import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({@@ -63,6 +64,7 @@ export class JobStatusModal extends OpModalComponent implements OnInit {readonly I18n:I18nService,readonly elementRef:ElementRef,readonly pathHelper:PathHelperService,+ readonly apiV3Service:APIV3Service,readonly loadingIndicator:LoadingIndicatorService,readonly notifications:NotificationsService,readonly httpClient:HttpClient) {@@ -173,6 +175,6 @@ export class JobStatusModal extends OpModalComponent implements OnInit {}private get jobUrl():string {- return this.pathHelper.api.v3.job_statuses.id(this.jobId).toString();+ return this.apiV3Service.job_statuses.id(this.jobId).toString();}}diff --git a/frontend/src/app/modules/plugins/plugin-context.ts b/frontend/src/app/modules/plugins/plugin-context.tsindex b280878bdfe..9260a2026b0 100644--- a/frontend/src/app/modules/plugins/plugin-context.ts+++ b/frontend/src/app/modules/plugins/plugin-context.ts@@ -7,13 +7,11 @@ import {ExternalQueryConfigurationService} from "core-components/wp-table/externimport {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";import {PasswordConfirmationModal} from "../../components/modals/request-for-confirmation/password-confirmation.modal";import {OpModalService} from "../../components/op-modals/op-modal.service";-import {HelpTextDmService} from "../hal/dm-services/help-text-dm.service";import {AttributeHelpTextsService} from "../common/help-texts/attribute-help-text.service";import {AttributeHelpTextModal} from "../common/help-texts/attribute-help-text.modal";import {DynamicContentModal} from "../../components/modals/modal-wrapper/dynamic-content.modal";import {DisplayField} from "core-app/modules/fields/display/display-field.module";import {HalResource} from "core-app/modules/hal/resources/hal-resource";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {DisplayFieldService} from "core-app/modules/fields/display/display-field.service";import {EditFieldService} from "core-app/modules/fields/edit/edit-field.service";import {OpenProjectFileUploadService} from "core-components/api/op-file-upload/op-file-upload.service";@@ -25,6 +23,7 @@ import {States} from 'core-components/states.service';import {CKEditorPreviewService} from "core-app/modules/common/ckeditor/ckeditor-preview.service";import {ExternalRelationQueryConfigurationService} from "core-components/wp-table/external-configuration/external-relation-query-configuration.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";/*** Plugin context bridge for plugins outside the CLI compiler context@@ -49,16 +48,15 @@ export class OpenProjectPluginContext {notifications: this.injector.get<NotificationsService>(NotificationsService),opModalService: this.injector.get<OpModalService>(OpModalService),opFileUpload: this.injector.get<OpenProjectFileUploadService>(OpenProjectFileUploadService),- helpTextDm: this.injector.get<HelpTextDmService>(HelpTextDmService),attributeHelpTexts: this.injector.get<AttributeHelpTextsService>(AttributeHelpTextsService),displayField: this.injector.get<DisplayFieldService>(DisplayFieldService),editField: this.injector.get<EditFieldService>(EditFieldService),- wpCache: this.injector.get<WorkPackageCacheService>(WorkPackageCacheService),macros: this.injector.get<EditorMacrosService>(EditorMacrosService),htmlSanitizeService: this.injector.get<HTMLSanitizeService>(HTMLSanitizeService),ckEditorPreview: this.injector.get<CKEditorPreviewService>(CKEditorPreviewService),pathHelperService: this.injector.get<PathHelperService>(PathHelperService),states: this.injector.get<States>(States),+ apiV3Service: this.injector.get<APIV3Service>(APIV3Service)};// Random collection of classes needed outside of angulardiff --git a/frontend/src/app/modules/time_entries/create/create.service.ts b/frontend/src/app/modules/time_entries/create/create.service.tsindex 2755ecc361f..b8925f21a97 100644--- a/frontend/src/app/modules/time_entries/create/create.service.ts+++ b/frontend/src/app/modules/time_entries/create/create.service.ts@@ -5,13 +5,13 @@ import { I18nService } from "core-app/modules/common/i18n/i18n.service";import { TimeEntryResource } from 'core-app/modules/hal/resources/time-entry-resource';import { take } from 'rxjs/operators';import { FormResource } from "core-app/modules/hal/resources/form-resource";-import { TimeEntryDmService } from "core-app/modules/hal/dm-services/time-entry-dm.service";import { ResourceChangeset } from "core-app/modules/fields/changeset/resource-changeset";import { HalResourceEditingService } from "core-app/modules/fields/edit/services/hal-resource-editing.service";import { 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";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable()export class TimeEntryCreateService {@@ -19,7 +19,7 @@ export class TimeEntryCreateService {constructor(readonly opModalService:OpModalService,readonly injector:Injector,readonly halResource:HalResourceService,- readonly timeEntryDm:TimeEntryDmService,+ readonly apiV3Service:APIV3Service,readonly schemaCache:SchemaCacheService,protected halEditing:HalResourceEditingService,readonly i18n:I18nService) {@@ -59,7 +59,13 @@ export class TimeEntryCreateService {};}- return this.timeEntryDm.createForm(payload).then(form => {+ return this+ .apiV3Service+ .time_entries+ .form+ .post(payload)+ .toPromise()+ .then(form => {return this.fromCreateForm(form);});}@@ -83,7 +89,11 @@ export class TimeEntryCreateService {entry['update'] = entry.$links['update'] = form.$links.self;// Use POST /work_packages for saving linkentry['updateImmediately'] = entry.$links['updateImmediately'] = (payload:{}) => {- return this.timeEntryDm.create(payload);+ return this+ .apiV3Service+ .time_entries+ .post(payload)+ .toPromise();};entry.state.putValue(entry);diff --git a/frontend/src/app/modules/time_entries/edit/edit.service.ts b/frontend/src/app/modules/time_entries/edit/edit.service.tsindex 44857b93abc..9360911d485 100644--- a/frontend/src/app/modules/time_entries/edit/edit.service.ts+++ b/frontend/src/app/modules/time_entries/edit/edit.service.ts@@ -7,14 +7,14 @@ import { 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";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable()export class TimeEntryEditService {constructor(readonly opModalService:OpModalService,readonly injector:Injector,- readonly timeEntryDm:TimeEntryDmService,+ readonly apiV3Service:APIV3Service,readonly halResource:HalResourceService,protected halEditing:HalResourceEditingService,readonly i18n:I18nService) {@@ -46,7 +46,14 @@ export class TimeEntryEditService {}public createChangeset(entry:TimeEntryResource) {- return this.timeEntryDm.updateForm(entry).then(form => {+ return this+ .apiV3Service+ .time_entries+ .id(entry)+ .form+ .post(entry)+ .toPromise()+ .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 7b5af9a2da7..43736a98228 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@@ -1,11 +1,11 @@import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, Injector, OnInit} from "@angular/core";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";import {TimeEntryEditService} from "core-app/modules/time_entries/edit/edit.service";-import {TimeEntryCacheService} from "core-components/time-entries/time-entry-cache.service";import {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";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {TimeEntryResource} from "core-app/modules/hal/resources/time-entry-resource";export const triggerActionsEntryComponentSelector = 'time-entry--trigger-actions-entry';@@ -31,8 +31,7 @@ export const triggerActionsEntryComponentSelector = 'time-entry--trigger-actions})export class TriggerActionsEntryComponent {@InjectField() readonly timeEntryEditService:TimeEntryEditService;- @InjectField() readonly timeEntryCache:TimeEntryCacheService;- @InjectField() readonly timeEntryDmService:TimeEntryDmService;+ @InjectField() readonly apiv3Service:APIV3Service;@InjectField() readonly notificationsService:NotificationsService;@InjectField() readonly elementRef:ElementRef;@InjectField() readonly i18n:I18nService;@@ -69,21 +68,26 @@ export class TriggerActionsEntryComponent {this.loadEntry().then(entry => {- this.timeEntryDmService- .delete(entry)- .then(() => {- window.location.reload();- })- .catch((error) => {- this.notificationsService.addError(error || this.text.error);- });+ this+ .apiv3Service+ .time_entries+ .id(entry)+ .delete()+ .subscribe(+ () => window.location.reload(),+ error => this.notificationsService.addError(error || this.text.error)+ );});}- protected loadEntry() {+ protected loadEntry():Promise<TimeEntryResource> {let timeEntryId = this.elementRef.nativeElement.dataset['entry'];- return this.timeEntryCache- .require(timeEntryId);+ return this+ .apiv3Service+ .time_entries+ .id(timeEntryId)+ .get()+ .toPromise();}}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 8f3f718593b..2607dd0c365 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@@ -6,7 +6,7 @@ import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {TimeEntryFormComponent} from "core-app/modules/time_entries/form/form.component";import {HalResource} from "core-app/modules/hal/resources/hal-resource";import { InjectField } from 'core-app/helpers/angular/inject-field.decorator';-import { WorkPackageCacheService } from 'core-app/components/work-packages/work-package-cache.service';+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Directive()export abstract class TimeEntryBaseModal extends OpModalComponent {@@ -23,7 +23,7 @@ export abstract class TimeEntryBaseModal extends OpModalComponent {public closeOnEscape = false;public closeOnOutsideClick = false;- @InjectField() workPackageCacheService:WorkPackageCacheService;+ @InjectField() apiV3Service:APIV3Service;constructor(readonly elementRef:ElementRef,@Inject(OpModalLocalsToken) readonly locals:OpModalLocalsMap,@@ -52,7 +52,11 @@ export abstract class TimeEntryBaseModal extends OpModalComponent {.then(() => {// reload workPackageif (this.entry.workPackage) {- this.workPackageCacheService.require(this.entry.workPackage.id, true);+ this+ .apiV3Service+ .work_packages+ .id(this.entry.workPackage)+ .refresh();}this.service.close();});diff --git a/frontend/src/app/modules/work-package-graphs/configuration/wp-graph-configuration.service.ts b/frontend/src/app/modules/work-package-graphs/configuration/wp-graph-configuration.service.tsindex 6484e7d5606..f84803981f4 100644--- a/frontend/src/app/modules/work-package-graphs/configuration/wp-graph-configuration.service.ts+++ b/frontend/src/app/modules/work-package-graphs/configuration/wp-graph-configuration.service.ts@@ -5,15 +5,14 @@ import {TabInterface} from "core-components/wp-table/configuration-modal/tab-porimport {Injectable} from '@angular/core';import {WpGraphConfigurationFiltersTab} from "core-app/modules/work-package-graphs/configuration-modal/tabs/filters-tab.component";import {ChartType} from 'chart.js';-import {QueryFormDmService} from "core-app/modules/hal/dm-services/query-form-dm.service";import {QueryFormResource} from "core-app/modules/hal/resources/query-form-resource";-import {QueryDmService} from "core-app/modules/hal/dm-services/query-dm.service";import {WpGraphConfiguration,WpGraphQueryParams} from "core-app/modules/work-package-graphs/configuration/wp-graph-configuration";import {CurrentProjectService} from "core-components/projects/current-project.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable()export class WpGraphConfigurationService {@@ -23,8 +22,7 @@ export class WpGraphConfigurationService {private _formsPromise:Promise<void[]>|null;constructor(readonly I18n:I18nService,- readonly queryFormDm:QueryFormDmService,- protected readonly queryDm:QueryDmService,+ readonly apiv3Service:APIV3Service,readonly notificationService:WorkPackageNotificationService,readonly currentProject:CurrentProjectService) {}@@ -75,17 +73,23 @@ export class WpGraphConfigurationService {}private createInitial():Promise<QueryResource> {- return this.queryFormDm+ return this+ .apiv3Service+ .queries+ .form.loadWithParams({pageSize: 0},undefined,this.currentProject.identifier,WpGraphConfiguration.queryCreationParams(this.I18n, !!this.currentProject.identifier))- .then(form => {- const query = this.queryFormDm.buildQueryResource(form);-- return this.queryDm.create(query, form);+ .toPromise()+ .then(([form, query]) => {+ return this+ .apiv3Service+ .queries+ .post(query, form)+ .toPromise();});}@@ -98,12 +102,15 @@ export class WpGraphConfigurationService {}private loadQuery(params:WpGraphQueryParams) {- return this.queryDm+ return this+ .apiv3Service+ .queries.find(Object.assign({pageSize: 0}, params.props),params.id,this.currentProject.identifier,)+ .toPromise().then(query => {if (params.name) {query.name = params.name;@@ -116,8 +123,10 @@ export class WpGraphConfigurationService {return this.formFor(query).then(form => {return this- .queryDm- .update(query, form)+ .apiv3Service+ .queries+ .id(query)+ .patch(query, form).toPromise();});}@@ -162,9 +171,13 @@ export class WpGraphConfigurationService {public loadForms() {if (!this._formsPromise) {let formPromises = this.configuration.queries.map((query) => {- return this.queryFormDm+ return this+ .apiv3Service+ .queries+ .form.load(query)- .then((form:QueryFormResource) => {+ .toPromise()+ .then(([form, _]) => {this._forms[query.id as string] = form;}).catch((error) => this.notificationService.handleRawError(error));diff --git a/frontend/src/app/modules/work_packages/notifications/work-package-notification.service.ts b/frontend/src/app/modules/work_packages/notifications/work-package-notification.service.tsindex ddab4611748..4f9dfc42a3e 100644--- a/frontend/src/app/modules/work_packages/notifications/work-package-notification.service.ts+++ b/frontend/src/app/modules/work_packages/notifications/work-package-notification.service.ts@@ -30,13 +30,13 @@ import {Injectable, Injector} from '@angular/core';import {INotification} from 'core-app/modules/common/notifications/notifications.service';import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable()export class WorkPackageNotificationService extends HalResourceNotificationService {constructor(readonly injector:Injector,- protected wpCacheService:WorkPackageCacheService) {+ readonly apiV3Service:APIV3Service) {super(injector);}@@ -57,7 +57,7 @@ export class WorkPackageNotificationService extends HalResourceNotificationServitype: 'error',link: {text: this.I18n.t('js.hal.error.update_conflict_refresh'),- target: () => this.wpCacheService.require(resource.id!, true)+ target: () => this.apiV3Service.work_packages.id(resource).refresh()}});diff --git a/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts b/frontend/src/app/modules/work_packages/openproject-work-packages.module.tsindex d33e5ff34ff..07d691057c9 100644--- a/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts+++ b/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts@@ -125,11 +125,9 @@ import {ExternalRelationQueryConfigurationComponent} from "core-components/wp-taimport {ExternalRelationQueryConfigurationService} from "core-components/wp-table/external-configuration/external-relation-query-configuration.service";import {WorkPackageStaticQueriesService} from 'core-components/wp-query-select/wp-static-queries.service';import {WorkPackagesListInvalidQueryService} from 'core-components/wp-list/wp-list-invalid-query.service';-import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';import {SchemaCacheService} from 'core-components/schemas/schema-cache.service';import {WorkPackageWatchersService} from 'core-components/wp-single-view-tabs/watchers-tab/wp-watchers.service';import {WorkPackagesActivityService} from 'core-components/wp-single-view-tabs/activity-panel/wp-activity.service';-import {QueryFormDmService} from 'core-app/modules/hal/dm-services/query-form-dm.service';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {WorkPackageChildrenQueryComponent} from "core-components/wp-relations/embedded/children/wp-children-query.component";import {WpRelationInlineAddExistingComponent} from "core-components/wp-relations/embedded/inline/add-existing/wp-relation-inline-add-existing.component";@@ -143,7 +141,6 @@ import {WorkPackageFilterByTextInputComponent} from "core-components/filters/quiimport {QueryFiltersService} from "core-components/wp-query/query-filters.service";import {WorkPackageCardViewComponent} from "core-components/wp-card-view/wp-card-view.component";import {WorkPackageIsolatedQuerySpaceDirective} from "core-app/modules/work_packages/query-space/wp-isolated-query-space.directive";-import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";import {WorkPackageRelationsService} from "core-components/wp-relations/wp-relations.service";import {OpenprojectBcfModule} from "core-app/modules/bim/bcf/openproject-bcf.module";import {WorkPackageRelationsAutocomplete} from "core-components/wp-relations/wp-relations-create/wp-relations-autocomplete/wp-relations-autocomplete.component";@@ -195,7 +192,6 @@ import {AttributeHelpTextModal} from "core-app/modules/common/help-texts/attribuExternalRelationQueryConfigurationService,// Global work package states / services- WorkPackageCacheService,SchemaCacheService,// Global query/table state services@@ -208,16 +204,11 @@ import {AttributeHelpTextModal} from "core-app/modules/common/help-texts/attribu// Provide a separate service for creation events of WP Inline create// This can be hierarchically injected to provide isolated events on an embedded tableWorkPackageRelationsService,- WorkPackageCacheService,- SchemaCacheService,-- WorkPackageDmService,WorkPackagesActivityService,WorkPackageRelationsService,WorkPackageWatchersService,- QueryFormDmService,HalEventsService,],declarations: [diff --git a/frontend/src/app/modules/work_packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts b/frontend/src/app/modules/work_packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.tsindex 63ddc5bd55f..6d854ef7246 100644--- a/frontend/src/app/modules/work_packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts+++ b/frontend/src/app/modules/work_packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts@@ -234,20 +234,27 @@ export class PartitionedQuerySpacePageComponent extends WorkPackagesViewBase imprefresh(visibly:boolean = false, firstPage:boolean = false):Promise<unknown> {let promise:Promise<unknown>;+ let query = this.currentQuery;- if (firstPage) {+ if (firstPage || !query) {promise = this.loadFirstPage();} else {- promise = this.wpListService.reloadCurrentResultsList();+ let pagination = this.wpListService.getPaginationInfo();+ promise = this.wpListService+ .loadQueryFromExisting(query, pagination, this.projectIdentifier)+ .toPromise();}if (visibly) {- this.loadingIndicator = promise.then(() => {+ return this.loadingIndicator = promise.then((loadedQuery:QueryResource) => {+ this.wpStatesInitialization.initialize(loadedQuery, loadedQuery.results);return this.additionalLoadingTime();});}- return promise;+ return promise.then((loadedQuery:QueryResource) => {+ this.wpStatesInitialization.initialize(loadedQuery, loadedQuery.results);+ });}protected loadFirstPage():Promise<QueryResource> {diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-additional-elements.service.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-additional-elements.service.tsindex 90b514dc460..7aa6ac6ffc7 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-additional-elements.service.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-additional-elements.service.ts@@ -33,12 +33,12 @@ import {WorkPackageViewHierarchiesService} from './wp-view-hierarchy.service';import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";import {Injectable} from '@angular/core';import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {RelationsStateValue, WorkPackageRelationsService} from "core-components/wp-relations/wp-relations.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";import {WorkPackageCollectionResource} from "core-app/modules/hal/resources/wp-collection-resource";import {QueryResource} from "core-app/modules/hal/resources/query-resource";import {SchemaCacheService} from "core-components/schemas/schema-cache.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable()export class WorkPackageViewAdditionalElementsService {@@ -48,7 +48,7 @@ export class WorkPackageViewAdditionalElementsService {readonly wpTableColumns:WorkPackageViewColumnsService,readonly notificationService:WorkPackageNotificationService,readonly halResourceService:HalResourceService,- readonly wpCacheService:WorkPackageCacheService,+ readonly apiV3Service:APIV3Service,readonly schemaCache:SchemaCacheService,readonly wpRelations:WorkPackageRelationsService) {}@@ -67,7 +67,10 @@ export class WorkPackageViewAdditionalElementsService {}private loadAdditional(wpIds:string[]) {- this.wpCacheService.requireAll(wpIds)+ this+ .apiV3Service+ .work_packages+ .requireAll(wpIds).then(() => {this.querySpace.additionalRequiredWorkPackages.putValue(null, 'All required work packages are loaded');})@@ -87,7 +90,7 @@ export class WorkPackageViewAdditionalElementsService {return Promise.resolve([]);}return this.wpRelations- .requireAll(rows, true)+ .requireAll(rows).then(() => {const ids = this.getInvolvedWorkPackages(rows.map(id => {return this.wpRelations.state(id).value!;@@ -130,7 +133,7 @@ export class WorkPackageViewAdditionalElementsService {if (results.sumsSchema) {return this.schemaCache- .require(results.sumsSchema.$href!)+ .ensureLoaded(results.sumsSchema.$href!).then(() => []);}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 859d855b658..67d60085014 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@@ -325,4 +325,8 @@ export class WorkPackageViewFiltersService extends WorkPackageQueryStateService<private get currentFilterResources():QueryFilterResource[] {return this.rawFilters.map((filter:QueryFilterInstanceResource) => filter.filter);}++ isAvailable(el:QueryFilterInstanceResource):boolean {+ return !!this.availableFilters.find(available => available.id === el.id);+ }}diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service.spec.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service.spec.tsindex e01adfd587e..6080437d90e 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service.spec.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service.spec.ts@@ -34,9 +34,10 @@ import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isoimport {WorkPackageViewHierarchiesService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-hierarchy.service";import {WorkPackageRelationsHierarchyService} from "core-components/wp-relations/wp-relations-hierarchy/wp-relations-hierarchy.service";import {WorkPackageViewHierarchyIdentationService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {WorkPackageViewDisplayRepresentationService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-display-representation.service";import SpyObj = jasmine.SpyObj;+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {of} from "rxjs";describe('WorkPackageViewIndentation service', function () {let service:WorkPackageViewHierarchyIdentationService;@@ -51,10 +52,14 @@ describe('WorkPackageViewIndentation service', function () {}}- class WorkPackageCacheServiceStub {- require(wpId:string) {- return Promise.resolve(states.workPackages.get(wpId).value);- }+ class Apiv3serviceStub {+ work_packages = {+ id: (wpId:string) => {+ return {+ get: () => of(states.workPackages.get(wpId).value)+ };+ }+ };}beforeEach(async(() => {@@ -70,9 +75,8 @@ describe('WorkPackageViewIndentation service', function () {providers: [States,IsolatedQuerySpace,- WorkPackageCacheService,{ provide: WorkPackageViewDisplayRepresentationService, useValue: { isList: true } },- { provide: WorkPackageCacheService, useClass: WorkPackageCacheServiceStub },+ { provide: APIV3Service, useClass: Apiv3serviceStub },{ provide: WorkPackageViewHierarchiesService, useClass: HierarchyServiceStub },{ provide: WorkPackageRelationsHierarchyService, useValue: parentServiceSpy },WorkPackageViewHierarchyIdentationServicediff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service.tsindex 62f37c7e5e3..f3905a92dcf 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service.ts@@ -4,8 +4,8 @@ import {WorkPackageViewHierarchiesService} from "core-app/modules/work_packages/import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";import {WorkPackageRelationsHierarchyService} from "core-components/wp-relations/wp-relations-hierarchy/wp-relations-hierarchy.service";import {States} from "core-components/states.service";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {WorkPackageViewDisplayRepresentationService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-display-representation.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable()export class WorkPackageViewHierarchyIdentationService {@@ -14,7 +14,7 @@ export class WorkPackageViewHierarchyIdentationService {private wpDisplayRepresentation:WorkPackageViewDisplayRepresentationService,private states:States,private wpRelationHierarchy:WorkPackageRelationsHierarchyService,- private wpCacheService:WorkPackageCacheService,+ private apiV3Service:APIV3Service,private querySpace:IsolatedQuerySpace) {}@@ -89,7 +89,7 @@ export class WorkPackageViewHierarchyIdentationService {// If the predecessor is in an ancestor chain.// get the first element of the ancestor chain that workPackage is not in- const predecessor = await this.wpCacheService.require(predecessorId);+ const predecessor = await this.apiV3Service.work_packages.id(predecessorId).get().toPromise();const difference = _.difference(predecessor.ancestorIds, workPackage.ancestorIds);if (difference && difference.length > 0) {diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-order.service.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-order.service.tsindex c74a0398fdb..07aef41d4f1 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-order.service.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-order.service.ts@@ -36,18 +36,19 @@ import {States} from "core-components/states.service";import {QuerySchemaResource} from "core-app/modules/hal/resources/query-schema-resource";import {WorkPackageCollectionResource} from "core-app/modules/hal/resources/wp-collection-resource";import {MAX_ORDER, ReorderDeltaBuilder} from "core-app/modules/common/drag-and-drop/reorder-delta-builder";-import {QueryOrder, QueryOrderDmService} from "core-app/modules/hal/dm-services/query-order-dm.service";import {take} from "rxjs/operators";import {InputState} from "reactivestates";import {WorkPackageViewSortByService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-sort-by.service";import {CausedUpdatesService} from "core-app/modules/boards/board/caused-updates/caused-updates.service";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {QueryOrder} from "core-app/modules/apiv3/endpoints/queries/apiv3-query-order";@Injectable()export class WorkPackageViewOrderService extends WorkPackageQueryStateService<QueryOrder> {constructor(protected readonly querySpace:IsolatedQuerySpace,- protected readonly queryOrderDm:QueryOrderDmService,+ protected readonly apiV3Service:APIV3Service,protected readonly states:States,protected readonly causedUpdates:CausedUpdatesService,protected readonly wpTableSortBy:WorkPackageViewSortByService,@@ -143,7 +144,12 @@ export class WorkPackageViewOrderService extends WorkPackageQueryStateService<Qu// Push the update if the query is savedif (this.currentQuery.persisted) {- const updatedAt = await this.queryOrderDm.update(this.currentQuery.id!, delta);+ const updatedAt = await this+ .apiV3Service+ .queries.id(this.currentQuery)+ .order+ .update(delta);+this.currentQuery.updatedAt = updatedAt;// Remember that we caused this update@@ -171,7 +177,11 @@ export class WorkPackageViewOrderService extends WorkPackageQueryStateService<Qu// Load the current order from backendthis.positions.putFromPromiseIfPristine(- () => this.queryOrderDm.get(this.currentQuery.id!)+ () => this+ .apiV3Service+ .queries.id(this.currentQuery)+ .order+ .get());} else if (this.positions.isPristine()) {// Insert an empty fallback in case we have no data yetdiff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-pagination.service.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-pagination.service.tsindex 2d351f862b8..fb81e88941e 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-pagination.service.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-pagination.service.ts@@ -27,11 +27,10 @@//++import {Injectable} from '@angular/core';-import {PaginationObject} from 'core-app/modules/hal/dm-services/query-dm.service';import {QueryResource} from 'core-app/modules/hal/resources/query-resource';import {WorkPackageCollectionResource} from 'core-app/modules/hal/resources/wp-collection-resource';import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";-import {PaginationService} from 'core-components/table-pagination/pagination-service';+import {PaginationObject, PaginationService} from 'core-components/table-pagination/pagination-service';import {WorkPackageViewPagination} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-table-pagination";import {WorkPackageViewBaseService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-base.service";diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-relation-columns.service.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-relation-columns.service.tsindex 2d38a4184e3..16850add4ba 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-relation-columns.service.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-relation-columns.service.ts@@ -34,7 +34,6 @@ import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.serimport {RelationResource} from 'core-app/modules/hal/resources/relation-resource';import {WorkPackageViewRelationColumns} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-table-relation-columns";import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {RelationsStateValue, WorkPackageRelationsService} from "core-components/wp-relations/wp-relations.service";import {Injectable} from "@angular/core";import {@@ -43,6 +42,7 @@ import {RelationQueryColumn,TypeRelationQueryColumn} from "core-components/wp-query/query-column";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";export type RelationColumnType = 'toType'|'ofType';@@ -51,7 +51,7 @@ export class WorkPackageViewRelationColumnsService extends WorkPackageViewBaseSeconstructor(public querySpace:IsolatedQuerySpace,public wpTableColumns:WorkPackageViewColumnsService,public halResourceService:HalResourceService,- public wpCacheService:WorkPackageCacheService,+ public apiV3Service:APIV3Service,public wpRelations:WorkPackageRelationsService) {super(querySpace);}@@ -116,7 +116,7 @@ export class WorkPackageViewRelationColumnsService extends WorkPackageViewBaseSereturn _.filter(relations, (relation:RelationResource) => {const denormalized = relation.denormalized(workPackage);- const target = this.wpCacheService.state(denormalized.targetId).value;+ const target = this.apiV3Service.work_packages.cache.state(denormalized.targetId).value;return _.get(target, 'type.href') === typeHref;});diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-selection.service.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-selection.service.tsindex c4f5ef3177c..f915eb9537d 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-selection.service.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/view-services/wp-view-selection.service.ts@@ -1,5 +1,4 @@import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";-import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';import {Injectable, OnDestroy} from '@angular/core';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';import {States} from 'core-components/states.service';@@ -22,7 +21,6 @@ export class WorkPackageViewSelectionService extends WorkPackageViewBaseService<public constructor(readonly querySpace:IsolatedQuerySpace,readonly states:States,- readonly wpCacheService:WorkPackageCacheService,readonly opContextMenu:OPContextMenuService) {super(querySpace);this.reset();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 397c33f5890..4fcbbd9ce29 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@@ -31,10 +31,8 @@ import {I18nService} from 'core-app/modules/common/i18n/i18n.service';import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';import {WorkPackageViewFocusService} from 'core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-focus.service';import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';-import {ProjectCacheService} from 'core-components/projects/project-cache.service';import {OpTitleService} from 'core-components/html/op-title.service';import {AuthorisationService} from "core-app/modules/common/model-auth/model-auth.service";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {States} from "core-components/states.service";import {KeepTabService} from "core-components/wp-single-view-tabs/keep-tab/keep-tab.service";@@ -42,10 +40,11 @@ import {HalResourceEditingService} from "core-app/modules/fields/edit/services/himport {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";+import {catchError, subscribeOn} from "rxjs/operators";export class WorkPackageSingleViewBase extends UntilDestroyedMixin {- @InjectField() wpCacheService:WorkPackageCacheService;@InjectField() states:States;@InjectField() I18n:I18nService;@InjectField() keepTab:KeepTabService;@@ -53,9 +52,10 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {@InjectField() halEditing:HalResourceEditingService;@InjectField() wpTableFocus:WorkPackageViewFocusService;@InjectField() notificationService:WorkPackageNotificationService;- @InjectField() projectCacheService:ProjectCacheService;@InjectField() authorisationService:AuthorisationService;@InjectField() cdRef:ChangeDetectorRef;+ @InjectField() readonly titleService:OpTitleService;+ @InjectField() readonly apiV3Service:APIV3Service;// Static textspublic text:any = {};@@ -67,8 +67,6 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {public focusAnchorLabel:string;public showStaticPagePath:string;- @InjectField() readonly titleService:OpTitleService;-constructor(public injector:Injector, protected workPackageId:string) {super();this.initializeTexts();@@ -80,20 +78,21 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {*/protected observeWorkPackage() {/** Require the work package once to ensure we're displaying errors */- this.wpCacheService.require(this.workPackageId)- .catch((error) => this.notificationService.handleRawError(error));-- /** Stream updates of the work package */- this.wpCacheService.state(this.workPackageId)- .values$()+ this+ .apiV3Service+ .work_packages+ .id(this.workPackageId)+ .requireAndStream().pipe(this.untilDestroyed()).subscribe((wp:WorkPackageResource) => {- this.workPackage = wp;- this.init();- this.cdRef.detectChanges();- });+ this.workPackage = wp;+ this.init();+ this.cdRef.detectChanges();+ },+ (error) => this.notificationService.handleRawError(error)+ );}/**@@ -111,10 +110,14 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {*/protected init() {// Set elements- this.projectCacheService- .require(this.workPackage.project.idFromLink)- .then(() => {+ this+ .apiV3Service+ .projects+ .id(this.workPackage.project)+ .requireAndStream()+ .subscribe(() => {this.projectIdentifier = this.workPackage.project.identifier;+ this.cdRef.detectChanges();});// Set authorisation datadiff --git a/frontend/src/app/modules/work_packages/routing/wp-view-base/work-packages-view.base.ts b/frontend/src/app/modules/work_packages/routing/wp-view-base/work-packages-view.base.tsindex 37b17b9596b..b87aaf227bd 100644--- a/frontend/src/app/modules/work_packages/routing/wp-view-base/work-packages-view.base.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-view-base/work-packages-view.base.ts@@ -47,7 +47,6 @@ import {WorkPackageViewPaginationService} from "core-app/modules/work_packages/rimport {WorkPackagesListService} from "core-components/wp-list/wp-list.service";import {WorkPackagesListChecksumService} from "core-components/wp-list/wp-list-checksum.service";import {WorkPackageQueryStateService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-base.service";-import {QueryDmService} from "core-app/modules/hal/dm-services/query-dm.service";import {WorkPackageStatesInitializationService} from "core-components/wp-list/wp-states-initialization.service";import {WorkPackageViewOrderService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-order.service";import {WorkPackageViewDisplayRepresentationService} from "core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-display-representation.service";@@ -80,7 +79,6 @@ export abstract class WorkPackagesViewBase extends UntilDestroyedMixin implement@InjectField() $transitions:TransitionService;@InjectField() I18n:I18nService;@InjectField() wpStaticQueries:WorkPackageStaticQueriesService;- @InjectField() QueryDm:QueryDmService;@InjectField() wpStatesInitialization:WorkPackageStatesInitializationService;@InjectField() cdRef:ChangeDetectorRef;@InjectField() wpDisplayRepresentation:WorkPackageViewDisplayRepresentationService;diff --git a/modules/costs/frontend/module/wp-display/costs-by-type-display-field.module.ts b/modules/costs/frontend/module/wp-display/costs-by-type-display-field.module.tsindex 7932021d220..135b152803a 100644--- a/modules/costs/frontend/module/wp-display/costs-by-type-display-field.module.ts+++ b/modules/costs/frontend/module/wp-display/costs-by-type-display-field.module.ts@@ -28,8 +28,9 @@import {DisplayField} from "core-app/modules/fields/display/display-field.module";-import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {IFieldSchema} from "core-app/modules/fields/field.base";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";interface ICostsByType {costObjectId:string;@@ -44,11 +45,10 @@ interface ICostsByType {export class CostsByTypeDisplayField extends DisplayField {- public wpCacheService:any;+ @InjectField() apiV3Service:APIV3Service;public apply(resource:any, schema:IFieldSchema) {super.apply(resource, schema);- this.wpCacheService = this.injector.get(WorkPackageCacheService);this.loadIfNecessary();}@@ -57,7 +57,11 @@ export class CostsByTypeDisplayField extends DisplayField {this.value.$load().then(() => {if (this.resource.$source._type === 'WorkPackage') {- this.wpCacheService.touch(this.resource.id!);+ this+ .apiV3Service+ .work_packages+ .cache+ .touch(this.resource.id!);}});}diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rbindex cab52d4e265..7a77ee5f0f3 100644--- a/spec/features/search_spec.rb+++ b/spec/features/search_spec.rb@@ -87,8 +87,8 @@ describe 'Search', type: :feature, js: true, with_settings: { per_page_options:def expect_range(a, b)(a..b).each do |n|- expect(page.body).to include("No. #{n} WP")- expect(page.body).to have_selector("a[href*='#{work_package_path(work_packages[n - 1].id)}']")+ expect(page).to have_content("No. #{n} WP")+ expect(page).to have_selector("a[href*='#{work_package_path(work_packages[n - 1].id)}']")endenddiff --git a/spec/features/work_packages/tabs/watcher_tab_spec.rb b/spec/features/work_packages/tabs/watcher_tab_spec.rbindex 11c1e90d3ab..e02f92ea058 100644--- a/spec/features/work_packages/tabs/watcher_tab_spec.rb+++ b/spec/features/work_packages/tabs/watcher_tab_spec.rb@@ -20,8 +20,8 @@ describe 'Watcher tab', js: true, selenium: true dodef expect_button_is_watchingtitle = I18n.t('js.label_unwatch_work_package')- expect(page).to have_selector("#unwatch-button[title='#{title}']")- expect(page).to have_selector('#unwatch-button .button--icon.icon-watched')+ expect(page).to have_selector("#unwatch-button[title='#{title}']", wait: 10)+ expect(page).to have_selector('#unwatch-button .button--icon.icon-watched', wait: 10)enddef expect_button_is_not_watching