Documentation Viewer
+ +OPAT File Inspector
diff --git a/electron/renderer-refactored.js b/electron/renderer-refactored.js index 4f5d1df..70898a2 100644 --- a/electron/renderer-refactored.js +++ b/electron/renderer-refactored.js @@ -17,6 +17,7 @@ const eventHandlers = require('./renderer/event-handlers'); const opatHandler = require('./renderer/opat-handler'); const fillWorkflow = require('./renderer/fill-workflow'); const opatPlotting = require('./renderer/opat-plotting'); +const docsHandler = require('./renderer/docs-handler'); // Initialize all modules with their dependencies function initializeModules() { @@ -31,7 +32,8 @@ function initializeModules() { eventHandlers, opatHandler, fillWorkflow, - opatPlotting + opatPlotting, + docsHandler }; // Initialize each module with its dependencies @@ -44,6 +46,10 @@ function initializeModules() { fillWorkflow.initializeDependencies(deps); opatPlotting.initializePlottingDependencies(deps); + // Initialize documentation handler + const docsHandlerInstance = new docsHandler(domManager, stateManager); + docsHandlerInstance.initialize(); + console.log('[RENDERER] All modules initialized with dependencies'); } diff --git a/electron/renderer/docs-handler.js b/electron/renderer/docs-handler.js new file mode 100644 index 0000000..ad21b64 --- /dev/null +++ b/electron/renderer/docs-handler.js @@ -0,0 +1,370 @@ +/** + * Documentation Handler Module + * Manages documentation viewing functionality for the 4DSTAR Electron app + */ + +class DocsHandler { + constructor(domManager, stateManager) { + this.domManager = domManager; + this.stateManager = stateManager; + this.docsConfig = null; + this.currentDoc = null; + this.filteredDocs = []; + + console.log('[DOCS_HANDLER] Documentation handler initialized'); + } + + /** + * Initialize the documentation handler + */ + async initialize() { + try { + await this.loadDocsConfig(); + this.setupEventListeners(); + this.populateDocsGrid(); + this.populateDocsList(); + console.log('[DOCS_HANDLER] Documentation handler ready'); + } catch (error) { + console.error('[DOCS_HANDLER] Failed to initialize:', error); + } + } + + /** + * Load documentation configuration from docs.json + */ + async loadDocsConfig() { + try { + const response = await fetch('./docs.json'); + if (!response.ok) { + throw new Error(`Failed to load docs.json: ${response.status}`); + } + this.docsConfig = await response.json(); + console.log('[DOCS_HANDLER] Loaded documentation config:', Object.keys(this.docsConfig)); + } catch (error) { + console.error('[DOCS_HANDLER] Error loading docs config:', error); + // Fallback to empty config + this.docsConfig = {}; + } + } + + /** + * Setup event listeners for documentation interface + */ + setupEventListeners() { + // Search functionality + const searchInput = document.getElementById('docs-search'); + if (searchInput) { + searchInput.addEventListener('input', (e) => { + this.filterDocs(e.target.value); + }); + } + + // Category filter + const categoryFilter = document.getElementById('docs-category-filter'); + if (categoryFilter) { + categoryFilter.addEventListener('change', (e) => { + this.filterDocsByCategory(e.target.value); + }); + } + + // Documentation viewer controls + const backBtn = document.getElementById('docs-back-btn'); + if (backBtn) { + backBtn.addEventListener('click', () => { + this.showDocsHome(); + }); + } + + const externalBtn = document.getElementById('docs-open-external-btn'); + if (externalBtn) { + externalBtn.addEventListener('click', () => { + this.openExternalDoc(); + }); + } + + const githubBtn = document.getElementById('docs-github-btn'); + if (githubBtn) { + githubBtn.addEventListener('click', () => { + this.openGitHub(); + }); + } + } + + /** + * Populate the documentation grid on the home screen + */ + populateDocsGrid() { + const docsGrid = document.getElementById('docs-grid'); + if (!docsGrid || !this.docsConfig) return; + + docsGrid.innerHTML = ''; + + Object.entries(this.docsConfig).forEach(([key, doc]) => { + const card = this.createDocCard(key, doc); + docsGrid.appendChild(card); + }); + } + + /** + * Populate the documentation list in the sidebar + */ + populateDocsList() { + const docsList = document.getElementById('docs-list'); + if (!docsList || !this.docsConfig) return; + + this.filteredDocs = Object.entries(this.docsConfig); + this.renderDocsList(); + } + + /** + * Create a documentation card for the grid + */ + createDocCard(key, doc) { + const card = document.createElement('div'); + card.className = 'docs-card'; + card.dataset.docKey = key; + + card.innerHTML = ` +${doc.name}
+${doc.desc}
+ + `; + + card.addEventListener('click', () => { + this.openDocumentation(key, doc); + }); + + return card; + } + + /** + * Create a documentation item for the sidebar list + */ + createDocItem(key, doc) { + const item = document.createElement('div'); + item.className = 'docs-item'; + item.dataset.docKey = key; + + item.innerHTML = ` +