1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/settings/indexing/indexing.settings.service.ts

48 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-03-31 03:30:30 +08:00
import {Injectable} from '@angular/core';
import {NetworkService} from '../../model/network/network.service';
import {SettingsService} from '../settings.service';
import {AbstractSettingsService} from '../_abstract/abstract.settings.service';
import {DatabaseType, IndexingConfig} from '../../../../common/config/private/IPrivateConfig';
import {IndexingProgressDTO} from '../../../../common/entities/settings/IndexingProgressDTO';
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
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
public progress: BehaviorSubject<IndexingProgressDTO>;
constructor(private _networkService: NetworkService,
_settingsService: SettingsService) {
super(_settingsService);
this.progress = new BehaviorSubject(null);
}
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 {
return this._settingsService.settings.value.Server.database.type != DatabaseType.memory;
}
public index() {
2018-03-31 03:30:30 +08:00
return this._networkService.putJson('/admin/indexes/job');
2017-07-26 03:09:37 +08:00
}
public cancel() {
2018-03-31 03:30:30 +08:00
return this._networkService.deleteJson('/admin/indexes/job');
2017-07-26 03:09:37 +08:00
}
public async getProgress() {
2018-03-31 03:30:30 +08:00
this.progress.next(await this._networkService.getJson<IndexingProgressDTO>('/admin/indexes/job/progress'));
2017-07-26 03:09:37 +08:00
}
public reset() {
2018-03-31 03:30:30 +08:00
return this._networkService.deleteJson('/admin/indexes');
2017-07-26 03:09:37 +08:00
}
}