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
[#42157] fixed state handling
Eric Schuberta65143909b11
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 37528603c0a..c955ac32d4e 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@@ -74,16 +74,7 @@ export class FileLinksResourceService {.subscribe((fileLinkCollections) => {const storageId = idFromLink(fileLinkCollections.storage);const collectionKey = `${fileLinksSelfLink}?filters=[{"storage":{"operator":"=","values":["${storageId}"]}}]`;- const collection:IHALCollection<IFileLink> = {- _type: 'Collection',- count: fileLinkCollections.fileLinks.length,- total: fileLinkCollections.fileLinks.length,- pageSize: fileLinkCollections.fileLinks.length,- offset: 0,- _embedded: {- elements: fileLinkCollections.fileLinks,- },- };+ const collection = { _embedded: { elements: fileLinkCollections.fileLinks } } as IHALCollection<IFileLink>;insertCollectionIntoState(this.store, collection, collectionKey);});}diff --git a/frontend/src/app/core/state/projects/project.model.ts b/frontend/src/app/core/state/projects/project.model.tsindex 4fe8d3c29fc..fc8179bfaea 100644--- a/frontend/src/app/core/state/projects/project.model.ts+++ b/frontend/src/app/core/state/projects/project.model.ts@@ -13,7 +13,7 @@ export interface IProjectHalResourceLinks extends IHalResourceLinks {self:IHalResourceLink;status:IHalResourceLink;schema:IHalResourceLink;- storages:IHalResourceLink[];+ storages?:IHalResourceLink[];}export interface IProject {diff --git a/frontend/src/app/core/state/projects/projects.service.ts b/frontend/src/app/core/state/projects/projects.service.tsindex 716c94641f7..fb134e2be3b 100644--- a/frontend/src/app/core/state/projects/projects.service.ts+++ b/frontend/src/app/core/state/projects/projects.service.ts@@ -27,7 +27,7 @@//++import { Injectable } from '@angular/core';-import { catchError, map, tap } from 'rxjs/operators';+import { catchError, filter, tap } from 'rxjs/operators';import { Observable } from 'rxjs';import { ID } from '@datorama/akita';import { HttpClient } from '@angular/common/http';@@ -43,6 +43,10 @@ import {import { ProjectsStore } from './projects.store';import { IProject } from './project.model';+export function isIProject(input:IProject|undefined):input is IProject {+ return input !== undefined;+}+@Injectable()export class ProjectsResourceService {protected store = new ProjectsStore();@@ -78,31 +82,18 @@ export class ProjectsResourceService {);}- lookup(id:ID, require = false):Observable<IProject> {- if (require && !this.query.hasEntity(id)) {- return this.http- .get<IProject>(`${this.projectsPath}/${id}`)- .pipe(- tap((project) => {- if (project) {- this.store.add(project);- }- }),- );- }-- return this.query.selectEntity(id)+ update(link:string):Observable<IProject> {+ return this.http.get<IProject>(link).pipe(- map((project) => {- if (!project) {- throw new Error('not found');- }- return project;+ tap((project) => {+ this.store.upsertMany([project]);}),);}- update(id:ID, project:Partial<IProject>):void {- this.store.update(id, project);+ lookup(id:ID):Observable<IProject> {+ return this.query+ .selectEntity(id)+ .pipe(filter(isIProject));}}diff --git a/frontend/src/app/core/state/storages/storages.service.ts b/frontend/src/app/core/state/storages/storages.service.tsindex 7347e0b0d8a..cabb7ed8521 100644--- a/frontend/src/app/core/state/storages/storages.service.ts+++ b/frontend/src/app/core/state/storages/storages.service.ts@@ -29,12 +29,17 @@import { Injectable } from '@angular/core';import { HttpClient } from '@angular/common/http';import { forkJoin, Observable } from 'rxjs';-import { map, switchMap } from 'rxjs/operators';+import { filter, map, switchMap } from 'rxjs/operators';import { IStorage } from 'core-app/core/state/storages/storage.model';import { StoragesStore } from 'core-app/core/state/storages/storages.store';import { StoragesQuery } from 'core-app/core/state/storages/storages.query';import { insertCollectionIntoState } from 'core-app/core/state/collection-store';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';+import { IHalResourceLink } from 'core-app/core/state/hal-resource';++export function isIStorage(input:IStorage|undefined):input is IStorage {+ return input !== undefined;+}@Injectable()export class StoragesResourceService {@@ -58,18 +63,10 @@ export class StoragesResourceService {return this.query.selectEntity(id)- .pipe(- map((storage) => {- if (storage === undefined) {- throw new Error('not found');- }-- return storage;- }),- );+ .pipe(filter(isIStorage));}- updateCollection(key:string, storageLinks:{ href:string }[]):void {+ updateCollection(key:string, storageLinks:IHalResourceLink[]):void {forkJoin(storageLinks.map((link) => this.http.get<IStorage>(link.href)),).subscribe((storages) => {diff --git a/frontend/src/app/features/hal/resources/work-package-resource.ts b/frontend/src/app/features/hal/resources/work-package-resource.tsindex 01560f67bf7..1ccac6ec4cc 100644--- a/frontend/src/app/features/hal/resources/work-package-resource.ts+++ b/frontend/src/app/features/hal/resources/work-package-resource.ts@@ -51,7 +51,7 @@ export interface WorkPackageResourceEmbedded {ancestors:WorkPackageResource[];assignee:HalResource|any;attachments:AttachmentCollectionResource;- fileLinks:CollectionResource;+ fileLinks?:CollectionResource;author:HalResource|any;availableWatchers:HalResource|any;category:HalResource|any;diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.tsindex 0d77b7fbb8b..79fae76d72e 100644--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts@@ -72,7 +72,7 @@ export class WorkPackageFilesTabComponent implements OnInit {) { }ngOnInit():void {- const project = this.workPackage.$embedded.project as HalResource;+ const project = this.workPackage.project as HalResource;if (project.id === null) {return;}diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.tsindex 80b284e8ab2..2c6734f4b05 100644--- a/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts@@ -26,10 +26,7 @@// See COPYRIGHT and LICENSE files for more details.//++-import {- ChangeDetectorRef,- Injector,-} from '@angular/core';+import { ChangeDetectorRef, Injector } from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import {@@ -58,6 +55,9 @@ import { ActionsService } from 'core-app/core/state/actions/actions.service';import { AttachmentsResourceService } from 'core-app/core/state/attachments/attachments.service';import { StoragesResourceService } from 'core-app/core/state/storages/storages.service';import { FileLinksResourceService } from 'core-app/core/state/file-links/file-links.service';+import { ProjectsResourceService } from 'core-app/core/state/projects/projects.service';+import { HalResource } from 'core-app/features/hal/resources/hal-resource';+import { ToastService } from 'core-app/shared/components/toaster/toast.service';export class WorkPackageSingleViewBase extends UntilDestroyedMixin {@InjectField() states:States;@@ -76,9 +76,15 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {@InjectField() authorisationService:AuthorisationService;- @InjectField() attachmentsResourceService:AttachmentsResourceService;+ @InjectField() private readonly attachmentsResourceService:AttachmentsResourceService;++ @InjectField() private readonly fileLinkResourceService:FileLinksResourceService;- @InjectField() fileLinkResourceService:FileLinksResourceService;+ @InjectField() private readonly projectsResourceService:ProjectsResourceService;++ @InjectField() private readonly storages:StoragesResourceService;++ @InjectField() private readonly toastService:ToastService;@InjectField() cdRef:ChangeDetectorRef;@@ -92,9 +98,6 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {@InjectField() readonly storeService:WpSingleViewService;- @InjectField() private readonly storages:StoragesResourceService;-- // Static textspublic text:any = {};// Work package resource to be loaded from the cache@@ -118,15 +121,13 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {* Observe changes of work package and re-run initialization.* Needs to be run explicitly by descendants.*/- protected observeWorkPackage() {+ protected observeWorkPackage():void {this.apiV3Service.work_packages.id(this.workPackageId).requireAndStream()- .pipe(- this.untilDestroyed(),- )+ .pipe(this.untilDestroyed()).subscribe((wp:WorkPackageResource) => {if (!this.workPackage) {this.workPackage = wp;@@ -136,8 +137,7 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {}this.cdRef.detectChanges();- },- (error) => {+ }, (error) => {this.handleLoadingError(error);});}@@ -145,7 +145,7 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {/*** Provide static translations*/- protected initializeTexts() {+ protected initializeTexts():void {this.text.tabs = {};['overview', 'activity', 'relations', 'watchers'].forEach((tab) => {this.text.tabs[tab] = this.I18n.t(`js.work_packages.tabs.${tab}`);@@ -155,7 +155,7 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {/*** Initialize controller after workPackage resource has been loaded.*/- protected init() {+ protected init():void {// Set elementsthis.apiV3Service@@ -167,6 +167,14 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {this.cdRef.detectChanges();});+ // lazy load the work package's project, needed when initializing+ // the work package resource from split view.+ this.projectsResourceService+ .update((this.workPackage.$links.project as HalResource).href as string)+ .subscribe(() => {}, (error) => {+ this.toastService.addError(error);+ });+this.displayNotificationsButton$ = this.storeService.query.hasNotifications$;this.storeService.setFilters(this.workPackage.id as string);@@ -183,20 +191,27 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {const attachments = this.workPackage.attachments as unknown&{ href:string };this.attachmentsResourceService.fetchAttachments(attachments.href).subscribe();- // Fetch file link collections for work package- this.fileLinkResourceService.updateCollectionsForWorkPackage(this.workPackage.$links.fileLinks.href as string);+ // Fetch file link collections for work package (only if storages module is enabled)+ if (this.workPackage.$links.fileLinks) {+ this.fileLinkResourceService.updateCollectionsForWorkPackage(this.workPackage.$links.fileLinks.href as string);+ }++ // Fetch storages for work package's project (only if storages module is enabled)+ this.projectsResourceService+ .lookup((this.workPackage.project as unknown&{ id:string }).id)+ .pipe(this.untilDestroyed())+ .subscribe((project) => {+ if (project._links.storages) {+ this.storages.updateCollection(project._links.self.href, project._links.storages);+ }+ });// Listen to tab changes to update the tab labelthis.keepTab.observable- .pipe(- this.untilDestroyed(),- )- .subscribe((tabs:any) => {+ .pipe(this.untilDestroyed())+ .subscribe((tabs:{ active:string }) => {this.updateFocusAnchorLabel(tabs.active);});-- const project = this.workPackage.project as { $links:{ storages:{ href:string }[] }, href:string };- this.storages.updateCollection(project.href, project.$links.storages);}protected handleLoadingError(error:unknown):void {@@ -207,12 +222,11 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {* Recompute the current tab focus label*/public updateFocusAnchorLabel(tabName:string):string {- const tabLabel = this.I18n.t('js.label_work_package_details_you_are_here', {+ this.focusAnchorLabel = this.I18n.t('js.label_work_package_details_you_are_here', {tab: this.I18n.t(`js.work_packages.tabs.${tabName}`),type: this.workPackage.type.name,subject: this.workPackage.subject,});-- return this.focusAnchorLabel = tabLabel;+ return this.focusAnchorLabel;}}