delete song
This commit is contained in:
@@ -15,6 +15,8 @@ export class SongDataService {
|
|||||||
public list$ = (): Observable<Song[]> => this.dbService.col$(this.collection);
|
public list$ = (): Observable<Song[]> => this.dbService.col$(this.collection);
|
||||||
public read$ = (songId: string): Observable<Song | undefined> => this.dbService.doc$(this.collection + '/' + songId);
|
public read$ = (songId: string): Observable<Song | undefined> => this.dbService.doc$(this.collection + '/' + songId);
|
||||||
public update$ = async (songId: string, data: Partial<Song>): Promise<void> => await this.dbService.doc(this.collection + '/' + songId).update(data);
|
public update$ = async (songId: string, data: Partial<Song>): Promise<void> => await this.dbService.doc(this.collection + '/' + songId).update(data);
|
||||||
public add = async (data: Partial<Song>): Promise<string> => (await this.dbService.col(this.collection).add(data)).id
|
public add = async (data: Partial<Song>): Promise<string> => (await this.dbService.col(this.collection).add(data)).id;
|
||||||
|
public delete = async (songId: string): Promise<void> => await this.dbService.doc(this.collection + '/' + songId).delete();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ export class SongService {
|
|||||||
public static LEGAL_OWNER = ['CCLI', 'other'];
|
public static LEGAL_OWNER = ['CCLI', 'other'];
|
||||||
public static LEGAL_TYPE = ['open', 'allowed'];
|
public static LEGAL_TYPE = ['open', 'allowed'];
|
||||||
|
|
||||||
|
|
||||||
private list: Song[];
|
private list: Song[];
|
||||||
|
|
||||||
constructor(private songDataService: SongDataService) {
|
constructor(private songDataService: SongDataService) {
|
||||||
@@ -36,6 +35,10 @@ export class SongService {
|
|||||||
return await this.songDataService.add({number, title, status: 'draft', legalType: 'open'})
|
return await this.songDataService.add({number, title, status: 'draft', legalType: 'open'})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async delete(songId: string): Promise<void> {
|
||||||
|
await this.songDataService.delete(songId);
|
||||||
|
}
|
||||||
|
|
||||||
// https://www.csvjson.com/csv2json
|
// https://www.csvjson.com/csv2json
|
||||||
private async updateFromCLI(songs: Song[]) {
|
private async updateFromCLI(songs: Song[]) {
|
||||||
const mapped = songs.map(_ => ({
|
const mapped = songs.map(_ => ({
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<app-button-row>
|
<app-button-row>
|
||||||
|
<app-button (click)="onDelete(song.id)" *appRole="['admin']" [icon]="faDelete">Löschen</app-button>
|
||||||
<app-button *appRole="['contributor']" [icon]="faEdit" routerLink="edit">Bearbeiten</app-button>
|
<app-button *appRole="['contributor']" [icon]="faEdit" routerLink="edit">Bearbeiten</app-button>
|
||||||
</app-button-row>
|
</app-button-row>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {Component, OnInit} from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import {ActivatedRoute} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import {SongService} from '../services/song.service';
|
import {SongService} from '../services/song.service';
|
||||||
import {map, switchMap} from 'rxjs/operators';
|
import {map, switchMap} from 'rxjs/operators';
|
||||||
import {Song} from '../services/song';
|
import {Song} from '../services/song';
|
||||||
@@ -9,6 +9,7 @@ import {File} from '../services/file';
|
|||||||
import {UserService} from '../../../services/user/user.service';
|
import {UserService} from '../../../services/user/user.service';
|
||||||
import {User} from '../../../services/user/user';
|
import {User} from '../../../services/user/user';
|
||||||
import {faEdit} from '@fortawesome/free-solid-svg-icons/faEdit';
|
import {faEdit} from '@fortawesome/free-solid-svg-icons/faEdit';
|
||||||
|
import {faTrash} from '@fortawesome/free-solid-svg-icons/faTrash';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-song',
|
selector: 'app-song',
|
||||||
@@ -20,12 +21,14 @@ export class SongComponent implements OnInit {
|
|||||||
public files$: Observable<File[]>;
|
public files$: Observable<File[]>;
|
||||||
public user$: Observable<User>;
|
public user$: Observable<User>;
|
||||||
public faEdit = faEdit;
|
public faEdit = faEdit;
|
||||||
|
public faDelete = faTrash;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private activatedRoute: ActivatedRoute,
|
private activatedRoute: ActivatedRoute,
|
||||||
private songService: SongService,
|
private songService: SongService,
|
||||||
private fileService: FileDataService,
|
private fileService: FileDataService,
|
||||||
private userService: UserService,
|
private userService: UserService,
|
||||||
|
private router: Router,
|
||||||
) {
|
) {
|
||||||
this.user$ = userService.user$;
|
this.user$ = userService.user$;
|
||||||
}
|
}
|
||||||
@@ -40,7 +43,6 @@ export class SongComponent implements OnInit {
|
|||||||
map(param => param.songId),
|
map(param => param.songId),
|
||||||
switchMap(songId => this.fileService.read$(songId))
|
switchMap(songId => this.fileService.read$(songId))
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getFlags = (flags: string): string[] => {
|
public getFlags = (flags: string): string[] => {
|
||||||
@@ -48,4 +50,8 @@ export class SongComponent implements OnInit {
|
|||||||
return flags.split(';').filter(_ => !!_);
|
return flags.split(';').filter(_ => !!_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public async onDelete(songId: string): Promise<void> {
|
||||||
|
await this.songService.delete(songId);
|
||||||
|
await this.router.navigateByUrl('/songs');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user