You need to sign in or sign up before continuing.
Newer
Older
import { Component, Input, OnInit, EventEmitter, Output } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { TranslateService } from '@ngx-translate/core';
import { NotificationService } from '../../service/notification/notification.service';
import { tap, finalize, catchError, exhaustMap, filter } from 'rxjs/operators';
import { HeaderService } from '../../service/header.service';
import { ConfirmComponent } from '../../plugins/modal/confirm.component';
import { MatDialogRef, MatDialog } from '@angular/material/dialog';

Florian Azizian
committed
import { FunctionsService } from '../../service/functions.service';
@Component({
selector: 'app-notes-list',
templateUrl: 'notes-list.component.html',
styleUrls: ['notes-list.component.scss'],
})
export class NotesListComponent implements OnInit {

Alex ORLUC
committed
loading: boolean = true;
resIds: number[] = [];
@Input('injectDatas') injectDatas: any;
@Input('resId') resId: number = null;
@Input('editMode') editMode: boolean = false;
@Output('reloadBadgeNotes') reloadBadgeNotes = new EventEmitter<string>();
dialogRef: MatDialogRef<any>;
public translate: TranslateService,
private notify: NotificationService,
public headerService: HeaderService,

Florian Azizian
committed
public dialog: MatDialog,
public functions: FunctionsService
ngOnInit(): void {
if (this.resId !== null) {
this.http.get(`../rest/resources/${this.resId}/notes`).pipe(
this.notes = data['notes'];
}),
finalize(() => this.loading = false),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
}
}
loadNotes(resId: number) {
this.http.get("../rest/resources/" + this.resIds[0] + "/notes")
.subscribe((data: any) => {
this.notes = data['notes'];
this.reloadBadgeNotes.emit(`${this.notes.length}`);
this.loading = false;
});
getRestrictionEntitiesId(entities: any) {

Florian Azizian
committed
if (!this.functions.empty(entities)) {
return entities.map((entity: any) => entity.item_id[0]);
}
return [];
this.dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: false, data: { title: this.translate.instant('lang.confirmRemoveNote'), msg: this.translate.instant('lang.confirmAction') } });
this.dialogRef.afterClosed().pipe(
filter((data: string) => data === 'ok'),
exhaustMap(() => this.http.request('DELETE', '../rest/notes/' + note.id)),
tap(() => {
var index = this.notes.findIndex(elem => elem.id == note.id)
if (index > -1) {
this.notes.splice(index, 1);
}
this.notify.success(this.translate.instant('lang.noteRemoved'));
this.reloadBadgeNotes.emit(`${this.notes.length}`);
editNote(note: any) {
if (!note.edit) {
note.edit = true;
} else {
note.edit = false;
}
}