Skip to content

Commit 8c2d207

Browse files
committed
files: add invenio record resources support
* Refactors the file component and service. Co-Authored-by: Johnny Mariéthoz <[email protected]>
1 parent 753e32e commit 8c2d207

File tree

9 files changed

+350
-275
lines changed

9 files changed

+350
-275
lines changed

projects/rero/ng-core/src/lib/record/files/file/file.component.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
</p>
3333
</div>
3434
<div class="col text-right">
35-
@if (canUpdateMetadata.can) {
35+
@if (canUpdateMetadata?.can) {
3636
<button class="btn btn-sm btn-outline-primary" (click)="editMetadata()">
3737
<i class="fa fa-pencil mr-1"></i>{{ 'Edit' | translate }}
3838
</button>
3939
}
40-
@if (canUpdate.can) {
40+
@if (canUpdate?.can) {
4141
<button class="btn btn-sm btn-outline-primary ml-1" (click)="manage()">
4242
<i class="fa fa-upload mr-1"></i>{{ 'New version' | translate }}
4343
</button>
@@ -47,14 +47,14 @@
4747
<i class="fa fa-download mr-1"></i>{{ 'Download' | translate }}
4848
</a>
4949

50-
@if (canDelete.can) {
50+
@if (canDelete?.can) {
5151
<button class="btn btn-sm btn-outline-danger ml-1" (click)="delete()">
5252
<i class="fa fa-trash mr-1"></i>{{ 'Delete' | translate }}
5353
</button>
5454
}
5555
</div>
5656
</div>
57-
@if (file.showInfo) {
57+
@if (file?.showInfo) {
5858
<div class="row mt-2">
5959
@if (file.is_head) {
6060
<div class="col">

projects/rero/ng-core/src/lib/record/files/file/file.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class FileComponent implements OnInit, OnDestroy {
9090
this.canDelete = result;
9191
})
9292
);
93-
obs$ = config.files.canUpdate
93+
obs$ = config?.files?.canUpdate
9494
? config.files.canUpdateMetadata(this.record, this.file)
9595
: of({ can: false, message: '' });
9696
this._subscriptions.add(

projects/rero/ng-core/src/lib/record/files/files.component.html

+61-68
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,43 @@
1414
You should have received a copy of the GNU Affero General Public License
1515
along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
-->
17-
<div class="card my-4">
17+
<div class="my-4" [ngClass]="{ card: title }">
18+
@if (title) {
1819
<div class="card-header">
19-
<h5 class="m-0" translate>Files</h5>
20+
<h5 class="m-0 d-inline-block" translate>{{ title }}</h5>
2021
</div>
21-
@if (!hasError && files.length) {
22-
<ul class="list-group list-group-flush">
23-
@for (file of files; track file) {
24-
@if (showItem(file)) {
25-
<li class="list-group-item">
26-
<ng-core-record-file
27-
[type]=type
28-
[record]=record
29-
[file]=file
30-
[hasChildren]=hasChildren(file)
31-
[infoExcludedFields]=infoExcludedFields
32-
(deleteFile)=deleteFile(file)
33-
(editMetadataFile)=editMetadataFile(file)
34-
(manageFile)=manageFile(file)
35-
></ng-core-record-file>
36-
</li>
37-
}
38-
}
39-
</ul>
4022
}
41-
42-
@if (hasError || files.length === 0) {
43-
<div class="card-body">
44-
@if (!hasError && files.length === 0) {
45-
<div class="alert alert-info m-0" translate>
46-
No file found for this record.
47-
</div>
48-
}
49-
@if (hasError) {
50-
<div class="alert alert-danger m-0" translate>An error occurred, files cannot be loaded.</div>
51-
}
52-
</div>
53-
}
54-
@if (canAdd.can) {
55-
<div class="card-footer text-center">
56-
<button class="btn btn-sm btn-primary" (click)="manageFile(null)">
57-
<i class="fa fa-plus mr-1"></i>{{ 'Add a new file' | translate }}
58-
</button>
23+
<div [ngClass]="{ 'card-body': title }">
24+
@if (canAdd.can) {
25+
<div class="row">
26+
<div class="col">
27+
<button class="pull-right btn btn-sm btn-primary" (click)="manageFile(null)">
28+
<i class="fa fa-plus mr-1"></i>{{ 'Add a new file' | translate }}
29+
</button>
30+
</div>
5931
</div>
60-
}
32+
<hr />
33+
} @if (!hasError && files.length) {
34+
<ul class="list-group list-group-flush">
35+
@for (file of files; track file) { @if (showItem(file)) {
36+
<li class="list-group-item">
37+
<ng-core-record-file
38+
[type]="type"
39+
[record]="parentRecord"
40+
[file]="file"
41+
[hasChildren]="hasChildren(file)"
42+
[infoExcludedFields]="infoExcludedFields"
43+
(deleteFile)="deleteFile(file)"
44+
(editMetadataFile)="editMetadataFile(file)"
45+
(manageFile)="manageFile(file)"
46+
></ng-core-record-file>
47+
</li>
48+
} }
49+
</ul>
50+
} @if (hasError) {
51+
<div class="alert alert-danger m-0" translate>An error occurred, files cannot be loaded.</div>
52+
}
53+
</div>
6154
</div>
6255

6356
<ng-template #formModal>
@@ -72,43 +65,43 @@ <h4 class="modal-title pull-left">{{ currentFile ? currentFile.key : ('Add a new
7265
<input #file type="file" id="file" (change)="handleFileInput($event.target.files)" />
7366
</div>
7467
@if (!currentFile && filesToUpload) {
75-
<div class="form-group">
76-
<label for="file-key" translate>File name</label>
77-
<input type="text" id="file-key" class="form-control" [(ngModel)]="fileKey" />
78-
</div>
68+
<div class="form-group">
69+
<label for="file-key" translate>File name</label>
70+
<input type="text" id="file-key" class="form-control" [(ngModel)]="fileKey" />
71+
</div>
7972
}
8073
<div>
8174
@if (filesToUpload && filesToUpload.length > 0) {
82-
<button class="btn btn-sm btn-outline-primary mr-1" (click)="upload()">
83-
<i class="fa fa-upload mr-1"></i> {{ 'Upload' | translate }}
84-
</button>
85-
<button class="btn btn-sm btn-outline-danger" (click)="resetForm(); hideForm()">
86-
<i class="fa fa-times mr-1"></i> {{ 'Cancel' | translate }}
87-
</button>
75+
<button class="btn btn-sm btn-outline-primary mr-1" (click)="upload()">
76+
<i class="fa fa-upload mr-1"></i> {{ 'Upload' | translate }}
77+
</button>
78+
<button class="btn btn-sm btn-outline-danger" (click)="resetForm(); hideForm()">
79+
<i class="fa fa-times mr-1"></i> {{ 'Cancel' | translate }}
80+
</button>
8881
}
8982
</div>
9083
</div>
9184
</ng-template>
9285

9386
<ng-template #metadataFormModal>
9487
@if (metadataForm.model) {
95-
<div class="modal-header">
96-
<h4 class="modal-title pull-left">{{ metadataForm.model.key }}</h4>
97-
<button type="button" class="close pull-right" aria-label="Close" (click)="hideForm()">
98-
<span aria-hidden="true">&times;</span>
99-
</button>
100-
</div>
101-
<div class="modal-body">
102-
<form [formGroup]="metadataForm.form" (ngSubmit)="saveMetadata()">
103-
<formly-form [form]="metadataForm.form" [model]="metadataForm.model" [fields]="metadataForm.fields">
104-
</formly-form>
105-
<div class="text-center">
106-
<button type="submit" class="btn btn-primary btn-block">
107-
<i class="fa fa-floppy-o mr-2"></i>
108-
{{ 'Save' | translate }}
109-
</button>
110-
</div>
111-
</form>
112-
</div>
88+
<div class="modal-header">
89+
<h4 class="modal-title pull-left">{{ metadataForm.model.key }}</h4>
90+
<button type="button" class="close pull-right" aria-label="Close" (click)="hideForm()">
91+
<span aria-hidden="true">&times;</span>
92+
</button>
93+
</div>
94+
<div class="modal-body">
95+
<form [formGroup]="metadataForm.form" (ngSubmit)="saveMetadata()">
96+
<formly-form [form]="metadataForm.form" [model]="metadataForm.model" [fields]="metadataForm.fields">
97+
</formly-form>
98+
<div class="text-center">
99+
<button type="submit" class="btn btn-primary btn-block">
100+
<i class="fa fa-floppy-o mr-2"></i>
101+
{{ 'Save' | translate }}
102+
</button>
103+
</div>
104+
</form>
105+
</div>
113106
}
114107
</ng-template>

0 commit comments

Comments
 (0)