Merge pull request #4480 from FinnStutzenstein/sortMotionBlocksOnSlide

Sort motions on the motion block slide
This commit is contained in:
Emanuel Schütze 2019-03-08 20:49:18 +01:00 committed by GitHub
commit 5e7c604c4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 17 deletions

View File

@ -2,7 +2,11 @@ import { TranslateService } from '@ngx-translate/core';
import { BaseSlideComponent } from 'app/slides/base-slide-component'; import { BaseSlideComponent } from 'app/slides/base-slide-component';
import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; 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. * Format for referenced motions: A mapping of motion ids to their title information.

View File

@ -1,9 +1,4 @@
import { ReferencedMotions } from '../base/base-motion-slide'; import { ReferencedMotions, MotionTitleInformation } from '../base/base-motion-slide';
export interface MotionTitleInformation {
title: string;
identifier?: string;
}
export interface MotionBlockSlideMotionRepresentation extends MotionTitleInformation { export interface MotionBlockSlideMotionRepresentation extends MotionTitleInformation {
recommendation?: { recommendation?: {

View File

@ -1,14 +1,12 @@
import { Component } from '@angular/core'; import { Component, Input } from '@angular/core';
import { import { TranslateService } from '@ngx-translate/core';
MotionBlockSlideData,
MotionBlockSlideMotionRepresentation, import { MotionBlockSlideData, MotionBlockSlideMotionRepresentation } from './motion-block-slide-data';
MotionTitleInformation
} from './motion-block-slide-data';
import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service';
import { StateCssClassMapping } from 'app/site/motions/models/view-workflow'; import { StateCssClassMapping } from 'app/site/motions/models/view-workflow';
import { TranslateService } from '@ngx-translate/core'; import { BaseMotionSlideComponent, MotionTitleInformation } from '../base/base-motion-slide';
import { BaseMotionSlideComponent } from '../base/base-motion-slide'; import { SlideData } from 'app/core/core-services/projector-data.service';
@Component({ @Component({
selector: 'os-motion-block-slide', selector: 'os-motion-block-slide',
@ -16,14 +14,49 @@ import { BaseMotionSlideComponent } from '../base/base-motion-slide';
styleUrls: ['./motion-block-slide.component.scss'] styleUrls: ['./motion-block-slide.component.scss']
}) })
export class MotionBlockSlideComponent extends BaseMotionSlideComponent<MotionBlockSlideData> { export class MotionBlockSlideComponent extends BaseMotionSlideComponent<MotionBlockSlideData> {
public constructor(translate: TranslateService, motionRepo: MotionRepositoryService) { /**
super(translate, motionRepo); * For sorting motion blocks by their displayed title
*/
private languageCollator: Intl.Collator;
private _data: SlideData<MotionBlockSlideData>;
/**
* Sort the motions given.
*/
@Input()
public set data(data: SlideData<MotionBlockSlideData>) {
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<MotionBlockSlideData> {
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 { public getMotionTitle(motion: MotionTitleInformation): string {
return this.motionRepo.getTitle(motion); 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 { public getStateCssColor(motion: MotionBlockSlideMotionRepresentation): string {
return StateCssClassMapping[motion.recommendation.css_class] || ''; return StateCssClassMapping[motion.recommendation.css_class] || '';
} }