Skip to content

Commit

Permalink
Improve motion meta
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianjoel committed Aug 15, 2024
1 parent 86db014 commit 3724a94
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 252 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Directive, inject, Input } from '@angular/core';
import { ChangeDetectorRef, Directive, inject, Input } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { filter, Subscription } from 'rxjs';
import { ChangeRecoMode, LineNumberingMode } from 'src/app/domain/models/motions/motions.constants';
Expand All @@ -21,6 +21,8 @@ import { MotionDetailViewService } from '../services/motion-detail-view.service'

@Directive()
export abstract class BaseMotionDetailChildComponent extends BaseMeetingComponent {
protected cd: ChangeDetectorRef = inject(ChangeDetectorRef);

@Input()
public set motion(motion: ViewMotion) {
const previousMotion = this._motion;
Expand All @@ -34,6 +36,7 @@ export abstract class BaseMotionDetailChildComponent extends BaseMeetingComponen
}

this.onAfterSetMotion(previousMotion, motion);
this.cd.markForCheck();
}

public get motion(): ViewMotion {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectorRef, Component, EventEmitter, Output } from '@angular/core';
import { Component, EventEmitter, Output } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
Expand Down Expand Up @@ -147,7 +147,6 @@ export class MotionContentComponent extends BaseMotionDetailChildComponent {
private fb: UntypedFormBuilder,
private dialog: MotionChangeRecommendationDialogService,
private route: ActivatedRoute,
private cd: ChangeDetectorRef,
private perms: MotionPermissionService,
private motionController: MotionControllerService,
public participantSortService: ParticipantListSortService
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject, distinctUntilChanged, map, Observable, Subscription } from 'rxjs';
import { BehaviorSubject, map, Observable, Subscription } from 'rxjs';
import { Permission } from 'src/app/domain/definitions/permission';
import { Selectable } from 'src/app/domain/interfaces';
import { Settings } from 'src/app/domain/models/meetings/meeting';
Expand All @@ -26,14 +26,13 @@ import { SearchListDefinition } from '../motion-extension-field/motion-extension
@Component({
selector: `os-motion-meta-data`,
templateUrl: `./motion-meta-data.component.html`,
styleUrls: [`./motion-meta-data.component.scss`]
styleUrls: [`./motion-meta-data.component.scss`],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MotionMetaDataComponent extends BaseMotionDetailChildComponent implements OnInit, OnDestroy {
public motionBlocks: MotionBlock[] = [];

public categories: ViewMotionCategory[] = [];

public tags: ViewTag[] = [];
public categories$: Observable<ViewMotionCategory[]> = this.categoryRepo.getViewModelListObservable();
public tags$: Observable<ViewTag[]> = this.tagRepo.getViewModelListObservable();
public motionBlocks$: Observable<MotionBlock[]> = this.blockRepo.getViewModelListObservable();

/**
* Determine if the name of supporters are visible
Expand Down Expand Up @@ -89,7 +88,28 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
/**
* All amendments to this motion
*/
public override amendments: ViewMotion[] = [];
public amendments$: Observable<ViewMotion[]> = null;

public get referencingMotions$(): Observable<ViewMotion[]> {
return this.motion?.referenced_in_motion_recommendation_extensions$.pipe(
map(motions => motions.naturalSort(this.translate.currentLang, [`number`, `title`]))
);
}

public get referencedMotions$(): Observable<ViewMotion[]> {
return this.motion?.recommendation_extension_references$.pipe(
map(motions => (motions as ViewMotion[]).naturalSort(this.translate.currentLang, [`number`, `title`]))
);
}

public get originMotions$(): Observable<ViewMotion[] | ViewMeeting[]> {
if (this.motion.origin_id) {
return this.motion.all_origins$.pipe(map(origins => origins?.reverse()));
} else if (this.motion.origin_meeting_id) {
return this.motion.origin_meeting$.pipe(map(origin => [origin]));
}
return null;
}

public override set showAllAmendments(is: boolean) {
this.viewService.showAllAmendmentsStateSubject.next(is);
Expand All @@ -104,20 +124,8 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
);
}

public get referencingMotions(): ViewMotion[] {
return this._referencingMotions;
}

public get referencedMotions(): ViewMotion[] {
return this._referencedMotions;
}

public loadForwardingCommittees: () => Promise<Selectable[]>;

private _referencingMotions: ViewMotion[];

private _referencedMotions: ViewMotion[];

private _forwardingAvailable = false;

public get supportersObservable(): Observable<ViewUser[]> {
Expand Down Expand Up @@ -170,6 +178,16 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
super.ngOnDestroy();
}

protected override onAfterInit(): void {
this.setupRecommender();
}

protected override onAfterSetMotion(previous: ViewMotion, current: ViewMotion): void {
super.onAfterSetMotion(previous, current);
this.amendments$ = this.amendmentRepo.getViewModelListObservableFor(current);
this.updateSupportersSubject();
}

/**
* Sets the state
*
Expand Down Expand Up @@ -297,15 +315,6 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
return allStates.filter(state => state.recommendation_label).sort((a, b) => a.weight - b.weight);
}

public getOriginMotions(): (ViewMotion | ViewMeeting)[] {
const copy = this.motion.origin_id
? [...(this.motion.all_origins || [])]
: this.motion.origin_meeting
? [this.motion.origin_meeting]
: [];
return copy.reverse();
}

public getMeetingName(origin: ViewMotion | ViewMeeting): string {
if (this.isViewMotion(origin)) {
const motion = origin as ViewMotion;
Expand All @@ -330,11 +339,6 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
return origin?.canAccess();
}

protected override onAfterSetMotion(previous: ViewMotion, current: ViewMotion): void {
super.onAfterSetMotion(previous, current);
this.updateSupportersSubject();
}

private async updateSupportersSubject(): Promise<void> {
this._supportersSubject.next(await this.participantSort.sort(this.motion.supporters));
}
Expand All @@ -343,32 +347,6 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
return toTest.COLLECTION === Motion.COLLECTION;
}

protected override getSubscriptions(): Subscription[] {
return [
this.amendmentRepo.getViewModelListObservableFor(this.motion).subscribe(value => (this.amendments = value)),
this.tagRepo.getViewModelListObservable().subscribe(value => (this.tags = value)),
this.categoryRepo.getViewModelListObservable().subscribe(value => (this.categories = value)),
this.blockRepo.getViewModelListObservable().subscribe(value => (this.motionBlocks = value)),
this.repo
.getViewModelObservable(this.motion.id)
.pipe(
map(motion => [
motion?.referenced_in_motion_recommendation_extensions,
motion?.recommendation_extension_references as ViewMotion[]
]),
distinctUntilChanged((p, c) => [...Array(2).keys()].every(i => p[i].equals(c[i]))),
map(arr =>
arr.map(motions => (motions || []).naturalSort(this.translate.currentLang, [`number`, `title`]))
)
)
.subscribe(value => ([this._referencingMotions, this._referencedMotions] = value))
];
}

protected override onAfterInit(): void {
this.setupRecommender();
}

/**
* Observes the repository for changes in the motion recommender
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { TranslateService } from '@ngx-translate/core';
import { UnsafeHtml } from 'src/app/domain/definitions/key-types';
Expand Down Expand Up @@ -60,8 +60,7 @@ export class MotionParagraphbasedAmendmentComponent extends BaseMotionDetailChil

public constructor(
protected override translate: TranslateService,
private fb: UntypedFormBuilder,
private cd: ChangeDetectorRef
private fb: UntypedFormBuilder
) {
super();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
Input,
Output
} from '@angular/core';
import { ChangeDetectionStrategy, Component, ElementRef, EventEmitter, Input, Output } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { TranslateService } from '@ngx-translate/core';
import { UnsafeHtml } from 'src/app/domain/definitions/key-types';
Expand Down Expand Up @@ -76,7 +68,6 @@ export class ParagraphBasedAmendmentComponent extends BaseMotionDetailChildCompo
public constructor(
protected override translate: TranslateService,
private fb: UntypedFormBuilder,
private cd: ChangeDetectorRef,
private el: ElementRef
) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ import { ViewMotionSubmitter } from '../modules/submitters';
import { HasTags } from '../modules/tags/view-models/has-tags';
import { ViewMotionWorkingGroupSpeaker } from '../modules/working-group-speakers';

export interface HasReferencedMotionsInExtension extends HasReferencedMotionInExtensionIds {
referenced_in_motion_state_extensions: ViewMotion[];
referenced_in_motion_recommendation_extensions: ViewMotion[];
}
export type HasReferencedMotionsInExtension = HasReferencedMotionInExtensionIds &
ViewModelRelations<{
referenced_in_motion_state_extensions: ViewMotion[];
referenced_in_motion_recommendation_extensions: ViewMotion[];
}>;

export enum ForwardingStatus {
none = `none`,
Expand Down

0 comments on commit 3724a94

Please sign in to comment.