Add amendments as dependencies in ViewMotion

This commit is contained in:
FinnStutzenstein 2019-03-08 12:21:00 +01:00 committed by Emanuel Schütze
parent 1c02d5f496
commit 6cb4b9a691
2 changed files with 24 additions and 6 deletions

View File

@ -166,6 +166,7 @@ export class MotionRepositoryService extends BaseAgendaContentObjectRepository<V
const attachments = this.viewModelStoreService.getMany(ViewMediafile, motion.attachments_id); const attachments = this.viewModelStoreService.getMany(ViewMediafile, motion.attachments_id);
const tags = this.viewModelStoreService.getMany(ViewTag, motion.tags_id); const tags = this.viewModelStoreService.getMany(ViewTag, motion.tags_id);
const parent = this.viewModelStoreService.get(ViewMotion, motion.parent_id); const parent = this.viewModelStoreService.get(ViewMotion, motion.parent_id);
const amendments = this.viewModelStoreService.filter(ViewMotion, m => m.parent_id && m.parent_id === motion.id);
const changeRecommendations = this.viewModelStoreService.filter( const changeRecommendations = this.viewModelStoreService.filter(
ViewMotionChangeRecommendation, ViewMotionChangeRecommendation,
cr => cr.motion_id === motion.id cr => cr.motion_id === motion.id
@ -188,6 +189,7 @@ export class MotionRepositoryService extends BaseAgendaContentObjectRepository<V
tags, tags,
parent, parent,
changeRecommendations, changeRecommendations,
amendments,
personalNote personalNote
); );
viewMotion.getIdentifierOrTitle = () => this.getIdentifierOrTitle(viewMotion); viewMotion.getIdentifierOrTitle = () => this.getIdentifierOrTitle(viewMotion);

View File

@ -60,6 +60,7 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
protected _attachments: ViewMediafile[]; protected _attachments: ViewMediafile[];
protected _tags: ViewTag[]; protected _tags: ViewTag[];
protected _parent: ViewMotion; protected _parent: ViewMotion;
protected _amendments: ViewMotion[];
protected _changeRecommendations: ViewMotionChangeRecommendation[]; protected _changeRecommendations: ViewMotionChangeRecommendation[];
public personalNote?: PersonalNoteContent; public personalNote?: PersonalNoteContent;
@ -255,6 +256,10 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
return this._parent; return this._parent;
} }
public get amendments(): ViewMotion[] {
return this._amendments;
}
/** /**
* @returns the creation date as Date object * @returns the creation date as Date object
*/ */
@ -374,6 +379,7 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
tags?: ViewTag[], tags?: ViewTag[],
parent?: ViewMotion, parent?: ViewMotion,
changeRecommendations?: ViewMotionChangeRecommendation[], changeRecommendations?: ViewMotionChangeRecommendation[],
amendments?: ViewMotion[],
personalNote?: PersonalNoteContent personalNote?: PersonalNoteContent
) { ) {
super(Motion.COLLECTIONSTRING); super(Motion.COLLECTIONSTRING);
@ -388,6 +394,7 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
this._attachments = attachments; this._attachments = attachments;
this._tags = tags; this._tags = tags;
this._parent = parent; this._parent = parent;
this._amendments = amendments;
this._changeRecommendations = changeRecommendations; this._changeRecommendations = changeRecommendations;
this.personalNote = personalNote; this.personalNote = personalNote;
} }
@ -463,7 +470,7 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
} else if (update instanceof ViewTag) { } else if (update instanceof ViewTag) {
this.updateTags(update); this.updateTags(update);
} else if (update instanceof ViewMotion && update.id !== this.id) { } else if (update instanceof ViewMotion && update.id !== this.id) {
this.updateParent(update); this.updateMotion(update);
} else if (update instanceof ViewMotionChangeRecommendation) { } else if (update instanceof ViewMotionChangeRecommendation) {
this.updateChangeRecommendation(update); this.updateChangeRecommendation(update);
} }
@ -561,9 +568,19 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
} }
} }
private updateParent(parent: ViewMotion): void { /**
if (this.parent_id && this.parent_id === parent.id) { * The update cen be the parent or a child motion (=amendment).
this._parent = parent; */
private updateMotion(update: ViewMotion): void {
if (this.parent_id && this.parent_id === update.id) {
this._parent = update;
} else if (update.parent_id && update.parent_id === this.id) {
const index = this._amendments.findIndex(m => m.id === update.id);
if (index >= 0) {
this._amendments[index] = update;
} else {
this._amendments.push(update);
}
} }
} }
@ -611,8 +628,7 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
public getSlide(configService: ConfigService): ProjectorElementBuildDeskriptor { public getSlide(configService: ConfigService): ProjectorElementBuildDeskriptor {
const slideOptions = []; const slideOptions = [];
if ((this.changeRecommendations && this.changeRecommendations.length) || this.amendments) {
if (this.changeRecommendations && this.changeRecommendations.length) {
slideOptions.push({ slideOptions.push({
key: 'mode', key: 'mode',
displayName: _('Which version?'), displayName: _('Which version?'),