Skip to content

Commit

Permalink
Cleanup motion content component
Browse files Browse the repository at this point in the history
Change detection for amendments and crs not working yet
  • Loading branch information
bastianjoel committed Aug 16, 2024
1 parent 2579251 commit 385b402
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 357 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
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
@@ -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
@@ -1,6 +1,6 @@
import { ChangeDetectorRef, Directive, inject, Input } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { filter, Subscription } from 'rxjs';
import { filter, Observable, Subscription } from 'rxjs';
import { ChangeRecoMode, LineNumberingMode } from 'src/app/domain/models/motions/motions.constants';
import { BaseMeetingComponent } from 'src/app/site/pages/meetings/base/base-meeting.component';
import { ViewMotion, ViewMotionChangeRecommendation } from 'src/app/site/pages/meetings/pages/motions';
Expand Down Expand Up @@ -62,10 +62,18 @@ export abstract class BaseMotionDetailChildComponent extends BaseMeetingComponen
return this.viewService.currentLineNumberingMode;
}

public get lineNumberingMode$(): Observable<LineNumberingMode> {
return this.viewService.lineNumberingModeSubject;
}

public get changeRecoMode(): ChangeRecoMode {
return this.viewService.currentChangeRecommendationMode;
}

public get changeRecoMode$(): Observable<ChangeRecoMode> {
return this.viewService.changeRecommendationModeSubject;
}

public get hasChangingObjects(): boolean {
if (this.sortedChangingObjects !== null) {
return this.sortedChangingObjects.length > 0;
Expand All @@ -88,6 +96,10 @@ export abstract class BaseMotionDetailChildComponent extends BaseMeetingComponen
return this.viewService.currentShowAllAmendmentsState;
}

public get showAllAmendments$(): Observable<boolean> {
return this.viewService.showAllAmendmentsStateSubject;
}

///////////////////////////////////////////////
/////// Getter to repos & services
///////////////////////////////////////////////
Expand Down Expand Up @@ -156,12 +168,19 @@ export abstract class BaseMotionDetailChildComponent extends BaseMeetingComponen
* All change recommendations to this motion
*/
public changeRecommendations: ViewUnifiedChange[] = [];
public get changeRecommendations$(): Observable<ViewUnifiedChange[]> {
return this.changeRecoRepo.getChangeRecosOfMotionObservable(this.motion.id).pipe(filter(value => !!value));
}

/**
* Value for os-motion-detail-diff: when this is set, that component scrolls to the given change
*/
public scrollToChange: ViewUnifiedChange | null = null;

protected amendments: ViewMotion[] = [];
protected get amendments$(): Observable<ViewMotion[]> {
return this.amendmentRepo.getViewModelListObservableFor(this.motion).pipe(filter(value => !!value));
}

private _isEditing = false;
private _motion: ViewMotion | null = null;
Expand Down Expand Up @@ -233,21 +252,17 @@ export abstract class BaseMotionDetailChildComponent extends BaseMeetingComponen

private getSharedSubscriptionsToRepositories(): Subscription[] {
return [
this.changeRecoRepo
.getChangeRecosOfMotionObservable(this.motion.id)
.pipe(filter(value => !!value))
.subscribe(changeRecos => {
this.changeRecommendations = changeRecos;
this.sortedChangingObjects = null;
}),
this.amendmentRepo
.getViewModelListObservableFor(this.motion)
.pipe(filter(value => !!value))
.subscribe((amendments: ViewMotion[]): void => {
this.amendments = amendments;
this.motionLineNumbering.resetAmendmentChangeRecoListeners(amendments);
this.sortedChangingObjects = null;
})
this.changeRecommendations$.subscribe(changeRecos => {
console.log(`crs updated`);
this.changeRecommendations = changeRecos;
this.sortedChangingObjects = null;
}),
this.amendments$.subscribe((amendments: ViewMotion[]): void => {
console.log(`amendments updated`);
this.amendments = amendments;
this.motionLineNumbering.resetAmendmentChangeRecoListeners(amendments);
this.sortedChangingObjects = null;
})
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<!-- Regular motions or traditional amendments -->
@if (!motion.isParagraphBasedAmendment()) {
<!-- Text (hide preamble, if diff mode. The preample is included in the motion-detail-diff component) -->
@if (showPreamble && changeRecoMode !== ChangeRecoMode.Diff) {
<span class="text-prefix-label">
{{ preamble }}
</span>
}
@if (changeRecoMode !== ChangeRecoMode.Diff && !isFinalEdit) {
@if (!isParagraphBasedAmendment) {
@let changeRecoMode = changeRecoMode$ | async;
@let lineNumberingMode = lineNumberingMode$ | async;

@if (changeRecoMode !== ChangeRecoMode.Diff) {
<!-- Text (hide preamble, if diff mode. The preample is included in the motion-detail-diff component) -->
@if (showPreamble) {
<span class="text-prefix-label">
{{ preamble }}
</span>
}

<div
class="motion-text underlined-links"
[class.line-numbers-inline]="lineNumberingMode === LineNumberingMode.Inside"
Expand All @@ -21,16 +25,14 @@
(createChangeRecommendation)="createChangeRecommendation($event)"
(gotoChangeRecommendation)="gotoChangeRecommendation($event)"
></os-motion-detail-original-change-recommendations>
}
@if (lineNumberingMode !== LineNumberingMode.Outside || changeRecoMode !== ChangeRecoMode.Original) {
} @else {
<os-motion-final-version
[formattedText]="getFormattedTextPlain()"
[motion]="motion"
></os-motion-final-version>
}
</div>
}
@if (changeRecoMode === ChangeRecoMode.Diff) {
} @else {
<os-motion-detail-diff
[changes]="getChangesForDiffMode()"
[highlightedLine]="highlightedLine"
Expand All @@ -41,16 +43,13 @@
(createChangeRecommendation)="createChangeRecommendation($event)"
></os-motion-detail-diff>
}
} @else if (isParagraphBasedAmendment) {
} @else {
<!-- Paragraph-based amendments -->
<os-paragraph-based-amendment
[changesForDiffMode]="getChangesForDiffMode()"
[highlightedLine]="highlightedLine"
[isFinalEdit]="isFinalEdit"
[motion]="motion"
(createChangeRecommendation)="createChangeRecommendation($event)"
(formChanged)="paragraphBasedAmendmentContent = $event"
(validStateChanged)="canSaveParagraphBasedAmendment = $event"
></os-paragraph-based-amendment>
}

Expand Down
Loading

0 comments on commit 385b402

Please sign in to comment.