Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Matthieu Haefele
website
Commits
157279d9
Commit
157279d9
authored
Jan 11, 2018
by
Marco Mancini
Browse files
indico_planning in Class
parent
8bb96baf
Changes
2
Hide whitespace changes
Inline
Side-by-side
content/js/indico.js
View file @
157279d9
...
...
@@ -4,10 +4,8 @@ function read(data){
}
function
read_indico_timetable
(
url
,
nb_event
)
{
$
.
ajax
(
{
type
:
"
GET
"
,
url
:
url
+
"
/export/timetable/
"
+
nb_event
+
"
.jsonp?callback=read?
"
,
...
...
@@ -22,7 +20,7 @@ function read_indico_timetable(url, nb_event)
complete
:
function
(
data
){
// console.log(data);
// parse(data.responseJSON, nb_event);
parse_indico_json
(
data
.
responseJSON
,
nb_event
);
IndicoPlanning
.
parse
(
data
.
responseJSON
,
nb_event
);
}
});
...
...
content/js/indico_planning.js
View file @
157279d9
"
use strict
"
;
// function parse_in(event){
// var output = '<dt class="indico_subevent">';
// output += ' <div class="indico_header">';
// output += ' <div class="indico_times">' + event.startDate.time + ' - ' + event.endDate.time + '</div>' ;
// output += ' <div class="indico_title">' + event.title + '</div>';
// output += ' </div>';
// output += ' <div class="indico_desc">' + event.description + '</div>';
// output += ' <div class="indico_loc">Lieu: ' + event.room + '</div>';
// return output;
// }
(
function
(
exports
){
// function parse_in(event){
// let output = '<dt class="indico_subevent">';
// output += ' <div class="indico_header">';
// output += ' <div class="indico_times">' + event.startDate.time + ' - ' + event.endDate.time + '</div>' ;
// output += ' <div class="indico_title">' + event.title + '</div>';
// output += ' </div>';
// output += ' <div class="indico_desc">' + event.description + '</div>';
// output += ' <div class="indico_loc">Lieu: ' + event.room + '</div>';
// return output;
// }
function
serialize_Indico
(
base
,
level
,
obj
)
{
// convert object into array
var
sortable
=
[];
for
(
var
key
in
obj
){
if
(
obj
[
key
].
hasOwnProperty
(
'
startDate
'
)){
var
newkey
=
base
+
'
:
'
+
obj
[
key
][
'
startDate
'
][
'
time
'
];
obj
[
key
].
level
=
level
;
sortable
.
push
([
newkey
,
obj
[
key
]]);
// each item is an array in format [key, value]
}
if
(
obj
[
key
].
hasOwnProperty
(
'
entries
'
)){
if
(
Object
.
keys
(
obj
[
key
][
'
entries
'
]).
length
!==
0
){
sortable
.
push
.
apply
(
sortable
,
serialize_Indico
(
base
,
level
+
1
,
obj
[
key
][
'
entries
'
]));
function
serialize_Indico
(
base
,
level
,
obj
)
{
// convert object into array
let
sortable
=
[];
for
(
let
key
in
obj
){
if
(
obj
[
key
].
hasOwnProperty
(
'
startDate
'
)){
let
newkey
=
base
+
'
:
'
+
obj
[
key
][
'
startDate
'
][
'
time
'
];
obj
[
key
].
level
=
level
;
sortable
.
push
([
newkey
,
obj
[
key
]]);
// each item is an array in format [key, value]
}
if
(
obj
[
key
].
hasOwnProperty
(
'
entries
'
)){
if
(
Object
.
keys
(
obj
[
key
][
'
entries
'
]).
length
!==
0
){
sortable
.
push
.
apply
(
sortable
,
serialize_Indico
(
base
,
level
+
1
,
obj
[
key
][
'
entries
'
]));
}
}
}
// sort items by value
sortable
.
sort
(
function
(
a
,
b
){
let
x
=
a
[
0
].
toLowerCase
(),
y
=
b
[
0
].
toLowerCase
();
return
x
<
y
?
-
1
:
x
>
y
?
1
:
0
;
});
return
sortable
;
// array in format [ [ key1, val1 ], [ key2, val2 ], ... ]
}
// sort items by value
sortable
.
sort
(
function
(
a
,
b
){
var
x
=
a
[
0
].
toLowerCase
(),
y
=
b
[
0
].
toLowerCase
();
return
x
<
y
?
-
1
:
x
>
y
?
1
:
0
;
});
return
sortable
;
// array in format [ [ key1, val1 ], [ key2, val2 ], ... ]
}
function
makeup_Indico
(
key
,
event_array
){
// level 0 : parsing days
moment
.
locale
(
'
fr
'
);
var
m
=
moment
(
key
,
[
'
YYYYMMDD
'
]).
format
(
'
dddd DD MMMM YYYY
'
);
function
makeup_Indico
(
key
,
event_array
){
// level 0 : parsing days
moment
.
locale
(
'
fr
'
);
let
m
=
moment
(
key
,
[
'
YYYYMMDD
'
]).
format
(
'
dddd DD MMMM YYYY
'
);
var
element
=
document
.
getElementById
(
'
indico
'
);
//let element = document.createElement('div');
let
element
=
document
.
getElementById
(
'
indico
'
);
//let element = document.createElement('div');
var
day
=
d3
.
select
(
'
#
'
+
element
.
id
)
.
append
(
'
div
'
)
.
attr
(
'
class
'
,
'
indico indico_event
'
)
.
attr
(
'
id
'
,
'
indico_
'
+
key
)
;
let
day
=
d3
.
select
(
'
#
'
+
element
.
id
)
.
append
(
'
div
'
)
.
attr
(
'
class
'
,
'
indico indico_event
'
)
.
attr
(
'
id
'
,
'
indico_
'
+
key
)
;
day
.
append
(
'
div
'
)
.
attr
(
'
class
'
,
'
indico_date
'
)
.
html
(
m
);
day
.
append
(
'
div
'
)
.
attr
(
'
class
'
,
'
indico_date
'
)
.
html
(
m
);
var
hours
=
day
.
selectAll
(
"
.indico
"
)
.
data
(
event_array
)
.
enter
()
.
append
(
"
div
"
)
.
attr
(
'
class
'
,
function
(
d
){
return
'
indico_
'
+
d
[
1
].
level
;
})
;
let
hours
=
day
.
selectAll
(
"
.indico
"
)
.
data
(
event_array
)
.
enter
()
.
append
(
"
div
"
)
.
attr
(
'
class
'
,
function
(
d
){
return
'
indico_
'
+
d
[
1
].
level
;
})
;
hours
.
append
(
'
div
'
)
.
attr
(
'
class
'
,
'
indico_header
'
)
.
html
(
function
(
d
){
let
start
=
d
[
1
].
startDate
.
time
.
split
(
'
:
'
);
start
.
pop
();
start
=
start
.
join
(
'
:
'
);
hours
.
append
(
'
div
'
)
.
attr
(
'
class
'
,
'
indico_header
'
)
.
html
(
function
(
d
){
let
start
=
d
[
1
].
startDate
.
time
.
split
(
'
:
'
);
start
.
pop
();
start
=
start
.
join
(
'
:
'
);
let
end
=
d
[
1
].
endDate
.
time
.
split
(
'
:
'
);
end
.
pop
();
end
=
end
.
join
(
'
:
'
);
let
end
=
d
[
1
].
endDate
.
time
.
split
(
'
:
'
);
end
.
pop
();
end
=
end
.
join
(
'
:
'
);
var
timeDiv
=
'
<div class="indico_times">
'
+
start
+
'
-
'
+
end
+
'
</div>
'
;
var
titleDiv
=
'
<div class="indico_title">
'
+
d
[
1
].
title
+
'
</div>
'
;
return
timeDiv
+
titleDiv
;})
;
let
timeDiv
=
'
<div class="indico_times">
'
+
start
+
'
-
'
+
end
+
'
</div>
'
;
let
titleDiv
=
'
<div class="indico_title">
'
+
d
[
1
].
title
+
'
</div>
'
;
return
timeDiv
+
titleDiv
;})
;
}
}
function
parse_indico_json
(
data
,
nb_event
){
var
event
=
data
.
results
[
nb_event
];
console
.
log
(
event
)
function
parse_indico_json
(
data
,
nb_event
){
let
event
=
data
.
results
[
nb_event
];
for
(
let
key
in
event
)
{
for
(
var
key
in
event
){
let
day_event
=
serialize_Indico
(
key
,
1
,
event
[
key
]);
//console.log(key,event[key])
makeup_Indico
(
key
,
day_event
);
}
}
var
day_event
=
serialize_Indico
(
key
,
1
,
event
[
key
]);
/* Exported fuctions */
exports
.
parse
=
parse_indico_json
;
makeup_Indico
(
key
,
day_event
);
//console.log(day_event)
}
}
})(
this
.
IndicoPlanning
=
{});
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment