From 5c7e588c2ade871f5b42a525131eb7d3b9ba2d14 Mon Sep 17 00:00:00 2001 From: smuddyx Date: Wed, 22 Apr 2020 11:34:03 +0200 Subject: [PATCH] add songs live on presentation --- .../presentation/presentation.module.ts | 4 +- .../presentation/remote/remote.component.html | 4 ++ .../presentation/remote/remote.component.ts | 5 +- .../modules/shows/services/docx.service.ts | 2 +- .../shows/services/show-song-data.service.ts | 2 +- .../shows/services/show-song.service.ts | 13 +++-- .../services/{showSong.ts => show-song.ts} | 3 +- .../modules/shows/show/show.component.html | 13 +---- .../modules/shows/show/show.component.less | 9 ---- src/app/modules/shows/show/show.component.ts | 31 +----------- .../modules/shows/show/song/song.component.ts | 2 +- src/app/modules/shows/shows.module.ts | 2 + .../add-song/add-song.component.html | 11 ++++ .../add-song/add-song.component.less | 8 +++ .../add-song/add-song.component.spec.ts | 25 ++++++++++ .../components/add-song/add-song.component.ts | 50 +++++++++++++++++++ .../components/add-song/add-song.module.ts | 24 +++++++++ 17 files changed, 149 insertions(+), 59 deletions(-) rename src/app/modules/shows/services/{showSong.ts => show-song.ts} (82%) create mode 100644 src/app/widget-modules/components/add-song/add-song.component.html create mode 100644 src/app/widget-modules/components/add-song/add-song.component.less create mode 100644 src/app/widget-modules/components/add-song/add-song.component.spec.ts create mode 100644 src/app/widget-modules/components/add-song/add-song.component.ts create mode 100644 src/app/widget-modules/components/add-song/add-song.module.ts diff --git a/src/app/modules/presentation/presentation.module.ts b/src/app/modules/presentation/presentation.module.ts index afaa240..0ce9bf6 100644 --- a/src/app/modules/presentation/presentation.module.ts +++ b/src/app/modules/presentation/presentation.module.ts @@ -15,6 +15,7 @@ import {MatButtonModule} from '@angular/material/button'; import {FontAwesomeModule} from '@fortawesome/angular-fontawesome'; import {MatSliderModule} from '@angular/material/slider'; import {FormsModule} from '@angular/forms'; +import {AddSongModule} from '../../widget-modules/components/add-song/add-song.module'; @NgModule({ @@ -31,7 +32,8 @@ import {FormsModule} from '@angular/forms'; MatButtonModule, FontAwesomeModule, MatSliderModule, - FormsModule + FormsModule, + AddSongModule ] }) export class PresentationModule { diff --git a/src/app/modules/presentation/remote/remote.component.html b/src/app/modules/presentation/remote/remote.component.html index 0099860..0a28ae8 100644 --- a/src/app/modules/presentation/remote/remote.component.html +++ b/src/app/modules/presentation/remote/remote.component.html @@ -41,6 +41,10 @@ > + + + diff --git a/src/app/modules/presentation/remote/remote.component.ts b/src/app/modules/presentation/remote/remote.component.ts index 9ac0ad5..2ccdb94 100644 --- a/src/app/modules/presentation/remote/remote.component.ts +++ b/src/app/modules/presentation/remote/remote.component.ts @@ -8,6 +8,7 @@ import {Song} from '../../songs/services/song'; import {Section, TextRenderingService} from '../../songs/services/text-rendering.service'; import {faDesktop} from '@fortawesome/free-solid-svg-icons/faDesktop'; import {ShowService} from '../../shows/services/show.service'; +import {ShowSong} from '../../shows/services/show-song'; export interface PresentationSong { id: string; @@ -23,6 +24,7 @@ export interface PresentationSong { export class RemoteComponent { public shows$: Observable; public show: Show; + public showSongs: ShowSong[]; public songs: Song[]; public presentationSongs: PresentationSong[]; public currentShowId: string; @@ -33,7 +35,7 @@ export class RemoteComponent { private showService: ShowService, private showSongService: ShowSongService, private songService: SongService, - private textRenderingService: TextRenderingService + private textRenderingService: TextRenderingService, ) { this.shows$ = showService.list$(true); songService.list$().subscribe(_ => this.songs = _); @@ -43,6 +45,7 @@ export class RemoteComponent { this.currentShowId = change.value; this.showService.read$(change.value).subscribe(_ => this.show = _); this.showSongService.list$(change.value).subscribe(_ => { + this.showSongs = _; this.presentationSongs = _ .map(song => this.songs.filter(f => f.id == song.songId)[0]) .map(song => ({ diff --git a/src/app/modules/shows/services/docx.service.ts b/src/app/modules/shows/services/docx.service.ts index 064bb6a..3d10ab6 100644 --- a/src/app/modules/shows/services/docx.service.ts +++ b/src/app/modules/shows/services/docx.service.ts @@ -7,7 +7,7 @@ import {ShowSongService} from './show-song.service'; import {Line, LineType, Section, TextRenderingService} from '../../songs/services/text-rendering.service'; import {Song} from '../../songs/services/song'; import {SongService} from '../../songs/services/song.service'; -import {ShowSong} from './showSong'; +import {ShowSong} from './show-song'; import {Show} from './show'; import {ChordMode} from '../../../widget-modules/components/song-text/song-text.component'; import {UserService} from '../../../services/user.service'; diff --git a/src/app/modules/shows/services/show-song-data.service.ts b/src/app/modules/shows/services/show-song-data.service.ts index f262227..a2bdc00 100644 --- a/src/app/modules/shows/services/show-song-data.service.ts +++ b/src/app/modules/shows/services/show-song-data.service.ts @@ -1,7 +1,7 @@ import {Injectable} from '@angular/core'; import {DbService} from '../../../services/db.service'; import {Observable} from 'rxjs'; -import {ShowSong} from './showSong'; +import {ShowSong} from './show-song'; @Injectable({ providedIn: 'root' diff --git a/src/app/modules/shows/services/show-song.service.ts b/src/app/modules/shows/services/show-song.service.ts index d744ce1..d96d322 100644 --- a/src/app/modules/shows/services/show-song.service.ts +++ b/src/app/modules/shows/services/show-song.service.ts @@ -1,7 +1,7 @@ import {Injectable} from '@angular/core'; import {ShowSongDataService} from './show-song-data.service'; import {Observable} from 'rxjs'; -import {ShowSong} from './showSong'; +import {ShowSong} from './show-song'; import {SongDataService} from '../../songs/services/song-data.service'; import {take} from 'rxjs/operators'; import {UserService} from '../../../services/user.service'; @@ -18,10 +18,17 @@ export class ShowSongService { ) { } - public async new$(showId: string, songId: string, order: number): Promise { + public async new$(showId: string, songId: string, order: number, addedLive = false): Promise { const song = await this.songDataService.read$(songId).pipe(take(1)).toPromise(); const user = await this.userService.user$.pipe(take(1)).toPromise(); - const data: Partial = {songId, order, key: song.key, keyOriginal: song.key, chordMode: user.chordMode}; + const data: Partial = { + songId, + order, + key: song.key, + keyOriginal: song.key, + chordMode: user.chordMode, + addedLive + }; return await this.showSongDataService.add(showId, data); } diff --git a/src/app/modules/shows/services/showSong.ts b/src/app/modules/shows/services/show-song.ts similarity index 82% rename from src/app/modules/shows/services/showSong.ts rename to src/app/modules/shows/services/show-song.ts index 0a64d16..4b64f0c 100644 --- a/src/app/modules/shows/services/showSong.ts +++ b/src/app/modules/shows/services/show-song.ts @@ -6,5 +6,6 @@ export interface ShowSong { key: string; keyOriginal: string; order: number; - chordMode: ChordMode + chordMode: ChordMode; + addedLive: boolean; } diff --git a/src/app/modules/shows/show/show.component.html b/src/app/modules/shows/show/show.component.html index af62132..d88acea 100644 --- a/src/app/modules/shows/show/show.component.html +++ b/src/app/modules/shows/show/show.component.html @@ -17,18 +17,9 @@ > -
- - Lied hinzufügen... - - - - - {{song.title}} - - + -
diff --git a/src/app/modules/shows/show/show.component.less b/src/app/modules/shows/show/show.component.less index 5f0b845..da87eac 100644 --- a/src/app/modules/shows/show/show.component.less +++ b/src/app/modules/shows/show/show.component.less @@ -1,12 +1,3 @@ -.add-row { - display: flex; - margin-top: 10px; - - .mat-form-field { - width: 100%; - } -} - .song-row:not(:last-child) { display: block; border-bottom: 1px solid #0002; diff --git a/src/app/modules/shows/show/show.component.ts b/src/app/modules/shows/show/show.component.ts index 14bfaf7..3c15679 100644 --- a/src/app/modules/shows/show/show.component.ts +++ b/src/app/modules/shows/show/show.component.ts @@ -6,12 +6,9 @@ import {Observable} from 'rxjs'; import {Show} from '../services/show'; import {SongService} from '../../songs/services/song.service'; import {Song} from '../../songs/services/song'; -import {MatSelectChange} from '@angular/material/select'; import {ShowSongService} from '../services/show-song.service'; -import {ShowSong} from '../services/showSong'; +import {ShowSong} from '../services/show-song'; import {DocxService} from '../services/docx.service'; -import {FormControl} from '@angular/forms'; -import {filterSong} from '../../../services/filter.helper'; @Component({ selector: 'app-show', @@ -46,29 +43,10 @@ export class ShowComponent implements OnInit { filter(_ => !!_) ).subscribe(_ => this.showSongs = _); this.songService.list$().pipe( - map(_ => _ - .filter(_ => !!_) - .filter(_ => !!_.title) - .filter(_ => _.title !== 'nicht gefunden') - .filter(_ => _.title !== 'nicht vorhanden') - .sort((a, b) => { - if (a.title < b.title) { - return -1; - } - if (a.title > b.title) { - return 1; - } - return 0; - })), filter(_ => !!_) ).subscribe(_ => this.songs = _); } - public async onAddSongSelectionChanged(event: MatSelectChange) { - await this.showSongService.new$(this.showId, event.value, this.showSongs.reduce((oa, u) => Math.max(oa, u.order), 0) + 1); - event.source.value = null; - } - public getSong(songId: string): Song { const filtered = this.songs.filter(_ => _.id === songId); return filtered.length > 0 ? filtered[0] : null; @@ -91,11 +69,4 @@ export class ShowComponent implements OnInit { public async onDownload(): Promise { await this.docxService.create(this.showId); } - - public filteredSongsControl = new FormControl(); - - filteredSongs() { - const filterValue = this.filteredSongsControl.value; - return filterValue ? this.songs.filter(_ => filterSong(_, filterValue)) : this.songs; - } } diff --git a/src/app/modules/shows/show/song/song.component.ts b/src/app/modules/shows/show/song/song.component.ts index b019b86..5efb41c 100644 --- a/src/app/modules/shows/show/song/song.component.ts +++ b/src/app/modules/shows/show/song/song.component.ts @@ -4,7 +4,7 @@ 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'; import {ShowSongService} from '../../services/show-song.service'; -import {ShowSong} from '../../services/showSong'; +import {ShowSong} from '../../services/show-song'; import {getScale} from '../../../songs/services/key.helper'; import {FormControl} from '@angular/forms'; import {ChordMode} from '../../../../widget-modules/components/song-text/song-text.component'; diff --git a/src/app/modules/shows/shows.module.ts b/src/app/modules/shows/shows.module.ts index a944e17..a8c3415 100644 --- a/src/app/modules/shows/shows.module.ts +++ b/src/app/modules/shows/shows.module.ts @@ -23,6 +23,7 @@ import {FontAwesomeModule} from '@fortawesome/angular-fontawesome'; import {MenuButtonModule} from '../../widget-modules/components/menu-button/menu-button.module'; import {SongTextModule} from '../../widget-modules/components/song-text/song-text.module'; import {NgxMatSelectSearchModule} from 'ngx-mat-select-search'; +import {AddSongModule} from '../../widget-modules/components/add-song/add-song.module'; @NgModule({ @@ -47,6 +48,7 @@ import {NgxMatSelectSearchModule} from 'ngx-mat-select-search'; FormsModule, SongTextModule, NgxMatSelectSearchModule, + AddSongModule, ] }) export class ShowsModule { diff --git a/src/app/widget-modules/components/add-song/add-song.component.html b/src/app/widget-modules/components/add-song/add-song.component.html new file mode 100644 index 0000000..def72e6 --- /dev/null +++ b/src/app/widget-modules/components/add-song/add-song.component.html @@ -0,0 +1,11 @@ +
+ + Lied hinzufügen... + + + + + {{song.title}} + + +
diff --git a/src/app/widget-modules/components/add-song/add-song.component.less b/src/app/widget-modules/components/add-song/add-song.component.less new file mode 100644 index 0000000..56cde8c --- /dev/null +++ b/src/app/widget-modules/components/add-song/add-song.component.less @@ -0,0 +1,8 @@ +.add-row { + display: flex; + margin-top: 10px; + + .mat-form-field { + width: 100%; + } +} diff --git a/src/app/widget-modules/components/add-song/add-song.component.spec.ts b/src/app/widget-modules/components/add-song/add-song.component.spec.ts new file mode 100644 index 0000000..697188d --- /dev/null +++ b/src/app/widget-modules/components/add-song/add-song.component.spec.ts @@ -0,0 +1,25 @@ +import {async, ComponentFixture, TestBed} from '@angular/core/testing'; + +import {AddSongComponent} from './add-song.component'; + +describe('AddSongComponent', () => { + let component: AddSongComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [AddSongComponent] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AddSongComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/widget-modules/components/add-song/add-song.component.ts b/src/app/widget-modules/components/add-song/add-song.component.ts new file mode 100644 index 0000000..2820921 --- /dev/null +++ b/src/app/widget-modules/components/add-song/add-song.component.ts @@ -0,0 +1,50 @@ +import {Component, Input} from '@angular/core'; +import {FormControl} from '@angular/forms'; +import {filterSong} from '../../../services/filter.helper'; +import {MatSelectChange} from '@angular/material/select'; +import {Song} from '../../../modules/songs/services/song'; +import {ShowSong} from '../../../modules/shows/services/show-song'; +import {ShowSongService} from '../../../modules/shows/services/show-song.service'; + +@Component({ + selector: 'app-add-song', + templateUrl: './add-song.component.html', + styleUrls: ['./add-song.component.less'] +}) +export class AddSongComponent { + @Input() public songs: Song[]; + @Input() public showSongs: ShowSong[]; + @Input() public showId: string; + @Input() public addedLive = false; + public filteredSongsControl = new FormControl(); + + constructor(private showSongService: ShowSongService) { + } + + filteredSongs() { + const songs = this.songs + .filter(_ => !!_) + .filter(_ => !!_.title) + .filter(_ => _.title !== 'nicht gefunden') + .filter(_ => _.title !== 'nicht vorhanden') + .sort((a, b) => { + if (a.title < b.title) { + return -1; + } + if (a.title > b.title) { + return 1; + } + return 0; + }) + + const filterValue = this.filteredSongsControl.value; + return filterValue ? songs.filter(_ => filterSong(_, filterValue)) : songs; + } + + public async onAddSongSelectionChanged(event: MatSelectChange) { + let order = this.showSongs.reduce((oa, u) => Math.max(oa, u.order), 0) + 1; + await this.showSongService.new$(this.showId, event.value, order, this.addedLive); + event.source.value = null; + } + +} diff --git a/src/app/widget-modules/components/add-song/add-song.module.ts b/src/app/widget-modules/components/add-song/add-song.module.ts new file mode 100644 index 0000000..62a167a --- /dev/null +++ b/src/app/widget-modules/components/add-song/add-song.module.ts @@ -0,0 +1,24 @@ +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {AddSongComponent} from './add-song.component'; +import {MatFormFieldModule} from '@angular/material/form-field'; +import {MatSelectModule} from '@angular/material/select'; +import {NgxMatSelectSearchModule} from 'ngx-mat-select-search'; +import {ReactiveFormsModule} from '@angular/forms'; + + +@NgModule({ + declarations: [AddSongComponent], + exports: [ + AddSongComponent + ], + imports: [ + CommonModule, + MatFormFieldModule, + MatSelectModule, + NgxMatSelectSearchModule, + ReactiveFormsModule + ] +}) +export class AddSongModule { +}