cms/app-client/app/routes/tabs/thematiques.js
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--
Correct themes visualisation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
     6
  player: Ember.inject.service(),
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
     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
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
     9
  index: 0,
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    10
  limit: 40,
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    11
  sort: 'alphabetical',
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    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
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    14
  themes: null,
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    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
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    17
  model() {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    18
    var filterQueryParams = _.clone(this.get('filter').get('queryParamsValues'));
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    19
    var promise = this.get('store').query('theme', _.merge(filterQueryParams, {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    20
      'limit': this.get('limit'),
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    21
      'index': this.get('index'),
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    22
      'sort': this.get('sort')
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    23
    }));
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    24
    promise.then(response => {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    25
      console.log("MODEL", response, response.get('content'), response.get('meta').total);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    26
      this.set('themes', response.get('content'));
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    27
      this.set('total', response.get('meta').total);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    28
    });
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    29
    return promise;
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    30
  },
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    31
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    32
  activate: function () {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    33
    this.get('player').set('window', false);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    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
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    36
  actions: {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    37
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    38
    loadMore: function() {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    39
      if(this.get('isFetching') || (this.get('themes').length === this.get('total'))) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    40
        return;
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    41
      }
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    42
      this.set('isFetching', true);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    43
      this.set('index', this.get('index') + 1);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    44
      var filterQueryParams = _.clone(this.get('filter').get('queryParamsValues'));
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    45
      this.get('store').query('theme', _.merge(filterQueryParams, {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    46
        'limit': this.get('limit'),
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    47
        'index': this.get('index'),
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    48
        'sort': this.get('sort')
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    49
      })).then(response => { // success
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    50
        this.get('themes').pushObjects(response.get('content'));
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    51
        this.set('isFetching', false);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    52
      }, () => { // fail
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    53
        this.set('isFetching', false);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    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
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    57
    resetIndexQueryParams: function () {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    58
      this.set('index', 0);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    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
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    62
    setSortQueryparams: function (sort) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    63
      this.set('sort', sort);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    64
      this.set('index', 0);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    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
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    68
  }
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    69
176
d1baf7ccecc8 Add `thematiques` components
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    70
});