argos/dmp-frontend/src/app/ui/admin/maintenance-tasks/maintenance-tasks.component.ts

52 lines
1.8 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
import { BaseComponent } from '@common/base/base.component';
import { takeUntil } from 'rxjs/operators';
import { UiNotificationService, SnackBarNotificationLevel } from '@app/core/services/notification/ui-notification-service';
import { TranslateService } from '@ngx-translate/core';
import { Router } from '@angular/router';
import { MaintenanceTasksService } from '@app/core/services/maintenance-tasks/maintenance-tasks.service';
@Component({
selector: 'app-maintenance-tasks',
templateUrl: './maintenance-tasks.component.html',
styleUrls: ['./maintenance-tasks.component.scss']
})
export class MaintenanceTasksComponent extends BaseComponent implements OnInit {
constructor(
private maintenanceTasksService: MaintenanceTasksService,
private uiNotificationService: UiNotificationService,
private translate: TranslateService,
private router: Router,
) {
super();
}
ngOnInit(): void {
}
migrateSchematics(ev: Event) {
(ev.srcElement as HTMLButtonElement).disabled = true;
this.maintenanceTasksService.migrateSchematics().pipe(takeUntil(this._destroyed)).subscribe(
response => {
(ev.srcElement as HTMLButtonElement).disabled = false;
this.onCallbackSuccess();
},
error => {
(ev.srcElement as HTMLButtonElement).disabled = false;
this.onCallbackError(error);
}
);
}
onCallbackSuccess(): void {
this.uiNotificationService.snackBarNotification( this.translate.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
this.router.navigate(['/reload']).then(() => this.router.navigate(['/maintenance-tasks']));
}
onCallbackError(error: any) {
this.uiNotificationService.snackBarNotification( error, SnackBarNotificationLevel.Error);
}
}