-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreferences.js
282 lines (225 loc) · 6.41 KB
/
preferences.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
271
272
273
274
275
276
277
278
279
280
281
282
var selectedTracks=[];
function hoverCover(){
//$(this).parent().css("box-shadow", "10px 10px 3px #888");
$(this).addClass("coverHovered");
//css("width", "220px");
//$(this).css("height", "220px");
}
function leaveCover(){
//$(this).parent().css("box-shadow", "0px 0px 0px #000000");
$(this).removeClass("coverHovered");
//$(this).css("width", "200px");
//$(this).css("height", "200px");
}
function selectTrack(){
if($(this).hasClass("selected")){
$(this).removeClass("selected");
$(this).find("img").remove();
removeInLikeList($(this).attr('data-uri'));
}
else{
var v = $("<img>");
v.attr("src", "selected.png");
$(this).addClass("selected");
$(this).append(v);
addToLikeList($(this).attr('data-uri'),
{
releasedate: $(this).attr('data-releasedate'),
name: $(this).attr('data-name'),
album: $(this).attr('data-album'),
genre: $(this).attr('data-genre')
});
}
}
function open() {
$(".lightbox").off('click', '.album');
$(".lightbox").off('mouseover', '.cover');
$(".lightbox").off('mouseout', '.cover');
$(".lightbox").on('click', '.close', close);
$(".lightbox").on('click', 'li', selectTrack);
$(this).css({
position: 'fixed',
display: 'block',
color: 'white',
boxShadow: "0px 0px 0px #000000",
width: '600px',
height: 'auto',
zIndex:'9999'
});
$(this).find(".cover").removeClass("coverHovered");
$(".album").not(this).find('.cover').css(
{
opacity:0.3,
filter: 'grayscale(100%)'
}
)
$(this).css('background-color', 'black');
$(this).find(".cover").stop().animate({
width :'220px',
height: '220px',
marginTop: '0px',
marginLeft:'0px',
marginRight:'0px',
marginBottom:'0px'
});
$(this).stop().animate({
paddingRight: '10px',
width: '600px',
height: 'auto',
left :'50%',
top: '50%',
marginTop: '-200px',
marginLeft: '-220px'
},function(){
$(this).find(".secret").show();
});
return false;
}
function close () {
$(".secret").removeAttr("style");
$(".cover").removeAttr("style");
$(".album").removeAttr("style");
$(".lightbox").on('click', '.album', open);
$(".lightbox").on('mouseover', '.cover', hoverCover);
$(".lightbox").on('mouseout', '.cover', leaveCover);
$(".lightbox").off('click', '.close');
$(".lightbox").off('click', 'li');
return false;
}
// fonction qui sert à rajouter une track dans le cookie
// avec les track likées par la personne
function addToLikeList(track, params)
{
var cookie = {};
if (typeof Cookies.get('likes') != 'undefined') {
// si il y a des déjà des choses likées
var cookie = JSON.parse(Cookies.get('likes'));
}
cookie[track] = params;
Cookies.set('likes', cookie);
}
// fonction qui sert à get les track qui ont été likées
// dans le passé
function getLikeList()
{
if (typeof Cookies.get('likes') != 'undefined') {
return JSON.parse(Cookies.get('likes'));
}
else {
console.log('no liked tracks were found');
return {};
}
}
// fonction qui sert à remove une track
// directement avec l'uri de la track
function removeInLikeList(track)
{
if (typeof Cookies.get('likes') != 'undefined') {
var cookie = JSON.parse(Cookies.get('likes'));
if (typeof cookie[track] != 'undefined')
{
delete cookie[track];
}
Cookies.set('likes', cookie);
}
}
/* Display tastes of the user based on the data contained on the cookie */
function displayLikes()
{
$('a.remove_from_tastes').off('click');
$('#tastes').empty();
var table = $('<table>');
table.addClass("table").addClass("table-hover");
var likes = getLikeList();
for (el in likes)
{
var tr = $('<tr>');
var td1 = $('<td>');
var td2 = $('<td>');
var a = $('<a />');
//a.attr("href", "#");
a.addClass('remove_from_tastes');
a.attr('data-uri', el);
a.css("cursor", "pointer");
a.text('Remove');
td1.text(likes[el].name);
td2.append(a);
tr.append(td1).append(td2);
table.append(tr);
}
$('#tastes').append(table);
$('a.remove_from_tastes').on('click', function() {
removeInLikeList($(this).data('uri'));
$(this).parent().parent().hide(500, function(){$(this).remove();});
});
}
/* Display the recommendations */
function displayRecommendations()
{
var the_length = 8;
requetesSparql['recommandation-jamendo'](the_length)
.execute(function(res)
{
console.log(res);
for (el in res)
{
var album = new Album();
album.init_from_jamendo(el, res);
$('#recommendations').append(album.generateHTML());
}
});
}
function displayRecommendationsDBPedia()
{
// vide
$('#recommendations-dbpedia').empty();
var tracks = JSON.parse(Cookies.get('likes'));
var uris = Object.keys(tracks);
var genre;
var countGenres= {};
var dates = [];
for (t in tracks){
genre = tracks[t].genre;
if (countGenres[genre]) countGenres[genre] += 1;
else countGenres[genre] = 1
releaseDate = tracks[t].releasedate;
dates.push(new Date(releaseDate));
console.log(releaseDate);
console.log(genre);
}
genre = Object.keys(countGenres).reduce(function(a, b){ return countGenres[a] > countGenres[b] ? a : b });
var maxDate=new Date(Math.max.apply(null,dates));
var minDate=new Date(Math.min.apply(null,dates));
requetesSparql['recommandation-dbpedia'](genre, minDate.toISOString(), maxDate.toISOString())
.execute(function(res)
{
console.log(res);
var table = $("<table>");
table.addClass("table").addClass("table-hover");
var tracks={};
for (el in res)
{
if (res[el].track)
tracks[res[el].track.uri] = res[el];
}
for(t in tracks){
var album = new Album();
album.init_from_dbpedia(t, tracks);
var tr = $('<tr>');
var td = $('<td>');
tr.append(td);
td.append(album.getDescription());
table.append(tr);
}
$('#recommendations-dbpedia').append(table);
});
}
$(document).ready(function(){
$(".lightbox").on('click', '.album', open);
$(".lightbox").on('mouseover', '.cover', hoverCover);
$(".lightbox").on('mouseout', '.cover', leaveCover);
displayLikes();
$.featherlight.defaults.afterClose = function() { displayLikes(); displayRecommendationsDBPedia(); };
displayRecommendations();
displayRecommendationsDBPedia();
});