diff --git a/src/api/Courses.js b/src/api/Courses.js
index 2ec4e6d..5f7e843 100644
--- a/src/api/Courses.js
+++ b/src/api/Courses.js
@@ -1,25 +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)
}
patchChapters(courseName, course, options) {
return Api.patch(`courses/${courseName}/chapters`, course, options)
}
+
+ postChapter(courseName, course, options) {
+ return Api.post(`courses/${courseName}/chapters`, course, options)
+ }
}
export const Courses = new CoursesClass()
diff --git a/src/app.js b/src/app.js
index 59ccd02..785f07d 100644
--- a/src/app.js
+++ b/src/app.js
@@ -1,79 +1,82 @@
import Vue from "vue"
import { sync } from "vuex-router-sync"
import { createStore } from "./store"
import { createRouter } from "./router"
import App from "./App.vue"
import Router from "vue-router"
Vue.use(Router)
// allow i18n for components
import VueI18n from "vue-i18n"
Vue.use(VueI18n)
import axios from "axios"
import VueAxios from "vue-axios"
Vue.use(VueAxios, axios)
import { Api } from "api/Api"
Vue.axios.defaults.baseURL = Api.baseURL
import metaInfo from "mixins/metaInfo"
Vue.mixin(metaInfo)
+import helpers from "mixins/helpers"
+Vue.mixin(helpers)
+
import Dialog from "components/ui/Dialog"
Vue.prototype.$dialog = Dialog
import WTLButton from "components/ui/WTLButton"
Vue.component("WTLButton", WTLButton)
import WTLInput from "components/ui/WTLInput"
Vue.component("WTLInput", WTLInput)
import WTLIcon from "components/ui/WTLIcon"
Vue.component("WTLIcon", WTLIcon)
import WTLField from "components/ui/WTLField"
Vue.component("WTLField", WTLField)
import WTLModal from "components/ui/WTLModal"
Vue.component("WTLModal", WTLModal)
import NoSSR from "vue-no-ssr"
Vue.component("NoSSR", NoSSR)
// we use "primaryLanguage" as a key because it does not really matter
// we can do this since the file is loaded using the `LANGUAGE_FILENAME` key
const messages = {
"main": require(`./../i18n/${LANGUAGE_MAIN_FILENAME}.json`)
}
const i18n = new VueI18n({
locale: "main",
messages
})
// Expose a factory function that creates a fresh set of store, router,
// app instances on each call (which is called for each SSR request)
export function createApp(ssrContext) {
// create store and router instances
const store = createStore()
const router = createRouter()
// sync the router with the vuex store.
// this registers `store.state.route`
sync(store, router)
// create the app instance.
// here we inject the router and store to all child components,
// making them available everywhere as `this.$router` and `this.$store`.
const app = new Vue({
router,
store,
i18n,
ssrContext,
render: (h) => h(App)
})
// expose the app, the router and the store.
// note we are not mounting the app here, since bootstrapping will be
// different depending on whether we are in a browser or on the server.
return { app, router, store }
}
diff --git a/src/components/CourseEditor.vue b/src/components/CourseEditor.vue
index f5b6d18..9417276 100644
--- a/src/components/CourseEditor.vue
+++ b/src/components/CourseEditor.vue
@@ -1,130 +1,145 @@
.CourseEditor
h2 Change course's title
br
- WTLField(grouped=true)
+ WTLField(grouped=true, label="Update course title")
WTLInput.CourseEditor__title(
v-model="newCourse.title"
)
WTLButton(
@click="patchCourse"
icon="done"
type="success"
) Update course title
br
br
h2 Change chapter order by dragging them
hr
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"
) {{ chapter.title }}
br
WTLButton(
@click="patchCourseChapters"
icon="done"
type="success"
) Update chapters order
h2 Insert new chapter
br
- WTLInput.CourseEditor__new-chapter(
- v-model="newChapter.title"
- placeholder="Chapter's title"
- )
+ WTLField(grouped=true, label="Add new chapter")
+ WTLInput.CourseEditor__new-chapter(
+ v-model="newChapter.title"
+ placeholder="Insert title"
+ )
+ WTLButton(
+ @click="postChapter"
+ icon="done"
+ type="success"
+ ) Add new chapter
br
diff --git a/src/components/ui/WTLBanner.vue b/src/components/ui/WTLBanner.vue
index 4329f80..47d39ca 100644
--- a/src/components/ui/WTLBanner.vue
+++ b/src/components/ui/WTLBanner.vue
@@ -1,85 +1,81 @@
.WTLBanner(
v-if="opened"
:class=`[
"WTLBanner--" + type
]`
)
slot
WTLButton.WTLBanner__close(
v-if="closable"
@click="opened = false"
icon="close"
)
diff --git a/src/mixins/helpers.js b/src/mixins/helpers.js
new file mode 100644
index 0000000..f83da5e
--- /dev/null
+++ b/src/mixins/helpers.js
@@ -0,0 +1,15 @@
+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
+ }
+ }
+}
diff --git a/src/store/actions.js b/src/store/actions.js
index 0225efe..ad2d11a 100644
--- a/src/store/actions.js
+++ b/src/store/actions.js
@@ -1,118 +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)
.then((response) => {
return dispatch("FETCH_COURSE", { courseName })
})
},
PATCH_COURSE_CHAPTERS({ commit, dispatch }, { courseName, course, options }) {
return Courses.patchChapters(courseName, course, options)
.then((response) => {
return dispatch("FETCH_COURSE", { courseName })
})
},
+ POST_CHAPTER({ commit, dispatch }, { courseName, course, options }) {
+ return Courses.postChapter(courseName, course, options)
+ .then((response) => {
+ return dispatch("FETCH_COURSE", { courseName })
+ })
+ },
+
SET_ERROR({ commit }, { error }) {
commit("EMPTY_ERROR")
commit("SET_ERROR", { error: error })
}
}