Merge pull request #4675 from tsiegleauq/personal-note-bug

Update personal note in motion
This commit is contained in:
Emanuel Schütze 2019-05-08 20:55:37 +02:00 committed by GitHub
commit cef2e45b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 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 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 { ConfigService } from 'app/core/ui-services/config.service';
import { ViewMotionChangeRecommendation } from './view-change-recommendation';
import { ViewPersonalNote } from 'app/site/users/models/view-personal-note';
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);
}
/**
* @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
*
@ -477,6 +485,8 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable {
this.updateMotion(update);
} else if (update instanceof ViewMotionChangeRecommendation) {
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 {
return !!(this.supporters && this.supporters.length > 0);
}

View File

@ -1,42 +1,47 @@
<os-meta-text-block showActionRow="true" icon="speaker_notes">
<!-- Title row -->
<ng-container class="meta-text-block-title">
<span translate>Personal note</span>
</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 *ngIf="!isEditMode">
<div *ngIf="motion && motion.personalNote" [innerHTML]="sanitizeText(motion.personalNote.note)"></div>
<div class="no-content" *ngIf="!motion || !motion.personalNote || !motion.personalNote.note" translate>
<div *ngIf="motion && motion.personalNote" [innerHTML]="personalNoteText"></div>
<div class="no-content" *ngIf="!motion || !motion.hasNotes" translate>
No personal note
</div>
</ng-container>
<form [formGroup]="personalNoteForm" *ngIf="isEditMode">
<!-- The HTML Editor -->
<h4 translate>Personal note</h4>
<editor
formControlName='note'
[init]="tinyMceSettings"
></editor>
<editor formControlName="note" [init]="tinyMceSettings"></editor>
</form>
</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>

View File

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

View File

@ -1,5 +1,5 @@
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 {
public static COLLECTIONSTRING = PersonalNote.COLLECTIONSTRING;
@ -32,6 +32,14 @@ export class ViewPersonalNote extends BaseViewModel {
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 = () => {
return this.personalNote ? this.personalNote.toString() : null;
};