@@ -31,16 +27,27 @@
\ No newline at end of file
diff --git a/web/src/components/blocks/BlockImages.vue b/web/src/components/blocks/BlockImages.vue
index b4e54462..b01821f6 100644
--- a/web/src/components/blocks/BlockImages.vue
+++ b/web/src/components/blocks/BlockImages.vue
@@ -32,14 +32,11 @@
+
+
\ No newline at end of file
diff --git a/web/src/components/inputs/LilSelect.vue b/web/src/components/inputs/LilSelect.vue
index 4d0a535c..c8db3253 100644
--- a/web/src/components/inputs/LilSelect.vue
+++ b/web/src/components/inputs/LilSelect.vue
@@ -17,7 +17,7 @@
props: ["options", "value", "valueKey", "placeholder"],
data() {
return {
- key: this.valueKey ? this.valueKey : 'value',
+ key: this.valueKey ? this.valueKey : 'title',
isOpened: false,
}
},
diff --git a/web/src/js/modules/api.js b/web/src/js/modules/api.js
index 803a2e69..8348c7ed 100644
--- a/web/src/js/modules/api.js
+++ b/web/src/js/modules/api.js
@@ -1,9 +1,17 @@
import axios from 'axios';
+import moment from 'moment';
axios.defaults.headers.post['Content-Type'] = 'application/json';
axios.defaults.headers.post['Accept'] = 'application/json';
export const api = {
+ getCategories: (accessToken) => {
+ return axios.get('/api/v1/categories/', {
+ headers: {
+ 'Authorization': `Token ${accessToken}`,
+ }
+ });
+ },
uploadImage: (imageData, accessToken) => {
return axios.post('/api/v1/image-objects/', {
image: imageData,
@@ -12,5 +20,195 @@ export const api = {
'Authorization': `Token ${accessToken}`,
}
});
- }
+ },
+ saveCourse: (courseObject, accessToken) => {
+ const isAdding = (!courseObject.hasOwnProperty('id') || !courseObject.hasOwnProperty('id'));
+
+ let deferredStart = null;
+ if (courseObject.is_deferred) {
+ let deferredStartTime = moment(courseObject.time.value, "HH:mm");
+ let deferredStartDate = moment(courseObject.date).hour(deferredStartTime.hour());
+ deferredStart = deferredStartDate.format();
+ }
+
+ const courseJson = {
+ title: courseObject.title,
+ short_description: courseObject.short_description,
+ category: courseObject.category,
+ price: courseObject.is_paid ? courseObject.price : 0,
+ deferred_start_at: deferredStart,
+ duration: courseObject.duration,
+ is_featured: courseObject.is_featured,
+ url: courseObject.url,
+ cover: courseObject.cover_id ? courseObject.cover_id : null,
+ content: courseObject.blocks.map((block) => {
+ if (block.type === 'text') {
+ return {
+ 'type': 'text',
+ 'data': {
+ 'id': block.data.id ? block.data.id : null,
+ 'title': block.data.title,
+ 'txt': block.data.text,
+ }
+ }
+ } else if (block.type === 'image') {
+ return {
+ 'type': 'image',
+ 'data': {
+ 'id': block.data.id ? block.data.id : null,
+ 'title': block.data.title,
+ 'img': block.data.image_id,
+ }
+ }
+ } else if (block.type === 'image-text') {
+ return {
+ 'type': 'image-text',
+ 'data': {
+ 'id': block.data.id ? block.data.id : null,
+ 'title': block.data.title,
+ 'img': block.data.image_id,
+ 'txt': block.data.text,
+ }
+ }
+ } else if (block.type === 'images') {
+ return {
+ 'type': 'images',
+ 'data': {
+ 'id': block.data.id ? block.data.id : null,
+ 'title': block.data.title,
+ 'images': block.data.images.map((galleryImage) => {
+ return {
+ 'id': galleryImage.id ? galleryImage.id : null,
+ 'img': galleryImage.img,
+ }
+ }),
+ }
+ }
+ } else if (block.type === 'video') {
+ return {
+ 'type': 'video',
+ 'data': {
+ 'id': block.data.id ? block.data.id : null,
+ 'title': block.data.title,
+ 'url': block.data.video_url,
+ }
+ }
+ }
+ }),
+ };
+
+ console.log(courseJson);
+
+ let request;
+ if (isAdding) {
+ return api.addCourse(courseJson, accessToken);
+ } else {
+ return api.updateCourse(courseObject.id, courseJson, accessToken);
+ }
+ },
+ convertCourseJson: (courseJSON) => {
+ let isDeferred = false;
+ let deferredDate = '';
+ let deferredTime = '';
+ if (courseJSON.deferred_start_at) {
+ let deferredDateTime = moment(courseJSON.deferred_start_at);
+ isDeferred = true;
+ deferredDate = deferredDateTime.format('MM-DD-YYYY');
+ deferredTime = deferredDateTime.format('HH:mm');
+ }
+ return {
+ id: courseJSON.id,
+ title: courseJSON.title,
+ short_description: courseJSON.short_description,
+ category: courseJSON.category,
+ price: courseJSON.price,
+ is_paid: courseJSON.price === 0,
+ is_deferred: isDeferred,
+ date: deferredDate,
+ time: deferredTime ? {title: deferredTime, value: deferredTime} : null,
+ duration: courseJSON.duration,
+ is_featured: courseJSON.is_featured,
+ url: courseJSON.url,
+ cover_id: courseJSON.cover.id,
+ cover_url: courseJSON.cover.image,
+ content: courseJSON.content.map((contentItem) => {
+ if (contentItem.type === 'text') {
+ return {
+ 'type': 'text',
+ 'data': {
+ 'id': contentItem.data.id ? contentItem.data.id : null,
+ 'title': contentItem.data.title,
+ 'text': contentItem.data.txt,
+ }
+ }
+ } else if (contentItem.type === 'image') {
+ return {
+ 'type': 'image',
+ 'data': {
+ 'id': contentItem.data.id ? contentItem.data.id : null,
+ 'title': contentItem.data.title,
+ 'image_id': contentItem.data.image.id,
+ 'image_url': contentItem.data.image.image,
+ }
+ }
+ } else if (contentItem.type === 'image-text') {
+ return {
+ 'type': 'image-text',
+ 'data': {
+ 'id': contentItem.data.id ? contentItem.data.id : null,
+ 'title': contentItem.data.title,
+ 'image_id': contentItem.data.image.id,
+ 'image_url': contentItem.data.image.image,
+ 'text': contentItem.data.txt,
+ }
+ }
+ } else if (contentItem.type === 'images') {
+ return {
+ 'type': 'images',
+ 'data': {
+ 'id': contentItem.data.id ? contentItem.data.id : null,
+ 'title': contentItem.data.title,
+ 'images': contentItem.data.images.map((galleryImage) => {
+ return {
+ 'id': galleryImage.id ? galleryImage.id : null,
+ 'image_id': galleryImage.image.id,
+ 'image_url': galleryImage.image.url,
+ }
+ }),
+ }
+ }
+ } else if (contentItem.type === 'video') {
+ return {
+ 'type': 'video',
+ 'data': {
+ 'id': contentItem.data.id ? contentItem.data.id : null,
+ 'title': contentItem.data.title,
+ 'video_url': contentItem.data.url,
+ }
+ }
+ }
+ }),
+ }
+ },
+ addCourse: (courseJson, accessToken) => {
+ return axios.post('/api/v1/courses/', courseJson, {
+ headers: {
+ 'Authorization': `Token ${accessToken}`,
+ }
+ });
+ },
+ updateCourse: (courseId, courseJson, accessToken) => {
+ return axios.put(`/api/v1/courses/${courseId}/`, courseJson, {
+ headers: {
+ 'Authorization': `Token ${accessToken}`,
+ }
+ });
+ },
+ getCourseLessons: (courseId, accessToken) => {
+ return axios.get(`/api/v1/lessons/?course=${courseId}`, {
+ headers: {
+ 'Authorization': `Token ${accessToken}`,
+ }
+ });
+ },
};
\ No newline at end of file