| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 | 2×
2×
2×
2×
2×
2×
2×
42×
42×
42×
42×
336×
42×
42×
210×
210×
42×
21×
21×
21×
21×
105×
21×
21×
21×
168×
21×
21×
21×
168×
2×
2×
2×
| var CrudConfig, StudentDashboardConfig, TimeStore, _, actions, arrayToSentence, extendConfig, makeSimpleStore, moment, ref, ref1, store;
ref = require('./helpers'), CrudConfig = ref.CrudConfig, makeSimpleStore = ref.makeSimpleStore, extendConfig = ref.extendConfig;
TimeStore = require('./time').TimeStore;
_ = require('underscore');
moment = require('moment');
arrayToSentence = function(arry) {
if (arry.length > 1) {
return arry.slice(0, arry.length - 1).join(', ') + ' & ' + arry.slice(-1);
} else {
return arry[0];
}
};
StudentDashboardConfig = {
exports: {
eventsByWeek: function(courseId) {
var data, events, sorted, tasks, weekId, weeks;
data = this._get(courseId);
tasks = data.tasks || [];
weeks = _.groupBy(tasks, function(event) {
return moment(event.due_at).startOf('isoweek').format('YYYYww');
});
sorted = {};
for (weekId in weeks) {
events = weeks[weekId];
sorted[weekId] = _.sortBy(events, 'due_at');
}
return sorted;
},
pastEventsByWeek: function(courseId) {
var thisWeek, weeks;
weeks = this.exports.eventsByWeek.call(this, courseId);
thisWeek = moment(TimeStore.getNow()).startOf('isoweek').format('YYYYww');
return _.pick(weeks, function(events, week) {
return week < thisWeek;
});
},
weeklyEventsForDay: function(courseId, day) {
var events;
events = this.exports.eventsByWeek.call(this, courseId);
return events[moment(day).startOf('isoweek').format('YYYYww')] || [];
},
canWorkTask: function(event) {
return new Date(event.opens_at) < TimeStore.getNow();
},
upcomingEvents: function(courseId, now) {
var ref1;
Iif (now == null) {
now = TimeStore.getNow();
}
return _.chain(((ref1 = this._get(courseId)) != null ? ref1.tasks : void 0) || []).filter(function(event) {
return new Date(event.due_at) > now;
}).sortBy('due_at').value();
},
pastDueEvents: function(courseId, now) {
var ref1;
if (now == null) {
now = TimeStore.getNow();
}
return _.chain(((ref1 = this._get(courseId)) != null ? ref1.tasks : void 0) || []).filter(function(event) {
return new Date(event.due_at) < now;
}).sortBy('due_at').value();
}
}
};
extendConfig(StudentDashboardConfig, new CrudConfig());
ref1 = makeSimpleStore(StudentDashboardConfig), actions = ref1.actions, store = ref1.store;
module.exports = {
StudentDashboardActions: actions,
StudentDashboardStore: store
};
|