bugfixing
This commit is contained in:
@@ -21,7 +21,7 @@ export class FileService {
|
||||
|
||||
public async delete(path: string, songId: string, fileId: string) {
|
||||
const ref = this.storage.ref(path);
|
||||
await ref.delete().toPromise()
|
||||
await ref.delete().toPromise();
|
||||
await this.fileDataService.delete(songId, fileId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +34,12 @@ export class SongService {
|
||||
const song = await this.read(songId);
|
||||
const edits = song.edits ?? [];
|
||||
const user = await this.userService.currentUser();
|
||||
edits.push({username: user.name, timestamp: Timestamp.now()})
|
||||
edits.push({username: user.name, timestamp: Timestamp.now()});
|
||||
await this.songDataService.update$(songId, {...data, edits});
|
||||
}
|
||||
|
||||
public async new(number: number, title: string): Promise<string> {
|
||||
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> {
|
||||
|
||||
@@ -90,7 +90,7 @@ Cool bridge without any chords
|
||||
const service: TextRenderingService = TestBed.inject(TextRenderingService);
|
||||
const text = `Strophe
|
||||
g# F# E g# F# E
|
||||
text`
|
||||
text`;
|
||||
const sections = service.parse(text, null);
|
||||
expect(sections[0].lines[0].type).toBe(LineType.chord);
|
||||
expect(sections[0].lines[0].text).toBe('g# F# E g# F# E');
|
||||
|
||||
@@ -17,7 +17,9 @@ export class TextRenderingService {
|
||||
}
|
||||
|
||||
public parse(text: string, transpose: TransposeMode): Section[] {
|
||||
if (!text) return [];
|
||||
if (!text) {
|
||||
return [];
|
||||
}
|
||||
const arrayOfLines = text.split(/\r?\n/).filter(_ => _);
|
||||
const indices = {
|
||||
[SectionType.Bridge]: 0,
|
||||
@@ -26,18 +28,22 @@ export class TextRenderingService {
|
||||
};
|
||||
return arrayOfLines.reduce((array, line) => {
|
||||
const type = this.getSectionTypeOfLine(line);
|
||||
if (line.match(this.regexSection)) return [...array, {
|
||||
type: type,
|
||||
number: indices[type]++,
|
||||
lines: []
|
||||
}];
|
||||
if (line.match(this.regexSection)) {
|
||||
return [...array, {
|
||||
type,
|
||||
number: indices[type]++,
|
||||
lines: []
|
||||
}];
|
||||
}
|
||||
array[array.length - 1].lines.push(this.getLineOfLineText(line, transpose));
|
||||
return array;
|
||||
}, [] as Section[]);
|
||||
}
|
||||
|
||||
private getLineOfLineText(text: string, transpose: TransposeMode): Line {
|
||||
if (!text) return null;
|
||||
if (!text) {
|
||||
return null;
|
||||
}
|
||||
const cords = this.readChords(text);
|
||||
const hasMatches = cords.length > 0;
|
||||
const type = hasMatches ? LineType.chord : LineType.text;
|
||||
@@ -49,16 +55,20 @@ export class TextRenderingService {
|
||||
}
|
||||
|
||||
private getSectionTypeOfLine(line: string): SectionType {
|
||||
if (!line) return null;
|
||||
if (!line) {
|
||||
return null;
|
||||
}
|
||||
const match = line.match(this.regexSection);
|
||||
if (!match || match.length < 2) return null;
|
||||
if (!match || match.length < 2) {
|
||||
return null;
|
||||
}
|
||||
const typeString = match[1];
|
||||
switch (typeString) {
|
||||
case "Strophe":
|
||||
case 'Strophe':
|
||||
return SectionType.Verse;
|
||||
case "Refrain":
|
||||
case 'Refrain':
|
||||
return SectionType.Chorus;
|
||||
case "Bridge":
|
||||
case 'Bridge':
|
||||
return SectionType.Bridge;
|
||||
}
|
||||
}
|
||||
@@ -76,14 +86,18 @@ export class TextRenderingService {
|
||||
length: match[0].length,
|
||||
position: regex.lastIndex - match[0].length,
|
||||
};
|
||||
if (match[3]) chord.slashChord = match[3];
|
||||
if (match[4]) chord.add = match[4];
|
||||
if (match[3]) {
|
||||
chord.slashChord = match[3];
|
||||
}
|
||||
if (match[4]) {
|
||||
chord.add = match[4];
|
||||
}
|
||||
|
||||
chords.push(chord);
|
||||
}
|
||||
|
||||
const chordCount = chords.reduce((acc: number, cur: Chord) => acc + cur.length, 0);
|
||||
const lineCount = chordLine.replace(/\s/g, "").length;
|
||||
const lineCount = chordLine.replace(/\s/g, '').length;
|
||||
const isChrod = chordCount * 1.2 > lineCount;
|
||||
return isChrod ? chords : [];
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface TransposeMode {
|
||||
baseKey: string;
|
||||
targetKey: string
|
||||
targetKey: string;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,9 @@ import {Line} from './line';
|
||||
export class TransposeService {
|
||||
|
||||
public transpose(line: Line, baseKey: string, targetKey: string): Line {
|
||||
if (line.type !== LineType.chord) return line;
|
||||
if (line.type !== LineType.chord) {
|
||||
return line;
|
||||
}
|
||||
const difference = this.getDistance(baseKey, targetKey);
|
||||
const map = this.getMap(baseKey, difference);
|
||||
|
||||
@@ -21,7 +23,9 @@ export class TransposeService {
|
||||
}
|
||||
|
||||
public renderChords(line: Line): Line {
|
||||
if (line.type !== LineType.chord) return line;
|
||||
if (line.type !== LineType.chord) {
|
||||
return line;
|
||||
}
|
||||
|
||||
const renderedLine = this.renderLine(line.chords);
|
||||
return {...line, text: renderedLine};
|
||||
@@ -37,7 +41,9 @@ export class TransposeService {
|
||||
|
||||
public getMap(baseKey: string, difference: number) {
|
||||
const scale = getScaleType(baseKey);
|
||||
if (!scale) return null;
|
||||
if (!scale) {
|
||||
return null;
|
||||
}
|
||||
const map = {};
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const source = scale[0][i];
|
||||
@@ -71,7 +77,7 @@ export class TransposeService {
|
||||
const post = template.substr(pos + newLength);
|
||||
|
||||
template = pre + renderedChord + post;
|
||||
})
|
||||
});
|
||||
|
||||
return template.trimRight();
|
||||
}
|
||||
|
||||
@@ -30,12 +30,22 @@ export class FilterComponent implements OnInit {
|
||||
});
|
||||
|
||||
activatedRoute.queryParams.subscribe((filterValues: FilterValues) => {
|
||||
if (filterValues.q) this.filterFormGroup.controls.q.setValue(filterValues.q);
|
||||
if (filterValues.type) this.filterFormGroup.controls.type.setValue(filterValues.type);
|
||||
if (filterValues.key) this.filterFormGroup.controls.key.setValue(filterValues.key);
|
||||
if (filterValues.legalType) this.filterFormGroup.controls.legalType.setValue(filterValues.legalType);
|
||||
if (filterValues.flag) this.filterFormGroup.controls.flag.setValue(filterValues.flag);
|
||||
})
|
||||
if (filterValues.q) {
|
||||
this.filterFormGroup.controls.q.setValue(filterValues.q);
|
||||
}
|
||||
if (filterValues.type) {
|
||||
this.filterFormGroup.controls.type.setValue(filterValues.type);
|
||||
}
|
||||
if (filterValues.key) {
|
||||
this.filterFormGroup.controls.key.setValue(filterValues.key);
|
||||
}
|
||||
if (filterValues.legalType) {
|
||||
this.filterFormGroup.controls.legalType.setValue(filterValues.legalType);
|
||||
}
|
||||
if (filterValues.flag) {
|
||||
this.filterFormGroup.controls.flag.setValue(filterValues.flag);
|
||||
}
|
||||
});
|
||||
|
||||
this.filterFormGroup.controls.q.valueChanges.subscribe(_ => this.filerValueChanged('q', _));
|
||||
this.filterFormGroup.controls.key.valueChanges.subscribe(_ => this.filerValueChanged('key', _));
|
||||
|
||||
@@ -38,8 +38,8 @@ export class SongListComponent implements OnInit, OnDestroy {
|
||||
|
||||
this.songs$ = combineLatest([filter$, songs$]).pipe(
|
||||
map(_ => {
|
||||
let songs = _[1];
|
||||
let filter = _[0];
|
||||
const songs = _[1];
|
||||
const filter = _[0];
|
||||
this.anyFilterActive = this.checkIfFilterActive(filter);
|
||||
return songs.filter(song => this.filter(song, filter));
|
||||
})
|
||||
@@ -68,10 +68,14 @@ export class SongListComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private checkFlag(flag: string, flags: string) {
|
||||
if (!flags) return false;
|
||||
if (!flags) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const flagStrings = flags.split(';');
|
||||
if (flagStrings.length === 0) return false;
|
||||
if (flagStrings.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return flagStrings.indexOf(flag) !== -1;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ export class FileComponent {
|
||||
this.name = file.name;
|
||||
this.fileId = file.id;
|
||||
this.path = file.path + '/' + file.name;
|
||||
};
|
||||
}
|
||||
|
||||
public async onDelete(): Promise<void> {
|
||||
await this.fileService.delete(this.path, this.songId, this.fileId);
|
||||
|
||||
@@ -51,7 +51,7 @@ export class EditSongComponent implements OnInit {
|
||||
).subscribe(song => {
|
||||
this.song = song;
|
||||
this.form = this.editService.createSongForm(song);
|
||||
this.form.controls.flags.valueChanges.subscribe(_ => this.onFlagsChanged(_))
|
||||
this.form.controls.flags.valueChanges.subscribe(_ => this.onFlagsChanged(_));
|
||||
this.onFlagsChanged(this.form.controls.flags.value);
|
||||
});
|
||||
}
|
||||
@@ -78,7 +78,9 @@ export class EditSongComponent implements OnInit {
|
||||
this.form.controls.flags.setValue(flags.join(';'));
|
||||
}
|
||||
|
||||
if (input) input.value = '';
|
||||
if (input) {
|
||||
input.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
private onFlagsChanged(flagArray: string): void {
|
||||
@@ -91,7 +93,9 @@ export class EditSongComponent implements OnInit {
|
||||
}
|
||||
|
||||
public askForSave(nextState?: RouterStateSnapshot): boolean {
|
||||
if (!this.form.dirty) return true;
|
||||
if (!this.form.dirty) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const dialogRef = this.dialog.open(SaveDialogComponent, {
|
||||
width: '350px'
|
||||
|
||||
@@ -21,7 +21,7 @@ export class FileComponent implements OnInit {
|
||||
this.url$ = ref.getDownloadURL();
|
||||
this.name = file.name;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ export class NewComponent implements OnInit {
|
||||
this.form = new FormGroup({
|
||||
number: new FormControl(null, Validators.required),
|
||||
title: new FormControl(null, Validators.required),
|
||||
})
|
||||
});
|
||||
|
||||
this.songService.list$().pipe(autoComplete(this)).subscribe(songs => {
|
||||
const freeSongnumber = this.getFreeSongNumber(songs);
|
||||
this.form.controls.number.setValue(freeSongnumber);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
public async onSave(): Promise<void> {
|
||||
@@ -41,7 +41,9 @@ export class NewComponent implements OnInit {
|
||||
private getFreeSongNumber(songs: Song[]): Number {
|
||||
const numbers = songs.map(_ => _.number);
|
||||
for (let i = 1; i < Number.MAX_SAFE_INTEGER; i++) {
|
||||
if (!numbers.some(_ => _ === i)) return i;
|
||||
if (!numbers.some(_ => _ === i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,11 @@ export class SongComponent implements OnInit {
|
||||
}
|
||||
|
||||
public getFlags = (flags: string): string[] => {
|
||||
if (!flags) return [];
|
||||
if (!flags) {
|
||||
return [];
|
||||
}
|
||||
return flags.split(';').filter(_ => !!_);
|
||||
};
|
||||
}
|
||||
|
||||
public async onDelete(songId: string): Promise<void> {
|
||||
await this.songService.delete(songId);
|
||||
|
||||
Reference in New Issue
Block a user