2018-03-31 03:30:30 +08:00
|
|
|
import {Injectable} from '@angular/core';
|
2019-03-03 17:30:12 +08:00
|
|
|
import {NetworkService} from '../../../model/network/network.service';
|
2018-03-31 03:30:30 +08:00
|
|
|
import {SettingsService} from '../settings.service';
|
|
|
|
import {AbstractSettingsService} from '../_abstract/abstract.settings.service';
|
2019-03-03 17:30:12 +08:00
|
|
|
import {DatabaseType, IndexingConfig} from '../../../../../common/config/private/IPrivateConfig';
|
2018-05-23 08:27:07 +08:00
|
|
|
import {BehaviorSubject} from 'rxjs';
|
2019-03-03 17:30:12 +08:00
|
|
|
import {StatisticDTO} from '../../../../../common/entities/settings/StatisticDTO';
|
2019-12-08 02:28:57 +08:00
|
|
|
import {ScheduledTasksService} from '../scheduled-tasks.service';
|
|
|
|
import {DefaultsTasks} from '../../../../../common/entities/task/TaskDTO';
|
2017-07-26 03:09:37 +08:00
|
|
|
|
|
|
|
@Injectable()
|
2017-07-28 05:10:16 +08:00
|
|
|
export class IndexingSettingsService extends AbstractSettingsService<IndexingConfig> {
|
2017-07-26 03:09:37 +08:00
|
|
|
|
|
|
|
|
2019-12-08 02:28:57 +08:00
|
|
|
public statistic: BehaviorSubject<StatisticDTO>;
|
2017-07-26 03:09:37 +08:00
|
|
|
|
|
|
|
constructor(private _networkService: NetworkService,
|
2019-12-08 02:28:57 +08:00
|
|
|
private _tasksService: ScheduledTasksService,
|
2017-07-26 03:09:37 +08:00
|
|
|
_settingsService: SettingsService) {
|
|
|
|
super(_settingsService);
|
2019-12-08 02:28:57 +08:00
|
|
|
this.statistic = new BehaviorSubject(null);
|
|
|
|
const sub = _settingsService.settings.subscribe(() => {
|
|
|
|
if (this.isSupported()) {
|
|
|
|
this.loadStatistic();
|
|
|
|
sub.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this._tasksService.onTaskFinish.subscribe((taskName: string) => {
|
|
|
|
if (taskName === DefaultsTasks[DefaultsTasks.Indexing] ||
|
|
|
|
taskName === DefaultsTasks[DefaultsTasks['Database Reset']]) {
|
|
|
|
if (this.isSupported()) {
|
|
|
|
this.loadStatistic();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-07-26 03:09:37 +08:00
|
|
|
}
|
|
|
|
|
2017-07-28 05:10:16 +08:00
|
|
|
public updateSettings(settings: IndexingConfig): Promise<void> {
|
2018-03-31 03:30:30 +08:00
|
|
|
return this._networkService.putJson('/settings/indexing', {settings: settings});
|
2017-07-28 05:10:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-26 03:09:37 +08:00
|
|
|
public isSupported(): boolean {
|
2019-12-09 21:05:06 +08:00
|
|
|
return this._settingsService.settings.value.Server.Database.type !== DatabaseType.memory;
|
2017-07-26 03:09:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-08 02:28:57 +08:00
|
|
|
async loadStatistic() {
|
|
|
|
this.statistic.next(await this._networkService.getJson<StatisticDTO>('/admin/statistic'));
|
2018-12-10 06:25:39 +08:00
|
|
|
}
|
2017-07-26 03:09:37 +08:00
|
|
|
}
|