-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6076b84
commit 1d5ed49
Showing
12 changed files
with
563 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useTranslatedString } from './../hooks/useTranslatedString'; | ||
import i18n from 'i18next'; | ||
import Course from '@/shapes/model/subject/Course'; | ||
import { FullCourseFocus } from '@/shapes/state/dictionary/CourseFocus'; | ||
import User from '@/shapes/model/session/User'; | ||
|
||
export const isFocused = (course: Course, courseFocus: FullCourseFocus) => | ||
Boolean(courseFocus.course) && courseFocus.course.id === course.id; | ||
|
||
export const isDimmedCourse = (course: Course, courseFocus: FullCourseFocus) => | ||
Boolean(courseFocus.course) && courseFocus.course.id !== course.id; | ||
|
||
export const isTaken = (courseId: number, user: User) => | ||
user.review_writable_lectures.some((l) => l.course === courseId); | ||
|
||
export const getProfessorsFullStr = (course: Course) => { | ||
const translate = useTranslatedString(); | ||
const professors = course.professors.slice().sort((a, b) => (a.name < b.name ? -1 : 1)); | ||
const professorNames = professors.map((p) => translate(p, 'name')); | ||
return professorNames.join(', '); | ||
}; | ||
|
||
export const isSpecialLectureCourse = (course: Course) => | ||
course.title.includes('특강') || | ||
course.title_en.includes('Special Lectures') || | ||
course.title_en.includes('Special Topics'); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useTranslatedString } from '@/hooks/useTranslatedString'; | ||
import Examtime from '@/shapes/model/subject/Examtime'; | ||
|
||
const translate = useTranslatedString(); | ||
|
||
export const getStr = (examtime: Examtime) => translate(examtime, 'str'); | ||
|
||
export const getTimeStr = (examtime: Examtime) => { | ||
const fullStr = getStr(examtime); | ||
return fullStr?.slice(fullStr.indexOf(' ')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { CategoryFirstIndex } from '@/shapes/enum'; | ||
import Planner from '@/shapes/model/planner/Planner'; | ||
import { PlannerItem } from '@/shapes/state/planner/ItemFocus'; | ||
import { AdditionalTrackType } from '@/shapes/enum'; | ||
|
||
export const isIdenticalCategory = (category1, category2) => | ||
category1 && | ||
category2 && | ||
category1[0] === category2[0] && | ||
category1[1] === category2[1] && | ||
category1[2] === category2[2]; | ||
|
||
export const getSeparateMajorTracks = (planner: Planner) => { | ||
if (!planner) { | ||
return []; | ||
} | ||
|
||
return [ | ||
planner.major_track, | ||
...planner.additional_tracks.filter((at) => at.type === AdditionalTrackType.DOUBLE), | ||
...planner.additional_tracks.filter((at) => at.type === AdditionalTrackType.MINOR), | ||
...planner.additional_tracks.filter((at) => at.type === AdditionalTrackType.INTERDISCIPLINARY), | ||
]; | ||
}; | ||
|
||
export const getCategoryOfType = (planner: Planner, type: string, departmentCode?: string) => { | ||
switch (type) { | ||
case 'Basic Required': | ||
return [CategoryFirstIndex.BASIC, 0, 0]; | ||
case 'Basic Elective': | ||
return [CategoryFirstIndex.BASIC, 0, 1]; | ||
case 'Major Required': { | ||
const separateMajorTracks = getSeparateMajorTracks(planner); | ||
const targetTrack = | ||
separateMajorTracks.find((smt) => smt.department?.code === departmentCode) || | ||
separateMajorTracks.find((smt) => smt.type === 'INTERDISCIPLINARY'); | ||
if (targetTrack) { | ||
const secondIndex = separateMajorTracks.findIndex((smt) => smt.id === targetTrack.id); | ||
return [CategoryFirstIndex.MAJOR, secondIndex, 0]; | ||
} | ||
return [CategoryFirstIndex.OTHERS, 0, 0]; | ||
} | ||
case 'Major Elective': | ||
case 'Elective(Graduate)': { | ||
const separateMajorTracks = getSeparateMajorTracks(planner); | ||
const targetTrack = | ||
separateMajorTracks.find((smt) => smt.department?.code === departmentCode) || | ||
separateMajorTracks.find((smt) => smt.type === AdditionalTrackType.INTERDISCIPLINARY); | ||
if (targetTrack) { | ||
const secondIndex = separateMajorTracks.findIndex((smt) => smt.id === targetTrack.id); | ||
return [CategoryFirstIndex.MAJOR, secondIndex, 1]; | ||
} | ||
return [CategoryFirstIndex.OTHERS, 0, 0]; | ||
} | ||
case 'Thesis Study(Undergraduate)': | ||
return [CategoryFirstIndex.RESEARCH, 0, 0]; | ||
case 'Individual Study': | ||
return [CategoryFirstIndex.RESEARCH, 0, 1]; | ||
case 'General Required': | ||
case 'Mandatory General Courses': | ||
return [CategoryFirstIndex.GENERAL_AND_HUMANITY, 0, 0]; | ||
case 'Humanities & Social Elective': | ||
return [CategoryFirstIndex.GENERAL_AND_HUMANITY, 0, 1]; | ||
case 'Other Elective': | ||
return [CategoryFirstIndex.OTHERS, 0, 0]; | ||
default: | ||
break; | ||
} | ||
if (type?.startsWith('Humanities & Social Elective')) { | ||
return [CategoryFirstIndex.GENERAL_AND_HUMANITY, 0, 1]; | ||
} | ||
return [CategoryFirstIndex.OTHERS, 0, 0]; | ||
}; | ||
|
||
export const getCategoryOfItem = (planner: Planner, item: PlannerItem) => { | ||
switch (item.item_type) { | ||
case 'TAKEN': | ||
return getCategoryOfType(planner, item.lecture.type_en, item.lecture.department_code); | ||
case 'FUTURE': | ||
return getCategoryOfType(planner, item.course.type_en, item.course.department?.code); | ||
case 'ARBITRARY': | ||
return getCategoryOfType(planner, item.type_en, item.department?.code); | ||
default: | ||
return getCategoryOfType(planner, '', ''); | ||
} | ||
}; | ||
|
||
export const getColorOfCategory = (planner: Planner, category) => { | ||
switch (category[0]) { | ||
case 0: | ||
return 1; | ||
case 1: | ||
return 3 + ((category[1] * 2) % 7); | ||
case 2: | ||
return 11; | ||
case 3: | ||
return 14; | ||
case 4: | ||
return 17; | ||
default: | ||
return 17; | ||
} | ||
}; | ||
|
||
export const getColorOfItem = (planner: Planner, item: PlannerItem) => { | ||
return getColorOfCategory(planner, getCategoryOfItem(planner, item)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { ItemFocusFrom } from '@/shapes/enum'; | ||
import { | ||
getCategoryOfItem, | ||
getSeparateMajorTracks, | ||
isIdenticalCategory, | ||
} from './itemCategoryUtils'; | ||
import { CategoryFirstIndex } from '@/shapes/enum'; | ||
import { getCourseOfItem, getCreditOfItem, getAuOfItem } from './itemUtils'; | ||
import ItemFocus, { PlannerItem, PlannerCourse } from '@/shapes/state/planner/ItemFocus'; | ||
import Planner from '@/shapes/model/planner/Planner'; | ||
|
||
export const isIdenticalItem = (item1: PlannerItem, item2: PlannerItem) => | ||
item1 != null && item2 != null && item1.item_type === item2.item_type && item1.id === item2.id; | ||
|
||
export const isTableFocusedItem = (item: PlannerItem, itemFocus: ItemFocus) => | ||
(itemFocus.from === ItemFocusFrom.TABLE_TAKEN || | ||
itemFocus.from === ItemFocusFrom.TABLE_FUTURE || | ||
itemFocus.from === ItemFocusFrom.TABLE_ARBITRARY) && | ||
isIdenticalItem(item, itemFocus.item); | ||
|
||
export const isTableClickedItem = (item: PlannerItem, itemFocus: ItemFocus) => | ||
isTableFocusedItem(item, itemFocus) && itemFocus.clicked === true; | ||
|
||
export const isSingleFocusedItem = (item: PlannerItem, itemFocus: ItemFocus) => | ||
isTableFocusedItem(item, itemFocus) || | ||
((itemFocus.from === ItemFocusFrom.LIST || itemFocus.from === ItemFocusFrom.ADDING) && | ||
getCourseOfItem(item) && | ||
itemFocus.course && | ||
getCourseOfItem(item).id === itemFocus.course.id); | ||
|
||
export const isMultipleFocusedItem = ( | ||
item: PlannerItem, | ||
itemFocus: ItemFocus, | ||
planner: Planner, | ||
) => { | ||
if (itemFocus.from !== ItemFocusFrom.CATEGORY) { | ||
return false; | ||
} | ||
if (!planner) { | ||
return false; | ||
} | ||
const focusedCategory = itemFocus.category; | ||
const itemCategory = getCategoryOfItem(planner, item); | ||
if (focusedCategory[0] === CategoryFirstIndex.TOTAL) { | ||
if (focusedCategory[2] === 0) { | ||
return getCreditOfItem(item) > 0; | ||
} | ||
return getAuOfItem(item) > 0; | ||
} | ||
if (focusedCategory[0] !== itemCategory[0]) { | ||
return false; | ||
} | ||
switch (focusedCategory[0]) { | ||
case CategoryFirstIndex.MAJOR: { | ||
const targetSmt = getSeparateMajorTracks(planner)[focusedCategory[1]]; | ||
if (targetSmt.major_required === 0) { | ||
if (focusedCategory[2] === 0) { | ||
return false; | ||
} | ||
const mrCategory = [focusedCategory[0], focusedCategory[1], 0]; | ||
return ( | ||
isIdenticalCategory(itemCategory, focusedCategory) || | ||
isIdenticalCategory(itemCategory, mrCategory) | ||
); | ||
} | ||
return isIdenticalCategory(itemCategory, focusedCategory); | ||
} | ||
default: { | ||
return isIdenticalCategory(itemCategory, focusedCategory); | ||
} | ||
} | ||
}; | ||
|
||
export const isFocusedItem = (item: PlannerItem, itemFocus: ItemFocus, planner?: Planner) => | ||
isSingleFocusedItem(item, itemFocus) || isMultipleFocusedItem(item, itemFocus, planner); | ||
|
||
export const isDimmedItem = (item: PlannerItem, itemFocus: ItemFocus) => | ||
!isFocusedItem(item, itemFocus) && itemFocus.clicked === true; | ||
|
||
export const isFocusedListCourse = (course: PlannerCourse, itemFocus: ItemFocus) => | ||
itemFocus.from === ItemFocusFrom.LIST && itemFocus.course.id === course.id; | ||
|
||
export const isClickedListCourse = (course: PlannerCourse, itemFocus: ItemFocus) => | ||
itemFocus.from === ItemFocusFrom.LIST && | ||
itemFocus.course.id === course.id && | ||
itemFocus.clicked === true; | ||
|
||
export const isDimmedListCourse = (course: PlannerCourse, itemFocus: ItemFocus) => | ||
itemFocus.clicked === true && | ||
(itemFocus.course?.id !== course.id || itemFocus.from !== ItemFocusFrom.LIST); |
Oops, something went wrong.