author | ymh <ymh.work@gmail.com> |
Fri, 16 Dec 2016 17:43:07 +0100 | |
changeset 474 | 245b4df137d3 |
parent 394 | 48458e099b05 |
child 495 | c71923e6fa2f |
permissions | -rw-r--r-- |
176
d1baf7ccecc8
Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
1 |
import Ember from 'ember'; |
394
48458e099b05
make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents:
338
diff
changeset
|
2 |
import _ from 'lodash/lodash'; |
176
d1baf7ccecc8
Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
3 |
|
d1baf7ccecc8
Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
4 |
export default Ember.Route.extend({ |
d1baf7ccecc8
Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
5 |
|
474 | 6 |
player: Ember.inject.service(), |
7 |
filter: Ember.inject.service(), |
|
338
4a3899b6a7ed
Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents:
337
diff
changeset
|
8 |
|
474 | 9 |
index: 0, |
10 |
limit: 40, |
|
11 |
sort: 'alphabetical', |
|
12 |
isFetching: false, |
|
237
69a9f3687902
Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
236
diff
changeset
|
13 |
|
474 | 14 |
themes: null, |
15 |
total: 0, |
|
237
69a9f3687902
Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
236
diff
changeset
|
16 |
|
474 | 17 |
model() { |
18 |
var filterQueryParams = _.clone(this.get('filter').get('queryParamsValues')); |
|
19 |
var promise = this.get('store').query('theme', _.merge(filterQueryParams, { |
|
20 |
'limit': this.get('limit'), |
|
21 |
'index': this.get('index'), |
|
22 |
'sort': this.get('sort') |
|
23 |
})); |
|
24 |
promise.then(response => { |
|
25 |
console.log("MODEL", response, response.get('content'), response.get('meta').total); |
|
26 |
this.set('themes', response.get('content')); |
|
27 |
this.set('total', response.get('meta').total); |
|
28 |
}); |
|
29 |
return promise; |
|
30 |
}, |
|
31 |
||
32 |
activate: function () { |
|
33 |
this.get('player').set('window', false); |
|
34 |
}, |
|
236
ac6928e86d14
Adapt theme query limit and offset and sorting order in fixtures
Chloe Laisne <chloe.laisne@gmail.com>
parents:
176
diff
changeset
|
35 |
|
474 | 36 |
actions: { |
37 |
||
38 |
loadMore: function() { |
|
39 |
if(this.get('isFetching') || (this.get('themes').length === this.get('total'))) { |
|
40 |
return; |
|
41 |
} |
|
42 |
this.set('isFetching', true); |
|
43 |
this.set('index', this.get('index') + 1); |
|
44 |
var filterQueryParams = _.clone(this.get('filter').get('queryParamsValues')); |
|
45 |
this.get('store').query('theme', _.merge(filterQueryParams, { |
|
46 |
'limit': this.get('limit'), |
|
47 |
'index': this.get('index'), |
|
48 |
'sort': this.get('sort') |
|
49 |
})).then(response => { // success |
|
50 |
this.get('themes').pushObjects(response.get('content')); |
|
51 |
this.set('isFetching', false); |
|
52 |
}, () => { // fail |
|
53 |
this.set('isFetching', false); |
|
54 |
}); |
|
237
69a9f3687902
Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
236
diff
changeset
|
55 |
}, |
69a9f3687902
Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
236
diff
changeset
|
56 |
|
474 | 57 |
resetIndexQueryParams: function () { |
58 |
this.set('index', 0); |
|
59 |
this.refresh(); |
|
338
4a3899b6a7ed
Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents:
337
diff
changeset
|
60 |
}, |
4a3899b6a7ed
Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents:
337
diff
changeset
|
61 |
|
474 | 62 |
setSortQueryparams: function (sort) { |
63 |
this.set('sort', sort); |
|
64 |
this.set('index', 0); |
|
65 |
this.refresh(); |
|
176
d1baf7ccecc8
Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
66 |
} |
d1baf7ccecc8
Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
67 |
|
474 | 68 |
} |
69 |
||
176
d1baf7ccecc8
Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff
changeset
|
70 |
}); |