From 25692869151b507ac6a3aee3514a361853016420 Mon Sep 17 00:00:00 2001 From: Patrik Braun Date: Tue, 25 Jul 2017 21:09:37 +0200 Subject: [PATCH] implementing manual directory indexing --- backend/middlewares/AdminMWs.ts | 47 +++++- backend/middlewares/RenderingMWs.ts | 2 +- backend/model/DiskManger.ts | 2 - backend/model/ObjectManagerRepository.ts | 59 ++++--- backend/model/interfaces/IGalleryManager.ts | 1 + backend/model/interfaces/IIndexingManager.ts | 11 ++ backend/model/memory/IndexingManager.ts | 21 +++ backend/model/sql/GalleryManager.ts | 3 +- backend/model/sql/IGalleryManager.ts | 10 ++ backend/model/sql/IndexingManager.ts | 80 ++++++++++ backend/model/threading/DiskMangerWorker.ts | 2 +- backend/routes/AdminRouter.ts | 33 ++-- .../entities/settings/IndexingProgressDTO.ts | 5 + frontend/app/admin/admin.component.html | 2 + frontend/app/app.module.ts | 2 + .../_abstract/abstract.settings.component.ts | 8 +- .../indexing/indexing.settings.component.css | 3 + .../indexing/indexing.settings.component.html | 47 ++++++ .../indexing/indexing.settings.component.ts | 144 ++++++++++++++++++ .../indexing/indexing.settings.service.ts | 45 ++++++ 20 files changed, 481 insertions(+), 46 deletions(-) create mode 100644 backend/model/interfaces/IIndexingManager.ts create mode 100644 backend/model/memory/IndexingManager.ts create mode 100644 backend/model/sql/IGalleryManager.ts create mode 100644 backend/model/sql/IndexingManager.ts create mode 100644 common/entities/settings/IndexingProgressDTO.ts create mode 100644 frontend/app/settings/indexing/indexing.settings.component.css create mode 100644 frontend/app/settings/indexing/indexing.settings.component.html create mode 100644 frontend/app/settings/indexing/indexing.settings.component.ts create mode 100644 frontend/app/settings/indexing/indexing.settings.service.ts diff --git a/backend/middlewares/AdminMWs.ts b/backend/middlewares/AdminMWs.ts index 941b29dc..46476246 100644 --- a/backend/middlewares/AdminMWs.ts +++ b/backend/middlewares/AdminMWs.ts @@ -13,6 +13,7 @@ import {ProjectPath} from "../ProjectPath"; const LOG_TAG = "[AdminMWs]"; + export class AdminMWs { @@ -125,7 +126,7 @@ export class AdminMWs { } - public static async updateAuthenticationSettings(req: Request, res: Response, next: NextFunction) { + public static async updateAuthenticationSettings(req: Request, res: Response, next: NextFunction) { if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) { return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, "settings is needed")); } @@ -145,7 +146,7 @@ export class AdminMWs { } } - public static async updateThumbnailSettings(req: Request, res: Response, next: NextFunction) { + public static async updateThumbnailSettings(req: Request, res: Response, next: NextFunction) { if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) { return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, "settings is needed")); } @@ -179,7 +180,7 @@ export class AdminMWs { } - public static async updateBasicSettings(req: Request, res: Response, next: NextFunction) { + public static async updateBasicSettings(req: Request, res: Response, next: NextFunction) { if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) { return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, "settings is needed")); } @@ -209,7 +210,7 @@ export class AdminMWs { } - public static async updateOtherSettings(req: Request, res: Response, next: NextFunction) { + public static async updateOtherSettings(req: Request, res: Response, next: NextFunction) { if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) { return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, "settings is needed")); } @@ -237,4 +238,42 @@ export class AdminMWs { } + public static startIndexing(req: Request, res: Response, next: NextFunction) { + try { + ObjectManagerRepository.getInstance().IndexingManager.startIndexing(); + req.resultPipe = "ok"; + return next(); + } catch (err) { + return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, "Indexing error: " + JSON.stringify(err, null, ' '), err)); + } + } + + public static getIndexingProgress(req: Request, res: Response, next: NextFunction) { + try { + req.resultPipe = ObjectManagerRepository.getInstance().IndexingManager.getProgress(); + return next(); + } catch (err) { + return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, "Indexing error: " + JSON.stringify(err, null, ' '), err)); + } + } + + public static cancelIndexing(req: Request, res: Response, next: NextFunction) { + try { + ObjectManagerRepository.getInstance().IndexingManager.cancelIndexing(); + req.resultPipe = "ok"; + return next(); + } catch (err) { + return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, "Indexing error: " + JSON.stringify(err, null, ' '), err)); + } + } + + public static async resetIndexes(req: Request, res: Response, next: NextFunction) { + try { + await ObjectManagerRepository.getInstance().IndexingManager.reset(); + req.resultPipe = "ok"; + return next(); + } catch (err) { + return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, "Indexing error: " + JSON.stringify(err, null, ' '), err)); + } + } } diff --git a/backend/middlewares/RenderingMWs.ts b/backend/middlewares/RenderingMWs.ts index 42347858..80f902e8 100644 --- a/backend/middlewares/RenderingMWs.ts +++ b/backend/middlewares/RenderingMWs.ts @@ -12,7 +12,7 @@ import {Logger} from "../Logger"; export class RenderingMWs { public static renderResult(req: Request, res: Response, next: NextFunction) { - if (!req.resultPipe) + if (typeof req.resultPipe == "undefined") return next(); return RenderingMWs.renderMessage(res, req.resultPipe); diff --git a/backend/model/DiskManger.ts b/backend/model/DiskManger.ts index 90238e65..64cc04e0 100644 --- a/backend/model/DiskManger.ts +++ b/backend/model/DiskManger.ts @@ -7,8 +7,6 @@ import {DiskMangerWorker} from "./threading/DiskMangerWorker"; const LOG_TAG = "[DiskManager]"; - - export class DiskManager { static threadPool: DiskManagerTH = null; diff --git a/backend/model/ObjectManagerRepository.ts b/backend/model/ObjectManagerRepository.ts index 42aec966..077fc717 100644 --- a/backend/model/ObjectManagerRepository.ts +++ b/backend/model/ObjectManagerRepository.ts @@ -4,6 +4,7 @@ import {ISearchManager} from "./interfaces/ISearchManager"; import {SQLConnection} from "./sql/SQLConnection"; import {ISharingManager} from "./interfaces/ISharingManager"; import {Logger} from "../Logger"; +import {IIndexingManager} from "./interfaces/IIndexingManager"; export class ObjectManagerRepository { @@ -11,33 +12,15 @@ export class ObjectManagerRepository { private _userManager: IUserManager; private _searchManager: ISearchManager; private _sharingManager: ISharingManager; + private _indexingManager: IIndexingManager; private static _instance: ObjectManagerRepository = null; - - public static async InitMemoryManagers() { - await ObjectManagerRepository.reset(); - const GalleryManager = require("./memory/GalleryManager").GalleryManager; - const UserManager = require("./memory/UserManager").UserManager; - const SearchManager = require("./memory/SearchManager").SearchManager; - const SharingManager = require("./memory/SharingManager").SharingManager; - ObjectManagerRepository.getInstance().GalleryManager = new GalleryManager(); - ObjectManagerRepository.getInstance().UserManager = new UserManager(); - ObjectManagerRepository.getInstance().SearchManager = new SearchManager(); - ObjectManagerRepository.getInstance().SharingManager = new SharingManager(); + get IndexingManager(): IIndexingManager { + return this._indexingManager; } - public static async InitSQLManagers() { - await ObjectManagerRepository.reset(); - await SQLConnection.init(); - const GalleryManager = require("./sql/GalleryManager").GalleryManager; - const UserManager = require("./sql/UserManager").UserManager; - const SearchManager = require("./sql/SearchManager").SearchManager; - const SharingManager = require("./sql/SharingManager").SharingManager; - ObjectManagerRepository.getInstance().GalleryManager = new GalleryManager(); - ObjectManagerRepository.getInstance().UserManager = new UserManager(); - ObjectManagerRepository.getInstance().SearchManager = new SearchManager(); - ObjectManagerRepository.getInstance().SharingManager = new SharingManager(); - Logger.debug("SQL DB inited"); + set IndexingManager(value: IIndexingManager) { + this._indexingManager = value; } public static getInstance() { @@ -85,4 +68,34 @@ export class ObjectManagerRepository { this._sharingManager = value; } + public static async InitMemoryManagers() { + await ObjectManagerRepository.reset(); + const GalleryManager = require("./memory/GalleryManager").GalleryManager; + const UserManager = require("./memory/UserManager").UserManager; + const SearchManager = require("./memory/SearchManager").SearchManager; + const SharingManager = require("./memory/SharingManager").SharingManager; + const IndexingManager = require("./memory/IndexingManager").IndexingManager; + ObjectManagerRepository.getInstance().GalleryManager = new GalleryManager(); + ObjectManagerRepository.getInstance().UserManager = new UserManager(); + ObjectManagerRepository.getInstance().SearchManager = new SearchManager(); + ObjectManagerRepository.getInstance().SharingManager = new SharingManager(); + ObjectManagerRepository.getInstance().IndexingManager = new IndexingManager(); + } + + public static async InitSQLManagers() { + await ObjectManagerRepository.reset(); + await SQLConnection.init(); + const GalleryManager = require("./sql/GalleryManager").GalleryManager; + const UserManager = require("./sql/UserManager").UserManager; + const SearchManager = require("./sql/SearchManager").SearchManager; + const SharingManager = require("./sql/SharingManager").SharingManager; + const IndexingManager = require("./sql/IndexingManager").IndexingManager; + ObjectManagerRepository.getInstance().GalleryManager = new GalleryManager(); + ObjectManagerRepository.getInstance().UserManager = new UserManager(); + ObjectManagerRepository.getInstance().SearchManager = new SearchManager(); + ObjectManagerRepository.getInstance().SharingManager = new SharingManager(); + ObjectManagerRepository.getInstance().IndexingManager = new IndexingManager(); + Logger.debug("SQL DB inited"); + } + } diff --git a/backend/model/interfaces/IGalleryManager.ts b/backend/model/interfaces/IGalleryManager.ts index ca380590..20a088f7 100644 --- a/backend/model/interfaces/IGalleryManager.ts +++ b/backend/model/interfaces/IGalleryManager.ts @@ -4,4 +4,5 @@ export interface IGalleryManager { listDirectory(relativeDirectoryName: string, knownLastModified?: number, knownLastScanned?: number): Promise; + } diff --git a/backend/model/interfaces/IIndexingManager.ts b/backend/model/interfaces/IIndexingManager.ts new file mode 100644 index 00000000..4607c4a3 --- /dev/null +++ b/backend/model/interfaces/IIndexingManager.ts @@ -0,0 +1,11 @@ +import {IndexingProgressDTO} from "../../../common/entities/settings/IndexingProgressDTO"; + +export interface IIndexingManager { + startIndexing(): void; + + getProgress(): IndexingProgressDTO; + + cancelIndexing(): void; + + reset(): Promise ; +} diff --git a/backend/model/memory/IndexingManager.ts b/backend/model/memory/IndexingManager.ts new file mode 100644 index 00000000..02707168 --- /dev/null +++ b/backend/model/memory/IndexingManager.ts @@ -0,0 +1,21 @@ +import {IIndexingManager} from "../interfaces/IIndexingManager"; +import {IndexingProgressDTO} from "../../../common/entities/settings/IndexingProgressDTO"; + +export class IndexingManager implements IIndexingManager { + + startIndexing(): void { + throw new Error("not supported by memory DB"); + } + + getProgress(): IndexingProgressDTO { + throw new Error("not supported by memory DB"); + } + + cancelIndexing(): void { + throw new Error("not supported by memory DB"); + } + + reset(): Promise { + throw new Error("Method not implemented."); + } +} diff --git a/backend/model/sql/GalleryManager.ts b/backend/model/sql/GalleryManager.ts index e750d324..0919f210 100644 --- a/backend/model/sql/GalleryManager.ts +++ b/backend/model/sql/GalleryManager.ts @@ -9,8 +9,9 @@ import {PhotoEntity, PhotoMetadataEntity} from "./enitites/PhotoEntity"; import {Utils} from "../../../common/Utils"; import {ProjectPath} from "../../ProjectPath"; import {Config} from "../../../common/config/private/Config"; +import {ISQLGalleryManager} from "./IGalleryManager"; -export class GalleryManager implements IGalleryManager { +export class GalleryManager implements IGalleryManager, ISQLGalleryManager { public async listDirectory(relativeDirectoryName: string, diff --git a/backend/model/sql/IGalleryManager.ts b/backend/model/sql/IGalleryManager.ts new file mode 100644 index 00000000..af5bba97 --- /dev/null +++ b/backend/model/sql/IGalleryManager.ts @@ -0,0 +1,10 @@ +import {DirectoryDTO} from "../../../common/entities/DirectoryDTO"; + +export interface ISQLGalleryManager { + listDirectory(relativeDirectoryName: string, + knownLastModified?: number, + knownLastScanned?: number): Promise; + + indexDirectory(relativeDirectoryName): Promise; + +} diff --git a/backend/model/sql/IndexingManager.ts b/backend/model/sql/IndexingManager.ts new file mode 100644 index 00000000..098573c0 --- /dev/null +++ b/backend/model/sql/IndexingManager.ts @@ -0,0 +1,80 @@ +import {IIndexingManager} from "../interfaces/IIndexingManager"; +import {IndexingProgressDTO} from "../../../common/entities/settings/IndexingProgressDTO"; +import {ObjectManagerRepository} from "../ObjectManagerRepository"; +import {ISQLGalleryManager} from "./IGalleryManager"; +import * as path from "path"; +import {SQLConnection} from "./SQLConnection"; +import {DirectoryEntity} from "./enitites/DirectoryEntity"; +import {Logger} from "../../Logger"; + +const LOG_TAG = "[IndexingManager]"; + +export class IndexingManager implements IIndexingManager { + directoriesToIndex: string[] = []; + indexingProgress = null; + enabled = false; + private indexNewDirectory = async () => { + if (this.directoriesToIndex.length == 0) { + this.indexingProgress = null; + if (global.gc) { + global.gc(); + } + return; + } + const directory = this.directoriesToIndex.shift(); + this.indexingProgress.current = directory; + this.indexingProgress.left = this.directoriesToIndex.length; + const scanned = await (ObjectManagerRepository.getInstance().GalleryManager).indexDirectory(directory); + if (this.enabled == false) { + return; + } + this.indexingProgress.indexed++; + for (let i = 0; i < scanned.directories.length; i++) { + this.directoriesToIndex.push(path.join(scanned.directories[i].path, scanned.directories[i].name)) + } + process.nextTick(this.indexNewDirectory); + }; + + startIndexing(): void { + if (this.directoriesToIndex.length == 0 && this.enabled == false) { + Logger.info(LOG_TAG, "Starting indexing"); + this.indexingProgress = { + indexed: 0, + left: 0, + current: "" + }; + this.directoriesToIndex.push("/"); + this.enabled = true; + this.indexNewDirectory(); + } else { + Logger.info(LOG_TAG, "Already indexing.."); + } + } + + getProgress(): IndexingProgressDTO { + return this.indexingProgress; + } + + cancelIndexing(): void { + Logger.info(LOG_TAG, "Canceling indexing"); + this.directoriesToIndex = []; + this.indexingProgress = null; + this.enabled = false; + if (global.gc) { + global.gc(); + } + } + + async reset(): Promise { + Logger.info(LOG_TAG, "Resetting DB"); + this.directoriesToIndex = []; + this.indexingProgress = null; + this.enabled = false; + const connection = await SQLConnection.getConnection(); + return connection + .getRepository(DirectoryEntity) + .createQueryBuilder("directory") + .delete() + .execute(); + } +} diff --git a/backend/model/threading/DiskMangerWorker.ts b/backend/model/threading/DiskMangerWorker.ts index b94239a2..5d514467 100644 --- a/backend/model/threading/DiskMangerWorker.ts +++ b/backend/model/threading/DiskMangerWorker.ts @@ -155,7 +155,7 @@ export class DiskMangerWorker { metadata.creationDate = (iptcData.date_time ? iptcData.date_time.getTime() : metadata.creationDate); } catch (err) { - Logger.debug(LOG_TAG, "Error parsing iptc data", fullPath, err); + // Logger.debug(LOG_TAG, "Error parsing iptc data", fullPath, err); } metadata.creationDate = metadata.creationDate || 0; diff --git a/backend/routes/AdminRouter.ts b/backend/routes/AdminRouter.ts index ff298f7b..0b9482d4 100644 --- a/backend/routes/AdminRouter.ts +++ b/backend/routes/AdminRouter.ts @@ -6,24 +6,35 @@ import {AdminMWs} from "../middlewares/AdminMWs"; export class AdminRouter { public static route(app: any) { - this.addResetDB(app); this.addIndexGallery(app); this.addSettings(app); } - private static addResetDB(app) { - app.post("/api/admin/db/reset", - AuthenticationMWs.authenticate, - AuthenticationMWs.authorise(UserRoles.Admin) - //TODO: implement - ); - }; private static addIndexGallery(app) { - app.post("/api/admin/gallery/index", + app.get("/api/admin/indexes/job/progress", AuthenticationMWs.authenticate, - AuthenticationMWs.authorise(UserRoles.Admin) - //TODO: implement + AuthenticationMWs.authorise(UserRoles.Admin), + AdminMWs.getIndexingProgress, + RenderingMWs.renderResult + ); + app.put("/api/admin/indexes/job", + AuthenticationMWs.authenticate, + AuthenticationMWs.authorise(UserRoles.Admin), + AdminMWs.startIndexing, + RenderingMWs.renderResult + ); + app.delete("/api/admin/indexes/job", + AuthenticationMWs.authenticate, + AuthenticationMWs.authorise(UserRoles.Admin), + AdminMWs.cancelIndexing, + RenderingMWs.renderResult + ); + app.delete("/api/admin/indexes", + AuthenticationMWs.authenticate, + AuthenticationMWs.authorise(UserRoles.Admin), + AdminMWs.resetIndexes, + RenderingMWs.renderResult ); }; diff --git a/common/entities/settings/IndexingProgressDTO.ts b/common/entities/settings/IndexingProgressDTO.ts new file mode 100644 index 00000000..5288599e --- /dev/null +++ b/common/entities/settings/IndexingProgressDTO.ts @@ -0,0 +1,5 @@ +export interface IndexingProgressDTO { + indexed: number; + left: number; + current: string; +} diff --git a/frontend/app/admin/admin.component.html b/frontend/app/admin/admin.component.html index a59ab382..ed9e50b1 100644 --- a/frontend/app/admin/admin.component.html +++ b/frontend/app/admin/admin.component.html @@ -50,5 +50,7 @@ + diff --git a/frontend/app/app.module.ts b/frontend/app/app.module.ts index ca6db40a..d05e58f2 100644 --- a/frontend/app/app.module.ts +++ b/frontend/app/app.module.ts @@ -54,6 +54,7 @@ import {ShareSettingsComponent} from "./settings/share/share.settings.component" import {BasicSettingsComponent} from "./settings/basic/basic.settings.component"; import {OtherSettingsComponent} from "./settings/other/other.settings.component"; import {DefaultUrlSerializer, UrlSerializer, UrlTree} from '@angular/router'; +import {IndexingSettingsComponent} from "./settings/indexing/indexing.settings.component"; @Injectable() export class GoogleMapsConfig { @@ -129,6 +130,7 @@ export class CustomUrlSerializer implements UrlSerializer { ShareSettingsComponent, BasicSettingsComponent, OtherSettingsComponent, + IndexingSettingsComponent, StringifyRole], providers: [ {provide: UrlSerializer, useClass: CustomUrlSerializer}, diff --git a/frontend/app/settings/_abstract/abstract.settings.component.ts b/frontend/app/settings/_abstract/abstract.settings.component.ts index 8c4a08a1..227e1b85 100644 --- a/frontend/app/settings/_abstract/abstract.settings.component.ts +++ b/frontend/app/settings/_abstract/abstract.settings.component.ts @@ -34,9 +34,11 @@ export abstract class SettingsComponent implements OnInit, OnDestroy, OnChang private _navigation: NavigationService, public _settingsService: AbstractSettingsService, protected notification: NotificationService, - private sliceFN: (s: IPrivateConfig) => T) { - this.settingsSubscription = this._settingsService.Settings.subscribe(this.onNewSettings); - this.onNewSettings(this._settingsService._settingsService.settings.value); + private sliceFN?: (s: IPrivateConfig) => T) { + if (this.sliceFN) { + this.settingsSubscription = this._settingsService.Settings.subscribe(this.onNewSettings); + this.onNewSettings(this._settingsService._settingsService.settings.value); + } } onNewSettings = (s) => { diff --git a/frontend/app/settings/indexing/indexing.settings.component.css b/frontend/app/settings/indexing/indexing.settings.component.css new file mode 100644 index 00000000..c79ddcef --- /dev/null +++ b/frontend/app/settings/indexing/indexing.settings.component.css @@ -0,0 +1,3 @@ +.buttons { + text-align: center; +} diff --git a/frontend/app/settings/indexing/indexing.settings.component.html b/frontend/app/settings/indexing/indexing.settings.component.html new file mode 100644 index 00000000..48127fed --- /dev/null +++ b/frontend/app/settings/indexing/indexing.settings.component.html @@ -0,0 +1,47 @@ +
+
+
+

Folder indexing

+
+
+ + + If you add a new folder to your gallery, the site indexes it automatically. + If you would like to trigger indexing manually, click index button.
+ (Note: search ony searched among the indexed directories)
+ +
+ indexing: {{_settingsService.progress.value.current}} +
+
+ {{_settingsService.progress.value.indexed}}/{{_settingsService.progress.value.indexed+_settingsService.progress.value.left}} +
+
+
+ +
+ + + +
+
+
+ +
diff --git a/frontend/app/settings/indexing/indexing.settings.component.ts b/frontend/app/settings/indexing/indexing.settings.component.ts new file mode 100644 index 00000000..7cdd885b --- /dev/null +++ b/frontend/app/settings/indexing/indexing.settings.component.ts @@ -0,0 +1,144 @@ +import {Component, Input, OnDestroy, OnInit, Output} from "@angular/core"; +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 {UserRoles} from "../../../../common/entities/UserDTO"; +import {Observable} from "rxjs/Rx"; + +@Component({ + selector: 'settings-indexing', + templateUrl: './indexing.settings.component.html', + styleUrls: ['./indexing.settings.component.css', + './../_abstract/abstract.settings.component.css'], + providers: [IndexingSettingsService], +}) +export class IndexingSettingsComponent implements OnInit, OnDestroy { + + @Input() + public simplifiedMode: boolean = true; + @Output('hasAvailableSettings') + hasAvailableSettings: boolean = true; + public inProgress = false; + public error: string = null; + updateProgress = async () => { + try { + await this._settingsService.getProgress(); + } catch (err) { + if (this.subscription.timer != null) { + this.subscription.timer.unsubscribe(); + this.subscription.timer = null; + } + } + if (this._settingsService.progress.value != null && this.subscription.timer == null) { + if (!this.$counter) { + this.$counter = Observable.interval(5000); + } + this.subscription.timer = this.$counter.subscribe((x) => this.updateProgress()); + } + if (this._settingsService.progress.value == null && this.subscription.timer != null) { + this.subscription.timer.unsubscribe(); + this.subscription.timer = null; + } + + }; + private subscription: { timer: any, settings: any } = { + timer: null, + settings: null + }; + private $counter: Observable = null; + + constructor(private _authService: AuthenticationService, + private _navigation: NavigationService, + public _settingsService: IndexingSettingsService, + private notification: NotificationService) { + } + + async ngOnInit() { + if (!this._authService.isAuthenticated() || + this._authService.user.value.role < UserRoles.Admin) { + this._navigation.toLogin(); + return; + } + this.subscription.settings = this._settingsService.Settings.subscribe(() => { + this.hasAvailableSettings = (this._settingsService.isSupported() || !this.simplifiedMode); + }); + + this.updateProgress(); + } + + ngOnDestroy() { + 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 { + await this._settingsService.index(); + this.updateProgress(); + this.notification.success("Folder indexed", "Success"); + this.inProgress = false; + return true; + } catch (err) { + console.log(err); + if (err.message) { + this.error = (err).message; + } + } + + this.inProgress = false; + return false; + } + + async cancel() { + this.inProgress = true; + this.error = ""; + try { + await this._settingsService.cancel(); + this.notification.success("Folder indexed", "Success"); + this.inProgress = false; + return true; + } catch (err) { + console.log(err); + if (err.message) { + this.error = (err).message; + } + } + + this.inProgress = false; + return false; + } + + async reset() { + this.inProgress = true; + this.error = ""; + try { + await this._settingsService.reset(); + this.notification.success('Database reset', "Success"); + this.inProgress = false; + return true; + } catch (err) { + console.log(err); + if (err.message) { + this.error = (err).message; + } + } + + this.inProgress = false; + return false; + } + + +} + + + diff --git a/frontend/app/settings/indexing/indexing.settings.service.ts b/frontend/app/settings/indexing/indexing.settings.service.ts new file mode 100644 index 00000000..556c9edb --- /dev/null +++ b/frontend/app/settings/indexing/indexing.settings.service.ts @@ -0,0 +1,45 @@ +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} from "../../../../common/config/private/IPrivateConfig"; +import {IndexingProgressDTO} from "../../../../common/entities/settings/IndexingProgressDTO"; +import {BehaviorSubject} from "rxjs/BehaviorSubject"; + +@Injectable() +export class IndexingSettingsService extends AbstractSettingsService { + + + public progress: BehaviorSubject; + + constructor(private _networkService: NetworkService, + _settingsService: SettingsService) { + super(_settingsService); + this.progress = new BehaviorSubject(null); + } + + public isSupported(): boolean { + return this._settingsService.settings.value.Server.database.type != DatabaseType.memory; + } + + public index() { + return this._networkService.putJson("/admin/indexes/job"); + } + + public cancel() { + return this._networkService.deleteJson("/admin/indexes/job"); + } + + public async getProgress() { + this.progress.next(await this._networkService.getJson("/admin/indexes/job/progress")); + } + + public reset() { + return this._networkService.deleteJson("/admin/indexes"); + } + + + updateSettings(settings: void): Promise { + throw new Error("Method not implemented."); + } +}