2018-05-04 06:23:48 +08:00
|
|
|
import {Component, OnDestroy, OnInit} from '@angular/core';
|
2018-03-31 03:30:30 +08:00
|
|
|
import {IndexingSettingsService} from './indexing.settings.service';
|
2019-03-03 17:30:12 +08:00
|
|
|
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';
|
2019-01-20 00:31:23 +08:00
|
|
|
import {interval, Observable} from 'rxjs';
|
2019-03-03 17:30:12 +08:00
|
|
|
import {IndexingConfig, ReIndexingSensitivity} from '../../../../../common/config/private/IPrivateConfig';
|
2018-03-31 03:30:30 +08:00
|
|
|
import {SettingsComponent} from '../_abstract/abstract.settings.component';
|
2019-03-03 17:30:12 +08:00
|
|
|
import {Utils} from '../../../../../common/Utils';
|
2018-03-31 03:30:30 +08:00
|
|
|
import {I18n} from '@ngx-translate/i18n-polyfill';
|
2019-03-03 17:30:12 +08:00
|
|
|
import {StatisticDTO} from '../../../../../common/entities/settings/StatisticDTO';
|
2017-07-26 03:09:37 +08:00
|
|
|
|
|
|
|
@Component({
|
2018-05-04 07:17:08 +08:00
|
|
|
selector: 'app-settings-indexing',
|
2017-07-26 03:09:37 +08:00
|
|
|
templateUrl: './indexing.settings.component.html',
|
|
|
|
styleUrls: ['./indexing.settings.component.css',
|
|
|
|
'./../_abstract/abstract.settings.component.css'],
|
|
|
|
providers: [IndexingSettingsService],
|
|
|
|
})
|
2018-05-04 06:23:48 +08:00
|
|
|
export class IndexingSettingsComponent extends SettingsComponent<IndexingConfig, IndexingSettingsService>
|
|
|
|
implements OnInit, OnDestroy {
|
2017-07-28 05:10:16 +08:00
|
|
|
|
|
|
|
|
2018-05-28 23:51:52 +08:00
|
|
|
types: { key: number; value: string }[] = [];
|
2019-01-20 00:31:23 +08:00
|
|
|
statistic: StatisticDTO;
|
2017-07-28 05:10:16 +08:00
|
|
|
private subscription: { timer: any, settings: any } = {
|
|
|
|
timer: null,
|
|
|
|
settings: null
|
|
|
|
};
|
|
|
|
private $counter: Observable<number> = null;
|
2019-01-20 00:31:23 +08:00
|
|
|
|
|
|
|
constructor(_authService: AuthenticationService,
|
|
|
|
_navigation: NavigationService,
|
|
|
|
_settingsService: IndexingSettingsService,
|
|
|
|
notification: NotificationService,
|
|
|
|
i18n: I18n) {
|
|
|
|
|
|
|
|
super(i18n('Indexing'),
|
|
|
|
_authService,
|
|
|
|
_navigation,
|
|
|
|
<any>_settingsService,
|
|
|
|
notification,
|
|
|
|
i18n,
|
|
|
|
s => s.Server.indexing);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
get TimeLeft() {
|
|
|
|
const prg = this._settingsService.progress.value;
|
|
|
|
return (prg.time.current - prg.time.start) / prg.indexed * prg.left;
|
|
|
|
}
|
|
|
|
|
|
|
|
get TimeElapsed() {
|
|
|
|
const prg = this._settingsService.progress.value;
|
|
|
|
return (prg.time.current - prg.time.start);
|
|
|
|
}
|
|
|
|
|
2017-07-26 03:09:37 +08:00
|
|
|
updateProgress = async () => {
|
|
|
|
try {
|
2019-01-20 00:31:23 +08:00
|
|
|
const wasRunning = this._settingsService.progress.value !== null;
|
2017-07-28 05:10:16 +08:00
|
|
|
await (<IndexingSettingsService>this._settingsService).getProgress();
|
2019-01-20 00:31:23 +08:00
|
|
|
if (wasRunning && this._settingsService.progress.value === null) {
|
|
|
|
this.notification.success(this.i18n('Folder indexed'), this.i18n('Success'));
|
|
|
|
}
|
2017-07-26 03:09:37 +08:00
|
|
|
} catch (err) {
|
|
|
|
if (this.subscription.timer != null) {
|
|
|
|
this.subscription.timer.unsubscribe();
|
|
|
|
this.subscription.timer = null;
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 05:10:16 +08:00
|
|
|
if ((<IndexingSettingsService>this._settingsService).progress.value != null && this.subscription.timer == null) {
|
2017-07-26 03:09:37 +08:00
|
|
|
if (!this.$counter) {
|
2018-05-04 06:23:48 +08:00
|
|
|
this.$counter = interval(5000);
|
2017-07-26 03:09:37 +08:00
|
|
|
}
|
|
|
|
this.subscription.timer = this.$counter.subscribe((x) => this.updateProgress());
|
|
|
|
}
|
2017-07-28 05:10:16 +08:00
|
|
|
if ((<IndexingSettingsService>this._settingsService).progress.value == null && this.subscription.timer != null) {
|
2017-07-26 03:09:37 +08:00
|
|
|
this.subscription.timer.unsubscribe();
|
|
|
|
this.subscription.timer = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-05 05:40:57 +08:00
|
|
|
get excludeFolderList(): string {
|
|
|
|
return this.settings.excludeFolderList.join(';');
|
|
|
|
}
|
|
|
|
|
|
|
|
set excludeFolderList(value: string) {
|
|
|
|
this.settings.excludeFolderList = value.split(';');
|
|
|
|
}
|
|
|
|
|
|
|
|
get excludeFileList(): string {
|
|
|
|
return this.settings.excludeFileList.join(';');
|
|
|
|
}
|
|
|
|
|
|
|
|
set excludeFileList(value: string) {
|
|
|
|
this.settings.excludeFileList = value.split(';');
|
|
|
|
}
|
|
|
|
|
2017-07-26 03:09:37 +08:00
|
|
|
async ngOnInit() {
|
2017-07-28 05:10:16 +08:00
|
|
|
super.ngOnInit();
|
|
|
|
this.types = Utils
|
|
|
|
.enumToArray(ReIndexingSensitivity);
|
2018-05-28 23:51:52 +08:00
|
|
|
this.types.forEach(v => {
|
|
|
|
switch (v.value) {
|
|
|
|
case 'low':
|
|
|
|
v.value = this.i18n('low');
|
|
|
|
break;
|
|
|
|
case 'medium':
|
|
|
|
v.value = this.i18n('medium');
|
|
|
|
break;
|
|
|
|
case 'high':
|
|
|
|
v.value = this.i18n('high');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2017-07-26 03:09:37 +08:00
|
|
|
this.updateProgress();
|
2019-07-21 16:52:34 +08:00
|
|
|
if (this._settingsService.isSupported()) {
|
|
|
|
this.statistic = await this._settingsService.getStatistic();
|
|
|
|
}
|
2017-07-26 03:09:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
2017-07-28 05:10:16 +08:00
|
|
|
super.ngOnDestroy();
|
2017-07-26 03:09:37 +08: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-24 20:08:34 +08:00
|
|
|
async index(createThumbnails: boolean) {
|
2017-07-26 03:09:37 +08:00
|
|
|
this.inProgress = true;
|
2018-03-31 03:30:30 +08:00
|
|
|
this.error = '';
|
2017-07-26 03:09:37 +08:00
|
|
|
try {
|
2018-11-24 20:08:34 +08:00
|
|
|
await this._settingsService.index(createThumbnails);
|
2017-07-26 03:09:37 +08:00
|
|
|
this.updateProgress();
|
2019-01-20 00:31:23 +08:00
|
|
|
this.notification.info(this.i18n('Folder indexing started'));
|
2017-07-26 03:09:37 +08:00
|
|
|
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-28 05:10:16 +08:00
|
|
|
async cancelIndexing() {
|
2017-07-26 03:09:37 +08:00
|
|
|
this.inProgress = true;
|
2018-03-31 03:30:30 +08:00
|
|
|
this.error = '';
|
2017-07-26 03:09:37 +08:00
|
|
|
try {
|
2017-07-28 05:10:16 +08:00
|
|
|
await (<IndexingSettingsService>this._settingsService).cancel();
|
2019-01-20 00:31:23 +08:00
|
|
|
this._settingsService.progress.next(null);
|
|
|
|
this.notification.info(this.i18n('Folder indexing interrupted'));
|
2017-07-26 03:09:37 +08:00
|
|
|
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-28 05:10:16 +08:00
|
|
|
async resetDatabase() {
|
2017-07-26 03:09:37 +08:00
|
|
|
this.inProgress = true;
|
2018-03-31 03:30:30 +08:00
|
|
|
this.error = '';
|
2017-07-26 03:09:37 +08:00
|
|
|
try {
|
2017-07-28 05:10:16 +08:00
|
|
|
await (<IndexingSettingsService>this._settingsService).reset();
|
2018-03-31 03:30:30 +08:00
|
|
|
this.notification.success(this.i18n('Database reset'), this.i18n('Success'));
|
2017-07-26 03:09:37 +08:00
|
|
|
this.inProgress = false;
|
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
if (err.message) {
|
|
|
|
this.error = (<ErrorDTO>err).message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.inProgress = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|