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

[#43693] Add storage components to work package creation

Eric Schubertc3af6362c886
diff --git a/frontend/src/app/core/state/storages/storages.service.ts b/frontend/src/app/core/state/storages/storages.service.ts
index 8669bea2455..5cc6a19c864 100644
--- a/frontend/src/app/core/state/storages/storages.service.ts
+++ b/frontend/src/app/core/state/storages/storages.service.ts
@@ -27,7 +27,8 @@
//++
import { Injectable } from '@angular/core';
-import { forkJoin } from 'rxjs';
+import { tap } from 'rxjs/operators';
+import { forkJoin, Observable } from 'rxjs';
import { IStorage } from 'core-app/core/state/storages/storage.model';
import { StoragesStore } from 'core-app/core/state/storages/storages.store';
import { insertCollectionIntoState } from 'core-app/core/state/collection-store';
@@ -40,13 +41,14 @@ import {
@Injectable()
export class StoragesResourceService extends ResourceCollectionService<IStorage> {
- updateCollection(key:string, storageLinks:IHalResourceLink[]):void {
- forkJoin(
- storageLinks.map((link) => this.http.get<IStorage>(link.href)),
- ).subscribe((storages) => {
- const storageCollection = { _embedded: { elements: storages } } as IHALCollection<IStorage>;
- insertCollectionIntoState(this.store, storageCollection, key);
- });
+ updateCollection(key:string, storageLinks:IHalResourceLink[]):Observable<IStorage[]> {
+ return forkJoin(storageLinks.map((link) => this.http.get<IStorage>(link.href)))
+ .pipe(
+ tap((storages) => {
+ const storageCollection = { _embedded: { elements: storages } } as IHALCollection<IStorage>;
+ insertCollectionIntoState(this.store, storageCollection, key);
+ }),
+ );
}
protected createStore():CollectionStore<IStorage> {
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 2b89dbfe932..8e388d06ee5 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,19 +36,26 @@ import {
OnInit,
} from '@angular/core';
import { StateService } from '@uirouter/core';
+import {
+ BehaviorSubject,
+ combineLatest,
+ of,
+ Subject,
+} from 'rxjs';
+import { distinctUntilChanged, map, switchMap } from 'rxjs/operators';
+
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { distinctUntilChanged, map } from 'rxjs/operators';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
-import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
+import {
+ HalResourceEditingService,
+} from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
import { DisplayFieldService } from 'core-app/shared/components/fields/display/display-field.service';
import { DisplayField } from 'core-app/shared/components/fields/display/display-field.module';
import { QueryResource } from 'core-app/features/hal/resources/query-resource';
import { HookService } from 'core-app/features/plugins/hook-service';
import { WorkPackageChangeset } from 'core-app/features/work-packages/components/wp-edit/work-package-changeset';
-import { Subject } from 'rxjs';
import { randomString } from 'core-app/shared/helpers/random-string';
-import { BrowserDetector } from 'core-app/core/browser/browser-detector.service';
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';
@@ -57,6 +64,10 @@ import { CurrentProjectService } from 'core-app/core/current-project/current-pro
import { States } from 'core-app/core/states/states.service';
import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
import { debugLog } from 'core-app/shared/helpers/debug_output';
+import { IStorage } from 'core-app/core/state/storages/storage.model';
+import { StoragesResourceService } from 'core-app/core/state/storages/storages.service';
+import { ProjectsResourceService } from 'core-app/core/state/projects/projects.service';
+import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
export interface FieldDescriptor {
name:string;
@@ -107,6 +118,7 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen
// when editing the work package in a different project
public projectContext:{
matches:boolean,
+ id:string|null,
href:string|null,
field?:FieldDescriptor[]
};
@@ -138,24 +150,34 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen
public uiSelfRef:string;
- protected firstTimeFocused = false;
-
$element:JQuery;
- constructor(readonly I18n:I18nService,
- protected currentProject:CurrentProjectService,
- protected PathHelper:PathHelperService,
- protected $state:StateService,
- protected states:States,
- protected halEditing:HalResourceEditingService,
- protected halResourceService:HalResourceService,
- protected displayFieldService:DisplayFieldService,
- protected schemaCache:SchemaCacheService,
- protected hook:HookService,
- protected injector:Injector,
- protected cdRef:ChangeDetectorRef,
- readonly elementRef:ElementRef,
- readonly browserDetector:BrowserDetector) {
+ storages$ = new BehaviorSubject<IStorage[]>([]);
+
+ public get workPackageWithProjectContext():WorkPackageResource {
+ const clone = Object.create(this.workPackage) as WorkPackageResource;
+ clone.project = { id: this.projectContext.id };
+ return clone;
+ }
+
+ constructor(
+ protected readonly injector:Injector,
+ private readonly states:States,
+ private readonly I18n:I18nService,
+ private readonly hook:HookService,
+ private readonly $state:StateService,
+ private readonly elementRef:ElementRef,
+ private readonly cdRef:ChangeDetectorRef,
+ private readonly PathHelper:PathHelperService,
+ private readonly schemaCache:SchemaCacheService,
+ private readonly currentProject:CurrentProjectService,
+ private readonly halEditing:HalResourceEditingService,
+ private readonly halResourceService:HalResourceService,
+ private readonly currentUserService:CurrentUserService,
+ private readonly storagesService:StoragesResourceService,
+ private readonly displayFieldService:DisplayFieldService,
+ private readonly projectsResourceService:ProjectsResourceService,
+ ) {
super();
}
@@ -166,31 +188,18 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen
this.uiSelfRef = this.$state.$current.name;
- const change = this.halEditing.changeFor<WorkPackageResource, WorkPackageChangeset>(this.workPackage);
- this.resourceContextChange.next(this.contextFrom(change.projectedResource));
- this.refresh(change);
-
- // Whenever the resource context changes in any way,
+ // Whenever the temporary resource changes in any way,
// update the visible fields.
- this.resourceContextChange
- .pipe(
- this.untilDestroyed(),
- distinctUntilChanged<ResourceContextChange>((a, b) => _.isEqual(a, b)),
- map(() => this.halEditing.changeFor(this.workPackage)),
- )
- .subscribe((changeset:WorkPackageChangeset) => this.refresh(changeset));
-
- // Update the resource context on every update to the temporary resource.
- // This allows detecting a changed type value in a new work package.
this.halEditing
.temporaryEditResource(this.workPackage)
.values$()
.pipe(
this.untilDestroyed(),
+ map((resource) => this.contextFrom(resource)),
+ distinctUntilChanged<ResourceContextChange>((a, b) => _.isEqual(a, b)),
+ map(() => this.halEditing.changeFor(this.workPackage)),
)
- .subscribe((resource) => {
- this.resourceContextChange.next(this.contextFrom(resource));
- });
+ .subscribe((changeset:WorkPackageChangeset) => this.refresh(changeset));
}
private refresh(change:WorkPackageChangeset) {
@@ -199,12 +208,36 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen
const resource = change.projectedResource;
if (!resource.project) {
- this.projectContext = { matches: false, href: null };
+ this.projectContext = { matches: false, href: null, id: null };
} else {
+ const project = resource.project as unknown&{ href:string, id:string };
+ const workPackageId = this.workPackage.id;
+ if (!workPackageId) {
+ throw new Error('work package id is invalid');
+ }
+
this.projectContext = {
- href: this.PathHelper.projectWorkPackagePath(idFromLink(resource.project.href), this.workPackage.id!),
- matches: resource.project.href === this.currentProject.apiv3Path,
+ id: project.id,
+ href: this.PathHelper.projectWorkPackagePath(project.id, workPackageId),
+ matches: project.href === this.currentProject.apiv3Path,
};
+
+ combineLatest([
+ this.projectsResourceService.update(project.href),
+ this.currentUserService.hasCapabilities$('file_links/manage', project.id),
+ ])
+ .pipe(
+ switchMap(([p, manageFileLinks]) => {
+ if (!p._links.storages || !manageFileLinks) {
+ return of([] as IStorage[]);
+ }
+
+ return this.storagesService.updateCollection(p._links.self.href, p._links.storages);
+ }),
+ )
+ .subscribe((storages) => {
+ this.storages$.next(storages);
+ });
}
if (isNew && !this.currentProject.inProjectContext) {
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.html b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.html
index 3cc75d4ea3f..b9805154f75 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.html
+++ b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.html
@@ -5,8 +5,8 @@
<div class="wp-new--subject-wrapper"
*ngIf="isNewResource">
<op-editable-attribute-field [resource]="workPackage"
- [wrapperClasses]="'-no-label'"
- [fieldName]="'subject'"></op-editable-attribute-field>
+ [wrapperClasses]="'-no-label'"
+ [fieldName]="'subject'"></op-editable-attribute-field>
</div>
<div class="wp-info-wrapper">
@@ -55,7 +55,7 @@
</div>
<div class="attributes-key-value--value-container">
<op-editable-attribute-field [resource]="workPackage"
- [fieldName]="descriptor.name"></op-editable-attribute-field>
+ [fieldName]="descriptor.name"></op-editable-attribute-field>
</div>
</div>
</div>
@@ -86,9 +86,9 @@
<div class="attributes-group description-group">
<div class="single-attribute work-packages--details--description">
<op-editable-attribute-field [fieldName]="'description'"
- [resource]="workPackage"
- [isDropTarget]="true"
- [wrapperClasses]="'-no-label'">
+ [resource]="workPackage"
+ [isDropTarget]="true"
+ [wrapperClasses]="'-no-label'">
</op-editable-attribute-field>
</div>
</div>
@@ -125,12 +125,13 @@
</div>
</div>
-<div class="work-packages--attachments attributes-group" *ngIf="isNewResource">
- <div class="work-packages--attachments-container">
- <div class="attributes-group--header">
- <div class="attributes-group--header-container">
- <h3 class="attributes-group--header-text" [textContent]="text.attachments.label"></h3>
- </div>
+<div
+ *ngIf="isNewResource"
+ class="work-packages--storages"
+>
+ <div>
+ <div class="op-tab-content--header">
+ <span class="op-tab-content--header-text" [textContent]="text.attachments.label"></span>
</div>
<ndc-dynamic [ndcDynamicComponent]="attachmentListComponent()"
@@ -142,24 +143,12 @@
*ngIf="workPackage.canAddAttachments">
</ndc-dynamic>
</div>
-</div>
-<div class="work-packages--files attributes-group" *ngIf="!isNewResource">
- <div class="work-packages--files-container">
- <div class="attributes-group--header">
- <div class="attributes-group--header-container">
- <h3 class="attributes-group--header-text" [textContent]="text.files.label"></h3>
- </div>
- </div>
-
- <div class="attributes-group--icon-indented-text">
- <op-icon icon-classes="icon-info1"></op-icon>
- <span [textContent]="text.files.migration_help"></span>
- <a
- [textContent]="text.files.label"
- [uiSref]="uiSelfRef"
- [uiParams]="{ workPackageId: workPackage.id, tabIdentifier: 'files' }"
- ></a>
- </div>
- </div>
+ <op-storage
+ *ngFor="let storage of storages$ | async"
+ [resource]="workPackageWithProjectContext"
+ [storage]="storage"
+ [allowLinking]="true"
+ [allowUploading]="true"
+ ></op-storage>
</div>
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 b76030818fd..e79eac44639 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
@@ -204,7 +204,7 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
.subscribe(
(project) => {
if (project._links.storages) {
- this.storages.updateCollection(project._links.self.href, project._links.storages);
+ this.storages.updateCollection(project._links.self.href, project._links.storages).subscribe();
}
},
(error) => {
diff --git a/frontend/src/app/shared/components/storages/storage/storage.component.ts b/frontend/src/app/shared/components/storages/storage/storage.component.ts
index 01850e8dfef..3ed8eba3cca 100644
--- a/frontend/src/app/shared/components/storages/storage/storage.component.ts
+++ b/frontend/src/app/shared/components/storages/storage/storage.component.ts
@@ -153,7 +153,11 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD
return this.storage._links.open.href;
}
- private get addFileLinksHref() {
+ private get addFileLinksHref():string {
+ if (isNewResource(this.resource)) {
+ return '/api/v3/file_links';
+ }
+
return (this.resource.$links as unknown&{ addFileLink:IHalResourceLink }).addFileLink.href;
}
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 6e780587c8e..27e9c1b63e2 100644
--- a/frontend/src/global_styles/layout/work_packages/_details_view.sass
+++ b/frontend/src/global_styles/layout/work_packages/_details_view.sass
@@ -138,15 +138,18 @@ body.router--work-packages-partitioned-split-view-new
.work-packages--type-selector
flex-shrink: 0
-.work-packages--details
- .work-packages--attachments
- margin-bottom: 25px
-
.work-package--new-state
margin-bottom: 55px
.title-container
overflow: visible
- .work-packages--attachments
- margin-bottom: 25px
+.work-packages--storages
+ margin-top: $spot-spacing-2
+ display: grid
+ grid-template-columns: 1fr 1fr
+ grid-row-gap: $spot-spacing-1
+ grid-column-gap: $spot-spacing-1
+
+ .work-packages-partitioned-page--content-right &
+ grid-template-columns: 1fr