2018-05-03 18:23:48 -04:00
|
|
|
import {Component, OnDestroy, OnInit} from '@angular/core';
|
2018-03-30 15:30:30 -04:00
|
|
|
import {IndexingSettingsService} from './indexing.settings.service';
|
2019-03-03 10:30:12 +01: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';
|
|
|
|
import {IndexingConfig, ReIndexingSensitivity} from '../../../../../common/config/private/IPrivateConfig';
|
2018-03-30 15:30:30 -04:00
|
|
|
import {SettingsComponent} from '../_abstract/abstract.settings.component';
|
2019-03-03 10:30:12 +01:00
|
|
|
import {Utils} from '../../../../../common/Utils';
|
2018-03-30 15:30:30 -04:00
|
|
|
import {I18n} from '@ngx-translate/i18n-polyfill';
|
2019-07-27 22:56:12 +02:00
|
|
|
import {ScheduledTasksService} from '../scheduled-tasks.service';
|
|
|
|
import {DefaultsTasks} from '../../../../../common/entities/task/TaskDTO';
|
2017-07-25 21:09:37 +02:00
|
|
|
|
|
|
|
@Component({
|
2018-05-03 19:17:08 -04:00
|
|
|
selector: 'app-settings-indexing',
|
2017-07-25 21:09:37 +02:00
|
|
|
templateUrl: './indexing.settings.component.html',
|
|
|
|
styleUrls: ['./indexing.settings.component.css',
|
|
|
|
'./../_abstract/abstract.settings.component.css'],
|
|
|
|
providers: [IndexingSettingsService],
|
|
|
|
})
|
2018-05-03 18:23:48 -04:00
|
|
|
export class IndexingSettingsComponent extends SettingsComponent<IndexingConfig, IndexingSettingsService>
|
|
|
|
implements OnInit, OnDestroy {
|
2017-07-27 23:10:16 +02:00
|
|
|
|
|
|
|
|
2018-05-28 11:51:52 -04:00
|
|
|
types: { key: number; value: string }[] = [];
|
2019-01-19 17:31:23 +01:00
|
|
|
|
|
|
|
constructor(_authService: AuthenticationService,
|
|
|
|
_navigation: NavigationService,
|
|
|
|
_settingsService: IndexingSettingsService,
|
2019-07-27 22:56:12 +02:00
|
|
|
public tasksService: ScheduledTasksService,
|
2019-01-19 17:31:23 +01:00
|
|
|
notification: NotificationService,
|
|
|
|
i18n: I18n) {
|
|
|
|
|
|
|
|
super(i18n('Indexing'),
|
|
|
|
_authService,
|
|
|
|
_navigation,
|
|
|
|
<any>_settingsService,
|
|
|
|
notification,
|
|
|
|
i18n,
|
2019-12-09 14:05:06 +01:00
|
|
|
s => s.Server.Indexing);
|
2019-01-19 17:31:23 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-27 22:56:12 +02:00
|
|
|
get Progress() {
|
|
|
|
return this.tasksService.progress.value[DefaultsTasks[DefaultsTasks.Indexing]];
|
2019-01-19 17:31:23 +01:00
|
|
|
}
|
|
|
|
|
2019-12-04 21:40:57 +00: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(';');
|
|
|
|
}
|
|
|
|
|
2019-12-07 19:28:57 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
super.ngOnDestroy();
|
|
|
|
this.tasksService.unsubscribeFromProgress();
|
|
|
|
}
|
|
|
|
|
2017-07-25 21:09:37 +02:00
|
|
|
async ngOnInit() {
|
2017-07-27 23:10:16 +02:00
|
|
|
super.ngOnInit();
|
2019-07-27 22:56:12 +02:00
|
|
|
this.tasksService.subscribeToProgress();
|
2017-07-27 23:10:16 +02:00
|
|
|
this.types = Utils
|
|
|
|
.enumToArray(ReIndexingSensitivity);
|
2018-05-28 11:51:52 -04: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-25 21:09:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-24 13:08:34 +01:00
|
|
|
async index(createThumbnails: boolean) {
|
2017-07-25 21:09:37 +02:00
|
|
|
this.inProgress = true;
|
2018-03-30 15:30:30 -04:00
|
|
|
this.error = '';
|
2017-07-25 21:09:37 +02:00
|
|
|
try {
|
2019-07-27 22:56:12 +02:00
|
|
|
await this.tasksService.start(DefaultsTasks[DefaultsTasks.Indexing], {createThumbnails: !!createThumbnails});
|
2019-01-19 17:31:23 +01:00
|
|
|
this.notification.info(this.i18n('Folder indexing started'));
|
2017-07-25 21:09:37 +02: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-27 23:10:16 +02:00
|
|
|
async cancelIndexing() {
|
2017-07-25 21:09:37 +02:00
|
|
|
this.inProgress = true;
|
2018-03-30 15:30:30 -04:00
|
|
|
this.error = '';
|
2017-07-25 21:09:37 +02:00
|
|
|
try {
|
2019-07-27 22:56:12 +02:00
|
|
|
await this.tasksService.stop(DefaultsTasks[DefaultsTasks.Indexing]);
|
2019-01-19 17:31:23 +01:00
|
|
|
this.notification.info(this.i18n('Folder indexing interrupted'));
|
2017-07-25 21:09:37 +02: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-27 23:10:16 +02:00
|
|
|
async resetDatabase() {
|
2017-07-25 21:09:37 +02:00
|
|
|
this.inProgress = true;
|
2018-03-30 15:30:30 -04:00
|
|
|
this.error = '';
|
2017-07-25 21:09:37 +02:00
|
|
|
try {
|
2019-07-27 22:56:12 +02:00
|
|
|
await this.tasksService.start(DefaultsTasks[DefaultsTasks['Database Reset']]);
|
2019-12-07 19:28:57 +01:00
|
|
|
this.notification.info(this.i18n('Resetting database'));
|
2017-07-25 21:09:37 +02:00
|
|
|
this.inProgress = false;
|
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
if (err.message) {
|
|
|
|
this.error = (<ErrorDTO>err).message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.inProgress = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|