Skip to content

Commit

Permalink
Improve meeting change subscription handling (OpenSlides#3604)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianjoel authored and peb-adr committed Apr 30, 2024
1 parent 47000cd commit 0f2f4b7
Show file tree
Hide file tree
Showing 25 changed files with 272 additions and 165 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Directive, EventEmitter, inject, OnDestroy, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { combineLatest, map, Observable, startWith } from 'rxjs';
import { combineLatest, firstValueFrom, map, Observable, skip, startWith } from 'rxjs';
import { Id } from 'src/app/domain/definitions/key-types';
import { ModelRequestService } from 'src/app/site/services/model-request.service';
import { BaseUiComponent } from 'src/app/ui/base/base-ui-component';
Expand Down Expand Up @@ -53,9 +53,13 @@ export class BaseModelRequestHandlerComponent extends BaseUiComponent implements
this.openslidesRouter = inject(OpenSlidesRouterService);
}

public ngOnInit(): void {
public async ngOnInit(): Promise<void> {
const currentParams = await firstValueFrom(this.openslidesRouter.currentParamMap);
this._currentParams = currentParams;
this._currentMeetingId = Number(currentParams[`meetingId`]) || null;

this.subscriptions.push(
this.openslidesRouter.currentParamMap.subscribe(event => {
this.openslidesRouter.currentParamMap.pipe(skip(1)).subscribe(event => {
const nextMeetingId = Number(event[`meetingId`]) || null;
if (nextMeetingId !== this._currentMeetingId) {
this._currentMeetingId = nextMeetingId;
Expand All @@ -79,7 +83,7 @@ export class BaseModelRequestHandlerComponent extends BaseUiComponent implements
}

protected onBeforeModelRequests(): void | Promise<void> {}
protected onShouldCreateModelRequests(): void {}
protected onShouldCreateModelRequests(_params?: any, _meetingId?: Id | null): void {}
protected onNextMeetingId(_id: Id | null): void {}
protected onParamsChanged(_params: any, _oldParams?: any): void {}

Expand Down Expand Up @@ -125,7 +129,7 @@ export class BaseModelRequestHandlerComponent extends BaseUiComponent implements

private async initModelSubscriptions(): Promise<void> {
await this.onBeforeModelRequests();
this.onShouldCreateModelRequests();
this.onShouldCreateModelRequests(this._currentParams, this._currentMeetingId);
}

private createHideWhenObservable(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Directive } from '@angular/core';
import { Id } from 'src/app/domain/definitions/key-types';
import { SubscriptionConfig } from 'src/app/domain/interfaces/subscription-config';
import { BaseModelRequestHandlerComponent } from 'src/app/site/base/base-model-request-handler.component';

@Directive()
export abstract class BaseMeetingModelRequestHandler extends BaseModelRequestHandlerComponent {
protected abstract getSubscriptions(meetingId: Id): SubscriptionConfig<any>[];

protected override onShouldCreateModelRequests(_params: any, id: number | null): void {
if (id) {
this.subscribeTo(this.getSubscriptions(id), { hideWhenMeetingChanged: true });
}
}

protected override onNextMeetingId(id: number | null): void {
if (id) {
this.updateSubscribeTo(this.getSubscriptions(id), { hideWhenMeetingChanged: true });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { AfterViewInit, Component, Input, OnDestroy } from '@angular/core';
import { AbstractControl, UntypedFormGroup } from '@angular/forms';
import { BehaviorSubject, map, Observable, Subscription } from 'rxjs';
import { Permission } from 'src/app/domain/definitions/permission';
import { SubscriptionConfig } from 'src/app/domain/interfaces/subscription-config';
import { ItemTypeChoices } from 'src/app/domain/models/agenda/agenda-item';
import { BaseModelRequestHandlerComponent } from 'src/app/site/base/base-model-request-handler.component';
import { BaseMeetingModelRequestHandler } from 'src/app/site/pages/meetings/base/base-meeting-model-request-handler.component';
import { ViewAgendaItem } from 'src/app/site/pages/meetings/pages/agenda';
import { getAgendaListMinimalSubscriptionConfig } from 'src/app/site/pages/meetings/pages/agenda/agenda.subscription';
import { MeetingSettingsService } from 'src/app/site/pages/meetings/services/meeting-settings.service';
Expand All @@ -16,7 +17,7 @@ import { AgendaContentObjectFormService } from '../../services/agenda-content-ob
styleUrls: [`./agenda-content-object-form.component.scss`]
})
export class AgendaContentObjectFormComponent
extends BaseModelRequestHandlerComponent
extends BaseMeetingModelRequestHandler
implements AfterViewInit, OnDestroy
{
@Input()
Expand Down Expand Up @@ -92,10 +93,8 @@ export class AgendaContentObjectFormComponent
super.ngOnDestroy();
}

protected override onNextMeetingId(id: number | null): void {
if (id) {
this.subscribeTo(getAgendaListMinimalSubscriptionConfig(id), { hideWhenDestroyed: true });
}
protected getSubscriptions(meetingId: number): SubscriptionConfig<any>[] {
return [getAgendaListMinimalSubscriptionConfig(meetingId)];
}

private setupSubscription(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Component } from '@angular/core';
import { BaseModelRequestHandlerComponent } from 'src/app/site/base/base-model-request-handler.component';
import { Id } from 'src/app/domain/definitions/key-types';
import { SubscriptionConfig } from 'src/app/domain/interfaces/subscription-config';
import { BaseMeetingModelRequestHandler } from 'src/app/site/pages/meetings/base/base-meeting-model-request-handler.component';

import { getAgendaListSubscriptionConfig } from '../../agenda.subscription';

Expand All @@ -8,10 +10,8 @@ import { getAgendaListSubscriptionConfig } from '../../agenda.subscription';
templateUrl: `./agenda-main.component.html`,
styleUrls: [`./agenda-main.component.scss`]
})
export class AgendaMainComponent extends BaseModelRequestHandlerComponent {
protected override onNextMeetingId(id: number | null): void {
if (id) {
this.subscribeTo(getAgendaListSubscriptionConfig(id), { hideWhenMeetingChanged: true });
}
export class AgendaMainComponent extends BaseMeetingModelRequestHandler {
protected getSubscriptions(id: Id): SubscriptionConfig<any>[] {
return [getAgendaListSubscriptionConfig(id)];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,30 @@ export class ListOfSpeakersMainComponent extends BaseModelRequestHandlerComponen

protected override onParamsChanged(params: any, oldParams: any): void {
if (params[`id`] !== oldParams[`id`] || params[`meetingId`] !== oldParams[`meetingId`]) {
this.sequentialNumberMapping
.getIdBySequentialNumber({
collection: ListOfSpeakers.COLLECTION,
meetingId: params[`meetingId`],
sequentialNumber: +params[`id`]
})
.then(id => {
if (id && this._currentLOSId !== id) {
this._currentLOSId = id;
this.loadLOSDetail();
}
});
this.loadLOSDetail(+params[`id`], +params[`meetingId`]);
}
}

private loadLOSDetail(): void {
this.updateSubscribeTo(getListOfSpeakersDetailSubscriptionConfig(this._currentLOSId), {
hideWhenDestroyed: true
});
protected override onShouldCreateModelRequests(params: any, meetingId: Id): void {
if (params[`id`] && meetingId) {
this.loadLOSDetail(+params[`id`], meetingId);
}
}

private loadLOSDetail(id: Id, meetingId: Id): void {
this.sequentialNumberMapping
.getIdBySequentialNumber({
collection: ListOfSpeakers.COLLECTION,
meetingId: meetingId,
sequentialNumber: id
})
.then(id => {
if (id && this._currentLOSId !== id) {
this._currentLOSId = id;
this.updateSubscribeTo(getListOfSpeakersDetailSubscriptionConfig(this._currentLOSId), {
hideWhenDestroyed: true
});
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,44 @@ export class TopicDetailMainComponent extends BaseModelRequestHandlerComponent {
super();
}

protected override onShouldCreateModelRequests(params: any, meetingId: any): void {
if (meetingId) {
if (+params[`id`]) {
this.loadTopicDetail(+params[`id`], +params[`meetingId`]);
} else {
this.loadTopicList(+params[`meetingId`]);
}
}
}

protected override onParamsChanged(params: any, oldParams: any): void {
if (params[`id`] !== oldParams[`id`] || params[`meetingId`] !== oldParams[`meetingId`]) {
this.sequentialNumberMapping
.getIdBySequentialNumber({
collection: Topic.COLLECTION,
meetingId: params[`meetingId`],
sequentialNumber: +params[`id`]
})
.then(id => {
if (id && this._currentTopicId !== id) {
this._currentTopicId = id;
this.loadTopicDetail();
} else if (!id && params[`meetingId`]) {
this.loadTopicList(+params[`meetingId`]);
}
});
if (
params[`id`] !== oldParams[`id`] ||
(+params[`meetingId`] && params[`meetingId`] !== oldParams[`meetingId`])
) {
if (+params[`id`]) {
this.loadTopicDetail(+params[`id`], +params[`meetingId`]);
} else {
this.loadTopicList(+params[`meetingId`]);
}
}
}

private loadTopicDetail(): void {
this.updateSubscribeTo(getTopicDetailSubscriptionConfig(this._currentTopicId), { hideWhenDestroyed: true });
private loadTopicDetail(sNr: Id, meetingId: Id): void {
this.sequentialNumberMapping
.getIdBySequentialNumber({
collection: Topic.COLLECTION,
meetingId,
sequentialNumber: sNr
})
.then(id => {
if (id && this._currentTopicId !== id) {
this._currentTopicId = id;
this.updateSubscribeTo(getTopicDetailSubscriptionConfig(this._currentTopicId), {
hideWhenDestroyed: true
});
}
});
}

private async loadTopicList(meetingId: number): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Component } from '@angular/core';
import { BaseModelRequestHandlerComponent } from 'src/app/site/base/base-model-request-handler.component';
import { Id } from 'src/app/domain/definitions/key-types';
import { SubscriptionConfig } from 'src/app/domain/interfaces/subscription-config';
import { BaseMeetingModelRequestHandler } from 'src/app/site/pages/meetings/base/base-meeting-model-request-handler.component';

import { getAgendaListSubscriptionConfig } from '../../../../../../agenda.subscription';

Expand All @@ -8,10 +10,8 @@ import { getAgendaListSubscriptionConfig } from '../../../../../../agenda.subscr
templateUrl: `./topic-import-main.component.html`,
styleUrls: [`./topic-import-main.component.scss`]
})
export class TopicImportMainComponent extends BaseModelRequestHandlerComponent {
protected override onNextMeetingId(id: number | null): void {
if (id) {
this.subscribeTo(getAgendaListSubscriptionConfig(id), { hideWhenMeetingChanged: true });
}
export class TopicImportMainComponent extends BaseMeetingModelRequestHandler {
protected getSubscriptions(id: Id): SubscriptionConfig<any>[] {
return [getAgendaListSubscriptionConfig(id)];
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Component } from '@angular/core';
import { BaseModelRequestHandlerComponent } from 'src/app/site/base/base-model-request-handler.component';
import { Id } from 'src/app/domain/definitions/key-types';
import { SubscriptionConfig } from 'src/app/domain/interfaces/subscription-config';

import { BaseMeetingModelRequestHandler } from '../../../../base/base-meeting-model-request-handler.component';
import { getAssignmentSubscriptionConfig } from '../../assignments.subscription';

@Component({
selector: `os-assignment-main`,
templateUrl: `./assignment-main.component.html`,
styleUrls: [`./assignment-main.component.scss`]
})
export class AssignmentMainComponent extends BaseModelRequestHandlerComponent {
protected override onNextMeetingId(id: number | null): void {
if (id) {
this.subscribeTo(getAssignmentSubscriptionConfig(id), { hideWhenMeetingChanged: true });
}
export class AssignmentMainComponent extends BaseMeetingModelRequestHandler {
protected getSubscriptions(id: Id): SubscriptionConfig<any>[] {
return [getAssignmentSubscriptionConfig(id)];
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from '@angular/core';
import { Id } from 'src/app/domain/definitions/key-types';
import { BaseModelRequestHandlerComponent } from 'src/app/site/base/base-model-request-handler.component';
import { SequentialNumberMappingService } from 'src/app/site/pages/meetings/services/sequential-number-mapping.service';

Expand All @@ -16,12 +17,12 @@ export class AssignmentPollMainComponent extends BaseModelRequestHandlerComponen
super();
}

protected override onParamsChanged(params: any, oldParams: any): void {
if (params[`id`] && params[`id`] !== oldParams[`id`]) {
protected override onShouldCreateModelRequests(params: any, meetingId: Id): void {
if (params[`id`]) {
this.sequentialNumberMappingService
.getIdBySequentialNumber({
collection: ViewPoll.COLLECTION,
meetingId: params[`meetingId`],
meetingId,
sequentialNumber: +params[`id`]
})
.then(id => {
Expand All @@ -34,4 +35,23 @@ export class AssignmentPollMainComponent extends BaseModelRequestHandlerComponen
});
}
}

protected override onParamsChanged(params: any, oldParams: any): void {
if ((params[`id`] && params[`id`] !== oldParams[`id`]) || params[`meetingId`] !== oldParams[`meetingId`]) {
this.sequentialNumberMappingService
.getIdBySequentialNumber({
collection: ViewPoll.COLLECTION,
meetingId: params[`meetingId`],
sequentialNumber: +params[`id`]
})
.then(id => {
if (id) {
this.updateSubscribeTo(getPollDetailSubscriptionConfig(id), { hideWhenDestroyed: true });
this.updateSubscribeTo(getParticipantMinimalSubscriptionConfig(+params[`meetingId`]), {
hideWhenDestroyed: true
});
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Component } from '@angular/core';
import { distinctUntilChanged, map } from 'rxjs';
import { Id } from 'src/app/domain/definitions/key-types';
import { SubscriptionConfig } from 'src/app/domain/interfaces/subscription-config';
import { ProjectorRepositoryService } from 'src/app/gateways/repositories/projectors/projector-repository.service';
import { collectionFromFqid } from 'src/app/infrastructure/utils/transform-functions';
import { BaseModelRequestHandlerComponent } from 'src/app/site/base/base-model-request-handler.component';
import { BaseMeetingModelRequestHandler } from 'src/app/site/pages/meetings/base/base-meeting-model-request-handler.component';
import { CollectionMapperService } from 'src/app/site/services/collection-mapper.service';

import {
Expand All @@ -17,7 +18,7 @@ import {
templateUrl: `./autopilot-main.component.html`,
styleUrls: [`./autopilot-main.component.scss`]
})
export class AutopilotMainComponent extends BaseModelRequestHandlerComponent {
export class AutopilotMainComponent extends BaseMeetingModelRequestHandler {
private currentSubscriptions: Id[] = [];

public constructor(
Expand Down Expand Up @@ -83,11 +84,7 @@ export class AutopilotMainComponent extends BaseModelRequestHandlerComponent {
);
}

protected override onNextMeetingId(id: number | null): void {
if (id) {
this.subscribeTo(getAutopilotSubscriptionConfig(id), {
hideWhenMeetingChanged: true
});
}
protected getSubscriptions(id: Id): SubscriptionConfig<any>[] {
return [getAutopilotSubscriptionConfig(id)];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getParticipantMinimalSubscriptionConfig } from '../../../participants/p
styleUrls: [`./history-main.component.scss`]
})
export class HistoryMainComponent extends BaseModelRequestHandlerComponent {
protected override onNextMeetingId(id: Id | null): void {
protected override onShouldCreateModelRequests(_params: any, id: Id | null): void {
if (id) {
this.subscribeTo(getMotionListMinimalSubscriptionConfig(id), { hideWhenDestroyed: true });
this.subscribeTo(getParticipantMinimalSubscriptionConfig(id), { hideWhenDestroyed: true });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Component } from '@angular/core';
import { BaseModelRequestHandlerComponent } from 'src/app/site/base/base-model-request-handler.component';
import { Id } from 'src/app/domain/definitions/key-types';
import { SubscriptionConfig } from 'src/app/domain/interfaces/subscription-config';

import { BaseMeetingModelRequestHandler } from '../../../../base/base-meeting-model-request-handler.component';
import { getMediafilesSubscriptionConfig } from '../../mediafiles.subscription';

@Component({
selector: `os-mediafile-main`,
templateUrl: `./mediafile-main.component.html`,
styleUrls: [`./mediafile-main.component.scss`]
})
export class MediafileMainComponent extends BaseModelRequestHandlerComponent {
protected override onNextMeetingId(id: number | null): void {
if (id) {
this.subscribeTo(getMediafilesSubscriptionConfig(id), { hideWhenMeetingChanged: true });
}
export class MediafileMainComponent extends BaseMeetingModelRequestHandler {
protected getSubscriptions(id: Id): SubscriptionConfig<any>[] {
return [getMediafilesSubscriptionConfig(id)];
}
}
Loading

0 comments on commit 0f2f4b7

Please sign in to comment.