From d90e88fa537dae89ebc2b0eec2078ced14b0bc9e Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Fri, 8 Mar 2019 11:38:18 +0100 Subject: [PATCH] Sort motions on the motion block slide --- .../slides/motions/base/base-motion-slide.ts | 6 ++- .../motion-block/motion-block-slide-data.ts | 7 +-- .../motion-block-slide.component.ts | 53 +++++++++++++++---- 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/client/src/app/slides/motions/base/base-motion-slide.ts b/client/src/app/slides/motions/base/base-motion-slide.ts index e03f61add..9ad627917 100644 --- a/client/src/app/slides/motions/base/base-motion-slide.ts +++ b/client/src/app/slides/motions/base/base-motion-slide.ts @@ -2,7 +2,11 @@ import { TranslateService } from '@ngx-translate/core'; import { BaseSlideComponent } from 'app/slides/base-slide-component'; import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; -import { MotionTitleInformation } from '../motion-block/motion-block-slide-data'; + +export interface MotionTitleInformation { + title: string; + identifier?: string; +} /** * Format for referenced motions: A mapping of motion ids to their title information. diff --git a/client/src/app/slides/motions/motion-block/motion-block-slide-data.ts b/client/src/app/slides/motions/motion-block/motion-block-slide-data.ts index 98b3e79dd..382e1b0c9 100644 --- a/client/src/app/slides/motions/motion-block/motion-block-slide-data.ts +++ b/client/src/app/slides/motions/motion-block/motion-block-slide-data.ts @@ -1,9 +1,4 @@ -import { ReferencedMotions } from '../base/base-motion-slide'; - -export interface MotionTitleInformation { - title: string; - identifier?: string; -} +import { ReferencedMotions, MotionTitleInformation } from '../base/base-motion-slide'; export interface MotionBlockSlideMotionRepresentation extends MotionTitleInformation { recommendation?: { diff --git a/client/src/app/slides/motions/motion-block/motion-block-slide.component.ts b/client/src/app/slides/motions/motion-block/motion-block-slide.component.ts index 27013435a..fb2506ec6 100644 --- a/client/src/app/slides/motions/motion-block/motion-block-slide.component.ts +++ b/client/src/app/slides/motions/motion-block/motion-block-slide.component.ts @@ -1,14 +1,12 @@ -import { Component } from '@angular/core'; +import { Component, Input } from '@angular/core'; -import { - MotionBlockSlideData, - MotionBlockSlideMotionRepresentation, - MotionTitleInformation -} from './motion-block-slide-data'; +import { TranslateService } from '@ngx-translate/core'; + +import { MotionBlockSlideData, MotionBlockSlideMotionRepresentation } from './motion-block-slide-data'; import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; import { StateCssClassMapping } from 'app/site/motions/models/view-workflow'; -import { TranslateService } from '@ngx-translate/core'; -import { BaseMotionSlideComponent } from '../base/base-motion-slide'; +import { BaseMotionSlideComponent, MotionTitleInformation } from '../base/base-motion-slide'; +import { SlideData } from 'app/core/core-services/projector-data.service'; @Component({ selector: 'os-motion-block-slide', @@ -16,14 +14,49 @@ import { BaseMotionSlideComponent } from '../base/base-motion-slide'; styleUrls: ['./motion-block-slide.component.scss'] }) export class MotionBlockSlideComponent extends BaseMotionSlideComponent { - public constructor(translate: TranslateService, motionRepo: MotionRepositoryService) { - super(translate, motionRepo); + /** + * For sorting motion blocks by their displayed title + */ + private languageCollator: Intl.Collator; + + private _data: SlideData; + + /** + * Sort the motions given. + */ + @Input() + public set data(data: SlideData) { + if (data && data.data.motions) { + data.data.motions = data.data.motions.sort((a, b) => + this.languageCollator.compare(this.getMotionIdentifier(a), this.getMotionIdentifier(b)) + ); + } + this._data = data; } + public get data(): SlideData { + return this._data; + } + + public constructor(translate: TranslateService, motionRepo: MotionRepositoryService) { + super(translate, motionRepo); + this.languageCollator = new Intl.Collator(this.translate.currentLang); + } + + /** + * @returns the title of the given motion. + */ public getMotionTitle(motion: MotionTitleInformation): string { return this.motionRepo.getTitle(motion); } + /** + * @returns the identifier (of title if identifier not availabe) of the given motion. + */ + public getMotionIdentifier(motion: MotionTitleInformation): string { + return this.motionRepo.getIdentifierOrTitle(motion); + } + public getStateCssColor(motion: MotionBlockSlideMotionRepresentation): string { return StateCssClassMapping[motion.recommendation.css_class] || ''; }