Skip to content

Commit 4b02519

Browse files
committed
elasticsearch module replaced by request, making CLS to work, fixes on courses
1 parent 8ee7a74 commit 4b02519

37 files changed

Lines changed: 523 additions & 334 deletions

assets/img/presenter.jpg

-4.45 KB
Binary file not shown.

fixture/init/course.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,55 @@ var CourseInvite = require('courses').CourseInvite;
66

77
exports.Course = [
88
{
9-
"_id": "543250000000000000000002",
10-
slug: "js",
11-
videoKeyTag: "js",
12-
title: "Курс JavaScript/DOM/интерфейсы",
9+
"_id": "543250000000000000000002",
10+
slug: "js",
11+
videoKeyTag: "js",
12+
title: "Курс JavaScript/DOM/интерфейсы",
1313
shortDescription: `"Правильный" курс по профессиональному JavaScript, цель которого – научить думать на JavaScript, писать просто, быстро и красиво.`,
14-
isListed: true,
15-
weight: 1
14+
isListed: true,
15+
weight: 1
1616
},
1717
{
18-
"_id": "543250000000000000000003",
19-
slug: "nodejs",
20-
videoKeyTag: "nodejs",
21-
title: "Курс по Node.JS",
18+
"_id": "543250000000000000000003",
19+
slug: "nodejs",
20+
videoKeyTag: "nodejs",
21+
title: "Курс по Node.JS",
2222
shortDescription: `Грамотная разработка на платформе Node.JS (серверный JavaScript).`,
23-
isListed: true,
24-
weight: 2
23+
isListed: true,
24+
weight: 2
2525
}
2626
];
2727

2828
exports.CourseInvite = [];
29+
exports.CourseParticipant = [];
30+
exports.CourseFeedback = [];
2931

3032
exports.CourseGroup = [
3133
{
32-
course: '543250000000000000000002',
33-
dateStart: new Date(2016, 0, 1),
34-
dateEnd: new Date(2016, 10, 10),
35-
timeDesc: "пн/чт 19:30 - 21:00 GMT+3",
36-
slug: 'js-1',
37-
price: 1,
34+
course: '543250000000000000000002',
35+
dateStart: new Date(2016, 0, 1),
36+
dateEnd: new Date(2016, 10, 10),
37+
timeDesc: "пн/чт 19:30 - 21:00 GMT+3",
38+
slug: 'js-1',
39+
price: 1,
3840
participantsLimit: 30,
39-
webinarId: '123',
40-
isListed: true,
41-
isOpenForSignup: true,
42-
title: "Курс JavaScript/DOM/интерфейсы (01.01)"
41+
webinarId: '123',
42+
isListed: true,
43+
isOpenForSignup: true,
44+
title: "Курс JavaScript/DOM/интерфейсы (01.01)"
4345
},
4446
{
45-
course: '543250000000000000000002',
46-
dateStart: new Date(2016, 5, 1),
47-
dateEnd: new Date(2016, 11, 10),
48-
timeDesc: "пн/чт 21:30 - 23:00 GMT+3",
49-
slug: 'js-2',
50-
price: 1,
51-
webinarId: '456',
47+
course: '543250000000000000000002',
48+
dateStart: new Date(2016, 5, 1),
49+
dateEnd: new Date(2016, 11, 10),
50+
timeDesc: "пн/чт 21:30 - 23:00 GMT+3",
51+
slug: 'js-2',
52+
price: 1,
53+
webinarId: '456',
5254
participantsLimit: 30,
53-
isListed: true,
54-
isOpenForSignup: true,
55-
title: "Курс JavaScript/DOM/интерфейсы (06.01)"
55+
isListed: true,
56+
isOpenForSignup: true,
57+
title: "Курс JavaScript/DOM/интерфейсы (06.01)"
5658
}
5759
];
5860

handlers/accessLogger.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ exports.init = function(app) {
5454
// set the color of the status code;
5555
var s = status / 100 | 0;
5656

57+
// not ctx.url, but ctx.originalUrl because mount middleware changes it
58+
// request to /payments/common/order in case of error is logged as /order
59+
5760
ctx.log[err ? 'error' : 'info'](
58-
"<-- %s %s", ctx.method, ctx.url, {
61+
"<-- %s %s", ctx.method, ctx.originalUrl, {
5962
event: "request-end",
6063
method: ctx.method,
61-
// not url, because mount middleware changes it
62-
// request to /payments/common/order in case of error is logged as /order
6364
url: ctx.originalUrl,
6465
status: status,
6566
timeDuration: Date.now() - start
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
var thumb = require('client/image').thumb;
2+
var PhotoLoadWidget = require('../lib/photoLoadWidget');
3+
var notification = require('client/notification');
4+
5+
function init() {
6+
7+
initFeedbackForm();
8+
9+
}
10+
11+
12+
13+
14+
function initFeedbackForm() {
15+
16+
var feedbackForm = document.querySelector('[data-feedback-form]');
17+
18+
feedbackForm.onsubmit = function(event) {
19+
var starInput = [].filter.call(
20+
feedbackForm.querySelectorAll('[name="stars"]'),
21+
function(input) { return input.checked; }
22+
);
23+
24+
if (!starInput.length) {
25+
// actually an error, but let's show it nicely
26+
new notification.Success("Поставьте, пожалуйста, курсу оценку.");
27+
document.querySelector('.rating-chooser').parentNode.scrollIntoView();
28+
window.scrollBy(0, -100);
29+
event.preventDefault();
30+
return;
31+
}
32+
33+
if (!feedbackForm.elements.content.value) {
34+
new notification.Error("Вы забыли написать текст отзыва.");
35+
feedbackForm.elements.content.scrollIntoView();
36+
window.scrollBy(0, -100);
37+
event.preventDefault();
38+
return;
39+
}
40+
41+
};
42+
43+
44+
var photoWidgetElem = feedbackForm.querySelector('[data-photo-load]');
45+
46+
new PhotoLoadWidget({
47+
elem: photoWidgetElem,
48+
onSuccess: function(imgurImage) {
49+
feedbackForm.querySelector('.course-feedback__userpic-img').src = thumb(imgurImage.link, 86, 86);
50+
photoWidgetElem.querySelector('i').style.backgroundImage = `url('${thumb(imgurImage.link, 64, 64)}')`;
51+
photoWidgetElem.querySelector('input').value = imgurImage.imgurId;
52+
},
53+
onLoadStart: function() {
54+
photoWidgetElem.classList.add('modal-overlay_light');
55+
feedbackForm.querySelector('button[type="submit"]').disabled = true;
56+
},
57+
onLoadEnd: function() {
58+
photoWidgetElem.classList.remove('modal-overlay_light');
59+
feedbackForm.querySelector('button[type="submit"]').disabled = false;
60+
}
61+
});
62+
}
63+
64+
init();
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
var promptSquarePhoto = require('photoCut').promptSquarePhoto;
2+
var notification = require('client/notification');
3+
var xhr = require('client/xhr');
4+
var Spinner = require('client/spinner');
5+
6+
function PhotoLoadWidget({elem, onSuccess, onLoadStart, onLoadEnd}) {
7+
var link = elem.querySelector('a');
8+
var photoDiv = elem.querySelector('i');
9+
var input = elem.querySelector('input');
10+
11+
link.onclick = function(e) {
12+
e.preventDefault();
13+
promptSquarePhoto({
14+
minSize: 160,
15+
onSuccess: uploadPhoto
16+
});
17+
};
18+
19+
20+
var spinner = new Spinner({
21+
elem: photoDiv,
22+
size: 'small'
23+
});
24+
25+
function uploadPhoto(file) {
26+
27+
var formData = new FormData();
28+
formData.append("photo", file);
29+
30+
var request = xhr({
31+
method: 'POST',
32+
url: '/imgur/upload',
33+
body: formData,
34+
noDocumentEvents: true,
35+
normalStatuses: [200, 400]
36+
});
37+
38+
request.addEventListener('loadstart', function() {
39+
spinner.start();
40+
onLoadStart();
41+
});
42+
request.addEventListener('loadend', function() {
43+
spinner.stop();
44+
onLoadEnd();
45+
});
46+
47+
request.addEventListener('fail', (event) => {
48+
new notification.Error("Ошибка загрузки: " + event.reason);
49+
});
50+
51+
request.addEventListener('success', (event) => {
52+
if (request.status == 400) {
53+
new notification.Error("Неверный тип файла или изображение повреждено.");
54+
} else {
55+
onSuccess(event.result);
56+
}
57+
});
58+
59+
}
60+
61+
62+
}
63+
64+
module.exports = PhotoLoadWidget;
Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
var thumb = require('client/image').thumb;
2-
var promptSquarePhoto = require('photoCut').promptSquarePhoto;
3-
var notification = require('client/notification');
4-
var xhr = require('client/xhr');
5-
var Spinner = require('client/spinner');
2+
var PhotoLoadWidget = require('../lib/photoLoadWidget');
63

74
function init() {
85

@@ -15,75 +12,18 @@ function initPhotoLoadWidget() {
1512
var photoWidgetElem = document.querySelector('[data-photo-load]');
1613
if (!photoWidgetElem) return;
1714
new PhotoLoadWidget({
18-
elem: photoWidgetElem
15+
elem: photoWidgetElem,
16+
onSuccess: function(imgurImage) {
17+
photoWidgetElem.querySelector('i').style.backgroundImage = `url('${thumb(imgurImage.link, 64, 64)}')`;
18+
photoWidgetElem.querySelector('input').value = imgurImage.imgurId;
19+
},
20+
onLoadStart: function() {
21+
photoWidgetElem.classList.add('modal-overlay_light');
22+
},
23+
onLoadEnd: function() {
24+
photoWidgetElem.classList.remove('modal-overlay_light');
25+
}
1926
});
2027
}
2128

22-
function PhotoLoadWidget({elem}) {
23-
var link = elem.querySelector('a');
24-
var photoDiv = elem.querySelector('i');
25-
var input = elem.querySelector('input');
26-
27-
link.onclick = function(e) {
28-
e.preventDefault();
29-
promptSquarePhoto({
30-
minSize: 160,
31-
onSuccess: uploadPhoto
32-
});
33-
};
34-
35-
36-
var spinner = new Spinner({
37-
elem: photoDiv,
38-
size: 'small'
39-
});
40-
41-
function uploadPhoto(file) {
42-
43-
var formData = new FormData();
44-
formData.append("photo", file);
45-
46-
var request = xhr({
47-
method: 'POST',
48-
url: '/imgur/upload',
49-
body: formData,
50-
normalStatuses: [200, 400]
51-
});
52-
53-
request.addEventListener('loadstart', onLoadStart);
54-
request.addEventListener('loadend', onLoadEnd);
55-
56-
request.addEventListener('fail', (event) => {
57-
new notification.Error("Ошибка загрузки: " + event.reason);
58-
});
59-
60-
request.addEventListener('success', (event) => {
61-
if (request.status == 400) {
62-
new notification.Error("Неверный тип файла или изображение повреждено.");
63-
} else {
64-
onSuccess(event.result);
65-
}
66-
});
67-
68-
}
69-
70-
71-
function onSuccess(imgurImage) {
72-
photoDiv.style.backgroundImage = `url('${thumb(imgurImage.link, 64, 64)}')`;
73-
input.value = imgurImage.imgurId;
74-
}
75-
76-
77-
function onLoadStart() {
78-
spinner.start();
79-
elem.classList.add('modal-overlay_light');
80-
}
81-
82-
function onLoadEnd() {
83-
spinner.stop();
84-
elem.classList.remove('modal-overlay_light');
85-
}
86-
}
87-
88-
8929
init();

handlers/courses/controller/coursesByUser.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
const CourseInvite = require('../models/courseInvite');
4+
const CourseParticipant = require('../models/courseParticipant');
45
const CourseGroup = require('../models/courseGroup');
56

67
/**
@@ -24,10 +25,20 @@ exports.get = function*(next) {
2425
}).populate('group').exec();
2526

2627
// plus groups where participates
27-
var groups = yield CourseGroup.find({
28-
'participants.user': user._id
28+
var participant = yield CourseParticipant.findOne({
29+
user: user._id
2930
}).exec();
3031

32+
var groups;
33+
if (participant) {
34+
// plus groups where participates
35+
groups = yield CourseGroup.find({
36+
participants: participant._id
37+
}).exec();
38+
} else {
39+
groups = [];
40+
}
41+
3142
this.body = [];
3243

3344
for (let i = 0; i < invites.length; i++) {

0 commit comments

Comments
 (0)