Newer
Older
import { Component, ViewChild, OnInit } from '@angular/core';

Alex ORLUC
committed
import { HttpClient } from '@angular/common/http';
import { LANG } from '../../translate.component';
import { NotificationService } from '../../notification.service';
import { MatPaginator } from '@angular/material/paginator';

Alex ORLUC
committed
import { MatSidenav } from '@angular/material/sidenav';
import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { HeaderService } from '../../../service/header.service';

Alex ORLUC
committed
import { AppService } from '../../../service/app.service';
import { tap, finalize, catchError, filter, exhaustMap, map } from 'rxjs/operators';

Alex ORLUC
committed
import { of } from 'rxjs';
import { ConfirmComponent } from '../../../plugins/modal/confirm.component';
import { MatDialogRef, MatDialog } from '@angular/material/dialog';

Florian Azizian
committed
import { AlertComponent } from '../../../plugins/modal/alert.component';

Alex ORLUC
committed
declare function $j(selector: any): any;
@Component({
templateUrl: "indexing-models-administration.component.html",
styleUrls: ['indexing-models-administration.component.scss'],
providers: [NotificationService, AppService]

Alex ORLUC
committed
})
export class IndexingModelsAdministrationComponent implements OnInit {
@ViewChild('snav', { static: true }) public sidenavLeft: MatSidenav;
@ViewChild('snav2', { static: true }) public sidenavRight: MatSidenav;
lang: any = LANG;
search: string = null;
indexingModels: any[] = [];

Alex ORLUC
committed
loading: boolean = false;
displayedColumns = ['id', 'category', 'label', 'private', 'default', 'enabled', 'actions'];
dataSource = new MatTableDataSource(this.indexingModels);
@ViewChild(MatPaginator, { static: false }) paginator: MatPaginator;
@ViewChild(MatSort, { static: false }) sort: MatSort;
dialogRef: MatDialogRef<any>;
applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.dataSource.filter = filterValue;
}

Alex ORLUC
committed
constructor(
public http: HttpClient,
private notify: NotificationService,
private headerService: HeaderService,
public appService: AppService,
private dialog: MatDialog,
) { }

Alex ORLUC
committed
ngOnInit(): void {
window['MainHeaderComponent'].setSnav(this.sidenavLeft);
window['MainHeaderComponent'].setSnavRight(null);

Alex ORLUC
committed

Alex ORLUC
committed
this.http.get("../../rest/indexingModels?showDisabled=true").pipe(
map((data: any) => {
return data.indexingModels.filter((info: any) => info.private === false);
}),

Alex ORLUC
committed
tap((data: any) => {
this.indexingModels = data;
this.headerService.setHeader(this.lang.administration + ' ' + this.lang.indexingModels);
setTimeout(() => {
this.dataSource = new MatTableDataSource(this.indexingModels);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}, 0);

Alex ORLUC
committed
}),
finalize(() => this.loading = false),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
}

Alex ORLUC
committed

Florian Azizian
committed
if (!indexingModel.used) {
this.dialogRef = this.dialog.open(ConfirmComponent, { autoFocus: false, disableClose: true, data: { title: this.lang.delete, msg: this.lang.confirmAction } });
this.dialogRef.afterClosed().pipe(
filter((data: string) => data === 'ok'),
exhaustMap(() => this.http.delete('../../rest/indexingModels/' + indexingModel.id)),
tap(() => {
for (let i in this.indexingModels) {
if (this.indexingModels[i].id == indexingModel.id) {
this.indexingModels.splice(Number(i), 1);
}

Florian Azizian
committed
this.dataSource = new MatTableDataSource(this.indexingModels);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.notify.success(this.lang.indexingModelDeleted);
}),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
} else {
this.dialog.open(AlertComponent, { autoFocus: false, disableClose: true, data: { title: indexingModel.label, msg: this.lang.canNotDeleteIndexingModel } });
}

Alex ORLUC
committed
}
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
disableIndexingModel(indexingModel: any) {
this.dialogRef = this.dialog.open(ConfirmComponent, { autoFocus: false, disableClose: true, data: { title: this.lang.disable, msg: this.lang.confirmAction } });
this.dialogRef.afterClosed().pipe(
filter((data: string) => data === 'ok'),
exhaustMap(() => this.http.request('PUT', '../../rest/indexingModels/' + indexingModel.id + '/disable')),
tap((data: any) => {
for (let i in this.indexingModels) {
if (this.indexingModels[i].id == indexingModel.id) {
this.indexingModels[i].enabled = false;
}
}
this.notify.success(this.lang.indexingModelDisabled);
}),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
}
enableIndexingModel(indexingModel: any) {
this.dialogRef = this.dialog.open(ConfirmComponent, { autoFocus: false, disableClose: true, data: { title: this.lang.enable, msg: this.lang.confirmAction } });
this.dialogRef.afterClosed().pipe(
filter((data: string) => data === 'ok'),
exhaustMap(() => this.http.request('PUT', '../../rest/indexingModels/' + indexingModel.id + '/enable')),
tap((data: any) => {
for (let i in this.indexingModels) {
if (this.indexingModels[i].id == indexingModel.id) {
this.indexingModels[i].enabled = true;
}
}
this.notify.success(this.lang.indexingModelEnabled);
}),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
}