Skip to content

Commit 15efc9f

Browse files
committed
BSAPP-1926 improve duplicate conflict handling in verein dialogs
1 parent a8bd22a commit 15efc9f

3 files changed

Lines changed: 47 additions & 4 deletions

File tree

bogenliga/src/app/modules/verwaltung/components/verein/verein-detail/mannschafts-detail/mannschaft-detail.component.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
8686
// maps the MannschaftsMitgliedDO with the DSBMitgliedId
8787
private currentMannschaftsMitglied: MannschaftsMitgliedDO = new MannschaftsMitgliedDO();
8888
private members: Map<number, MannschaftsMitgliedDO> = new Map<number, MannschaftsMitgliedDO>();
89+
private duplicateNotificationSubscription;
8990
private deleteNotification: Notification;
9091
private deleteSubscription;
9192
private dsbmitglied: DsbMitgliedDO = new DsbMitgliedDO();
@@ -137,6 +138,14 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
137138
}
138139
}
139140
});
141+
142+
this.duplicateNotificationSubscription = this.notificationService.observeNotification(NOTIFICATION_DUPLICATE_MANNSCHAFT)
143+
.subscribe((notification) => {
144+
if (notification.userAction === NotificationUserAction.ACCEPTED
145+
|| notification.userAction === NotificationUserAction.DECLINED) {
146+
this.saveLoading = false;
147+
}
148+
});
140149
}
141150

142151
/** When a MouseOver-Event is triggered, it will call this inMouseOver-function.
@@ -153,13 +162,17 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
153162

154163

155164
ngOnDestroy() {
165+
if (this.duplicateNotificationSubscription != null) {
166+
this.duplicateNotificationSubscription.unsubscribe();
167+
}
156168
if (this.deleteSubscription != null) {
157169
this.deleteSubscription.unsubscribe();
158170
}
159171
}
160172

161173

162174
public onSave(ignore: any) {
175+
this.notificationService.discardNotification();
163176
this.saveLoading = true;
164177
// persist
165178
this.currentMannschaft.vereinId = this.currentVerein.id; // Set selected verein id// set selected veranstaltung id
@@ -171,6 +184,7 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
171184
}
172185

173186
public onUpdate(ignore: any): void {
187+
this.notificationService.discardNotification();
174188
this.saveLoading = true;
175189

176190
// persist
@@ -711,6 +725,8 @@ export class MannschaftDetailComponent extends CommonComponentDirective implemen
711725
}
712726

713727
private showDuplicateMannschaftNotification(): void {
728+
this.notificationService.discardNotification();
729+
714730
const notification: Notification = {
715731
id: NOTIFICATION_DUPLICATE_MANNSCHAFT,
716732
title: 'MANAGEMENT.VEREIN_DETAIL.NOTIFICATION.DUPLICATE.TITLE',

bogenliga/src/app/modules/verwaltung/components/verein/verein-detail/verein-detail.component.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
1+
import {Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
22
import {ActivatedRoute, Router} from '@angular/router';
33
import {isNullOrUndefined, isUndefined} from '@shared/functions';
44
import {
@@ -56,14 +56,16 @@ const NOTIFICATION_COPY_MANNSCHAFT = 'mannschaft_detail_copy';
5656
const NOTIFICATION_DELETE_MANNSCHAFT_SUCCESS = 'mannschaft_detail_delete_success';
5757
const NOTIFICATION_DELETE_MANNSCHAFT_FAILURE = 'mannschaft_detail_delete_failure';
5858
const NOTIFICATION_NO_LICENSE = 'no_license_found';
59+
const NOTIFICATION_ENTITY_CONFLICT_ERROR = 'ENTITY_CONFLICT_ERROR';
60+
const NOTIFICATION_DATABASE_ERROR = 'DATABASE_ERROR';
5961
const PLATZHALTER_ID = 99;
6062

6163
@Component({
6264
selector: 'bla-verein-detail',
6365
templateUrl: './verein-detail.component.html',
6466
styleUrls: ['./verein-detail.component.scss']
6567
})
66-
export class VereinDetailComponent extends CommonComponentDirective implements OnInit {
68+
export class VereinDetailComponent extends CommonComponentDirective implements OnInit, OnDestroy {
6769
public regionType = 'KREIS';
6870
public config = VEREIN_DETAIL_CONFIG;
6971
public config_table = VEREIN_DETAIL_TABLE_CONFIG;
@@ -80,6 +82,7 @@ export class VereinDetailComponent extends CommonComponentDirective implements O
8082

8183

8284
private sessionHandling: SessionHandling;
85+
private saveErrorNotificationSubscriptions = [];
8386

8487
@ViewChild('downloadLink')
8588
private aElementRef: ElementRef;
@@ -103,9 +106,15 @@ export class VereinDetailComponent extends CommonComponentDirective implements O
103106
ngOnInit() {
104107
this.loading = true;
105108
this.notificationService.discardNotification();
109+
this.registerSaveErrorReset(NOTIFICATION_ENTITY_CONFLICT_ERROR);
110+
this.registerSaveErrorReset(NOTIFICATION_DATABASE_ERROR);
106111
this.loadRegions(this.regionType); // Request all regions from the backend
107112
}
108113

114+
ngOnDestroy() {
115+
this.saveErrorNotificationSubscriptions.forEach((subscription) => subscription.unsubscribe());
116+
}
117+
109118
/** When a MouseOver-Event is triggered, it will call this inMouseOver-function.
110119
* This function calls the checkSessionExpired-function in the sessionHandling class and get a boolean value back.
111120
* If the boolean value is true, then the page will be reloaded and due to the expired session, the user will
@@ -136,6 +145,7 @@ export class VereinDetailComponent extends CommonComponentDirective implements O
136145
}
137146

138147
public onSave(ignore: any): void {
148+
this.notificationService.discardNotification();
139149
this.saveLoading = true;
140150

141151
// persist
@@ -186,6 +196,7 @@ export class VereinDetailComponent extends CommonComponentDirective implements O
186196
}
187197

188198
public onUpdate(ignore: any): void {
199+
this.notificationService.discardNotification();
189200
this.saveLoading = true;
190201

191202
// persist
@@ -618,6 +629,18 @@ export class VereinDetailComponent extends CommonComponentDirective implements O
618629
this.loading = false;
619630
}
620631

632+
private registerSaveErrorReset(notificationId: string): void {
633+
const subscription = this.notificationService.observeNotification(notificationId)
634+
.subscribe((notification) => {
635+
if (notification.userAction === NotificationUserAction.ACCEPTED
636+
|| notification.userAction === NotificationUserAction.DECLINED) {
637+
this.saveLoading = false;
638+
}
639+
});
640+
641+
this.saveErrorNotificationSubscriptions.push(subscription);
642+
}
643+
621644
private loadMannschaften() {
622645
this.loading = true;
623646
this.mannschaftsDataProvider.findAllByVereinsId(this.currentVerein.id)

bogenliga/src/assets/i18n/de.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,8 @@
10481048
"DESCRIPTION": "Verein wurde erfolgreich gespeichert."
10491049
},
10501050
"DUPLICATE": {
1051-
"TITLE": "Mannschaftsnummer in dem Verein bereits vergeben!",
1052-
"DESCRIPTION": "Möchten sie die Mannschaft trotzdem hinzufügen?"
1051+
"TITLE": "Doppelte Mannschaft",
1052+
"DESCRIPTION": "Die Mannschaftsnummer ist in diesem Verein bereits vergeben. Bitte wählen Sie eine andere Nummer."
10531053
},
10541054
"SAVE_FAILURE": {
10551055
"TITLE": "Fehler beim Aktualisieren",
@@ -1902,6 +1902,10 @@
19021902
"TITLE": "Datenbankfehler",
19031903
"DESCRIPTION": "Ihre Anfrage wurde von der Datenbank abgewiesen."
19041904
},
1905+
"ENTITY_CONFLICT_ERROR": {
1906+
"TITLE": "Doppelte Eingabe",
1907+
"DESCRIPTION": "Ein Eintrag mit diesen Werten existiert bereits. Bitte prüfen Sie Ihre Eingaben."
1908+
},
19051909
"ENTITY_NOT_FOUND_ERROR": {
19061910
"TITLE": "Nicht gefunden",
19071911
"DESCRIPTION": "Die angeforderte Resource wurde nicht gefunden."

0 commit comments

Comments
 (0)