author | Chloe Laisne <chloe.laisne@gmail.com> |
Tue, 14 Jun 2016 18:15:26 +0200 | |
changeset 189 | 21b30ee23191 |
parent 126 | e87a340711a4 |
child 190 | 226ae8f2e8e9 |
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({ |
95 | 4 |
queryParams: ['location', 'langue', 'discours', 'date', 'thematique', 'detail'], |
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
|
5 |
location: null, |
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
|
6 |
langue: null, |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
7 |
discours: null, |
81
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
8 |
date: [], |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
9 |
thematique: null, |
95 | 10 |
detail: null, |
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
|
11 |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
12 |
dateIntervals: Ember.computed('date', function() { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
13 |
var intervals = []; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
14 |
|
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
15 |
this.get('date').forEach(function(date) { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
16 |
var intervalDate = false; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
17 |
|
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
18 |
intervals.forEach(function(interval) { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
19 |
if(interval.length && (interval.includes(date + 1) || interval.includes(date - 1))) { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
20 |
interval.push(date); |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
21 |
intervalDate = true; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
22 |
} |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
23 |
}); |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
24 |
|
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
25 |
if (!intervalDate) { intervals.push([date]); } |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
26 |
}); |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
27 |
|
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
28 |
return intervals; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
29 |
}), |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
30 |
|
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
|
31 |
currentId: null, |
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
|
32 |
currentItem: Ember.computed('currentId', function() { |
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
|
33 |
Ember.$(".result-item").toggleClass("playing", false); |
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
|
34 |
if (this.get('currentId') === null){ |
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
|
35 |
return null; |
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
|
36 |
} |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
95
diff
changeset
|
37 |
Ember.$("#"+this.get('currentId').replace( /(:|\.|\[|\]|,)/g, "\\$1" )).toggleClass("playing", true); |
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
|
38 |
return this.store.findRecord('document', this.get('currentId')); |
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
|
39 |
}), |
95 | 40 |
modalItem: Ember.computed('detail', function() { |
41 |
return this.store.findRecord('document', this.get('detail')); |
|
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
|
42 |
}), |
91
acfeddc7821d
rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
89
diff
changeset
|
43 |
filteredDocuments: Ember.computed('location', 'langue', 'discours', 'date', 'thematique', 'model', function() { |
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
|
44 |
var location = this.get('location'); |
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
|
45 |
var langue = this.get('langue'); |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
46 |
var discours = this.get('discours'); |
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
47 |
var date = this.get('date'); |
81
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
48 |
var thematique = this.get('thematique'); |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
49 |
|
91
acfeddc7821d
rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
89
diff
changeset
|
50 |
var documents = this.get('model'); |
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
|
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
|
52 |
if (location) { |
91
acfeddc7821d
rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
89
diff
changeset
|
53 |
documents = documents.filterBy('spatial', location); |
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
|
54 |
} |
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
|
55 |
if (langue) { |
91
acfeddc7821d
rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
89
diff
changeset
|
56 |
documents = documents.filterBy('language', langue); |
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
|
57 |
} |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
58 |
if (discours) { |
91
acfeddc7821d
rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
89
diff
changeset
|
59 |
documents = documents.filterBy('type', discours); |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
60 |
} |
81
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
61 |
if (date.length > 0) { |
91
acfeddc7821d
rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
89
diff
changeset
|
62 |
var temp = documents; |
acfeddc7821d
rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
89
diff
changeset
|
63 |
documents.map(function(elt){ |
81
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
64 |
if (date.indexOf(elt.get('created')) === -1){ |
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
65 |
temp = temp.without(elt); |
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
66 |
} |
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
67 |
}); |
91
acfeddc7821d
rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
89
diff
changeset
|
68 |
documents = temp; |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
69 |
} |
81
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
70 |
if (thematique) { |
91
acfeddc7821d
rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
89
diff
changeset
|
71 |
documents = documents.filterBy('thematique', thematique); |
81
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
72 |
} |
91
acfeddc7821d
rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
89
diff
changeset
|
73 |
return documents; |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
74 |
}), |
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
75 |
|
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
76 |
actions: { |
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
77 |
|
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
78 |
deleteTag: function(key, value){ |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
79 |
var newValue = null; |
89
89be68e13215
fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents:
88
diff
changeset
|
80 |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
81 |
if (key === 'date'){ |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
82 |
newValue = []; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
83 |
Ember.$.each(this.get('date'), function(index, date){ |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
84 |
if(!value.includes(date)) { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
85 |
newValue.push(date); |
89
89be68e13215
fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents:
88
diff
changeset
|
86 |
} |
89be68e13215
fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents:
88
diff
changeset
|
87 |
}); |
81
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
88 |
} |
89
89be68e13215
fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents:
88
diff
changeset
|
89 |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
90 |
this.set(key, newValue); |
61
bbc8a582fcc3
introduce new action "play" to play the sounds and "details" to show more
nowmad@23.1.168.192.in-addr.arpa
parents:
58
diff
changeset
|
91 |
}, |
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
92 |
|
91
acfeddc7821d
rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
89
diff
changeset
|
93 |
changeDocument: function(docDirection){ |
acfeddc7821d
rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
89
diff
changeset
|
94 |
var direction = (docDirection === "next") ? 1 : -1; |
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
|
95 |
var currentObject = this.get("filteredDocuments").findBy('id', this.get("currentItem").get('id')); |
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
|
96 |
if ( currentObject !== 'undefined'){ |
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
|
97 |
var index = this.get("filteredDocuments").indexOf(currentObject); |
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
|
98 |
if ( typeof(this.get("filteredDocuments").objectAt(index+direction)) !== 'undefined'){ |
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
|
99 |
return this.set('currentId', this.get("filteredDocuments").objectAt(index+direction).id); |
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
100 |
} |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
101 |
} |
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
|
102 |
return this.set('currentId', this.get('filteredDocuments').get('firstObject').id); |
86
15ded106ef1a
add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents:
84
diff
changeset
|
103 |
}, |
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
104 |
play: function(item){ |
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
|
105 |
this.set("currentId", item.id); |
61
bbc8a582fcc3
introduce new action "play" to play the sounds and "details" to show more
nowmad@23.1.168.192.in-addr.arpa
parents:
58
diff
changeset
|
106 |
}, |
95 | 107 |
showMore: function(item){ |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
95
diff
changeset
|
108 |
var domItem = Ember.$("#"+item.id.replace( /(:|\.|\[|\]|,)/g, "\\$1" )); |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
95
diff
changeset
|
109 |
if (domItem.hasClass("show-more")){ |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
95
diff
changeset
|
110 |
domItem.toggleClass("show-more", false); |
61
bbc8a582fcc3
introduce new action "play" to play the sounds and "details" to show more
nowmad@23.1.168.192.in-addr.arpa
parents:
58
diff
changeset
|
111 |
} else{ |
95 | 112 |
Ember.$(".result-item").toggleClass("show-more", false); |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
95
diff
changeset
|
113 |
domItem.toggleClass("show-more", true); |
61
bbc8a582fcc3
introduce new action "play" to play the sounds and "details" to show more
nowmad@23.1.168.192.in-addr.arpa
parents:
58
diff
changeset
|
114 |
} |
84 | 115 |
}, |
116 |
toggleModal: function(item){ |
|
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
|
117 |
if (typeof(item) !== 'undefined'){ |
95 | 118 |
this.set("detail", item.id); |
119 |
} else { |
|
120 |
this.set("detail", null); |
|
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
|
121 |
} |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
122 |
} |
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
123 |
} |
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
|
124 |
}); |