@@ -7,6 +7,7 @@ import { ZButton } from '../ui/Buttons';
77import { data } from '@/data/faculty' ;
88import { fullCourseData } from '@/lib/type' ;
99import AlertModal from '../ui/AlertModal' ;
10+ import { course_type_map } from '@/lib/course_codes_map' ;
1011
1112const schools = [
1213 'SCOPE' ,
@@ -18,17 +19,18 @@ const schools = [
1819 'SENSE' ,
1920 'SCE' ,
2021 'SHINE' ,
21- 'MTech' ,
22+ 'MTech (SCOPE)' ,
23+ // 'MTech (SCORE)',
2224 'SCOPE (Fresher)' ,
2325 'SCORE (Fresher)' ,
2426 'SELECT (Fresher)' ,
2527 'SMEC (Fresher)' ,
26- 'SBST (Fresher)' ,
27- 'SCHEME (Fresher)' ,
28+ // 'SBST (Fresher)',
29+ // 'SCHEME (Fresher)',
2830 'SENSE (Fresher)' ,
29- 'SCE (Fresher)' ,
30- 'SHINE (Fresher)' ,
31- 'MTech (Fresher)' ,
31+ // 'SCE (Fresher)',
32+ // 'SHINE (Fresher)',
33+ // 'MTech (Fresher)',
3234] ;
3335
3436type SelectFieldProps = {
@@ -213,25 +215,33 @@ function generateCourseSlotsBoth({
213215 selectedSubject,
214216 selectedSlot,
215217 selectedFaculties,
218+ courseCodeType,
216219} : {
217220 data : FacultyData ;
218221 selectedSchool : string ;
219222 selectedDomain : string ;
220223 selectedSubject : string ;
221224 selectedSlot : string ;
222225 selectedFaculties : string [ ] ;
226+ courseCodeType : 'L' | 'P' | 'E' | undefined ;
223227} ) {
224228 const [ courseCode ] = selectedSubject . split ( ' - ' ) ;
225229 const baseCode = courseCode . slice ( 0 , - 1 ) ;
226230
227- const labEntryKey = Object . keys ( data [ selectedSchool ] [ selectedDomain ] ) . find ( key => {
228- const code = key . split ( ' - ' ) [ 0 ] ;
229- return code . slice ( 0 , - 1 ) === baseCode && ( code . endsWith ( 'P' ) || code . endsWith ( 'E' ) ) ;
230- } ) ;
231+ let labData : SubjectEntry [ ] = [ ] ;
231232
232- const labData : SubjectEntry [ ] = labEntryKey
233- ? data [ selectedSchool ] [ selectedDomain ] [ labEntryKey ]
234- : [ ] ;
233+ if ( courseCodeType === 'E' ) {
234+ labData = data [ selectedSchool ] [ selectedDomain ] [ selectedSubject ] ;
235+ } else {
236+ const labEntryKey = Object . keys ( data [ selectedSchool ] [ selectedDomain ] ) . find ( key => {
237+ const code = key . split ( ' - ' ) [ 0 ] ;
238+ const type = getCourseType ( code ) ;
239+ return code . slice ( 0 , - 1 ) === baseCode && ( type === 'P' || type === 'E' ) ;
240+ } ) ;
241+ if ( labEntryKey ) {
242+ labData = data [ selectedSchool ] [ selectedDomain ] [ labEntryKey ] ;
243+ }
244+ }
235245
236246 const isMorningTheory = selectedSlot . includes ( '1' ) ;
237247 const isEveningTheory = selectedSlot . includes ( '2' ) ;
@@ -259,7 +269,7 @@ function generateCourseSlotsBoth({
259269
260270 return {
261271 facultyName,
262- ... ( labSlots . length > 0 && { facultyLabSlot : labSlots . join ( ', ' ) } ) ,
272+ facultyLabSlot : labSlots . length > 0 ? labSlots . join ( ', ' ) : courseCode ,
263273 } ;
264274 } ) ;
265275
@@ -280,6 +290,18 @@ const prettifyDomain = (domain: string) => {
280290 . replace ( / ( [ A - Z ] ) ( [ A - Z ] [ a - z ] ) / g, '$1 $2' )
281291 . trim ( ) ;
282292} ;
293+
294+ const getCourseType = ( courseCode : string ) : 'L' | 'P' | 'E' | undefined => {
295+ if ( course_type_map [ courseCode ] ) {
296+ return course_type_map [ courseCode ] as 'L' | 'P' | 'E' ;
297+ }
298+ const lastChar = courseCode . slice ( - 1 ) . toUpperCase ( ) ;
299+ if ( [ 'L' , 'P' , 'E' ] . includes ( lastChar ) ) {
300+ return lastChar as 'L' | 'P' | 'E' ;
301+ }
302+ return undefined ;
303+ } ;
304+
283305type ShiftKey = 'morning' | 'evening' ;
284306export default function FacultySelector ( {
285307 onConfirm,
@@ -328,18 +350,16 @@ export default function FacultySelector({
328350 setPopup ( { showPopup : true , message : 'Please select a subject.' } ) ;
329351 return ;
330352 }
331- if (
332- ! selectedLabShift &&
333- selectedSubject . split ( ' - ' ) [ 0 ] . endsWith ( 'P' ) &&
334- ! selectedSubject . split ( ' - ' ) [ 0 ] . startsWith ( 'BSTS' )
335- ) {
353+ const courseCode = selectedSubject . split ( ' - ' ) [ 0 ] ;
354+ const courseCodeType = getCourseType ( courseCode ) ;
355+
356+ if ( ! selectedLabShift && courseCodeType === 'P' && ! courseCode . startsWith ( 'BSTS' ) ) {
336357 setPopup ( { showPopup : true , message : 'Please select a lab slot.' } ) ;
337358 return ;
338359 }
339360 if (
340361 ! selectedSlot &&
341- ( ! selectedSubject . split ( ' - ' ) [ 0 ] . endsWith ( 'P' ) ||
342- selectedSubject . split ( ' - ' ) [ 0 ] . startsWith ( 'BSTS' ) )
362+ ( courseCodeType === 'L' || courseCodeType === 'E' || courseCode . startsWith ( 'BSTS' ) )
343363 ) {
344364 setPopup ( { showPopup : true , message : 'Please select a theory slot.' } ) ;
345365 return ;
@@ -355,39 +375,36 @@ export default function FacultySelector({
355375 setPopup ( { showPopup : true , message : 'Successfully added course' } ) ;
356376 }
357377
358- const courseCode = selectedSubject . split ( ' - ' ) [ 0 ] ;
359- const courseCodeType = courseCode . at ( - 1 ) ;
360378 const id = selectedSubject ;
361379
362380 const labSubject = Object . keys ( data [ selectedSchool ] [ selectedDomain ] ) . filter ( subject => {
363381 const subjectCode = subject . split ( ' - ' ) [ 0 ] ;
382+ const subjectType = getCourseType ( subjectCode ) ;
364383 return (
365384 subjectCode . slice ( 0 , - 1 ) === courseCode . slice ( 0 , - 1 ) &&
366- ( subjectCode . at ( - 1 ) === 'P' || subjectCode . at ( - 1 ) === 'E' ) &&
385+ ( subjectType === 'P' || subjectType === 'E' ) &&
367386 subjectCode !== courseCode &&
368387 ! courseCode . startsWith ( 'BSTS' )
369388 ) ;
370389 } ) ;
371390
372391 const courseType : 'both' | 'th' | 'lab' =
373- labSubject . length == 1 || courseCodeType = == 'E'
392+ labSubject . length === 1 && courseCodeType ! == 'E'
374393 ? 'both'
375394 : courseCodeType === 'P' && ! courseCode . startsWith ( 'BSTS' )
376395 ? 'lab'
377- : courseCodeType === 'L' || courseCode . startsWith ( 'BSTS' )
378- ? 'th'
379- : 'th' ;
396+ : 'th' ;
380397
381398 const courseName = selectedSubject . split ( ' - ' ) [ 1 ] ;
382399
383400 let courseCodeLab ;
384401 let courseNameLab ;
385402 let courseSlots ;
386- if ( courseCodeType == 'E' ) {
387- courseCodeLab = courseCode ;
388- courseNameLab = courseName ;
403+ if ( courseCodeType === 'E' ) {
404+ courseCodeLab = '' ;
405+ courseNameLab = '' ;
389406 } else {
390- courseCodeLab = courseCodeLab = labSubject . length == 1 ? labSubject [ 0 ] . split ( ' - ' ) [ 0 ] : '' ;
407+ courseCodeLab = labSubject . length == 1 ? labSubject [ 0 ] . split ( ' - ' ) [ 0 ] : '' ;
391408 courseNameLab = labSubject . length == 1 ? labSubject [ 0 ] . split ( ' - ' ) [ 1 ] : '' ;
392409 }
393410 if ( selectedLabShift ) {
@@ -397,14 +414,15 @@ export default function FacultySelector({
397414 labShift : selectedLabShift ,
398415 } ) ;
399416 } else {
400- if ( courseType == 'both' ) {
417+ if ( courseType == 'both' || courseCodeType === 'E' ) {
401418 courseSlots = generateCourseSlotsBoth ( {
402419 data,
403420 selectedSchool,
404421 selectedDomain,
405422 selectedSubject,
406423 selectedSlot,
407424 selectedFaculties : priorityList ,
425+ courseCodeType,
408426 } ) ;
409427 } else if ( courseType == 'th' ) {
410428 courseSlots = generateCourseSlotsSingle ( {
@@ -424,13 +442,14 @@ export default function FacultySelector({
424442 }
425443 const courseData : fullCourseData = {
426444 id,
427- courseType,
445+ courseType : courseCodeType === 'E' ? 'both' : courseType ,
428446 courseCode,
429447 courseName,
430- ...( ( labSubject . length == 1 || courseCodeType === 'E' ) && {
431- courseCodeLab,
432- courseNameLab,
433- } ) ,
448+ ...( labSubject . length == 1 &&
449+ courseCodeType !== 'E' && {
450+ courseCodeLab,
451+ courseNameLab,
452+ } ) ,
434453 courseSlots : courseSlots ! ,
435454 } ;
436455
@@ -493,9 +512,10 @@ export default function FacultySelector({
493512
494513 const filteredSubjects = allSubjects . filter ( subject => {
495514 const code = subject . split ( ' - ' ) [ 0 ] ;
496- const base = code . slice ( 0 , - 1 ) ;
497- if ( code . endsWith ( 'P' ) ) {
498- return ! allSubjects . some ( s => s . startsWith ( base + 'L' ) ) ;
515+ const type = getCourseType ( code ) ;
516+ if ( type === 'P' ) {
517+ const theoryCode = code . slice ( 0 , - 1 ) + 'L' ;
518+ return ! allSubjects . some ( s => s . startsWith ( theoryCode ) ) ;
499519 }
500520 return true ;
501521 } ) ;
@@ -505,8 +525,9 @@ export default function FacultySelector({
505525 if ( selectedSubject ) {
506526 const subjectData = domainData [ selectedSubject ] ;
507527 const courseCode = selectedSubject . split ( ' - ' ) [ 0 ] ;
528+ const courseType = getCourseType ( courseCode ) ;
508529
509- if ( courseCode . endsWith ( 'P' ) && ! courseCode . startsWith ( 'BSTS' ) ) {
530+ if ( courseType === 'P' && ! courseCode . startsWith ( 'BSTS' ) ) {
510531 const allLabSlots = [ ...new Set ( subjectData . map ( entry => entry . slot ) ) ] ;
511532
512533 const morningLabSlots = allLabSlots . filter ( slot => {
@@ -684,7 +705,7 @@ export default function FacultySelector({
684705 options = { subjects }
685706 onChange = { handleSubjectChange }
686707 />
687- { selectedSubject . split ( ' - ' ) [ 0 ] . endsWith ( 'P' ) &&
708+ { getCourseType ( selectedSubject . split ( ' - ' ) [ 0 ] ) === 'P' &&
688709 ! selectedSubject . split ( ' - ' ) [ 0 ] . startsWith ( 'BSTS' ) ? (
689710 < SelectField
690711 label = "Slot"
@@ -730,9 +751,10 @@ export default function FacultySelector({
730751
731752 const labSubjectKey = Object . keys ( domainData ) . find ( subject => {
732753 const subjectCode = subject . split ( ' - ' ) [ 0 ] ;
754+ const subjectType = getCourseType ( subjectCode ) ;
733755 return (
734756 subjectCode . slice ( 0 , - 1 ) === baseCode &&
735- ( subjectCode . endsWith ( 'P' ) || subjectCode . endsWith ( 'E' ) )
757+ ( subjectType === 'P' || subjectType === 'E' )
736758 ) ;
737759 } ) ;
738760
0 commit comments