import { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; import { RendicontazioneService } from './rendicontazione.service'; import { HttpErrorResponse } from '@angular/common/http'; import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; @Component({ selector: 'jhi-rendicontazione', templateUrl: './rendicontazione.component.html', styleUrls: ['rendicontazione.scss'], }) export class RendicontazioneComponent implements OnInit { year: number; month: number; m!: NgbModalRef; @ViewChild('content', { static: true }) content!: ElementRef; constructor(private modalService: NgbModal, private rendicontazioneService: RendicontazioneService) { const date: Date = new Date(); this.year = date.getFullYear(); this.month = date.getMonth() + 1; } ngOnInit(): void {} private openLoading(): void { this.m = this.modalService.open(this.content, { size: 'sm', centered: true, backdrop: 'static', keyboard: false }); } private closeLoading(): void { this.m.close(); } rendiconta(): void { this.openLoading(); if (this.year == null || this.year <= 0) { // eslint-disable-next-line no-console console.log('Select the year'); this.closeLoading(); return; } if (this.month == null || this.month <= 0) { // eslint-disable-next-line no-console console.log('Select the month'); this.closeLoading(); return; } this.rendicontazioneService.rendiconta(this.year, this.month).subscribe( () => this.onSuccess(), error => this.onError(error) ); } private onSuccess(): void { this.closeLoading(); // eslint-disable-next-line no-console console.log('Success'); } private onError(error: HttpErrorResponse): void { this.closeLoading(); // eslint-disable-next-line no-console console.log('Error'); // eslint-disable-next-line no-console console.log(error); } }