Add enable/disable management for book tools (characters, worlds, and locations)
- Introduced toggling functionality for managing `characters`, `worlds`, and `locations` tool availability per book. - Updated `CharacterComponent`, `WorldSetting`, and `LocationComponent` with toggle switches for tool enablement. - Added `book_tools` database table and related schema migration for storing tool settings. - Extended API calls, models, and IPC handlers to support tool enablement states. - Localized new strings for English with supporting descriptions and messages. - Adjusted conditional rendering logic across components to respect tool enablement.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import System from '../System.js';
|
||||
import { getUserEncryptionKey } from '../keyManager.js';
|
||||
import BookRepo, { BookQuery, EritBooksTable } from "../repositories/book.repository.js";
|
||||
import BookRepo, { BookQuery, BookToolsTable, BookToolsSettings, EritBooksTable } from "../repositories/book.repository.js";
|
||||
import { BookActSummariesTable } from "../repositories/act.repository.js";
|
||||
import { BookAIGuideLineTable, BookGuideLineTable } from "../repositories/guideline.repository.js";
|
||||
import ChapterRepo, {
|
||||
@@ -34,6 +34,12 @@ import { SyncedAIGuideLine, SyncedGuideLine } from "./GuideLine.js";
|
||||
import Cover from "./Cover.js";
|
||||
import UserRepo from "../repositories/user.repository.js";
|
||||
|
||||
export interface SyncedBookTools {
|
||||
charactersEnabled: boolean;
|
||||
worldsEnabled: boolean;
|
||||
locationsEnabled: boolean;
|
||||
}
|
||||
|
||||
export interface BookProps {
|
||||
id: string;
|
||||
type: string;
|
||||
@@ -47,6 +53,7 @@ export interface BookProps {
|
||||
wordCount?: number;
|
||||
coverImage?: string;
|
||||
bookMeta?: string;
|
||||
tools?: BookToolsSettings;
|
||||
}
|
||||
|
||||
export interface CompleteBook {
|
||||
@@ -67,6 +74,7 @@ export interface CompleteBook {
|
||||
worldElements: BookWorldElementsTable[];
|
||||
locationElements: LocationElementTable[];
|
||||
locationSubElements: LocationSubElementTable[];
|
||||
bookTools: BookToolsTable[];
|
||||
}
|
||||
|
||||
export interface SyncedBook {
|
||||
@@ -85,6 +93,7 @@ export interface SyncedBook {
|
||||
actSummaries: SyncedActSummary[];
|
||||
guideLine: SyncedGuideLine | null;
|
||||
aiGuideLine: SyncedAIGuideLine | null;
|
||||
bookTools: SyncedBookTools | null;
|
||||
}
|
||||
|
||||
export interface BookSyncCompare {
|
||||
@@ -105,6 +114,7 @@ export interface BookSyncCompare {
|
||||
actSummaries: string[];
|
||||
guideLine: boolean;
|
||||
aiGuideLine: boolean;
|
||||
bookTools: boolean;
|
||||
}
|
||||
|
||||
export interface CompleteBookData {
|
||||
@@ -242,6 +252,7 @@ export default class Book {
|
||||
public static async getBook(userId: string, bookId: string, lang: 'fr' | 'en'): Promise<BookProps> {
|
||||
const book: Book = new Book(bookId);
|
||||
book.getBookInfos(userId);
|
||||
const bookTools: BookToolsTable | null = BookRepo.fetchBookTools(userId, bookId, lang);
|
||||
return {
|
||||
id: book.getId(),
|
||||
type: book.getType(),
|
||||
@@ -253,7 +264,12 @@ export default class Book {
|
||||
desiredReleaseDate: book.getDesiredReleaseDate(),
|
||||
desiredWordCount: book.getDesiredWordCount(),
|
||||
wordCount: book.getWordCount(),
|
||||
coverImage: book.getCover()
|
||||
coverImage: book.getCover(),
|
||||
tools: {
|
||||
characters: bookTools ? bookTools.characters_enabled === 1 : false,
|
||||
worlds: bookTools ? bookTools.worlds_enabled === 1 : false,
|
||||
locations: bookTools ? bookTools.locations_enabled === 1 : false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -290,6 +306,11 @@ export default class Book {
|
||||
return BookRepo.deleteBook(userId, bookId, lang);
|
||||
}
|
||||
|
||||
public static updateBookToolSetting(userId: string, bookId: string, toolName: 'characters' | 'worlds' | 'locations', enabled: boolean, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
const columnName: 'characters_enabled' | 'worlds_enabled' | 'locations_enabled' = `${toolName}_enabled` as 'characters_enabled' | 'worlds_enabled' | 'locations_enabled';
|
||||
return BookRepo.updateBookToolSetting(userId, bookId, columnName, enabled, lang);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the book ID.
|
||||
* @returns The book's unique identifier
|
||||
|
||||
Reference in New Issue
Block a user