better song sorting
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import {Component, Input, OnInit} from '@angular/core';
|
||||
import {Song} from '../../../songs/services/song';
|
||||
import {faTrash} from '@fortawesome/free-solid-svg-icons/faTrash';
|
||||
import {faCaretUp} from '@fortawesome/free-solid-svg-icons/faCaretUp';
|
||||
import {faCaretDown} from '@fortawesome/free-solid-svg-icons/faCaretDown';
|
||||
@@ -17,8 +16,6 @@ import {Show} from '../../services/show';
|
||||
})
|
||||
export class SongComponent implements OnInit {
|
||||
@Input() public show: Show | null = null;
|
||||
@Input() public showSong: ShowSong | null = null;
|
||||
@Input() public showSongs: ShowSong[] | null = null;
|
||||
@Input() public showId: string | null = null;
|
||||
@Input() public showText: boolean | null = null;
|
||||
|
||||
@@ -27,77 +24,77 @@ export class SongComponent implements OnInit {
|
||||
public faUp = faCaretUp;
|
||||
public faDown = faCaretDown;
|
||||
public keyFormControl: FormControl = new FormControl();
|
||||
public iSong: Song | null = null;
|
||||
public iSong: ShowSong | null = null;
|
||||
|
||||
public constructor(private showSongService: ShowSongService) {}
|
||||
|
||||
@Input()
|
||||
public set Song(song: Song) {
|
||||
public set showSong(song: ShowSong) {
|
||||
this.iSong = song;
|
||||
this.keys = song ? getScale(song.key) : [];
|
||||
}
|
||||
|
||||
public ngOnInit(): void {
|
||||
if (!this.showSong) return;
|
||||
this.keyFormControl = new FormControl(this.showSong.key);
|
||||
if (!this.iSong) return;
|
||||
this.keyFormControl = new FormControl(this.iSong.key);
|
||||
this.keyFormControl.valueChanges.subscribe((value: string) => {
|
||||
if (!this.showId || !this.showSong) return;
|
||||
void this.showSongService.update$(this.showId, this.showSong.id, {key: value});
|
||||
if (!this.showId || !this.iSong) return;
|
||||
void this.showSongService.update$(this.showId, this.iSong.id, {key: value});
|
||||
});
|
||||
}
|
||||
|
||||
public async onDelete(): Promise<void> {
|
||||
if (!this.showId || !this.showSong) return;
|
||||
await this.showSongService.delete$(this.showId, this.showSong.id);
|
||||
if (!this.showId || !this.iSong) return;
|
||||
await this.showSongService.delete$(this.showId, this.iSong.id);
|
||||
}
|
||||
|
||||
public async reorder(up: boolean): Promise<void> {
|
||||
if (up) {
|
||||
await this.reorderUp();
|
||||
} else {
|
||||
await this.reorderDown();
|
||||
}
|
||||
}
|
||||
|
||||
public async reorderUp(): Promise<void> {
|
||||
if (!this.showSongs || !this.showId) return;
|
||||
const index = this.showSongs.findIndex(_ => _.songId === this.iSong?.id);
|
||||
if (index === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const song = this.showSongs[index];
|
||||
const toggleSong = this.showSongs[index - 1];
|
||||
|
||||
await this.showSongService.update$(this.showId, song.id, {
|
||||
order: toggleSong.order,
|
||||
});
|
||||
await this.showSongService.update$(this.showId, toggleSong.id, {
|
||||
order: song.order,
|
||||
});
|
||||
}
|
||||
|
||||
public async reorderDown(): Promise<void> {
|
||||
if (!this.showSongs || !this.showId) return;
|
||||
const index = this.showSongs.findIndex(_ => _.songId === this.iSong?.id);
|
||||
if (index === this.showSongs.length - 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const song = this.showSongs[index];
|
||||
const toggleSong = this.showSongs[index + 1];
|
||||
|
||||
await this.showSongService.update$(this.showId, song.id, {
|
||||
order: toggleSong.order,
|
||||
});
|
||||
await this.showSongService.update$(this.showId, toggleSong.id, {
|
||||
order: song.order,
|
||||
});
|
||||
}
|
||||
// public async reorder(up: boolean): Promise<void> {
|
||||
// if (up) {
|
||||
// await this.reorderUp();
|
||||
// } else {
|
||||
// await this.reorderDown();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public async reorderUp(): Promise<void> {
|
||||
// if (!this.showSongs || !this.showId) return;
|
||||
// const index = this.showSongs.findIndex(_ => _.songId === this.iSong?.id);
|
||||
// if (index === 0) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// const song = this.showSongs[index];
|
||||
// const toggleSong = this.showSongs[index - 1];
|
||||
//
|
||||
// await this.showSongService.update$(this.showId, song.id, {
|
||||
// order: toggleSong.order,
|
||||
// });
|
||||
// await this.showSongService.update$(this.showId, toggleSong.id, {
|
||||
// order: song.order,
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// public async reorderDown(): Promise<void> {
|
||||
// if (!this.showSongs || !this.showId) return;
|
||||
// const index = this.showSongs.findIndex(_ => _.songId === this.iSong?.id);
|
||||
// if (index === this.showSongs.length - 1) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// const song = this.showSongs[index];
|
||||
// const toggleSong = this.showSongs[index + 1];
|
||||
//
|
||||
// await this.showSongService.update$(this.showId, song.id, {
|
||||
// order: toggleSong.order,
|
||||
// });
|
||||
// await this.showSongService.update$(this.showId, toggleSong.id, {
|
||||
// order: song.order,
|
||||
// });
|
||||
// }
|
||||
|
||||
public async onChordModeChanged(value: ChordMode): Promise<void> {
|
||||
if (!this.showId || !this.showSong) return;
|
||||
await this.showSongService.update$(this.showId, this.showSong.id, {
|
||||
if (!this.showId || !this.iSong) return;
|
||||
await this.showSongService.update$(this.showId, this.iSong.id, {
|
||||
chordMode: value,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user