From 6dc7a4eb8402cdca615c1383be8ca41db919dc8f Mon Sep 17 00:00:00 2001 From: Nordine Bittich Date: Sat, 27 Jan 2024 22:43:55 +0100 Subject: [PATCH] fee page, table, labels --- .../default-price.component.html | 16 ++--- .../default-price/default-price.component.ts | 49 +++++++++++---- .../fee/fee-page/fee-page.component.html | 30 ++++------ .../fee/fee-page/fee-page.component.ts | 11 +++- .../fee-table-result.component.html | 60 ++++++------------- .../fee-table-result.component.ts | 7 ++- 6 files changed, 87 insertions(+), 86 deletions(-) diff --git a/src/app/features/fee/default-price/default-price.component.html b/src/app/features/fee/default-price/default-price.component.html index 9acc00a..66b52e1 100644 --- a/src/app/features/fee/default-price/default-price.component.html +++ b/src/app/features/fee/default-price/default-price.component.html @@ -4,7 +4,7 @@ label name. Duplicates label will be simply overriden
-
+
@@ -15,7 +15,7 @@ Label Price HVAT VAT - + @@ -29,14 +29,8 @@ - +
@@ -50,7 +44,7 @@
- + diff --git a/src/app/features/fee/default-price/default-price.component.ts b/src/app/features/fee/default-price/default-price.component.ts index a559d3e..35326aa 100644 --- a/src/app/features/fee/default-price/default-price.component.ts +++ b/src/app/features/fee/default-price/default-price.component.ts @@ -5,6 +5,7 @@ import { Label } from '@core/models/fee'; import { firstValueFrom, Observable } from 'rxjs'; import { LabelService } from '@core/service/label.service'; import { ToastService } from '@core/service/toast.service'; +import { User } from '@core/models/user'; @Component({ selector: 'app-default-price', @@ -14,12 +15,18 @@ import { ToastService } from '@core/service/toast.service'; export class DefaultPriceComponent implements OnInit { form: UntypedFormGroup; tags: Label[]; + @Input() + user: User; + + get hasRoleAdmin(): boolean { + return this.user.authorities.includes('ADMIN'); + } constructor( @Optional() public activeModal: NgbActiveModal, private labelService: LabelService, private toastService: ToastService, - private fb: UntypedFormBuilder - ) {} + private fb: UntypedFormBuilder, + ) { } async ngOnInit() { this.tags = await firstValueFrom(this.labelService.findAll()); @@ -27,8 +34,12 @@ export class DefaultPriceComponent implements OnInit { } loadForm() { + const defaultPrices = []; + for (const tag of this.tags.sort((a, b) => a.name.localeCompare(b.name))) { + defaultPrices.push(this.convertPrice(tag)); + } this.form = this.fb.group({ - defaultPrices: this.fb.array(this.tags.sort((a, b) => a.name.localeCompare(b.name)).map(this.convertPrice)), + defaultPrices: this.fb.array(defaultPrices), }); } @@ -38,18 +49,27 @@ export class DefaultPriceComponent implements OnInit { add($event: MouseEvent) { $event.preventDefault(); + if (!this.hasRoleAdmin) { + return; + } this.defaultPrices.push( this.convertPrice({ id: null, - }) + }), ); } remove($event: MouseEvent, idx: number) { $event.preventDefault(); + if (!this.hasRoleAdmin) { + return; + } this.defaultPrices.removeAt(idx); } canRemove(idx: number) { const group = this.defaultPrices.at(idx); + if (!this.hasRoleAdmin) { + return; + } return group.get('id').value?.length; } @@ -62,39 +82,42 @@ export class DefaultPriceComponent implements OnInit { colorHex: new UntypedFormControl( { value: price.colorHex, - disabled: false, + disabled: !this.hasRoleAdmin, }, - [Validators.required] + [Validators.required], ), tag: new UntypedFormControl( { value: price.name, - disabled: price.name?.length, + disabled: price.name?.length || !this.hasRoleAdmin, }, - [Validators.required] + [Validators.required], ), priceHVAT: new UntypedFormControl( { value: price.priceHVAT, - disabled: price.noDefaultPrice, + disabled: price.noDefaultPrice || !this.hasRoleAdmin, }, - [Validators.required] + [Validators.required], ), vat: new UntypedFormControl( { value: price.vat, - disabled: price.noDefaultPrice, + disabled: price.noDefaultPrice || !this.hasRoleAdmin, }, - [Validators.required] + [Validators.required], ), }); } - changeTextToUppercase(idx) { + changeTextToUppercase(idx: any) { const field = this.defaultPrices.at(idx).get('tag'); field.patchValue(field.value?.toUpperCase()); } async submit() { + if (!this.hasRoleAdmin) { + return; + } const labels = this.defaultPrices.controls?.map((p) => { return { id: p.get('id').value, diff --git a/src/app/features/fee/fee-page/fee-page.component.html b/src/app/features/fee/fee-page/fee-page.component.html index d827e22..4e5ce11 100644 --- a/src/app/features/fee/fee-page/fee-page.component.html +++ b/src/app/features/fee/fee-page/fee-page.component.html @@ -14,12 +14,10 @@

{{ title }}

Unprocessed
- -
- + +
+
@@ -28,13 +26,11 @@

{{ title }}

Processed
- + -
- +
+
@@ -43,13 +39,11 @@

{{ title }}

Labels
- + -
- +
+
diff --git a/src/app/features/fee/fee-page/fee-page.component.ts b/src/app/features/fee/fee-page/fee-page.component.ts index 0f2d3f0..02eb467 100644 --- a/src/app/features/fee/fee-page/fee-page.component.ts +++ b/src/app/features/fee/fee-page/fee-page.component.ts @@ -2,6 +2,8 @@ import { Component, HostListener, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { Title } from '@angular/platform-browser'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { PersonalInfoService } from '@core/service/personal.info.service'; +import { User } from '@core/models/user'; @Component({ selector: 'app-fee-page', @@ -11,6 +13,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; export class FeePageComponent implements OnInit { activeId: string; fullScreen: boolean; + user: User; @HostListener('document:keydown.escape', ['$event']) onKeydownHandler(event: KeyboardEvent) { if (!this.modalService.hasOpenModals()) { @@ -18,10 +21,16 @@ export class FeePageComponent implements OnInit { } } - constructor(public route: ActivatedRoute, private modalService: NgbModal, private titleService: Title) {} + constructor( + public route: ActivatedRoute, + private personalInfoService: PersonalInfoService, + private modalService: NgbModal, + private titleService: Title, + ) { } ngOnInit(): void { this.titleService.setTitle('Expenses'); this.activeId = this.route.snapshot.params.name || 'unprocessed'; + this.personalInfoService.me().subscribe((u) => (this.user = u)); } } 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 a66693e..e9804a6 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 @@ -6,7 +6,7 @@

Total Elements: {{ fees.totalElements }}

-
+
@@ -14,23 +14,16 @@ - -
@@ -52,16 +45,11 @@ Subject Date received Files - - - + + + @@ -78,26 +66,20 @@
{{ f.subject }} - - Imported on {{ f.importedDate | date : 'dd/MM/yyyy HH:mm' }} - -
- {{ f.date | date : 'dd/MM/yyyy HH:mm' }} + {{ f.date | date: 'dd/MM/yyyy HH:mm' }} {{ f.attachmentIds.length }} - + @@ -123,14 +105,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 3c61675..63b88d9 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 @@ -20,6 +20,7 @@ import { MailService } from '@core/service/mail.service'; import { MailFormComponent } from '@shared/mail-form/mail-form.component'; import { MailRequest } from '@core/models/mail'; import { ToastService } from '@core/service/toast.service'; +import { User } from '@core/models/user'; @Component({ selector: 'app-fee-table-result', @@ -32,7 +33,11 @@ export class FeeTableResultComponent implements OnInit, OnApplicationEvent { searchCriteria: FeeSearchCriteria; fees: Page; pageSize: number = 5; - + @Input() + user: User; + get hasRoleAdmin(): boolean { + return this.user.authorities.includes('ADMIN'); + } tags: Label[]; selectedRows: Fee[] = [];