Only show factions of body of which the session is

This commit is contained in:
Jim Martens 2021-10-05 17:05:25 +02:00
parent d7948a94fd
commit f27734d009
10 changed files with 43 additions and 24 deletions

View File

@ -7,9 +7,9 @@
<div class="col">
<ul class="nav nav-pills">
<li class="nav-item" *ngFor="let body of sessionInBodyService.bodies | async">
<button type="button" class="nav-link" [class.active]="sessionInBodyService.currentPage === body.payload.val()?.name"
[attr.aria-current]="sessionInBodyService.currentPage === body.payload.val()?.name ? 'page' : 'false'"
(click)="sessionInBodyService.changeBody(body.payload.val()?.name, 'edit')">{{body.payload.val()?.name}}</button>
<button type="button" class="nav-link" [class.active]="sessionInBodyService.currentBody === body.payload.val()?.name"
[attr.aria-current]="sessionInBodyService.currentBody === body.payload.val()?.name ? 'page' : 'false'"
(click)="sessionInBodyService.changeBody(body.key, body.payload.val()?.name, 'edit')">{{body.payload.val()?.name}}</button>
</li>
</ul>
</div>
@ -41,7 +41,7 @@
<form #addForm="ngForm"
(ngSubmit)="sessionService.addSession(
sessionNumber.value, sessionDate.value, sessionInBodyService.currentPage
sessionNumber.value, sessionDate.value, sessionInBodyService.currentBody, sessionInBodyService.currentBodyKey
); addForm.resetForm(); sessionNumber.value = ''; sessionDate.value = ''">
<div class="row">
<div class="col">

View File

@ -22,7 +22,7 @@ export class EditComponent implements OnInit {
ngOnInit(): void {
this.sessionInBodyService.bodies.pipe(first()).subscribe(bodies => {
if (bodies.length > 0) {
this.sessionInBodyService.changeBody(bodies[0].payload.val()?.name, 'edit');
this.sessionInBodyService.changeBody(bodies[0].key, bodies[0].payload.val()?.name, 'edit');
}
});
}

View File

@ -1,5 +1,6 @@
export interface Session {
body: string;
bodyKey: string;
number: number;
date: string;
}

View File

@ -1,6 +1,6 @@
import {Injectable} from '@angular/core';
import {AngularFireDatabase, SnapshotAction} from '@angular/fire/compat/database';
import {FactionInBody} from '../administration/factions-in-bodies/faction-in-body';
import {FactionInBody} from '../../shared/faction-in-body';
import {Faction} from '../administration/factions/faction';
import {Body} from '../administration/bodies/body';
import {map} from 'rxjs/operators';

View File

@ -11,16 +11,17 @@ export class SessionService {
constructor(private database: AngularFireDatabase,
private speechTimes: SpeechTimeService) { }
public addSession(sessionNumber: string, date: string, body: string | undefined): void {
if (body == null) {
console.error("body should not be undefined");
public addSession(sessionNumber: string, date: string, body: string | undefined, bodyKey: string | null): void {
if (body == null || bodyKey == null) {
console.error("body or bodyKey should not be undefined|null");
return;
}
const sessionRef = this.database.list<Session>('sessions');
sessionRef.push({
number: +sessionNumber,
date: date,
body: body
body: body,
bodyKey: bodyKey
});
}

View File

@ -12,9 +12,14 @@ export class SessionInBodyService {
public readonly bodies: Observable<SnapshotAction<Body>[]>;
public readonly sessions: Subject<SnapshotAction<Session>[]> = new Subject<SnapshotAction<Session>[]>();
private _currentPage: string | undefined;
get currentPage(): string|undefined {
return this._currentPage;
private _currentBody: string | undefined;
get currentBody(): string | undefined {
return this._currentBody;
}
private _currentBodyKey: string | null = null;
get currentBodyKey(): string | null {
return this._currentBodyKey;
}
public readonly fullSessions: Observable<SnapshotAction<Session>[]>;
@ -34,24 +39,25 @@ export class SessionInBodyService {
if (payload == null) {
continue;
}
let sessionsPerBody = this.sessionsMap.get(payload.body);
let sessionsPerBody = this.sessionsMap.get(payload.bodyKey);
if (sessionsPerBody == null) {
sessionsPerBody = [];
this.sessionsMap.set(payload.body, sessionsPerBody);
this.sessionsMap.set(payload.bodyKey, sessionsPerBody);
}
sessionsPerBody.push(session);
}
this.changeBody(this.currentPage, undefined);
this.changeBody(this.currentBodyKey, this.currentBody, undefined);
});
}
public changeBody(newBody: string | undefined, redirectUrl: string | undefined): void {
if (newBody == null) {
public changeBody(newBodyKey: string | null, newBody: string | undefined, redirectUrl: string | undefined): void {
if (newBodyKey == null || newBody == null) {
return;
}
this._currentPage = newBody;
this.sessions.next(this.sessionsMap.get(newBody));
this._currentBody = newBody;
this._currentBodyKey = newBodyKey;
this.sessions.next(this.sessionsMap.get(newBodyKey));
if (redirectUrl != null) {
this.router.navigate([redirectUrl]);
}

View File

@ -7,6 +7,7 @@ import {map} from 'rxjs/operators';
import {FactionInBodyService} from '../../auth/shared/faction-in-body.service';
import {SpeechType} from '../../shared/speech-type';
import {Session} from '../../auth/edit/session';
import {FactionInBody} from '../../shared/faction-in-body';
@Component({
selector: 'app-session-statistics',
@ -25,6 +26,7 @@ export class SessionStatisticsComponent implements OnInit, OnDestroy {
public readonly proportionOfSpeechTimePerFaction: Map<string, number> = new Map<string, number>();
public readonly proportionOfCommentaryTimePerFaction: Map<string, number> = new Map<string, number>();
public session: Observable<SnapshotAction<Session>> = new Observable<SnapshotAction<Session>>();
public factionsInCurrentBody: Observable<SnapshotAction<FactionInBody>[]> = new Observable<SnapshotAction<FactionInBody>[]>();
private sessionKey: string | undefined;
private speechTimes: Observable<SnapshotAction<Speech>[]> = new Observable<SnapshotAction<Speech>[]>();
@ -49,6 +51,15 @@ export class SessionStatisticsComponent implements OnInit, OnDestroy {
this.subscriptions.push(
this.speechTimes.subscribe((speechTimes) => this.calculateStatistics(speechTimes)),
this.session.subscribe(session => {
const payload = session.payload.val();
if (payload == null) {
return;
}
this.factionsInCurrentBody = this.factionInBodyService.factionsInBodies.pipe(
map(list => list.filter(factionInBody => factionInBody.payload.val()?.bodyKey == payload.bodyKey))
);
})
);
}

View File

@ -6,9 +6,9 @@
<div class="col">
<ul class="nav nav-pills">
<li class="nav-item" *ngFor="let body of sessionInBodyService.bodies | async">
<button type="button" class="nav-link" [class.active]="sessionInBodyService.currentPage === body.payload.val()?.name"
[attr.aria-current]="sessionInBodyService.currentPage === body.payload.val()?.name ? 'page' : 'false'"
(click)="sessionInBodyService.changeBody(body.payload.val()?.name, 'statistics')">{{body.payload.val()?.name}}</button>
<button type="button" class="nav-link" [class.active]="sessionInBodyService.currentBody === body.payload.val()?.name"
[attr.aria-current]="sessionInBodyService.currentBody === body.payload.val()?.name ? 'page' : 'false'"
(click)="sessionInBodyService.changeBody(body.key, body.payload.val()?.name, 'statistics')">{{body.payload.val()?.name}}</button>
</li>
</ul>
</div>

View File

@ -14,7 +14,7 @@ export class StatisticsComponent implements OnInit {
ngOnInit(): void {
this.sessionInBodyService.bodies.pipe(first()).subscribe(bodies => {
if (bodies.length > 0) {
this.sessionInBodyService.changeBody(bodies[0].payload.val()?.name, 'statistics');
this.sessionInBodyService.changeBody(bodies[0].key, bodies[0].payload.val()?.name, 'statistics');
}
});
}