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
[#44376] added file link creation
Eric Schubert1d16a27e352f
diff --git a/docs/api/apiv3/paths/work_package_file_links.yml b/docs/api/apiv3/paths/work_package_file_links.ymlindex a7299f5b9f6..adfcf1b34cf 100644--- a/docs/api/apiv3/paths/work_package_file_links.yml+++ b/docs/api/apiv3/paths/work_package_file_links.yml@@ -44,6 +44,7 @@ post:id: 5503name: logo.pngmimeType: image/png+ size: 433765createdAt: '2021-12-19T09:42:10.170Z'lastModifiedAt: '2021-12-20T14:00:13.987Z'createdByName: Luke Skywalkerdiff --git a/frontend/src/app/core/state/file-links/file-link.model.ts b/frontend/src/app/core/state/file-links/file-link.model.tsindex edd3f9d1d1f..37d64048a71 100644--- a/frontend/src/app/core/state/file-links/file-link.model.ts+++ b/frontend/src/app/core/state/file-links/file-link.model.ts@@ -37,7 +37,7 @@ export interface IFileLinkHalResourceLinks extends IHalResourceLinks {container:IHalResourceLink;creator:IHalResourceLink;delete?:IHalResourceLink;- permission:IHalResourceLink;+ permission?:IHalResourceLink;originOpen:IHalResourceLink;staticOriginOpen:IHalResourceLink;originOpenLocation:IHalResourceLink;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..7c1be8ed5b0 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@@ -26,6 +26,7 @@// See COPYRIGHT and LICENSE files for more details.//+++import { applyTransaction } from '@datorama/akita';import { Injectable } from '@angular/core';import { HttpClient, HttpHeaders } from '@angular/common/http';import { from } from 'rxjs';@@ -37,16 +38,16 @@ import {switchMap,tap,} from 'rxjs/operators';+import { IFileLink } from 'core-app/core/state/file-links/file-link.model';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';import { ToastService } from 'core-app/shared/components/toaster/toast.service';import { FileLinksStore } from 'core-app/core/state/file-links/file-links.store';import { insertCollectionIntoState, removeEntityFromCollectionAndState } from 'core-app/core/state/collection-store';+import { CollectionStore, ResourceCollectionService } from 'core-app/core/state/resource-collection.service';+import { IHalResourceLink } from 'core-app/core/state/hal-resource';+import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';import idFromLink from 'core-app/features/hal/helpers/id-from-link';-import {- CollectionStore,- ResourceCollectionService,-} from 'core-app/core/state/resource-collection.service';@Injectable()export class FileLinksResourceService extends ResourceCollectionService<IFileLink> {@@ -107,4 +108,47 @@ export class FileLinksResourceService extends ResourceCollectionService<IFileLin).subscribe(() => removeEntityFromCollectionAndState(this.store, fileLink.id, collectionKey));}++ addFileLinks(collectionKey:string, addFileLinksHref:string, storage:IHalResourceLink, filesToLink:IStorageFile[]):void {+ const elements = filesToLink.map((file) => ({+ originData: {+ id: file.id,+ name: file.name,+ mimeType: file.mimeType,+ size: file.size,+ createdAt: file.createdAt,+ lastModifiedAt: file.lastModifiedAt,+ createdByName: file.createdByName,+ lastModifiedByName: file.lastModifiedByName,+ },+ _links: { storage },+ }));++ this.http+ .post<IHALCollection<IFileLink>>(addFileLinksHref, { _type: 'Collection', _embedded: { elements } })+ .pipe(+ tap((collection) => {+ applyTransaction(() => {+ const newFileLinks = collection._embedded.elements;+ this.store.add(newFileLinks);+ this.store.update(({ collections }) => (+ {+ collections: {+ ...collections,+ [collectionKey]: {+ ...collections[collectionKey],+ ids: (collections[collectionKey]?.ids || []).concat(newFileLinks.map((link) => link.id)),+ },+ },+ }+ ));+ });+ }),+ catchError((error) => {+ this.toastService.addError(error);+ throw error;+ }),+ )+ .subscribe();+ }}diff --git a/frontend/src/app/shared/components/file-links/file-link-list-item/file-link-list-item.component.ts b/frontend/src/app/shared/components/file-links/file-link-list-item/file-link-list-item.component.tsindex 5413a4b1572..b4c3b9bcfa9 100644--- a/frontend/src/app/shared/components/file-links/file-link-list-item/file-link-list-item.component.ts+++ b/frontend/src/app/shared/components/file-links/file-link-list-item/file-link-list-item.component.ts@@ -120,7 +120,7 @@ export class FileLinkListItemComponent implements OnInit, AfterViewInit {{ fileName: this.fileLink.originData.name },);- this.viewAllowed = this.fileLink._links.permission.href === fileLinkViewAllowed;+ this.viewAllowed = !this.fileLink._links.permission || this.fileLink._links.permission.href === fileLinkViewAllowed;}ngAfterViewInit():void {diff --git a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.tsindex d4990af66f2..611c03e2ed7 100644--- a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts+++ b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts@@ -36,6 +36,7 @@ import {BehaviorSubject,Observable,} from 'rxjs';+import { take } from 'rxjs/operators';import { CookieService } from 'ngx-cookie-service';import { v4 as uuidv4 } from 'uuid';@@ -62,6 +63,7 @@ import { OpModalService } from 'core-app/shared/components/modal/modal.service';import {FilePickerModalComponent,} from 'core-app/shared/components/file-links/file-picker-modal/file-picker-modal.component';+import { IHalResourceLink } from 'core-app/core/state/hal-resource';@Component({selector: 'op-file-link-list',@@ -155,7 +157,7 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInitpublic openLinkFilesDialog():void {this.fileLinks$- .pipe(this.untilDestroyed())+ .pipe(take(1)).subscribe((fileLinks) => {const locals = {storageType: this.storage._links.type.href,@@ -163,6 +165,8 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInitstorageName: this.storage.name,storageLocation: this.storageFilesLocation,storageLink: this.storage._links.self,+ addFileLinksHref: (this.resource.$links as unknown&{ addFileLink:IHalResourceLink }).addFileLink.href,+ collectionKey: this.collectionKey,fileLinks,};this.opModalService.show<FilePickerModalComponent>(FilePickerModalComponent, 'global', locals);@@ -179,7 +183,7 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInitif (fileLinks.length === 0) {return [this.emptyStorageInformation];}- if (fileLinks.filter((fileLink) => fileLink._links.permission.href === fileLinkViewError).length > 0) {+ if (fileLinks.filter((fileLink) => fileLink._links.permission?.href === fileLinkViewError).length > 0) {this.disabled = true;return [this.fileLinkErrorInformation];}diff --git a/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.component.ts b/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.component.tsindex fe4071e06ed..67bdd61edea 100644--- a/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.component.ts+++ b/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.component.ts@@ -38,17 +38,18 @@ import {import { BehaviorSubject } from 'rxjs';import { I18nService } from 'core-app/core/i18n/i18n.service';+import { IHalResourceLink } from 'core-app/core/state/hal-resource';+import { IFileLink } from 'core-app/core/state/file-links/file-link.model';+import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.service';import { StorageFilesResourceService } from 'core-app/core/state/storage-files/storage-files.service';-import { IHalResourceLink } from 'core-app/core/state/hal-resource';import { BreadcrumbsContent } from 'core-app/spot/components/breadcrumbs/breadcrumbs-content';import {IStorageFileListItem,} from 'core-app/shared/components/file-links/storage-file-list-item/storage-file-list-item';-import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';-import { IFileLink } from 'core-app/core/state/file-links/file-link.model';+import { FileLinksResourceService } from 'core-app/core/state/file-links/file-links.service';import getIconForStorageType from 'core-app/shared/components/file-links/storage-icons/get-icon-for-storage-type';@Component({@@ -78,11 +79,16 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInitprivate readonly selection = new Set<string>();+ private readonly fileMap:Record<string, IStorageFile> = {};++ private storageLink:IHalResourceLink;+constructor(@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,readonly elementRef:ElementRef,readonly cdRef:ChangeDetectorRef,private readonly i18n:I18nService,+ private readonly fileLinksResourceService:FileLinksResourceService,private readonly storageFilesResourceService:StorageFilesResourceService,) {super(locals, cdRef, elementRef);@@ -96,8 +102,9 @@ export class FilePickerModalComponent extends OpModalComponent implements OnIniticon: getIconForStorageType(this.locals.storageType as string),}]);+ this.storageLink = (this.locals.storageLink as IHalResourceLink);const filesLink:IHalResourceLink = {- href: `${(this.locals.storageLink as IHalResourceLink).href}/files`,+ href: `${this.storageLink.href}/files`,title: 'Storage files',};@@ -106,7 +113,7 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInitconst fileListItems = files.map((file, index) => ({disabled: this.isAlreadyLinked(file),isFirst: index === 0,- changeSelection: () => { this.changeSelection(file.id as string); },+ changeSelection: () => { this.changeSelection(file); },...file,}));this.storageFiles$.next(fileListItems);@@ -125,14 +132,24 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInit}public createSelectedFileLinks():void {+ const files = Array.from(this.selection).map((id) => this.fileMap[id]);+ this.fileLinksResourceService.addFileLinks(+ this.locals.collectionKey as string,+ this.locals.addFileLinksHref as string,+ this.storageLink,+ files,+ );+this.service.close();}- public changeSelection(id:string):void {- if (this.selection.has(id)) {- this.selection.delete(id);+ public changeSelection(file:IStorageFile):void {+ const fileId = file.id as string;+ if (this.selection.has(fileId)) {+ this.selection.delete(fileId);} else {- this.selection.add(id);+ this.selection.add(fileId);+ this.fileMap[fileId] = file;}}diff --git a/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.html b/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.htmlindex 37401375c8d..7fc4d0f32aa 100644--- a/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.html+++ b/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.html@@ -46,17 +46,16 @@[textContent]="text.buttons.cancel"(click)="closeMe()"></button>-<!-- TODO: #44376, enable button with functionality-->-<!-- <button-->-<!-- type="button"-->-<!-- class="button spot-action-bar--action"-->-<!-- [ngClass]="{ '-highlight': selectedFileCount > 0 }"-->-<!-- [disabled]="selectedFileCount === 0"-->-<!-- (click)="createSelectedFileLinks()"-->-<!-- >-->-<!-- <span class="spot-icon spot-icon_add-link"></span>-->-<!-- <span>{{selectedFileCount > 0 ? text.buttons.submit() : text.buttons.submitEmptySelection}}</span>-->-<!-- </button>-->+ <button+ type="button"+ class="button spot-action-bar--action"+ [ngClass]="{ '-highlight': selectedFileCount > 0 }"+ [disabled]="selectedFileCount === 0"+ (click)="createSelectedFileLinks()"+ >+ <span class="spot-icon spot-icon_add-link"></span>+ <span>{{selectedFileCount > 0 ? text.buttons.submit() : text.buttons.submitEmptySelection}}</span>+ </button></div></div></div>