author | Chloe Laisne <chloe.laisne@gmail.com> |
Tue, 05 Jul 2016 01:30:27 +0200 | |
changeset 227 | 5c9250f55f4b |
parent 224 | d284324358b2 |
child 228 | a2497a2b6224 |
permissions | -rw-r--r-- |
51
70dff07a76ff
add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
1 |
import Ember from 'ember'; |
70dff07a76ff
add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
2 |
|
70dff07a76ff
add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
3 |
export default Ember.Controller.extend({ |
94
62984937a062
- add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents:
91
diff
changeset
|
4 |
|
227
5c9250f55f4b
Basic notice logic from query parameters
Chloe Laisne <chloe.laisne@gmail.com>
parents:
224
diff
changeset
|
5 |
queryParams: ['location', 'date', 'notice', { |
197 | 6 |
language: 'langue', |
7 |
discourse: 'discours', |
|
8 |
theme: 'thematique' |
|
9 |
}], |
|
196 | 10 |
|
11 |
date: [], |
|
197 | 12 |
discourse: null, |
13 |
language: null, |
|
14 |
location: null, |
|
227
5c9250f55f4b
Basic notice logic from query parameters
Chloe Laisne <chloe.laisne@gmail.com>
parents:
224
diff
changeset
|
15 |
notice: null, |
197 | 16 |
theme: null, |
17 |
||
198 | 18 |
filter: Ember.inject.service(), |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
19 |
setFilter: Ember.observer('discourse', 'language', 'location', 'theme', function(sender, key) { |
197 | 20 |
this.get('filter').set(key, this.get(key)); |
196 | 21 |
}), |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
22 |
filterObserver: Ember.observer('filter.discourse', 'filter.language', 'filter.location', 'filter.theme', function(sender, key) { |
197 | 23 |
key = key.split('.').pop(); |
24 |
this.set(key, this.get('filter').get(key)); |
|
196 | 25 |
}), |
26 |
||
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
27 |
setDateFilter: Ember.observer('date', function(sender, key) { |
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
28 |
var intervals = []; |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
29 |
this.get(key).forEach(function(interval) { |
204
dd969e178944
Fix linting, remove logs and dead code
Chloe Laisne <chloe.laisne@gmail.com>
parents:
203
diff
changeset
|
30 |
interval = interval.split('-'); |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
31 |
if(interval.length > 1) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
32 |
var array = []; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
33 |
for(var i = interval[0]; i <= interval[1]; i++) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
34 |
array.push(parseInt(i)); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
35 |
} |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
36 |
interval = array; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
37 |
} else { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
38 |
interval = parseInt(interval); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
39 |
} |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
40 |
intervals = intervals.concat(interval); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
41 |
}); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
42 |
this.get('filter').set(key, intervals); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
43 |
}), |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
44 |
dateFilterObserver: Ember.observer('filter.date', function(sender, key) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
45 |
key = key.split('.').pop(); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
46 |
var intervals = []; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
47 |
this.get('filter').get(key).forEach(function(date) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
48 |
var isInterval = false; |
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
49 |
intervals.forEach(function(interval) { |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
50 |
if(interval.length && (interval.includes(date + 1) || interval.includes(date - 1))) { |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
51 |
interval.push(date); |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
52 |
isInterval = true; |
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
53 |
} |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
54 |
}); |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
55 |
if (!isInterval) { |
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
56 |
intervals.push([date]); |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
57 |
} |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
58 |
}); |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
59 |
intervals.forEach(function(interval, index) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
60 |
if(interval.length > 1) { |
204
dd969e178944
Fix linting, remove logs and dead code
Chloe Laisne <chloe.laisne@gmail.com>
parents:
203
diff
changeset
|
61 |
intervals[index] = interval.shift() + '-' + interval.pop(); |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
62 |
} else { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
63 |
intervals[index] = interval.toString(); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
64 |
} |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
65 |
}); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
66 |
if(!this.arraysEqual(this.get(key).toArray(), intervals)) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
67 |
this.set(key, intervals); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
68 |
} |
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
69 |
}), |
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
70 |
|
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
71 |
arraysEqual: function(a, b) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
72 |
if (a === b) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
73 |
return true; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
74 |
} |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
75 |
if (a == null || b == null) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
76 |
return false; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
77 |
} |
204
dd969e178944
Fix linting, remove logs and dead code
Chloe Laisne <chloe.laisne@gmail.com>
parents:
203
diff
changeset
|
78 |
if (a.length !== b.length) { |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
79 |
return false; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
80 |
} |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
81 |
for(var i = 0; i < a.length; ++i) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
82 |
if(a[i] !== b[i]) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
83 |
return false; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
84 |
} |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
85 |
} |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
86 |
return true; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
87 |
}, |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
88 |
|
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
89 |
player: Ember.inject.service(), |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
90 |
|
212
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
209
diff
changeset
|
91 |
itemIdObserver: Ember.observer('player.item', function() { |
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
92 |
var self = this; |
212
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
209
diff
changeset
|
93 |
this.store.findRecord('document', this.get('player').get('item'), { reload: true }).then(function(it){ |
f2c6080a73aa
Player backward/forward design logic
Chloe Laisne <chloe.laisne@gmail.com>
parents:
209
diff
changeset
|
94 |
self.get('player').set('model', it); |
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
95 |
}); |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
96 |
}), |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
97 |
|
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
98 |
init: function() { |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
99 |
this._super(...arguments); |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
100 |
this.get('player'); |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
101 |
}, |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
102 |
|
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
103 |
actions: { |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
104 |
|
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
105 |
changeDocument: function(docDirection){ |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
106 |
var direction = (docDirection === "next") ? 1 : -1; |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
107 |
var currentObject = this.get("filteredDocuments").findBy('id', this.get("currentItem").get('id')); |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
108 |
if ( currentObject !== 'undefined'){ |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
109 |
var index = this.get("filteredDocuments").indexOf(currentObject); |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
110 |
if ( typeof(this.get("filteredDocuments").objectAt(index+direction)) !== 'undefined'){ |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
111 |
return this.set('currentId', this.get("filteredDocuments").objectAt(index+direction).id); |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
112 |
} |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
113 |
} |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
114 |
return this.set('currentId', this.get('filteredDocuments').get('firstObject').id); |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
115 |
}, |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
116 |
play: function(item){ |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
117 |
this.set("currentId", item.id); |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
118 |
} |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
119 |
|
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
120 |
} |
51
70dff07a76ff
add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
121 |
}); |