author | Chloe Laisne <chloe.laisne@gmail.com> |
Tue, 28 Jun 2016 22:11:38 +0200 | |
changeset 210 | 08ad36c693b1 |
parent 202 | 0446e07981db |
child 233 | 0ff47a9c5da2 |
permissions | -rw-r--r-- |
48
9ef0952033e0
add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
1 |
import Ember from 'ember'; |
9ef0952033e0
add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
2 |
|
197 | 3 |
export default Ember.Component.extend({ |
120 | 4 |
|
197 | 5 |
filter: Ember.inject.service(), |
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
6 |
|
202
0446e07981db
Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents:
197
diff
changeset
|
7 |
dateObserver: Ember.observer('filter.date', function() { |
0446e07981db
Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents:
197
diff
changeset
|
8 |
var self = this; |
0446e07981db
Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents:
197
diff
changeset
|
9 |
this.$('li').removeClass('highlighted'); |
0446e07981db
Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents:
197
diff
changeset
|
10 |
this.get('filter.date').forEach(function(date) { |
0446e07981db
Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents:
197
diff
changeset
|
11 |
self.$('li#' + date).addClass('highlighted'); |
0446e07981db
Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents:
197
diff
changeset
|
12 |
}); |
0446e07981db
Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents:
197
diff
changeset
|
13 |
}), |
0446e07981db
Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents:
197
diff
changeset
|
14 |
|
195
9d083636bd99
Layout and style of the /chronologie endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
15 |
elementId: "chrono-table", |
9d083636bd99
Layout and style of the /chronologie endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
16 |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
17 |
didInsertElement: function(){ |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
18 |
var self = this; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
19 |
|
197 | 20 |
if (this.get('filter').get('date') !== null){ |
21 |
this.highlightQuery(this.get('filter').get('date')); |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
22 |
} |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
23 |
|
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
24 |
var isMouseDown = false, |
202
0446e07981db
Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents:
197
diff
changeset
|
25 |
isHighlighted; |
77
0889740f79c2
on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents:
72
diff
changeset
|
26 |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
27 |
Ember.$("#chrono-table li").mousedown(function () { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
28 |
isMouseDown = true; |
197 | 29 |
var dates = self.get('filter').get('date').toArray(); |
30 |
var index = dates.indexOf(parseInt(Ember.$(this).attr('id'))); |
|
31 |
if(index === -1) { |
|
32 |
dates.push(parseInt(Ember.$(this).attr('id'))); |
|
202
0446e07981db
Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents:
197
diff
changeset
|
33 |
isHighlighted = true; |
197 | 34 |
} else { |
35 |
dates.splice(index, 1); |
|
202
0446e07981db
Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents:
197
diff
changeset
|
36 |
isHighlighted = false; |
197 | 37 |
} |
38 |
self.get('filter').set('date', dates); |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
39 |
return false; // prevent text selection |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
40 |
}).mouseover(function () { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
41 |
if (isMouseDown) { |
197 | 42 |
if(Ember.$(this).hasClass("highlighted") !== isHighlighted) { |
43 |
var dates = self.get('filter').get('date').toArray(); |
|
44 |
var index = dates.indexOf(parseInt(Ember.$(this).attr('id'))); |
|
45 |
if(index === -1) { |
|
46 |
dates.push(parseInt(Ember.$(this).attr('id'))); |
|
47 |
} else { |
|
48 |
dates.splice(index, 1); |
|
49 |
} |
|
50 |
self.get('filter').set('date', dates); |
|
51 |
} |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
52 |
} |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
53 |
}).bind("selectstart", function () { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
54 |
return false; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
55 |
}); |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
56 |
|
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
57 |
Ember.$(document).mouseup(function () { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
58 |
isMouseDown = false; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
59 |
}); |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
60 |
}, |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
61 |
|
197 | 62 |
highlightQuery: function(dates){ |
63 |
dates.map(function(date){ |
|
64 |
Ember.$("#" + date).toggleClass("highlighted", true); |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
65 |
}); |
77
0889740f79c2
on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents:
72
diff
changeset
|
66 |
} |
0889740f79c2
on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents:
72
diff
changeset
|
67 |
|
48
9ef0952033e0
add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
68 |
}); |