From 6ecf3f5eb8409952ea7947943ae7b9120d495aa9 Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Thu, 3 Apr 2025 17:08:46 +0200 Subject: [PATCH 1/2] Show loading icon when loading the files with a asking to contant the administrator when it took so long --- .../file-description.component.html | 36 ++++++++++++------- .../file-description.component.ts | 22 ++++++++++-- .../preview-section.component.html | 7 ++++ .../preview-section.component.spec.ts | 15 +++++++- .../preview-section.component.ts | 10 +++++- src/assets/i18n/cs.json5 | 4 +++ src/assets/i18n/en.json5 | 4 +++ 7 files changed, 81 insertions(+), 17 deletions(-) diff --git a/src/app/item-page/simple/field-components/preview-section/file-description/file-description.component.html b/src/app/item-page/simple/field-components/preview-section/file-description/file-description.component.html index 2b2f211a316..4778ab0b795 100644 --- a/src/app/item-page/simple/field-components/preview-section/file-description/file-description.component.html +++ b/src/app/item-page/simple/field-components/preview-section/file-description/file-description.component.html @@ -60,18 +60,30 @@
-
diff --git a/src/app/item-page/simple/field-components/preview-section/file-description/file-description.component.ts b/src/app/item-page/simple/field-components/preview-section/file-description/file-description.component.ts index 6a2b69acdce..510010b6de9 100644 --- a/src/app/item-page/simple/field-components/preview-section/file-description/file-description.component.ts +++ b/src/app/item-page/simple/field-components/preview-section/file-description/file-description.component.ts @@ -1,7 +1,8 @@ -import { Component, Input } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { MetadataBitstream } from 'src/app/core/metadata/metadata-bitstream.model'; import { HALEndpointService } from '../../../../../core/shared/hal-endpoint.service'; import {Router} from '@angular/router'; +import { ConfigurationDataService } from '../../../../../core/data/configuration-data.service'; const allowedPreviewFormats = ['text/plain', 'text/html', 'application/zip', 'application/x-tar']; @Component({ @@ -9,14 +10,24 @@ const allowedPreviewFormats = ['text/plain', 'text/html', 'application/zip', 'ap templateUrl: './file-description.component.html', styleUrls: ['./file-description.component.scss'], }) -export class FileDescriptionComponent { +export class FileDescriptionComponent implements OnInit { MIME_TYPE_IMAGES_PATH = './assets/images/mime/'; MIME_TYPE_DEFAULT_IMAGE_NAME = 'application-octet-stream.png'; @Input() fileInput: MetadataBitstream; - constructor(protected halService: HALEndpointService, private router: Router) { } + emailToContact: string; + + constructor(protected halService: HALEndpointService, + private router: Router, + private configService: ConfigurationDataService) { } + + ngOnInit(): void { + this.configService.findByPropertyName('lr.help.mail').subscribe(remoteData => { + this.emailToContact = remoteData.payload.values[0]; + }); + } public downloadFile() { void this.router.navigateByUrl('bitstreams/' + this.fileInput.id + '/download'); @@ -45,4 +56,9 @@ export class FileDescriptionComponent { const imgElement = event.target as HTMLImageElement; imgElement.src = this.MIME_TYPE_IMAGES_PATH + this.MIME_TYPE_DEFAULT_IMAGE_NAME; } + + isArchive(format: string): boolean { + return format === 'application/zip' || format === 'application/x-tar'; + } + } diff --git a/src/app/item-page/simple/field-components/preview-section/preview-section.component.html b/src/app/item-page/simple/field-components/preview-section/preview-section.component.html index 8404f491b4f..f094c948079 100644 --- a/src/app/item-page/simple/field-components/preview-section/preview-section.component.html +++ b/src/app/item-page/simple/field-components/preview-section/preview-section.component.html @@ -1,3 +1,10 @@ + +
+
+
{{'item.preview.loading-files' | translate}} + +
+
diff --git a/src/app/item-page/simple/field-components/preview-section/preview-section.component.spec.ts b/src/app/item-page/simple/field-components/preview-section/preview-section.component.spec.ts index 7b14feefd87..827b53a4cd6 100644 --- a/src/app/item-page/simple/field-components/preview-section/preview-section.component.spec.ts +++ b/src/app/item-page/simple/field-components/preview-section/preview-section.component.spec.ts @@ -7,20 +7,33 @@ import { PreviewSectionComponent } from './preview-section.component'; import { ResourceType } from 'src/app/core/shared/resource-type'; import { HALLink } from 'src/app/core/shared/hal-link.model'; import { Item } from 'src/app/core/shared/item.model'; +import { ConfigurationDataService } from '../../../../core/data/configuration-data.service'; +import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; +import { TranslateLoaderMock } from '../../../../shared/mocks/translate-loader.mock'; describe('PreviewSectionComponent', () => { let component: PreviewSectionComponent; let fixture: ComponentFixture; let mockRegistryService: any; + let mockConfigService: any; beforeEach(async () => { + mockConfigService = jasmine.createSpyObj(['findByPropertyName']); mockRegistryService = jasmine.createSpyObj('RegistryService', [ 'getMetadataBitstream', ]); await TestBed.configureTestingModule({ + imports: [TranslateModule.forRoot({ + loader: { + provide: TranslateLoader, + useClass: TranslateLoaderMock + } + })], declarations: [PreviewSectionComponent], - providers: [{ provide: RegistryService, useValue: mockRegistryService }], + providers: [ + { provide: RegistryService, useValue: mockRegistryService }, + { provide: ConfigurationDataService, useValue: mockConfigService }], }).compileComponents(); }); diff --git a/src/app/item-page/simple/field-components/preview-section/preview-section.component.ts b/src/app/item-page/simple/field-components/preview-section/preview-section.component.ts index ac8b5df4dd4..efcfcaba609 100644 --- a/src/app/item-page/simple/field-components/preview-section/preview-section.component.ts +++ b/src/app/item-page/simple/field-components/preview-section/preview-section.component.ts @@ -4,6 +4,7 @@ import { MetadataBitstream } from 'src/app/core/metadata/metadata-bitstream.mode import { RegistryService } from 'src/app/core/registry/registry.service'; import { Item } from 'src/app/core/shared/item.model'; import { getAllSucceededRemoteListPayload } from 'src/app/core/shared/operators'; +import { ConfigurationDataService } from '../../../../core/data/configuration-data.service'; @Component({ selector: 'ds-preview-section', @@ -14,8 +15,10 @@ export class PreviewSectionComponent implements OnInit { @Input() item: Item; listOfFiles: BehaviorSubject = new BehaviorSubject([] as any); + emailToContact: string; - constructor(protected registryService: RegistryService) {} // Modified + constructor(protected registryService: RegistryService, + private configService: ConfigurationDataService) {} // Modified ngOnInit(): void { this.registryService @@ -24,5 +27,10 @@ export class PreviewSectionComponent implements OnInit { .subscribe((data: MetadataBitstream[]) => { this.listOfFiles.next(data); }); + this.configService.findByPropertyName('lr.help.mail')?.subscribe(remoteData => { + this.emailToContact = remoteData.payload.values[0]; + }); } + + } diff --git a/src/assets/i18n/cs.json5 b/src/assets/i18n/cs.json5 index 347f7244a8f..cd0da6dccbe 100644 --- a/src/assets/i18n/cs.json5 +++ b/src/assets/i18n/cs.json5 @@ -3380,6 +3380,10 @@ "item.preview.authors.show.everyone": "Zobraz všechny autory", // "item.preview.authors.et.al": " ; et al.", "item.preview.authors.et.al": "; et al.", + // "item.preview.loading-files": "Loading files... This may take a few seconds as file previews are being generated. If the process takes too long, please contact the system administrator", + "item.preview.loading-files": "Načítání souborů... Může to trvat několik sekund, protože se generují náhledy souborů. Pokud proces trvá příliš dlouho, kontaktujte prosím správce systému", + // "item.preview.no-preview": "The file preview wasn't successfully generated, please contact the system administrator", + "item.preview.no-preview": "Náhled souboru nebyl úspěšně vygenerován, kontaktujte prosím správce systému", // "item.refbox.modal.copy.instruction": ["Press", "ctrl + c", "to copy"], "item.refbox.modal.copy.instruction": ["Stiskněte", "ctrl + c", "pro kopírování"], // "item.refbox.modal.submit": "Ok", diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index cdc43133891..7c8a91cfdbd 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -2832,6 +2832,10 @@ "item.preview.authors.et.al": " ; et al.", + "item.preview.loading-files": "Loading files... This may take a few seconds as file previews are being generated. If the process takes too long, please contact the system administrator", + + "item.preview.no-preview": "The file preview wasn't successfully generated, please contact the system administrator", + "item.refbox.modal.copy.instruction": ["Press", "ctrl + c", "to copy"], "item.refbox.modal.submit": "Ok", From b0be8b7e9f94f5cf7cfba99faae5b38c14958208 Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Thu, 3 Apr 2025 17:33:43 +0200 Subject: [PATCH 2/2] The (listOfFiles | async) could be null add a `?` check after it. --- .../file-description/file-description.component.ts | 2 +- .../preview-section/preview-section.component.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/item-page/simple/field-components/preview-section/file-description/file-description.component.ts b/src/app/item-page/simple/field-components/preview-section/file-description/file-description.component.ts index 510010b6de9..f8dc723c5a8 100644 --- a/src/app/item-page/simple/field-components/preview-section/file-description/file-description.component.ts +++ b/src/app/item-page/simple/field-components/preview-section/file-description/file-description.component.ts @@ -1,7 +1,7 @@ import { Component, Input, OnInit } from '@angular/core'; import { MetadataBitstream } from 'src/app/core/metadata/metadata-bitstream.model'; import { HALEndpointService } from '../../../../../core/shared/hal-endpoint.service'; -import {Router} from '@angular/router'; +import { Router } from '@angular/router'; import { ConfigurationDataService } from '../../../../../core/data/configuration-data.service'; const allowedPreviewFormats = ['text/plain', 'text/html', 'application/zip', 'application/x-tar']; diff --git a/src/app/item-page/simple/field-components/preview-section/preview-section.component.html b/src/app/item-page/simple/field-components/preview-section/preview-section.component.html index f094c948079..cd937f7b465 100644 --- a/src/app/item-page/simple/field-components/preview-section/preview-section.component.html +++ b/src/app/item-page/simple/field-components/preview-section/preview-section.component.html @@ -1,5 +1,5 @@ -
+
{{'item.preview.loading-files' | translate}}