From 82812b32c10fb1470e1485de591119fef0985d28 Mon Sep 17 00:00:00 2001 From: Nordine Bittich Date: Sat, 27 Jan 2024 22:59:27 +0100 Subject: [PATCH] fee --- .../dossier-form/dossier-form.component.ts | 7 +++++++ .../fee/fee-detail/fee-detail.component.html | 16 +++++++------- .../fee/fee-detail/fee-detail.component.ts | 21 ++++++++++++++++--- .../fee-table-result.component.html | 3 ++- .../fee-table-result.component.ts | 1 + .../fee/tag-form/tag-form.component.html | 12 +++-------- .../fee/tag-form/tag-form.component.ts | 14 ++++++++++--- .../update-price/update-price.component.html | 8 +++---- .../update-price/update-price.component.ts | 17 ++++++++++++--- 9 files changed, 68 insertions(+), 31 deletions(-) diff --git a/src/app/features/dossier/dossier-form/dossier-form.component.ts b/src/app/features/dossier/dossier-form/dossier-form.component.ts index acd7e30..7e09b9b 100644 --- a/src/app/features/dossier/dossier-form/dossier-form.component.ts +++ b/src/app/features/dossier/dossier-form/dossier-form.component.ts @@ -17,6 +17,7 @@ import { AdministrativeDocumentService } from '@core/service/administrative-docu import { AdministrativeDocument } from '@core/models/administrative-document'; import { DocumentEditorComponent } from '@feature/administrative-document/document-editor/document-editor.component'; import { FileService } from '@core/service/file.service'; +import { User } from '@core/models/user'; @Component({ selector: 'app-dossier-form', @@ -36,6 +37,11 @@ export class DossierFormComponent implements OnInit, OnDestroy { recallForModification: boolean = false; @Input() labels: Label[]; + @Input() + user: User; + get hasRoleAdmin(): boolean { + return this.user.authorities.includes('ADMIN'); + } searchExpense: string; vatTotal: number = 0; @@ -294,6 +300,7 @@ export class DossierFormComponent implements OnInit, OnDestroy { openFeeDetail(f: Fee) { const modalRef = this.modalService.open(FeeDetailComponent, { size: 'xl' }); + modalRef.componentInstance.user = this.user; modalRef.componentInstance.fee = f; } diff --git a/src/app/features/fee/fee-detail/fee-detail.component.html b/src/app/features/fee/fee-detail/fee-detail.component.html index 2a0975e..63db635 100644 --- a/src/app/features/fee/fee-detail/fee-detail.component.html +++ b/src/app/features/fee/fee-detail/fee-detail.component.html @@ -5,10 +5,8 @@ fee.subject | titlecase }} - - Imported on {{fee.importedDate | date:'dd/MM/yyyy HH:mm'}} - - @@ -65,7 +63,8 @@ {{ a.originalFilename }}
- @@ -86,7 +85,8 @@ Costs
- +
@@ -94,8 +94,8 @@ Tag
- +
diff --git a/src/app/features/fee/fee-detail/fee-detail.component.ts b/src/app/features/fee/fee-detail/fee-detail.component.ts index 31c545e..3b70bf4 100644 --- a/src/app/features/fee/fee-detail/fee-detail.component.ts +++ b/src/app/features/fee/fee-detail/fee-detail.component.ts @@ -9,6 +9,7 @@ import { ImageViewerComponent } from '@shared/image-viewer/image-viewer.componen import { LabelService } from '@core/service/label.service'; import { ToastService } from '@core/service/toast.service'; import { firstValueFrom } from 'rxjs'; +import { User } from '@core/models/user'; @Component({ selector: 'app-fee-detail', @@ -20,7 +21,12 @@ export class FeeDetailComponent implements OnInit { fee: Fee; @Output() feeUpdated: EventEmitter = new EventEmitter(); + @Input() + user: User; + get hasRoleAdmin(): boolean { + return this.user.authorities.includes('ADMIN'); + } tags: Label[]; constructor( @Optional() public activeModal: NgbActiveModal, @@ -28,8 +34,8 @@ export class FeeDetailComponent implements OnInit { private labelService: LabelService, private modalService: NgbModal, private toastService: ToastService, - private fileService: FileService - ) {} + private fileService: FileService, + ) { } ngOnInit(): void { this.load(); @@ -48,7 +54,7 @@ export class FeeDetailComponent implements OnInit { this.tags = labels; } - downloadAttachment(evt, a: FileUpload) { + downloadAttachment(evt: any, a: FileUpload) { evt.stopPropagation(); this.fileService.download(a); } @@ -64,6 +70,9 @@ export class FeeDetailComponent implements OnInit { removeAttachment($event: MouseEvent, a: FileUpload) { $event.stopPropagation(); + if (!this.hasRoleAdmin) { + return; + } this.feeService.removeAttachment(this.fee.id, a.id).subscribe((f) => { this.feeUpdated.emit(f); this.fee = f; @@ -98,6 +107,9 @@ export class FeeDetailComponent implements OnInit { } updatePrice(request: FeeUpdatePriceRequest) { + if (!this.hasRoleAdmin) { + return; + } this.feeService.updatePrice(request.id, request.priceHVAT, request.vat).subscribe((f) => { this.fee = f; this.load(); @@ -107,6 +119,9 @@ export class FeeDetailComponent implements OnInit { } updateTag(fee: Fee, $event: Label) { + if (!this.hasRoleAdmin) { + return; + } this.feeService.updateTag([fee.id], $event).subscribe((data) => { if (data?.length !== 1) { console.error('response not equals to 1!!'); diff --git a/src/app/features/fee/fee-table-result/fee-table-result.component.html b/src/app/features/fee/fee-table-result/fee-table-result.component.html index e9804a6..3151998 100644 --- a/src/app/features/fee/fee-table-result/fee-table-result.component.html +++ b/src/app/features/fee/fee-table-result/fee-table-result.component.html @@ -30,7 +30,8 @@
- +
diff --git a/src/app/features/fee/fee-table-result/fee-table-result.component.ts b/src/app/features/fee/fee-table-result/fee-table-result.component.ts index 63b88d9..2a0e0f4 100644 --- a/src/app/features/fee/fee-table-result/fee-table-result.component.ts +++ b/src/app/features/fee/fee-table-result/fee-table-result.component.ts @@ -140,6 +140,7 @@ export class FeeTableResultComponent implements OnInit, OnApplicationEvent { scrollable: true, backdrop: 'static', }); + modalRef.componentInstance.user = this.user; modalRef.componentInstance.fee = f; modalRef.componentInstance.feeUpdated.subscribe((_f: any) => { this.load(); diff --git a/src/app/features/fee/tag-form/tag-form.component.html b/src/app/features/fee/tag-form/tag-form.component.html index 9db1f00..1b28c38 100644 --- a/src/app/features/fee/tag-form/tag-form.component.html +++ b/src/app/features/fee/tag-form/tag-form.component.html @@ -3,18 +3,12 @@
-
-
+
 Saved!
diff --git a/src/app/features/fee/update-price/update-price.component.ts b/src/app/features/fee/update-price/update-price.component.ts index 2592a7a..17353ea 100644 --- a/src/app/features/fee/update-price/update-price.component.ts +++ b/src/app/features/fee/update-price/update-price.component.ts @@ -1,6 +1,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { Fee, FeeUpdatePriceRequest } from '@core/models/fee'; import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; +import { User } from '@core/models/user'; @Component({ selector: 'app-update-price', @@ -11,18 +12,28 @@ export class UpdatePriceComponent implements OnInit { @Input() fee: Fee; + @Input() + user: User; + get hasRoleAdmin(): boolean { + return this.user.authorities.includes('ADMIN'); + } @Output() updatePriceSubmitted: EventEmitter = new EventEmitter(); form: UntypedFormGroup; saved: boolean; - constructor(private fb: UntypedFormBuilder) {} + constructor(private fb: UntypedFormBuilder) { } ngOnInit(): void { this.form = this.fb.group({ id: new UntypedFormControl({ value: this.fee.id, disabled: true }, [Validators.required]), - priceHVat: new UntypedFormControl({ value: this.fee.priceHVAT, disabled: this.fee?.archived }, [Validators.required]), - vat: new UntypedFormControl({ value: this.fee.vat, disabled: this.fee?.archived }, [Validators.required]), + priceHVat: new UntypedFormControl( + { value: this.fee.priceHVAT, disabled: this.fee?.archived || !this.hasRoleAdmin }, + [Validators.required], + ), + vat: new UntypedFormControl({ value: this.fee.vat, disabled: this.fee?.archived || !this.hasRoleAdmin }, [ + Validators.required, + ]), priceTot: new UntypedFormControl({ value: this.fee.priceTot, disabled: true }, [Validators.required]), }); }