Skip to content
Snippets Groups Projects
note-editor.component.ts 1.82 KiB
Newer Older
  • Learn to ignore specific revisions
  • Alex ORLUC's avatar
    Alex ORLUC committed
    import { Component, AfterViewInit, Input, EventEmitter, Output } from '@angular/core';
    
    import { HttpClient } from '@angular/common/http';
    import { LANG } from '../translate.component';
    import { NotificationService } from '../notification.service';
    
    @Component({
        selector: 'app-note-editor',
        templateUrl: 'note-editor.component.html',
        styleUrls: ['note-editor.component.scss'],
        providers: [NotificationService]
    })
    export class NoteEditorComponent implements AfterViewInit {
    
        lang: any = LANG;
        notes: any;
    
        loading: boolean = false;
    
        templatesNote: any = [];
    
        content: string = '';
    
    
        @Input('resIds') resIds: any[];
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        @Input('addMode') addMode: boolean;
        @Output('refreshNotes') refreshNotes = new EventEmitter<string>();
    
        constructor(public http: HttpClient) { }
    
    
        ngAfterViewInit() {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
    
            this.loading = true
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.http.post("../../rest/res/" + this.resIds[0] + "/notes", { note_text: this.content })
                .subscribe((data: any) => {
                    this.refreshNotes.emit(this.resIds[0]);
    
                    this.loading = false;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                });
    
    
        getNoteContent() {
            return this.content;
        }
    
    
        selectTemplate(template: any) {
            if (this.content.length > 0) {
                this.content = this.content + ' ' + template.template_content;
            } else {
                this.content = template.template_content;
            }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
    
        }
    
        getTemplatesNote() {
            if (this.templatesNote.length == 0) {
    
    Damien's avatar
    Damien committed
                let params = {};
    
                if (this.resIds.length == 1) {
    
    Damien's avatar
    Damien committed
                    params['resId'] = this.resIds[0];
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                this.http.get("../../rest/notes/templates", { params: params })
                    .subscribe((data: any) => {
                        this.templatesNote = data['templates'];
                    });