Skip to content

Commit

Permalink
deletion button shows only to admin-role + hint for non-admins
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangroese committed Aug 11, 2024
1 parent 4ff44ba commit e9a08ba
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 29 deletions.
4 changes: 4 additions & 0 deletions src/app/features/appointments/appointments.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { OverlayPanelModule } from 'primeng/overlaypanel';
import { RippleModule } from 'primeng/ripple';
import { TabViewModule } from 'primeng/tabview';
import { ChartModule } from '@arpa/components';
import { MessageModule } from 'primeng/message';
import { ChipModule } from 'primeng/chip';

@NgModule({
declarations: [AppointmentsComponent, EditAppointmentComponent],
Expand Down Expand Up @@ -56,6 +58,8 @@ import { ChartModule } from '@arpa/components';
RippleModule,
TabViewModule,
ChartModule,
MessageModule,
ChipModule,
],
providers: [
AppointmentCategoryListResolver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,27 +315,37 @@ <h4 class="appointment-title">
</div>
<div style="display: flex; justify-content: center; margin-bottom: 2rem">
<button
[label]="getSendNotificationLabel()"
[pTooltip]="'appointments.SEND_NOTIFICATION_TOOLTIP' | translate"
*ngIf="!isNew && formGroup.pristine"
type="button"
(click)="onSendNotification($event)"
[label]="getSendNotificationLabel()"
[pTooltip]="'appointments.SEND_NOTIFICATION_TOOLTIP' | translate"
pButton
class="p-button-outlined p-button-warning p-mr-3"
type="button"
class="p-button-warning p-mr-3"
icon="pi pi-envelope"
></button>
</div>

<button
*ngIf="hasAdminRole()"
(click)="showDeleteConfirmation($event)"
[label]="'DELETE' | translate"
class="ml-3 p-button-danger"
icon="pi pi-trash"
iconPos="left"
pButton
type="button"
></button>
<div style="display: flex; justify-content: center; margin-bottom: 2rem">
<button
*ngIf="hasAdminRole()"
type="button"
(click)="showDeleteConfirmation($event)"
[label]="'DELETE' | translate"
class="p-button-danger p-mr-3"
icon="pi pi-trash"
iconPos="left"
pButton
></button>
<button
*ngIf="!hasAdminRole()"
type="button"
class="p-button-text p-mr-3"
[label]="'appointments.DELETION_HINT' | translate"
pButton
icon="pi pi-info-circle"
iconPos="left"
></button>
</div>
</div>
</p-tabPanel>
<p-tabPanel header="{{ 'appointments.PARTICIPATIONS' | translate }}" [disabled]="isNew">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ th {
}
}
}
.p-col-12.p-d-flex.p-jc-between.p-mt-3 {
@media screen and (max-width: 768px) {
flex-direction: column;
align-items: center;
}
}
.project-title {
color: var(--primary-color);
font-weight: lighter;
color: var(--secondary-color);
font-weight: 500;
font-size: small;
text-align: center;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { AppointmentService } from '@arpa/services';
import { first, map } from 'rxjs/operators';
import { of, zip } from 'rxjs';
import { Table } from 'primeng/table';
import { AuthService } from '@arpa/services';

class ParticipationTableItem {
givenName: string;
Expand Down Expand Up @@ -113,6 +114,7 @@ export class EditAppointmentComponent implements OnInit {
private appointmentService: AppointmentService,
private formBuilder: UntypedFormBuilder,
private translate: TranslateService,
private authService: AuthService,
private confirmationService: ConfirmationService,
private selectValueService: SelectValueService,
private enumService: EnumService,
Expand All @@ -128,7 +130,10 @@ export class EditAppointmentComponent implements OnInit {
ngOnInit(): void {
this.createForm();
this.loadData();
this.loadCurrentUser();
this.authService.currentUser.subscribe((user) => {
this.currentUser = user;
});

this.columns = [
{ field: 'surname', header: this.translate.instant('SURNAME'), width: '20%' },
{ field: 'givenName', header: this.translate.instant('GIVENNAME'), width: '20%' },
Expand Down Expand Up @@ -225,7 +230,9 @@ export class EditAppointmentComponent implements OnInit {
this.loadAppointmentParticipations();
});
}

hasAdminRole(): boolean {
return this.currentUser?.roles.includes('admin');
}
private calculateTotalParticipationCount() {
this.totalParticipationCount = this.appointment.participations?.length || 0;
}
Expand Down Expand Up @@ -603,14 +610,6 @@ export class EditAppointmentComponent implements OnInit {
});
}

private loadCurrentUser(): void {
this.currentUser = { roles: ['admin'] };
}

hasAdminRole(): boolean {
return this.currentUser?.roles?.includes('admin');
}

private deleteAppointment(): void {
this.appointmentService.delete(this.appointment.id).subscribe(() => {
this.notificationsService.success('appointments.APPOINTMENT_DELETED');
Expand Down
5 changes: 3 additions & 2 deletions src/assets/i18n/appointments/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"APPOINTMENT_DETAILS": "Termindetails",
"CATEGORY": "Kategorie",
"CREATE": "Termin erstellen",
"DELETION_HINT": "Nur Admins können Termine löschen",
"DETAILSINTERNAL": "Interne Details",
"DETAILSPUBLIC": "Öffentliche Details",
"DOWNLOAD_APPOINTMENTS": "Termine herunterladen",
Expand Down Expand Up @@ -47,8 +48,8 @@
"SECTION_ADDED": "Register hinzugefügt",
"SECTION_REMOVED": "Register entfernt",
"SELECT_PREDICTION": "Vorhersage wählen",
"SEND_NOTIFICATION": "E-Mail-Benachrichtigung senden",
"SEND_NOTIFICATION_TOOLTIP": "Eine E-Mail-Benachrichtigung über die Änderung dieses Termins an alle Teilnehmer senden",
"SEND_NOTIFICATION": "Benachrichtigung senden",
"SEND_NOTIFICATION_TOOLTIP": "Achtung: ALLE Teilnehmer erhalten eine E-Mail mit den aktuellen Termindetails",
"START": "Beginn",
"STATUS": "Status",
"TARGET_AUDIENCE": "Zielgruppe",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/appointments/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"APPOINTMENT_DETAILS": "Appointment details",
"CATEGORY": "Category",
"CREATE": "Create an appointment",
"DELETION_HINT": "Only admins can delete appointments",
"DETAILSINTERNAL": "Internal Details",
"DETAILSPUBLIC": "Public Details",
"DOWNLOAD_APPOINTMENTS": "Download appointments",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/appointments/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"APPOINTMENT_DETAILS": "Détails de l'événement",
"CATEGORY": "Catégorie",
"CREATE": "Créer un nouvel événement",
"DELETION_HINT": "Seuls les administrateurs peuvent supprimer des événements",
"DETAILSINTERNAL": "Détails privés",
"DETAILSPUBLIC": "Détails publics",
"DOWNLOAD_APPOINTMENTS": "Télécharger les rendez-vous",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/appointments/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"APPOINTMENT_DETAILS": "Detalhes do evento",
"CATEGORY": "Categoria",
"CREATE": "Criar evento",
"DELETION_HINT": "Apenas os administradores podem apagar eventos",
"DETAILSINTERNAL": "Detalhes privados",
"DETAILSPUBLIC": "Detalhes públicos",
"DOWNLOAD_APPOINTMENTS": "Descarregar eventos",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/appointments/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"APPOINTMENT_DETAILS": "Детали назначения",
"CATEGORY": "Категория",
"CREATE": "Назначить встречу",
"DELETION_HINT": "Только администраторы могут удалять назначения",
"DETAILSINTERNAL": "Внутренние детали",
"DETAILSPUBLIC": "Публичные подробности",
"DOWNLOAD_APPOINTMENTS": "Загрузить даты",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/appointments/ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"APPOINTMENT_DETAILS": "Деталі зустрічі",
"CATEGORY": "Категорія",
"CREATE": "Створити зустріч",
"DELETION_HINT": "Тільки адміністратори можуть видаляти зустрічі",
"DETAILSINTERNAL": "Внутрішні деталі",
"DETAILSPUBLIC": "Публічна інформація",
"DOWNLOAD_APPOINTMENTS": "Завантажити зустрічі",
Expand Down

0 comments on commit e9a08ba

Please sign in to comment.