diff --git a/src/api/Courses.js b/src/api/Courses.js
index 5f7e843..c8a68d3 100644
--- a/src/api/Courses.js
+++ b/src/api/Courses.js
@@ -1,29 +1,29 @@
import { Api } from "./Api"
class CoursesClass {
get(courseName) {
return Api.get(`courses/${courseName}`)
}
getAll(page=1) {
if (page === 1) {
return Api.get("courses")
} else {
return Api.get(`courses?page=${page}`)
}
}
- patch(courseName, course, options) {
- return Api.patch(`courses/${courseName}`, course, options)
+ patch({ courseName }, params, options) {
+ return Api.patch(`courses/${courseName}`, params, options)
}
- patchChapters(courseName, course, options) {
- return Api.patch(`courses/${courseName}/chapters`, course, options)
+ patchChapters({ courseName }, params, options) {
+ return Api.patch(`courses/${courseName}/chapters`, params, options)
}
- postChapter(courseName, course, options) {
- return Api.post(`courses/${courseName}/chapters`, course, options)
+ postChapter({ courseName }, params, options) {
+ return Api.post(`courses/${courseName}/chapters`, params, options)
}
}
export const Courses = new CoursesClass()
diff --git a/src/components/CourseEditor.vue b/src/components/CourseEditor.vue
index 35a231a..46c9abf 100644
--- a/src/components/CourseEditor.vue
+++ b/src/components/CourseEditor.vue
@@ -1,212 +1,228 @@
.CourseEditor
div
h2 Change course's title
WTLField(grouped=true)
WTLInput.CourseEditor__title(
v-model="newCourse.title"
)
WTLButton(
@click="patchCourse"
icon="done"
type="success"
) Update course title
div
h2 Change chapter order by dragging them
.CourseEditor__chapters-container
ol.CourseEditor__old-chapters
li.CourseEditor__chapter(v-for="(chapter, index) in course.chapters") {{ index+1 }}. {{ chapter.title }}
VueDraggable.CourseEditor__chapters(
v-if="newChapters"
v-model="newChapters"
@start="drag=true"
@end="drag=false"
)
.CourseEditor__chapter(
v-for="chapter in newChapters"
:key="chapter._id"
)
WTLIcon(icon="swap_vertical")
| {{ chapter.title }}
div.flex-container.flex-content-end
h3 Confirm changes?
WTLButton(
@click="patchCourseChapters"
icon="done"
type="success"
) Update chapters order
div
h2 Insert new chapter
WTLField(grouped=true)
WTLInput.CourseEditor__new-chapter(
v-model="newChapter.title"
placeholder="Insert title"
)
WTLButton(
@click="postChapter"
icon="done"
type="success"
) Add new chapter
diff --git a/src/mixins/helpers.js b/src/mixins/helpers.js
index f83da5e..5cae773 100644
--- a/src/mixins/helpers.js
+++ b/src/mixins/helpers.js
@@ -1,15 +1,22 @@
export default {
methods: {
slice(array, keys) {
let array2 = []
for (let obj of array) {
let obj2 = {}
for (let key of keys) {
obj2[key] = obj[key]
}
array2.push(obj2)
}
return array2
+ },
+ filterKeys(object, keys) {
+ let obj = {}
+ for (let key of keys) {
+ obj[key] = object[key]
+ }
+ return obj
}
}
}
diff --git a/src/store/actions.js b/src/store/actions.js
index ad2d11a..ef7621d 100644
--- a/src/store/actions.js
+++ b/src/store/actions.js
@@ -1,125 +1,125 @@
import { Categories } from "api/Categories"
import { Courses } from "api/Courses"
import { Pages } from "api/Pages"
import { Chapters } from "api/Chapters"
import { Polling } from "api/Polling"
import { Api } from "api/Api"
export const actions = {
FETCH_HOME({ commit }) {
return Api.get("")
.then((response) => {
commit("SET_NAVIGATION_LINKS", { navigationLinks: response._links })
})
},
FETCH_ROOT_CATEGORIES({ commit }) {
return Categories.getRootCategories()
.then((response) => {
commit("SET_ROOT_CATEGORIES", { categories: response.data })
})
},
FETCH_CATEGORY({ commit }, { categoryName }) {
return Categories.get(categoryName)
.then((response) => {
commit("SET_CATEGORY", { category: response.data })
})
},
FETCH_COURSE({ commit }, { courseName }) {
return Courses.get(courseName)
.then((response) => {
const resp = Object.assign({}, response)
commit("SET_COURSE", { course: resp })
for (const chapter of resp.chapters) {
commit("SET_CHAPTER", { chapter: chapter })
}
return response
}).then((response) => {
commit("SET_NAVIGATION_LINKS", { navigationLinks: response._links })
})
},
FETCH_COURSES({ commit }, { page }) {
return Courses.getAll(page)
.then((response) => {
const resp = Object.assign({}, response)
commit("CLEAR_COURSES")
for (const course of resp._items) {
commit("SET_COURSE", { course: course })
}
return response
}).then((response) => {
commit("SET_NAVIGATION_LINKS", { navigationLinks: response._links })
return response
}).then((response) => {
commit("SET_META", { meta: response._meta })
})
},
FETCH_PAGE({ commit }, { pageTitle }) {
return Pages.get(pageTitle)
.then((response) => {
commit("SET_PAGE", { page: response })
})
},
FETCH_CHAPTER({ commit }, { chapterName }) {
return Chapters.get(chapterName)
.then((response) => {
const resp = Object.assign({}, response)
commit("SET_CHAPTER", { page: resp })
for (const page of resp.pages) {
commit("SET_PAGE", { page: page })
}
})
},
START_POLLING({ commit }) {
return Polling.start()
.then((response) => {
const pollingId = response.data.pollingId
const pollTimer = setInterval(() => {
Polling.getStatus(pollingId)
.then((response) => {
commit("UPDATE_POLLING", { pollingId, progress: response.data.progress })
})
}, 500)
commit("CREATE_POLLING", { pollingId, pollTimer })
})
},
UPDATE_ACTIVE_REQUESTS({ commit }, { add }) {
commit("UPDATE_ACTIVE_REQUESTS", { addNewRequest: add })
},
- PATCH_COURSE({ commit, dispatch }, { courseName, course, options }) {
- return Courses.patch(courseName, course, options)
+ PATCH_COURSE({ commit, dispatch }, { urlParams, bodyParams, options }) {
+ return Courses.patch(urlParams, bodyParams, options)
.then((response) => {
- return dispatch("FETCH_COURSE", { courseName })
+ commit("UPDATE_COURSE_FIELDS", { ...bodyParams, ...response })
})
},
- PATCH_COURSE_CHAPTERS({ commit, dispatch }, { courseName, course, options }) {
- return Courses.patchChapters(courseName, course, options)
+ PATCH_COURSE_CHAPTERS({ commit, dispatch }, { urlParams, bodyParams, options }) {
+ return Courses.patchChapters(urlParams, bodyParams, options)
.then((response) => {
- return dispatch("FETCH_COURSE", { courseName })
+ commit("UPDATE_COURSE_FIELDS", { ...response })
})
},
- POST_CHAPTER({ commit, dispatch }, { courseName, course, options }) {
- return Courses.postChapter(courseName, course, options)
+ POST_CHAPTER({ commit, dispatch }, { urlParams, bodyParams, options }) {
+ return Courses.postChapter(urlParams, bodyParams, options)
.then((response) => {
- return dispatch("FETCH_COURSE", { courseName })
+ commit("UPDATE_COURSE_FIELDS", { ...response })
})
},
SET_ERROR({ commit }, { error }) {
commit("EMPTY_ERROR")
commit("SET_ERROR", { error: error })
}
}
diff --git a/src/store/mutations.js b/src/store/mutations.js
index b23262e..4d013a5 100644
--- a/src/store/mutations.js
+++ b/src/store/mutations.js
@@ -1,69 +1,77 @@
import Vue from "vue"
export const mutations = {
SET_ROOT_CATEGORIES(state, { categories }) {
state.rootCategories = categories
},
SET_CHAPTER(state, { chapter }) {
Vue.set(state.chapters, chapter._id, chapter)
},
SET_NAVIGATION_LINKS(state, { navigationLinks }) {
state.navigationLinks = navigationLinks
},
SET_CATEGORY(state, { category }) {
Vue.set(state.categories, category.name, category)
},
SET_COURSE(state, { course }) {
Vue.set(state.courses, course._id, course)
},
SET_PAGE(state, { page }) {
Vue.set(state.pages, page._id, page)
},
SET_ERROR(state, { error }) {
state.error = Object.assign({}, error)
},
EMPTY_ERROR(state) {
state.error = null
},
CLEAR_ERROR(state) {
state.error = null
},
CLEAR_COURSES(state) {
state.courses = {}
},
CREATE_POLLING(state, { pollingId, pollTimer }) {
Vue.set(state.pollingOperations, pollingId, {
title: pollingId,
id: pollingId,
progress: 0,
timer: pollTimer
})
},
+ UPDATE_COURSE_FIELDS(state, course) {
+ let courseToUpdate = state.courses[course._id]
+ for (let key of Object.keys(course)) {
+ courseToUpdate[key] = course[key]
+ }
+ Vue.set(state.courses, course._id, courseToUpdate)
+ },
+
UPDATE_POLLING(state, { pollingId, progress }) {
Vue.set(state.pollingOperations[pollingId], "progress", progress)
},
DELETE_POLLING(state, { id }) {
clearTimeout(state.pollingOperations[id].timer)
Vue.delete(state.pollingOperations, id)
},
UPDATE_ACTIVE_REQUESTS(state, { addNewRequest }) {
state.activeApiRequests += addNewRequest
},
SET_META(state, { meta }) {
state.meta = meta
}
}