author | ymh <ymh.work@gmail.com> |
Wed, 08 Feb 2017 15:25:24 +0100 | |
changeset 502 | 74fba571487e |
parent 495 | c71923e6fa2f |
child 532 | 1190ea937f2d |
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 |
this.set('themes', response.get('content')); |
|
26 |
this.set('total', response.get('meta').total); |
|
27 |
}); |
|
28 |
return promise; |
|
29 |
}, |
|
30 |
||
31 |
activate: function () { |
|
32 |
this.get('player').set('window', false); |
|
33 |
}, |
|
236
ac6928e86d14
Adapt theme query limit and offset and sorting order in fixtures
Chloe Laisne <chloe.laisne@gmail.com>
parents:
176
diff
changeset
|
34 |
|
495
c71923e6fa2f
Correct error when transitioning between thematiques tabs and others (bug #0025983) + correct scroll for themes
ymh <ymh.work@gmail.com>
parents:
474
diff
changeset
|
35 |
filterObserver: Ember.observer('filter.date.[]', 'filter.discourse.[]', 'filter.language', 'filter.location', 'filter.theme.[]', function() { |
c71923e6fa2f
Correct error when transitioning between thematiques tabs and others (bug #0025983) + correct scroll for themes
ymh <ymh.work@gmail.com>
parents:
474
diff
changeset
|
36 |
this.set('index', 0); |
c71923e6fa2f
Correct error when transitioning between thematiques tabs and others (bug #0025983) + correct scroll for themes
ymh <ymh.work@gmail.com>
parents:
474
diff
changeset
|
37 |
this.refresh(); |
c71923e6fa2f
Correct error when transitioning between thematiques tabs and others (bug #0025983) + correct scroll for themes
ymh <ymh.work@gmail.com>
parents:
474
diff
changeset
|
38 |
}), |
c71923e6fa2f
Correct error when transitioning between thematiques tabs and others (bug #0025983) + correct scroll for themes
ymh <ymh.work@gmail.com>
parents:
474
diff
changeset
|
39 |
|
474 | 40 |
actions: { |
41 |
||
42 |
loadMore: function() { |
|
43 |
if(this.get('isFetching') || (this.get('themes').length === this.get('total'))) { |
|
44 |
return; |
|
45 |
} |
|
46 |
this.set('isFetching', true); |
|
47 |
this.set('index', this.get('index') + 1); |
|
48 |
var filterQueryParams = _.clone(this.get('filter').get('queryParamsValues')); |
|
49 |
this.get('store').query('theme', _.merge(filterQueryParams, { |
|
50 |
'limit': this.get('limit'), |
|
51 |
'index': this.get('index'), |
|
52 |
'sort': this.get('sort') |
|
53 |
})).then(response => { // success |
|
54 |
this.get('themes').pushObjects(response.get('content')); |
|
55 |
this.set('isFetching', false); |
|
56 |
}, () => { // fail |
|
57 |
this.set('isFetching', false); |
|
58 |
}); |
|
237
69a9f3687902
Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
236
diff
changeset
|
59 |
}, |
69a9f3687902
Scrolling system in thematiques: more button and append data on scroll
Chloe Laisne <chloe.laisne@gmail.com>
parents:
236
diff
changeset
|
60 |
|
474 | 61 |
setSortQueryparams: function (sort) { |
62 |
this.set('sort', sort); |
|
63 |
this.set('index', 0); |
|
64 |
this.refresh(); |
|
495
c71923e6fa2f
Correct error when transitioning between thematiques tabs and others (bug #0025983) + correct scroll for themes
ymh <ymh.work@gmail.com>
parents:
474
diff
changeset
|
65 |
return false; |
c71923e6fa2f
Correct error when transitioning between thematiques tabs and others (bug #0025983) + correct scroll for themes
ymh <ymh.work@gmail.com>
parents:
474
diff
changeset
|
66 |
}, |
176
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 |
}); |