Skip to content

Commit

Permalink
added logic to auto add selected courses from rsearch to reqpanel, fi…
Browse files Browse the repository at this point in the history
…xed bug where user could add course to any rule field
  • Loading branch information
samuel-lao committed Dec 8, 2024
1 parent 29f3edb commit bfd5804
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
7 changes: 5 additions & 2 deletions backend/degree/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,12 @@ def validate(self, data):
identical_rules.append(curr_rule)
else: # parent rule
bfs_queue.extend(curr_rule.children.all())
try:
rules.extend(identical_rules)
data["rules"] = rules
except:
pass

rules.extend(identical_rules)
data["rules"] = rules

# TODO: check that rules belong to this degree plan
for rule in rules:
Expand Down
9 changes: 7 additions & 2 deletions frontend/degree-plan/components/Requirements/Rule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const RuleLeafWrapper = styled.div<{$isDroppable:boolean, $isOver: boolean}>`
justify-content: space-between;
gap: .5rem;
align-items: center;
box-shadow: ${props => props.$isOver ? '0px 0px 4px 2px var(--selected-color);' : props.$isDroppable ? '0px 0px 4px 2px var(--primary-color-dark);' : 'rgba(0, 0, 0, 0.05);'}
box-shadow: ${props => props.$isOver && props.$isDroppable ? '0px 0px 4px 2px var(--selected-color);' : props.$isDroppable ? '0px 0px 4px 2px var(--primary-color-dark);' : 'rgba(0, 0, 0, 0.05);'};
// background-color: ${props => props.$isOver ? props.$isDroppable ? null : 'lightgray' : null};
// cursor: ${props => props.$isOver ? props.$isDroppable ? "not-allowed" : "not-allowed" : "not-allowed"};
cursor: not-allowed;
`

const CusCourses = styled.div`
Expand Down Expand Up @@ -167,7 +170,9 @@ const RuleComponent = (ruleTree : RuleTree) => {
createOrUpdate({ rules: course.rules !== undefined ? [...course.rules, rule.id] : [rule.id] }, course.full_code);
return undefined;
}, // TODO: this doesn't handle fulfillments that already have a rule
canDrop: () => { return !satisfied && !!rule.q },
canDrop: (item, monitor) => {
return !satisfied && !!rule.q && (item.rule_id === rule.id)
},
collect: monitor => ({
isOver: !!monitor.isOver() && !satisfied,
canDrop: !!monitor.canDrop()
Expand Down
5 changes: 4 additions & 1 deletion frontend/degree-plan/components/Search/CourseInSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ interface CourseProps {
isStar?: boolean;
}



export default function Course({
course,
ruleId,
Expand All @@ -148,9 +150,10 @@ export default function Course({
isStar,
}: CourseProps) {
/** React dnd */

const [{ isDragging }, drag] = useDrag<DnDCourse, never, { isDragging: boolean }>(() => ({
type: ItemTypes.COURSE_IN_PLAN,
item: {full_code: course.id},
item: {full_code: course.id, rule_id: ruleId == null ? undefined : ruleId},
collect: (monitor) => ({
isDragging: !!monitor.isDragging()
})
Expand Down
3 changes: 2 additions & 1 deletion frontend/degree-plan/components/Search/ResultsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ const ResultsList = ({
isLoading
}: ResultListProps) => {
// TODO: what if activeDegreeplan is not defined

const { createOrUpdate: createOrUpdateFulfillment } = useSWRCrud<Fulfillment>(
`/api/degree/degreeplans/${activeDegreeplanId}/fulfillments`,
{
idKey: "full_code",
createDefaultOptimisticData: { semester: null, rules: [] }
createDefaultOptimisticData: { semester: null, rules: [ruleId] }
}
);
const { createOrUpdate: createOrUpdateDockedCourse } = useSWRCrud<DockedCourse>(`/api/degree/docked`, { idKey: 'full_code' });
Expand Down
2 changes: 2 additions & 0 deletions frontend/degree-plan/components/Search/SearchPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export const SearchPanel = ({ activeDegreeplanId }: SearchPanelProp) => {
setSearchRuleId(null);
}

// console.log(ruleId)

return (
<PanelContainer>
<SearchPanelHeader>
Expand Down
12 changes: 11 additions & 1 deletion frontend/degree-plan/pages/OnboardingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,19 @@ const OnboardingPage = ({
separatedCourses[currentSem] = [];
} else {
let courseMatch = line.match(/\b\w+\s\d{3,4}\b/);

if (courseMatch) {
separatedCourses[currentSem].push(courseMatch[0]);
// Check if course didn't get an F or a W. If current sem's courses are empty, remove sem key from separatedCourses
if ((line[line.length -1] == "f" || line[line.length -1] == "w") && separatedCourses[currentSem].length == 0) {
delete separatedCourses[currentSem];
}
else {
separatedCourses[currentSem].push(courseMatch[0]);
}
}



}
}
separatedCourses = Object.keys(separatedCourses).map(
Expand Down

0 comments on commit bfd5804

Please sign in to comment.