author | Chloe Laisne <chloe.laisne@gmail.com> |
Tue, 05 Jul 2016 16:53:04 +0200 | |
changeset 228 | a2497a2b6224 |
parent 227 | 5c9250f55f4b |
child 233 | 0ff47a9c5da2 |
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, |
|
15 |
theme: null, |
|
16 |
||
198 | 17 |
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
|
18 |
setFilter: Ember.observer('discourse', 'language', 'location', 'theme', function(sender, key) { |
197 | 19 |
this.get('filter').set(key, this.get(key)); |
196 | 20 |
}), |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
21 |
filterObserver: Ember.observer('filter.discourse', 'filter.language', 'filter.location', 'filter.theme', function(sender, key) { |
197 | 22 |
key = key.split('.').pop(); |
23 |
this.set(key, this.get('filter').get(key)); |
|
196 | 24 |
}), |
25 |
||
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
26 |
setDateFilter: Ember.observer('date', function(sender, key) { |
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
27 |
var intervals = []; |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
28 |
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
|
29 |
interval = interval.split('-'); |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
30 |
if(interval.length > 1) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
31 |
var array = []; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
32 |
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
|
33 |
array.push(parseInt(i)); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
34 |
} |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
35 |
interval = array; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
36 |
} else { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
37 |
interval = parseInt(interval); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
38 |
} |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
39 |
intervals = intervals.concat(interval); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
40 |
}); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
41 |
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
|
42 |
}), |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
43 |
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
|
44 |
key = key.split('.').pop(); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
45 |
var intervals = []; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
46 |
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
|
47 |
var isInterval = false; |
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
48 |
intervals.forEach(function(interval) { |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
49 |
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
|
50 |
interval.push(date); |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
51 |
isInterval = true; |
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
52 |
} |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
53 |
}); |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
54 |
if (!isInterval) { |
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
55 |
intervals.push([date]); |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
56 |
} |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
57 |
}); |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
58 |
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
|
59 |
if(interval.length > 1) { |
204
dd969e178944
Fix linting, remove logs and dead code
Chloe Laisne <chloe.laisne@gmail.com>
parents:
203
diff
changeset
|
60 |
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
|
61 |
} else { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
62 |
intervals[index] = interval.toString(); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
63 |
} |
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 |
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
|
66 |
this.set(key, intervals); |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
67 |
} |
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
68 |
}), |
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
69 |
|
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
70 |
arraysEqual: function(a, b) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
71 |
if (a === b) { |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
72 |
return true; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
73 |
} |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
74 |
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
|
75 |
return false; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
76 |
} |
204
dd969e178944
Fix linting, remove logs and dead code
Chloe Laisne <chloe.laisne@gmail.com>
parents:
203
diff
changeset
|
77 |
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
|
78 |
return false; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
79 |
} |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
80 |
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
|
81 |
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
|
82 |
return false; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
83 |
} |
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 |
return true; |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
86 |
}, |
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
87 |
|
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
88 |
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
|
89 |
|
228
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
90 |
itemObserver: 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
|
91 |
var self = this; |
228
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
92 |
this.store.findRecord('document', this.get('player').get('item'), { reload: true }).then(function(model){ |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
93 |
self.get('player').set('model', model); |
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
94 |
}); |
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 |
|
228
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
97 |
notice: null, |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
98 |
noticeModel: null, |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
99 |
|
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
100 |
noticeObserver: Ember.observer('notice', function() { |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
101 |
var self = this; |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
102 |
if (this.get('notice')) { |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
103 |
this.store.findRecord('document', this.get('notice'), { reload: true }).then(function(model){ |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
104 |
self.set('noticeModel', model); |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
105 |
}); |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
106 |
} |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
107 |
}), |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
108 |
noticeModelObserver: Ember.observer('noticeModel', function() { |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
109 |
if (!this.get('noticeModel')) { |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
110 |
this.set('notice', null); |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
111 |
} |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
112 |
}), |
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
113 |
|
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
114 |
|
a2497a2b6224
Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents:
227
diff
changeset
|
115 |
|
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
116 |
init: function() { |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
117 |
this._super(...arguments); |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
118 |
this.get('player'); |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
119 |
}, |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
204
diff
changeset
|
120 |
|
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
121 |
actions: { |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
122 |
|
190
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
123 |
changeDocument: function(docDirection){ |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
124 |
var direction = (docDirection === "next") ? 1 : -1; |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
125 |
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
|
126 |
if ( currentObject !== 'undefined'){ |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
127 |
var index = this.get("filteredDocuments").indexOf(currentObject); |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
128 |
if ( typeof(this.get("filteredDocuments").objectAt(index+direction)) !== 'undefined'){ |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
129 |
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
|
130 |
} |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
131 |
} |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
132 |
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
|
133 |
}, |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
134 |
play: function(item){ |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
135 |
this.set("currentId", item.id); |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
136 |
} |
226ae8f2e8e9
JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
137 |
|
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
138 |
} |
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
|
139 |
}); |