diff --git a/src/app/modules/shows/services/show-data.service.ts b/src/app/modules/shows/services/show-data.service.ts index 2116c8b..738e4db 100644 --- a/src/app/modules/shows/services/show-data.service.ts +++ b/src/app/modules/shows/services/show-data.service.ts @@ -1,5 +1,5 @@ import {Injectable} from '@angular/core'; -import {BehaviorSubject, Observable} from 'rxjs'; +import {BehaviorSubject, firstValueFrom, Observable} from 'rxjs'; import {DbService} from '../../../services/db.service'; import {Show} from './show'; import {map} from 'rxjs/operators'; @@ -15,6 +15,8 @@ export class ShowDataService { } public list$ = new BehaviorSubject([]); + public list = () => firstValueFrom(this.dbService.col$(this.collection)); + public read$ = (showId: string): Observable => this.list$.pipe(map(_ => _.find(s => s.id === showId) || null)); // public list$ = (): Observable => this.dbService.col$(this.collection); 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 5304fa0..74bb650 100644 --- a/src/app/modules/shows/services/show-song-data.service.ts +++ b/src/app/modules/shows/services/show-song-data.service.ts @@ -1,6 +1,6 @@ import {Injectable} from '@angular/core'; import {DbService} from '../../../services/db.service'; -import {Observable} from 'rxjs'; +import {firstValueFrom, Observable} from 'rxjs'; import {ShowSong} from './show-song'; import {QueryFn} from '@angular/fire/compat/firestore/interfaces'; @@ -14,6 +14,8 @@ export class ShowSongDataService { public constructor(private dbService: DbService) {} public list$ = (showId: string, queryFn?: QueryFn): Observable => this.dbService.col$(`${this.collection}/${showId}/${this.subCollection}`, queryFn); + public list = (showId: string): Promise => firstValueFrom(this.list$(showId)); + public read$ = (showId: string, songId: string): Observable => this.dbService.doc$(`${this.collection}/${showId}/${this.subCollection}/${songId}`); public update$ = async (showId: string, songId: string, data: Partial): Promise => await this.dbService.doc(`${this.collection}/${showId}/${this.subCollection}/${songId}`).update(data); diff --git a/src/app/modules/shows/services/show-song.service.ts b/src/app/modules/shows/services/show-song.service.ts index 67ca804..8b6c21c 100644 --- a/src/app/modules/shows/services/show-song.service.ts +++ b/src/app/modules/shows/services/show-song.service.ts @@ -1,10 +1,12 @@ import {Injectable} from '@angular/core'; import {ShowSongDataService} from './show-song-data.service'; -import {firstValueFrom, Observable} from 'rxjs'; +import {firstValueFrom, forkJoin, mergeMap, Observable} from 'rxjs'; import {ShowSong} from './show-song'; import {SongDataService} from '../../songs/services/song-data.service'; import {UserService} from '../../../services/user/user.service'; import {ShowService} from './show.service'; +import {map, switchMap} from 'rxjs/operators'; +import {ShowDataService} from './show-data.service'; @Injectable({ providedIn: 'root', @@ -14,7 +16,8 @@ export class ShowSongService { private showSongDataService: ShowSongDataService, private songDataService: SongDataService, private userService: UserService, - private showService: ShowService + private showService: ShowService, + private showDataService: ShowDataService ) {} public async new$(showId: string, songId: string, addedLive = false): Promise { @@ -47,5 +50,39 @@ export class ShowSongService { await this.showService.update$(showId, {order}); } + public countSongUsage$(songId: string) { + return this.userService.user$.pipe( + switchMap(user => + this.showService.list$().pipe( + map(shows => { + const myShows = shows.filter(_ => _.owner === user?.id); + return myShows.map(show => this.list$(show.id)); + }), + mergeMap(songs => forkJoin(songs)), + map(songs => songs.reduce((pn, u) => [...pn, ...u], [])), + map(songs => songs.reduce((count, song) => (song.songId === songId ? 1 : 0), 0)) + ) + ) + ); + } + + public async countSongUsage(songId: string) { + // return 0; // todo + + const user = await this.userService.currentUser(); + const userId = user?.id; + if (!userId) return null; + const shows = await this.showDataService.list(); + let count = 0; + for (const show of shows.filter(_ => _.owner === userId)) { + const songs = await this.showSongDataService.list(show.id); + for (const song of songs) { + if (song.songId === songId) count++; + } + } + + return count; + } + public update$ = async (showId: string, songId: string, data: Partial): Promise => await this.showSongDataService.update$(showId, songId, data); } diff --git a/src/app/modules/songs/song/song-used/song-used.component.html b/src/app/modules/songs/song/song-used/song-used.component.html new file mode 100644 index 0000000..ceaf93a --- /dev/null +++ b/src/app/modules/songs/song/song-used/song-used.component.html @@ -0,0 +1,3 @@ +Verwendet: {{count}}x + + diff --git a/src/app/modules/songs/song/song-used/song-used.component.less b/src/app/modules/songs/song/song-used/song-used.component.less new file mode 100644 index 0000000..e69de29 diff --git a/src/app/modules/songs/song/song-used/song-used.component.spec.ts b/src/app/modules/songs/song/song-used/song-used.component.spec.ts new file mode 100644 index 0000000..fb70d93 --- /dev/null +++ b/src/app/modules/songs/song/song-used/song-used.component.spec.ts @@ -0,0 +1,22 @@ +import {ComponentFixture, TestBed} from '@angular/core/testing'; + +import {SongUsedComponent} from './song-used.component'; + +describe('SongUsedComponent', () => { + let component: SongUsedComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [SongUsedComponent], + }).compileComponents(); + + fixture = TestBed.createComponent(SongUsedComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/modules/songs/song/song-used/song-used.component.ts b/src/app/modules/songs/song/song-used/song-used.component.ts new file mode 100644 index 0000000..34c57f9 --- /dev/null +++ b/src/app/modules/songs/song/song-used/song-used.component.ts @@ -0,0 +1,18 @@ +import {ChangeDetectorRef, Component, Input, OnInit} from '@angular/core'; +import {ShowSongService} from '../../../shows/services/show-song.service'; + +@Component({ + selector: 'app-song-used', + templateUrl: './song-used.component.html', + styleUrls: ['./song-used.component.less'], +}) +export class SongUsedComponent implements OnInit { + @Input() public songId: string | null = null; + public count = 0; + + public constructor(private service: ShowSongService, private cref: ChangeDetectorRef) {} + + public async ngOnInit() { + this.count = (await this.service.countSongUsage(this.songId ?? '')) ?? 0; + } +} diff --git a/src/app/modules/songs/song/song.component.html b/src/app/modules/songs/song/song.component.html index 92d2ee9..22ee68e 100644 --- a/src/app/modules/songs/song/song.component.html +++ b/src/app/modules/songs/song/song.component.html @@ -29,6 +29,9 @@
Verlag: {{ song.label }}
Quelle: {{ song.origin }}
Quelle: {{ song.origin }}
+
+ +
@@ -65,7 +68,8 @@ >Bearbeiten - + + Zu Veranstaltung hinzufügen diff --git a/src/app/modules/songs/song/song.module.ts b/src/app/modules/songs/song/song.module.ts index 715be7b..46c4fce 100644 --- a/src/app/modules/songs/song/song.module.ts +++ b/src/app/modules/songs/song/song.module.ts @@ -15,9 +15,10 @@ import {ButtonModule} from '../../../widget-modules/components/button/button.mod import {FileComponent} from './file/file.component'; import {MatMenuModule} from '@angular/material/menu'; import {ShowTypeTranslaterModule} from '../../../widget-modules/pipes/show-type-translater/show-type-translater.module'; +import {SongUsedComponent} from './song-used/song-used.component'; @NgModule({ - declarations: [SongComponent, FileComponent], + declarations: [SongComponent, FileComponent, SongUsedComponent], exports: [SongComponent], imports: [ CommonModule, diff --git a/src/app/widget-modules/components/application-frame/navigation/navigation.component.html b/src/app/widget-modules/components/application-frame/navigation/navigation.component.html index 14f4f56..a4dc651 100644 --- a/src/app/widget-modules/components/application-frame/navigation/navigation.component.html +++ b/src/app/widget-modules/components/application-frame/navigation/navigation.component.html @@ -21,7 +21,13 @@ > -
- +
+ +
+ diff --git a/src/app/widget-modules/components/application-frame/navigation/navigation.component.less b/src/app/widget-modules/components/application-frame/navigation/navigation.component.less index 801b77e..5367194 100644 --- a/src/app/widget-modules/components/application-frame/navigation/navigation.component.less +++ b/src/app/widget-modules/components/application-frame/navigation/navigation.component.less @@ -32,7 +32,7 @@ nav { display: flex; height: 100%; align-items: center; - padding-right: 20px; + // padding-right: 20px; } diff --git a/src/app/widget-modules/components/application-frame/navigation/navigation.component.ts b/src/app/widget-modules/components/application-frame/navigation/navigation.component.ts index 1a3582f..2b1963c 100644 --- a/src/app/widget-modules/components/application-frame/navigation/navigation.component.ts +++ b/src/app/widget-modules/components/application-frame/navigation/navigation.component.ts @@ -1,7 +1,9 @@ import {Component} from '@angular/core'; -import {faChalkboard, faMusic, faPersonBooth, faUserCog} from '@fortawesome/free-solid-svg-icons'; +import {faChalkboard, faMusic, faPersonBooth, faRightFromBracket, faUserCog} from '@fortawesome/free-solid-svg-icons'; import {fromEvent, Observable} from 'rxjs'; import {distinctUntilChanged, map, shareReplay, startWith} from 'rxjs/operators'; +import {UserService} from '../../../../services/user/user.service'; +import {Router} from '@angular/router'; @Component({ selector: 'app-navigation', @@ -13,6 +15,9 @@ export class NavigationComponent { public faShows = faPersonBooth; public faUser = faUserCog; public faPresentation = faChalkboard; + public faLogout = faRightFromBracket; + + public constructor(public userService: UserService, private router: Router) {} public readonly windowScroll$: Observable = fromEvent(window, 'scroll').pipe( map(() => window.scrollY), @@ -22,4 +27,9 @@ export class NavigationComponent { ); public isNavigationHidden = (scroll: number | null): boolean => (scroll ?? 0) > 60; + + public async logout(): Promise { + await this.userService.logout(); + await this.router.navigateByUrl('/'); + } } diff --git a/src/app/widget-modules/components/card/card.component.less b/src/app/widget-modules/components/card/card.component.less index 2d5412b..d3e6243 100644 --- a/src/app/widget-modules/components/card/card.component.less +++ b/src/app/widget-modules/components/card/card.component.less @@ -3,7 +3,7 @@ .card { margin: 20px; border-radius: 8px; - background: #fffc; + background: #fff; backdrop-filter: blur(12px); overflow: hidden; width: 800px; diff --git a/src/index.html b/src/index.html index e41a32f..d4d68e0 100644 --- a/src/index.html +++ b/src/index.html @@ -11,7 +11,7 @@ - +