diff --git a/src/app/modules/songs/services/file-data.service.ts b/src/app/modules/songs/services/file-data.service.ts index 2136e83..9132feb 100644 --- a/src/app/modules/songs/services/file-data.service.ts +++ b/src/app/modules/songs/services/file-data.service.ts @@ -20,6 +20,11 @@ export class FileDataService { return id.id; } + public async delete(songId: string, fileId: string): Promise { + const fileRef = this.db.doc('songs/' + songId + '/files/' + fileId); + await fileRef.delete(); + } + public read$(songId: string): Observable { const songRef = this.db.doc('songs/' + songId); return songRef.collection('files').snapshotChanges().pipe(map(actions => { diff --git a/src/app/modules/songs/services/file.service.spec.ts b/src/app/modules/songs/services/file.service.spec.ts new file mode 100644 index 0000000..cc88625 --- /dev/null +++ b/src/app/modules/songs/services/file.service.spec.ts @@ -0,0 +1,16 @@ +import {TestBed} from '@angular/core/testing'; + +import {FileService} from './file.service'; + +describe('FileService', () => { + let service: FileService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(FileService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/modules/songs/services/file.service.ts b/src/app/modules/songs/services/file.service.ts new file mode 100644 index 0000000..7dcf395 --- /dev/null +++ b/src/app/modules/songs/services/file.service.ts @@ -0,0 +1,27 @@ +import {Injectable} from '@angular/core'; +import {AngularFireStorage} from '@angular/fire/storage'; +import {Observable} from 'rxjs'; +import {FileDataService} from './file-data.service'; + +@Injectable({ + providedIn: 'root' +}) +export class FileService { + + constructor( + private storage: AngularFireStorage, + private fileDataService: FileDataService + ) { + } + + public getDownloadUrl(path: string): Observable { + const ref = this.storage.ref(path); + return ref.getDownloadURL(); + } + + public async delete(path: string, songId: string, fileId: string) { + const ref = this.storage.ref(path); + await ref.delete().toPromise() + await this.fileDataService.delete(songId, fileId); + } +} diff --git a/src/app/modules/songs/services/text-rendering.service.spec.ts b/src/app/modules/songs/services/text-rendering.service.spec.ts index b6f8ded..12c4c91 100644 --- a/src/app/modules/songs/services/text-rendering.service.spec.ts +++ b/src/app/modules/songs/services/text-rendering.service.spec.ts @@ -77,12 +77,25 @@ Cool bridge without any chords // c c# db c7 cmaj7 c/e expect(sections[2].lines[0].chords).toEqual([ - {chord: 'c', length: 2, position: 0}, - {chord: 'c#', length: 3, position: 2}, - {chord: 'db', length: 3, position: 5}, + {chord: 'c', length: 1, position: 0}, + {chord: 'c#', length: 2, position: 2}, + {chord: 'db', length: 2, position: 5}, {chord: 'c', length: 2, position: 8, add: '7'}, {chord: 'c', length: 5, position: 13, add: 'maj7'}, {chord: 'c', length: 3, position: 22, slashChord: 'e'}, ]); }); + + it('should parse chords with a lot of symbols', () => { + const service: TextRenderingService = TestBed.inject(TextRenderingService); + const text = `Strophe +g# F# E g# F# E +text` + const sections = service.parse(text); + expect(sections[0].lines[0].type).toBe(LineType.chord); + expect(sections[0].lines[0].text).toBe('g# F# E g# F# E'); + expect(sections[0].lines[1].type).toBe(LineType.text); + expect(sections[0].lines[1].text).toBe('text'); + + }); }); diff --git a/src/app/modules/songs/services/text-rendering.service.ts b/src/app/modules/songs/services/text-rendering.service.ts index 955b6b0..1cdea64 100644 --- a/src/app/modules/songs/services/text-rendering.service.ts +++ b/src/app/modules/songs/services/text-rendering.service.ts @@ -89,7 +89,7 @@ export class TextRenderingService { const chords: Chord[] = []; // https://regex101.com/r/68jMB8/5 - const regex = /\b(C#|C|Db|D#|D|Eb|E|F#|F|Gb|G#|G|Ab|A#|A|B|H|c#|c|db|d#|d|eb|e|f#|f|gb|g#|g|ab|a#|a|b|h)(\/(C#|C|Db|D#|D|Eb|E|F#|F|Gb|G#|G|Ab|A#|A|B|H|c#|c|db|d#|d|eb|e|f#|f|gb|g#|g|ab|a#|a|b|h))?(\d+|maj7)?\b\s/mg; + const regex = /(C#|C|Db|D#|D|Eb|E|F#|F|Gb|G#|G|Ab|A#|A|B|H|c#|c|db|d#|d|eb|e|f#|f|gb|g#|g|ab|a#|a|b|h)(\/(C#|C|Db|D#|D|Eb|E|F#|F|Gb|G#|G|Ab|A#|A|B|H|c#|c|db|d#|d|eb|e|f#|f|gb|g#|g|ab|a#|a|b|h))?(\d+|maj7)?/mg; while ((match = regex.exec(chordLine)) !== null) { const chord: Chord = { @@ -105,7 +105,8 @@ export class TextRenderingService { const chordCount = chords.reduce((acc: number, cur: Chord) => acc + cur.length, 0); const lineCount = chordLine.replace(/\s/g, "").length; - + console.log(chordCount + ' - ' + lineCount + ' - ' + chordLine); + console.log(chords); const isChrod = chordCount * 2 > lineCount; return isChrod ? chords : []; } diff --git a/src/app/modules/songs/services/upload.service.ts b/src/app/modules/songs/services/upload.service.ts index d3309e9..6626cfb 100644 --- a/src/app/modules/songs/services/upload.service.ts +++ b/src/app/modules/songs/services/upload.service.ts @@ -31,22 +31,6 @@ export class UploadService extends FileBase { }) ).subscribe(); - // const storageRef = storage().ref(); - // const uploadTask = storageRef.child(`${this.basePath}/${songId}/${file.file.name}`).put(file.file as any); - // - // uploadTask.on(storage.TaskEvent.STATE_CHANGED, - // (snapshot) => { - // file.progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; - // }, - // (error) => { - // console.log(error); - // }, - // () => { - // file.url = uploadTask.snapshot.downloadURL; - // file.name = file.file.name; - // this.saveFileData(songId, file); - // } - // ); } private async saveFileData(songId: string, upload: Upload) { diff --git a/src/app/modules/songs/song/edit/edit-file/edit-file.component.html b/src/app/modules/songs/song/edit/edit-file/edit-file.component.html index 3d184a0..dfc2981 100644 --- a/src/app/modules/songs/song/edit/edit-file/edit-file.component.html +++ b/src/app/modules/songs/song/edit/edit-file/edit-file.component.html @@ -20,7 +20,7 @@

- +

diff --git a/src/app/modules/songs/song/edit/edit-file/file/file.component.html b/src/app/modules/songs/song/edit/edit-file/file/file.component.html index a02880b..cffaf84 100644 --- a/src/app/modules/songs/song/edit/edit-file/file/file.component.html +++ b/src/app/modules/songs/song/edit/edit-file/file/file.component.html @@ -1,3 +1,5 @@ - - {{name}} - + + +{{name}} diff --git a/src/app/modules/songs/song/edit/edit-file/file/file.component.less b/src/app/modules/songs/song/edit/edit-file/file/file.component.less index e69de29..6ba7fa4 100644 --- a/src/app/modules/songs/song/edit/edit-file/file/file.component.less +++ b/src/app/modules/songs/song/edit/edit-file/file/file.component.less @@ -0,0 +1,3 @@ +button { + margin: -5px 0; +} diff --git a/src/app/modules/songs/song/edit/edit-file/file/file.component.ts b/src/app/modules/songs/song/edit/edit-file/file/file.component.ts index 79c177d..e51b823 100644 --- a/src/app/modules/songs/song/edit/edit-file/file/file.component.ts +++ b/src/app/modules/songs/song/edit/edit-file/file/file.component.ts @@ -1,28 +1,33 @@ -import {Component, Input, OnInit} from '@angular/core'; +import {Component, Input} from '@angular/core'; import {Observable} from 'rxjs'; import {File} from '../../../../services/file'; -import {AngularFireStorage} from '@angular/fire/storage'; +import {faTrashAlt} from '@fortawesome/free-solid-svg-icons/faTrashAlt'; +import {FileService} from '../../../../services/file.service'; @Component({ selector: 'app-file', templateUrl: './file.component.html', styleUrls: ['./file.component.less'] }) -export class FileComponent implements OnInit { +export class FileComponent { public url$: Observable; public name: string; + public faTrash = faTrashAlt; + @Input() songId: string; + private fileId: string; + private path: string; - constructor(private storage: AngularFireStorage) { + constructor(private fileService: FileService) { } @Input() set file(file: File) { - - const ref = this.storage.ref(file.path + '/' + file.name); - this.url$ = ref.getDownloadURL(); + this.url$ = this.fileService.getDownloadUrl(file.path + '/' + file.name); this.name = file.name; - + this.fileId = file.id; + this.path = file.path + '/' + file.name; }; - ngOnInit(): void { + public async onDelete(): Promise { + await this.fileService.delete(this.path, this.songId, this.fileId); } } diff --git a/src/app/modules/songs/song/song.component.html b/src/app/modules/songs/song/song.component.html index 002e814..689ada4 100644 --- a/src/app/modules/songs/song/song.component.html +++ b/src/app/modules/songs/song/song.component.html @@ -39,11 +39,11 @@ - +

-
+