Skip to content
This repository was archived by the owner on Jul 27, 2024. It is now read-only.

Commit 862da97

Browse files
committed
FE - WIP add course plan settings component
1 parent 7a34e9a commit 862da97

File tree

3 files changed

+84
-5
lines changed

3 files changed

+84
-5
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<template>
2+
<p class="subtitle is-3">הגדרות תכנית לימודים</p>
3+
<div class="field">
4+
<year-selection label="שנת תחילת לימודים" v-model="selectedYear" />
5+
</div>
6+
<div class="field">
7+
<label class="label">מסלול לימודים</label>
8+
<div class="control" dir="rtl">
9+
<multiselect
10+
placeholder="חיפוש מסלול"
11+
class="is-loading"
12+
v-model="selectedTrack"
13+
searchable
14+
:delay="0"
15+
:minChars="1"
16+
:resolveOnLoad="false"
17+
:options="fetchTracks"
18+
/>
19+
</div>
20+
</div>
21+
22+
</template>
23+
24+
<script>
25+
import YearSelection from "./YearSelection.vue";
26+
import Multiselect from "@vueform/multiselect";
27+
import { fetchDjangoListIntoSelectOptions } from "@/utils.js";
28+
import { currentTrack, setTrack } from "@/course-store.js";
29+
import { reactive, toRefs, inject, computed } from "vue";
30+
31+
export default {
32+
components: { YearSelection, Multiselect },
33+
setup() {
34+
console.log("setup tracksettings");
35+
const state = reactive({
36+
selectedYear: 2022,
37+
selectedTrack: null,
38+
saving: false,
39+
});
40+
41+
const http = inject("http");
42+
const fetchTracks = async (query) => {
43+
const url = `tracks/?limit=10&data_year=${state.selectedYear}&search=${query}`;
44+
return await fetchDjangoListIntoSelectOptions(
45+
http,
46+
url,
47+
(track) => track.name
48+
);
49+
};
50+
51+
const selectedTrack = computed({
52+
get() { return currentTrack },
53+
set(newVal) { setTrack(newVal) }
54+
})
55+
56+
return { ...toRefs(state), selectedTrack, fetchTracks };
57+
},
58+
};
59+
</script>
60+
61+
<style src="@vueform/multiselect/themes/default.css">
62+
</style>

Closure_Front_End/src/components/Navigation.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<template>
2+
<course-plan-settings />
23
<h2 class="subtitle is-2">הוספת קורסים</h2>
34
<year-selection label="גרסת שנתון" v-model="selectedYear" />
45
<div class="field">
@@ -35,11 +36,12 @@
3536

3637
<script>
3738
import YearSelection from './YearSelection.vue'
39+
import CoursePlanSettings from './CoursePlanSettings.vue'
3840
import Multiselect from '@vueform/multiselect';
3941
import { fetchDjangoListIntoSelectOptions } from '@/utils.js';
4042
4143
export default {
42-
components: { YearSelection, Multiselect },
44+
components: { YearSelection, Multiselect, CoursePlanSettings },
4345
data() {
4446
return {
4547
"selectedYear": 2022,

Closure_Front_End/src/course-store.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ const getInitialState = () => {
1919

2020
const state = reactive(getInitialState());
2121

22+
/* */
23+
watch(state, (newState) => {
24+
localStorage.setItem(LS_PATH, JSON.stringify(newState));
25+
});
26+
27+
/* course-plan operations */
28+
2229
const getCoursesAsTakes = () => {
2330
return state.courses.map((course) => ({
2431
course: course.id,
@@ -69,7 +76,7 @@ export const deletePlan = async (plan) => {
6976
}
7077

7178
export const loadPlan = async (planId) => {
72-
console.assert(typeof(planId) === "number", "loadPlan() - planId must be a number")
79+
// console.assert(typeof(planId) === "number", "loadPlan() - planId must be a number")
7380
const res = await http.get(`/course_plans/${planId}`)
7481
const plan = res.data
7582
console.log("loaded plan", plan)
@@ -85,9 +92,7 @@ export const loadPlan = async (planId) => {
8592
state.dirty = false
8693
}
8794

88-
watch(state, (newState) => {
89-
localStorage.setItem(LS_PATH, JSON.stringify(newState));
90-
});
95+
/* course operations */
9196

9297
export const addCourse = (course) => {
9398
if (!course) {
@@ -127,6 +132,16 @@ export const addCourses = (courses, overwrite) => {
127132
state.dirty = true;
128133
};
129134

135+
/* track operations */
136+
137+
export const setTrack = (newTrack) => {
138+
console.log("Changing track, from", state.track, "to", newTrack);
139+
state.track = newTrack;
140+
state.dirty = true;
141+
}
142+
143+
/* store state getters */
144+
130145
export const courses = shallowReadonly(state.courses);
131146
export const currentTrack = computed(() => state.track);
132147
export const currentCourseplan = computed(() => state.courseplan);

0 commit comments

Comments
 (0)