set song count
This commit is contained in:
12
.run/build.run.xml
Normal file
12
.run/build.run.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="build" type="js.build_tools.npm" nameIsGenerated="true">
|
||||
<package-json value="$PROJECT_DIR$/package.json"/>
|
||||
<command value="run"/>
|
||||
<scripts>
|
||||
<script value="build"/>
|
||||
</scripts>
|
||||
<node-interpreter value="project"/>
|
||||
<envs/>
|
||||
<method v="2"/>
|
||||
</configuration>
|
||||
</component>
|
||||
12
.run/deploy.run.xml
Normal file
12
.run/deploy.run.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="deploy" type="js.build_tools.npm" nameIsGenerated="true">
|
||||
<package-json value="$PROJECT_DIR$/package.json"/>
|
||||
<command value="run"/>
|
||||
<scripts>
|
||||
<script value="deploy"/>
|
||||
</scripts>
|
||||
<node-interpreter value="project"/>
|
||||
<envs/>
|
||||
<method v="2"/>
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -14,6 +14,7 @@ export class ShowDataService {
|
||||
this.dbService.col$<Show>(this.collection).subscribe(_ => this.list$.next(_));
|
||||
}
|
||||
|
||||
public listRaw$ = () => this.dbService.col$<Show>(this.collection);
|
||||
public list$ = new BehaviorSubject<Show[]>([]);
|
||||
public read$ = (showId: string): Observable<Show | null> => this.list$.pipe(map(_ => _.find(s => s.id === showId) || null));
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ export class ShowSongService {
|
||||
chordMode: user.chordMode,
|
||||
addedLive,
|
||||
};
|
||||
await this.userService.incSongCount(songId);
|
||||
return await this.showSongDataService.add(showId, data);
|
||||
}
|
||||
|
||||
@@ -38,13 +39,15 @@ export class ShowSongService {
|
||||
public list$ = (showId: string): Observable<ShowSong[]> => this.showSongDataService.list$(showId);
|
||||
public list = (showId: string): Promise<ShowSong[]> => firstValueFrom(this.list$(showId));
|
||||
|
||||
public async delete$(showId: string, songId: string, index: number): Promise<void> {
|
||||
await this.showSongDataService.delete(showId, songId);
|
||||
public async delete$(showId: string, showSongId: string, index: number): Promise<void> {
|
||||
const showSong = await this.read(showId, showSongId);
|
||||
await this.showSongDataService.delete(showId, showSongId);
|
||||
const show = await firstValueFrom(this.showService.read$(showId));
|
||||
if (!show) return;
|
||||
const order = show.order;
|
||||
order.splice(index, 1);
|
||||
await this.showService.update$(showId, {order});
|
||||
await this.userService.decSongCount(showSong.songId);
|
||||
}
|
||||
|
||||
public update$ = async (showId: string, songId: string, data: Partial<ShowSong>): Promise<void> => await this.showSongDataService.update$(showId, songId, data);
|
||||
|
||||
@@ -29,10 +29,10 @@
|
||||
<div *ngIf="song.label">Verlag: {{ song.label }}</div>
|
||||
<div *ngIf="song.origin">Quelle: {{ song.origin }}</div>
|
||||
<div *ngIf="song.origin">Quelle: {{ song.origin }}</div>
|
||||
<div *ngIf="songCount$()|async as count">Wie oft verwendet: {{ count }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <div class="text">{{song.text}}</div>-->
|
||||
<app-song-text
|
||||
*ngIf="user$ | async as user"
|
||||
[chordMode]="user.chordMode"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {SongService} from '../services/song.service';
|
||||
import {map, switchMap} from 'rxjs/operators';
|
||||
import {distinctUntilChanged, map, switchMap} from 'rxjs/operators';
|
||||
import {Song} from '../services/song';
|
||||
import {Observable} from 'rxjs';
|
||||
import {combineLatest, Observable} from 'rxjs';
|
||||
import {FileDataService} from '../services/file-data.service';
|
||||
import {File} from '../services/file';
|
||||
import {UserService} from '../../../services/user/user.service';
|
||||
@@ -71,4 +71,12 @@ export class SongComponent implements OnInit {
|
||||
await this.showService.update$(show?.id, {order: [...show.order, newId ?? '']});
|
||||
await this.router.navigateByUrl('/shows/' + show.id);
|
||||
}
|
||||
|
||||
public songCount$ = () =>
|
||||
combineLatest([this.user$, this.song$]).pipe(
|
||||
map(([user, song]) => {
|
||||
return user.songUsage[song.id];
|
||||
}),
|
||||
distinctUntilChanged()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import {User} from './user';
|
||||
import {DbService} from '../db.service';
|
||||
import {environment} from '../../../environments/environment';
|
||||
import {Router} from '@angular/router';
|
||||
import {ShowDataService} from '../../modules/shows/services/show-data.service';
|
||||
import {ShowSongDataService} from '../../modules/shows/services/show-song-data.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -29,7 +31,9 @@ export class UserService {
|
||||
public constructor(
|
||||
private afAuth: AngularFireAuth,
|
||||
private db: DbService,
|
||||
private router: Router
|
||||
private router: Router,
|
||||
private showDataService: ShowDataService,
|
||||
private showSongDataService: ShowSongDataService
|
||||
) {
|
||||
this.afAuth.authState
|
||||
.pipe(
|
||||
@@ -49,6 +53,7 @@ export class UserService {
|
||||
const aUser = await this.afAuth.signInWithEmailAndPassword(user, password);
|
||||
if (!aUser.user) return null;
|
||||
const dUser = await this.readUser(aUser.user.uid);
|
||||
await this.initSongUsage(dUser);
|
||||
this.iUser$.next(dUser);
|
||||
this.iUserId$.next(aUser.user.uid);
|
||||
|
||||
@@ -84,6 +89,40 @@ export class UserService {
|
||||
await this.router.navigateByUrl('/brand/new-user');
|
||||
}
|
||||
|
||||
public incSongCount = (songId: string) => this.updateSongUsage(songId, 1);
|
||||
public decSongCount = (songId: string) => this.updateSongUsage(songId, -1);
|
||||
|
||||
private async updateSongUsage(songId: string, direction: number) {
|
||||
const user = await firstValueFrom(this.user$);
|
||||
if (!user) return null;
|
||||
|
||||
const songUsage = user?.songUsage ?? {};
|
||||
let currentSongCount = songUsage[songId];
|
||||
if (currentSongCount === null || currentSongCount === undefined) currentSongCount = 0;
|
||||
else currentSongCount = currentSongCount + direction;
|
||||
songUsage[songId] = Math.max(0, currentSongCount);
|
||||
|
||||
await this.update$(user.id, {songUsage});
|
||||
}
|
||||
|
||||
private async initSongUsage(user: User) {
|
||||
if (user.songUsage) return;
|
||||
|
||||
const shows = await firstValueFrom(this.showDataService.listRaw$());
|
||||
const myShows = shows.filter(show => show.owner === user.id);
|
||||
const songUsage: {[songId: string]: number} = {};
|
||||
for (const show of myShows) {
|
||||
const showSongs = await firstValueFrom(this.showSongDataService.list$(show.id));
|
||||
for (const showSong of showSongs) {
|
||||
const current = songUsage[showSong.songId] ?? 0;
|
||||
songUsage[showSong.songId] = current + 1;
|
||||
}
|
||||
}
|
||||
|
||||
await this.update$(user.id, {songUsage});
|
||||
return;
|
||||
}
|
||||
|
||||
private readUser$ = (uid: string) => this.db.doc$<User>('users/' + uid);
|
||||
private readUser: (uid: string) => Promise<User | null> = (uid: string) => firstValueFrom(this.readUser$(uid));
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ export interface User {
|
||||
name: string;
|
||||
role: string;
|
||||
chordMode: ChordMode;
|
||||
songUsage: {[songId: string]: number};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user