diff --git a/angular.json b/angular.json index 1b98344b..f7a61f9a 100644 --- a/angular.json +++ b/angular.json @@ -1,7 +1,7 @@ { "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, - "newProjectRoot": "projects", + "defaultProject": "@rero/ng-core", "projects": { "@rero/ng-core": { "projectType": "library", @@ -167,15 +167,5 @@ } } } - }, - "cli": { - "schematicCollections": [ - "@ngx-formly/schematics" - ] - }, - "schematics": { - "@ngx-formly/schematics:component": { - "styleext": "scss" - } } } diff --git a/projects/rero/ng-core/src/lib/record/detail/detail.component.html b/projects/rero/ng-core/src/lib/record/detail/detail.component.html index 141c2eda..e2e6ddf0 100644 --- a/projects/rero/ng-core/src/lib/record/detail/detail.component.html +++ b/projects/rero/ng-core/src/lib/record/detail/detail.component.html @@ -46,6 +46,7 @@ {{ 'Edit' | translate }} + + + + + + {{ 'Download' | translate }} + + + + + +
+
+
+ + +
{{ item.key | translate }}
+
{{ item.value | translate }}
+
+
+
+
+
+
+
Size
+
{{ file.size | filesize }}
+ +
Mime type
+
{{ file.mimetype }}
+ +
Checksum
+
{{ file.checksum }}
+ +
Modified at
+
{{ file.updated | dateTranslate : 'medium' }}
+
+
+
+
diff --git a/projects/rero/ng-core/src/lib/record/files/file/file.component.spec.ts b/projects/rero/ng-core/src/lib/record/files/file/file.component.spec.ts new file mode 100644 index 00000000..1aedc6f5 --- /dev/null +++ b/projects/rero/ng-core/src/lib/record/files/file/file.component.spec.ts @@ -0,0 +1,29 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { FileComponent } from './file.component'; +import { RecordUiService } from '../../record-ui.service'; +import { TranslateModule } from '@ngx-translate/core'; + +const recordUiServiceSpy = jasmine.createSpyObj('RecordUiService', ['getResourceConfig']); +recordUiServiceSpy.getResourceConfig.and.returnValue({ key: 'documents', files: {} }); +describe('FileComponent', () => { + let component: FileComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [FileComponent], + imports: [TranslateModule.forRoot()], + providers: [{ provide: RecordUiService, useValue: recordUiServiceSpy }], + }).compileComponents(); + + fixture = TestBed.createComponent(FileComponent); + component = fixture.componentInstance; + component.type = 'documents'; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/projects/rero/ng-core/src/lib/record/files/file/file.component.ts b/projects/rero/ng-core/src/lib/record/files/file/file.component.ts new file mode 100644 index 00000000..193fd3d6 --- /dev/null +++ b/projects/rero/ng-core/src/lib/record/files/file/file.component.ts @@ -0,0 +1,130 @@ +/* + * RERO angular core + * Copyright (C) 2023 RERO + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'; +import { RecordUiService } from '../../record-ui.service'; +import { Subscription, of } from 'rxjs'; +import { ActionStatus } from '../../action-status'; + +@Component({ + selector: 'ng-core-record-file', + templateUrl: './file.component.html', +}) +export class FileComponent implements OnInit, OnDestroy { + // record data + @Input() record: any; + + // record file data + @Input() file: any; + + // record type + @Input() type: any; + + // true if the file has old versions + @Input() hasChildren: boolean; + + // list of fields to not display + @Input() infoExcludedFields: Array = []; + + // event emitter when the delete button is clicked + @Output() deleteFile: EventEmitter = new EventEmitter(); + + // event emitter when the edit metadata button is clicked + @Output() manageFile: EventEmitter = new EventEmitter(); + + // event emitter when edit button is clicked + @Output() editMetadataFile: EventEmitter = new EventEmitter(); + + // permissions + canUpdateMetadata: ActionStatus; + canUpdate: ActionStatus; + canDelete: ActionStatus; + + // subscriptions to observables + private _subscriptions: Subscription = new Subscription(); + + /** + * Constructor. + * + * @param _recordUiService RecordUiService. + */ + constructor(private _recordUiService: RecordUiService) {} + + /** + * hook OnInit + */ + ngOnInit(): void { + this.loadPermission(); + } + + /** + * Loads the permissions. + */ + loadPermission() { + const config = this._recordUiService.getResourceConfig(this.type); + let obs$ = config.files.canUpdate + ? config.files.canUpdate(this.record, this.file) + : of({ can: false, message: '' }); + this._subscriptions.add( + obs$.subscribe((result: ActionStatus) => { + this.canUpdate = result; + }) + ); + obs$ = config.files.canDelete ? config.files.canDelete(this.record, this.file) : of({ can: false, message: '' }); + this._subscriptions.add( + obs$.subscribe((result: ActionStatus) => { + this.canDelete = result; + }) + ); + obs$ = config.files.canUpdate + ? config.files.canUpdateMetadata(this.record, this.file) + : of({ can: false, message: '' }); + this._subscriptions.add( + obs$.subscribe((result: ActionStatus) => { + this.canUpdateMetadata = result; + }) + ); + } + + /** + * Component destruction. + */ + ngOnDestroy(): void { + this._subscriptions.unsubscribe(); + } + + /** + * Delete the file. + */ + delete() { + this.deleteFile.emit(); + } + + /** + * Edit the files. + */ + manage() { + this.manageFile.emit(); + } + + /** + * Edit the metadata. + */ + editMetadata() { + this.editMetadataFile.emit(); + } +} diff --git a/projects/rero/ng-core/src/lib/record/files/files.component.html b/projects/rero/ng-core/src/lib/record/files/files.component.html index a8ad5b6b..6b4926a7 100644 --- a/projects/rero/ng-core/src/lib/record/files/files.component.html +++ b/projects/rero/ng-core/src/lib/record/files/files.component.html @@ -1,16 +1,16 @@ @@ -22,74 +22,28 @@
Files
  • -
    -
    -

    - {{ file.key }} - - - - - - -

    -
    -
    - - - - {{ 'Download' | translate }} - - -
    -
    -
    -
    -
    - - -
    {{ item.key | translate }}
    -
    {{ item.value | translate }}
    -
    -
    -
    -
    -
    -
    -
    Size
    -
    {{ file.size | filesize }}
    - -
    Mime type
    -
    {{ file.mimetype }}
    - -
    Checksum
    -
    {{ file.checksum }}
    - -
    Modified at
    -
    {{ file.updated | dateTranslate:'medium' }}
    -
    -
    -
    +
- - +
-
No file found for this record. +
+ No file found for this record.
An error occurred, files cannot be loaded.
-