Merge pull request #4514 from CatoTH/amendmentsInViewMotion

Add amendments as dependencies in ViewMotion [2]
This commit is contained in:
Emanuel Schütze 2019-03-17 22:04:22 +01:00 committed by GitHub
commit 5d045a894a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 17 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?'),

View File

@ -110,7 +110,6 @@ export class MotionSlideComponent extends BaseMotionSlideComponent<MotionSlideDa
} }
const origText = baseParagraphs[paraNo], const origText = baseParagraphs[paraNo],
paragraphLines = this.lineNumbering.getLineNumberRange(origText),
diff = this.diff.diff(origText, newText), diff = this.diff.diff(origText, newText),
affectedLines = this.diff.detectAffectedLineRange(diff); affectedLines = this.diff.detectAffectedLineRange(diff);
@ -118,18 +117,12 @@ export class MotionSlideComponent extends BaseMotionSlideComponent<MotionSlideDa
return null; return null;
} }
let newTextLines = this.lineNumbering.insertLineNumbers( const affectedDiff = this.diff.formatDiff(
newText, this.diff.extractRangeByLineNumbers(diff, affectedLines.from, affectedLines.to)
this.lineLength,
null,
null,
paragraphLines.from
);
newTextLines = this.diff.formatDiff(
this.diff.extractRangeByLineNumbers(newTextLines, affectedLines.from, affectedLines.to)
); );
const affectedConsolidated = this.diff.diffHtmlToFinalText(affectedDiff);
return new MotionSlideObjAmendmentParagraph(amendment, paraNo, newTextLines, affectedLines); return new MotionSlideObjAmendmentParagraph(amendment, paraNo, affectedConsolidated, affectedLines);
} }
) )
.filter((para: MotionSlideObjAmendmentParagraph) => para !== null); .filter((para: MotionSlideObjAmendmentParagraph) => para !== null);