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

[#44376] add link state to file picker state

Eric Schubertb106cae8002d
diff --git a/frontend/src/app/shared/components/file-links/file-link-list-item/file-link-list-item.html b/frontend/src/app/shared/components/file-links/file-link-list-item/file-link-list-item.html
index dcd4e9eb86a..2212825a0c5 100644
--- a/frontend/src/app/shared/components/file-links/file-link-list-item/file-link-list-item.html
+++ b/frontend/src/app/shared/components/file-links/file-link-list-item/file-link-list-item.html
@@ -2,7 +2,7 @@
[disabled]="!disabled"
[alignment]="tooltipAllignment"
class="spot-list--item-floating-wrapper op-file-list--item-floating-wrapper"
- [ngClass]="{ 'spot-list--item-floating-wrapper__disabled op-file-list--item-floating-wrapper__disabled': disabled }"
+ [ngClass]="{ 'spot-list--item-floating-wrapper_disabled op-file-list--item-floating-wrapper__disabled': disabled }"
>
<p
slot="body"
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.ts
index 2a28c2b0706..d4990af66f2 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
@@ -154,14 +154,19 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInit
}
public openLinkFilesDialog():void {
- const locals = {
- storageType: this.storage._links.type.href,
- storageTypeName: this.storageType,
- storageName: this.storage.name,
- storageLocation: this.storageFilesLocation,
- storageLink: this.storage._links.self,
- };
- this.opModalService.show<FilePickerModalComponent>(FilePickerModalComponent, 'global', locals);
+ this.fileLinks$
+ .pipe(this.untilDestroyed())
+ .subscribe((fileLinks) => {
+ const locals = {
+ storageType: this.storage._links.type.href,
+ storageTypeName: this.storageType,
+ storageName: this.storage.name,
+ storageLocation: this.storageFilesLocation,
+ storageLink: this.storage._links.self,
+ fileLinks,
+ };
+ this.opModalService.show<FilePickerModalComponent>(FilePickerModalComponent, 'global', locals);
+ });
}
private instantiateStorageInformation(fileLinks:IFileLink[]):StorageInformationBox[] {
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.ts
index d2ce5c3292b..fe4071e06ed 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
@@ -39,12 +39,16 @@ import { BehaviorSubject } from 'rxjs';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';
-import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
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 getIconForStorageType from 'core-app/shared/components/file-links/storage-icons/get-icon-for-storage-type';
@Component({
@@ -54,7 +58,7 @@ import getIconForStorageType from 'core-app/shared/components/file-links/storage
export class FilePickerModalComponent extends OpModalComponent implements OnInit, OnDestroy {
public loading$ = new BehaviorSubject<boolean>(true);
- public storageFiles$ = new BehaviorSubject<IStorageFile[]>([]);
+ public storageFiles$ = new BehaviorSubject<IStorageFileListItem[]>([]);
public breadcrumbs:BreadcrumbsContent;
@@ -99,7 +103,13 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInit
this.storageFilesResourceService.files(filesLink)
.subscribe((files) => {
- this.storageFiles$.next(files);
+ const fileListItems = files.map((file, index) => ({
+ disabled: this.isAlreadyLinked(file),
+ isFirst: index === 0,
+ changeSelection: () => { this.changeSelection(file.id as string); },
+ ...file,
+ }));
+ this.storageFiles$.next(fileListItems);
this.loading$.next(false);
});
}
@@ -118,12 +128,18 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInit
this.service.close();
}
- public changeSelection(file:IStorageFile):void {
- const id = file.id as string;
+ public changeSelection(id:string):void {
if (this.selection.has(id)) {
this.selection.delete(id);
} else {
this.selection.add(id);
}
}
+
+ private isAlreadyLinked(file:IStorageFile):boolean {
+ const currentFileLinks = this.locals.fileLinks as IFileLink[];
+ const found = currentFileLinks.find((a) => a.originData.id === file.id);
+
+ return !!found;
+ }
}
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.html
index a8b7ec33af5..37401375c8d 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
@@ -28,8 +28,7 @@
class="spot-list--item op-file-list--item"
data-qa-selector="op-file-list--item"
op-storage-file-list-item
- [storageFile]="file"
- (changeSelection)="changeSelection(file)"
+ [fileListItemContent]="file"
></li>
</ul>
</ng-container>
diff --git a/frontend/src/app/shared/components/file-links/laoding-file-list/loading-file-list.component.ts b/frontend/src/app/shared/components/file-links/loading-file-list/loading-file-list.component.ts
similarity index 100%
rename from frontend/src/app/shared/components/file-links/laoding-file-list/loading-file-list.component.ts
rename to frontend/src/app/shared/components/file-links/loading-file-list/loading-file-list.component.ts
diff --git a/frontend/src/app/shared/components/file-links/laoding-file-list/loading-file-list.html b/frontend/src/app/shared/components/file-links/loading-file-list/loading-file-list.html
similarity index 100%
rename from frontend/src/app/shared/components/file-links/laoding-file-list/loading-file-list.html
rename to frontend/src/app/shared/components/file-links/loading-file-list/loading-file-list.html
diff --git a/frontend/src/app/shared/components/file-links/openproject-file-links.module.ts b/frontend/src/app/shared/components/file-links/openproject-file-links.module.ts
index 1c73bf1f931..8e1e333e267 100644
--- a/frontend/src/app/shared/components/file-links/openproject-file-links.module.ts
+++ b/frontend/src/app/shared/components/file-links/openproject-file-links.module.ts
@@ -50,7 +50,7 @@ import {
import { SortFilesPipe } from 'core-app/shared/components/file-links/file-picker-modal/sort-files.pipe';
import {
LoadingFileListComponent,
-} from 'core-app/shared/components/file-links/laoding-file-list/loading-file-list.component';
+} from 'core-app/shared/components/file-links/loading-file-list/loading-file-list.component';
@NgModule({
imports: [
diff --git a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts
index 7ab6c971ab2..b14c4e5b4ba 100644
--- a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts
+++ b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts
@@ -29,11 +29,8 @@
import {
ChangeDetectionStrategy,
Component,
- ElementRef,
- EventEmitter,
Input,
- OnInit, Output,
- ViewChild,
+ OnInit,
} from '@angular/core';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
@@ -41,9 +38,13 @@ import { IFileIcon } from 'core-app/shared/components/file-links/file-link-icons
import {
getIconForMimeType,
} from 'core-app/shared/components/file-links/file-link-icons/file-link-list-item-icon.factory';
-import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
import { isDirectory } from 'core-app/shared/components/file-links/file-link-icons/file-icons.helper';
import { PrincipalLike } from 'core-app/shared/components/principal/principal-types';
+import {
+ IStorageFileListItem,
+} from 'core-app/shared/components/file-links/storage-file-list-item/storage-file-list-item';
+import SpotDropAlignmentOption from 'core-app/spot/drop-alignment-options';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
@Component({
// eslint-disable-next-line @angular-eslint/component-selector
@@ -52,13 +53,7 @@ import { PrincipalLike } from 'core-app/shared/components/principal/principal-ty
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class StorageFileListItemComponent implements OnInit {
- @Input() public storageFile:IStorageFile;
-
- @Input() public selected = false;
-
- @Output() public changeSelection = new EventEmitter();
-
- @ViewChild('avatar') avatar:ElementRef;
+ @Input() public fileListItemContent:IStorageFileListItem;
infoTimestampText:string;
@@ -66,10 +61,14 @@ export class StorageFileListItemComponent implements OnInit {
showDetails:boolean;
+ text = {
+ tooltip: this.i18n.t('js.storages.file_links.already_linked'),
+ };
+
get principal():PrincipalLike {
- return this.storageFile.createdByName
+ return this.fileListItemContent.createdByName
? {
- name: this.storageFile.createdByName,
+ name: this.fileListItemContent.createdByName,
href: '/external_users/1',
}
: {
@@ -78,15 +77,26 @@ export class StorageFileListItemComponent implements OnInit {
};
}
- constructor(private readonly timezoneService:TimezoneService) {}
+ get getTooltipAlignment():SpotDropAlignmentOption {
+ if (this.fileListItemContent.isFirst) {
+ return SpotDropAlignmentOption.BottomLeft;
+ }
+
+ return SpotDropAlignmentOption.TopLeft;
+ }
+
+ constructor(
+ private readonly i18n:I18nService,
+ private readonly timezoneService:TimezoneService,
+ ) {}
ngOnInit():void {
- if (this.storageFile.lastModifiedAt) {
- this.infoTimestampText = this.timezoneService.parseDatetime(this.storageFile.lastModifiedAt).fromNow();
+ if (this.fileListItemContent.lastModifiedAt) {
+ this.infoTimestampText = this.timezoneService.parseDatetime(this.fileListItemContent.lastModifiedAt).fromNow();
}
- this.fileLinkIcon = getIconForMimeType(this.storageFile.mimeType);
+ this.fileLinkIcon = getIconForMimeType(this.fileListItemContent.mimeType);
- this.showDetails = !isDirectory(this.storageFile.mimeType);
+ this.showDetails = !isDirectory(this.fileListItemContent.mimeType);
}
}
diff --git a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.html b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.html
index ca8bb4fe528..2f731e24a1f 100644
--- a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.html
+++ b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.html
@@ -1,32 +1,45 @@
-<label
- class="spot-list--item-action"
+<spot-tooltip
+ [alignment]="getTooltipAlignment"
+ [disabled]="!fileListItemContent.disabled"
>
- <spot-checkbox
- [checked]="selected"
- (checkedChange)="changeSelection.emit()"
- ></spot-checkbox>
- <span
- class="spot-icon spot-icon_{{fileLinkIcon.icon}} op-files-tab--icon op-files-tab--icon_{{fileLinkIcon.clazz}}"
- ></span>
+ <p
+ slot="body"
+ class="spot-body-small"
+ >{{text.tooltip}}</p>
- <span
- [textContent]="storageFile.name"
- [title]="storageFile.name"
- class="spot-list--item-title op-file-list--item-title"
- ></span>
+ <label
+ slot="trigger"
+ class="spot-list--item-action"
+ [ngClass]="{ 'spot-list--item-action_disabled': fileListItemContent.disabled }"
+ >
+ <spot-checkbox
+ [checked]="fileListItemContent.disabled"
+ (checkedChange)="fileListItemContent.changeSelection()"
+ [disabled]="fileListItemContent.disabled"
+ ></spot-checkbox>
+ <span
+ class="spot-icon spot-icon_{{fileLinkIcon.icon}} op-files-tab--icon op-files-tab--icon_{{fileLinkIcon.clazz}}"
+ ></span>
- <span
- *ngIf="showDetails"
- class="op-file-list--item-text"
- [textContent]="infoTimestampText"
- ></span>
+ <span
+ [textContent]="fileListItemContent.name"
+ [title]="fileListItemContent.name"
+ class="spot-list--item-title op-file-list--item-title"
+ ></span>
- <op-principal
- *ngIf="showDetails"
- class="op-file-list--item-avatar"
- [principal]="principal"
- [hideName]="true"
- [size]="'mini'"
- [link]="false"
- ></op-principal>
-</label>
+ <span
+ *ngIf="showDetails"
+ class="op-file-list--item-text"
+ [textContent]="infoTimestampText"
+ ></span>
+
+ <op-principal
+ *ngIf="showDetails"
+ class="op-file-list--item-avatar"
+ [principal]="principal"
+ [hideName]="true"
+ [size]="'mini'"
+ [link]="false"
+ ></op-principal>
+ </label>
+</spot-tooltip>
diff --git a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.ts b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.ts
new file mode 100644
index 00000000000..c6b014e120f
--- /dev/null
+++ b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.ts
@@ -0,0 +1,35 @@
+// -- 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 { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
+
+export interface IStorageFileListItem extends IStorageFile {
+ disabled:boolean;
+ isFirst:boolean;
+ changeSelection:() => void;
+}
diff --git a/frontend/src/app/shared/components/project-include/list/project-include-list.component.html b/frontend/src/app/shared/components/project-include/list/project-include-list.component.html
index ae474de9600..04a9550b055 100644
--- a/frontend/src/app/shared/components/project-include/list/project-include-list.component.html
+++ b/frontend/src/app/shared/components/project-include/list/project-include-list.component.html
@@ -5,7 +5,7 @@
[attr.data-list-selector]="projectListItemIdentifier"
>
<spot-tooltip
- class="op-project-include-list--tooltip spot-list--item-floating-wrapper"
+ class="op-project-include-list--tooltip"
[alignment]="getTooltipAlignment(isFirst)"
[disabled]="!project.disabled"
[dark]="true"
diff --git a/frontend/src/app/spot/styles/sass/components/list.sass b/frontend/src/app/spot/styles/sass/components/list.sass
index 195bf6f185d..d8b471d6428 100644
--- a/frontend/src/app/spot/styles/sass/components/list.sass
+++ b/frontend/src/app/spot/styles/sass/components/list.sass
@@ -40,6 +40,8 @@
&:hover
background-color: transparent
cursor: not-allowed
+ opacity: 0.5
+ color: $spot-color-basic-gray-1
&_active#{&}_disabled
color: $spot-color-basic-gray-3
@@ -56,7 +58,7 @@
&:focus-within
background-color: $spot-color-basic-gray-6
- &__disabled
+ &_disabled
color: $spot-color-basic-gray-1
&:hover
diff --git a/modules/storages/config/locales/js-en.yml b/modules/storages/config/locales/js-en.yml
index 70e5259f0a9..071ce44d6c3 100644
--- a/modules/storages/config/locales/js-en.yml
+++ b/modules/storages/config/locales/js-en.yml
@@ -37,3 +37,4 @@ en:
selection_none: "Select files to link"
selection_any: "Link %{number} files"
not_allowed_tooltip: "Please log in to Nextcloud to access this file"
+ already_linked: "This file is already linked to this work package."