Skip to content

Commit

Permalink
delete current repertoire
Browse files Browse the repository at this point in the history
  • Loading branch information
hwellmann committed Feb 25, 2024
1 parent 68f22cf commit 530ed02
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/component/repertoire/repertoire.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ <h2 class="mat-h2">{{currentRepertoire ? currentRepertoire.name + ' ': ''}}Reper
<button mat-menu-item *ngFor="let rep of repertoires()"
(click)="selectRepertoire(rep)">{{rep.name}}</button>
<button mat-menu-item (click)="openNewRepertoireDialog()">New repertoire</button>
<button mat-menu-item (click)="openDeleteRepertoireDialog()">Delete current repertoire</button>
</mat-menu>
</div>

Expand Down
13 changes: 13 additions & 0 deletions src/app/component/repertoire/repertoire.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ export class RepertoireComponent implements OnInit {
dialogRef.afterClosed().subscribe(added => this.newRepertoire(added));
}

openDeleteRepertoireDialog(): void {
const dialogRef = this.dialog.open(DeleteRepertoireItemComponent, { data: `Delete "${this.currentRepertoire.name}" repertoire?` });
dialogRef.afterClosed().subscribe(confirmed => {
if (confirmed) {
this.deleteCurrentRepertoire();
}
});
}
selectRepertoire(repertoire: Repertoire): void {
this.currentRepertoire = repertoire;
this.prepareTunes();
Expand All @@ -84,6 +92,11 @@ export class RepertoireComponent implements OnInit {
this.prepareTunes();
}

private async deleteCurrentRepertoire(): Promise<void> {
await this.repertoireRepository.deleteRepertoire(this.currentRepertoire.name);
await this.loadRepertoire();
}

private async loadRepertoire() {
this.repertoireCollection = await this.repertoireRepository.load();
const rep = await this.repertoireRepository.findRepertoire();
Expand Down
15 changes: 15 additions & 0 deletions src/app/service/repertoire-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,19 @@ export class RepertoireRepository {
? collection.repertoires.find(r => r.name === name)
: collection.repertoires[0];
}

/**
* Finds the repertoire with the given identity.
* @param name repertoire name
* @return file ID of updated repertoire file, or empty string
*/
async deleteRepertoire(name: string): Promise<String> {
const collection = await this.load();
const index = collection.repertoires.findIndex(r => r.name === name);
if (index == -1) {
return "";
}
collection.repertoires.splice(index, 1);
return this.saveCollection(collection);
}
}

0 comments on commit 530ed02

Please sign in to comment.