Skip to content

Commit

Permalink
Motion detail refactoring (#4024)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianjoel authored Sep 16, 2024
1 parent 37b113f commit 56e5cf3
Show file tree
Hide file tree
Showing 128 changed files with 3,003 additions and 3,081 deletions.
4 changes: 4 additions & 0 deletions client/src/app/gateways/repositories/base-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@ export abstract class BaseRepository<V extends BaseViewModel, M extends BaseMode
result = this.relationManager.handleRelation(_model, relation);
}
return result;
},
set: (obj, ...args): any => {
obj.viewModelUpdateTimestamp = Date.now();
return Reflect.set(obj, ...args);
}
});
this._createViewModelPipes.forEach(fn => fn(viewModel));
Expand Down
4 changes: 4 additions & 0 deletions client/src/app/infrastructure/utils/subscription-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export class SubscriptionMap {
this._subscriptions = {};
}

public size(): number {
return Object.keys(this._subscriptions).length;
}

private nextRandomId(): string {
const id = Math.floor(Math.random() * (900000 - 1) + 100000);
return id.toString();
Expand Down
2 changes: 2 additions & 0 deletions client/src/app/site/base/base-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface ViewModelConstructor<T extends BaseViewModel> {
* Base class for view models.
*/
export abstract class BaseViewModel<M extends BaseModel = any> implements DetailNavigable {
public viewModelUpdateTimestamp = Date.now();

public get fqid(): Fqid {
return this.getModel().fqid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@
margin-top: -3px;
transform: scale(0.75);
}

@keyframes train {
0% {
right: 0;
}
99% {
right: 100%;
}
100% {
right: 100%;
display: none;
}
}

.global-headbar.train:after {
content: '🚂 🚃 🚃 🚃';
position: absolute;
overflow: hidden;
animation-name: train;
animation-duration: 15s;
animation-fill-mode: forwards;
animation-iteration-count: 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import {
OnInit,
Output
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { marker as _ } from '@colsen1991/ngx-translate-extract-marker';
import { Subscription } from 'rxjs';
import { Collection, Id } from 'src/app/domain/definitions/key-types';
import { ActiveMeetingService } from 'src/app/site/pages/meetings/services/active-meeting.service';
import { ActiveMeetingIdService } from 'src/app/site/pages/meetings/services/active-meeting-id.service';
import { SequentialNumberMappingService } from 'src/app/site/pages/meetings/services/sequential-number-mapping.service';

Expand Down Expand Up @@ -44,29 +45,38 @@ export class DetailViewComponent implements OnInit {
private _shouldShowContent = false;
private _loading = true;
private _id!: Id;
private _sequential_number!: number;

private _subscriptionMap: { [name: string]: Subscription } = {};

public constructor(
private sequentialNumberMappingService: SequentialNumberMappingService,
private activeMeetingService: ActiveMeetingService,
private activeMeetingIdService: ActiveMeetingIdService,
private route: ActivatedRoute,
private router: Router,
private cd: ChangeDetectorRef
) {}

public ngOnInit(): void {
this.activeMeetingIdService.meetingIdObservable.subscribe(() => this.onMeetingChanged());
this.activeMeetingService.meetingIdObservable.subscribe(id => this.onMeetingChanged(id));
}

private onMeetingChanged(): void {
const subscription = this.route.params.subscribe(params => {
this.parseSequentialNumber(params);
private onMeetingChanged(meetingId: Id): void {
this.deleteSubscription(ROUTE_SUBSCRIPTION_NAME);
this.activeMeetingService.ensureActiveMeetingIsAvailable().then(() => {
const subscription = this.route.params.subscribe(params => {
if (this.activeMeetingIdService.parseUrlMeetingId(this.router.url) === meetingId) {
this.parseSequentialNumber(params);
}
});
this.updateSubscription(ROUTE_SUBSCRIPTION_NAME, subscription);
});
this.updateSubscription(ROUTE_SUBSCRIPTION_NAME, subscription);
}

private parseSequentialNumber(params: { id?: string }): void {
const sequentialNumber = +(params.id ?? 0);
this._sequential_number = sequentialNumber;
if (!sequentialNumber && params.id === undefined) {
// it must be another subroute, like creating a new one
this._shouldShowContent = true;
Expand All @@ -76,12 +86,12 @@ export class DetailViewComponent implements OnInit {
const config = {
collection: this.collection,
sequentialNumber,
meetingId: this.activeMeetingIdService.meetingId!
meetingId: this.activeMeetingService.meetingId!
};

this.sequentialNumberMappingService.getIdBySequentialNumber(config).then(id => {
this._loading = false;
if (id !== undefined) {
if (id !== undefined && this._sequential_number === sequentialNumber) {
if (id) {
if (this._id !== id) {
this._id = id;
Expand Down Expand Up @@ -109,4 +119,11 @@ export class DetailViewComponent implements OnInit {
}
this._subscriptionMap[subscriptionName] = subscription;
}

private deleteSubscription(subscriptionName: string): void {
if (this._subscriptionMap[subscriptionName]) {
this._subscriptionMap[subscriptionName].unsubscribe();
this._subscriptionMap[subscriptionName] = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export abstract class BasePollComponent<C extends PollContentObject = any> exten
return this._poll;
}

protected set poll(poll: ViewPoll) {
this._poll = poll;
this.onAfterUpdatePoll(poll);
}

public pollStateActions = {
[PollState.Created]: {
icon: `play_arrow`,
Expand Down Expand Up @@ -110,8 +115,7 @@ export abstract class BasePollComponent<C extends PollContentObject = any> exten
this.subscriptions.push(
this.repo.getViewModelObservable(this._id).subscribe(poll => {
if (poll) {
this._poll = poll;
this.onAfterUpdatePoll(poll);
this.poll = poll;
}
})
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { map, Observable } from 'rxjs';
import { distinctUntilChanged, map, Observable } from 'rxjs';
import { Id } from 'src/app/domain/definitions/key-types';
import { Identifiable } from 'src/app/domain/interfaces';
import { MotionChangeRecommendation } from 'src/app/domain/models/motions/motion-change-recommendation';
Expand Down Expand Up @@ -47,7 +47,13 @@ export class MotionChangeRecommendationControllerService extends BaseMeetingCont
*/
public getChangeRecosOfMotionObservable(motionId: Id): Observable<ViewMotionChangeRecommendation[]> {
return this.getViewModelListObservable().pipe(
map((recos: ViewMotionChangeRecommendation[]) => recos.filter(reco => reco.motion_id === motionId))
map((recos: ViewMotionChangeRecommendation[]) => recos.filter(reco => reco.motion_id === motionId)),
distinctUntilChanged(
(prev, curr) =>
prev?.length === curr?.length &&
Math.max(...prev.map(e => e.viewModelUpdateTimestamp)) ===
Math.max(...curr.map(e => e.viewModelUpdateTimestamp))
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BasePollComponent } from 'src/app/site/pages/meetings/modules/poll/base
import { OperatorService } from 'src/app/site/services/operator.service';

import { VotingPrivacyWarningDialogService } from '../../../../../../modules/poll/modules/voting-privacy-dialog/services/voting-privacy-warning-dialog.service';
import { ViewPoll } from '../../../../../polls';
import { MotionPollService } from '../../services';
import { MotionPollPdfService } from '../../services/motion-poll-pdf.service/motion-poll-pdf.service';

Expand All @@ -16,6 +17,11 @@ import { MotionPollPdfService } from '../../services/motion-poll-pdf.service/mot
styleUrls: [`./motion-poll.component.scss`]
})
export class MotionPollComponent extends BasePollComponent {
@Input()
public set pollViewModel(poll: ViewPoll) {
this.poll = poll;
}

@Input()
public set pollId(id: Id) {
this.initializePoll(id);
Expand Down
Loading

0 comments on commit 56e5cf3

Please sign in to comment.