Add motion controls + small fixes

This commit is contained in:
Sean Engelhardt 2018-09-28 15:10:48 +02:00
parent b6ad0d759c
commit 0c05eb38e2
8 changed files with 179 additions and 10 deletions

View File

@ -249,7 +249,17 @@
</ng-template>
<ng-template #contentTemplate>
<form [formGroup]='contentForm' (ngSubmit)='saveMotion()'>
<form class="motion-content" [formGroup]='contentForm' (ngSubmit)='saveMotion()'>
<!-- Line Number and Diff buttons-->
<div class="motion-text-controls">
<button type="button" mat-icon-button [matMenuTriggerFor]="lineNumberingMenu">
<fa-icon icon="list-ol" [fixedWidth]="true"></fa-icon>
</button>
<button type="button" mat-icon-button [matMenuTriggerFor]="changeRecoMenu">
<fa-icon icon="edit" [fixedWidth]="true"></fa-icon>
</button>
</div>
<!-- Title -->
<div *ngIf="motion && motion.title || editMotion">
@ -266,7 +276,7 @@
<!-- TODO: this is a config variable. Read it out -->
<h3 translate>The assembly may decide:</h3>
<div *ngIf='motion && !editMotion'>
<div [innerHtml]='motion.text'></div>
<div [innerHtml]='getFormatedText()'></div>
</div>
<mat-form-field *ngIf="motion && editMotion" class="wide-form">
<textarea matInput placeholder='Motion Text' formControlName='text' [value]='motionCopy.text'></textarea>
@ -286,3 +296,18 @@
</form>
</ng-template>
<!-- Line number Menu -->
<mat-menu #lineNumberingMenu="matMenu">
<button mat-menu-item translate (click)=setLineNumberingMode(0)>None</button>
<button mat-menu-item translate (click)=setLineNumberingMode(1)>Inline</button>
<button mat-menu-item translate (click)=setLineNumberingMode(2)>Outside</button>
</mat-menu>
<!-- Diff View Menu -->
<mat-menu #changeRecoMenu="matMenu">
<button mat-menu-item translate (click)=setChangeRecoMode(0)>Original version</button>
<button mat-menu-item translate (click)=setChangeRecoMode(1)>Changed version</button>
<button mat-menu-item translate (click)=setChangeRecoMode(2)>Diff version</button>
<button mat-menu-item translate (click)=setChangeRecoMode(3)>Final version</button>
</mat-menu>

View File

@ -7,6 +7,17 @@ span {
line-height: 100%;
}
.motion-content {
display: flow-root;
}
.motion-text-controls {
float: right;
button {
font-size: 115%;
}
}
.motion-submitter {
display: inline;
font-weight: bold;

View File

@ -168,8 +168,8 @@ export class MotionDetailComponent extends BaseComponent implements OnInit {
category_id: [''],
state_id: [''],
recommendation_id: [''],
submitters_id: [''],
supporters_id: [''],
submitters_id: [],
supporters_id: [],
origin: ['']
});
this.contentForm = this.formBuilder.group({
@ -197,28 +197,42 @@ export class MotionDetailComponent extends BaseComponent implements OnInit {
if (this.newMotion) {
this.repo.create(fromForm).subscribe(response => {
this.router.navigate(['./motions/' + response.id]);
if (response.id) {
this.router.navigate(['./motions/' + response.id]);
}
});
} else {
this.repo.update(fromForm, this.motionCopy).subscribe();
this.repo.update(fromForm, this.motionCopy).subscribe(response => {
// if the motion was successfully updated, change the edit mode.
// TODO: Show errors if there appear here
if (response.id) {
this.editMotion = false;
}
});
}
}
/**
* get the formated motion text from the repository.
*/
public getFormatedText(): string {
return this.repo.formatMotion(this.motion.id, this.motion.lnMode, this.motion.crMode);
}
/**
* Click on the edit button (pen-symbol)
*/
public editMotionButton(): void {
this.editMotion ? (this.editMotion = false) : (this.editMotion = true);
if (this.editMotion) {
// copy the motion
this.saveMotion();
} else {
this.editMotion = true;
this.motionCopy = this.motion.copy();
this.patchForm(this.motionCopy);
if (this.vp.isMobile) {
this.metaInfoPanel.open();
this.contentPanel.open();
}
} else {
this.saveMotion();
}
}
@ -246,6 +260,22 @@ export class MotionDetailComponent extends BaseComponent implements OnInit {
});
}
/**
* Sets the motions line numbering mode
* @param mode Needs to fot to the enum defined in ViewMotion
*/
public setLineNumberingMode(mode: number): void {
this.motion.lnMode = mode;
}
/**
* Sets the motions change reco mode
* @param mode Needs to fot to the enum defined in ViewMotion
*/
public setChangeRecoMode(mode: number): void {
this.motion.crMode = mode;
}
/**
* Init. Does nothing here.
*/

View File

@ -6,6 +6,20 @@ import { WorkflowState } from '../../../shared/models/motions/workflow-state';
import { BaseModel } from '../../../shared/models/base/base-model';
import { BaseViewModel } from '../../base/base-view-model';
import { TranslateService } from '@ngx-translate/core';
enum LineNumbering {
None,
Inside,
Outside
}
enum ChangeReco {
Original,
Change,
Diff,
Final
}
/**
* Motion class for the View
*
@ -21,6 +35,18 @@ export class ViewMotion extends BaseViewModel {
private _workflow: Workflow;
private _state: WorkflowState;
/**
* Indicates the LineNumbering Mode.
* Needs to be accessed from outside
*/
public lnMode: LineNumbering;
/**
* Indicates the Change reco Mode.
* Needs to be accessed from outside
*/
public crMode: ChangeReco;
public get motion(): Motion {
return this._motion;
}
@ -150,6 +176,10 @@ export class ViewMotion extends BaseViewModel {
this._supporters = supporters;
this._workflow = workflow;
this._state = state;
// TODO: Should be set using a a config variable
this.lnMode = LineNumbering.None;
this.crMode = ChangeReco.Original;
}
public getTitle(translate?: TranslateService): string {

View File

@ -66,6 +66,9 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
* TODO: Remove the viewMotion and make it actually distignuishable from save()
*/
public create(motion: Motion): Observable<any> {
if (!motion.supporters_id) {
delete motion.supporters_id;
}
return this.dataSend.createModel(motion);
}
@ -94,4 +97,56 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
public delete(viewMotion: ViewMotion): Observable<any> {
return this.dataSend.delete(viewMotion.motion);
}
/**
* Format the motion text using the line numbering and change
* reco algorithm.
*
* TODO: Call DiffView and LineNumbering Service here.
*
* Can be called from detail view and exporter
* @param id Motion ID - will be pulled from the repository
* @param lnMode indicator for the line numbering mode
* @param crMode indicator for the change reco mode
*/
public formatMotion(id: number, lnMode: number, crMode: number): string {
const targetMotion = this.getViewModel(id);
if (targetMotion && targetMotion.text) {
let motionText = targetMotion.text;
// TODO : Use Line numbering service here
switch (lnMode) {
case 0: // no line numbers
break;
case 1: // line number inside
motionText = 'Get line numbers outside';
break;
case 2: // line number outside
motionText = 'Get line numbers inside';
break;
}
// TODO : Use Diff Service here.
// this will(currently) append the previous changes.
// update
switch (crMode) {
case 0: // Original
break;
case 1: // Changed Version
motionText += ' and get changed version';
break;
case 2: // Diff Version
motionText += ' and get diff version';
break;
case 3: // Final Version
motionText += ' and final version';
break;
}
return motionText;
} else {
return null;
}
}
}

View File

@ -5,6 +5,7 @@
"Assignments": "Wahlen",
"Category": "",
"Change Password": "Passwort ändern",
"Changed version": "",
"Comment": "",
"Content": "",
"Copyright by": "Copyright by",
@ -21,6 +22,7 @@
"0": ""
}
},
"Diff version": "",
"EMail": "",
"Edit Profile": "Profil bearbeiten",
"Edit category details:": "",
@ -34,6 +36,7 @@
},
"FILTER": "",
"Files": "Dateien",
"Final version": "",
"First Name": "",
"French": "Französisch",
"German": "Deutsch",
@ -41,6 +44,7 @@
"Home": "Startseite",
"Identifier": "",
"Initial Password": "",
"Inline": "",
"Installed plugins": "",
"Is Active": "",
"Is Present": "",
@ -64,6 +68,8 @@
"0": ""
},
"Origin": "",
"Original version": "",
"Outside": "",
"Participant Number": "",
"Participants": "Teilnehmer",
"Personal Note": "",

View File

@ -5,6 +5,7 @@
"Assignments": "",
"Category": "",
"Change Password": "",
"Changed version": "",
"Comment": "",
"Content": "",
"Copyright by": "",
@ -21,6 +22,7 @@
"0": ""
}
},
"Diff version": "",
"EMail": "",
"Edit Profile": "",
"Edit category details:": "",
@ -34,6 +36,7 @@
},
"FILTER": "",
"Files": "",
"Final version": "",
"First Name": "",
"French": "",
"German": "",
@ -41,6 +44,7 @@
"Home": "",
"Identifier": "",
"Initial Password": "",
"Inline": "",
"Installed plugins": "",
"Is Active": "",
"Is Present": "",
@ -64,6 +68,8 @@
"0": ""
},
"Origin": "",
"Original version": "",
"Outside": "",
"Participant Number": "",
"Participants": "",
"Personal Note": "",

View File

@ -5,6 +5,7 @@
"Assignments": "",
"Category": "",
"Change Password": "",
"Changed version": "",
"Comment": "",
"Content": "",
"Copyright by": "",
@ -21,6 +22,7 @@
"0": ""
}
},
"Diff version": "",
"EMail": "",
"Edit Profile": "",
"Edit category details:": "",
@ -34,6 +36,7 @@
},
"FILTER": "",
"Files": "",
"Final version": "",
"First Name": "",
"French": "",
"German": "",
@ -41,6 +44,7 @@
"Home": "",
"Identifier": "",
"Initial Password": "",
"Inline": "",
"Installed plugins": "",
"Is Active": "",
"Is Present": "",
@ -64,6 +68,8 @@
"0": ""
},
"Origin": "",
"Original version": "",
"Outside": "",
"Participant Number": "",
"Participants": "",
"Personal Note": "",