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
Provide require$ and cachable resource services in base class
Oliver Günthera5e757840965
diff --git a/frontend/src/app/core/apiv3/api-v3.service.spec.ts b/frontend/src/app/core/apiv3/api-v3.service.spec.tsindex b6d1c7930f8..9f8fb6ed413 100644--- a/frontend/src/app/core/apiv3/api-v3.service.spec.ts+++ b/frontend/src/app/core/apiv3/api-v3.service.spec.ts@@ -26,7 +26,10 @@// See COPYRIGHT and LICENSE files for more details.//++-import { TestBed, waitForAsync } from '@angular/core/testing';+import {+ TestBed,+ waitForAsync,+} from '@angular/core/testing';import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { States } from 'core-app/core/states/states.service';@@ -35,8 +38,7 @@ describe('APIv3Service', () => {let service:ApiV3Service;beforeEach(waitForAsync(() => {- // noinspection JSIgnoredPromiseFromCall- TestBed.configureTestingModule({+ void TestBed.configureTestingModule({providers: [States,PathHelperService,diff --git a/frontend/src/app/core/apiv3/api-v3.service.ts b/frontend/src/app/core/apiv3/api-v3.service.tsindex d0fc48cb443..47bc3eafb05 100644--- a/frontend/src/app/core/apiv3/api-v3.service.ts+++ b/frontend/src/app/core/apiv3/api-v3.service.ts@@ -62,6 +62,7 @@ import { ApiV3NotificationsPaths } from 'core-app/core/apiv3/endpoints/notificatimport { ApiV3ViewsPaths } from 'core-app/core/apiv3/endpoints/views/apiv3-views-paths';import { Apiv3BackupsPath } from 'core-app/core/apiv3/endpoints/backups/apiv3-backups-path';import { ApiV3DaysPaths } from 'core-app/core/apiv3/endpoints/days/api-v3-days-paths';+import { Apiv3StoragesPaths } from 'core-app/core/apiv3/endpoints/storages/apiv3-storages-paths';@Injectable({ providedIn: 'root' })export class ApiV3Service {@@ -80,6 +81,9 @@ export class ApiV3Service {// /api/v3/documentspublic readonly documents = this.apiV3CollectionEndpoint('documents');+ // /api/v3/file_links+ public readonly file_links = this.apiV3CollectionEndpoint('file_links');+// /api/v3/notificationspublic readonly notifications = this.apiV3CustomEndpoint(ApiV3NotificationsPaths);@@ -116,6 +120,9 @@ export class ApiV3Service {// /api/v3/newspublic readonly news = this.apiV3CustomEndpoint(ApiV3NewsPaths);+ // /api/v3/storages+ public readonly storages = this.apiV3CustomEndpoint(Apiv3StoragesPaths);+// /api/v3/typespublic readonly types = this.apiV3CustomEndpoint(ApiV3TypesPaths);diff --git a/frontend/src/app/core/apiv3/endpoints/storages/apiv3-storages-paths.ts b/frontend/src/app/core/apiv3/endpoints/storages/apiv3-storages-paths.tsnew file mode 100644index 00000000000..02099b702c6--- /dev/null+++ b/frontend/src/app/core/apiv3/endpoints/storages/apiv3-storages-paths.ts@@ -0,0 +1,45 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2022 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 COPYRIGHT and LICENSE files for more details.+//++++import {+ ApiV3GettableResource,+ ApiV3ResourceCollection,+} from 'core-app/core/apiv3/paths/apiv3-resource';+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';+import { IStorage } from 'core-app/core/state/storages/storage.model';++export class Apiv3StoragesPaths+ extends ApiV3ResourceCollection<IStorage, ApiV3GettableResource<IStorage>> {+ // /api/v3/storages/files+ public readonly files = this.subResource('files');++ constructor(protected apiRoot:ApiV3Service,+ protected basePath:string) {+ super(apiRoot, basePath, 'storages');+ }+}diff --git a/frontend/src/app/core/config/configuration.service.ts b/frontend/src/app/core/config/configuration.service.tsindex 6a1b8457baf..27d5bc3fcec 100644--- a/frontend/src/app/core/config/configuration.service.ts+++ b/frontend/src/app/core/config/configuration.service.ts@@ -44,13 +44,9 @@ export class ConfigurationService {public constructor(readonly I18n:I18nService,readonly apiV3Service:ApiV3Service,- readonly weekdayService:WeekdayService,) {- this.initialized = Promise- .all([- this.loadConfiguration(),- this.weekdayService.loadWeekdays().toPromise(),- ])+ this.initialized = this+ .loadConfiguration().then(() => true).catch(() => false);}diff --git a/frontend/src/app/core/current-user/current-user.service.ts b/frontend/src/app/core/current-user/current-user.service.tsindex 3ceec40bcd0..85dea4e81cb 100644--- a/frontend/src/app/core/current-user/current-user.service.ts+++ b/frontend/src/app/core/current-user/current-user.service.ts@@ -92,7 +92,7 @@ export class CurrentUserService {return { filters, pageSize: -1 };}),- switchMap((params) => this.capabilitiesService.require$(params)),+ switchMap((params) => this.capabilitiesService.require(params)),);}diff --git a/frontend/src/app/core/days/weekday.service.ts b/frontend/src/app/core/days/weekday.service.tsindex 5fcfd805083..dfee9443f7a 100644--- a/frontend/src/app/core/days/weekday.service.ts+++ b/frontend/src/app/core/days/weekday.service.ts@@ -59,7 +59,7 @@ export class WeekdayService {*/public isNonWorkingDay(date:Date|number):boolean {const isoDayOfWeek = (typeof date === 'number') ? date : moment(date).isoWeekday();- return !!this.weekdays.find((wd) => wd.day === isoDayOfWeek && !wd.working);+ return !!(this.weekdays || []).find((wd) => wd.day === isoDayOfWeek && !wd.working);}loadWeekdays():Observable<IWeekday[]> {diff --git a/frontend/src/app/core/state/attachments/attachments.service.ts b/frontend/src/app/core/state/attachments/attachments.service.tsindex 9c49f93aa03..5810ec9a0f7 100644--- a/frontend/src/app/core/state/attachments/attachments.service.ts+++ b/frontend/src/app/core/state/attachments/attachments.service.ts@@ -61,20 +61,19 @@ import {CollectionStore,ResourceCollectionService,} from 'core-app/core/state/resource-collection.service';+import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';@Injectable()export class AttachmentsResourceService extends ResourceCollectionService<IAttachment> {- constructor(- private readonly I18n:I18nService,- private readonly http:HttpClient,- private readonly apiV3Service:ApiV3Service,- private readonly fileUploadService:OpenProjectFileUploadService,- private readonly directFileUploadService:OpenProjectDirectFileUploadService,- private readonly configurationService:ConfigurationService,- private readonly toastService:ToastService,- ) {- super();- }+ @InjectField() I18n:I18nService;++ @InjectField() fileUploadService:OpenProjectFileUploadService;++ @InjectField() directFileUploadService:OpenProjectDirectFileUploadService;++ @InjectField() configurationService:ConfigurationService;++ @InjectField() toastService:ToastService;/*** This method ensures that a specific collection is fetched, if not available.@@ -246,4 +245,8 @@ export class AttachmentsResourceService extends ResourceCollectionService<IAttacprotected createStore():CollectionStore<IAttachment> {return new AttachmentsStore();}++ protected basePath():string {+ return this.apiV3Service.attachments.path;+ }}diff --git a/frontend/src/app/core/state/capabilities/capabilities.service.spec.ts b/frontend/src/app/core/state/capabilities/capabilities.service.spec.tsindex c4c01929087..8184b55872f 100644--- a/frontend/src/app/core/state/capabilities/capabilities.service.spec.ts+++ b/frontend/src/app/core/state/capabilities/capabilities.service.spec.ts@@ -220,7 +220,7 @@ describe('Capabilities service', () => {};service- .require$(params)+ .require(params).subscribe((caps) => {expect(caps.length).toEqual(1);});@@ -234,7 +234,7 @@ describe('Capabilities service', () => {};service- .require$(params)+ .require(params).subscribe((caps) => {expect(caps.length).toEqual(1);});@@ -244,7 +244,7 @@ describe('Capabilities service', () => {};service- .require$(params)+ .require(params).subscribe((caps) => {expect(caps.length).toEqual(2);});@@ -254,7 +254,7 @@ describe('Capabilities service', () => {};service- .require$(params)+ .require(params).subscribe((caps) => {expect(caps.length).toEqual(1);});diff --git a/frontend/src/app/core/state/capabilities/capabilities.service.ts b/frontend/src/app/core/state/capabilities/capabilities.service.tsindex 76576d22fb6..db643c64cd0 100644--- a/frontend/src/app/core/state/capabilities/capabilities.service.ts+++ b/frontend/src/app/core/state/capabilities/capabilities.service.ts@@ -5,8 +5,6 @@ import {switchMap,} from 'rxjs/operators';import { Observable } from 'rxjs';-import { HttpClient } from '@angular/common/http';-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { ToastService } from 'core-app/shared/components/toaster/toast.service';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';@@ -17,23 +15,11 @@ import {CollectionStore,ResourceCollectionService,} from 'core-app/core/state/resource-collection.service';+import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';@Injectable()export class CapabilitiesResourceService extends ResourceCollectionService<ICapability> {- constructor(- private http:HttpClient,- private apiV3Service:ApiV3Service,- private toastService:ToastService,- ) {- super();- }-- private get capabilitiesPath():string {- return this- .apiV3Service- .capabilities- .path;- }+ @InjectField() toastService:ToastService;/*** Require the available capabilities for the given filter params@@ -69,7 +55,7 @@ export class CapabilitiesResourceService extends ResourceCollectionService<ICapapublic fetchCapabilities(params:ApiV3ListParameters):Observable<IHALCollection<ICapability>> {return this- .fetchCollection(this.http, this.capabilitiesPath, params)+ .fetchCollection(params).pipe(catchError((error) => {this.toastService.addError(error);@@ -81,4 +67,11 @@ export class CapabilitiesResourceService extends ResourceCollectionService<ICapaprotected createStore():CollectionStore<ICapability> {return new CapabilitiesStore();}++ protected basePath():string {+ return this+ .apiV3Service+ .capabilities+ .path;+ }}diff --git a/frontend/src/app/core/state/days/day.service.ts b/frontend/src/app/core/state/days/day.service.tsindex 94ace0d01a6..5f2b599ad2a 100644--- a/frontend/src/app/core/state/days/day.service.ts+++ b/frontend/src/app/core/state/days/day.service.ts@@ -1,17 +1,20 @@import { Injectable } from '@angular/core';import {+ finalize,map,tap,} from 'rxjs/operators';import { Observable } from 'rxjs';-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';-import { HttpClient } from '@angular/common/http';-import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';+import {+ ApiV3ListFilter,+ ApiV3ListParameters,+} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';import {collectionKey,extendCollectionElementsWithId,insertCollectionIntoState,+ setCollectionLoading,} from 'core-app/core/state/collection-store';import { DayStore } from 'core-app/core/state/days/day.store';import { IDay } from 'core-app/core/state/days/day.model';@@ -22,29 +25,47 @@ import {@Injectable()export class DayResourceService extends ResourceCollectionService<IDay> {- private get daysPath():string {+ protected basePath():string {return this.apiV3Service.days.path;}- constructor(- private http:HttpClient,- private apiV3Service:ApiV3Service,- ) {- super();+ isNonWorkingDay$(input:Date):Observable<boolean> {+ const date = moment(input).format('YYYY-MM-DD');++ return this+ .requireNonWorkingYear$(input)+ .pipe(+ map((days) => days.findIndex((day:IDay) => !day.working && day.date === date) !== -1),+ );+ }++ requireNonWorkingYear$(date:Date):Observable<IDay[]> {+ const from = moment(date).startOf('year').format('YYYY-MM-DD');+ const to = moment(date).endOf('year').format('YYYY-MM-DD');++ const filters:ApiV3ListFilter[] = [+ ['date', '<>d', [from, to]],+ ['working', '=', ['f']],+ ];++ return this.require({ filters });}- fetchDays(params:ApiV3ListParameters):Observable<IHALCollection<IDay>> {+ fetchCollection(params:ApiV3ListParameters):Observable<IHALCollection<IDay>> {const collectionURL = collectionKey(params);+ setCollectionLoading(this.store, collectionURL, true);+return this.http- .get<IHALCollection<IDay>>(this.daysPath + collectionURL)+ .get<IHALCollection<IDay>>(this.basePath() + collectionURL).pipe(map((collection) => extendCollectionElementsWithId(collection)),tap((collection) => insertCollectionIntoState(this.store, collection, collectionURL)),+ finalize(() => setCollectionLoading(this.store, collectionURL, false)),);}diff --git a/frontend/src/app/core/state/days/weekday.service.ts b/frontend/src/app/core/state/days/weekday.service.tsindex 6eea2e6e838..b10170f65a8 100644--- a/frontend/src/app/core/state/days/weekday.service.ts+++ b/frontend/src/app/core/state/days/weekday.service.ts@@ -8,9 +8,7 @@ import {EMPTY,Observable,} from 'rxjs';-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';-import { HttpClient } from '@angular/common/http';import {extendCollectionElementsWithId,insertCollectionIntoState,@@ -24,21 +22,6 @@ import {@Injectable()export class WeekdayResourceService extends ResourceCollectionService<IWeekday> {- private get weekdaysPath():string {- return this- .apiV3Service- .days- .week- .path;- }-- constructor(- private http:HttpClient,- private apiV3Service:ApiV3Service,- ) {- super();- }-require():Observable<IWeekday[]> {return this.query@@ -49,12 +32,12 @@ export class WeekdayResourceService extends ResourceCollectionService<IWeekday>);}- private fetchWeekdays():Observable<IHALCollection<IWeekday>> {+ protected fetchWeekdays():Observable<IHALCollection<IWeekday>> {const collectionURL = 'all'; // We load all weekdaysreturn this.http- .get<IHALCollection<IWeekday>>(this.weekdaysPath)+ .get<IHALCollection<IWeekday>>(this.basePath()).pipe(map((collection) => extendCollectionElementsWithId(collection)),tap((collection) => insertCollectionIntoState(this.store, collection, collectionURL)),@@ -64,4 +47,12 @@ export class WeekdayResourceService extends ResourceCollectionService<IWeekday>protected createStore():CollectionStore<IWeekday> {return new WeekdayStore();}++ protected basePath():string {+ return this+ .apiV3Service+ .days+ .week+ .path;+ }}diff --git a/frontend/src/app/core/state/file-links/file-links.service.ts b/frontend/src/app/core/state/file-links/file-links.service.tsindex 9b6d5d45c1d..a397d97ea13 100644--- a/frontend/src/app/core/state/file-links/file-links.service.ts+++ b/frontend/src/app/core/state/file-links/file-links.service.ts@@ -47,15 +47,11 @@ import {CollectionStore,ResourceCollectionService,} from 'core-app/core/state/resource-collection.service';+import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';@Injectable()export class FileLinksResourceService extends ResourceCollectionService<IFileLink> {- constructor(- private readonly http:HttpClient,- private readonly toastService:ToastService,- ) {- super();- }+ @InjectField() toastService:ToastService;updateCollectionsForWorkPackage(fileLinksSelfLink:string):void {this.http@@ -107,4 +103,8 @@ export class FileLinksResourceService extends ResourceCollectionService<IFileLin).subscribe(() => removeEntityFromCollectionAndState(this.store, fileLink.id, collectionKey));}++ protected basePath():string {+ return this.apiV3Service.file_links.path;+ }}diff --git a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.tsindex f73e370401d..77384015ba8 100644--- a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts+++ b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts@@ -2,15 +2,6 @@ import { Injectable } from '@angular/core';import { tap } from 'rxjs/operators';import { Observable } from 'rxjs';import { ID } from '@datorama/akita';-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';-import { ToastService } from 'core-app/shared/components/toaster/toast.service';-import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';-import { HttpClient } from '@angular/common/http';-import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';-import {- collectionKey,- insertCollectionIntoState,-} from 'core-app/core/state/collection-store';import {markNotificationsAsRead,notificationsMarkedRead,@@ -26,36 +17,12 @@ import {CollectionStore,ResourceCollectionService,} from 'core-app/core/state/resource-collection.service';+import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';@EffectHandler@Injectable()export class InAppNotificationsResourceService extends ResourceCollectionService<INotification> {- private get notificationsPath():string {- return this- .apiV3Service- .notifications- .path;- }-- constructor(- readonly actions$:ActionsService,- private http:HttpClient,- private apiV3Service:ApiV3Service,- private toastService:ToastService,- ) {- super();- }-- fetchNotifications(params:ApiV3ListParameters):Observable<IHALCollection<INotification>> {- const collectionURL = collectionKey(params);-- return this- .http- .get<IHALCollection<INotification>>(this.notificationsPath + collectionURL)- .pipe(- tap((collection) => insertCollectionIntoState(this.store, collection, collectionURL)),- );- }+ @InjectField() actions$:ActionsService;update(id:ID, inAppNotification:Partial<INotification>):void {this.store.update(id, inAppNotification);@@ -88,4 +55,11 @@ export class InAppNotificationsResourceService extends ResourceCollectionServiceprotected createStore():CollectionStore<INotification> {return new InAppNotificationsStore();}++ protected basePath():string {+ return this+ .apiV3Service+ .notifications+ .path;+ }}diff --git a/frontend/src/app/core/state/principals/principals.service.ts b/frontend/src/app/core/state/principals/principals.service.tsindex e98a3da8022..174c604ca63 100644--- a/frontend/src/app/core/state/principals/principals.service.ts+++ b/frontend/src/app/core/state/principals/principals.service.ts@@ -5,10 +5,8 @@ import {} from 'rxjs/operators';import { Observable } from 'rxjs';import { applyTransaction } from '@datorama/akita';-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { ToastService } from 'core-app/shared/components/toaster/toast.service';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';-import { HttpClient } from '@angular/common/http';import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';import {collectionKey,@@ -23,25 +21,14 @@ import {CollectionStore,ResourceCollectionService,} from 'core-app/core/state/resource-collection.service';+import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';@EffectHandler@Injectable()export class PrincipalsResourceService extends ResourceCollectionService<IPrincipal> {- private get principalsPath():string {- return this- .apiV3Service- .principals- .path;- }+ @InjectField() actions$:ActionsService;- constructor(- readonly actions$:ActionsService,- private http:HttpClient,- private apiV3Service:ApiV3Service,- private toastService:ToastService,- ) {- super();- }+ @InjectField() toastService:ToastService;fetchUser(id:string|number):Observable<IUser> {return this.http@@ -64,7 +51,7 @@ export class PrincipalsResourceService extends ResourceCollectionService<IPrincireturn this.http- .get<IHALCollection<IPrincipal>>(this.principalsPath + collectionURL)+ .get<IHALCollection<IPrincipal>>(this.basePath() + collectionURL).pipe(tap((collection) => insertCollectionIntoState(this.store, collection, collectionURL)),catchError((error) => {@@ -77,4 +64,11 @@ export class PrincipalsResourceService extends ResourceCollectionService<IPrinciprotected createStore():CollectionStore<IPrincipal> {return new PrincipalsStore();}++ protected basePath():string {+ return this+ .apiV3Service+ .principals+ .path;+ }}diff --git a/frontend/src/app/core/state/projects/projects.service.ts b/frontend/src/app/core/state/projects/projects.service.tsindex 42c6afc0bb7..e9b444ba9e4 100644--- a/frontend/src/app/core/state/projects/projects.service.ts+++ b/frontend/src/app/core/state/projects/projects.service.ts@@ -27,20 +27,8 @@//++import { Injectable } from '@angular/core';-import {- catchError,- tap,-} from 'rxjs/operators';+import { tap } from 'rxjs/operators';import { Observable } from 'rxjs';-import { HttpClient } from '@angular/common/http';-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';-import { ToastService } from 'core-app/shared/components/toaster/toast.service';-import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';-import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';-import {- collectionKey,- insertCollectionIntoState,-} from 'core-app/core/state/collection-store';import { IProject } from './project.model';import {CollectionStore,@@ -50,36 +38,6 @@ import { ProjectsStore } from 'core-app/core/state/projects/projects.store';@Injectable()export class ProjectsResourceService extends ResourceCollectionService<IProject> {- private get projectsPath():string {- return this- .apiV3Service- .projects- .path;- }-- constructor(- private http:HttpClient,- private apiV3Service:ApiV3Service,- private toastService:ToastService,- ) {- super();- }-- fetchProjects(params:ApiV3ListParameters):Observable<IHALCollection<IProject>> {- const collectionURL = collectionKey(params);-- return this- .http- .get<IHALCollection<IProject>>(this.projectsPath + collectionURL)- .pipe(- tap((collection) => insertCollectionIntoState(this.store, collection, collectionURL)),- catchError((error) => {- this.toastService.addError(error);- throw error;- }),- );- }-update(link:string):Observable<IProject> {return this.http.get<IProject>(link).pipe(@@ -92,4 +50,11 @@ export class ProjectsResourceService extends ResourceCollectionService<IProject>protected createStore():CollectionStore<IProject> {return new ProjectsStore();}++ protected basePath():string {+ return this+ .apiV3Service+ .projects+ .path;+ }}diff --git a/frontend/src/app/core/state/resource-collection.service.ts b/frontend/src/app/core/state/resource-collection.service.tsindex 5fa7361c0dc..132988531e7 100644--- a/frontend/src/app/core/state/resource-collection.service.ts+++ b/frontend/src/app/core/state/resource-collection.service.ts@@ -33,6 +33,7 @@ import {} from '@datorama/akita';import { Observable } from 'rxjs';import {+ catchError,filter,finalize,map,@@ -50,15 +51,53 @@ import { omit } from 'lodash';import isDefinedEntity from 'core-app/core/state/is-defined-entity';import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';-import { HttpClient } from '@angular/common/http';+import {+ HttpClient,+ HttpErrorResponse,+} from '@angular/common/http';+import {+ Injectable,+ Injector,+} from '@angular/core';+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';+import { ToastService } from 'core-app/shared/components/toaster/toast.service';export type CollectionStore<T> = EntityStore<CollectionState<T>>;+@Injectable()export abstract class ResourceCollectionService<T extends { id:ID }> {protected store:CollectionStore<T> = this.createStore();protected query = new QueryEntity(this.store);+ constructor(+ readonly injector:Injector,+ readonly http:HttpClient,+ readonly apiV3Service:ApiV3Service,+ readonly toastService:ToastService,+ ) {+ }++ /**+ * Require the results for the given filter params+ * Returns a cached set if it was loaded already.+ *+ * @param params List params to require+ * @private+ */+ public require(params:ApiV3ListParameters):Observable<T[]> {+ const key = collectionKey(params);+ if (this.collectionExists(key) || this.collectionLoading(key)) {+ return this.loadedCollection(key);+ }++ return this+ .fetchCollection(params)+ .pipe(+ switchMap(() => this.loadedCollection(key)),+ );+ }+/*** Retrieve a collection from the store*@@ -173,24 +212,50 @@ export abstract class ResourceCollectionService<T extends { id:ID }> {}/**- * Create a new instance of this resource service's underyling store.- * @protected+ * Fetch a given collection, returning only its results*/- protected abstract createStore():CollectionStore<T>;+ fetchResults(params:ApiV3ListParameters|string):Observable<T[]> {+ return this+ .fetchCollection(params)+ .pipe(+ map((collection) => collection._embedded.elements),+ );+ }/*** Fetch a given collection, ensuring it is being flagged as loaded*/- protected fetchCollection(http:HttpClient, basePath:string, params:ApiV3ListParameters):Observable<IHALCollection<T>> {- const key = collectionKey(params);+ fetchCollection(params:ApiV3ListParameters|string):Observable<IHALCollection<T>> {+ const key = typeof params === 'string' ? params : collectionKey(params);setCollectionLoading(this.store, key, true);- return http- .get<IHALCollection<T>>(basePath + key)+ return this+ .http+ .get<IHALCollection<T>>(this.basePath() + key).pipe(tap((collection) => insertCollectionIntoState(this.store, collection, key)),finalize(() => setCollectionLoading(this.store, key, false)),+ catchError((error:unknown) => {+ this.handleCollectionLoadingError(error as HttpErrorResponse, key);+ throw error;+ }),);}++ /**+ * Create a new instance of this resource service's underyling store.+ * @protected+ */+ protected abstract createStore():CollectionStore<T>;++ /**+ * Base path for this collection+ * @protected+ */+ protected abstract basePath():string;++ protected handleCollectionLoadingError(error:HttpErrorResponse, _collectionKey:string):void {+ this.toastService.addError(error);+ }}diff --git a/frontend/src/app/core/state/storage-files/storage-files.service.ts b/frontend/src/app/core/state/storage-files/storage-files.service.tsindex a1e3f9e33ca..10973655503 100644--- a/frontend/src/app/core/state/storage-files/storage-files.service.ts+++ b/frontend/src/app/core/state/storage-files/storage-files.service.ts@@ -43,9 +43,6 @@ import { insertCollectionIntoState } from 'core-app/core/state/collection-store'@Injectable()export class StorageFilesResourceService extends ResourceCollectionService<IStorageFile> {- constructor(private readonly http:HttpClient) {- super();- }protected createStore():CollectionStore<IStorageFile> {return new StorageFilesStore();@@ -69,4 +66,8 @@ export class StorageFilesResourceService extends ResourceCollectionService<IStorreset():void {this.store.reset();}++ protected basePath():string {+ return this.apiV3Service.storages.files.path;+ }}diff --git a/frontend/src/app/core/state/storages/storages.service.ts b/frontend/src/app/core/state/storages/storages.service.tsindex 8a14cd2bbdc..4c5f05742b8 100644--- a/frontend/src/app/core/state/storages/storages.service.ts+++ b/frontend/src/app/core/state/storages/storages.service.ts@@ -27,7 +27,6 @@//++import { Injectable } from '@angular/core';-import { HttpClient } from '@angular/common/http';import { forkJoin } from 'rxjs';import { IStorage } from 'core-app/core/state/storages/storage.model';import { StoragesStore } from 'core-app/core/state/storages/storages.store';@@ -41,10 +40,6 @@ import {@Injectable()export class StoragesResourceService extends ResourceCollectionService<IStorage> {- constructor(private readonly http:HttpClient) {- super();- }-updateCollection(key:string, storageLinks:IHalResourceLink[]):void {forkJoin(storageLinks.map((link) => this.http.get<IStorage>(link.href)),@@ -57,4 +52,8 @@ export class StoragesResourceService extends ResourceCollectionService<IStorage>protected createStore():CollectionStore<IStorage> {return new StoragesStore();}++ protected basePath():string {+ return this.apiV3Service.storages.path;+ }}diff --git a/frontend/src/app/core/state/views/views.service.ts b/frontend/src/app/core/state/views/views.service.tsindex b00bcfd2c20..f6c92523668 100644--- a/frontend/src/app/core/state/views/views.service.ts+++ b/frontend/src/app/core/state/views/views.service.ts@@ -1,70 +1,27 @@import { Injectable } from '@angular/core';-import {- catchError,- tap,-} from 'rxjs/operators';-import { Observable } from 'rxjs';-import {- applyTransaction,- ID,-} from '@datorama/akita';-import { ToastService } from 'core-app/shared/components/toaster/toast.service';-import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';-import { HttpClient } from '@angular/common/http';-import {- collectionKey,- insertCollectionIntoState,-} from 'core-app/core/state/collection-store';-import {- EffectHandler,-} from 'core-app/core/state/effects/effect-handler.decorator';+import { EffectHandler } from 'core-app/core/state/effects/effect-handler.decorator';import { ActionsService } from 'core-app/core/state/actions/actions.service';import { ViewsStore } from 'core-app/core/state/views/views.store';-import { ViewsQuery } from 'core-app/core/state/views/views.query';import { IView } from 'core-app/core/state/views/view.model';-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';-import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';-import { addParamToHref } from 'core-app/shared/helpers/url-helpers';import {CollectionStore,ResourceCollectionService,} from 'core-app/core/state/resource-collection.service';+import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';@EffectHandler@Injectable()export class ViewsResourceService extends ResourceCollectionService<IView> {- private get viewsPath():string {- return this- .apiV3Service- .views- .path;- }+ @InjectField() actions$:ActionsService;- constructor(- readonly actions$:ActionsService,- private http:HttpClient,- private apiV3Service:ApiV3Service,- private toastService:ToastService,- ) {- super();+ protected createStore():CollectionStore<IView> {+ return new ViewsStore();}- fetchViews(params:ApiV3ListParameters):Observable<IHALCollection<IView>> {- const collectionURL = collectionKey(params);-+ protected basePath():string {return this- .http- .get<IHALCollection<IView>>(addParamToHref(this.viewsPath + collectionURL, { pageSize: '-1' }))- .pipe(- tap((collection) => insertCollectionIntoState(this.store, collection, collectionURL)),- catchError((error) => {- this.toastService.addError(error);- throw error;- }),- );- }-- protected createStore():CollectionStore<IView> {- return new ViewsStore();+ .apiV3Service+ .views+ .path;}}diff --git a/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts b/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.tsindex de37f224c9e..0742c261d60 100644--- a/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts+++ b/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts@@ -265,7 +265,10 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implementadditionalOptions.initialView = 'dayGridWeek';}- void this.configuration.initialized+ void Promise.all([+ this.configuration.initialized,+ this.weekdayService.loadWeekdays().toPromise(),+ ]).then(() => {this.calendarOptions$.next(this.workPackagesCalendar.calendarOptions(additionalOptions),diff --git a/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.tsindex 65a344a03fe..1f2148b30ee 100644--- a/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts+++ b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts@@ -46,8 +46,9 @@ export class IanBellService {}fetchUnread():Observable<number> {- return this.resourceService- .fetchNotifications({ filters: IAN_FACET_FILTERS.unread, pageSize: 0 })+ return this+ .resourceService+ .fetchCollection({ filters: IAN_FACET_FILTERS.unread, pageSize: 0 }).pipe(map((result) => result.total),tap(diff --git a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.service.ts b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.service.tsindex 37cfa3f84ec..3f7e4ec570a 100644--- a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.service.ts+++ b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.service.ts@@ -90,7 +90,7 @@ export class IanMenuService {}public reload():void {- this.ianResourceService.fetchNotifications(IAN_MENU_PROJECT_FILTERS)+ this.ianResourceService.fetchCollection(IAN_MENU_PROJECT_FILTERS).subscribe((data) => {const projectsFilter:ApiV3ListParameters = {pageSize: 100,@@ -108,10 +108,10 @@ export class IanMenuService {// Only request if there are any groupsif (data.groups && data.groups.length > 0) {- this.projectsResourceService.fetchProjects(projectsFilter).subscribe();+ this.projectsResourceService.fetchCollection(projectsFilter).subscribe();}});- this.ianResourceService.fetchNotifications(IAN_MENU_REASON_FILTERS)+ this.ianResourceService.fetchCollection(IAN_MENU_REASON_FILTERS)// eslint-disable-next-line @typescript-eslint/no-unsafe-return.subscribe((data) => this.store.update({ notificationsByReason: data.groups }));}diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.tsindex 09e66e6fe25..c60718573aa 100644--- a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts+++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts@@ -153,7 +153,7 @@ export class IanCenterService extends UntilDestroyedMixin {}),switchMap(() => this.resourceService- .fetchNotifications(this.params)+ .fetchCollection(this.params).pipe(switchMap((results) => from(this.sideLoadInvolvedWorkPackages(results._embedded.elements))diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.store.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.store.tsindex d3d258fc9d1..07efa435ea4 100644--- a/frontend/src/app/features/in-app-notifications/center/state/ian-center.store.ts+++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.store.ts@@ -4,6 +4,8 @@ import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.iimport { NOTIFICATIONS_MAX_SIZE } from 'core-app/core/state/in-app-notifications/in-app-notification.model';import { INotificationPageQueryParameters } from 'core-app/features/in-app-notifications/in-app-notifications.routes';+export type InAppNotificationFacet = 'unread'|'all';+export interface IanCenterState {params:{page:number;@@ -18,8 +20,6 @@ export interface IanCenterState {notLoaded:number;}-export type InAppNotificationFacet = 'unread'|'all';-export const IAN_FACET_FILTERS:Record<InAppNotificationFacet, ApiV3ListFilter[]> = {unread: [['readIAN', '=', false]],all: [],diff --git a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.tsindex 492906a846f..c717c34b768 100644--- a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts+++ b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts@@ -416,7 +416,10 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,}private initializeCalendar() {- void this.configuration.initialized+ void Promise.all([+ this.configuration.initialized,+ this.weekdayService.loadWeekdays().toPromise(),+ ]).then(() => {this.calendarOptions$.next(this.workPackagesCalendar.calendarOptions({diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.tsindex 8c381b9f4df..15bc8c61cf2 100644--- a/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts@@ -106,7 +106,7 @@ export class WpSingleViewService {.pipe(take(1),filter((loggedIn) => loggedIn),- switchMap(() => this.resourceService.fetchNotifications(this.params)),+ switchMap(() => this.resourceService.fetchCollection(this.params)),).subscribe();}diff --git a/frontend/src/app/shared/components/op-view-select/op-view-select.component.ts b/frontend/src/app/shared/components/op-view-select/op-view-select.component.tsindex 8ffc54c5eb3..4ede5452247 100644--- a/frontend/src/app/shared/components/op-view-select/op-view-select.component.ts+++ b/frontend/src/app/shared/components/op-view-select/op-view-select.component.ts@@ -186,12 +186,10 @@ export class ViewSelectComponent extends UntilDestroyedMixin implements OnInit {);}- this.viewsService.fetchViews(params)+ this.viewsService.fetchResults(params).pipe(this.untilDestroyed())- .subscribe((queryCollection) => {- queryCollection- ._embedded- .elements+ .subscribe((views) => {+ views.sort((a, b) => a._links.query.title.localeCompare(b._links.query.title)).forEach((view) => {let cat = 'private';