Skip to content
Snippets Groups Projects
note-resume.component.ts 1.38 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
    
    import { HttpClient } from '@angular/common/http';
    import { LANG } from '../../translate.component';
    import { catchError, tap, finalize } from 'rxjs/operators';
    import { of } from 'rxjs';
    import { NotificationService } from '../../notification.service';
    
    
    @Component({
        selector: 'app-note-resume',
        templateUrl: "note-resume.component.html",
        styleUrls: [
            'note-resume.component.scss',
        ]
    })
    
    export class NoteResumeComponent implements OnInit {
    
        lang: any = LANG;
    
        loading: boolean = true;
    
        notes: any[] = [];
    
        @Input('resId') resId: number = null;
    
        @Output('goTo') goTo = new EventEmitter<string>();
    
    
        constructor(
            public http: HttpClient,
            private notify: NotificationService,
        ) {
        }
    
        ngOnInit(): void {
            this.loading = true;
            this.loadNotes(this.resId);
        }
    
        loadNotes(resId: number) {
    
            this.loading = true;
    
            this.http.get(`../../rest/resources/${resId}/notes?limit=3`).pipe(
    
                tap((data: any) => {
                    this.notes = data.notes;
                }),
                finalize(() => this.loading = false),
                catchError((err: any) => {
                    this.notify.handleErrors(err);
                    return of(false);
                })
            ).subscribe();
        }
    
    
        showMore() {
            this.goTo.emit();
        }