Merge branch 'dev' of gitlab.com:lilcity/backend into dev

remotes/origin/hasaccess
Ivlev Denis 8 years ago
commit 9e9ce9e965
  1. 56
      web/src/components/CourseRedactor.vue
  2. 4
      web/src/components/blocks/BlockImages.vue
  3. 2
      web/src/js/modules/api.js

@ -451,7 +451,7 @@
this.course.coverImageId = response.data.id; this.course.coverImageId = response.data.id;
}) })
.catch((error) => { .catch((error) => {
console.log('error', error); //console.log('error', error);
}); });
}; };
if (file) { if (file) {
@ -528,7 +528,7 @@
window.scrollTo(0, 0); window.scrollTo(0, 0);
}, },
onSubmit() { onSubmit() {
console.log('submit'); //console.log('onSubmit');
this.courseSaving = true; this.courseSaving = true;
api.saveCourse(this.course, this.accessToken) api.saveCourse(this.course, this.accessToken)
.then((response) => { .then((response) => {
@ -574,7 +574,7 @@
}); });
}, },
loadCourseDraft() { loadCourseDraft() {
console.log('loadCourseDraft'); //console.log('loadCourseDraft');
if(this.live) { return; } if(this.live) { return; }
this.courseLoading = true; this.courseLoading = true;
@ -591,13 +591,13 @@
}) })
.catch((err) => { .catch((err) => {
this.courseLoading = false; this.courseLoading = false;
console.log('error course loading', err); //console.log('error course loading', err);
}); });
return response; return response;
}, },
loadCourse() { loadCourse() {
console.log('loadCourse'); //console.log('loadCourse');
this.courseLoading = true; this.courseLoading = true;
let request = null; let request = null;
if(this.live) { if(this.live) {
@ -625,7 +625,7 @@
}) })
.catch((err) => { .catch((err) => {
this.courseLoading = false; this.courseLoading = false;
console.log('error course loading', err); //console.log('error course loading', err);
}); });
return request; return request;
@ -652,7 +652,7 @@
} }
}, },
validate(silent) { validate(silent) {
console.log('valadte', arguments); //console.log('valadte', arguments);
this.showErrors = true; this.showErrors = true;
if (this.$v.$invalid) { if (this.$v.$invalid) {
if(!silent) { if(!silent) {
@ -687,6 +687,7 @@
} }
}, },
saveCourseDraft: function (newValue, oldValue) { saveCourseDraft: function (newValue, oldValue) {
//console.log('saveCourseDraft');
// if (!oldValue.id) { // if (!oldValue.id) {
// return; // return;
// } // }
@ -694,12 +695,12 @@
// if(this.live) { // if(this.live) {
// if(!this.course.date || this.course.short_description == '' || this.course.title == '') { // if(!this.course.date || this.course.short_description == '' || this.course.title == '') {
// console.log('live valiedation error'); // //console.log('live valiedation error');
// return; // return;
// } // }
// } else { // } else {
// if(this.course.short_description == '' || this.course.title == '') { // if(this.course.short_description == '' || this.course.title == '') {
// console.log('course validation error'); // //console.log('course validation error');
// return; // return;
// } // }
// } // }
@ -734,15 +735,24 @@
courseData.is_deferred = true; courseData.is_deferred = true;
} }
let remoteUUIDMapper = {} let remoteUUIDMapper = {}
let remoteDataMapper = {}
if (courseData.content) { if (courseData.content) {
courseData.content.forEach((contentElement) => { courseData.content.forEach((contentElement) => {
remoteUUIDMapper[contentElement.uuid] = contentElement.data.id remoteUUIDMapper[contentElement.uuid] = contentElement.data.id;
remoteDataMapper[contentElement.uuid] = contentElement.data;
}) })
} }
this.course.content.forEach((contentElement, index) => { this.course.content.forEach((contentElement, index) => {
if (!contentElement.data.id) { if (!contentElement.data.id) {
this.$set(this.course.content[index].data, 'id', remoteUUIDMapper[contentElement.uuid]) this.$set(this.course.content[index].data, 'id', remoteUUIDMapper[contentElement.uuid])
} }
if(contentElement.type === 'images') {
remoteDataMapper[contentElement.uuid].images.forEach((image, imageIndex) => {
this.$set(this.course.content[index].data.images[imageIndex], 'id', image.id)
})
}
}); });
if (courseData.url) { if (courseData.url) {
this.slugChanged = true; this.slugChanged = true;
@ -764,13 +774,13 @@
.catch((err) => { .catch((err) => {
this.courseSyncHook = false; this.courseSyncHook = false;
this.courseSaving = false; this.courseSaving = false;
console.error(err); //console.error(err);
document.getElementById('course-redactor__saving-status').innerText = 'ОШИБКА'; document.getElementById('course-redactor__saving-status').innerText = 'ОШИБКА';
this.savingTimeout = setTimeout(() => { this.savingTimeout = setTimeout(() => {
document.getElementById('course-redactor__saving-status').innerText = ''; document.getElementById('course-redactor__saving-status').innerText = '';
}, 2000); }, 2000);
// alert('Произошло что-то страшное: '+err.toString()); // alert('Произошло что-то страшное: '+err.toString());
console.log(err.response.data); //console.log(err.response.data);
if(err.response.data) { if(err.response.data) {
for(let i in err.response.data) { for(let i in err.response.data) {
showNotification("error", this.fields[i]+": "+err.response.data[i].join(', ')); showNotification("error", this.fields[i]+": "+err.response.data[i].join(', '));
@ -782,7 +792,7 @@
}, 500); }, 500);
}, },
updateViewSection(location, action) { updateViewSection(location, action) {
console.log('updateViewSection[action]', action); //console.log('updateViewSection[action]', action);
if (location.pathname === '/course/create/lessons') { if (location.pathname === '/course/create/lessons') {
this.viewSection = 'lessons'; this.viewSection = 'lessons';
} else if (location.pathname === '/course/create') { } else if (location.pathname === '/course/create') {
@ -791,8 +801,8 @@
this.viewSection = 'lessons-edit'; this.viewSection = 'lessons-edit';
} else if (location.pathname.indexOf('/course/create/lessons/edit') !== -1) { } else if (location.pathname.indexOf('/course/create/lessons/edit') !== -1) {
let lessonId = parseInt(location.pathname.split('/').pop()); let lessonId = parseInt(location.pathname.split('/').pop());
console.log('lessonId', lessonId, this.lessons.toString()); //console.log('lessonId', lessonId, this.lessons.toString());
console.log('lessod edit', this.lessons.find((i)=>{return i.id === lessonId})); //console.log('lessod edit', this.lessons.find((i)=>{return i.id === lessonId}));
this.currentLesson = this.lessons.find((i)=>{return i.id === lessonId}); this.currentLesson = this.lessons.find((i)=>{return i.id === lessonId});
this.viewSection = 'lessons-edit'; this.viewSection = 'lessons-edit';
} }
@ -887,9 +897,9 @@
// }); // });
// } // }
console.log('wait promises'); //console.log('wait promises');
Promise.all(promises.map(p => p.catch(e => e))).then(()=>{ Promise.all(promises.map(p => p.catch(e => e))).then(()=>{
console.log('promises end'); //console.log('promises end');
this.mounting = false; this.mounting = false;
let load; let load;
if (this.courseId) { if (this.courseId) {
@ -906,7 +916,7 @@
}) })
}); });
console.log('mounted end'); //console.log('mounted end');
// this.updateViewSection(window.location); // this.updateViewSection(window.location);
}, },
computed: { computed: {
@ -969,17 +979,17 @@
watch: { watch: {
'course': { 'course': {
handler: function (newValue, oldValue) { handler: function (newValue, oldValue) {
// console.log('watch', JSON.stringify(newValue), JSON.stringify(oldValue)); // //console.log('watch', JSON.stringify(newValue), JSON.stringify(oldValue));
// Если курс загрузился и есть ID - делаем кнопки превью и публикации активными // Если курс загрузился и есть ID - делаем кнопки превью и публикации активными
console.log('newValue.id', newValue.id); //console.log('newValue.id', newValue.id);
if (newValue.id) { if (newValue.id) {
// console.log('newValue.id disabled remove', newValue.id); // //console.log('newValue.id disabled remove', newValue.id);
$('#course-redactor__preview-button').removeAttr('disabled'); $('#course-redactor__preview-button').removeAttr('disabled');
$('#course-redactor__publish-button').removeAttr('disabled'); $('#course-redactor__publish-button').removeAttr('disabled');
} }
// console.log('courseSyncHook', this.courseSyncHook); // //console.log('courseSyncHook', this.courseSyncHook);
if (this.courseSyncHook || this.courseLoading) { if (this.courseSyncHook || this.courseLoading) {
console.log('abort save draft', this.courseSyncHook, this.courseLoading); //console.log('abort save draft', this.courseSyncHook, this.courseLoading);
return; return;
} }
this.saveCourseDraft(newValue, oldValue); this.saveCourseDraft(newValue, oldValue);

@ -66,6 +66,8 @@
let reader = new FileReader(); let reader = new FileReader();
reader.onload = () => { reader.onload = () => {
let images = this.images; let images = this.images;
console.log('images before before', JSON.stringify(images));
images.push({ images.push({
src: reader.result, src: reader.result,
loading: true, loading: true,
@ -75,6 +77,7 @@
api.uploadImage(reader.result, this.accessToken) api.uploadImage(reader.result, this.accessToken)
.then((response) => { .then((response) => {
let images = this.images; let images = this.images;
console.log('images before', JSON.stringify(images));
images.forEach((image, index) => { images.forEach((image, index) => {
if (image.src === reader.result) { if (image.src === reader.result) {
images[index].img = response.data.id; images[index].img = response.data.id;
@ -82,6 +85,7 @@
images[index].src = response.data.image; images[index].src = response.data.image;
} }
}); });
console.log('images after', JSON.stringify(images));
this.$emit('update:images', images); this.$emit('update:images', images);
}) })
.catch((error) => { .catch((error) => {

@ -339,7 +339,7 @@ export const api = {
'title': contentItem.title, 'title': contentItem.title,
'images': contentItem.gallery_images.map((galleryImage) => { 'images': contentItem.gallery_images.map((galleryImage) => {
return { return {
'id': galleryImage.id ? galleryImage.id : null, 'id': galleryImage.id,
'img': galleryImage.img.id, 'img': galleryImage.img.id,
'src': galleryImage.img.image, 'src': galleryImage.img.image,
} }

Loading…
Cancel
Save