activated typescript strict mode

This commit is contained in:
2021-05-22 15:30:04 +02:00
parent a195fafa6b
commit cb2c028ca4
76 changed files with 511 additions and 296 deletions

View File

@@ -8,7 +8,7 @@
"bracketSpacing": false, "bracketSpacing": false,
"arrowParens": "avoid", "arrowParens": "avoid",
"jsxBracketSameLine": false, "jsxBracketSameLine": false,
"printWidth": 200, "printWidth": 120,
"overrides": [ "overrides": [
{ {
"files": "*.component.html", "files": "*.component.html",

5
package-lock.json generated
View File

@@ -12546,11 +12546,6 @@
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=", "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=",
"dev": true "dev": true
}, },
"ngx-hocs-unsubscriber": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/ngx-hocs-unsubscriber/-/ngx-hocs-unsubscriber-1.1.7.tgz",
"integrity": "sha512-FPasZvptGjzcnWzlUJcVhqq+mFi0bGt4/txTHe0XX6kDlIRX+9yfnPPDXvUvSSj6yXeuWDfnh9kn5Fr74W9Ohw=="
},
"ngx-mat-select-search": { "ngx-mat-select-search": {
"version": "3.3.0", "version": "3.3.0",
"resolved": "https://registry.npmjs.org/ngx-mat-select-search/-/ngx-mat-select-search-3.3.0.tgz", "resolved": "https://registry.npmjs.org/ngx-mat-select-search/-/ngx-mat-select-search-3.3.0.tgz",

View File

@@ -28,7 +28,6 @@
"@fortawesome/free-solid-svg-icons": "^5.13.0", "@fortawesome/free-solid-svg-icons": "^5.13.0",
"docx": "^6.0.3", "docx": "^6.0.3",
"firebase": "^7.24.0", "firebase": "^7.24.0",
"ngx-hocs-unsubscriber": "^1.1.7",
"ngx-mat-select-search": "^3.3.0", "ngx-mat-select-search": "^3.3.0",
"ngx-perfect-scrollbar": "^10.1.1", "ngx-perfect-scrollbar": "^10.1.1",
"ngx-swiper-wrapper": "^10.0.0", "ngx-swiper-wrapper": "^10.0.0",

View File

@@ -10,15 +10,15 @@ import {PerfectScrollbarComponent} from 'ngx-perfect-scrollbar';
animations: [fader], animations: [fader],
}) })
export class AppComponent implements OnInit { export class AppComponent implements OnInit {
@ViewChild('scrollbar', {static: false}) public scrollbar: PerfectScrollbarComponent; @ViewChild('scrollbar', {static: false}) public scrollbar: PerfectScrollbarComponent | null = null;
public constructor(private scrollService: ScrollService) { public constructor(private scrollService: ScrollService) {
scrollService.restoreScrollPosition$.subscribe(pos => { scrollService.restoreScrollPosition$.subscribe(pos => {
if (this.scrollbar && pos) this.scrollbar.directiveRef.scrollTo(0, pos, 300); if (this.scrollbar && pos) this.scrollbar.directiveRef?.scrollTo(0, pos, 300);
}); });
} }
public static hideLoader: () => void = () => document.querySelector('#load-bg').classList.add('hidden'); public static hideLoader: () => void = () => document.querySelector('#load-bg')?.classList.add('hidden');
public ngOnInit(): void { public ngOnInit(): void {
setTimeout(() => AppComponent.hideLoader(), 800); setTimeout(() => AppComponent.hideLoader(), 800);

View File

@@ -9,7 +9,7 @@ import {User} from '../../../services/user/user';
styleUrls: ['./new-user.component.less'], styleUrls: ['./new-user.component.less'],
}) })
export class NewUserComponent { export class NewUserComponent {
public user$: Observable<User>; public user$: Observable<User | null> | null = null;
public constructor(private userService: UserService) { public constructor(private userService: UserService) {
this.user$ = userService.user$; this.user$ = userService.user$;

View File

@@ -2,8 +2,10 @@ import {Component, OnInit} from '@angular/core';
import {SongService} from '../songs/services/song.service'; import {SongService} from '../songs/services/song.service';
import {GlobalSettingsService} from '../../services/global-settings.service'; import {GlobalSettingsService} from '../../services/global-settings.service';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
import {map, switchMap} from 'rxjs/operators'; import {filter, map, switchMap} from 'rxjs/operators';
import {ShowSongService} from '../shows/services/show-song.service'; import {ShowSongService} from '../shows/services/show-song.service';
import {GlobalSettings} from '../../services/global-settings';
import {Song} from '../songs/services/song';
@Component({ @Component({
selector: 'app-guest', selector: 'app-guest',
@@ -11,15 +13,31 @@ import {ShowSongService} from '../shows/services/show-song.service';
styleUrls: ['./guest.component.less'], styleUrls: ['./guest.component.less'],
}) })
export class GuestComponent implements OnInit { export class GuestComponent implements OnInit {
public songs$: Observable<Observable<string>[]>; public songs$: Observable<Observable<string>[]> | null = null;
public constructor(private songService: SongService, private globalSettingsService: GlobalSettingsService, private showSongService: ShowSongService) {} public constructor(
private songService: SongService,
private globalSettingsService: GlobalSettingsService,
private showSongService: ShowSongService
) {}
public ngOnInit(): void { public ngOnInit(): void {
this.songs$ = this.globalSettingsService.get$.pipe( this.songs$ = this.globalSettingsService.get$.pipe(
filter(_ => !!_),
map(_ => _ as GlobalSettings),
map(_ => _.currentShow), map(_ => _.currentShow),
switchMap(_ => this.showSongService.list$(_)), switchMap(_ => this.showSongService.list$(_)),
map(_ => _.sort((x, y) => x.order - y.order).map(showSong => this.songService.read$(showSong.songId).pipe(map(song => song.text)))) filter(_ => !!_),
map(_ => _),
map(_ =>
_.sort((x, y) => x.order - y.order).map(showSong =>
this.songService.read$(showSong.songId).pipe(
filter(_ => !!_),
map(_ => _ as Song),
map(song => song.text)
)
)
)
); );
} }
} }

View File

@@ -1,3 +1,4 @@
<ng-container *ngIf="song">
<p *ngIf="song.artist">{{ song.artist }}</p> <p *ngIf="song.artist">{{ song.artist }}</p>
<p *ngIf="song.label">{{ song.label }}</p> <p *ngIf="song.label">{{ song.label }}</p>
<p *ngIf="song.termsOfUse" class="terms-of-use">{{ song.termsOfUse }}</p> <p *ngIf="song.termsOfUse" class="terms-of-use">{{ song.termsOfUse }}</p>
@@ -10,3 +11,4 @@
</p> </p>
<p *ngIf="song.legalOwner !== 'CCLI'">Liednummer {{ song.legalOwnerId }}</p> <p *ngIf="song.legalOwner !== 'CCLI'">Liednummer {{ song.legalOwnerId }}</p>
</div> </div>
</ng-container>

View File

@@ -8,6 +8,6 @@ import {Config} from '../../../../services/config';
styleUrls: ['./legal.component.less'], styleUrls: ['./legal.component.less'],
}) })
export class LegalComponent { export class LegalComponent {
@Input() public song: Song; @Input() public song: Song | null = null;
@Input() public config: Config; @Input() public config: Config | null = null;
} }

View File

@@ -1,4 +1,4 @@
<div *ngIf="song" [style.font-size.px]="zoom" class="fullscreen background"> <div *ngIf="song && showType" [style.font-size.px]="zoom" class="fullscreen background">
<div <div
@songSwitch @songSwitch
[class.blur]="songId === 'title'" [class.blur]="songId === 'title'"

View File

@@ -1,5 +1,5 @@
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {distinctUntilChanged, map, switchMap, tap} from 'rxjs/operators'; import {distinctUntilChanged, filter, map, switchMap, tap} from 'rxjs/operators';
import {ShowService} from '../../shows/services/show.service'; import {ShowService} from '../../shows/services/show.service';
import {SongService} from '../../songs/services/song.service'; import {SongService} from '../../songs/services/song.service';
import {Song} from '../../songs/services/song'; import {Song} from '../../songs/services/song';
@@ -10,6 +10,7 @@ import {ConfigService} from '../../../services/config.service';
import {songSwitch} from '../../../widget-modules/components/song-text/animation'; import {songSwitch} from '../../../widget-modules/components/song-text/animation';
import {TextRenderingService} from '../../songs/services/text-rendering.service'; import {TextRenderingService} from '../../songs/services/text-rendering.service';
import {Show} from '../../shows/services/show'; import {Show} from '../../shows/services/show';
import {GlobalSettings} from '../../../services/global-settings';
@Component({ @Component({
selector: 'app-monitor', selector: 'app-monitor',
@@ -18,14 +19,14 @@ import {Show} from '../../shows/services/show';
animations: [songSwitch], animations: [songSwitch],
}) })
export class MonitorComponent implements OnInit { export class MonitorComponent implements OnInit {
public song: Song; public song: Song | null = null;
public zoom: number; public zoom = 10;
public currentShowId: string; public currentShowId: string | null = null;
public songId: string; public songId: string | null = null;
public index: number; public index: number | null = null;
public showType: string; public showType: string | null = null;
public date: Date; public date: Date | null = null;
public config$: Observable<Config>; public config$: Observable<Config | null>;
// private sections: Section[]; // private sections: Section[];
@@ -42,18 +43,28 @@ export class MonitorComponent implements OnInit {
public ngOnInit(): void { public ngOnInit(): void {
this.globalSettingsService.get$ this.globalSettingsService.get$
.pipe( .pipe(
filter(_ => !!_),
map(_ => _ as GlobalSettings),
map(_ => _.currentShow), map(_ => _.currentShow),
distinctUntilChanged(), distinctUntilChanged(),
tap(_ => (this.currentShowId = _)), tap(_ => (this.currentShowId = _))
switchMap(_ => this.showService.read$(_)),
tap(_ => (this.showType = _.showType)),
tap(_ => (this.date = _.date.toDate())),
tap(_ => (this.songId = _.presentationSongId)),
tap(_ => (this.index = _.presentationSection)),
tap(_ => (this.zoom = _.presentationZoom ?? 30)),
switchMap((_: Show) => this.songService.read$(_.presentationSongId))
) )
.subscribe((_: Song) => { .pipe(
switchMap(_ => this.showService.read$(_)),
filter(_ => !!_),
map(_ => _ as Show),
tap<Show>(_ => (this.showType = _.showType)),
tap<Show>(_ => (this.date = _.date.toDate())),
tap<Show>(_ => (this.songId = _.presentationSongId)),
tap<Show>(_ => (this.index = _.presentationSection)),
tap<Show>(_ => (this.zoom = _.presentationZoom ?? 30))
)
.pipe(
switchMap((_: Show) => this.songService.read$(_.presentationSongId)),
filter(_ => !!_),
map(_ => _ as Song)
)
.subscribe(_ => {
this.song = _; this.song = _;
// this.sections = this.textRenderingService.parse(_.text, null); // this.sections = this.textRenderingService.parse(_.text, null);
}); });

View File

@@ -33,7 +33,7 @@
</div> </div>
<div *ngFor="let song of presentationSongs" @fade class="song"> <div *ngFor="let song of presentationSongs" @fade class="song">
<div <div *ngIf="show"
[class.active]="show.presentationSongId === song.id" [class.active]="show.presentationSongId === song.id"
class="title song-part" class="title song-part"
> >

View File

@@ -9,11 +9,12 @@ import {ShowService} from '../../shows/services/show.service';
import {ShowSong} from '../../shows/services/show-song'; import {ShowSong} from '../../shows/services/show-song';
import {GlobalSettingsService} from '../../../services/global-settings.service'; import {GlobalSettingsService} from '../../../services/global-settings.service';
import {FormControl} from '@angular/forms'; import {FormControl} from '@angular/forms';
import {distinctUntilChanged, map} from 'rxjs/operators'; import {distinctUntilChanged, filter, map} from 'rxjs/operators';
import {fade} from '../../../animations'; import {fade} from '../../../animations';
import {delay} from '../../../services/delay'; import {delay} from '../../../services/delay';
import {TextRenderingService} from '../../songs/services/text-rendering.service'; import {TextRenderingService} from '../../songs/services/text-rendering.service';
import {Section} from '../../songs/services/section'; import {Section} from '../../songs/services/section';
import {GlobalSettings} from '../../../services/global-settings';
export interface PresentationSong { export interface PresentationSong {
id: string; id: string;
@@ -29,11 +30,11 @@ export interface PresentationSong {
}) })
export class RemoteComponent { export class RemoteComponent {
public shows$: Observable<Show[]>; public shows$: Observable<Show[]>;
public show: Show; public show: Show | null = null;
public showSongs: ShowSong[]; public showSongs: ShowSong[] = [];
public songs: Song[]; public songs: Song[] = [];
public presentationSongs: PresentationSong[]; public presentationSongs: PresentationSong[] = [];
public currentShowId: string; public currentShowId: string | null = null;
public progress = false; public progress = false;
public faDesktop = faDesktop; public faDesktop = faDesktop;
@@ -51,6 +52,8 @@ export class RemoteComponent {
globalSettingsService.get$ globalSettingsService.get$
.pipe( .pipe(
filter(_ => !!_),
map(_ => _ as GlobalSettings),
map(_ => _.currentShow), map(_ => _.currentShow),
distinctUntilChanged() distinctUntilChanged()
) )
@@ -88,6 +91,7 @@ export class RemoteComponent {
} }
public async onSectionClick(id: string, index: number): Promise<void> { public async onSectionClick(id: string, index: number): Promise<void> {
if (this.currentShowId != null)
await this.showService.update$(this.currentShowId, { await this.showService.update$(this.currentShowId, {
presentationSongId: id, presentationSongId: id,
presentationSection: index, presentationSection: index,
@@ -95,6 +99,6 @@ export class RemoteComponent {
} }
public async onZoom(zoom: number): Promise<void> { public async onZoom(zoom: number): Promise<void> {
await this.showService.update$(this.currentShowId, {presentationZoom: zoom}); if (this.currentShowId != null) await this.showService.update$(this.currentShowId, {presentationZoom: zoom});
} }
} }

View File

@@ -1,4 +1,4 @@
<div class="list-item"> <div class="list-item" *ngIf="show">
<div>{{ show.date.toDate() | date: "dd.MM.yyyy" }}</div> <div>{{ show.date.toDate() | date: "dd.MM.yyyy" }}</div>
<div>{{ show.showType | showType }}</div> <div>{{ show.showType | showType }}</div>
</div> </div>

View File

@@ -7,5 +7,5 @@ import {Show} from '../../services/show';
styleUrls: ['./list-item.component.less'], styleUrls: ['./list-item.component.less'],
}) })
export class ListItemComponent { export class ListItemComponent {
@Input() public show: Show; @Input() public show: Show | null = null;
} }

View File

@@ -16,7 +16,10 @@ export class NewComponent implements OnInit {
public shows$: Observable<Show[]>; public shows$: Observable<Show[]>;
public showTypePublic = ShowService.SHOW_TYPE_PUBLIC; public showTypePublic = ShowService.SHOW_TYPE_PUBLIC;
public showTypePrivate = ShowService.SHOW_TYPE_PRIVATE; public showTypePrivate = ShowService.SHOW_TYPE_PRIVATE;
public form: FormGroup; public form: FormGroup = new FormGroup({
date: new FormControl(null, Validators.required),
showType: new FormControl(null, Validators.required),
});
public faSave = faSave; public faSave = faSave;
public constructor(private showService: ShowService, showDataService: ShowDataService, private router: Router) { public constructor(private showService: ShowService, showDataService: ShowDataService, private router: Router) {
@@ -24,10 +27,7 @@ export class NewComponent implements OnInit {
} }
public ngOnInit(): void { public ngOnInit(): void {
this.form = new FormGroup({ this.form.reset();
date: new FormControl(null, Validators.required),
showType: new FormControl(null, Validators.required),
});
} }
public async onSave(): Promise<void> { public async onSave(): Promise<void> {
@@ -37,6 +37,6 @@ export class NewComponent implements OnInit {
} }
const id = await this.showService.new$(this.form.value); const id = await this.showService.new$(this.form.value);
await this.router.navigateByUrl('/shows/' + id); await this.router.navigateByUrl(`/shows/${id ?? ''}`);
} }
} }

View File

@@ -37,7 +37,9 @@ export class DocxService {
) {} ) {}
public async create(showId: string, options: DownloadOptions = {}): Promise<void> { public async create(showId: string, options: DownloadOptions = {}): Promise<void> {
const {show, songs, user, config} = await this.prepareData(showId); const data = await this.prepareData(showId);
if (!data) return;
const {show, songs, user, config} = data;
const type = new ShowTypePipe().transform(show.showType); const type = new ShowTypePipe().transform(show.showType);
const title = `${type} ${show.date.toDate().toLocaleDateString()}`; const title = `${type} ${show.date.toDate().toLocaleDateString()}`;
@@ -61,7 +63,12 @@ export class DocxService {
this.saveAs(blob, `${title}.docx`); this.saveAs(blob, `${title}.docx`);
} }
private prepareNewDocument(type: string, name: string, options: DownloadOptions, sections: ISectionOptions[]): Document { private prepareNewDocument(
type: string,
name: string,
options: DownloadOptions,
sections: ISectionOptions[]
): Document {
return new Document({ return new Document({
creator: name, creator: name,
title: type, title: type,
@@ -92,16 +99,29 @@ export class DocxService {
}); });
} }
private renderSongs(songs: {showSong: ShowSong; song: Song; sections: Section[]}[], options: DownloadOptions, config: Config): Paragraph[] { private renderSongs(
return songs.reduce((p: Paragraph[], song) => [...p, ...this.renderSong(song.showSong, song.song, song.sections, options, config)], []); songs: {showSong: ShowSong; song: Song; sections: Section[]}[],
options: DownloadOptions,
config: Config
): Paragraph[] {
return songs.reduce(
(p: Paragraph[], song) => [...p, ...this.renderSong(song.showSong, song.song, song.sections, options, config)],
[]
);
} }
private renderSong(showSong: ShowSong, song: Song, sections: Section[], options: DownloadOptions, config: Config): Paragraph[] { private renderSong(
showSong: ShowSong,
song: Song,
sections: Section[],
options: DownloadOptions,
config: Config
): Paragraph[] {
const songTitle = this.renderSongTitle(song); const songTitle = this.renderSongTitle(song);
const copyright = this.renderCopyright(song, options, config); const copyright = this.renderCopyright(song, options, config);
const songText = this.renderSongText(sections, options?.chordMode ?? showSong.chordMode); const songText = this.renderSongText(sections, options?.chordMode ?? showSong.chordMode);
return [songTitle, copyright, ...songText].filter(_ => _); return copyright ? [songTitle, copyright, ...songText] : [songTitle, ...songText];
} }
private renderSongText(sections: Section[], chordMode: ChordMode): Paragraph[] { private renderSongText(sections: Section[], chordMode: ChordMode): Paragraph[] {
@@ -119,7 +139,7 @@ export class DocxService {
}); });
} }
private renderCopyright(song: Song, options: DownloadOptions, config: Config): Paragraph { private renderCopyright(song: Song, options: DownloadOptions, config: Config): Paragraph | null {
if (!options?.copyright) { if (!options?.copyright) {
return null; return null;
} }
@@ -128,7 +148,10 @@ export class DocxService {
const artist = song.artist ? song.artist + ', ' : ''; const artist = song.artist ? song.artist + ', ' : '';
const termsOfUse = song.termsOfUse ? song.termsOfUse + ', ' : ''; const termsOfUse = song.termsOfUse ? song.termsOfUse + ', ' : '';
const origin = song.origin ? song.origin + ', ' : ''; const origin = song.origin ? song.origin + ', ' : '';
const licence = song.legalOwner === 'CCLI' ? 'CCLI-Liednummer: ' + song.legalOwnerId + ', CCLI-Lizenz: ' + config.ccliLicenseId : 'CCLI-Liednummer: ' + song.legalOwnerId; const licence =
song.legalOwner === 'CCLI'
? 'CCLI-Liednummer: ' + song.legalOwnerId + ', CCLI-Lizenz: ' + config.ccliLicenseId
: 'CCLI-Liednummer: ' + song.legalOwnerId;
return new Paragraph({ return new Paragraph({
text: artist + label + termsOfUse + origin + licence, text: artist + label + termsOfUse + origin + licence,
@@ -178,14 +201,18 @@ export class DocxService {
show: Show; show: Show;
user: User; user: User;
config: Config; config: Config;
}> { } | null> {
const show = await this.showService.read$(showId).pipe(first()).toPromise(); const show = await this.showService.read$(showId).pipe(first()).toPromise();
if (!show) return null;
const user = await this.userService.getUserbyId(show.owner); const user = await this.userService.getUserbyId(show.owner);
if (!user) return null;
const config = await this.configService.get(); const config = await this.configService.get();
if (!config) return null;
const showSongs = await this.showSongService.list(showId); const showSongs = await this.showSongService.list(showId);
const songsAsync = showSongs.map(async showSong => { const songsAsync = showSongs.map(async showSong => {
const song = await this.songService.read(showSong.songId); const song = await this.songService.read(showSong.songId);
if (!song) return null;
const sections = this.textRenderingService.parse(song.text, { const sections = this.textRenderingService.parse(song.text, {
baseKey: showSong.keyOriginal, baseKey: showSong.keyOriginal,
targetKey: showSong.key, targetKey: showSong.key,
@@ -196,7 +223,9 @@ export class DocxService {
sections, sections,
}; };
}); });
const songs = await Promise.all(songsAsync); const songs = (await Promise.all(songsAsync))
.filter(_ => !!_)
.map(_ => _ as {showSong: ShowSong; song: Song; sections: Section[]});
return {songs, show, user, config}; return {songs, show, user, config};
} }

View File

@@ -13,7 +13,8 @@ export class ShowDataService {
public constructor(private dbService: DbService) {} public constructor(private dbService: DbService) {}
public list$ = (queryFn?: QueryFn): Observable<Show[]> => this.dbService.col$(this.collection, queryFn); public list$ = (queryFn?: QueryFn): Observable<Show[]> => this.dbService.col$(this.collection, queryFn);
public read$ = (showId: string): Observable<Show | undefined> => this.dbService.doc$(`${this.collection}/${showId}`); public read$ = (showId: string): Observable<Show | null> => this.dbService.doc$(`${this.collection}/${showId}`);
public update = async (showId: string, data: Partial<Show>): Promise<void> => await this.dbService.doc(`${this.collection}/${showId}`).update(data); public update = async (showId: string, data: Partial<Show>): Promise<void> =>
await this.dbService.doc(`${this.collection}/${showId}`).update(data);
public add = async (data: Partial<Show>): Promise<string> => (await this.dbService.col(this.collection).add(data)).id; public add = async (data: Partial<Show>): Promise<string> => (await this.dbService.col(this.collection).add(data)).id;
} }

View File

@@ -13,10 +13,14 @@ export class ShowSongDataService {
public constructor(private dbService: DbService) {} public constructor(private dbService: DbService) {}
public list$ = (showId: string, queryFn?: QueryFn): Observable<ShowSong[]> => this.dbService.col$(`${this.collection}/${showId}/${this.subCollection}`, queryFn); public list$ = (showId: string, queryFn?: QueryFn): Observable<ShowSong[]> =>
public read$ = (showId: string, songId: string): Observable<ShowSong | undefined> => this.dbService.doc$(`${this.collection}/${showId}/${this.subCollection}/${songId}`); this.dbService.col$(`${this.collection}/${showId}/${this.subCollection}`, queryFn);
public read$ = (showId: string, songId: string): Observable<ShowSong | null> =>
this.dbService.doc$(`${this.collection}/${showId}/${this.subCollection}/${songId}`);
public update$ = async (showId: string, songId: string, data: Partial<ShowSong>): Promise<void> => public update$ = async (showId: string, songId: string, data: Partial<ShowSong>): Promise<void> =>
await this.dbService.doc(`${this.collection}/${showId}/${this.subCollection}/${songId}`).update(data); await this.dbService.doc(`${this.collection}/${showId}/${this.subCollection}/${songId}`).update(data);
public delete = async (showId: string, songId: string): Promise<void> => await this.dbService.doc(`${this.collection}/${showId}/${this.subCollection}/${songId}`).delete(); public delete = async (showId: string, songId: string): Promise<void> =>
public add = async (showId: string, data: Partial<ShowSong>): Promise<string> => (await this.dbService.col(`${this.collection}/${showId}/${this.subCollection}`).add(data)).id; await this.dbService.doc(`${this.collection}/${showId}/${this.subCollection}/${songId}`).delete();
public add = async (showId: string, data: Partial<ShowSong>): Promise<string> =>
(await this.dbService.col(`${this.collection}/${showId}/${this.subCollection}`).add(data)).id;
} }

View File

@@ -10,11 +10,16 @@ import {UserService} from '../../../services/user/user.service';
providedIn: 'root', providedIn: 'root',
}) })
export class ShowSongService { export class ShowSongService {
public constructor(private showSongDataService: ShowSongDataService, private songDataService: SongDataService, private userService: UserService) {} public constructor(
private showSongDataService: ShowSongDataService,
private songDataService: SongDataService,
private userService: UserService
) {}
public async new$(showId: string, songId: string, order: number, addedLive = false): Promise<string> { public async new$(showId: string, songId: string, order: number, addedLive = false): Promise<string | null> {
const song = await this.songDataService.read$(songId).pipe(take(1)).toPromise(); const song = await this.songDataService.read$(songId).pipe(take(1)).toPromise();
const user = await this.userService.user$.pipe(take(1)).toPromise(); const user = await this.userService.user$.pipe(take(1)).toPromise();
if (!song || !user) return null;
const data: Partial<ShowSong> = { const data: Partial<ShowSong> = {
songId, songId,
order, order,
@@ -26,8 +31,10 @@ export class ShowSongService {
return await this.showSongDataService.add(showId, data); return await this.showSongDataService.add(showId, data);
} }
public list$ = (showId: string): Observable<ShowSong[]> => this.showSongDataService.list$(showId, _ => _.orderBy('order')); public list$ = (showId: string): Observable<ShowSong[]> =>
this.showSongDataService.list$(showId, _ => _.orderBy('order'));
public list = (showId: string): Promise<ShowSong[]> => this.list$(showId).pipe(first()).toPromise(); public list = (showId: string): Promise<ShowSong[]> => this.list$(showId).pipe(first()).toPromise();
public delete$ = (showId: string, songId: string): Promise<void> => this.showSongDataService.delete(showId, songId); public delete$ = (showId: string, songId: string): Promise<void> => this.showSongDataService.delete(showId, songId);
public update$ = async (showId: string, songId: string, data: Partial<ShowSong>): Promise<void> => await this.showSongDataService.update$(showId, songId, data); public update$ = async (showId: string, songId: string, data: Partial<ShowSong>): Promise<void> =>
await this.showSongDataService.update$(showId, songId, data);
} }

View File

@@ -10,30 +10,51 @@ import {User} from '../../../services/user/user';
providedIn: 'root', providedIn: 'root',
}) })
export class ShowService { export class ShowService {
public static SHOW_TYPE = ['service-worship', 'service-praise', 'home-group-big', 'home-group', 'prayer-group', 'teens-group', 'kids-group', 'misc-public', 'misc-private']; public static SHOW_TYPE = [
public static SHOW_TYPE_PUBLIC = ['service-worship', 'service-praise', 'home-group-big', 'teens-group', 'kids-group', 'misc-public']; 'service-worship',
'service-praise',
'home-group-big',
'home-group',
'prayer-group',
'teens-group',
'kids-group',
'misc-public',
'misc-private',
];
public static SHOW_TYPE_PUBLIC = [
'service-worship',
'service-praise',
'home-group-big',
'teens-group',
'kids-group',
'misc-public',
];
public static SHOW_TYPE_PRIVATE = ['home-group', 'prayer-group', 'misc-private']; public static SHOW_TYPE_PRIVATE = ['home-group', 'prayer-group', 'misc-private'];
private user: User; private user: User | null = null;
public constructor(private showDataService: ShowDataService, private userService: UserService) { public constructor(private showDataService: ShowDataService, private userService: UserService) {
userService.user$.subscribe(_ => (this.user = _)); userService.user$.subscribe(_ => (this.user = _));
} }
public read$ = (showId: string): Observable<Show> => this.showDataService.read$(showId); public read$ = (showId: string): Observable<Show | null> => this.showDataService.read$(showId);
public list$(publishedOnly = false): Observable<Show[]> { public list$(publishedOnly = false): Observable<Show[]> {
return this.userService.user$.pipe( return this.userService.user$.pipe(
switchMap( switchMap(
() => this.showDataService.list$(), () => this.showDataService.list$(),
(user: User, shows: Show[]) => ({user, shows}) (user: User | null, shows: Show[]) => ({user, shows})
), ),
map(s => s.shows.filter(_ => !_.archived).filter(show => show.published || (show.owner === s.user.id && !publishedOnly))) map(s =>
s.shows.filter(_ => !_.archived).filter(show => show.published || (show.owner === s.user?.id && !publishedOnly))
)
); );
} }
public update$ = async (showId: string, data: Partial<Show>): Promise<void> => this.showDataService.update(showId, data); public update$ = async (showId: string, data: Partial<Show>): Promise<void> =>
this.showDataService.update(showId, data);
public async new$(data: Partial<Show>): Promise<string> { public async new$(data: Partial<Show>): Promise<string | null> {
if (!data.showType || !this.user) return null;
const calculatedData: Partial<Show> = { const calculatedData: Partial<Show> = {
...data, ...data,
owner: this.user.id, owner: this.user.id,

View File

@@ -23,11 +23,11 @@ import {faUsers} from '@fortawesome/free-solid-svg-icons/faUsers';
styleUrls: ['./show.component.less'], styleUrls: ['./show.component.less'],
}) })
export class ShowComponent implements OnInit { export class ShowComponent implements OnInit {
public show$: Observable<Show>; public show$: Observable<Show | null> | null = null;
public songs: Song[]; public songs: Song[] | null = null;
public showSongs: ShowSong[]; public showSongs: ShowSong[] | null = null;
public showId: string; public showId: string | null = null;
public showText: boolean; public showText = false;
public faBox = faBox; public faBox = faBox;
public faBoxOpen = faBoxOpen; public faBoxOpen = faBoxOpen;
@@ -47,13 +47,15 @@ export class ShowComponent implements OnInit {
public ngOnInit(): void { public ngOnInit(): void {
this.show$ = this.activatedRoute.params.pipe( this.show$ = this.activatedRoute.params.pipe(
map((param: {showId: string}) => param.showId), map(param => param as {showId: string}),
map(param => param.showId),
tap((_: string) => (this.showId = _)), tap((_: string) => (this.showId = _)),
switchMap((showId: string) => this.showService.read$(showId)) switchMap((showId: string) => this.showService.read$(showId))
); );
this.activatedRoute.params this.activatedRoute.params
.pipe( .pipe(
map((param: {showId: string}) => param.showId), map(param => param as {showId: string}),
map(param => param.showId),
switchMap(showId => this.showSongService.list$(showId)), switchMap(showId => this.showSongService.list$(showId)),
filter(_ => !!_) filter(_ => !!_)
) )
@@ -64,17 +66,18 @@ export class ShowComponent implements OnInit {
.subscribe(_ => (this.songs = _)); .subscribe(_ => (this.songs = _));
} }
public getSong(songId: string): Song { public getSong(songId: string): Song | null {
if (!this.songs) return null;
const filtered = this.songs.filter(_ => _.id === songId); const filtered = this.songs.filter(_ => _.id === songId);
return filtered.length > 0 ? filtered[0] : null; return filtered.length > 0 ? filtered[0] : null;
} }
public async onArchive(archived: boolean): Promise<void> { public async onArchive(archived: boolean): Promise<void> {
await this.showService.update$(this.showId, {archived}); if (this.showId != null) await this.showService.update$(this.showId, {archived});
} }
public async onPublish(published: boolean): Promise<void> { public async onPublish(published: boolean): Promise<void> {
await this.showService.update$(this.showId, {published}); if (this.showId != null) await this.showService.update$(this.showId, {published});
} }
public getStatus(show: Show): string { public getStatus(show: Show): string {
@@ -88,10 +91,11 @@ export class ShowComponent implements OnInit {
} }
public async onDownload(): Promise<void> { public async onDownload(): Promise<void> {
await this.docxService.create(this.showId); if (this.showId != null) await this.docxService.create(this.showId);
} }
public async onDownloadHandout(): Promise<void> { public async onDownloadHandout(): Promise<void> {
if (this.showId != null)
await this.docxService.create(this.showId, { await this.docxService.create(this.showId, {
chordMode: 'hide', chordMode: 'hide',
copyright: true, copyright: true,

View File

@@ -1,4 +1,4 @@
<div *ngIf="iSong"> <div *ngIf="iSong && showSong && show">
<div *ngIf="show.published" class="title published">{{ iSong.title }}</div> <div *ngIf="show.published" class="title published">{{ iSong.title }}</div>
<div *ngIf="!show.published" class="song"> <div *ngIf="!show.published" class="song">

View File

@@ -16,18 +16,18 @@ import {Show} from '../../services/show';
styleUrls: ['./song.component.less'], styleUrls: ['./song.component.less'],
}) })
export class SongComponent implements OnInit { export class SongComponent implements OnInit {
@Input() public show: Show; @Input() public show: Show | null = null;
@Input() public showSong: ShowSong; @Input() public showSong: ShowSong | null = null;
@Input() public showSongs: ShowSong[]; @Input() public showSongs: ShowSong[] | null = null;
@Input() public showId: string; @Input() public showId: string | null = null;
@Input() public showText: boolean; @Input() public showText: boolean | null = null;
public keys: string[]; public keys: string[] = [];
public faDelete = faTrash; public faDelete = faTrash;
public faUp = faCaretUp; public faUp = faCaretUp;
public faDown = faCaretDown; public faDown = faCaretDown;
public keyFormControl: FormControl; public keyFormControl: FormControl = new FormControl();
public iSong: Song; public iSong: Song | null = null;
public constructor(private showSongService: ShowSongService) {} public constructor(private showSongService: ShowSongService) {}
@@ -38,13 +38,16 @@ export class SongComponent implements OnInit {
} }
public ngOnInit(): void { public ngOnInit(): void {
if (!this.showSong) return;
this.keyFormControl = new FormControl(this.showSong.key); this.keyFormControl = new FormControl(this.showSong.key);
this.keyFormControl.valueChanges.subscribe((value: string) => { this.keyFormControl.valueChanges.subscribe((value: string) => {
if (!this.showId || !this.showSong) return;
void this.showSongService.update$(this.showId, this.showSong.id, {key: value}); void this.showSongService.update$(this.showId, this.showSong.id, {key: value});
}); });
} }
public async onDelete(): Promise<void> { public async onDelete(): Promise<void> {
if (!this.showId || !this.showSong) return;
await this.showSongService.delete$(this.showId, this.showSong.id); await this.showSongService.delete$(this.showId, this.showSong.id);
} }
@@ -57,7 +60,8 @@ export class SongComponent implements OnInit {
} }
public async reorderUp(): Promise<void> { public async reorderUp(): Promise<void> {
const index = this.showSongs.findIndex(_ => _.songId === this.iSong.id); if (!this.showSongs || !this.showId) return;
const index = this.showSongs.findIndex(_ => _.songId === this.iSong?.id);
if (index === 0) { if (index === 0) {
return; return;
} }
@@ -74,7 +78,8 @@ export class SongComponent implements OnInit {
} }
public async reorderDown(): Promise<void> { public async reorderDown(): Promise<void> {
const index = this.showSongs.findIndex(_ => _.songId === this.iSong.id); if (!this.showSongs || !this.showId) return;
const index = this.showSongs.findIndex(_ => _.songId === this.iSong?.id);
if (index === this.showSongs.length - 1) { if (index === this.showSongs.length - 1) {
return; return;
} }
@@ -91,6 +96,7 @@ export class SongComponent implements OnInit {
} }
public async onChordModeChanged(value: ChordMode): Promise<void> { public async onChordModeChanged(value: ChordMode): Promise<void> {
if (!this.showId || !this.showSong) return;
await this.showSongService.update$(this.showId, this.showSong.id, { await this.showSongService.update$(this.showId, this.showSong.id, {
chordMode: value, chordMode: value,
}); });

View File

@@ -2,6 +2,6 @@ export interface Chord {
chord: string; chord: string;
length: number; length: number;
position: number; position: number;
slashChord?: string; slashChord: string | null;
add?: string; add: string | null;
} }

View File

@@ -4,5 +4,5 @@ import {Chord} from './chord';
export interface Line { export interface Line {
type: LineType; type: LineType;
text: string; text: string;
chords?: Chord[]; chords: Chord[] | null;
} }

View File

@@ -12,8 +12,10 @@ export class SongDataService {
public constructor(private dbService: DbService) {} public constructor(private dbService: DbService) {}
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 | null> => 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(); public delete = async (songId: string): Promise<void> =>
await this.dbService.doc(this.collection + '/' + songId).delete();
} }

View File

@@ -26,13 +26,15 @@ export class SongService {
} }
public list$ = (): Observable<Song[]> => this.songDataService.list$(); //.pipe(tap(_ => (this.list = _))); public list$ = (): Observable<Song[]> => this.songDataService.list$(); //.pipe(tap(_ => (this.list = _)));
public read$ = (songId: string): Observable<Song | undefined> => this.songDataService.read$(songId); public read$ = (songId: string): Observable<Song | null> => this.songDataService.read$(songId);
public read = (songId: string): Promise<Song | undefined> => this.read$(songId).pipe(first()).toPromise(); public read = (songId: string): Promise<Song | null> => this.read$(songId).pipe(first()).toPromise();
public async update$(songId: string, data: Partial<Song>): Promise<void> { public async update$(songId: string, data: Partial<Song>): Promise<void> {
const song = await this.read(songId); const song = await this.read(songId);
if (!song) return;
const edits = song.edits ?? []; const edits = song.edits ?? [];
const user = await this.userService.currentUser(); const user = await this.userService.currentUser();
if (!user) return;
edits.push({username: user.name, timestamp: Timestamp.now()}); edits.push({username: user.name, timestamp: Timestamp.now()});
await this.songDataService.update$(songId, {...data, edits}); await this.songDataService.update$(songId, {...data, edits});
} }

View File

@@ -15,7 +15,7 @@ export class TextRenderingService {
public constructor(private transposeService: TransposeService) {} public constructor(private transposeService: TransposeService) {}
public parse(text: string, transpose: TransposeMode): Section[] { public parse(text: string, transpose: TransposeMode | null): Section[] {
if (!text) { if (!text) {
return []; return [];
} }
@@ -27,22 +27,21 @@ export class TextRenderingService {
}; };
return arrayOfLines.reduce((array, line) => { return arrayOfLines.reduce((array, line) => {
const type = this.getSectionTypeOfLine(line); const type = this.getSectionTypeOfLine(line);
if (this.regexSection.exec(line)) { if (this.regexSection.exec(line) && type !== null) {
return [ const section: Section = {
...array,
{
type, type,
number: indices[type]++, number: indices[type]++,
lines: [], lines: [],
}, };
]; return [...array, section];
} }
array[array.length - 1].lines.push(this.getLineOfLineText(line, transpose)); const lineOfLineText = this.getLineOfLineText(line, transpose);
if (lineOfLineText) array[array.length - 1].lines.push(lineOfLineText);
return array; return array;
}, [] as Section[]); }, [] as Section[]);
} }
private getLineOfLineText(text: string, transpose: TransposeMode): Line { private getLineOfLineText(text: string, transpose: TransposeMode | null): Line | null {
if (!text) { if (!text) {
return null; return null;
} }
@@ -50,11 +49,13 @@ export class TextRenderingService {
const hasMatches = cords.length > 0; const hasMatches = cords.length > 0;
const type = hasMatches ? LineType.chord : LineType.text; const type = hasMatches ? LineType.chord : LineType.text;
const line = {type, text, chords: hasMatches ? cords : undefined}; const line: Line = {type, text, chords: hasMatches ? cords : null};
return transpose ? this.transposeService.transpose(line, transpose.baseKey, transpose.targetKey) : this.transposeService.renderChords(line); return transpose
? this.transposeService.transpose(line, transpose.baseKey, transpose.targetKey)
: this.transposeService.renderChords(line);
} }
private getSectionTypeOfLine(line: string): SectionType { private getSectionTypeOfLine(line: string): SectionType | null {
if (!line) { if (!line) {
return null; return null;
} }
@@ -71,10 +72,12 @@ export class TextRenderingService {
case 'Bridge': case 'Bridge':
return SectionType.Bridge; return SectionType.Bridge;
} }
return null;
} }
private readChords(chordLine: string): Chord[] { private readChords(chordLine: string): Chord[] {
let match: string[]; let match: string[] | null;
const chords: Chord[] = []; const chords: Chord[] = [];
// https://regex101.com/r/68jMB8/5 // https://regex101.com/r/68jMB8/5
@@ -86,6 +89,8 @@ export class TextRenderingService {
chord: match[1], chord: match[1],
length: match[0].length, length: match[0].length,
position: regex.lastIndex - match[0].length, position: regex.lastIndex - match[0].length,
slashChord: null,
add: null,
}; };
if (match[3]) { if (match[3]) {
chord.slashChord = match[3]; chord.slashChord = match[3];

View File

@@ -17,8 +17,9 @@ export class TransposeService {
const difference = this.getDistance(baseKey, targetKey); const difference = this.getDistance(baseKey, targetKey);
const map = this.getMap(baseKey, difference); const map = this.getMap(baseKey, difference);
const chords = difference > 0 ? line.chords.map(chord => this.transposeChord(chord, map)) : line.chords; const chords =
const renderedLine = this.renderLine(chords); difference > 0 && line.chords && map ? line.chords.map(chord => this.transposeChord(chord, map)) : line.chords;
const renderedLine = this.renderLine(chords ?? []);
return {...line, text: renderedLine, chords}; return {...line, text: renderedLine, chords};
} }
@@ -28,13 +29,16 @@ export class TransposeService {
return line; return line;
} }
const renderedLine = this.renderLine(line.chords); const renderedLine = this.renderLine(line.chords ?? []);
return {...line, text: renderedLine}; return {...line, text: renderedLine};
} }
public getDistance(baseKey: string, targetKey: string): number { public getDistance(baseKey: string, targetKey: string): number {
const scale = getScaleType(baseKey); const scale = getScaleType(baseKey);
return scale ? (scale[0].indexOf(targetKey) - scale[0].indexOf(baseKey) ?? scale[1].indexOf(targetKey) - scale[1].indexOf(baseKey)) % 12 : 0; return scale
? (scale[0].indexOf(targetKey) - scale[0].indexOf(baseKey) ??
scale[1].indexOf(targetKey) - scale[1].indexOf(baseKey)) % 12
: 0;
} }
public getMap(baseKey: string, difference: number): TransposeMap | null { public getMap(baseKey: string, difference: number): TransposeMap | null {
@@ -42,7 +46,7 @@ export class TransposeService {
if (!scale) { if (!scale) {
return null; return null;
} }
const map = {}; const map: {[key: string]: string} = {};
for (let i = 0; i < 12; i++) { for (let i = 0; i < 12; i++) {
const source = scale[0][i]; const source = scale[0][i];
const mappedIndex = (i + difference) % 12; const mappedIndex = (i + difference) % 12;
@@ -68,7 +72,8 @@ export class TransposeService {
} }
private renderLine(chords: Chord[]): string { private renderLine(chords: Chord[]): string {
let template = ' '; let template =
' ';
chords.forEach(chord => { chords.forEach(chord => {
const pos = chord.position; const pos = chord.position;
@@ -85,6 +90,10 @@ export class TransposeService {
} }
private renderChord(chord: Chord) { private renderChord(chord: Chord) {
return scaleMapping[chord.chord] + (chord.add ? chord.add : '') + (chord.slashChord ? '/' + scaleMapping[chord.slashChord] : ''); return (
scaleMapping[chord.chord] +
(chord.add ? chord.add : '') +
(chord.slashChord ? '/' + scaleMapping[chord.slashChord] : '')
);
} }
} }

View File

@@ -22,7 +22,7 @@ export class UploadService extends FileBase {
const ref = this.angularFireStorage.ref(filePath); const ref = this.angularFireStorage.ref(filePath);
const task = ref.put(upload.file); const task = ref.put(upload.file);
task.percentageChanges().subscribe(percent => (upload.progress = percent)); task.percentageChanges().subscribe(percent => (upload.progress = percent ?? 0));
task task
.snapshotChanges() .snapshotChanges()
.pipe(finalize(() => void this.saveFileData(songId, upload))) .pipe(finalize(() => void this.saveFileData(songId, upload)))

View File

@@ -1,9 +1,8 @@
export class Upload { export class Upload {
public $key: string;
public file: File; public file: File;
public name: string; public name = '';
public path: string; public path = '';
public progress: number; public progress = 0;
public createdAt: Date = new Date(); public createdAt: Date = new Date();
public constructor(file: File) { public constructor(file: File) {

View File

@@ -13,8 +13,8 @@ import {KEYS} from '../../services/key.helper';
}) })
export class FilterComponent { export class FilterComponent {
public filterFormGroup: FormGroup; public filterFormGroup: FormGroup;
@Input() public route: string; @Input() public route = '/';
@Input() public songs: Song[]; @Input() public songs: Song[] = [];
public types = SongService.TYPES; public types = SongService.TYPES;
public legalType = SongService.LEGAL_TYPE; public legalType = SongService.LEGAL_TYPE;
public keys = KEYS; public keys = KEYS;
@@ -28,7 +28,8 @@ export class FilterComponent {
flag: '', flag: '',
}); });
activatedRoute.queryParams.subscribe((filterValues: FilterValues) => { activatedRoute.queryParams.subscribe(params => {
const filterValues = params as FilterValues;
if (filterValues.q) this.filterFormGroup.controls.q.setValue(filterValues.q); if (filterValues.q) this.filterFormGroup.controls.q.setValue(filterValues.q);
if (filterValues.type) this.filterFormGroup.controls.type.setValue(filterValues.type); if (filterValues.type) this.filterFormGroup.controls.type.setValue(filterValues.type);
if (filterValues.key) this.filterFormGroup.controls.key.setValue(filterValues.key); if (filterValues.key) this.filterFormGroup.controls.key.setValue(filterValues.key);

View File

@@ -1,4 +1,4 @@
<div class="list-item"> <div class="list-item" *ngIf="song">
<div class="number">{{ song.number }}</div> <div class="number">{{ song.number }}</div>
<div>{{ song.title }}</div> <div>{{ song.title }}</div>
<div> <div>

View File

@@ -10,7 +10,7 @@ import {faCheck} from '@fortawesome/free-solid-svg-icons/faCheck';
styleUrls: ['./list-item.component.less'], styleUrls: ['./list-item.component.less'],
}) })
export class ListItemComponent { export class ListItemComponent {
@Input() public song: Song; @Input() public song: Song | null = null;
public faLegal = faBalanceScaleRight; public faLegal = faBalanceScaleRight;
public faDraft = faPencilRuler; public faDraft = faPencilRuler;
public faFinal = faCheck; public faFinal = faCheck;

View File

@@ -16,10 +16,14 @@ import {ScrollService} from '../../../services/scroll.service';
animations: [fade], animations: [fade],
}) })
export class SongListComponent implements OnInit, OnDestroy { export class SongListComponent implements OnInit, OnDestroy {
public songs$: Observable<Song[]>; public songs$: Observable<Song[]> | null = null;
public anyFilterActive = false; public anyFilterActive = false;
public constructor(private songService: SongService, private activatedRoute: ActivatedRoute, private scrollService: ScrollService) {} public constructor(
private songService: SongService,
private activatedRoute: ActivatedRoute,
private scrollService: ScrollService
) {}
public ngOnInit(): void { public ngOnInit(): void {
const filter$ = this.activatedRoute.queryParams.pipe( const filter$ = this.activatedRoute.queryParams.pipe(

View File

@@ -13,18 +13,28 @@ import {File} from '../../../services/file';
styleUrls: ['./edit-file.component.less'], styleUrls: ['./edit-file.component.less'],
}) })
export class EditFileComponent { export class EditFileComponent {
public selectedFiles: FileList; public selectedFiles: FileList | null = null;
public currentUpload: Upload; public currentUpload: Upload | null = null;
public songId: string; public songId: string | null = null;
public files$: Observable<File[]>; public files$: Observable<File[]>;
public constructor(private activatedRoute: ActivatedRoute, private uploadService: UploadService, private fileService: FileDataService) { public constructor(
this.activatedRoute.params.pipe(map((param: {songId: string}) => param.songId)).subscribe(songId => { private activatedRoute: ActivatedRoute,
private uploadService: UploadService,
private fileService: FileDataService
) {
this.activatedRoute.params
.pipe(
map(param => param as {songId: string}),
map(param => param.songId)
)
.subscribe(songId => {
this.songId = songId; this.songId = songId;
}); });
this.files$ = this.activatedRoute.params.pipe( this.files$ = this.activatedRoute.params.pipe(
map((param: {songId: string}) => param.songId), map(param => param as {songId: string}),
map(param => param.songId),
switchMap(songId => this.fileService.read$(songId)) switchMap(songId => this.fileService.read$(songId))
); );
} }
@@ -35,7 +45,9 @@ export class EditFileComponent {
} }
public uploadSingle(): void { public uploadSingle(): void {
if (!this.selectedFiles || !this.songId) return;
const file = this.selectedFiles.item(0); const file = this.selectedFiles.item(0);
if (!file) return;
this.currentUpload = new Upload(file); this.currentUpload = new Upload(file);
this.uploadService.pushUpload(this.songId, this.currentUpload); this.uploadService.pushUpload(this.songId, this.currentUpload);
} }

View File

@@ -10,12 +10,12 @@ import {FileService} from '../../../../services/file.service';
styleUrls: ['./file.component.less'], styleUrls: ['./file.component.less'],
}) })
export class FileComponent { export class FileComponent {
public url$: Observable<string>; public url$: Observable<string> | null = null;
public name: string; public name = '';
public faTrash = faTrashAlt; public faTrash = faTrashAlt;
@Input() public songId: string; @Input() public songId: string | null = null;
private fileId: string; private fileId: string | null = null;
private path: string; private path: string | null = null;
public constructor(private fileService: FileService) {} public constructor(private fileService: FileService) {}
@@ -28,6 +28,6 @@ export class FileComponent {
} }
public async onDelete(): Promise<void> { public async onDelete(): Promise<void> {
await this.fileService.delete(this.path, this.songId, this.fileId); if (this.path && this.songId && this.fileId) await this.fileService.delete(this.path, this.songId, this.fileId);
} }
} }

View File

@@ -6,13 +6,13 @@ import {EditComponent} from './edit.component';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class EditSongGuard implements CanDeactivate<unknown> { export class EditSongGuard implements CanDeactivate<EditComponent> {
public canDeactivate( public canDeactivate(
component: EditComponent, component: EditComponent,
currentRoute: ActivatedRouteSnapshot, currentRoute: ActivatedRouteSnapshot,
currentState: RouterStateSnapshot, currentState: RouterStateSnapshot,
nextState?: RouterStateSnapshot nextState: RouterStateSnapshot
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { ): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return component.editSongComponent.askForSave(nextState); return component.editSongComponent ? component.editSongComponent.askForSave(nextState) : true;
} }
} }

View File

@@ -20,8 +20,8 @@ import {SaveDialogComponent} from './save-dialog/save-dialog.component';
styleUrls: ['./edit-song.component.less'], styleUrls: ['./edit-song.component.less'],
}) })
export class EditSongComponent implements OnInit { export class EditSongComponent implements OnInit {
public song: Song; public song: Song | null = null;
public form: FormGroup; public form: FormGroup = new FormGroup({});
public keys = KEYS; public keys = KEYS;
public types = SongService.TYPES; public types = SongService.TYPES;
public status = SongService.STATUS; public status = SongService.STATUS;
@@ -34,17 +34,25 @@ export class EditSongComponent implements OnInit {
public faLink = faExternalLinkAlt; public faLink = faExternalLinkAlt;
public songtextFocus = false; public songtextFocus = false;
public constructor(private activatedRoute: ActivatedRoute, private songService: SongService, private editService: EditService, private router: Router, public dialog: MatDialog) {} public constructor(
private activatedRoute: ActivatedRoute,
private songService: SongService,
private editService: EditService,
private router: Router,
public dialog: MatDialog
) {}
public ngOnInit(): void { public ngOnInit(): void {
this.activatedRoute.params this.activatedRoute.params
.pipe( .pipe(
map((param: {songId: string}) => param.songId), map(param => param as {songId: string}),
map(param => param.songId),
switchMap(songId => this.songService.read$(songId)), switchMap(songId => this.songService.read$(songId)),
first() first()
) )
.subscribe(song => { .subscribe(song => {
this.song = song; this.song = song;
if (!song) return;
this.form = this.editService.createSongForm(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); this.onFlagsChanged(this.form.controls.flags.value);
@@ -52,6 +60,7 @@ export class EditSongComponent implements OnInit {
} }
public async onSave(): Promise<void> { public async onSave(): Promise<void> {
if (!this.song) return;
const data = this.form.value as Partial<Song>; const data = this.form.value as Partial<Song>;
await this.songService.update$(this.song.id, data); await this.songService.update$(this.song.id, data);
this.form.markAsPristine(); this.form.markAsPristine();
@@ -78,7 +87,7 @@ export class EditSongComponent implements OnInit {
} }
} }
public askForSave(nextState?: RouterStateSnapshot): boolean { public askForSave(nextState: RouterStateSnapshot): boolean {
if (!this.form.dirty) { if (!this.form.dirty) {
return true; return true;
} }
@@ -104,7 +113,7 @@ export class EditSongComponent implements OnInit {
} }
private async onSaveDialogAfterClosed(save: boolean, url: string) { private async onSaveDialogAfterClosed(save: boolean, url: string) {
if (save) { if (save && this.song) {
const data = this.form.value as Partial<Song>; const data = this.form.value as Partial<Song>;
await this.songService.update$(this.song.id, data); await this.songService.update$(this.song.id, data);
} }

View File

@@ -7,5 +7,5 @@ import {EditSongComponent} from './edit-song/edit-song.component';
styleUrls: ['./edit.component.less'], styleUrls: ['./edit.component.less'],
}) })
export class EditComponent { export class EditComponent {
@ViewChild(EditSongComponent) public editSongComponent: EditSongComponent; @ViewChild(EditSongComponent) public editSongComponent: EditSongComponent | null = null;
} }

View File

@@ -28,7 +28,14 @@ import {HistoryComponent} from './history/history.component';
import {SongTextModule} from '../../../../widget-modules/components/song-text/song-text.module'; import {SongTextModule} from '../../../../widget-modules/components/song-text/song-text.module';
@NgModule({ @NgModule({
declarations: [EditComponent, EditSongComponent, EditFileComponent, FileComponent, SaveDialogComponent, HistoryComponent], declarations: [
EditComponent,
EditSongComponent,
EditFileComponent,
FileComponent,
SaveDialogComponent,
HistoryComponent,
],
exports: [EditComponent], exports: [EditComponent],
bootstrap: [SaveDialogComponent], bootstrap: [SaveDialogComponent],
imports: [ imports: [

View File

@@ -10,14 +10,15 @@ import {Song} from '../../../services/song';
styleUrls: ['./history.component.less'], styleUrls: ['./history.component.less'],
}) })
export class HistoryComponent implements OnInit { export class HistoryComponent implements OnInit {
public song: Song; public song: Song | null = null;
public constructor(private activatedRoute: ActivatedRoute, private songService: SongService) {} public constructor(private activatedRoute: ActivatedRoute, private songService: SongService) {}
public ngOnInit(): void { public ngOnInit(): void {
this.activatedRoute.params this.activatedRoute.params
.pipe( .pipe(
map((param: {songId: string}) => param.songId), map(param => param as {songId: string}),
map(param => param.songId),
switchMap(songId => this.songService.read$(songId)), switchMap(songId => this.songService.read$(songId)),
first() first()
) )

View File

@@ -9,8 +9,8 @@ import {Observable} from 'rxjs';
styleUrls: ['./file.component.less'], styleUrls: ['./file.component.less'],
}) })
export class FileComponent { export class FileComponent {
public url$: Observable<string>; public url$: Observable<string> | null = null;
public name: string; public name = '';
public constructor(private storage: AngularFireStorage) {} public constructor(private storage: AngularFireStorage) {}

View File

@@ -1,36 +1,39 @@
import {Component, OnInit} from '@angular/core'; import {Component, OnDestroy, OnInit} from '@angular/core';
import {faSave} from '@fortawesome/free-solid-svg-icons/faSave'; import {faSave} from '@fortawesome/free-solid-svg-icons/faSave';
import {FormControl, FormGroup, Validators} from '@angular/forms'; import {FormControl, FormGroup, Validators} from '@angular/forms';
import {autoComplete, Unsubscriber} from 'ngx-hocs-unsubscriber';
import {SongService} from '../../services/song.service'; import {SongService} from '../../services/song.service';
import {Song} from '../../services/song'; import {Song} from '../../services/song';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {Subscription} from 'rxjs';
@Unsubscriber()
@Component({ @Component({
selector: 'app-new', selector: 'app-new',
templateUrl: './new.component.html', templateUrl: './new.component.html',
styleUrls: ['./new.component.less'], styleUrls: ['./new.component.less'],
}) })
export class NewComponent implements OnInit { export class NewComponent implements OnInit, OnDestroy {
public faSave = faSave; public faSave = faSave;
public form: FormGroup; public form: FormGroup = new FormGroup({
public constructor(private songService: SongService, private router: Router) {}
public ngOnInit(): void {
this.form = new FormGroup({
number: new FormControl(null, Validators.required), number: new FormControl(null, Validators.required),
title: new FormControl(null, Validators.required), title: new FormControl(null, Validators.required),
}); });
this.songService public constructor(private songService: SongService, private router: Router) {}
.list$()
.pipe(autoComplete(this)) public ngOnInit(): void {
.subscribe(songs => { this.form.reset();
this.subs.push(
this.songService.list$().subscribe(songs => {
const freeSongnumber = this.getFreeSongNumber(songs); const freeSongnumber = this.getFreeSongNumber(songs);
this.form.controls.number.setValue(freeSongnumber); this.form.controls.number.setValue(freeSongnumber);
}); })
);
}
private subs: Subscription[] = [];
public ngOnDestroy(): void {
this.subs.forEach(_ => _.unsubscribe());
} }
public async onSave(): Promise<void> { public async onSave(): Promise<void> {
@@ -48,5 +51,6 @@ export class NewComponent implements OnInit {
return i; return i;
} }
} }
return Number.MAX_SAFE_INTEGER;
} }
} }

View File

@@ -11,6 +11,15 @@ import {AutofocusModule} from '../../../../widget-modules/directives/autofocus/a
@NgModule({ @NgModule({
declarations: [NewComponent], declarations: [NewComponent],
imports: [CommonModule, CardModule, ReactiveFormsModule, MatFormFieldModule, MatInputModule, ButtonRowModule, ButtonModule, AutofocusModule], imports: [
CommonModule,
CardModule,
ReactiveFormsModule,
MatFormFieldModule,
MatInputModule,
ButtonRowModule,
ButtonModule,
AutofocusModule,
],
}) })
export class NewModule {} export class NewModule {}

View File

@@ -17,24 +17,32 @@ import {faTrash} from '@fortawesome/free-solid-svg-icons/faTrash';
styleUrls: ['./song.component.less'], styleUrls: ['./song.component.less'],
}) })
export class SongComponent implements OnInit { export class SongComponent implements OnInit {
public song$: Observable<Song>; public song$: Observable<Song | null> | null = null;
public files$: Observable<File[]>; public files$: Observable<File[] | null> | null = null;
public user$: Observable<User>; public user$: Observable<User | null> | null = null;
public faEdit = faEdit; public faEdit = faEdit;
public faDelete = faTrash; public faDelete = faTrash;
public constructor(private activatedRoute: ActivatedRoute, private songService: SongService, private fileService: FileDataService, private userService: UserService, private router: Router) { public constructor(
private activatedRoute: ActivatedRoute,
private songService: SongService,
private fileService: FileDataService,
private userService: UserService,
private router: Router
) {
this.user$ = userService.user$; this.user$ = userService.user$;
} }
public ngOnInit(): void { public ngOnInit(): void {
this.song$ = this.activatedRoute.params.pipe( this.song$ = this.activatedRoute.params.pipe(
map((param: {songId: string}) => param.songId), map(param => param as {songId: string}),
map(param => param.songId),
switchMap(songId => this.songService.read$(songId)) switchMap(songId => this.songService.read$(songId))
); );
this.files$ = this.activatedRoute.params.pipe( this.files$ = this.activatedRoute.params.pipe(
map((param: {songId: string}) => param.songId), map(param => param as {songId: string}),
map(param => param.songId),
switchMap(songId => this.fileService.read$(songId)) switchMap(songId => this.fileService.read$(songId))
); );
} }

View File

@@ -11,7 +11,7 @@ import {faSignOutAlt} from '@fortawesome/free-solid-svg-icons/faSignOutAlt';
styleUrls: ['./info.component.less'], styleUrls: ['./info.component.less'],
}) })
export class InfoComponent implements OnInit { export class InfoComponent implements OnInit {
public user$: Observable<User>; public user$: Observable<User | null> | null = null;
public faSignOut = faSignOutAlt; public faSignOut = faSignOutAlt;
public constructor(private userService: UserService) {} public constructor(private userService: UserService) {}

View File

@@ -19,5 +19,7 @@ export class RolePipe implements PipeTransform {
case 'presenter': case 'presenter':
return 'Präsentator'; return 'Präsentator';
} }
return 'keine Rolle';
} }
} }

View File

@@ -10,9 +10,9 @@ import {faTimes} from '@fortawesome/free-solid-svg-icons/faTimes';
styleUrls: ['./user.component.less'], styleUrls: ['./user.component.less'],
}) })
export class UserComponent { export class UserComponent {
public id: string; public id = '';
public name: string; public name = '';
public roles: string[]; public roles: string[] = [];
public ROLE_TYPES = ROLE_TYPES; public ROLE_TYPES = ROLE_TYPES;
public edit = false; public edit = false;
public faClose = faTimes; public faClose = faTimes;

View File

@@ -11,18 +11,18 @@ import {faUserPlus} from '@fortawesome/free-solid-svg-icons/faUserPlus';
styleUrls: ['./login.component.less'], styleUrls: ['./login.component.less'],
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
public form: FormGroup; public form: FormGroup = new FormGroup({
public errorMessage: string; user: new FormControl(null, [Validators.required, Validators.email]),
pass: new FormControl(null, [Validators.required]),
});
public errorMessage = '';
public faSignIn = faSignInAlt; public faSignIn = faSignInAlt;
public faNewUser = faUserPlus; public faNewUser = faUserPlus;
public constructor(private userService: UserService, private router: Router) {} public constructor(private userService: UserService, private router: Router) {}
public ngOnInit(): void { public ngOnInit(): void {
this.form = new FormGroup({ this.form.reset;
user: new FormControl(null, [Validators.required, Validators.email]),
pass: new FormControl(null, [Validators.required]),
});
} }
public async onLogin(): Promise<void> { public async onLogin(): Promise<void> {

View File

@@ -9,17 +9,17 @@ import {faUserPlus} from '@fortawesome/free-solid-svg-icons/faUserPlus';
styleUrls: ['./new.component.less'], styleUrls: ['./new.component.less'],
}) })
export class NewComponent implements OnInit { export class NewComponent implements OnInit {
public form: FormGroup; public form: FormGroup = this.fb.group({
email: new FormControl(null, [Validators.required, Validators.email]),
name: new FormControl(null, [Validators.required]),
password: new FormControl(null, [Validators.required, Validators.minLength(6)]),
});
public faNewUser = faUserPlus; public faNewUser = faUserPlus;
public constructor(private fb: FormBuilder, private userService: UserService) {} public constructor(private fb: FormBuilder, private userService: UserService) {}
public ngOnInit(): void { public ngOnInit(): void {
this.form = this.fb.group({ this.form.reset();
email: new FormControl(null, [Validators.required, Validators.email]),
name: new FormControl(null, [Validators.required]),
password: new FormControl(null, [Validators.required, Validators.minLength(6)]),
});
} }
public async onCreate(): Promise<void> { public async onCreate(): Promise<void> {

View File

@@ -1,5 +1,5 @@
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {AbstractControl, FormControl, FormGroup, Validators} from '@angular/forms'; import {FormControl, FormGroup, Validators} from '@angular/forms';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {UserService} from '../../../services/user/user.service'; import {UserService} from '../../../services/user/user.service';
import {faWindowRestore} from '@fortawesome/free-solid-svg-icons/faWindowRestore'; import {faWindowRestore} from '@fortawesome/free-solid-svg-icons/faWindowRestore';
@@ -10,18 +10,17 @@ import {faWindowRestore} from '@fortawesome/free-solid-svg-icons/faWindowRestore
styleUrls: ['./password.component.less'], styleUrls: ['./password.component.less'],
}) })
export class PasswordComponent implements OnInit { export class PasswordComponent implements OnInit {
public form: FormGroup; public form: FormGroup = new FormGroup({
public errorMessage: string; user: new FormControl(null, [Validators.required, Validators.email]),
});
public errorMessage = '';
public faNewPassword = faWindowRestore; public faNewPassword = faWindowRestore;
public constructor(public userService: UserService, private router: Router) {} public constructor(public userService: UserService, private router: Router) {}
public ngOnInit(): void { public ngOnInit(): void {
const required = (c: AbstractControl) => Validators.required(c); this.form.reset();
const email = Validators.email;
this.form = new FormGroup({
user: new FormControl(null, [required, email]),
});
} }
public async onResetPassword(): Promise<void> { public async onResetPassword(): Promise<void> {

View File

@@ -24,7 +24,18 @@ import {LogoModule} from '../../widget-modules/components/logo/logo.module';
import {FontAwesomeModule} from '@fortawesome/angular-fontawesome'; import {FontAwesomeModule} from '@fortawesome/angular-fontawesome';
@NgModule({ @NgModule({
declarations: [LoginComponent, AuthMessagePipe, InfoComponent, LogoutComponent, RolePipe, PasswordComponent, PasswordSendComponent, UsersComponent, UserComponent, NewComponent], declarations: [
LoginComponent,
AuthMessagePipe,
InfoComponent,
LogoutComponent,
RolePipe,
PasswordComponent,
PasswordSendComponent,
UsersComponent,
UserComponent,
NewComponent,
],
imports: [ imports: [
CommonModule, CommonModule,
UserRoutingModule, UserRoutingModule,

View File

@@ -10,11 +10,11 @@ import {first} from 'rxjs/operators';
export class ConfigService { export class ConfigService {
public constructor(private db: DbService) {} public constructor(private db: DbService) {}
public get get$(): Observable<Config> { public get get$(): Observable<Config | null> {
return this.db.doc$<Config>('global/config'); return this.db.doc$<Config>('global/config');
} }
public async get(): Promise<Config> { public async get(): Promise<Config | null> {
return await this.db.doc$<Config>('global/config').pipe(first()).toPromise(); return await this.db.doc$<Config>('global/config').pipe(first()).toPromise();
} }
} }

View File

@@ -1,3 +1,4 @@
export interface Config { export interface Config {
id: string;
ccliLicenseId: string; ccliLicenseId: string;
} }

View File

@@ -2,6 +2,7 @@ import {Injectable} from '@angular/core';
import {AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument} from '@angular/fire/firestore'; import {AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument} from '@angular/fire/firestore';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
import {QueryFn} from '@angular/fire/firestore/interfaces'; import {QueryFn} from '@angular/fire/firestore/interfaces';
import {map} from 'rxjs/operators';
type CollectionPredicate<T> = string | AngularFirestoreCollection<T>; type CollectionPredicate<T> = string | AngularFirestoreCollection<T>;
type DocumentPredicate<T> = string | AngularFirestoreDocument<T>; type DocumentPredicate<T> = string | AngularFirestoreDocument<T>;
@@ -20,8 +21,10 @@ export class DbService {
return typeof ref === 'string' ? this.afs.doc<T>(ref) : ref; return typeof ref === 'string' ? this.afs.doc<T>(ref) : ref;
} }
public doc$<T>(ref: DocumentPredicate<T>): Observable<T> { public doc$<T>(ref: DocumentPredicate<T>): Observable<(T & {id: string}) | null> {
return this.doc(ref).valueChanges({idField: 'id'}); return this.doc(ref)
.valueChanges({idField: 'id'})
.pipe(map(_ => (_ ? _ : null)));
} }
public col$<T>(ref: CollectionPredicate<T>, queryFn?: QueryFn): Observable<T[]> { public col$<T>(ref: CollectionPredicate<T>, queryFn?: QueryFn): Observable<T[]> {

View File

@@ -5,8 +5,8 @@ export function filterSong(song: Song, filterValue: string): boolean {
return true; return true;
} }
const textMatch = song.text && normalize(song.text).indexOf(normalize(filterValue)) !== -1; const textMatch = !!song.text && normalize(song.text).indexOf(normalize(filterValue)) !== -1;
const titleMatch = song.title && normalize(song.title).indexOf(normalize(filterValue)) !== -1; const titleMatch = !!song.title && normalize(song.title).indexOf(normalize(filterValue)) !== -1;
return textMatch || titleMatch; return textMatch || titleMatch;
} }

View File

@@ -9,7 +9,7 @@ import {Observable} from 'rxjs';
export class GlobalSettingsService { export class GlobalSettingsService {
public constructor(private db: DbService) {} public constructor(private db: DbService) {}
public get get$(): Observable<GlobalSettings> { public get get$(): Observable<GlobalSettings | null> {
return this.db.doc$<GlobalSettings>('global/static'); return this.db.doc$<GlobalSettings>('global/static');
} }

View File

@@ -5,7 +5,7 @@ import {BehaviorSubject} from 'rxjs';
providedIn: 'root', providedIn: 'root',
}) })
export class ScrollService { export class ScrollService {
private scrollPosition: number; private scrollPosition = 0;
private scrollSlots: {[key: string]: number} = {}; private scrollSlots: {[key: string]: number} = {};
private iRestoreScrollPosition$ = new BehaviorSubject<number>(0); private iRestoreScrollPosition$ = new BehaviorSubject<number>(0);
public restoreScrollPosition$ = this.iRestoreScrollPosition$.asObservable(); public restoreScrollPosition$ = this.iRestoreScrollPosition$.asObservable();

View File

@@ -5,11 +5,15 @@ import {UserService} from './user.service';
selector: '[appOwner]', selector: '[appOwner]',
}) })
export class OwnerDirective implements OnInit { export class OwnerDirective implements OnInit {
private currentUserId: string; private currentUserId: string | null = null;
private iAppOwner: string | null = null;
private iAppOwner: string; public constructor(
private element: ElementRef,
public constructor(private element: ElementRef, private templateRef: TemplateRef<unknown>, private viewContainer: ViewContainerRef, private userService: UserService) {} private templateRef: TemplateRef<unknown>,
private viewContainer: ViewContainerRef,
private userService: UserService
) {}
@Input() @Input()
public set appOwner(value: string) { public set appOwner(value: string) {

View File

@@ -8,10 +8,15 @@ import {User} from './user';
}) })
export class RoleDirective implements OnInit { export class RoleDirective implements OnInit {
@Input() public appRole: roles[] = []; @Input() public appRole: roles[] = [];
private currentUser: User; private currentUser: User | null = null;
private loggedIn: boolean; private loggedIn = false;
public constructor(private element: ElementRef, private templateRef: TemplateRef<unknown>, private viewContainer: ViewContainerRef, private userService: UserService) {} public constructor(
private element: ElementRef,
private templateRef: TemplateRef<unknown>,
private viewContainer: ViewContainerRef,
private userService: UserService
) {}
public ngOnInit(): void { public ngOnInit(): void {
this.userService.user$.subscribe(user => { this.userService.user$.subscribe(user => {

View File

@@ -9,12 +9,12 @@ import {Observable} from 'rxjs';
styleUrls: ['./user-name.component.less'], styleUrls: ['./user-name.component.less'],
}) })
export class UserNameComponent { export class UserNameComponent {
public name$: Observable<string>; public name$: Observable<string | null> | null = null;
public constructor(private userService: UserService) {} public constructor(private userService: UserService) {}
@Input() @Input()
public set userId(id: string) { public set userId(id: string) {
this.name$ = this.userService.getUserbyId$(id).pipe(map(_ => _.name)); this.name$ = this.userService.getUserbyId$(id).pipe(map(_ => _?.name ?? null));
} }
} }

View File

@@ -1,7 +1,7 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {AngularFireAuth} from '@angular/fire/auth'; import {AngularFireAuth} from '@angular/fire/auth';
import {BehaviorSubject, Observable} from 'rxjs'; import {BehaviorSubject, Observable} from 'rxjs';
import {filter, first, switchMap, tap} from 'rxjs/operators'; import {filter, first, map, switchMap, tap} from 'rxjs/operators';
import {User} from './user'; import {User} from './user';
import {DbService} from '../db.service'; import {DbService} from '../db.service';
import {environment} from '../../../environments/environment'; import {environment} from '../../../environments/environment';
@@ -11,41 +11,43 @@ import {Router} from '@angular/router';
providedIn: 'root', providedIn: 'root',
}) })
export class UserService { export class UserService {
private iUserId$ = new BehaviorSubject<string>(null); private iUserId$ = new BehaviorSubject<string | null>(null);
private iUser$ = new BehaviorSubject<User>(null); private iUser$ = new BehaviorSubject<User | null>(null);
public constructor(private afAuth: AngularFireAuth, private db: DbService, private router: Router) { public constructor(private afAuth: AngularFireAuth, private db: DbService, private router: Router) {
this.afAuth.authState this.afAuth.authState
.pipe( .pipe(
filter(_ => !!_), filter(auth => !!auth),
tap(auth => this.iUserId$.next(auth.uid)), map(auth => auth?.uid ?? ''),
switchMap(auth => this.readUser$(auth.uid)) tap(uid => this.iUserId$.next(uid)),
switchMap(uid => this.readUser$(uid))
) )
.subscribe(_ => this.iUser$.next(_)); .subscribe(_ => this.iUser$.next(_));
} }
public get userId$(): Observable<string> { public get userId$(): Observable<string | null> {
return this.iUserId$.asObservable(); return this.iUserId$.asObservable();
} }
public get user$(): Observable<User> { public get user$(): Observable<User | null> {
return this.iUser$.pipe(filter(_ => !!_)); return this.iUser$.pipe(filter(_ => !!_));
} }
public async currentUser(): Promise<User> { public async currentUser(): Promise<User | null> {
return this.user$.pipe(first()).toPromise(); return this.user$.pipe(first()).toPromise();
} }
public getUserbyId(userId: string): Promise<User> { public getUserbyId(userId: string): Promise<User | null> {
return this.getUserbyId$(userId).pipe(first()).toPromise(); return this.getUserbyId$(userId).pipe(first()).toPromise();
} }
public getUserbyId$(userId: string): Observable<User> { public getUserbyId$(userId: string): Observable<User | null> {
return this.db.doc$<User>('users/' + userId); return this.db.doc$<User>('users/' + userId);
} }
public async login(user: string, password: string): Promise<string> { public async login(user: string, password: string): Promise<string | null> {
const aUser = await this.afAuth.signInWithEmailAndPassword(user, password); const aUser = await this.afAuth.signInWithEmailAndPassword(user, password);
if (!aUser.user) return null;
const dUser = await this.readUser(aUser.user.uid); const dUser = await this.readUser(aUser.user.uid);
this.iUser$.next(dUser); this.iUser$.next(dUser);
this.iUserId$.next(aUser.user.uid); this.iUserId$.next(aUser.user.uid);
@@ -73,6 +75,7 @@ export class UserService {
public async createNewUser(user: string, name: string, password: string): Promise<void> { public async createNewUser(user: string, name: string, password: string): Promise<void> {
const aUser = await this.afAuth.createUserWithEmailAndPassword(user, password); const aUser = await this.afAuth.createUserWithEmailAndPassword(user, password);
if (!aUser.user) return;
const userId = aUser.user.uid; const userId = aUser.user.uid;
await this.db.doc('users/' + userId).set({name, chordMode: 'onlyFirst'}); await this.db.doc('users/' + userId).set({name, chordMode: 'onlyFirst'});
const dUser = await this.readUser(aUser.user.uid); const dUser = await this.readUser(aUser.user.uid);
@@ -80,6 +83,6 @@ export class UserService {
await this.router.navigateByUrl('/brand/new-user'); await this.router.navigateByUrl('/brand/new-user');
} }
private readUser$ = (uid: string) => this.db.doc$<User>('users/' + uid); private readUser$ = (uid: string) => this.db.doc$<User | null>('users/' + uid);
private readUser = async (uid: string): Promise<User> => await this.readUser$(uid).pipe(first()).toPromise(); private readUser = async (uid: string): Promise<User | null> => await this.readUser$(uid).pipe(first()).toPromise();
} }

View File

@@ -12,15 +12,16 @@ import {ShowSongService} from '../../../modules/shows/services/show-song.service
styleUrls: ['./add-song.component.less'], styleUrls: ['./add-song.component.less'],
}) })
export class AddSongComponent { export class AddSongComponent {
@Input() public songs: Song[]; @Input() public songs: Song[] | null = null;
@Input() public showSongs: ShowSong[]; @Input() public showSongs: ShowSong[] | null = null;
@Input() public showId: string; @Input() public showId: string | null = null;
@Input() public addedLive = false; @Input() public addedLive = false;
public filteredSongsControl = new FormControl(); public filteredSongsControl = new FormControl();
public constructor(private showSongService: ShowSongService) {} public constructor(private showSongService: ShowSongService) {}
public filteredSongs(): Song[] { public filteredSongs(): Song[] {
if (!this.songs) return [];
const songs = this.songs const songs = this.songs
.filter(_ => !!_) .filter(_ => !!_)
.filter(_ => !!_.title) .filter(_ => !!_.title)
@@ -41,6 +42,7 @@ export class AddSongComponent {
} }
public async onAddSongSelectionChanged(event: MatSelectChange): Promise<void> { public async onAddSongSelectionChanged(event: MatSelectChange): Promise<void> {
if (!this.showSongs || !this.showId) return;
const order = this.showSongs.reduce((oa, u) => Math.max(oa, u.order), 0) + 1; const order = this.showSongs.reduce((oa, u) => Math.max(oa, u.order), 0) + 1;
await this.showSongService.new$(this.showId, event.value, order, this.addedLive); await this.showSongService.new$(this.showId, event.value, order, this.addedLive);
event.source.value = null; event.source.value = null;

View File

@@ -1,5 +1,5 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router'; import {ActivatedRoute, Params, Router} from '@angular/router';
@Component({ @Component({
selector: 'app-filter', selector: 'app-filter',
@@ -7,13 +7,12 @@ import {ActivatedRoute, Router} from '@angular/router';
styleUrls: ['./filter.component.less'], styleUrls: ['./filter.component.less'],
}) })
export class FilterComponent { export class FilterComponent {
public value: string; public value = '';
public constructor(private router: Router, activatedRoute: ActivatedRoute) { public constructor(private router: Router, activatedRoute: ActivatedRoute) {
activatedRoute.queryParams.subscribe((_: {q: string}) => { activatedRoute.queryParams.subscribe((params: Params) => {
if (_.q) { const typedParams = params as {q: string};
this.value = _.q; if (typedParams.q) this.value = typedParams.q;
}
}); });
} }

View File

@@ -1,5 +1,6 @@
import {Component, Input} from '@angular/core'; import {Component, Input} from '@angular/core';
import {IconProp} from '@fortawesome/fontawesome-svg-core'; import {IconProp} from '@fortawesome/fontawesome-svg-core';
import {faCross} from '@fortawesome/free-solid-svg-icons/faCross';
@Component({ @Component({
selector: 'app-link', selector: 'app-link',
@@ -7,7 +8,7 @@ import {IconProp} from '@fortawesome/fontawesome-svg-core';
styleUrls: ['./link.component.less'], styleUrls: ['./link.component.less'],
}) })
export class LinkComponent { export class LinkComponent {
@Input() public text: string; @Input() public text: string | null = null;
@Input() public link: string; @Input() public link: string | null = null;
@Input() public icon: IconProp; @Input() public icon: IconProp = faCross;
} }

View File

@@ -1,4 +1,4 @@
<nav [class.hidden]="(windowScroll$ | async) > 60" class="head"> <nav [class.hidden]="isNavigationHidden(windowScroll$|async)" class="head">
<div class="links"> <div class="links">
<app-brand routerLink="/brand"></app-brand> <app-brand routerLink="/brand"></app-brand>
<app-link <app-link

View File

@@ -2,7 +2,7 @@ import {Component} from '@angular/core';
import {faMusic} from '@fortawesome/free-solid-svg-icons/faMusic'; import {faMusic} from '@fortawesome/free-solid-svg-icons/faMusic';
import {faPersonBooth} from '@fortawesome/free-solid-svg-icons/faPersonBooth'; import {faPersonBooth} from '@fortawesome/free-solid-svg-icons/faPersonBooth';
import {faUserCog} from '@fortawesome/free-solid-svg-icons/faUserCog'; import {faUserCog} from '@fortawesome/free-solid-svg-icons/faUserCog';
import {fromEvent} from 'rxjs'; import {fromEvent, Observable} from 'rxjs';
import {distinctUntilChanged, map, shareReplay, startWith} from 'rxjs/operators'; import {distinctUntilChanged, map, shareReplay, startWith} from 'rxjs/operators';
import {faChalkboard} from '@fortawesome/free-solid-svg-icons/faChalkboard'; import {faChalkboard} from '@fortawesome/free-solid-svg-icons/faChalkboard';
@@ -17,10 +17,12 @@ export class NavigationComponent {
public faUser = faUserCog; public faUser = faUserCog;
public faPresentation = faChalkboard; public faPresentation = faChalkboard;
public readonly windowScroll$ = fromEvent(window, 'scroll').pipe( public readonly windowScroll$: Observable<number> = fromEvent(window, 'scroll').pipe(
map(() => window.scrollY), map(() => window.scrollY),
startWith(0), startWith(0),
distinctUntilChanged(), distinctUntilChanged(),
shareReplay(1) shareReplay(1)
); );
public isNavigationHidden = (scroll: number | null): boolean => (scroll ?? 0) > 60;
} }

View File

@@ -1,5 +1,6 @@
import {Component, Input} from '@angular/core'; import {Component, Input} from '@angular/core';
import {IconProp} from '@fortawesome/fontawesome-svg-core'; import {IconProp} from '@fortawesome/fontawesome-svg-core';
import {faCross} from '@fortawesome/free-solid-svg-icons/faCross';
@Component({ @Component({
selector: 'app-button', selector: 'app-button',
@@ -7,5 +8,5 @@ import {IconProp} from '@fortawesome/fontawesome-svg-core';
styleUrls: ['./button.component.less'], styleUrls: ['./button.component.less'],
}) })
export class ButtonComponent { export class ButtonComponent {
@Input() public icon: IconProp; @Input() public icon: IconProp = faCross;
} }

View File

@@ -8,8 +8,8 @@ import {faTimes} from '@fortawesome/free-solid-svg-icons/faTimes';
}) })
export class CardComponent { export class CardComponent {
@Input() public padding = true; @Input() public padding = true;
@Input() public heading: string; @Input() public heading: string | null = null;
@Input() public closeLink: string; @Input() public closeLink: string | null = null;
public faClose = faTimes; public faClose = faTimes;
} }

View File

@@ -1,5 +1,6 @@
import {Component, Input} from '@angular/core'; import {Component, Input} from '@angular/core';
import {IconProp} from '@fortawesome/fontawesome-svg-core'; import {IconProp} from '@fortawesome/fontawesome-svg-core';
import {faCross} from '@fortawesome/free-solid-svg-icons/faCross';
@Component({ @Component({
selector: 'app-menu-button', selector: 'app-menu-button',
@@ -7,5 +8,5 @@ import {IconProp} from '@fortawesome/fontawesome-svg-core';
styleUrls: ['./menu-button.component.less'], styleUrls: ['./menu-button.component.less'],
}) })
export class MenuButtonComponent { export class MenuButtonComponent {
@Input() public icon: IconProp; @Input() public icon: IconProp = faCross;
} }

View File

@@ -17,13 +17,13 @@ export type ChordMode = 'show' | 'hide' | 'onlyFirst';
animations: [songSwitch], animations: [songSwitch],
}) })
export class SongTextComponent implements OnInit { export class SongTextComponent implements OnInit {
public sections: Section[]; public sections: Section[] = [];
@Input() public index = -1; @Input() public index = -1;
@Input() public fullscreen = false; @Input() public fullscreen = false;
@Input() public showSwitch = false; @Input() public showSwitch = false;
@Input() public transpose: TransposeMode = null; @Input() public transpose: TransposeMode | null = null;
@Output() public chordModeChanged = new EventEmitter<ChordMode>(); @Output() public chordModeChanged = new EventEmitter<ChordMode>();
@ViewChildren('section') public viewSections: QueryList<ElementRef<HTMLElement>>; @ViewChildren('section') public viewSections: QueryList<ElementRef<HTMLElement>> | null = null;
public faLines = faGripLines; public faLines = faGripLines;
public offset = 0; public offset = 0;
public iChordMode: ChordMode = 'hide'; public iChordMode: ChordMode = 'hide';
@@ -37,10 +37,13 @@ export class SongTextComponent implements OnInit {
@Input() @Input()
public set text(value: string) { public set text(value: string) {
this.sections = null; this.sections = [];
this.offset = 0; this.offset = 0;
if (this.fullscreen) { if (this.fullscreen) {
setTimeout(() => (this.sections = this.textRenderingService.parse(value, this.transpose).sort((a, b) => a.type - b.type)), 100); setTimeout(
() => (this.sections = this.textRenderingService.parse(value, this.transpose).sort((a, b) => a.type - b.type)),
100
);
} else { } else {
this.sections = this.textRenderingService.parse(value, this.transpose).sort((a, b) => a.type - b.type); this.sections = this.textRenderingService.parse(value, this.transpose).sort((a, b) => a.type - b.type);
} }
@@ -48,11 +51,11 @@ export class SongTextComponent implements OnInit {
public ngOnInit(): void { public ngOnInit(): void {
setInterval(() => { setInterval(() => {
if (!this.fullscreen || this.index === -1 || !this.viewSections.toArray()[this.index]) { if (!this.fullscreen || this.index === -1 || !this.viewSections?.toArray()[this.index]) {
this.offset = 0; this.offset = 0;
return; return;
} }
this.offset = -this.viewSections.toArray()[this.index].nativeElement.offsetTop; this.offset = -this.viewSections?.toArray()[this.index].nativeElement.offsetTop;
}, 100); }, 100);
} }

View File

@@ -18,6 +18,7 @@ export class RoleGuard implements CanActivate {
return this.userService.user$.pipe( return this.userService.user$.pipe(
map(user => { map(user => {
if (!user) return false;
const roles = user.role?.split(';') ?? []; const roles = user.role?.split(';') ?? [];
if (roles.indexOf('admin') !== -1) { if (roles.indexOf('admin') !== -1) {
return true; return true;

View File

@@ -25,5 +25,7 @@ export class ShowTypePipe implements PipeTransform {
case 'misc-private': case 'misc-private':
return 'sonstige private Veranstaltung'; return 'sonstige private Veranstaltung';
} }
return 'unbekannter Veranstaltungstyp';
} }
} }

View File

@@ -15,6 +15,7 @@ body {
margin: 0; margin: 0;
font-family: Roboto, "Helvetica Neue", sans-serif; font-family: Roboto, "Helvetica Neue", sans-serif;
font-size: 14px; font-size: 14px;
overscroll-behavior-y: none;
background: #373b44; /* fallback for old browsers */ background: #373b44; /* fallback for old browsers */
background: -webkit-linear-gradient(to bottom, #373b44, @primary-color); /* Chrome 10-25, Safari 5.1-6 */ background: -webkit-linear-gradient(to bottom, #373b44, @primary-color); /* Chrome 10-25, Safari 5.1-6 */

View File

@@ -12,6 +12,7 @@
"moduleResolution": "node", "moduleResolution": "node",
"importHelpers": true, "importHelpers": true,
"target": "es2015", "target": "es2015",
"strict": true,
"typeRoots": [ "typeRoots": [
"node_modules/@types" "node_modules/@types"
], ],