Skip to content

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

[chore] reduce multiple storage requests

Eric Schubertd0032c8f80d2
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.ts b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.ts
index 228f67e21a1..16d071ab8c5 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.ts
@@ -36,12 +36,13 @@ import {
OnInit,
} from '@angular/core';
import { StateService } from '@uirouter/core';
+import { BehaviorSubject, combineLatest, of } from 'rxjs';
import {
- BehaviorSubject,
- combineLatest,
- of,
-} from 'rxjs';
-import { distinctUntilChanged, map, switchMap } from 'rxjs/operators';
+ distinctUntilChanged,
+ map,
+ switchMap,
+ take,
+} from 'rxjs/operators';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
@@ -56,8 +57,6 @@ import { HookService } from 'core-app/features/plugins/hook-service';
import { WorkPackageChangeset } from 'core-app/features/work-packages/components/wp-edit/work-package-changeset';
import { randomString } from 'core-app/shared/helpers/random-string';
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
-import idFromLink from 'core-app/features/hal/helpers/id-from-link';
-import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
import { States } from 'core-app/core/states/states.service';
@@ -68,6 +67,8 @@ import { StoragesResourceService } from 'core-app/core/state/storages/storages.s
import { ProjectsResourceService } from 'core-app/core/state/projects/projects.service';
import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+import idFromLink from 'core-app/features/hal/helpers/id-from-link';
+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
export interface FieldDescriptor {
name:string;
@@ -197,16 +198,10 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen
private refresh(change:WorkPackageChangeset) {
// Prepare the fields that are required always
- const isNew = isNewResource(this.workPackage);
const resource = change.projectedResource;
- if (!this.currentProject.inProjectContext) {
- this.workPackage.project = resource.project as HalResource;
- }
-
if (!resource.project) {
this.projectContext = { matches: false, href: null, id: null };
- this.storages$.next([]);
} else {
const project = resource.project as unknown&{ href:string, id:string };
const workPackageId = this.workPackage.id;
@@ -219,7 +214,28 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen
href: this.PathHelper.projectWorkPackagePath(project.id, workPackageId),
matches: project.href === this.currentProject.apiv3Path,
};
+ }
+
+ if (isNewResource(resource)) {
+ this.updateWorkPackageCreationState(change);
+ }
+
+ const attributeGroups = this.schema(resource)._attributeGroups;
+ this.groupedFields = this.rebuildGroupedFields(change, attributeGroups);
+ this.cdRef.detectChanges();
+ }
+ private updateWorkPackageCreationState(change:WorkPackageChangeset) {
+ const resource = change.projectedResource;
+ if (!this.currentProject.inProjectContext) {
+ this.projectContext.field = this.getFields(change, ['project']);
+ this.workPackage.project = resource.project as HalResource;
+ }
+
+ if (resource.project === null) {
+ this.storages$.next([]);
+ } else {
+ const project = resource.project as unknown&{ href:string, id:string };
combineLatest([
this.projectsResourceService.update(project.href),
this.currentUserService.hasCapabilities$('file_links/manage', project.id),
@@ -232,19 +248,12 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen
return this.storagesService.updateCollection(p._links.self.href, p._links.storages);
}),
+ take(1),
)
.subscribe((storages) => {
this.storages$.next(storages);
});
}
-
- if (isNew && !this.currentProject.inProjectContext) {
- this.projectContext.field = this.getFields(change, ['project']);
- }
-
- const attributeGroups = this.schema(resource)._attributeGroups;
- this.groupedFields = this.rebuildGroupedFields(change, attributeGroups);
- this.cdRef.detectChanges();
}
/**
diff --git a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts
index 8f94e02ed27..bf35cf2b47f 100644
--- a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts
+++ b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts
@@ -30,10 +30,16 @@ import { WorkPackageResource } from 'core-app/features/hal/resources/work-packag
import { StateService } from '@uirouter/core';
import { Component, Injector, OnInit } from '@angular/core';
import { of } from 'rxjs';
-import { WorkPackageViewSelectionService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-selection.service';
-import { WorkPackageSingleViewBase } from 'core-app/features/work-packages/routing/wp-view-base/work-package-single-view.base';
+import {
+ WorkPackageViewSelectionService,
+} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-selection.service';
+import {
+ WorkPackageSingleViewBase,
+} from 'core-app/features/work-packages/routing/wp-view-base/work-package-single-view.base';
import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';
-import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
+import {
+ WorkPackageNotificationService,
+} from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';
import { CommentService } from 'core-app/features/work-packages/components/wp-activity/comment-service';
@@ -56,12 +62,19 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
public watchers:any;
+ public text = {
+ fullView: {
+ buttonMore: this.i18n.t('js.button_more'),
+ },
+ };
+
stateName$ = of('work-packages.new');
constructor(
public injector:Injector,
public wpTableSelection:WorkPackageViewSelectionService,
readonly $state:StateService,
+ // private readonly i18n:I18nService,
) {
super(injector, $state.params.workPackageId);
}
@@ -70,14 +83,6 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
this.observeWorkPackage();
}
- protected initializeTexts() {
- super.initializeTexts();
-
- this.text.full_view = {
- button_more: this.I18n.t('js.button_more'),
- };
- }
-
protected init() {
super.init();
diff --git a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html
index 4be71ffd008..9031e23b632 100644
--- a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html
+++ b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html
@@ -42,7 +42,7 @@
</li>
<li class="toolbar-item action_menu_main" id="action-show-more-dropdown-menu">
<button class="button dropdown-relative toolbar-icon"
- [attr.title]="text.full_view.button_more"
+ [attr.title]="text.fullView.buttonMore"
wpSingleContextMenu
[wpSingleContextMenu-workPackage]="workPackage">
<op-icon icon-classes="button--icon icon-show-more"></op-icon>
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.ts
index e79eac44639..442a95d3743 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
@@ -46,7 +46,7 @@ import {
WorkPackageNotificationService,
} from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
import {
- switchMap,
+ switchMap, take,
} from 'rxjs/operators';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
@@ -61,11 +61,12 @@ import { FileLinksResourceService } from 'core-app/core/state/file-links/file-li
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';
+import { HttpErrorResponse } from '@angular/common/http';
export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
@InjectField() states:States;
- @InjectField() I18n!:I18nService;
+ @InjectField() i18n:I18nService;
@InjectField() keepTab:KeepTabService;
@@ -101,8 +102,6 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
@InjectField() readonly storeService:WpSingleViewService;
- public text:any = {};
-
// Work package resource to be loaded from the cache
public workPackage:WorkPackageResource;
@@ -114,10 +113,11 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
public displayNotificationsButton$:Observable<boolean>;
- constructor(public injector:Injector,
- protected workPackageId:string) {
+ constructor(
+ public injector:Injector,
+ protected workPackageId:string,
+ ) {
super();
- this.initializeTexts();
}
/**
@@ -145,16 +145,6 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
});
}
- /**
- * Provide static translations
- */
- protected initializeTexts():void {
- this.text.tabs = {};
- ['overview', 'activity', 'relations', 'watchers'].forEach((tab) => {
- this.text.tabs[tab] = this.I18n.t(`js.work_packages.tabs.${tab}`);
- });
- }
-
/**
* Initialize controller after workPackage resource has been loaded.
*/
@@ -174,9 +164,12 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
// 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);
- });
+ .subscribe(
+ () => {},
+ (error:HttpErrorResponse) => {
+ this.toastService.addError(error);
+ },
+ );
this.displayNotificationsButton$ = this.storeService.hasNotifications$;
this.storeService.setFilters(this.workPackage.id as string);
@@ -200,6 +193,7 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
.pipe(
this.untilDestroyed(),
switchMap(() => this.projectsResourceService.lookup((this.workPackage.project as unknown&{ id:string }).id)),
+ take(1),
)
.subscribe(
(project) => {
@@ -207,9 +201,8 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
this.storages.updateCollection(project._links.self.href, project._links.storages).subscribe();
}
},
- (error) => {
+ (error:HttpErrorResponse) => {
this.toastService.addError(error);
- throw error;
},
);
}
@@ -230,8 +223,8 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
* Recompute the current tab focus label
*/
public updateFocusAnchorLabel(tabName:string):string {
- this.focusAnchorLabel = this.I18n.t('js.label_work_package_details_you_are_here', {
- tab: this.I18n.t(`js.work_packages.tabs.${tabName}`),
+ 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,
});
diff --git a/frontend/src/global_styles/layout/work_packages/_details_view.sass b/frontend/src/global_styles/layout/work_packages/_details_view.sass
index 27e9c1b63e2..78bea9419a2 100644
--- a/frontend/src/global_styles/layout/work_packages/_details_view.sass
+++ b/frontend/src/global_styles/layout/work_packages/_details_view.sass
@@ -151,5 +151,8 @@ body.router--work-packages-partitioned-split-view-new
grid-row-gap: $spot-spacing-1
grid-column-gap: $spot-spacing-1
+ @media #{$spot-mq-mobile}
+ grid-template-columns: 1fr
+
.work-packages-partitioned-page--content-right &
grid-template-columns: 1fr