Commit 7f6a04e7 authored by Alicia.DeDiosFuente's avatar Alicia.DeDiosFuente Committed by Florent Poittevin
Browse files

feat: add reason when rejecting a deposit

parent 9850bf9a
<dlcm-shared-base-action-dialog [titleToTranslate]="'deposit.file.modal.changeDataCategory.title' | translate">
<dlcm-shared-base-action-dialog [titleToTranslate]="'deposit.dialog.reject.title' | translate">
<form [formGroup]="form"
(ngSubmit)="onSubmit()"
>
......@@ -64,4 +64,4 @@
(click)="onSubmit()"
>{{labelTranslateEnum.confirm | translate}}
</button>
</div>
\ No newline at end of file
</div>
<dlcm-shared-base-action-dialog [titleToTranslate]="'archiveRestricted.modal.requestAccess.title' | translate">
<form [formGroup]="form"
class="form"
(ngSubmit)="onSubmit()"
>
<mat-form-field *ngIf="getFormControl(formDefinition.message) as fd">
<mat-label>{{labelTranslateEnum.message | translate }}</mat-label>
<textarea [formControl]="fd"
[solidifyValidation]="errors"
matInput
[required]="formValidationHelper.hasRequiredField(fd)"
></textarea>
<mat-error #errors></mat-error>
</mat-form-field>
</form>
</dlcm-shared-base-action-dialog>
<div mat-dialog-actions
class="footer"
>
<button mat-button
[mat-dialog-close]=""
cdkFocusInitial
>{{labelTranslateEnum.close | translate}}
</button>
<button mat-flat-button
color="primary"
[dlcmButtonSpinner]="isLoadingObs | async"
[disabled]="form.invalid"
solidifyShortCuts
(onEnter)="onSubmit()"
(click)="onSubmit()"
>{{labelTranslateEnum.confirm | translate}}
</button>
</div>
@import "../../../../../../sass/abstracts/variables";
@import "../../../../../../sass/abstracts/mixins";
.form {
> * {
width: 100%;
}
}
import {
ChangeDetectionStrategy,
Component,
OnInit,
} from "@angular/core";
import {SharedAbstractContainer} from "@shared/components/containers/shared-abstract/shared-abstract.container";
import {
AbstractControl,
FormBuilder,
FormGroup,
Validators,
} from "@angular/forms";
import {BaseFormDefinition} from "@shared/models/base-form-definition.model";
import {PropertyName} from "solidify-frontend";
import {
Actions,
Store,
} from "@ngxs/store";
import {MatDialogRef} from "@angular/material/dialog";
import {
FormValidationHelper,
SolidifyValidator,
MemoizedUtil,
} from "solidify-frontend";
import {Observable} from "rxjs/index";
import {DepositState} from "@deposit/stores/deposit.state";
@Component({
selector: "dlcm-deposit-reject-dialog",
templateUrl: "./deposit-reject.dialog.html",
styleUrls: ["./deposit-reject.dialog.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DepositRejectDialog extends SharedAbstractContainer implements OnInit {
isLoadingObs: Observable<boolean> = MemoizedUtil.isLoading(this._store, DepositState);
form: FormGroup;
formDefinition: FormComponentFormDefinition = new FormComponentFormDefinition();
constructor(private readonly _store: Store,
private readonly _actions$: Actions,
private readonly _dialogRef: MatDialogRef<DepositRejectDialog>,
private readonly _fb: FormBuilder) {
super();
}
ngOnInit(): void {
super.ngOnInit();
this.form = this._fb.group({
[this.formDefinition.message]: ["", [Validators.required, SolidifyValidator]],
});
}
close(): void {
this._dialogRef.close();
}
onSubmit(): void {
this._dialogRef.close(this.form.get(this.formDefinition.message).value);
}
getFormControl(key: string): AbstractControl {
return FormValidationHelper.getFormControl(this.form, key);
}
get formValidationHelper(): typeof FormValidationHelper {
return FormValidationHelper;
}
}
class FormComponentFormDefinition extends BaseFormDefinition {
@PropertyName() message: string;
}
......@@ -83,6 +83,7 @@ import {
Override,
QueryParameters,
} from "solidify-frontend";
import {DepositRejectDialog} from "@deposit/components/dialogs/deposit-reject/deposit-reject.dialog";
@Component({
selector: "dlcm-deposit-detail-edit-routable",
......@@ -465,7 +466,19 @@ export class DepositDetailEditRoutable extends SharedAbstractDetailEditRoutable<
reject(): void {
this.subscribe(this.currentObs.pipe(
take(1),
tap(deposit => this._store.dispatch(new DepositAction.Reject(deposit))),
tap(deposit => {
this._dialog.open(DepositRejectDialog, {
minWidth: "500px",
}).afterClosed().pipe(
take(1),
tap((message: string | undefined) => {
if (isNullOrUndefined(message)) {
return;
}
this._store.dispatch(new DepositAction.Reject(deposit, message));
}),
).subscribe();
}),
));
}
......
......@@ -39,6 +39,7 @@ import {DepositCreateRoutable} from "./components/routables/deposit-create/depos
import {DepositDetailEditRoutable} from "./components/routables/deposit-detail-edit/deposit-detail-edit.routable";
import {DepositService} from "./services/deposit.service";
import {DepositDataFileMetadataTypeState} from "./stores/data-file/metadata-type/deposit-data-file-metadata-type.state";
import {DepositRejectDialog} from "@deposit/components/dialogs/deposit-reject/deposit-reject.dialog";
const routables = [
DepositRootRoutable,
......@@ -63,6 +64,7 @@ const dialogs = [
DepositAipUploadDialog,
DepositFileMoveDialog,
DepositFileChangeDataCategoryDialog,
DepositRejectDialog,
];
const presentationals = [
DepositFormPresentational,
......
......@@ -249,7 +249,7 @@ export namespace DepositAction {
export class Reject {
static readonly type: string = `[${state}] Reject`;
constructor(public deposit: Deposit) {
constructor(public deposit: Deposit, public message: string) {
}
}
......
......@@ -204,6 +204,8 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
private readonly _ZIP_EXTENSION: string = ".zip";
private readonly _DEPOSIT_FILE_DOWNLOAD_PREFIX: string = "deposit_";
private readonly _FOLDER_QUERY_PARAM: string = "folder";
private readonly _DEPOSIT_REJECT_MESSAGE: string = "message";
constructor(protected apiService: ApiService,
protected store: Store,
......@@ -483,14 +485,14 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
@Action(DepositAction.Reject)
reject(ctx: StateContext<DepositStateModel>, action: DepositAction.Reject): Observable<Result> {
return this.apiService.post<Result>(this._urlResource + urlSeparator + action.deposit.resId + urlSeparator + ApiActionEnum.REJECT)
return this.apiService.post<Result>(`${this._urlResource + urlSeparator + action.deposit.resId + urlSeparator + ApiActionEnum.REJECT}?${this._DEPOSIT_REJECT_MESSAGE}=${action.message}`)
.pipe(
tap(deposit => ctx.dispatch(new DepositAction.RejectSuccess(deposit))),
catchError(error => {
ctx.dispatch(new DepositAction.RejectFail());
throw new SolidifyStateError(this, error);
}),
);
tap(deposit => ctx.dispatch(new DepositAction.RejectSuccess(deposit))),
catchError(error => {
ctx.dispatch(new DepositAction.RejectFail());
throw new SolidifyStateError(this, error);
}),
);
}
@Action(DepositAction.RejectSuccess)
......
......@@ -584,6 +584,9 @@
},
"deleteFolder": {
"message": "Sind Sie sicher, dass Sie den Ordner: '{{name}}' löschen wollen? Dadurch werden auch Unterordner gelöscht."
},
"reject": {
"message": "Grund für die Ablehnung der Hinterlegung"
}
},
"error": {
......@@ -1890,4 +1893,4 @@
"required": "Dieses Feld muss ausgefüllt werden"
}
}
}
\ No newline at end of file
}
......@@ -584,6 +584,9 @@
},
"deleteFolder": {
"message": "Are you sure you want to delete the folder: '{{name}}'? This will also cause subfolders to be deleted."
},
"reject": {
"message": "Reason for rejecting deposit"
}
},
"error": {
......@@ -1890,4 +1893,4 @@
"required": "This field is required"
}
}
}
\ No newline at end of file
}
......@@ -584,6 +584,9 @@
},
"deleteFolder": {
"message": "Êtes-vous sûr de vouloir supprimer le dossier '{{name}}' ? Cela provoquera également la suppression des sous dossiers."
},
"reject": {
"message": "Motif du rejet du dépôt"
}
},
"error": {
......@@ -1890,4 +1893,4 @@
"required": "Ce champ est obligatoire"
}
}
}
\ No newline at end of file
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment