Update personal note in motion

Fixes an issue where personal notes were not update
during a view motions update process
This commit is contained in:
Sean Engelhardt 2019-05-08 13:24:52 +02:00 committed by FinnStutzenstein
parent 30232f3f08
commit 7d49187123
5 changed files with 60 additions and 29 deletions

View File

@ -66,7 +66,7 @@ export class ViewModelStoreService {
} }
/** /**
* Get all view modles from a collection, that satisfy the callback * Get all view models from a collection, that satisfy the callback
* *
* @param collectionString The collection * @param collectionString The collection
* @param callback The function to check * @param callback The function to check
@ -80,7 +80,7 @@ export class ViewModelStoreService {
} }
/** /**
* Finds one view model from the collection, that satifies the callback * Finds one view model from the collection, that satisfies the callback
* *
* @param collectionString The collection * @param collectionString The collection
* @param callback THe callback to satisfy * @param callback THe callback to satisfy

View File

@ -16,6 +16,7 @@ import { ViewMotionBlock } from './view-motion-block';
import { BaseViewModel } from 'app/site/base/base-view-model'; import { BaseViewModel } from 'app/site/base/base-view-model';
import { ConfigService } from 'app/core/ui-services/config.service'; import { ConfigService } from 'app/core/ui-services/config.service';
import { ViewMotionChangeRecommendation } from './view-change-recommendation'; import { ViewMotionChangeRecommendation } from './view-change-recommendation';
import { ViewPersonalNote } from 'app/site/users/models/view-personal-note';
import { _ } from 'app/core/translate/translation-marker'; import { _ } from 'app/core/translate/translation-marker';
/** /**
@ -318,6 +319,13 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
return this.motion.comments.map(comment => comment.section_id); return this.motion.comments.map(comment => comment.section_id);
} }
/**
* @returns the text of a personal note
*/
public get personalNoteText(): string {
return this.personalNote.note;
}
/** /**
* Getter to query the 'favorite'/'star' status of the motions * Getter to query the 'favorite'/'star' status of the motions
* *
@ -477,6 +485,8 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
this.updateMotion(update); this.updateMotion(update);
} else if (update instanceof ViewMotionChangeRecommendation) { } else if (update instanceof ViewMotionChangeRecommendation) {
this.updateChangeRecommendation(update); this.updateChangeRecommendation(update);
} else if (update instanceof ViewPersonalNote) {
this.updatePersonalNote(update);
} }
} }
@ -599,6 +609,10 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
} }
} }
private updatePersonalNote(personalNote: ViewPersonalNote): void {
this.personalNote = personalNote.getNoteContent(this.collectionString, this.id);
}
public hasSupporters(): boolean { public hasSupporters(): boolean {
return !!(this.supporters && this.supporters.length > 0); return !!(this.supporters && this.supporters.length > 0);
} }

View File

@ -1,42 +1,47 @@
<os-meta-text-block showActionRow="true" icon="speaker_notes"> <os-meta-text-block showActionRow="true" icon="speaker_notes">
<!-- Title row -->
<ng-container class="meta-text-block-title"> <ng-container class="meta-text-block-title">
<span translate>Personal note</span> <span translate>Personal note</span>
</ng-container> </ng-container>
<!-- Actions -->
<ng-container class="meta-text-block-action-row">
<button mat-icon-button *ngIf="!isEditMode" (click)="editPersonalNote()" matTooltip="{{ 'Edit' | translate }}">
<mat-icon>edit</mat-icon>
</button>
<button
mat-icon-button
*ngIf="!isEditMode && motion && motion.personalNote && motion.personalNote.note"
(click)="printPersonalNote()"
matTooltip="{{ 'Export personal note only' | translate }}"
>
<mat-icon>picture_as_pdf</mat-icon>
</button>
<button mat-icon-button *ngIf="isEditMode" (click)="savePersonalNote()" matTooltip="{{ 'Save' | translate }}">
<mat-icon>save</mat-icon>
</button>
<button
mat-icon-button
*ngIf="isEditMode"
(click)="isEditMode = false"
matTooltip="{{ 'Cancel edit' | translate }}"
>
<mat-icon>close</mat-icon>
</button>
</ng-container>
<!-- Content -->
<ng-container class="meta-text-block-content"> <ng-container class="meta-text-block-content">
<ng-container *ngIf="!isEditMode"> <ng-container *ngIf="!isEditMode">
<div *ngIf="motion && motion.personalNote" [innerHTML]="sanitizeText(motion.personalNote.note)"></div> <div *ngIf="motion && motion.personalNote" [innerHTML]="personalNoteText"></div>
<div class="no-content" *ngIf="!motion || !motion.personalNote || !motion.personalNote.note" translate> <div class="no-content" *ngIf="!motion || !motion.hasNotes" translate>
No personal note No personal note
</div> </div>
</ng-container> </ng-container>
<form [formGroup]="personalNoteForm" *ngIf="isEditMode"> <form [formGroup]="personalNoteForm" *ngIf="isEditMode">
<!-- The HTML Editor --> <!-- The HTML Editor -->
<h4 translate>Personal note</h4> <h4 translate>Personal note</h4>
<editor <editor formControlName="note" [init]="tinyMceSettings"></editor>
formControlName='note'
[init]="tinyMceSettings"
></editor>
</form> </form>
</ng-container> </ng-container>
<ng-container class="meta-text-block-action-row">
<button mat-icon-button *ngIf="!isEditMode" (click)="editPersonalNote()"
matTooltip="{{ 'Edit' | translate }}">
<mat-icon>edit</mat-icon>
</button>
<button mat-icon-button *ngIf="!isEditMode && motion && motion.personalNote && motion.personalNote.note"
(click)="printPersonalNote()"
matTooltip="{{ 'Export personal note only' | translate }}">
<mat-icon>picture_as_pdf</mat-icon>
</button>
<button mat-icon-button *ngIf="isEditMode" (click)="savePersonalNote()"
matTooltip="{{ 'Save' | translate }}">
<mat-icon>save</mat-icon>
</button>
<button mat-icon-button *ngIf="isEditMode" (click)="isEditMode = false"
matTooltip="{{ 'Cancel edit' | translate }}">
<mat-icon>close</mat-icon>
</button>
</ng-container>
</os-meta-text-block> </os-meta-text-block>

View File

@ -35,6 +35,10 @@ export class PersonalNoteComponent extends BaseComponent {
*/ */
public isEditMode = false; public isEditMode = false;
public get personalNoteText(): string {
return this.motion.personalNoteText;
}
/** /**
* Constructor. Creates form * Constructor. Creates form
* *

View File

@ -1,5 +1,5 @@
import { BaseViewModel } from 'app/site/base/base-view-model'; import { BaseViewModel } from 'app/site/base/base-view-model';
import { PersonalNote, PersonalNotesFormat } from 'app/shared/models/users/personal-note'; import { PersonalNote, PersonalNotesFormat, PersonalNoteContent } from 'app/shared/models/users/personal-note';
export class ViewPersonalNote extends BaseViewModel { export class ViewPersonalNote extends BaseViewModel {
public static COLLECTIONSTRING = PersonalNote.COLLECTIONSTRING; public static COLLECTIONSTRING = PersonalNote.COLLECTIONSTRING;
@ -32,6 +32,14 @@ export class ViewPersonalNote extends BaseViewModel {
this._personalNote = personalNote; this._personalNote = personalNote;
} }
public getNoteContent(collection: string, id: number): PersonalNoteContent | null {
if (this.notes[collection]) {
return this.notes[collection][id];
} else {
return null;
}
}
public getTitle = () => { public getTitle = () => {
return this.personalNote ? this.personalNote.toString() : null; return this.personalNote ? this.personalNote.toString() : null;
}; };