Skip to content

Commit cb1931c

Browse files
committed
course: access to group logs
1 parent e7837e5 commit cb1931c

8 files changed

Lines changed: 62 additions & 7 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
var path = require('path');
4+
var config = require('config');
5+
var fs = require('mz/fs');
6+
7+
// Group info for a participant, with user instructions on how to login
8+
exports.get = function*() {
9+
10+
let group = this.groupBySlug;
11+
12+
let logName = this.params.logName.replace(/[^-.\d\w]/g, '');
13+
14+
let filePath = path.join(config.jabberLogsRoot, group.webinarId, logName + '.html');
15+
16+
let exists = yield fs.exists(filePath);
17+
if (!exists) {
18+
this.throw(404);
19+
}
20+
21+
this.type = 'text/html; charset=utf-8';
22+
this.body = fs.createReadStream(filePath);
23+
24+
};
25+

handlers/courses/controller/groupMaterials.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ exports.get = function*() {
4444
});
4545
}
4646

47+
let logs;
48+
try {
49+
logs = yield fs.readdir(config.jabberLogsRoot + '/' + group.webinarId);
50+
} catch(e) { // no logs
51+
logs = [];
52+
}
53+
54+
logs = logs.sort().map(file => ({
55+
title: file,
56+
link: `/courses/groups/${group.slug}/logs/${file.replace(/\.html$/, '')}`
57+
}));
58+
59+
this.locals.chatLogs = logs;
60+
61+
4762
this.body = this.render('groupMaterials');
4863
};
4964

handlers/courses/router.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ router.get('/groups/:groupBySlug/materials', mustBeParticipantOrTeacher, require
3131
router.get('/groups/:groupBySlug/participants-info', mustBeTeacherOrAdmin, require('./controller/participantsInfo').get);
3232
router.post('/groups/:groupBySlug/materials', mustBeTeacher, require('./controller/groupMaterials').post);
3333

34+
router.get('/groups/:groupBySlug/logs/:logName', mustBeParticipantOrTeacher, require('./controller/groupLogs').get);
35+
3436
// not groups/:groupBySlug/* url,
3537
// because the prefix /course/download must be constant for nginx to proxy *.zip to node
3638
router.get('/download/:groupBySlug/:filename', mustBeParticipantOrTeacher, require('./controller/groupMaterialsDownload').get);

handlers/courses/templates/groupMaterials.jade

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ block content
4444
+b('button').button._action.__submit(type="submit")
4545
+e('span').text Добавить
4646

47-
if materials.length
48-
+b.courses-materials
47+
+b.courses-materials
48+
49+
if materials.length
4950

5051
if participant
5152
+e('p').video-key
@@ -68,10 +69,17 @@ block content
6869
+e('p').note!= material.comment
6970
+e('td').size= material.size
7071
+e('td').added= moment(material.created).format('DD.MM.YYYY')
71-
else
72-
+b.notification._message._info
73-
+e.content Материалов пока нет, будут доступны позже.
72+
else
73+
+b.notification._message._info
74+
+e.content Материалов пока нет, будут доступны позже.
75+
7476

77+
if chatLogs.length
78+
h2 Логи чата
7579

80+
+e('ul').chat-list
81+
each item in chatLogs
82+
+e('li').chat-list-item
83+
a(href=item.link)= item.title
7684

7785

jabber-logs/.gitkeep

Whitespace-only changes.

modules/config/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ var config = module.exports = {
110110
appId: secret.openexchangerates.appId
111111
},
112112

113-
jb: {
113+
jb: {
114114
email: env.NODE_ENV == 'production' ? secret.jb.email : '[email protected]'
115115
},
116116

@@ -159,8 +159,8 @@ var config = module.exports = {
159159
publicRoot: path.join(process.cwd(), 'public'),
160160
// private files, for expiring links, not directly accessible
161161
downloadRoot: path.join(process.cwd(), 'download'),
162+
jabberLogsRoot: path.join(process.cwd(), 'jabber-logs'),
162163
archiveRoot: path.join(process.cwd(), 'archive'),
163-
courseRoot: path.join(process.cwd(), 'course'),
164164
tmpRoot: path.join(process.cwd(), 'tmp'),
165165
localesRoot: path.join(process.cwd(), 'locales'),
166166
// js/css build versions

modules/iprotect/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ function* protect(name, filePath, targetDir) {
9898
});
9999
};
100100

101+
yield* del(name);
102+
101103
fs.unlinkSync(protectedPath); // strange bluebird/cls warning if I yield unlink
102104

103105
}

styles/blocks/courses-materials/courses-materials.styl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@
5050
&__line:hover &__delete-action
5151
opacity 1
5252

53+
54+
&__chat-list-item
55+
text-align left

0 commit comments

Comments
 (0)