|
|
|
|
@ -201,26 +201,68 @@ export const api = { |
|
|
|
|
convertContentJson: (contentJson, forSaving) => { |
|
|
|
|
if(forSaving){ |
|
|
|
|
return contentJson.map((block, index) => { |
|
|
|
|
const position = ++index; |
|
|
|
|
const data = Object.assign({position}, block); |
|
|
|
|
if (['image', 'image-text'].indexOf(data.type) > -1) { |
|
|
|
|
data.img = data.img && data.img.id; |
|
|
|
|
} |
|
|
|
|
else if (data.type === 'images') { |
|
|
|
|
data.gallery_images = data.gallery_images.map(image => { |
|
|
|
|
return { |
|
|
|
|
id: image.id, |
|
|
|
|
img: image.img && image.img.id, |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else if (data.type === 'video') { |
|
|
|
|
data.url = data.video_url; |
|
|
|
|
if (block.type === 'text') { |
|
|
|
|
return { |
|
|
|
|
'type': 'text', |
|
|
|
|
'data': { |
|
|
|
|
'id': block.data.id ? block.data.id : null, |
|
|
|
|
'uuid': block.uuid, |
|
|
|
|
'position': ++index, |
|
|
|
|
'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, |
|
|
|
|
'uuid': block.uuid, |
|
|
|
|
'position': ++index, |
|
|
|
|
'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, |
|
|
|
|
'uuid': block.uuid, |
|
|
|
|
'position': ++index, |
|
|
|
|
'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, |
|
|
|
|
'uuid': block.uuid, |
|
|
|
|
'position': ++index, |
|
|
|
|
'title': block.data.title, |
|
|
|
|
'images': block.data.images.map((galleryImage) => { |
|
|
|
|
return { |
|
|
|
|
'id': galleryImage.id ? galleryImage.id : null, |
|
|
|
|
'img': galleryImage.image_id, |
|
|
|
|
} |
|
|
|
|
}), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if (block.type === 'video') { |
|
|
|
|
return { |
|
|
|
|
'type': 'video', |
|
|
|
|
'data': { |
|
|
|
|
'id': block.data.id ? block.data.id : null, |
|
|
|
|
'uuid': block.uuid, |
|
|
|
|
'position': ++index, |
|
|
|
|
'title': block.data.title, |
|
|
|
|
'url': block.data.video_url, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return { |
|
|
|
|
type: block.type, |
|
|
|
|
data: data, |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
return contentJson.sort((a, b) => { |
|
|
|
|
@ -231,44 +273,70 @@ export const api = { |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
}).map(block => { |
|
|
|
|
/*const templates = { |
|
|
|
|
image: { |
|
|
|
|
img: {}, |
|
|
|
|
}, |
|
|
|
|
'image-text': { |
|
|
|
|
txt: '', |
|
|
|
|
img: {}, |
|
|
|
|
}, |
|
|
|
|
images: { |
|
|
|
|
gallery_images: [], |
|
|
|
|
}, |
|
|
|
|
video: { |
|
|
|
|
video_url: '', |
|
|
|
|
}, |
|
|
|
|
text: { |
|
|
|
|
txt: '', |
|
|
|
|
}).map((contentItem) => { |
|
|
|
|
if (contentItem.type === 'text') { |
|
|
|
|
return { |
|
|
|
|
'type': 'text', |
|
|
|
|
'uuid': contentItem.uuid, |
|
|
|
|
'data': { |
|
|
|
|
'id': contentItem.id ? contentItem.id : null, |
|
|
|
|
'title': contentItem.title, |
|
|
|
|
'text': contentItem.txt, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return Object.assign({ |
|
|
|
|
type: '', id: null, uuid: '', title: '', |
|
|
|
|
}, templates[block.type], block);*/ |
|
|
|
|
let data = Object.assign({}, block); |
|
|
|
|
if(data.type == 'image' || data.type == 'image-text'){ |
|
|
|
|
data.img_id = data.img.id; |
|
|
|
|
data.img_thumbnail = data.img.image_thumbnail; |
|
|
|
|
delete data.img; |
|
|
|
|
} |
|
|
|
|
else if(data.type === 'images'){ |
|
|
|
|
data.gallery_images = data.gallery_images.map(galleryImage => { |
|
|
|
|
return { |
|
|
|
|
'id': galleryImage.id ? galleryImage.id : null, |
|
|
|
|
'img_id': galleryImage.img.id, |
|
|
|
|
img_thumbnail: galleryImage.img.img_thumbnail, |
|
|
|
|
} else if (contentItem.type === 'image') { |
|
|
|
|
return { |
|
|
|
|
'type': 'image', |
|
|
|
|
'uuid': contentItem.uuid, |
|
|
|
|
'data': { |
|
|
|
|
'id': contentItem.id ? contentItem.id : null, |
|
|
|
|
'title': contentItem.title, |
|
|
|
|
'image_id': (contentItem.img) ? contentItem.img.id:null, |
|
|
|
|
'image_url': (contentItem.img) ? contentItem.img.image:null, |
|
|
|
|
'image_thumbnail_url': (contentItem.img) ? contentItem.img.image_thumbnail:null, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if (contentItem.type === 'image-text') { |
|
|
|
|
return { |
|
|
|
|
'type': 'image-text', |
|
|
|
|
'uuid': contentItem.uuid, |
|
|
|
|
'data': { |
|
|
|
|
'id': contentItem.id ? contentItem.id : null, |
|
|
|
|
'title': contentItem.title, |
|
|
|
|
'image_id': (contentItem.img) ? contentItem.img.id:null, |
|
|
|
|
'image_url': (contentItem.img) ? contentItem.img.image:null, |
|
|
|
|
'image_thumbnail_url': (contentItem.img) ? contentItem.img.image_thumbnail:null, |
|
|
|
|
'text': contentItem.txt, |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} else if (contentItem.type === 'images') { |
|
|
|
|
return { |
|
|
|
|
'type': 'images', |
|
|
|
|
'uuid': contentItem.uuid, |
|
|
|
|
'data': { |
|
|
|
|
'id': contentItem.id ? contentItem.id : null, |
|
|
|
|
'title': contentItem.title, |
|
|
|
|
'images': contentItem.gallery_images.map((galleryImage) => { |
|
|
|
|
return { |
|
|
|
|
'id': galleryImage.id, |
|
|
|
|
'image_id': galleryImage.img.id, |
|
|
|
|
'image_url': galleryImage.img.image, |
|
|
|
|
'image_thumbnail_url': galleryImage.img.image_thumbnail, |
|
|
|
|
} |
|
|
|
|
}), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if (contentItem.type === 'video') { |
|
|
|
|
return { |
|
|
|
|
'type': 'video', |
|
|
|
|
'uuid': contentItem.uuid, |
|
|
|
|
'data': { |
|
|
|
|
'id': contentItem.id ? contentItem.id : null, |
|
|
|
|
'title': contentItem.title, |
|
|
|
|
'video_url': contentItem.url, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return data; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
addCourse: (courseJson, accessToken) => { |
|
|
|
|
@ -331,19 +399,19 @@ export const api = { |
|
|
|
|
let removeUrl; |
|
|
|
|
switch(blockData.type) { |
|
|
|
|
case 'text': |
|
|
|
|
removeUrl = `/api/v1/texts/${blockData.id}/`; |
|
|
|
|
removeUrl = `/api/v1/texts/${blockData.data.id}/`; |
|
|
|
|
break; |
|
|
|
|
case 'image': |
|
|
|
|
removeUrl = `/api/v1/images/${blockData.id}/`; |
|
|
|
|
removeUrl = `/api/v1/images/${blockData.data.id}/`; |
|
|
|
|
break; |
|
|
|
|
case 'image-text': |
|
|
|
|
removeUrl = `/api/v1/image-texts/${blockData.id}/`; |
|
|
|
|
removeUrl = `/api/v1/image-texts/${blockData.data.id}/`; |
|
|
|
|
break; |
|
|
|
|
case 'images': |
|
|
|
|
removeUrl = `/api/v1/galleries/${blockData.id}/`; |
|
|
|
|
removeUrl = `/api/v1/galleries/${blockData.data.id}/`; |
|
|
|
|
break; |
|
|
|
|
case 'video': |
|
|
|
|
removeUrl = `/api/v1/videos/${blockData.id}/`; |
|
|
|
|
removeUrl = `/api/v1/videos/${blockData.data.id}/`; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (!removeUrl) { |
|
|
|
|
|