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 { MaintenanceService } from '@app/core/services/maintenance/maintenance.service'; @Component({ selector: 'app-index-managment', templateUrl: './index-managment.component.html', styleUrls: ['./index-managment.component.scss'] }) export class IndexManagmentComponent extends BaseComponent implements OnInit { constructor( private uiNotificationService: UiNotificationService, private translate: TranslateService, private router: Router, private maintenanceService: MaintenanceService ) { super(); } ngOnInit() { } generateIndex(ev: Event) { (ev.target as HTMLButtonElement).disabled = true; // this.datasetService.generateIndex().pipe(takeUntil(this._destroyed)).subscribe( // response => { // (ev.target as HTMLButtonElement).disabled = false; // this.onCallbackSuccess(); // }, // error => { // (ev.target as HTMLButtonElement).disabled = false; // this.onCallbackError(error); // } // ); this.maintenanceService.generateElasticIndex().pipe(takeUntil(this._destroyed)).subscribe( response => { (ev.target as HTMLButtonElement).disabled = false; this.onCallbackSuccess(); }, error => { (ev.target as HTMLButtonElement).disabled = false; this.onCallbackError(error); } ); } clearIndex(ev: Event) { (ev.target as HTMLButtonElement).disabled = true; // this.datasetService.clearIndex().pipe(takeUntil(this._destroyed)).subscribe( // response => { // (ev.target as HTMLButtonElement).disabled = false; // this.onCallbackSuccess(); // }, // error => { // (ev.target as HTMLButtonElement).disabled = false; // this.onCallbackError(error); // } // ); this.maintenanceService.clearElasticIndex().pipe(takeUntil(this._destroyed)).subscribe( response => { (ev.target as HTMLButtonElement).disabled = false; this.onCallbackSuccess(); }, error => { (ev.target 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(['/index-managment'])); } onCallbackError(error: any) { this.uiNotificationService.snackBarNotification( error, SnackBarNotificationLevel.Error); //this.validateAllFormFields(this.formGroup); } }