Skip to content

Commit 51d4b8d

Browse files
committed
register blanksCards automatically
1 parent bdb9988 commit 51d4b8d

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

packages/studio-ui/src/main.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,34 @@ const vuetify = createVuetify({
136136
}
137137
}
138138

139+
// Register BlanksCard (markdown fillIn) by default for all studio sessions
140+
console.log('🎨 Studio Mode: Registering default BlanksCard question type');
141+
try {
142+
const { getDataLayer } = await import('@vue-skuilder/db');
143+
const courseDB = getDataLayer().getCourseDB(studioConfig.database.name);
144+
const courseConfig = await courseDB.getCourseConfig();
145+
146+
const { BlanksCard, BlanksCardDataShapes } = await import('@vue-skuilder/courseware');
147+
const { registerBlanksCard } = await import('./utils/courseConfigRegistration');
148+
149+
const blanksRegistrationResult = await registerBlanksCard(
150+
BlanksCard,
151+
BlanksCardDataShapes,
152+
courseConfig,
153+
courseDB
154+
);
155+
156+
if (blanksRegistrationResult.success) {
157+
console.log(' ✅ BlanksCard question type registered successfully');
158+
} else {
159+
console.warn(` ⚠️ BlanksCard registration failed: ${blanksRegistrationResult.errorMessage}`);
160+
}
161+
} catch (blanksError) {
162+
console.warn(
163+
` ⚠️ Failed to register BlanksCard: ${blanksError instanceof Error ? blanksError.message : String(blanksError)}`
164+
);
165+
}
166+
139167
// Build custom courseware registry
140168
const { allCourseWare, AllCourseWare } = await import('@vue-skuilder/courseware');
141169
const studioCourseWare = customQuestions

packages/studio-ui/src/utils/courseConfigRegistration.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,68 @@ export async function registerSeedData(
237237
}
238238
}
239239

240+
/**
241+
* Register BlanksCard (markdown fillIn) question type specifically
242+
*/
243+
export async function registerBlanksCard(
244+
BlanksCard: any,
245+
BlanksCardDataShapes: any[],
246+
courseConfig: CourseConfig,
247+
courseDB: CourseDBInterface
248+
): Promise<{ success: boolean; errorMessage?: string }> {
249+
try {
250+
console.log(' 📋 Registering BlanksCard data shapes and question type...');
251+
252+
let registeredCount = 0;
253+
const courseName = 'default'; // BlanksCard comes from the default course
254+
255+
// Register BlanksCard data shapes
256+
for (const dataShapeClass of BlanksCardDataShapes) {
257+
const processedDataShape: ProcessedDataShape = {
258+
name: dataShapeClass.name,
259+
course: courseName,
260+
dataShape: dataShapeClass,
261+
};
262+
263+
if (registerDataShape(processedDataShape, courseConfig)) {
264+
registeredCount++;
265+
}
266+
}
267+
268+
// Register BlanksCard question type
269+
const processedQuestion: ProcessedQuestionData = {
270+
name: BlanksCard.name,
271+
course: courseName,
272+
questionClass: BlanksCard,
273+
dataShapes: BlanksCardDataShapes,
274+
views: BlanksCard.views || [],
275+
};
276+
277+
if (registerQuestionType(processedQuestion, courseConfig)) {
278+
registeredCount++;
279+
}
280+
281+
// Update the course config in the database
282+
console.log(' 💾 Updating course configuration with BlanksCard...');
283+
const updateResult = await courseDB.updateCourseConfig(courseConfig);
284+
285+
if (!updateResult.ok) {
286+
throw new Error(`Failed to update course config: ${JSON.stringify(updateResult)}`);
287+
}
288+
289+
// Register seed data if BlanksCard has any
290+
await registerSeedData(processedQuestion, courseDB);
291+
292+
console.log(` ✅ BlanksCard registration complete: ${registeredCount} items registered`);
293+
294+
return { success: true };
295+
} catch (error) {
296+
const errorMessage = error instanceof Error ? error.message : String(error);
297+
console.error(` ❌ BlanksCard registration failed: ${errorMessage}`);
298+
return { success: false, errorMessage };
299+
}
300+
}
301+
240302
/**
241303
* Main function to register all custom question types and data shapes
242304
*/

0 commit comments

Comments
 (0)