Skip to content

Commit

Permalink
Requirement builder with the new data format
Browse files Browse the repository at this point in the history
  • Loading branch information
SamChou19815 committed Nov 16, 2021
1 parent 3a671c8 commit 8b47015
Show file tree
Hide file tree
Showing 15 changed files with 237 additions and 433 deletions.
16 changes: 12 additions & 4 deletions src/components/Modals/NewCourse/NewCourseModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export default defineComponent({
components: { CourseSelector, TeleportModal, SelectedRequirementEditor },
emits: {
'close-course-modal': () => true,
'add-course': (course: CornellCourseRosterCourse, requirementID: string) =>
typeof course === 'object' && typeof requirementID === 'string',
'add-course': (course: CornellCourseRosterCourse, choice: FirestoreCourseOptInOptOutChoices) =>
typeof course === 'object' && typeof choice === 'object',
},
data() {
return {
Expand Down Expand Up @@ -98,7 +98,7 @@ export default defineComponent({
selectedCourse,
store.state.groupedRequirementFulfillmentReport,
store.state.toggleableRequirementChoices,
/* deprecated AppOverriddenFulfillmentChoices */ {}
store.state.overriddenFulfillmentChoices
);
const requirementsThatAllowDoubleCounting: string[] = [];
Expand Down Expand Up @@ -137,7 +137,15 @@ export default defineComponent({
},
addCourse() {
if (this.selectedCourse == null) return;
this.$emit('add-course', this.selectedCourse, this.selectedRequirementID);
this.$emit('add-course', this.selectedCourse, {
optOut: this.relatedRequirements
.filter(it => it.id !== this.selectedRequirementID)
.map(it => it.id),
acknowledgedCheckerWarningOptIn: this.selfCheckRequirements
.filter(it => it.id !== this.selectedRequirementID)
.map(it => it.id),
arbitraryOptIn: {},
});
this.closeCurrentModal();
},
onSelectedChange(selected: string) {
Expand Down
26 changes: 23 additions & 3 deletions src/components/Requirements/IncompleteSelfCheck.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import store from '@/store';
import {
cornellCourseRosterCourseToFirebaseSemesterCourseWithGlobalData,
addCourseToSemester,
addCourseToSelectableRequirements,
updateRequirementChoice,
} from '@/global-firestore-data';
import { canFulfillChecker } from '@/requirements/requirement-frontend-utils';
Expand Down Expand Up @@ -150,12 +150,32 @@ export default defineComponent({
},
addExistingCourse(option: string) {
this.showDropdown = false;
addCourseToSelectableRequirements(this.selfCheckCourses[option].uniqueID, this.subReqId);
updateRequirementChoice(this.selfCheckCourses[option].uniqueID, choice => ({
...choice,
// Since we edit from a self-check requirement,
// we know it must be `acknowledgedCheckerWarningOptIn`.
acknowledgedCheckerWarningOptIn: Array.from(
new Set([...choice.acknowledgedCheckerWarningOptIn, this.subReqId])
),
}));
},
addNewCourse(course: CornellCourseRosterCourse, season: FirestoreSemesterSeason, year: number) {
this.showDropdown = false;
const newCourse = cornellCourseRosterCourseToFirebaseSemesterCourseWithGlobalData(course);
addCourseToSemester(year, season, newCourse, this.subReqId, this.$gtag);
addCourseToSemester(
year,
season,
newCourse,
// Since the course is new, we know the old choice does not exist.
() => ({
arbitraryOptIn: {},
// Since we edit from a self-check requirement,
// we know it must be `acknowledgedCheckerWarningOptIn`.
acknowledgedCheckerWarningOptIn: [this.subReqId],
optOut: [],
}),
this.$gtag
);
},
openCourseModal() {
this.isCourseModalOpen = true;
Expand Down
14 changes: 10 additions & 4 deletions src/components/Semester/Semester.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ import {
addCourseToSemester,
deleteCourseFromSemester,
deleteAllCoursesFromSemester,
addCourseToSelectableRequirements,
updateRequirementChoice,
} from '@/global-firestore-data';
import { updateSubjectColorData } from '@/store';
Expand Down Expand Up @@ -240,7 +240,12 @@ export default defineComponent({
})
);
newCourses.forEach(({ uniqueID, requirementID }) =>
addCourseToSelectableRequirements(uniqueID, requirementID)
// Since it's dragged from a requirement without checker warning,
// we edit the normal opt-out field.
updateRequirementChoice(uniqueID, choice => ({
...choice,
optOut: choice.optOut.filter(it => it !== requirementID),
}))
);
},
},
Expand Down Expand Up @@ -328,9 +333,10 @@ export default defineComponent({
closeConfirmationModal() {
this.isConfirmationOpen = false;
},
addCourse(data: CornellCourseRosterCourse, requirementID: string) {
addCourse(data: CornellCourseRosterCourse, choice: FirestoreCourseOptInOptOutChoices) {
const newCourse = cornellCourseRosterCourseToFirebaseSemesterCourseWithGlobalData(data);
addCourseToSemester(this.year, this.season, newCourse, requirementID, this.$gtag);
// Since the course is new, we know the old choice does not exist.
addCourseToSemester(this.year, this.season, newCourse, () => choice, this.$gtag);
const courseCode = `${data.subject} ${data.catalogNbr}`;
this.openConfirmationModal(`Added ${courseCode} to ${this.season} ${this.year}`);
Expand Down
6 changes: 3 additions & 3 deletions src/global-firestore-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export {
} from './semesters';
export { default as chooseToggleableRequirementOption } from './toggleable-requirement-choices';
export {
addCourseToSelectableRequirements,
deleteCourseFromSelectableRequirements,
} from './selectable-requirement-choices';
updateRequirementChoice,
deleteCourseFromRequirementChoices,
} from './override-fulfillment-choices';
36 changes: 36 additions & 0 deletions src/global-firestore-data/override-fulfillment-choices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { overriddenFulfillmentChoicesCollection } from '../firebase-frontend-config';
import store from '../store';

export const updateRequirementChoice = (
courseUniqueID: string | number,
choiceUpdater: (choice: FirestoreCourseOptInOptOutChoices) => FirestoreCourseOptInOptOutChoices
): void => {
overriddenFulfillmentChoicesCollection.doc(store.state.currentFirebaseUser.email).set({
...store.state.overriddenFulfillmentChoices,
[courseUniqueID]: choiceUpdater(
store.state.overriddenFulfillmentChoices[courseUniqueID] || {
arbitraryOptIn: {},
acknowledgedCheckerWarningOptIn: [],
optOut: [],
}
),
});
};

export const deleteCourseFromRequirementChoices = (courseUniqueID: string | number): void =>
deleteCoursesFromRequirementChoices([courseUniqueID]);

export const deleteCoursesFromRequirementChoices = (
courseUniqueIds: readonly (string | number)[]
): void => {
const courseUniqueIdStrings = new Set(courseUniqueIds.map(uniqueId => uniqueId.toString()));
overriddenFulfillmentChoicesCollection
.doc(store.state.currentFirebaseUser.email)
.set(
Object.fromEntries(
Object.entries(store.state.overriddenFulfillmentChoices).filter(
([k]) => !courseUniqueIdStrings.has(k)
)
)
);
};
69 changes: 0 additions & 69 deletions src/global-firestore-data/selectable-requirement-choices.ts

This file was deleted.

22 changes: 10 additions & 12 deletions src/global-firestore-data/semesters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { GTag, GTagEvent } from '../gtag';
import { sortedSemesters } from '../utilities';

import {
addCourseToSelectableRequirements,
deleteCourseFromSelectableRequirements,
deleteCoursesFromSelectableRequirements,
} from './selectable-requirement-choices';
updateRequirementChoice,
deleteCourseFromRequirementChoices,
deleteCoursesFromRequirementChoices,
} from './override-fulfillment-choices';

export const editSemesters = (
updater: (oldSemesters: readonly FirestoreSemester[]) => readonly FirestoreSemester[]
Expand Down Expand Up @@ -81,7 +81,7 @@ export const deleteSemester = (
GTagEvent(gtag, 'delete-semester');
const semester = store.state.semesters.find(sem => semesterEquals(sem, year, season));
if (semester) {
deleteCoursesFromSelectableRequirements(semester.courses.map(course => course.uniqueID));
deleteCoursesFromRequirementChoices(semester.courses.map(course => course.uniqueID));
editSemesters(oldSemesters => oldSemesters.filter(sem => !semesterEquals(sem, year, season)));
}
};
Expand All @@ -90,7 +90,7 @@ export const addCourseToSemester = (
year: number,
season: FirestoreSemesterSeason,
newCourse: FirestoreSemesterCourse,
requirementID?: string,
choiceUpdater: (choice: FirestoreCourseOptInOptOutChoices) => FirestoreCourseOptInOptOutChoices,
gtag?: GTag
): void => {
GTagEvent(gtag, 'add-course');
Expand All @@ -106,9 +106,7 @@ export const addCourseToSemester = (
if (semesterFound) return newSemestersWithCourse;
return [...oldSemesters, createSemester(year, season, [newCourse])];
});
if (requirementID) {
addCourseToSelectableRequirements(newCourse.uniqueID, requirementID);
}
updateRequirementChoice(newCourse.uniqueID, choiceUpdater);
};

export const deleteCourseFromSemester = (
Expand All @@ -120,7 +118,7 @@ export const deleteCourseFromSemester = (
GTagEvent(gtag, 'delete-course');
const semester = store.state.semesters.find(sem => semesterEquals(sem, year, season));
if (semester) {
deleteCourseFromSelectableRequirements(courseUniqueID);
deleteCourseFromRequirementChoices(courseUniqueID);
editSemesters(oldSemesters =>
oldSemesters.map(sem => ({
...sem,
Expand All @@ -140,7 +138,7 @@ export const deleteAllCoursesFromSemester = (
GTagEvent(gtag, 'delete-semester-courses');
const semester = store.state.semesters.find(sem => semesterEquals(sem, year, season));
if (semester) {
deleteCoursesFromSelectableRequirements(semester.courses.map(course => course.uniqueID));
deleteCoursesFromRequirementChoices(semester.courses.map(course => course.uniqueID));
editSemesters(oldSemesters =>
oldSemesters.map(sem => ({
...sem,
Expand All @@ -160,7 +158,7 @@ export const deleteCourseFromSemesters = (courseUniqueID: number, gtag?: GTag):
return { ...semester, courses: coursesWithoutDeleted };
})
);
deleteCourseFromSelectableRequirements(courseUniqueID);
deleteCourseFromRequirementChoices(courseUniqueID);
};

// exposed for testing
Expand Down
Loading

0 comments on commit 8b47015

Please sign in to comment.