@@ -70,7 +70,7 @@ tags: tagC"
7070
7171<script lang="ts">
7272import { defineComponent , PropType } from ' vue' ;
73- import { CourseConfig , DataShape , Status } from ' @vue-skuilder/common' ;
73+ import { CourseConfig , DataShape , Status , NameSpacer } from ' @vue-skuilder/common' ;
7474import { BlanksCardDataShapes } from ' @vue-skuilder/courses' ;
7575import { getCurrentUser } from ' @vue-skuilder/common-ui' ;
7676import { getDataLayer , CourseDBInterface } from ' @vue-skuilder/db' ;
@@ -107,6 +107,15 @@ export default defineComponent({
107107 created() {
108108 if (this .courseCfg ?.courseID ) {
109109 this .courseDB = getDataLayer ().getCourseDB (this .courseCfg .courseID );
110+
111+ // Validate that we have datashapes in the course config
112+ if (! this .courseCfg .dataShapes || this .courseCfg .dataShapes .length === 0 ) {
113+ console .error (' [BulkImportView] Course config does not contain any dataShapes.' );
114+ alertUser ({
115+ text: ' Course configuration has no dataShapes. Bulk import may not work correctly.' ,
116+ status: Status .warning ,
117+ });
118+ }
110119 } else {
111120 console .error (' [BulkImportView] Course config or Course ID is missing.' );
112121 alertUser ({
@@ -157,13 +166,25 @@ export default defineComponent({
157166 }
158167 if (! this .bulkText .trim ()) return ;
159168
169+ // Validate that we have datashapes in the course config
170+ if (! this .courseCfg ?.dataShapes || this .courseCfg .dataShapes .length === 0 ) {
171+ alertUser ({
172+ text: ' This course has no data shapes configured. Cannot import cards.' ,
173+ status: Status .error ,
174+ });
175+ this .processing = false ;
176+ return ;
177+ }
178+
160179 this .processing = true ;
161180 this .results = [];
162181
163182 const cardDelimiter = ' \n ---\n ---\n ' ;
164183 const cardStrings = this .bulkText .split (cardDelimiter );
165184 const currentUser = await getCurrentUser ();
166185 const userName = currentUser .getUsername ();
186+
187+ // Use the BlanksCardDataShapes for the data structure
167188 const dataShapeToUse: DataShape = BlanksCardDataShapes [0 ];
168189
169190 if (! dataShapeToUse ) {
@@ -176,6 +197,14 @@ export default defineComponent({
176197 return ;
177198 }
178199
200+ // Log the course configuration to help with debugging
201+ console .log (' [BulkImportView] Processing with course config:' , {
202+ courseID: this .courseCfg .courseID ,
203+ dataShapes: this .courseCfg .dataShapes ,
204+ questionTypes: this .courseCfg .questionTypes ,
205+ dataShapeToUse: dataShapeToUse .name ,
206+ });
207+
179208 for (const cardString of cardStrings ) {
180209 const originalText = cardString .trim ();
181210 if (! originalText ) continue ;
@@ -201,8 +230,17 @@ export default defineComponent({
201230 };
202231
203232 try {
233+ // Extract course code from first dataShape in course config
234+ const configDataShape = this .courseCfg ?.dataShapes ?.[0 ];
235+ if (! configDataShape ) {
236+ throw new Error (' No data shapes found in course configuration' );
237+ }
238+
239+ const codeCourse = NameSpacer .getDataShapeDescriptor (configDataShape .name ).course ;
240+ console .log (` [BulkImportView] Using codeCourse: ${codeCourse } for note addition ` );
241+
204242 const result = await this .courseDB .addNote (
205- ' default ' ,
243+ codeCourse ,
206244 dataShapeToUse ,
207245 cardData ,
208246 userName ,
@@ -216,7 +254,7 @@ export default defineComponent({
216254 originalText ,
217255 status: ' success' ,
218256 message: ' Card added successfully.' ,
219- cardId: ' (unknown)' ,
257+ cardId: result . id ? result . id : ' (unknown)' ,
220258 });
221259 } else {
222260 this .results .push ({
@@ -230,7 +268,7 @@ export default defineComponent({
230268 this .results .push ({
231269 originalText ,
232270 status: ' error' ,
233- message: ` Error adding card: ${( error as any ) .message || ' Unknown error' } ` ,
271+ message: ` Error adding card: ${error instanceof Error ? error .message : ' Unknown error' } ` ,
234272 });
235273 }
236274 }
0 commit comments