diff --git a/src/App.vue b/src/App.vue
index c5b44a8..479d493 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,128 +1,130 @@
#app.App(:class="{ 'App--rtl': isRTL }")
// AuthCheck
noscript Your browser does not have JS enabled, you are still able to browse the website but you won't be able to access advanced features such as editing or loggin-in.
AppHeader
.App__content
transition(name="fade", mode="out-in")
router-view.view
transition(name="bounce")
WTLSpinner.App__spinner(
v-if="activeRequests"
)
//
.App__polling-operations
PollingBar
diff --git a/src/api/Api.js b/src/api/Api.js
index 96fd616..f440155 100644
--- a/src/api/Api.js
+++ b/src/api/Api.js
@@ -1,59 +1,71 @@
import Vue from "vue"
const config = {
hostname: process.env.API_HOSTNAME,
preamble: "api/v1"
}
let defaultOptions = {}
if (process.env.VUE_ENV === "server" && process.env.USE_CERTS === "true") {
https = require("https")
fs = require("fs")
const httpsAgent = new https.Agent({
keepAlive: true,
ca: fs.readFileSync(process.env.CERTS_CA),
cert: fs.readFileSync(process.env.CERTS_CERT),
key: fs.readFileSync(process.env.CERTS_KEY)
})
defaultOptions = {
httpsAgent
}
}
class ApiClass {
constructor() {
this.baseURL = `${config.hostname}/${config.preamble}`
}
+
get(endpoint, options = {}) {
endpoint = this._cleanEndpoint(endpoint)
options = Object.assign(options, defaultOptions)
return Vue.axios.get(`${this.baseURL}/${endpoint}`, options)
.then((response) => {
return Promise.resolve(response.data)
})
}
post(endpoint, data = {}, options = {}) {
endpoint = this._cleanEndpoint(endpoint)
options = Object.assign(options, defaultOptions)
- return Vue.axios.get(`${this.baseURL}/${endpoint}`, data, options)
+ return Vue.axios.post(`${this.baseURL}/${endpoint}`, data, options)
+ .then((response) => {
+ return Promise.resolve(response.data)
+ })
+ }
+
+ patch(endpoint, data = {}, options = {}) {
+ endpoint = this._cleanEndpoint(endpoint)
+
+ options = Object.assign(options, defaultOptions)
+
+ return Vue.axios.patch(`${this.baseURL}/${endpoint}`, data, options)
.then((response) => {
return Promise.resolve(response.data)
})
}
_cleanEndpoint(endpoint) {
if (endpoint.startsWith("/")) {
endpoint = endpoint.substring("/")
}
return endpoint
}
}
export const Api = new ApiClass()
diff --git a/src/api/Courses.js b/src/api/Courses.js
index dd848a3..b145030 100644
--- a/src/api/Courses.js
+++ b/src/api/Courses.js
@@ -1,17 +1,21 @@
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)
+ }
}
export const Courses = new CoursesClass()
diff --git a/src/components/CourseEditor.vue b/src/components/CourseEditor.vue
new file mode 100644
index 0000000..e1ee40a
--- /dev/null
+++ b/src/components/CourseEditor.vue
@@ -0,0 +1,60 @@
+
+ .CourseEditor
+ WTLInput.CourseEditor__name(
+ v-model="newCourse.title"
+ )
+ WTLButton(
+ @click="pushChanges"
+ ) Confirm changes
+
+
+
+
+
diff --git a/src/store/actions.js b/src/store/actions.js
index 519b5a7..08a8129 100644
--- a/src/store/actions.js
+++ b/src/store/actions.js
@@ -1,99 +1,106 @@
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 })
+ })
}
}
diff --git a/src/views/Course.vue b/src/views/Course.vue
index 51f6c6d..033e0c6 100644
--- a/src/views/Course.vue
+++ b/src/views/Course.vue
@@ -1,59 +1,78 @@
.view--Course
h1 {{ courseName }}
+ WTLButton(
+ @click="toggleEditMode"
+ ) Toggle edit mode
CourseRenderer(
- v-if="!error && course",
+ v-if="!error && course && !editMode",
:course="course",
:showName="false"
)
+ CourseEditor(
+ v-if="editMode && course",
+ :course="course"
+ )
Error(:error="error")