Skip to content

Commit 8a28726

Browse files
committed
fix(validation): restore ValidationComponent accidentally deleted
The ValidationComponent was removed in commit ced084f during the signal refactoring. This component is required for the project validation workflow in HEPVS. - Restore validation.component.ts and validation.component.html - Update import path for enums (./constants -> ../../enum/validation) - Add ValidationComponent to app.module.ts declarations Co-Authored-by: Pascal Repond <pascal.repond@rero.ch>
1 parent 1571c7e commit 8a28726

File tree

3 files changed

+237
-1
lines changed

3 files changed

+237
-1
lines changed

projects/sonar/src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import { BriefViewComponent as ProjectBriefViewComponent } from './record/projec
9595
import { DetailComponent as ProjectDetailComponent } from './record/project/detail/detail.component';
9696
import { BriefViewComponent as SubdivisionBriefViewComponent } from './record/subdivision/brief-view/brief-view.component';
9797
import { UserComponent } from './record/user/user.component';
98+
import { ValidationComponent } from './record/validation/validation.component';
9899
import { UserService } from './user.service';
99100
import { LicensePipe } from './record/document/license.pipe';
100101
import { BucketNameService } from './bucket-name.service';
@@ -145,7 +146,8 @@ export function minElementError(err: any, field: FormlyFieldConfig) {
145146
MetadataComponent,
146147
FilesComponent,
147148
SwisscoveryComponent,
148-
LicensePipe
149+
LicensePipe,
150+
ValidationComponent
149151
],
150152
bootstrap: [AppComponent],
151153
schemas: [CUSTOM_ELEMENTS_SCHEMA],
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<!--
2+
SONAR User Interface
3+
Copyright (C) 2021 RERO
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published by
7+
the Free Software Foundation, version 3 of the License.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Affero General Public License for more details.
13+
14+
You should have received a copy of the GNU Affero General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
-->
17+
@if(validation && user && (!isModerator() || !isOwner())) {
18+
<p-panel [header]="'Validation' | translate">
19+
<div class="ui:flex ui:flex-col ui:gap-2 ui:justify-center ui:p-2">
20+
@if(validation.status === validationStatus.IN_PROGRESS || validation.status === validationStatus.ASK_FOR_CHANGES) {
21+
<p-message class="ui:w-full" severity="warn" showTransitionOptions="0ms">
22+
{{ "The record is currently in status \"\{\{ status \}\}\". It is not visible in public views." | translate: { status: ('validation_status_' + validation.status) | translate } }}
23+
@if(isOwner()) {
24+
<a href="#" class="alert-link" (click)="$event.preventDefault(); updateValidation(validationAction.PUBLISH)" translate>
25+
Submit it
26+
</a>.
27+
}
28+
</p-message>
29+
}
30+
@if(validation.status === validationStatus.TO_VALIDATE) {
31+
<p-message class="ui:w-full" severity="warn" showTransitionOptions="0ms">
32+
{{"The record is in validation. It will be reviewed by a moderator before publishing." | translate}}
33+
</p-message>
34+
}
35+
@if(validation.status === validationStatus.REJECTED) {
36+
<p-message class="ui:w-full" severity="error" showTransitionOptions="0ms">
37+
{{ "The record has been rejected after a review from a moderator." | translate}}
38+
</p-message>
39+
}
40+
@if(validation.status === validationStatus.VALIDATED) {
41+
<p-message class="ui:w-full" severity="success" showTransitionOptions="0ms">
42+
{{ "The record is currently published. It is visible in public views." | translate }}
43+
</p-message>
44+
45+
}
46+
@if(validation.status === validationStatus.TO_VALIDATE && isModerator()) {
47+
<textarea
48+
#comment
49+
class="ui:min-w-lg ui:my-4"
50+
pTextarea
51+
[autoResize]="true"
52+
[placeholder]="'Leave a comment...' | translate"
53+
></textarea>
54+
<div class="ui:flex ui:justify-center">
55+
<p-buttongroup class="ui:mx-auto">
56+
<p-button
57+
size="large"
58+
severity="success"
59+
(onClick)="updateValidation(validationAction.APPROVE)"
60+
[label]="'Approve' | translate"
61+
/>
62+
<p-button
63+
size="large"
64+
severity="warn"
65+
(onClick)="updateValidation(validationAction.ASK_FOR_CHANGES)"
66+
[label]="'Ask for changes' | translate"
67+
/>
68+
<p-button
69+
size="large"
70+
severity="danger"
71+
(onClick)="updateValidation(validationAction.REJECT)"
72+
[label]="'Reject' | translate"
73+
/>
74+
</p-buttongroup>
75+
</div>
76+
}
77+
@if(validation.logs) {
78+
<p-button [text]="true" [label]="'Show logs'" (onClick)="showLogs = !showLogs" />
79+
@if(showLogs) {
80+
<p-table [value]="validation.logs" [tableStyle]="{ 'min-width': '50rem' }">
81+
<ng-template #header>
82+
<tr>
83+
<th translate>Status</th>
84+
<th translate>Date</th>
85+
<th translate>User</th>
86+
<th translate>Comment</th>
87+
</tr>
88+
</ng-template>
89+
<ng-template #body let-log>
90+
<tr>
91+
<td>{{ ('validation_status_' + log.status) | translate }}</td>
92+
<td>{{ log.date | dateTranslate: 'medium' }}</td>
93+
<td>{{ log.user.name }}</td>
94+
<td [innerHtml]="log.comment | nl2br"></td>
95+
</tr>
96+
</ng-template>
97+
</p-table>
98+
}
99+
}
100+
</div>
101+
</p-panel>
102+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* SONAR User Interface
3+
* Copyright (C) 2021 RERO
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, version 3 of the License.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
import { Component, ElementRef, inject, Input, OnInit, ViewChild } from '@angular/core';
18+
import { TranslateService } from '@ngx-translate/core';
19+
import { CONFIG, RecordService } from '@rero/ng-core';
20+
import { NgxSpinnerService } from 'ngx-spinner';
21+
import { ConfirmationService, MessageService } from 'primeng/api';
22+
import { UserService } from '../../user.service';
23+
import { validation_action, validation_status } from '../../enum/validation';
24+
25+
/**
26+
* Component to manage validation on a record.
27+
*/
28+
@Component({
29+
selector: 'sonar-record-validation',
30+
templateUrl: './validation.component.html',
31+
standalone: false,
32+
})
33+
export class ValidationComponent implements OnInit {
34+
35+
private userService: UserService = inject(UserService);
36+
private recordService: RecordService = inject(RecordService);
37+
private translateService: TranslateService = inject(TranslateService);
38+
private messageService: MessageService = inject(MessageService);
39+
private confirmationService: ConfirmationService = inject(ConfirmationService);
40+
private spinner: NgxSpinnerService = inject(NgxSpinnerService);
41+
42+
// Constant for validation status.
43+
readonly validationStatus = validation_status;
44+
45+
// Constant for validation actions.
46+
readonly validationAction = validation_action;
47+
48+
// Record object.
49+
@Input() record: any;
50+
51+
// Resource type.
52+
@Input() type: string;
53+
54+
// Current logged user.
55+
user: any;
56+
57+
// Validation metadata of the record.
58+
validation: any;
59+
60+
// Wether to show logs table or not.
61+
showLogs = false;
62+
63+
/** Used to retrieve value for the comment */
64+
@ViewChild('comment') comment: ElementRef;
65+
66+
ngOnInit(): void {
67+
this.validation = this.record.metadata.validation;
68+
69+
this.userService.user$.subscribe((user) => {
70+
this.user = user;
71+
});
72+
}
73+
74+
/**
75+
* Check if current user is the creator of the record.
76+
*
77+
* @returns True if current user is the creator of the record.
78+
*/
79+
isOwner(): boolean {
80+
return this.userService.getUserRefEndpoint() === this.validation.user.$ref;
81+
}
82+
83+
/**
84+
* Check if current user is moderator.
85+
*
86+
* @returns True if current user is moderator.
87+
*/
88+
isModerator(): boolean {
89+
return this.user.is_moderator;
90+
}
91+
92+
/**
93+
* Update the validation, depending on the action.
94+
*
95+
* @param action Action done.
96+
*/
97+
updateValidation(action: string): void {
98+
this.confirmationService.confirm({
99+
header: this.translateService.instant('validation_action_' + action),
100+
message: this.translateService.instant(
101+
'Do you really want to do this action?'
102+
),
103+
closable: false,
104+
rejectButtonStyleClass: 'p-button-text',
105+
accept: () => {
106+
this.spinner.show();
107+
108+
this.validation.action = action;
109+
110+
// Store the comment
111+
if (this.comment && this.comment.nativeElement.value) {
112+
this.validation.comment = this.comment.nativeElement.value;
113+
} else {
114+
delete this.validation.comment;
115+
}
116+
117+
this.recordService
118+
.update(this.type, this.record.id, this.record)
119+
.subscribe((record: any) => {
120+
this.record = record;
121+
this.validation = this.record.metadata.validation;
122+
this.spinner.hide();
123+
this.messageService.add({
124+
severity: 'success',
125+
detail: this.translateService.instant('Review has been done successfully!'),
126+
life: CONFIG.MESSAGE_LIFE,
127+
});
128+
});
129+
},
130+
});
131+
}
132+
}

0 commit comments

Comments
 (0)