OpenSlides/client/src/app/slides/motions/motion-block/motion-block-slide.component.ts

73 lines
2.6 KiB
TypeScript
Raw Normal View History

2019-03-08 11:38:18 +01:00
import { Component, Input } from '@angular/core';
2019-02-21 12:34:13 +01:00
2019-03-08 11:38:18 +01:00
import { TranslateService } from '@ngx-translate/core';
import { MotionBlockSlideData, MotionBlockSlideMotionRepresentation } from './motion-block-slide-data';
2019-02-21 12:34:13 +01:00
import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service';
import { StateCssClassMapping } from 'app/site/motions/models/view-workflow';
2019-03-08 11:38:18 +01:00
import { BaseMotionSlideComponent, MotionTitleInformation } from '../base/base-motion-slide';
import { SlideData } from 'app/core/core-services/projector-data.service';
2019-02-21 12:34:13 +01:00
@Component({
selector: 'os-motion-block-slide',
templateUrl: './motion-block-slide.component.html',
styleUrls: ['./motion-block-slide.component.scss']
})
export class MotionBlockSlideComponent extends BaseMotionSlideComponent<MotionBlockSlideData> {
2019-03-08 11:38:18 +01:00
/**
* 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);
2019-03-08 11:38:18 +01:00
this.languageCollator = new Intl.Collator(this.translate.currentLang);
2019-02-21 12:34:13 +01:00
}
2019-03-08 11:38:18 +01:00
/**
* @returns the title of the given motion.
*/
public getMotionTitle(motion: MotionTitleInformation): string {
return this.motionRepo.getTitle(motion);
2019-02-21 12:34:13 +01:00
}
2019-03-08 11:38:18 +01:00
/**
* @returns the identifier (of title if identifier not availabe) of the given motion.
*/
public getMotionIdentifier(motion: MotionTitleInformation): string {
return this.motionRepo.getIdentifierOrTitle(motion);
}
2019-02-21 12:34:13 +01:00
public getStateCssColor(motion: MotionBlockSlideMotionRepresentation): string {
return StateCssClassMapping[motion.recommendation.css_class] || '';
}
2019-02-21 15:06:14 +01:00
public getRecommendationLabel(motion: MotionBlockSlideMotionRepresentation): string {
2019-02-21 12:34:13 +01:00
let recommendation = this.translate.instant(motion.recommendation.name);
if (motion.recommendation_extension) {
recommendation +=
' ' + this.replaceReferencedMotions(motion.recommendation_extension, this.data.data.referenced_motions);
2019-02-21 12:34:13 +01:00
}
return recommendation;
}
}