WIP: Rearrange code
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
import {DOCUMENT, isPlatformBrowser} from '@angular/common';
|
||||
import {effect, inject, Injectable, PLATFORM_ID, signal} from '@angular/core';
|
||||
import {AppState} from '../model/state/app-state.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AppConfigService {
|
||||
private readonly STORAGE_KEY = 'appConfigState';
|
||||
appState = signal<AppState>({});
|
||||
document = inject(DOCUMENT);
|
||||
platformId = inject(PLATFORM_ID);
|
||||
private initialized = false;
|
||||
|
||||
constructor() {
|
||||
const initialState = this.loadAppState();
|
||||
this.appState.set({...initialState});
|
||||
this.document.documentElement.classList.add('p-dark');
|
||||
effect(
|
||||
() => {
|
||||
const state = this.appState();
|
||||
if (!this.initialized || !state) {
|
||||
this.initialized = true;
|
||||
return;
|
||||
}
|
||||
this.saveAppState(state);
|
||||
},
|
||||
{allowSignalWrites: true}
|
||||
);
|
||||
}
|
||||
|
||||
private loadAppState(): AppState {
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
const storedState = localStorage.getItem(this.STORAGE_KEY);
|
||||
if (storedState) {
|
||||
return JSON.parse(storedState);
|
||||
}
|
||||
}
|
||||
return {
|
||||
preset: 'Aura',
|
||||
primary: 'green',
|
||||
surface: 'viva',
|
||||
};
|
||||
}
|
||||
|
||||
private saveAppState(state: AppState): void {
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
localStorage.setItem(this.STORAGE_KEY, JSON.stringify(state));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject} from 'rxjs';
|
||||
import {LogNotification} from '../model/log-notification.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class EventService {
|
||||
private latestEventSubject = new BehaviorSubject<LogNotification>({message: 'No recent notifications...'});
|
||||
latestEvent$ = this.latestEventSubject.asObservable();
|
||||
|
||||
private eventHighlightSubject = new BehaviorSubject<boolean>(false);
|
||||
eventHighlight$ = this.eventHighlightSubject.asObservable();
|
||||
|
||||
private eventTimeout: any;
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
handleIncomingLog(logNotification: LogNotification): void {
|
||||
this.latestEventSubject.next(logNotification);
|
||||
this.eventHighlightSubject.next(true);
|
||||
|
||||
if (this.eventTimeout) {
|
||||
clearTimeout(this.eventTimeout);
|
||||
}
|
||||
|
||||
this.eventTimeout = setTimeout(() => {
|
||||
this.eventHighlightSubject.next(false);
|
||||
}, 5000);
|
||||
|
||||
setTimeout(() => {
|
||||
if (!this.eventHighlightSubject.value) {
|
||||
this.latestEventSubject.next({message: 'No recent notifications...'});
|
||||
}
|
||||
}, 12000);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class FileUploadService {
|
||||
|
||||
private uploadUrl = 'http://localhost:8080/api/v1/files/upload';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
uploadFile(file: File, libraryId: string, filePath: string): Observable<any> {
|
||||
const formData: FormData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('libraryId', libraryId);
|
||||
formData.append('filePath', filePath);
|
||||
return this.http.post(this.uploadUrl, formData).pipe(
|
||||
catchError((error) => {
|
||||
throw error;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import {LibraryService} from './library.service';
|
||||
import {ShelfService} from './shelf.service';
|
||||
import {Library} from '../model/library.model';
|
||||
import {Shelf} from '../model/shelf.model';
|
||||
import {MetadataService} from './metadata.service';
|
||||
import {MetadataProvider} from '../model/provider.model';
|
||||
import {MetadataService} from '../../metadata/metadata.service';
|
||||
import {MetadataProvider} from '../../metadata/model/provider.model';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {MetadataFetchOptionsComponent} from '../../metadata/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
|
||||
import {MetadataRefreshType} from '../../metadata/model/request/metadata-refresh-type.enum';
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from "rxjs";
|
||||
import {FetchMetadataRequest} from "../../metadata/model/request/fetch-metadata-request.model";
|
||||
import {BookMetadata, FetchedMetadata} from "../model/book.model";
|
||||
import {BookMetadataBI} from "../model/book-metadata-for-book-info.model";
|
||||
import {tap} from "rxjs/operators";
|
||||
import {BookService} from "./book.service";
|
||||
import {MetadataRefreshRequest} from '../../metadata/model/request/metadata-refresh-request.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MetadataService {
|
||||
|
||||
private readonly url = 'http://localhost:8080/v1/metadata';
|
||||
|
||||
constructor(private http: HttpClient, private bookService: BookService) {
|
||||
}
|
||||
|
||||
fetchBookMetadata(bookId: number, request: FetchMetadataRequest): Observable<FetchedMetadata[]> {
|
||||
return this.http.post<FetchedMetadata[]>(`${this.url}/${bookId}`, request);
|
||||
}
|
||||
|
||||
updateBookMetadata(bookId: number, bookMetadata: BookMetadataBI): Observable<BookMetadata> {
|
||||
return this.http.put<BookMetadata>(`${this.url}/${bookId}`, bookMetadata).pipe(
|
||||
tap(updatedMetadata => {
|
||||
this.bookService.handleBookMetadataUpdate(bookId, updatedMetadata);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
autoRefreshMetadata(metadataRefreshRequest: MetadataRefreshRequest) {
|
||||
return this.http.put<void>(`${this.url}/refreshV2`, metadataRefreshRequest);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import { RxStompService } from './rx-stomp.service';
|
||||
import { rxStompConfig } from './rx-stomp.config';
|
||||
|
||||
export function rxStompServiceFactory() {
|
||||
const rxStomp = new RxStompService();
|
||||
rxStomp.configure(rxStompConfig);
|
||||
rxStomp.activate();
|
||||
return rxStomp;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
import { RxStompConfig } from '@stomp/rx-stomp';
|
||||
|
||||
export const rxStompConfig: RxStompConfig = {
|
||||
// Which server?
|
||||
brokerURL: 'ws://localhost:8080/ws',
|
||||
|
||||
// Headers
|
||||
// Typical keys: login, passcode, host
|
||||
connectHeaders: {
|
||||
login: 'guest',
|
||||
passcode: 'guest',
|
||||
},
|
||||
|
||||
// How often to heartbeat?
|
||||
// Interval in milliseconds, set to 0 to disable
|
||||
heartbeatIncoming: 0, // Typical value 0 - disabled
|
||||
heartbeatOutgoing: 20000, // Typical value 20000 - every 20 seconds
|
||||
|
||||
// Wait in milliseconds before attempting auto reconnect
|
||||
// Set to 0 to disable
|
||||
// Typical value 500 (500 milli seconds)
|
||||
reconnectDelay: 200,
|
||||
|
||||
// Will log diagnostics on console
|
||||
// It can be quite verbose, not recommended in production
|
||||
// Skip this key to stop logging to console
|
||||
debug: (msg: string): void => {
|
||||
//console.log(new Date(), msg);
|
||||
},
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RxStomp } from '@stomp/rx-stomp';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RxStompService extends RxStomp {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {MessageService} from 'primeng/api';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ToastService {
|
||||
|
||||
constructor(private messageService: MessageService) {}
|
||||
|
||||
showSuccess(summary: string, detail: string) {
|
||||
this.messageService.add({ severity: 'success', summary, detail });
|
||||
}
|
||||
|
||||
showError(summary: string, detail: string) {
|
||||
this.messageService.add({ severity: 'error', summary, detail });
|
||||
}
|
||||
|
||||
showInfo(summary: string, detail: string) {
|
||||
this.messageService.add({ severity: 'info', summary, detail });
|
||||
}
|
||||
|
||||
showWarning(summary: string, detail: string) {
|
||||
this.messageService.add({ severity: 'warn', summary, detail });
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UtilityService {
|
||||
|
||||
private pathUrl = 'http://localhost:8080/v1/path';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
getFolders(path: string): Observable<string[]> {
|
||||
const params = new HttpParams().set('path', path);
|
||||
return this.http.get<string[]>(this.pathUrl, { params });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user