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
|
||||
|
||||
@@ -3,6 +3,7 @@ import CharacterRepo, {
|
||||
CharacterResult,
|
||||
CompleteCharacterResult
|
||||
} from "../repositories/character.repository.js";
|
||||
import BookRepo, {BookToolsTable} from "../repositories/book.repository.js";
|
||||
import System from "../System.js";
|
||||
import {getUserEncryptionKey} from "../keyManager.js";
|
||||
|
||||
@@ -41,6 +42,11 @@ export interface CharacterProps {
|
||||
history: string;
|
||||
}
|
||||
|
||||
export interface CharacterListResponse {
|
||||
characters: CharacterProps[];
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export interface CompleteCharacterProps {
|
||||
id?: string;
|
||||
name: string;
|
||||
@@ -87,11 +93,15 @@ export default class Character {
|
||||
* @param lang - The language code for localization (defaults to 'fr')
|
||||
* @returns An array of decrypted character properties
|
||||
*/
|
||||
public static getCharacterList(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): CharacterProps[] {
|
||||
public static getCharacterList(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): CharacterListResponse {
|
||||
const bookTools: BookToolsTable | null = BookRepo.fetchBookTools(userId, bookId, lang);
|
||||
const enabled: boolean = bookTools ? bookTools.characters_enabled === 1 : false;
|
||||
|
||||
const userEncryptionKey: string = getUserEncryptionKey(userId);
|
||||
const encryptedCharacters: CharacterResult[] = CharacterRepo.fetchCharacters(userId, bookId, lang);
|
||||
if (!encryptedCharacters) return [];
|
||||
if (encryptedCharacters.length === 0) return [];
|
||||
if (!encryptedCharacters || encryptedCharacters.length === 0) {
|
||||
return { characters: [], enabled };
|
||||
}
|
||||
const decryptedCharacterList: CharacterProps[] = [];
|
||||
for (const encryptedCharacter of encryptedCharacters) {
|
||||
decryptedCharacterList.push({
|
||||
@@ -106,7 +116,7 @@ export default class Character {
|
||||
history: encryptedCharacter.history ? System.decryptDataWithUserKey(encryptedCharacter.history, userEncryptionKey) : '',
|
||||
})
|
||||
}
|
||||
return decryptedCharacterList;
|
||||
return { characters: decryptedCharacterList, enabled };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -358,4 +368,5 @@ export default class Character {
|
||||
}).join('\n\n');
|
||||
return formattedCharactersDescription;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {getUserEncryptionKey} from "../keyManager.js";
|
||||
import System from "../System.js";
|
||||
import {CompleteBook} from "./Book.js";
|
||||
import BookRepo, {EritBooksTable} from "../repositories/book.repository.js";
|
||||
import BookRepo, {EritBooksTable, BookToolsTable} from "../repositories/book.repository.js";
|
||||
import ChapterRepo, {
|
||||
BookChapterInfosTable,
|
||||
BookChaptersTable
|
||||
@@ -192,9 +192,14 @@ export default class Download {
|
||||
});
|
||||
if (!guidelinesInserted) return false;
|
||||
|
||||
return data.issues.every((issue: BookIssuesTable): boolean => {
|
||||
const issuesInserted: boolean = data.issues.every((issue: BookIssuesTable): boolean => {
|
||||
const encryptedIssueName: string = System.encryptDataWithUserKey(issue.name, userEncryptionKey);
|
||||
return IssueRepository.insertSyncIssue(issue.issue_id, userId, issue.book_id, encryptedIssueName, issue.hashed_issue_name, issue.last_update, lang);
|
||||
});
|
||||
if (!issuesInserted) return false;
|
||||
|
||||
return data.bookTools.every((bookTool: BookToolsTable): boolean => {
|
||||
return BookRepo.insertSyncBookTools(bookTool.book_id, userId, bookTool.characters_enabled, bookTool.worlds_enabled, bookTool.locations_enabled, lang);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import LocationRepo, {
|
||||
} from "../repositories/location.repository.js";
|
||||
import System from "../System.js";
|
||||
import {getUserEncryptionKey} from "../keyManager.js";
|
||||
import BookRepo, {BookToolsTable} from "../repositories/book.repository.js";
|
||||
|
||||
export interface SubElement {
|
||||
id: string;
|
||||
@@ -25,6 +26,11 @@ export interface LocationProps {
|
||||
elements: Element[];
|
||||
}
|
||||
|
||||
export interface LocationListResponse {
|
||||
locations: LocationProps[];
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export interface SyncedLocation {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -51,11 +57,16 @@ export default class Location {
|
||||
* @param userId - The user's unique identifier.
|
||||
* @param bookId - The book's unique identifier.
|
||||
* @param lang - The language for error messages ('fr' or 'en'). Defaults to 'fr'.
|
||||
* @returns An array of location properties with their elements and sub-elements.
|
||||
* @returns LocationListResponse containing an array of locations and enabled flag.
|
||||
*/
|
||||
static getAllLocations(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): LocationProps[] {
|
||||
static getAllLocations(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): LocationListResponse {
|
||||
const bookTools: BookToolsTable | null = BookRepo.fetchBookTools(userId, bookId, lang);
|
||||
const enabled: boolean = bookTools ? bookTools.locations_enabled === 1 : false;
|
||||
|
||||
const locationRecords: LocationQueryResult[] = LocationRepo.getLocation(userId, bookId, lang);
|
||||
if (!locationRecords || locationRecords.length === 0) return [];
|
||||
if (!locationRecords || locationRecords.length === 0) {
|
||||
return { locations: [], enabled };
|
||||
}
|
||||
const userKey: string = getUserEncryptionKey(userId);
|
||||
|
||||
const locationArray: LocationProps[] = [];
|
||||
@@ -104,7 +115,7 @@ export default class Location {
|
||||
}
|
||||
}
|
||||
}
|
||||
return locationArray;
|
||||
return { locations: locationArray, enabled };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -325,4 +336,5 @@ export default class Location {
|
||||
return descriptionFields.join('\n');
|
||||
}).join('\n\n');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getUserEncryptionKey } from "../keyManager.js";
|
||||
import System from "../System.js";
|
||||
import { BookSyncCompare, CompleteBook, SyncedBook } from "./Book.js";
|
||||
import BookRepo, { EritBooksTable, SyncedBookResult } from "../repositories/book.repository.js";
|
||||
import { BookSyncCompare, CompleteBook, SyncedBook, SyncedBookTools } from "./Book.js";
|
||||
import BookRepo, { EritBooksTable, SyncedBookResult, BookToolsTable } from "../repositories/book.repository.js";
|
||||
import ChapterRepo, {
|
||||
BookChapterInfosTable,
|
||||
BookChaptersTable,
|
||||
@@ -350,6 +350,9 @@ export default class Sync {
|
||||
});
|
||||
}
|
||||
|
||||
const bookToolsResult: BookToolsTable | null = BookRepo.fetchBookTools(userId, syncCompareData.id, lang);
|
||||
const bookTools: BookToolsTable[] = bookToolsResult ? [bookToolsResult] : [];
|
||||
|
||||
return {
|
||||
eritBooks: decryptedBooks,
|
||||
chapters: decryptedChapters,
|
||||
@@ -367,7 +370,8 @@ export default class Sync {
|
||||
actSummaries: decryptedActSummaries,
|
||||
guideLine: decryptedGuideLines,
|
||||
aiGuideLine: decryptedAIGuideLines,
|
||||
issues: decryptedIssues
|
||||
issues: decryptedIssues,
|
||||
bookTools: bookTools
|
||||
};
|
||||
}
|
||||
|
||||
@@ -724,6 +728,23 @@ export default class Sync {
|
||||
}
|
||||
}
|
||||
|
||||
const serverBookTools: BookToolsTable[] = completeBook.bookTools;
|
||||
if (serverBookTools && serverBookTools.length > 0) {
|
||||
for (const serverBookTool of serverBookTools) {
|
||||
const bookToolsExists: BookToolsTable | null = BookRepo.fetchBookTools(userId, bookId, lang);
|
||||
if (bookToolsExists) {
|
||||
BookRepo.updateBookToolSetting(userId, bookId, 'characters_enabled', serverBookTool.characters_enabled === 1, lang);
|
||||
BookRepo.updateBookToolSetting(userId, bookId, 'worlds_enabled', serverBookTool.worlds_enabled === 1, lang);
|
||||
BookRepo.updateBookToolSetting(userId, bookId, 'locations_enabled', serverBookTool.locations_enabled === 1, lang);
|
||||
} else {
|
||||
const insertSuccessful: boolean = BookRepo.insertSyncBookTools(bookId, userId, serverBookTool.characters_enabled, serverBookTool.worlds_enabled, serverBookTool.locations_enabled, lang);
|
||||
if (!insertSuccessful) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -940,6 +961,13 @@ export default class Sync {
|
||||
lastUpdate: aiGuidelineRecord.last_update
|
||||
} : null;
|
||||
|
||||
const bookToolsRecord: BookToolsTable | null = BookRepo.fetchBookTools(userId, currentBookId, lang);
|
||||
const bookTools: SyncedBookTools | null = bookToolsRecord ? {
|
||||
charactersEnabled: bookToolsRecord.characters_enabled === 1,
|
||||
worldsEnabled: bookToolsRecord.worlds_enabled === 1,
|
||||
locationsEnabled: bookToolsRecord.locations_enabled === 1
|
||||
} : null;
|
||||
|
||||
return {
|
||||
id: currentBookId,
|
||||
type: bookRecord.type,
|
||||
@@ -955,7 +983,8 @@ export default class Sync {
|
||||
issues: bookIssues,
|
||||
actSummaries: bookActSummaries,
|
||||
guideLine: bookGuideLine,
|
||||
aiGuideLine: bookAIGuideLine
|
||||
aiGuideLine: bookAIGuideLine,
|
||||
bookTools: bookTools
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getUserEncryptionKey } from "../keyManager.js";
|
||||
import System from "../System.js";
|
||||
import { CompleteBook } from "./Book.js";
|
||||
import BookRepo, { EritBooksTable } from "../repositories/book.repository.js";
|
||||
import BookRepo, { EritBooksTable, BookToolsTable } from "../repositories/book.repository.js";
|
||||
import ActRepository, { BookActSummariesTable } from "../repositories/act.repository.js";
|
||||
import GuidelineRepo, { BookAIGuideLineTable, BookGuideLineTable } from "../repositories/guideline.repository.js";
|
||||
import ChapterRepo, {
|
||||
@@ -51,7 +51,8 @@ export default class Upload {
|
||||
encryptedIssues,
|
||||
encryptedLocations,
|
||||
encryptedPlotPoints,
|
||||
encryptedWorlds
|
||||
encryptedWorlds,
|
||||
bookToolsData
|
||||
]: [
|
||||
EritBooksTable[],
|
||||
BookActSummariesTable[],
|
||||
@@ -63,7 +64,8 @@ export default class Upload {
|
||||
BookIssuesTable[],
|
||||
BookLocationTable[],
|
||||
BookPlotPointsTable[],
|
||||
BookWorldTable[]
|
||||
BookWorldTable[],
|
||||
BookToolsTable | null
|
||||
] = await Promise.all([
|
||||
BookRepo.fetchEritBooksTable(userId, bookId, lang),
|
||||
ActRepository.fetchBookActSummaries(userId, bookId, lang),
|
||||
@@ -75,7 +77,8 @@ export default class Upload {
|
||||
IssueRepository.fetchBookIssues(userId, bookId, lang),
|
||||
LocationRepo.fetchBookLocations(userId, bookId, lang),
|
||||
PlotPointRepository.fetchBookPlotPoints(userId, bookId, lang),
|
||||
WorldRepository.fetchBookWorlds(userId, bookId, lang)
|
||||
WorldRepository.fetchBookWorlds(userId, bookId, lang),
|
||||
BookRepo.fetchBookTools(userId, bookId, lang)
|
||||
]);
|
||||
|
||||
const [
|
||||
@@ -234,6 +237,8 @@ export default class Upload {
|
||||
sub_elem_description: locationSubElement.sub_elem_description ? System.decryptDataWithUserKey(locationSubElement.sub_elem_description, userEncryptionKey) : null
|
||||
}));
|
||||
|
||||
const bookTools: BookToolsTable[] = bookToolsData ? [bookToolsData] : [];
|
||||
|
||||
return {
|
||||
eritBooks,
|
||||
actSummaries,
|
||||
@@ -251,7 +256,8 @@ export default class Upload {
|
||||
worlds,
|
||||
worldElements,
|
||||
locationElements,
|
||||
locationSubElements
|
||||
locationSubElements,
|
||||
bookTools
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { getUserEncryptionKey } from "../keyManager.js";
|
||||
import System from "../System.js";
|
||||
import WorldRepository, { WorldElementValue, WorldQuery } from "../repositories/world.repository.js";
|
||||
import BookRepo, {BookToolsTable} from "../repositories/book.repository.js";
|
||||
|
||||
export interface SyncedWorld {
|
||||
id: string;
|
||||
@@ -44,6 +45,11 @@ export interface WorldProps {
|
||||
importantCharacters: WorldElement[];
|
||||
}
|
||||
|
||||
export interface WorldListResponse {
|
||||
worlds: WorldProps[];
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapping of element type keys to their corresponding numeric type identifiers.
|
||||
*/
|
||||
@@ -107,9 +113,12 @@ export default class World {
|
||||
* @param userId - The unique identifier of the user
|
||||
* @param bookId - The unique identifier of the book
|
||||
* @param lang - The language for error messages ('fr' or 'en'), defaults to 'fr'
|
||||
* @returns An array of WorldProps objects containing all world data and their elements
|
||||
* @returns WorldListResponse containing an array of WorldProps and enabled flag
|
||||
*/
|
||||
public static getWorlds(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): WorldProps[] {
|
||||
public static getWorlds(userId: string, bookId: string, lang: 'fr' | 'en' = 'fr'): WorldListResponse {
|
||||
const bookTools: BookToolsTable | null = BookRepo.fetchBookTools(userId, bookId, lang);
|
||||
const enabled: boolean = bookTools ? bookTools.worlds_enabled === 1 : false;
|
||||
|
||||
const worldQueryResults: WorldQuery[] = WorldRepository.fetchWorlds(userId, bookId, lang);
|
||||
const userEncryptionKey: string = getUserEncryptionKey(userId);
|
||||
const worlds: WorldProps[] = [];
|
||||
@@ -167,7 +176,7 @@ export default class World {
|
||||
}
|
||||
}
|
||||
}
|
||||
return worlds;
|
||||
return { worlds, enabled };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,4 +274,5 @@ export default class World {
|
||||
public static removeElementFromWorld(userId: string, elementId: string, lang: 'fr' | 'en' = 'fr'): boolean {
|
||||
return WorldRepository.deleteElement(userId, elementId, lang);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user