Merge pull request #4117 from CatoTH/Issue4108-Unknown-ChangeRecoMode

Move lnMode/crMode/lineLength into components, Bugfix for lineLength …
This commit is contained in:
Emanuel Schütze 2019-01-17 18:04:38 +01:00 committed by GitHub
commit 57202e74ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 131 additions and 128 deletions

View File

@ -5,6 +5,7 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatSnackBar } from '@angular/material'; import { MatSnackBar } from '@angular/material';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { ConfigService } from '../../../../core/services/config.service';
import { MotionRepositoryService } from '../../services/motion-repository.service'; import { MotionRepositoryService } from '../../services/motion-repository.service';
import { ViewMotion } from '../../models/view-motion'; import { ViewMotion } from '../../models/view-motion';
@ -61,11 +62,17 @@ export class AmendmentCreateWizardComponent extends BaseViewComponent {
*/ */
public metaInfoForm: FormGroup; public metaInfoForm: FormGroup;
/**
* Indicates the maximum line length as defined in the configuration.
*/
public lineLength: number;
/** /**
* Constructs this component. * Constructs this component.
* *
* @param {Title} titleService set the browser title * @param {Title} titleService set the browser title
* @param {TranslateService} translate the translation service * @param {TranslateService} translate the translation service
* @param {ConfigService} configService The configuration provider
* @param {FormBuilder} formBuilder Form builder * @param {FormBuilder} formBuilder Form builder
* @param {MotionRepositoryService} repo Motion Repository * @param {MotionRepositoryService} repo Motion Repository
* @param {ActivatedRoute} route The activated route * @param {ActivatedRoute} route The activated route
@ -77,6 +84,7 @@ export class AmendmentCreateWizardComponent extends BaseViewComponent {
public constructor( public constructor(
titleService: Title, titleService: Title,
translate: TranslateService, translate: TranslateService,
private configService: ConfigService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private repo: MotionRepositoryService, private repo: MotionRepositoryService,
private route: ActivatedRoute, private route: ActivatedRoute,
@ -86,8 +94,12 @@ export class AmendmentCreateWizardComponent extends BaseViewComponent {
matSnackBar: MatSnackBar matSnackBar: MatSnackBar
) { ) {
super(titleService, translate, matSnackBar); super(titleService, translate, matSnackBar);
this.getMotionByUrl();
this.createForm(); this.createForm();
this.configService.get('motions_line_length').subscribe(lineLength => {
this.lineLength = lineLength;
this.getMotionByUrl();
});
} }
/** /**
@ -100,7 +112,7 @@ export class AmendmentCreateWizardComponent extends BaseViewComponent {
this.motion = newViewMotion; this.motion = newViewMotion;
this.paragraphs = this.repo this.paragraphs = this.repo
.getTextParagraphs(this.motion, true) .getTextParagraphs(this.motion, true, this.lineLength)
.map((paragraph: string, index: number) => { .map((paragraph: string, index: number) => {
return { return {
paragraphNo: index, paragraphNo: index,

View File

@ -13,6 +13,7 @@ import {
} from '../motion-change-recommendation/motion-change-recommendation.component'; } from '../motion-change-recommendation/motion-change-recommendation.component';
import { BaseViewComponent } from '../../../base/base-view'; import { BaseViewComponent } from '../../../base/base-view';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { ConfigService } from '../../../../core/services/config.service';
/** /**
* This component displays the original motion text with the change blocks inside. * This component displays the original motion text with the change blocks inside.
@ -49,6 +50,16 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte
@Output() @Output()
public createChangeRecommendation: EventEmitter<LineRange> = new EventEmitter<LineRange>(); public createChangeRecommendation: EventEmitter<LineRange> = new EventEmitter<LineRange>();
/**
* Indicates the LineNumberingMode Mode.
*/
public lnMode: LineNumberingMode;
/**
* Indicates the maximum line length as defined in the configuration.
*/
public lineLength: number;
/** /**
* @param title * @param title
* @param translate * @param translate
@ -57,6 +68,7 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte
* @param motionRepo * @param motionRepo
* @param recoRepo * @param recoRepo
* @param dialogService * @param dialogService
* @param configService
* @param el * @param el
*/ */
public constructor( public constructor(
@ -67,9 +79,13 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte
private motionRepo: MotionRepositoryService, private motionRepo: MotionRepositoryService,
private recoRepo: ChangeRecommendationRepositoryService, private recoRepo: ChangeRecommendationRepositoryService,
private dialogService: MatDialog, private dialogService: MatDialog,
private configService: ConfigService,
private el: ElementRef private el: ElementRef
) { ) {
super(title, translate, matSnackBar); super(title, translate, matSnackBar);
this.configService.get('motions_default_line_numbering').subscribe(mode => (this.lnMode = mode));
this.configService.get('motions_line_length').subscribe(lineLength => (this.lineLength = lineLength));
} }
/** /**
@ -89,7 +105,7 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte
return ''; return '';
} }
return this.motionRepo.extractMotionLineRange(this.motion.id, lineRange, true); return this.motionRepo.extractMotionLineRange(this.motion.id, lineRange, true, this.lineLength);
} }
/** /**
@ -118,7 +134,7 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte
* @param {ViewUnifiedChange} change * @param {ViewUnifiedChange} change
*/ */
public getDiff(change: ViewUnifiedChange): SafeHtml { public getDiff(change: ViewUnifiedChange): SafeHtml {
const html = this.motionRepo.getChangeDiff(this.motion, change); const html = this.motionRepo.getChangeDiff(this.motion, change, this.lineLength);
return this.sanitizer.bypassSecurityTrustHtml(html); return this.sanitizer.bypassSecurityTrustHtml(html);
} }
@ -126,7 +142,10 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte
* Returns the remainder text of the motion after the last change * Returns the remainder text of the motion after the last change
*/ */
public getTextRemainderAfterLastChange(): string { public getTextRemainderAfterLastChange(): string {
return this.motionRepo.getTextRemainderAfterLastChange(this.motion, this.changes); if (!this.lineLength) {
return ''; // @TODO This happens in the test case when the lineLength-variable is not set
}
return this.motionRepo.getTextRemainderAfterLastChange(this.motion, this.changes, this.lineLength);
} }
/** /**
@ -144,7 +163,7 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte
* @returns whether there are line numbers at all * @returns whether there are line numbers at all
*/ */
public isLineNumberingNone(): boolean { public isLineNumberingNone(): boolean {
return this.motion.lnMode === LineNumberingMode.None; return this.lnMode === LineNumberingMode.None;
} }
/** /**
@ -153,7 +172,7 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte
* @returns whether the line numberings are inside * @returns whether the line numberings are inside
*/ */
public isLineNumberingInline(): boolean { public isLineNumberingInline(): boolean {
return this.motion.lnMode === LineNumberingMode.Inside; return this.lnMode === LineNumberingMode.Inside;
} }
/** /**
@ -162,7 +181,7 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte
* @returns whether the line numberings are outside * @returns whether the line numberings are outside
*/ */
public isLineNumberingOutside(): boolean { public isLineNumberingOutside(): boolean {
return this.motion.lnMode === LineNumberingMode.Outside; return this.lnMode === LineNumberingMode.Outside;
} }
/** /**

View File

@ -615,7 +615,7 @@
mat-menu-item mat-menu-item
translate translate
(click)="setLineNumberingMode(LineNumberingMode.None)" (click)="setLineNumberingMode(LineNumberingMode.None)"
[ngClass]="{ selected: motion.lnMode === LineNumberingMode.None }" [ngClass]="{ selected: lnMode === LineNumberingMode.None }"
> >
none none
</button> </button>
@ -623,7 +623,7 @@
mat-menu-item mat-menu-item
translate translate
(click)="setLineNumberingMode(LineNumberingMode.Inside)" (click)="setLineNumberingMode(LineNumberingMode.Inside)"
[ngClass]="{ selected: motion.lnMode === LineNumberingMode.Inside }" [ngClass]="{ selected: lnMode === LineNumberingMode.Inside }"
> >
inline inline
</button> </button>
@ -631,7 +631,7 @@
mat-menu-item mat-menu-item
translate translate
(click)="setLineNumberingMode(LineNumberingMode.Outside)" (click)="setLineNumberingMode(LineNumberingMode.Outside)"
[ngClass]="{ selected: motion.lnMode === LineNumberingMode.Outside }" [ngClass]="{ selected: lnMode === LineNumberingMode.Outside }"
> >
outside outside
</button> </button>
@ -644,7 +644,7 @@
mat-menu-item mat-menu-item
translate translate
(click)="setChangeRecoMode(ChangeRecoMode.Original)" (click)="setChangeRecoMode(ChangeRecoMode.Original)"
[ngClass]="{ selected: motion?.crMode === ChangeRecoMode.Original }" [ngClass]="{ selected: crMode === ChangeRecoMode.Original }"
> >
Original version Original version
</button> </button>
@ -652,7 +652,7 @@
mat-menu-item mat-menu-item
translate translate
(click)="setChangeRecoMode(ChangeRecoMode.Changed)" (click)="setChangeRecoMode(ChangeRecoMode.Changed)"
[ngClass]="{ selected: motion?.crMode === ChangeRecoMode.Changed }" [ngClass]="{ selected: crMode === ChangeRecoMode.Changed }"
> >
Changed version Changed version
</button> </button>
@ -660,7 +660,7 @@
mat-menu-item mat-menu-item
translate translate
(click)="setChangeRecoMode(ChangeRecoMode.Diff)" (click)="setChangeRecoMode(ChangeRecoMode.Diff)"
[ngClass]="{ selected: motion?.crMode === ChangeRecoMode.Diff }" [ngClass]="{ selected: crMode === ChangeRecoMode.Diff }"
> >
Diff version Diff version
</button> </button>
@ -668,7 +668,7 @@
mat-menu-item mat-menu-item
translate translate
(click)="setChangeRecoMode(ChangeRecoMode.Final)" (click)="setChangeRecoMode(ChangeRecoMode.Final)"
[ngClass]="{ selected: motion?.crMode === ChangeRecoMode.Final }" [ngClass]="{ selected: crMode === ChangeRecoMode.Final }"
> >
Final version Final version
</button> </button>

View File

@ -239,6 +239,26 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
*/ */
public LineNumberingMode = LineNumberingMode; public LineNumberingMode = LineNumberingMode;
/**
* Indicates the LineNumberingMode Mode.
*/
public lnMode: LineNumberingMode;
/**
* Indicates the Change reco Mode.
*/
public crMode: ChangeRecoMode;
/**
* Indicates the maximum line length as defined in the configuration.
*/
public lineLength: number;
/**
* Indicates the currently highlighted line, if any.
*/
public highlightedLine: number;
/** /**
* Constuct the detail view. * Constuct the detail view.
* *
@ -314,6 +334,9 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
this.configService.get('motions_min_supporters').subscribe(supporters => (this.minSupporters = supporters)); this.configService.get('motions_min_supporters').subscribe(supporters => (this.minSupporters = supporters));
this.configService.get('motions_preamble').subscribe(preamble => (this.preamble = preamble)); this.configService.get('motions_preamble').subscribe(preamble => (this.preamble = preamble));
this.configService.get('motions_amendments_enabled').subscribe(enabled => (this.amendmentsEnabled = enabled)); this.configService.get('motions_amendments_enabled').subscribe(enabled => (this.amendmentsEnabled = enabled));
this.configService.get('motions_line_length').subscribe(lineLength => (this.lineLength = lineLength));
this.configService.get('motions_default_line_numbering').subscribe(mode => (this.lnMode = mode));
this.configService.get('motions_recommendation_text_mode').subscribe(mode => (this.crMode = mode));
} }
/** /**
@ -371,7 +394,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
if (this.amendments) { if (this.amendments) {
this.amendments.forEach( this.amendments.forEach(
(amendment: ViewMotion): void => { (amendment: ViewMotion): void => {
this.repo.getAmendmentAmendedParagraphs(amendment).forEach( this.repo.getAmendmentAmendedParagraphs(amendment, this.lineLength).forEach(
(change: ViewUnifiedChange): void => { (change: ViewUnifiedChange): void => {
this.allChangingObjects.push(change); this.allChangingObjects.push(change);
} }
@ -558,13 +581,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
public getFormattedTextPlain(): string { public getFormattedTextPlain(): string {
// Prevent this.allChangingObjects to be reordered from within formatMotion // Prevent this.allChangingObjects to be reordered from within formatMotion
const changes: ViewUnifiedChange[] = Object.assign([], this.allChangingObjects); const changes: ViewUnifiedChange[] = Object.assign([], this.allChangingObjects);
return this.repo.formatMotion( return this.repo.formatMotion(this.motion.id, this.crMode, changes, this.lineLength, this.highlightedLine);
this.motion.id,
this.motion.crMode,
changes,
this.motion.lineLength,
this.motion.highlightedLine
);
} }
/** /**
@ -584,7 +601,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
* @returns {DiffLinesInParagraph[]} * @returns {DiffLinesInParagraph[]}
*/ */
public getAmendedParagraphs(): DiffLinesInParagraph[] { public getAmendedParagraphs(): DiffLinesInParagraph[] {
return this.repo.getAmendedParagraphs(this.motion); return this.repo.getAmendedParagraphs(this.motion, this.lineLength);
} }
/** /**
@ -596,7 +613,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
* @returns safe html strings * @returns safe html strings
*/ */
public getParentMotionRange(from: number, to: number): SafeHtml { public getParentMotionRange(from: number, to: number): SafeHtml {
const str = this.repo.extractMotionLineRange(this.motion.parent_id, { from, to }, true); const str = this.repo.extractMotionLineRange(this.motion.parent_id, { from, to }, true, this.lineLength);
return this.sanitizer.bypassSecurityTrustHtml(str); return this.sanitizer.bypassSecurityTrustHtml(str);
} }
@ -606,7 +623,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
* @returns safe html strings * @returns safe html strings
*/ */
public getFormattedStatuteAmendment(): SafeHtml { public getFormattedStatuteAmendment(): SafeHtml {
const diffHtml = this.repo.formatStatuteAmendment(this.statuteParagraphs, this.motion, this.motion.lineLength); const diffHtml = this.repo.formatStatuteAmendment(this.statuteParagraphs, this.motion, this.lineLength);
return this.sanitizer.bypassSecurityTrustHtml(diffHtml); return this.sanitizer.bypassSecurityTrustHtml(diffHtml);
} }
@ -627,7 +644,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
* @param mode Needs to got the enum defined in ViewMotion * @param mode Needs to got the enum defined in ViewMotion
*/ */
public setLineNumberingMode(mode: LineNumberingMode): void { public setLineNumberingMode(mode: LineNumberingMode): void {
this.motion.lnMode = mode; this.lnMode = mode;
} }
/** /**
@ -636,7 +653,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
* @returns whether there are line numbers at all * @returns whether there are line numbers at all
*/ */
public isLineNumberingNone(): boolean { public isLineNumberingNone(): boolean {
return this.motion.lnMode === LineNumberingMode.None; return this.lnMode === LineNumberingMode.None;
} }
/** /**
@ -645,7 +662,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
* @returns whether the line numberings are inside * @returns whether the line numberings are inside
*/ */
public isLineNumberingInline(): boolean { public isLineNumberingInline(): boolean {
return this.motion.lnMode === LineNumberingMode.Inside; return this.lnMode === LineNumberingMode.Inside;
} }
/** /**
@ -654,7 +671,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
* @returns whether the line numberings are outside * @returns whether the line numberings are outside
*/ */
public isLineNumberingOutside(): boolean { public isLineNumberingOutside(): boolean {
return this.motion.lnMode === LineNumberingMode.Outside; return this.lnMode === LineNumberingMode.Outside;
} }
/** /**
@ -662,21 +679,21 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
* @param mode Needs to fot to the enum defined in ViewMotion * @param mode Needs to fot to the enum defined in ViewMotion
*/ */
public setChangeRecoMode(mode: ChangeRecoMode): void { public setChangeRecoMode(mode: ChangeRecoMode): void {
this.motion.crMode = mode; this.crMode = mode;
} }
/** /**
* Returns true if the original version (including change recommendation annotation) is to be shown * Returns true if the original version (including change recommendation annotation) is to be shown
*/ */
public isRecoModeOriginal(): boolean { public isRecoModeOriginal(): boolean {
return this.motion.crMode === ChangeRecoMode.Original || this.allChangingObjects.length === 0; return this.crMode === ChangeRecoMode.Original || this.allChangingObjects.length === 0;
} }
/** /**
* Returns true if the diff version is to be shown * Returns true if the diff version is to be shown
*/ */
public isRecoModeDiff(): boolean { public isRecoModeDiff(): boolean {
return this.motion.crMode === ChangeRecoMode.Diff && this.allChangingObjects.length > 0; return this.crMode === ChangeRecoMode.Diff && this.allChangingObjects.length > 0;
} }
/** /**
@ -689,8 +706,14 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
editChangeRecommendation: false, editChangeRecommendation: false,
newChangeRecommendation: true, newChangeRecommendation: true,
lineRange: lineRange, lineRange: lineRange,
changeRecommendation: this.repo.createChangeRecommendationTemplate(this.motion.id, lineRange) changeRecommendation: this.repo.createChangeRecommendationTemplate(
this.motion.id,
lineRange,
this.lineLength
)
}; };
console.log(this.lineLength);
console.log(data);
this.dialogService.open(MotionChangeRecommendationComponent, { this.dialogService.open(MotionChangeRecommendationComponent, {
height: '400px', height: '400px',
width: '600px', width: '600px',

View File

@ -4,7 +4,7 @@ import { Workflow } from '../../../shared/models/motions/workflow';
import { WorkflowState } from '../../../shared/models/motions/workflow-state'; import { WorkflowState } from '../../../shared/models/motions/workflow-state';
import { Item } from 'app/shared/models/agenda/item'; import { Item } from 'app/shared/models/agenda/item';
import { MotionBlock } from 'app/shared/models/motions/motion-block'; import { MotionBlock } from 'app/shared/models/motions/motion-block';
import { LineNumberingMode, ViewMotion } from './view-motion'; import { ViewMotion } from './view-motion';
import { CreateMotion } from './create-motion'; import { CreateMotion } from './create-motion';
/** /**
@ -43,7 +43,7 @@ export class ViewCreateMotion extends ViewMotion {
item?: Item, item?: Item,
block?: MotionBlock block?: MotionBlock
) { ) {
super(motion, category, submitters, supporters, workflow, state, item, block, null, 80, LineNumberingMode.None); super(motion, category, submitters, supporters, workflow, state, item, block, null);
} }
/** /**

View File

@ -49,30 +49,6 @@ export class ViewMotion extends BaseViewModel {
protected _block: MotionBlock; protected _block: MotionBlock;
protected _attachments: Mediafile[]; protected _attachments: Mediafile[];
/**
* Indicates the LineNumberingMode Mode.
* Needs to be accessed from outside
*/
public lnMode: LineNumberingMode;
/**
* Indicates the Change reco Mode.
* Needs to be accessed from outside
*/
public crMode: ChangeRecoMode;
/**
* Indicates the maximum line length as defined in the configuration.
* Needs to be accessed from outside
*/
public lineLength: number;
/**
* Indicates the currently highlighted line, if any.
* Needs to be accessed from outside
*/
public highlightedLine: number;
/** /**
* Is set by the repository; this is the order of the flat call list given by * Is set by the repository; this is the order of the flat call list given by
* the properties weight and sort_parent_id * the properties weight and sort_parent_id
@ -242,10 +218,7 @@ export class ViewMotion extends BaseViewModel {
state?: WorkflowState, state?: WorkflowState,
item?: Item, item?: Item,
block?: MotionBlock, block?: MotionBlock,
attachments?: Mediafile[], attachments?: Mediafile[]
lineLength: number = 80,
lineNumberingMode?: LineNumberingMode,
crMode?: ChangeRecoMode
) { ) {
super(); super();
this._motion = motion; this._motion = motion;
@ -257,12 +230,6 @@ export class ViewMotion extends BaseViewModel {
this._item = item; this._item = item;
this._block = block; this._block = block;
this._attachments = attachments; this._attachments = attachments;
this.lnMode = lineNumberingMode;
this.crMode = crMode;
this.lineLength = lineLength;
this.highlightedLine = null;
} }
public getTitle(): string { public getTitle(): string {
@ -421,10 +388,7 @@ export class ViewMotion extends BaseViewModel {
this._state, this._state,
this._item, this._item,
this._block, this._block,
this._attachments, this._attachments
this.lineLength,
this.lnMode,
this.crMode
); );
} }
} }

View File

@ -9,7 +9,7 @@ import { User } from '../../../shared/models/users/user';
import { Category } from '../../../shared/models/motions/category'; import { Category } from '../../../shared/models/motions/category';
import { Workflow } from '../../../shared/models/motions/workflow'; import { Workflow } from '../../../shared/models/motions/workflow';
import { WorkflowState } from '../../../shared/models/motions/workflow-state'; import { WorkflowState } from '../../../shared/models/motions/workflow-state';
import { ChangeRecoMode, LineNumberingMode, ViewMotion } from '../models/view-motion'; import { ChangeRecoMode, ViewMotion } from '../models/view-motion';
import { BaseRepository } from '../../base/base-repository'; import { BaseRepository } from '../../base/base-repository';
import { DataStoreService } from '../../../core/services/data-store.service'; import { DataStoreService } from '../../../core/services/data-store.service';
import { LinenumberingService } from './linenumbering.service'; import { LinenumberingService } from './linenumbering.service';
@ -28,7 +28,6 @@ import { ViewMotionAmendedParagraph } from '../models/view-motion-amended-paragr
import { CreateMotion } from '../models/create-motion'; import { CreateMotion } from '../models/create-motion';
import { MotionBlock } from 'app/shared/models/motions/motion-block'; import { MotionBlock } from 'app/shared/models/motions/motion-block';
import { Mediafile } from 'app/shared/models/mediafiles/mediafile'; import { Mediafile } from 'app/shared/models/mediafiles/mediafile';
import { ConfigService } from '../../../core/services/config.service';
import { MotionPoll } from 'app/shared/models/motions/motion-poll'; import { MotionPoll } from 'app/shared/models/motions/motion-poll';
/** /**
@ -45,15 +44,6 @@ import { MotionPoll } from 'app/shared/models/motions/motion-poll';
providedIn: 'root' providedIn: 'root'
}) })
export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion> { export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion> {
// The line length; comes from the config variable motions_line_length
private lineLength = 90;
// The default line numbering mode; comes from the config variable motions_default_line_numbering
private defaultLineNumbering = LineNumberingMode.Outside;
// The default line numbering mode; comes from the config variable motions_recommendation_text_mode
private defaultCrMode = ChangeRecoMode.Original;
/** /**
* Creates a MotionRepository * Creates a MotionRepository
* *
@ -66,7 +56,6 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
* @param httpService OpenSlides own Http service * @param httpService OpenSlides own Http service
* @param lineNumbering Line numbering for motion text * @param lineNumbering Line numbering for motion text
* @param diff Display changes in motion text as diff. * @param diff Display changes in motion text as diff.
* @param configService The configuration provider
*/ */
public constructor( public constructor(
DS: DataStoreService, DS: DataStoreService,
@ -75,15 +64,9 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
private httpService: HttpService, private httpService: HttpService,
private readonly lineNumbering: LinenumberingService, private readonly lineNumbering: LinenumberingService,
private readonly diff: DiffService, private readonly diff: DiffService,
private readonly configService: ConfigService,
private treeService: TreeService private treeService: TreeService
) { ) {
super(DS, mapperService, Motion, [Category, User, Workflow, Item, MotionBlock, Mediafile]); super(DS, mapperService, Motion, [Category, User, Workflow, Item, MotionBlock, Mediafile]);
// load config variables
this.configService.get('motions_line_length').subscribe(lineLength => (this.lineLength = lineLength));
this.configService.get('motions_default_line_numbering').subscribe(mode => (this.defaultLineNumbering = mode));
this.configService.get('motions_recommendation_text_mode').subscribe(mode => (this.defaultCrMode = mode));
} }
/** /**
@ -106,20 +89,7 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
if (workflow) { if (workflow) {
state = workflow.getStateById(motion.state_id); state = workflow.getStateById(motion.state_id);
} }
return new ViewMotion( return new ViewMotion(motion, category, submitters, supporters, workflow, state, item, block, attachments);
motion,
category,
submitters,
supporters,
workflow,
state,
item,
block,
attachments,
this.lineLength,
this.defaultLineNumbering,
this.defaultCrMode
);
} }
/** /**
@ -329,7 +299,8 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
from: 1, from: 1,
to: change.getLineFrom() to: change.getLineFrom()
}, },
true true,
lineLength
); );
} else if (changes[idx - 1].getLineTo() < change.getLineFrom()) { } else if (changes[idx - 1].getLineTo() < change.getLineFrom()) {
text += this.extractMotionLineRange( text += this.extractMotionLineRange(
@ -338,12 +309,13 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
from: changes[idx - 1].getLineTo(), from: changes[idx - 1].getLineTo(),
to: change.getLineFrom() to: change.getLineFrom()
}, },
true true,
lineLength
); );
} }
text += this.getChangeDiff(targetMotion, change, highlightLine); text += this.getChangeDiff(targetMotion, change, lineLength, highlightLine);
}); });
text += this.getTextRemainderAfterLastChange(targetMotion, changes, highlightLine); text += this.getTextRemainderAfterLastChange(targetMotion, changes, lineLength, highlightLine);
return text; return text;
case ChangeRecoMode.Final: case ChangeRecoMode.Final:
const appliedChanges: ViewUnifiedChange[] = changes.filter(change => change.isAccepted()); const appliedChanges: ViewUnifiedChange[] = changes.filter(change => change.isAccepted());
@ -374,9 +346,10 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
* @param {number} id * @param {number} id
* @param {LineRange} lineRange * @param {LineRange} lineRange
* @param {boolean} lineNumbers - weather to add line numbers to the returned HTML string * @param {boolean} lineNumbers - weather to add line numbers to the returned HTML string
* @param {number} lineLength
*/ */
public extractMotionLineRange(id: number, lineRange: LineRange, lineNumbers: boolean): string { public extractMotionLineRange(id: number, lineRange: LineRange, lineNumbers: boolean, lineLength: number): string {
const origHtml = this.formatMotion(id, ChangeRecoMode.Original, [], this.lineLength); const origHtml = this.formatMotion(id, ChangeRecoMode.Original, [], lineLength);
const extracted = this.diff.extractRangeByLineNumbers(origHtml, lineRange.from, lineRange.to); const extracted = this.diff.extractRangeByLineNumbers(origHtml, lineRange.from, lineRange.to);
let html = let html =
extracted.outerContextStart + extracted.outerContextStart +
@ -385,7 +358,7 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
extracted.innerContextEnd + extracted.innerContextEnd +
extracted.outerContextEnd; extracted.outerContextEnd;
if (lineNumbers) { if (lineNumbers) {
html = this.lineNumbering.insertLineNumbers(html, 80, null, null, lineRange.from); html = this.lineNumbering.insertLineNumbers(html, lineLength, null, null, lineRange.from);
} }
return html; return html;
} }
@ -395,12 +368,14 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
* *
* @param {ViewMotion} motion * @param {ViewMotion} motion
* @param {ViewUnifiedChange[]} changes * @param {ViewUnifiedChange[]} changes
* @param {number} lineLength
* @param {number} highlight * @param {number} highlight
* @returns {string} * @returns {string}
*/ */
public getTextRemainderAfterLastChange( public getTextRemainderAfterLastChange(
motion: ViewMotion, motion: ViewMotion,
changes: ViewUnifiedChange[], changes: ViewUnifiedChange[],
lineLength: number,
highlight?: number highlight?: number
): string { ): string {
let maxLine = 1; let maxLine = 1;
@ -410,7 +385,7 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
} }
}, 0); }, 0);
const numberedHtml = this.lineNumbering.insertLineNumbers(motion.text, motion.lineLength); const numberedHtml = this.lineNumbering.insertLineNumbers(motion.text, lineLength);
if (changes.length === 0) { if (changes.length === 0) {
return numberedHtml; return numberedHtml;
} }
@ -437,7 +412,7 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
data.html + data.html +
data.innerContextEnd + data.innerContextEnd +
data.outerContextEnd; data.outerContextEnd;
html = this.lineNumbering.insertLineNumbers(html, motion.lineLength, highlight, null, maxLine); html = this.lineNumbering.insertLineNumbers(html, lineLength, highlight, null, maxLine);
} else { } else {
// Prevents empty lines at the end of the motion // Prevents empty lines at the end of the motion
html = ''; html = '';
@ -451,13 +426,18 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
* *
* @param {number} motionId * @param {number} motionId
* @param {LineRange} lineRange * @param {LineRange} lineRange
* @param {number} lineLength
*/ */
public createChangeRecommendationTemplate(motionId: number, lineRange: LineRange): ViewChangeReco { public createChangeRecommendationTemplate(
motionId: number,
lineRange: LineRange,
lineLength: number
): ViewChangeReco {
const changeReco = new MotionChangeReco(); const changeReco = new MotionChangeReco();
changeReco.line_from = lineRange.from; changeReco.line_from = lineRange.from;
changeReco.line_to = lineRange.to; changeReco.line_to = lineRange.to;
changeReco.type = ModificationType.TYPE_REPLACEMENT; changeReco.type = ModificationType.TYPE_REPLACEMENT;
changeReco.text = this.extractMotionLineRange(motionId, lineRange, false); changeReco.text = this.extractMotionLineRange(motionId, lineRange, false, lineLength);
changeReco.rejected = false; changeReco.rejected = false;
changeReco.motion_id = motionId; changeReco.motion_id = motionId;
@ -470,12 +450,17 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
* *
* @param {ViewMotion} motion * @param {ViewMotion} motion
* @param {ViewUnifiedChange} change * @param {ViewUnifiedChange} change
* @param {number} lineLength
* @param {number} highlight * @param {number} highlight
* @returns {string} * @returns {string}
*/ */
public getChangeDiff(motion: ViewMotion, change: ViewUnifiedChange, highlight?: number): string { public getChangeDiff(
const lineLength = motion.lineLength, motion: ViewMotion,
html = this.lineNumbering.insertLineNumbers(motion.text, lineLength); change: ViewUnifiedChange,
lineLength: number,
highlight?: number
): string {
const html = this.lineNumbering.insertLineNumbers(motion.text, lineLength);
let data, oldText; let data, oldText;
@ -534,15 +519,15 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
* *
* @param {ViewMotion} motion * @param {ViewMotion} motion
* @param {boolean} lineBreaks * @param {boolean} lineBreaks
* @param {number} lineLength
* @returns {string[]} * @returns {string[]}
*/ */
public getTextParagraphs(motion: ViewMotion, lineBreaks: boolean): string[] { public getTextParagraphs(motion: ViewMotion, lineBreaks: boolean, lineLength: number): string[] {
if (!motion) { if (!motion) {
return []; return [];
} }
let html = motion.text; let html = motion.text;
if (lineBreaks) { if (lineBreaks) {
const lineLength = motion.lineLength;
html = this.lineNumbering.insertLineNumbers(html, lineLength); html = this.lineNumbering.insertLineNumbers(html, lineLength);
} }
return this.lineNumbering.splitToParagraphs(html); return this.lineNumbering.splitToParagraphs(html);
@ -552,12 +537,12 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
* Returns all paragraphs that are affected by the given amendment in diff-format * Returns all paragraphs that are affected by the given amendment in diff-format
* *
* @param {ViewMotion} amendment * @param {ViewMotion} amendment
* @param {number} lineLength
* @returns {DiffLinesInParagraph} * @returns {DiffLinesInParagraph}
*/ */
public getAmendedParagraphs(amendment: ViewMotion): DiffLinesInParagraph[] { public getAmendedParagraphs(amendment: ViewMotion, lineLength: number): DiffLinesInParagraph[] {
const motion = this.getAmendmentBaseMotion(amendment); const motion = this.getAmendmentBaseMotion(amendment);
const baseParagraphs = this.getTextParagraphs(motion, true); const baseParagraphs = this.getTextParagraphs(motion, true, lineLength);
const lineLength = amendment.lineLength;
return amendment.amendment_paragraphs return amendment.amendment_paragraphs
.map( .map(
@ -581,12 +566,12 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
* Returns all paragraphs that are affected by the given amendment as unified change objects. * Returns all paragraphs that are affected by the given amendment as unified change objects.
* *
* @param {ViewMotion} amendment * @param {ViewMotion} amendment
* @param {number} lineLength
* @returns {ViewMotionAmendedParagraph[]} * @returns {ViewMotionAmendedParagraph[]}
*/ */
public getAmendmentAmendedParagraphs(amendment: ViewMotion): ViewMotionAmendedParagraph[] { public getAmendmentAmendedParagraphs(amendment: ViewMotion, lineLength: number): ViewMotionAmendedParagraph[] {
const motion = this.getAmendmentBaseMotion(amendment); const motion = this.getAmendmentBaseMotion(amendment);
const baseParagraphs = this.getTextParagraphs(motion, true); const baseParagraphs = this.getTextParagraphs(motion, true, lineLength);
const lineLength = amendment.lineLength;
return amendment.amendment_paragraphs return amendment.amendment_paragraphs
.map( .map(