Skip to content

course page add to schedule button #901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion src/web/src/pages/CoursePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
{{ courseObj.description }}
</b-col>
</b-row>
<b-button @click="$router.go(-1)">Back</b-button>
<b-row class="mb-3">
<b-col>
<b-button variant="primary" class="mr-2" @click="addToSchedule">
Add to Schedule
</b-button>
<b-button @click="$router.go(-1)">Back</b-button>
</b-col>
</b-row>
<!-- :to="'/explore/' + courseObj.department"-->
</div>
<CenterSpinner
Expand Down Expand Up @@ -60,6 +67,8 @@ import { COURSES } from "@/store";
import { generateRequirementsText } from "@/utils";
import CenterSpinnerComponent from "../components/CenterSpinner.vue";
import CourseSectionsOpenBadge from "../components/CourseSectionsOpenBadge.vue";
import { SelectedCoursesCookie } from "../controllers/SelectedCoursesCookie";
import { addStudentCourse } from "@/services/YacsService";

export default {
components: {
Expand Down Expand Up @@ -91,8 +100,57 @@ export default {
},
methods: {
generateRequirementsText,
async addToSchedule() {
if (this.courseObj) {
if (this.isLoggedIn) {
try {
await addStudentCourse({
name: this.courseObj.name,
semester: this.selectedSemester,
cid: "-1"
});

for (const section of this.courseObj.sections) {
await addStudentCourse({
name: this.courseObj.name,
semester: this.selectedSemester,
cid: section.crn
});
}
} catch (error) {
this.$bvToast.toast('Failed to add course to schedule', {
title: 'Error',
variant: 'danger',
solid: true
});
return;
}
} else {
this.courseObj.selected = true;

const cookieManager = SelectedCoursesCookie.load(this.$cookies)
.semester(this.selectedSemester);

cookieManager.addCourse(this.courseObj);
this.courseObj.sections.forEach(section => {
section.selected = true;
cookieManager.addCourseSection(this.courseObj, section);
});

cookieManager.save();
}

this.$bvToast.toast(`Added ${this.courseObj.name} to schedule`, {
title: 'Course Added',
variant: 'success',
solid: true
});
}
}
},
computed: {
...mapState(['selectedSemester', 'selectedCourses']),
...mapGetters({ isLoggedIn: 'user/isLoggedIn' }),
...mapState(["isLoadingCourses"]),
...mapGetters([COURSES]),
transformed() {
Expand Down