2017-07-27 23:10:16 +02:00
|
|
|
import {Component} from "@angular/core";
|
2017-07-25 21:09:37 +02:00
|
|
|
import {IndexingSettingsService} from "./indexing.settings.service";
|
|
|
|
import {AuthenticationService} from "../../model/network/authentication.service";
|
|
|
|
import {NavigationService} from "../../model/navigation.service";
|
|
|
|
import {NotificationService} from "../../model/notification.service";
|
|
|
|
import {ErrorDTO} from "../../../../common/entities/Error";
|
|
|
|
import {Observable} from "rxjs/Rx";
|
2017-07-27 23:10:16 +02:00
|
|
|
import {IndexingConfig, ReIndexingSensitivity} from "../../../../common/config/private/IPrivateConfig";
|
|
|
|
import {SettingsComponent} from "../_abstract/abstract.settings.component";
|
|
|
|
import {Utils} from "../../../../common/Utils";
|
2017-07-25 21:09:37 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'settings-indexing',
|
|
|
|
templateUrl: './indexing.settings.component.html',
|
|
|
|
styleUrls: ['./indexing.settings.component.css',
|
|
|
|
'./../_abstract/abstract.settings.component.css'],
|
|
|
|
providers: [IndexingSettingsService],
|
|
|
|
})
|
2017-07-28 00:04:19 +02:00
|
|
|
export class IndexingSettingsComponent extends SettingsComponent<IndexingConfig, IndexingSettingsService> {
|
2017-07-27 23:10:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
types: Array<any> = [];
|
|
|
|
private subscription: { timer: any, settings: any } = {
|
|
|
|
timer: null,
|
|
|
|
settings: null
|
|
|
|
};
|
|
|
|
private $counter: Observable<number> = null;
|
2017-07-25 21:09:37 +02:00
|
|
|
updateProgress = async () => {
|
|
|
|
try {
|
2017-07-27 23:10:16 +02:00
|
|
|
await (<IndexingSettingsService>this._settingsService).getProgress();
|
2017-07-25 21:09:37 +02:00
|
|
|
} catch (err) {
|
|
|
|
if (this.subscription.timer != null) {
|
|
|
|
this.subscription.timer.unsubscribe();
|
|
|
|
this.subscription.timer = null;
|
|
|
|
}
|
|
|
|
}
|
2017-07-27 23:10:16 +02:00
|
|
|
if ((<IndexingSettingsService>this._settingsService).progress.value != null && this.subscription.timer == null) {
|
2017-07-25 21:09:37 +02:00
|
|
|
if (!this.$counter) {
|
|
|
|
this.$counter = Observable.interval(5000);
|
|
|
|
}
|
|
|
|
this.subscription.timer = this.$counter.subscribe((x) => this.updateProgress());
|
|
|
|
}
|
2017-07-27 23:10:16 +02:00
|
|
|
if ((<IndexingSettingsService>this._settingsService).progress.value == null && this.subscription.timer != null) {
|
2017-07-25 21:09:37 +02:00
|
|
|
this.subscription.timer.unsubscribe();
|
|
|
|
this.subscription.timer = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-07-27 23:10:16 +02:00
|
|
|
constructor(_authService: AuthenticationService,
|
|
|
|
_navigation: NavigationService,
|
|
|
|
_settingsService: IndexingSettingsService,
|
|
|
|
notification: NotificationService) {
|
|
|
|
|
|
|
|
super("Indexing", _authService, _navigation, <any>_settingsService, notification, s => s.Server.indexing);
|
|
|
|
|
2017-07-25 21:09:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async ngOnInit() {
|
2017-07-27 23:10:16 +02:00
|
|
|
super.ngOnInit();
|
|
|
|
this.types = Utils
|
|
|
|
.enumToArray(ReIndexingSensitivity);
|
2017-07-25 21:09:37 +02:00
|
|
|
this.updateProgress();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
2017-07-27 23:10:16 +02:00
|
|
|
super.ngOnDestroy();
|
2017-07-25 21:09:37 +02:00
|
|
|
if (this.subscription.timer != null) {
|
|
|
|
this.subscription.timer.unsubscribe();
|
|
|
|
this.subscription.timer = null;
|
|
|
|
}
|
|
|
|
if (this.subscription.settings != null) {
|
|
|
|
this.subscription.settings.unsubscribe();
|
|
|
|
this.subscription.settings = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async index() {
|
|
|
|
this.inProgress = true;
|
|
|
|
this.error = "";
|
|
|
|
try {
|
2017-07-28 00:04:19 +02:00
|
|
|
await this._settingsService.index();
|
2017-07-25 21:09:37 +02:00
|
|
|
this.updateProgress();
|
|
|
|
this.notification.success("Folder indexed", "Success");
|
|
|
|
this.inProgress = false;
|
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
if (err.message) {
|
|
|
|
this.error = (<ErrorDTO>err).message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.inProgress = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-27 23:10:16 +02:00
|
|
|
async cancelIndexing() {
|
2017-07-25 21:09:37 +02:00
|
|
|
this.inProgress = true;
|
|
|
|
this.error = "";
|
|
|
|
try {
|
2017-07-27 23:10:16 +02:00
|
|
|
await (<IndexingSettingsService>this._settingsService).cancel();
|
2017-07-25 21:09:37 +02:00
|
|
|
this.notification.success("Folder indexed", "Success");
|
|
|
|
this.inProgress = false;
|
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
if (err.message) {
|
|
|
|
this.error = (<ErrorDTO>err).message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.inProgress = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-27 23:10:16 +02:00
|
|
|
async resetDatabase() {
|
2017-07-25 21:09:37 +02:00
|
|
|
this.inProgress = true;
|
|
|
|
this.error = "";
|
|
|
|
try {
|
2017-07-27 23:10:16 +02:00
|
|
|
await (<IndexingSettingsService>this._settingsService).reset();
|
2017-07-25 21:09:37 +02:00
|
|
|
this.notification.success('Database reset', "Success");
|
|
|
|
this.inProgress = false;
|
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
if (err.message) {
|
|
|
|
this.error = (<ErrorDTO>err).message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.inProgress = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|