feat(umpires): move umpires between any lists
This commit is contained in:
@@ -45,4 +45,17 @@ export class CourtServiceJudgeService {
|
||||
async delete(id: number): Promise<void> {
|
||||
await db.courtServiceJudges.delete(id);
|
||||
}
|
||||
|
||||
async removeByUmpireId(umpireId: number): Promise<void> {
|
||||
const item = await db.courtServiceJudges
|
||||
.where('umpireId')
|
||||
.equals(umpireId)
|
||||
.first();
|
||||
|
||||
if (!item?.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
await db.courtServiceJudges.delete(item.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,9 +35,8 @@
|
||||
cdkDropList
|
||||
[id]="`court-umpire-${$index + 1}`"
|
||||
cdkDropListSortingDisabled
|
||||
[cdkDropListData]="waitingServiceJudges()"
|
||||
(cdkDropListDropped)="dropToUmpire($event, $index + 1)"
|
||||
[cdkDropListConnectedTo]="['list-on-rest', 'list-waiting-umpires']">
|
||||
[cdkDropListData]="courtUmpires()"
|
||||
(cdkDropListDropped)="dropToUmpire($event, $index + 1)">
|
||||
@if (umpireByCourt().get($index + 1); as umpire) {
|
||||
|
||||
<ion-item cdkDrag [cdkDragData]="umpire">
|
||||
@@ -48,7 +47,21 @@
|
||||
</ion-list>
|
||||
</ion-col>
|
||||
<ion-col>
|
||||
<ion-item [lines]="'none'"> aaa </ion-item>
|
||||
<ion-list
|
||||
[lines]="'none'"
|
||||
cdkDropList
|
||||
[id]="`court-service-judge-${$index + 1}`"
|
||||
cdkDropListSortingDisabled
|
||||
[cdkDropListData]="courtServiceJudges()"
|
||||
(cdkDropListDropped)="dropToServiceJudge($event, $index + 1)">
|
||||
@if (serviceJudgeByCourt().get($index + 1); as umpire) {
|
||||
|
||||
<ion-item cdkDrag [cdkDragData]="umpire">
|
||||
<ion-label>{{ umpire | fullname }}</ion-label>
|
||||
</ion-item>
|
||||
|
||||
}
|
||||
</ion-list>
|
||||
</ion-col>
|
||||
</ion-row>
|
||||
}
|
||||
|
||||
+28
-27
@@ -261,18 +261,7 @@ export class Tab1Page {
|
||||
} else {
|
||||
const comingFrom = event.previousContainer.id;
|
||||
const umpireToMove = event.item.data;
|
||||
if ('list-waiting-service-judges' === comingFrom) {
|
||||
// Remove from waiting service judges
|
||||
this.waitingServiceJudgeService.removeByUmpireId(umpireToMove.id);
|
||||
}
|
||||
|
||||
if ('list-waiting-umpires' === comingFrom) {
|
||||
this.waitingUmpireService.removeByUmpireId(umpireToMove.id);
|
||||
}
|
||||
|
||||
if (comingFrom.startsWith('court-umpire')) {
|
||||
this.courtUmpireService.removeByUmpireId(umpireToMove.id);
|
||||
}
|
||||
this.removeFromOriginalPlace(umpireToMove, comingFrom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,13 +273,7 @@ export class Tab1Page {
|
||||
const umpireToMove = event.item.data;
|
||||
this.waitingServiceJudgeService.add(umpireToMove.id);
|
||||
|
||||
if ('list-waiting-umpires' === comingFrom) {
|
||||
this.waitingUmpireService.removeByUmpireId(umpireToMove.id);
|
||||
}
|
||||
|
||||
if (comingFrom.startsWith('court-umpire')) {
|
||||
this.courtUmpireService.removeByUmpireId(umpireToMove.id);
|
||||
}
|
||||
this.removeFromOriginalPlace(umpireToMove, comingFrom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,14 +291,7 @@ export class Tab1Page {
|
||||
const umpireToMove = event.item.data;
|
||||
this.waitingUmpireService.add(umpireToMove.id);
|
||||
|
||||
if ('list-waiting-service-judges' === comingFrom) {
|
||||
// Remove from waiting service judges
|
||||
this.waitingServiceJudgeService.removeByUmpireId(umpireToMove.id);
|
||||
}
|
||||
|
||||
if (comingFrom.startsWith('court-umpire')) {
|
||||
this.courtUmpireService.removeByUmpireId(umpireToMove.id);
|
||||
}
|
||||
this.removeFromOriginalPlace(umpireToMove, comingFrom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,6 +302,23 @@ export class Tab1Page {
|
||||
const umpireToMove = event.item.data;
|
||||
this.courtUmpireService.save({ umpireId: umpireToMove.id, courtNo });
|
||||
|
||||
this.removeFromOriginalPlace(umpireToMove, comingFrom);
|
||||
}
|
||||
|
||||
dropToServiceJudge(event: CdkDragDrop<Umpire[]>, courtNo: number) {
|
||||
// TODO: stop dropping if there is already another umpire
|
||||
|
||||
const comingFrom = event.previousContainer.id;
|
||||
const umpireToMove = event.item.data;
|
||||
this.courtServiceJudgeService.save({ umpireId: umpireToMove.id, courtNo });
|
||||
|
||||
this.removeFromOriginalPlace(umpireToMove, comingFrom);
|
||||
}
|
||||
|
||||
private removeFromOriginalPlace(
|
||||
umpireToMove: Umpire,
|
||||
comingFrom: string
|
||||
): void {
|
||||
if ('list-waiting-service-judges' === comingFrom) {
|
||||
this.waitingServiceJudgeService.removeByUmpireId(umpireToMove.id);
|
||||
}
|
||||
@@ -333,5 +326,13 @@ export class Tab1Page {
|
||||
if ('list-waiting-umpires' === comingFrom) {
|
||||
this.waitingUmpireService.removeByUmpireId(umpireToMove.id);
|
||||
}
|
||||
|
||||
if (comingFrom.startsWith('court-umpire')) {
|
||||
this.courtUmpireService.removeByUmpireId(umpireToMove.id);
|
||||
}
|
||||
|
||||
if (comingFrom.startsWith('court-service-judge')) {
|
||||
this.courtServiceJudgeService.removeByUmpireId(umpireToMove.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user