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 tags = this.viewModelStoreService.getMany(ViewTag, motion.tags_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(
ViewMotionChangeRecommendation,
cr => cr.motion_id === motion.id
@ -188,6 +189,7 @@ export class MotionRepositoryService extends BaseAgendaContentObjectRepository<V
tags,
parent,
changeRecommendations,
amendments,
personalNote
);
viewMotion.getIdentifierOrTitle = () => this.getIdentifierOrTitle(viewMotion);

View File

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

View File

@ -110,7 +110,6 @@ export class MotionSlideComponent extends BaseMotionSlideComponent<MotionSlideDa
}
const origText = baseParagraphs[paraNo],
paragraphLines = this.lineNumbering.getLineNumberRange(origText),
diff = this.diff.diff(origText, newText),
affectedLines = this.diff.detectAffectedLineRange(diff);
@ -118,18 +117,12 @@ export class MotionSlideComponent extends BaseMotionSlideComponent<MotionSlideDa
return null;
}
let newTextLines = this.lineNumbering.insertLineNumbers(
newText,
this.lineLength,
null,
null,
paragraphLines.from
);
newTextLines = this.diff.formatDiff(
this.diff.extractRangeByLineNumbers(newTextLines, affectedLines.from, affectedLines.to)
const affectedDiff = this.diff.formatDiff(
this.diff.extractRangeByLineNumbers(diff, 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);