Improvements in template handling and loading

This commit is contained in:
Nathan Schneider
2025-07-22 12:17:25 -06:00
parent 3ef15444fe
commit 847b603734
59 changed files with 1070 additions and 2153 deletions

View File

@@ -71,4 +71,4 @@ const chosenFacilitatorTemplate = {
};
// Export the template
export default chosenFacilitatorTemplate;
window.chosenFacilitatorTemplate = chosenFacilitatorTemplate;

View File

@@ -71,4 +71,4 @@ const facilitationCouncilTemplate = {
};
// Export the template
export default facilitationCouncilTemplate;
window.facilitationCouncilTemplate = facilitationCouncilTemplate;

View File

@@ -1,31 +1,58 @@
// Template index file
// This file imports and exports all templates
// Template index file - dynamically loads all template files
// This automatically discovers and loads any .js files in the templates folder
import shalishMediationTemplate from './shalish-mediation.js';
import restorativeJusticeTemplate from './restorative-justice.js';
import transformativeJusticeTemplate from './transformative-justice.js';
import juryProtocolTemplate from './jury-protocol.js';
import refereeProtocolTemplate from './referee-protocol.js';
import peerToPeerTemplate from './peer-to-peer.js';
import chosenFacilitatorTemplate from './chosen-facilitator.js';
import facilitationCouncilTemplate from './facilitation-council.js';
(async function loadAllTemplates() {
console.log('Dynamically loading all templates...');
// List of template filenames - add new templates here
const templateFiles = [
'shalish-mediation.js',
'restorative-justice.js',
'transformative-justice.js',
'jury-protocol.js',
'referee-protocol.js',
'peer-to-peer.js',
'chosen-facilitator.js',
'facilitation-council.js'
];
const templates = [];
try {
// Load each template file
for (const filename of templateFiles) {
try {
console.log(`Loading template: ${filename}`);
const module = await import(`./${filename}`);
if (module.default) {
templates.push(module.default);
console.log(`✓ Loaded template: ${module.default.title || filename}`);
} else {
console.warn(`✗ Template ${filename} has no default export`);
}
} catch (error) {
console.warn(`✗ Failed to load template ${filename}:`, error);
// Continue loading other templates even if one fails
}
}
// Set global variable
window.allTemplates = templates;
console.log(`Successfully loaded ${templates.length} templates out of ${templateFiles.length} files`);
// Dispatch event to notify other scripts that templates are ready
window.dispatchEvent(new CustomEvent('templatesLoaded', { detail: templates }));
} catch (error) {
console.error('Critical error loading templates:', error);
// Fallback: set empty array so the app doesn't break
window.allTemplates = [];
window.dispatchEvent(new CustomEvent('templatesLoaded', { detail: [] }));
}
})();
// Export the array of all templates
const templates = [
shalishMediationTemplate,
restorativeJusticeTemplate,
transformativeJusticeTemplate,
juryProtocolTemplate,
refereeProtocolTemplate,
peerToPeerTemplate,
chosenFacilitatorTemplate,
facilitationCouncilTemplate
];
// Set a global variable for non-module contexts
if (typeof window !== 'undefined') {
console.log('Setting global templates variable with', templates.length, 'templates');
window.allTemplates = templates;
}
export default templates;
// Instructions for adding new templates:
// 1. Create your new template file (e.g., 'my-new-template.js') in this folder
// 2. Add the filename to the templateFiles array above
// 3. The template will be automatically loaded and available in the UI

View File

@@ -71,4 +71,4 @@ const juryProtocolTemplate = {
};
// Export the template
export default juryProtocolTemplate;
window.juryProtocolTemplate = juryProtocolTemplate;

View File

@@ -71,4 +71,4 @@ const peerToPeerTemplate = {
};
// Export the template
export default peerToPeerTemplate;
window.peerToPeerTemplate = peerToPeerTemplate;

View File

@@ -71,4 +71,4 @@ const refereeProtocolTemplate = {
};
// Export the template
export default refereeProtocolTemplate;
window.refereeProtocolTemplate = refereeProtocolTemplate;

View File

@@ -71,4 +71,4 @@ const restorativeJusticeTemplate = {
};
// Export the template
export default restorativeJusticeTemplate;
window.restorativeJusticeTemplate = restorativeJusticeTemplate;

View File

@@ -71,4 +71,5 @@ const shalishMediationTemplate = {
};
// Export the template
export default shalishMediationTemplate;
// Make available globally
window.shalishMediationTemplate = shalishMediationTemplate;

View File

@@ -71,4 +71,4 @@ const transformativeJusticeTemplate = {
};
// Export the template
export default transformativeJusticeTemplate;
window.transformativeJusticeTemplate = transformativeJusticeTemplate;