forked from luxigo/rmllnow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rmllnow.js
271 lines (231 loc) · 7.34 KB
/
rmllnow.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
var sys = require('util'),
fs = require('fs'),
xml2js = require('xml2js');
var result=[];
var en={};
var parser = new xml2js.Parser();
parser.addListener('end',function(xml, error) {
if (!error) {
// console.log(JSON.stringify(xml));
// process.exit(0);
conferences_getCurrent(xml);
}
else {
console.error(error);
}
// console.log('Done.');
});
fs.readFile( 'prog.xml', function(err, data) {
if (!parser.parseString(data)) {
// console.log('xml2js: successfully parsed file.');
// }
// else {
console.error('xml2js: parse error: "%s"', parser.getError());
}
});
var _date;
var date;
var now;
var hours;
var minutes;
var thisday;
function twoDigits(a) {
return (parseInt(a,10)>9)?a:'0'+a;
}
function upDate() {
_date=new Date;
date=_date.getFullYear()+'-'+twoDigits(_date.getMonth()+1)+'-'+twoDigits(_date.getDate());
hours=_date.getHours();
minutes=_date.getMinutes();
now=_date.getDate()*1440*hours*60+minutes;
////// uncomment for testing (same date must be set in _rmllnow.js):
//date="2012-07-09";
//now=10*1440+11*60;
}
function conferences_getCurrent(prog) {
// console.log(sys.inspect(prog,false,100001));
upDate();
function event_process(event) {
event.date=thisday;
var day=parseInt(thisday.split('-')[2],10);
var start=event.start.split(':');
event.start_time=parseInt(start[0],10)*60+parseInt(start[1],10);
var duration=event.duration.split(':');
var duration_time=parseInt(duration[0],10)*60+parseInt(duration[1],10);
event.end_time=event.start_time+duration_time;
var end_hours=Math.floor((event.start_time+duration_time)/60).toString();
var end_minutes=(event.start_time+duration_time-end_hours*60).toString();
event.end=twoDigits(end_hours)+':'+twoDigits(end_minutes);
event.start_time+=day*1440;
event.end_time+=day*1440;
/*
if (now>=event.start_time && now<=event.end_time) {
result.push(event);
} else if (event.start_time-now < 120) {
result.push(event);
}
*/
result.push(event);
}
function room_process(room) {
var room_name=room['@'].name;
if (Array.isArray(room.event)) {
room.event.forEach(function(event) {
event_process(event);
});
} else {
event_process(room.event);
}
}
prog.day.forEach(function(day) {
thisday=day['@'].date;
if(day['@'].date==date) {
if (Array.isArray(day.room)) {
day.room.forEach(function(room) {
room_process(room);
});
} else {
room_process(day.room);
}
}
});
result.sort(function(a,b){
var delta=a.start_time-b.start_time;
if (!delta) {
return a.end_time-b.end_time;
} else {
return delta;
}
});
var html='<!DOCTYPE html>';
html+='<html>';
html+=HEAD();
html+='<body>';
html+=index(result);
html+=pages(result);
html+='</body>';
html+='</html>';
console.log(html);
// console.log(JSON.stringify(result));
}
function HEAD() {
var html='<head>';
html+='<meta charset="utf-8">';
html+='<meta name="viewport" content="width=device-width, initial-scale=1">';
html+='<title>RMLL Now !</title>';
html+='<link rel="shortcut icon" href="favicon.ico" />';
html+='<link rel="stylesheet" href="themes/rmll.css" />'
html+='<link rel="stylesheet" href="jquery.mobile.css" />';
html+='<link rel="stylesheet" href="rmllnow.css" />';
html+='<script src="jquery.js"></script>';
html+='<script src="_rmllnow.js"></script>';
html+='<script src="jquery.mobile.js"></script>';
html+='</head>';
return html;
}
function header(name,title) {
var html='<!-- start of page: #'+name+' -->';
html+='<div data-role="page" id="'+name+'">';
html+='<div data-role="header" data-position="fixed">';
if (name=='index') {
html+='<a href onclick="setTimeout(moreless,0)" id="moreless" data-position="left" data-role="button" data-icon="plus" data-iconpos="notext"></a>';
} else {
html+='<a href onclick="document.location.assign(\'#\')" id="home" data-position="left" data-role="button" data-icon="home" data-iconpos="notext"></a>';
html+='<a href id="next" onclick="next()" class="arrow_right" data-role="button" data-position="right" data-icon="arrow-r" data-iconpos="notext"></a>';
}
//html+='<span class="navbar" data-role="controlgroup" data-type="horizontal">';
//html+='<a href class="arrow_left" data-role="button" data-icon="arrow-l" data-iconpos="notext"></a>';
//html+='<a href class="arrow_up" data-role="button" data-icon="arrow-u" data-iconpos="notext"></a>';
//html+='</span>';
html+='<h1>'+title+'</h1>';
html+='</div><!-- /header -->';
html+='<div data-role="content">';
return html;
}
function index(list) {
var html=header('index',date);
html+="<div id=\"nothing\" data-role=\"popup\"><center>Aucun événement à afficher<center></div>";
html+=confListView(list);
html+=footer();
return html;
}
function confListView(list) {
var html='<ul data-role="listview" data-filter="true">';
list.forEach(function(event){
html+='<li data-date="'+event.date+'" data-start="'+event.start_time+'" data-end="'+event.end_time+'"><a href="#_'+event['@'].id+'">';
html+=event.title;
html+='<span class="details">'+(event_type[lang][event.type]?' ('+event_type[lang][event.type]+' — '+event.track+')':'('+event.track+')')+'</span>';
var who=intervenants(event,true);
html+=who.length?'<div class="who">'+who+'</div>':'';
html+='<div class="sec">';
html+=event.start+' - '+event.end+' ';
html+=event.room;
html+='</div>';
html+='</a></li>';
});
html+='</ul>';
return html;
}
var event_type={
fr : {
plen: 'Plénière',
conf: 'Conférence',
atl: 'Atelier',
ligtal: 'Lightning talk',
ag: 'Assemblée générale',
tabler: 'Table ronde'
},
en: {
plen: 'Plénière',
conf: 'Conférence',
atl: 'Atelier',
ligtal: 'Lightning talk',
ag: 'Assemblée générale',
tabler: 'Table ronde'
}
};
var lang='fr';
function t(txt) {
if (lang=="fr") return txt;
return en[txt]?en[txt]:txt;
}
function pages(list) {
var html='';
list.forEach(function(event){
html+=header('_'+event['@'].id,event.start+' - '+event.end);
html+='<h3 class="track">'+event.track+'</h3>';
html+='<h2>'+event.title+(event_type[lang][event.type]?' <span class="etype">('+event_type[lang][event.type]+')</span>':'')+'</h2>';
html+=intervenants(event);
html+=event.description.replace(/h3/g,'strong');
//var ho='<strong>Horaire:</strong> '+event.start+' - '+event.end+' <strong>— Salle:</strong> '+event.room;
// var ho='<strong>Horaire:</strong> '+event.start+' - '+event.end;
// html+=ho;
html+=footer(event.room);
});
return html;
}
function intervenants(event,notitle) {
var html='';
if (event.persons && event.persons.person) {
if (!Array.isArray(event.persons.person)) {
event.persons.person=[event.persons.person];
}
if (!notitle) html+='<p><span class="intervenants">Intervenant'+(event.persons.person.length>1?'s' :'')+' :</span> ';
event.persons.person.forEach(function(person,idx){
html+=(idx?', ':'')+person['#'];
});
html+='</p>';
}
return html;
}
function footer(title) {
var html='';
html+='</div><!-- /content -->';
if (title) {
html+='<div data-role="footer" data-position="fixed">';
html+='<h1>'+(title?title:'')+'</h1>';
html+='</div><!-- /footer -->';
}
html+='</div><!-- /page -->';
return html;
}