cms/app-client/app/routes/application.js
author ymh <ymh.work@gmail.com>
Tue, 08 Nov 2016 15:48:01 +0100
changeset 404 0a5eef6ad2fe
parent 401 9ff56cc0c656
child 414 5c6c526a7fc1
permissions -rw-r--r--
correction, change colors for discourse categories, add loding spinner
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42
7d091abf82fd add application adapter to simulate REST, using fixtures
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     1
import Ember from 'ember';
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
     2
import _ from 'lodash/lodash';
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
     3
import RSVP from 'rsvp';
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
     4
import ENV from 'app-client/config/environment';
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
     5
import URI from 'urijs';
42
7d091abf82fd add application adapter to simulate REST, using fixtures
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     6
7d091abf82fd add application adapter to simulate REST, using fixtures
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     7
export default Ember.Route.extend({
194
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
     8
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
     9
    filter: Ember.inject.service(),
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    10
    constants: Ember.inject.service(),
344
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    11
401
9ff56cc0c656 reset pagination when filter change, translate player button
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    12
    model: function(params) {
9ff56cc0c656 reset pagination when filter change, translate player button
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    13
        let filterQueryArgs = _.clone(this.get('filter').get('queryParamsValues'));
9ff56cc0c656 reset pagination when filter change, translate player button
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    14
        return this.store.query('document', _.merge(filterQueryArgs, {
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    15
            page: params['page'],
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    16
            perpage: this.get('constants').DOCUMENTS_PAGINATION_PERPAGE
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    17
        }));
401
9ff56cc0c656 reset pagination when filter change, translate player button
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    18
    },
194
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
    19
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    20
    /**
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    21
      Serializes value of the query parameter based on defaultValueType
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    22
      @method serializeQueryParam
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    23
      @param {Object} value
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    24
      @param {String} urlKey
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    25
      @param {String} defaultValueType
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    26
      @private
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    27
    */
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    28
    serializeQueryParam(value, urlKey, defaultValueType) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    29
        if(_.contains(this.get('filter').get('queryParams'), urlKey)) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    30
            return this.get('filter').serializeQueryParam(value, urlKey, defaultValueType);
194
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
    31
        }
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    32
        return this._super(value, urlKey, defaultValueType);
194
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
    33
    },
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
    34
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    35
    /**
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    36
      Deserializes value of the query parameter based on defaultValueType
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    37
      @method deserializeQueryParam
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    38
      @param {Object} value
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    39
      @param {String} urlKey
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    40
      @param {String} defaultValueType
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    41
      @private
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    42
    */
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    43
    deserializeQueryParam(value, urlKey, defaultValueType) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    44
        if(_.contains(this.get('filter').get('queryParams'), urlKey)) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    45
            return this.get('filter').deserializeQueryParam(value, urlKey, defaultValueType);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    46
        }
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    47
        return this._super(value, urlKey, defaultValueType);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    48
    },
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    49
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    50
    beforeModel: function(transition) {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    51
        new RSVP.Promise((resolve) => {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    52
          // succeed
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    53
          this.get('filter').setProperties(transition['queryParams']);
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    54
          resolve();
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    55
        });
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    56
        return this._super(...arguments);
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    57
    },
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    58
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    59
    queryParams: Ember.computed('filter', function() {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    60
        var res = this.get('filter').getRouteQueryParams();
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    61
        res['page'] = { refreshModel: true };
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    62
        res['notice'] = { refreshModel: false };
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    63
        return res;
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    64
    }),
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    65
194
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
    66
    actions: {
404
0a5eef6ad2fe correction, change colors for discourse categories, add loding spinner
ymh <ymh.work@gmail.com>
parents: 401
diff changeset
    67
        loading(transition) {
0a5eef6ad2fe correction, change colors for discourse categories, add loding spinner
ymh <ymh.work@gmail.com>
parents: 401
diff changeset
    68
          let controller = this.controllerFor('application');
0a5eef6ad2fe correction, change colors for discourse categories, add loding spinner
ymh <ymh.work@gmail.com>
parents: 401
diff changeset
    69
          controller.set('isLoading', true);
0a5eef6ad2fe correction, change colors for discourse categories, add loding spinner
ymh <ymh.work@gmail.com>
parents: 401
diff changeset
    70
          transition.promise.finally(function() {
0a5eef6ad2fe correction, change colors for discourse categories, add loding spinner
ymh <ymh.work@gmail.com>
parents: 401
diff changeset
    71
              controller.set('isLoading', false);
0a5eef6ad2fe correction, change colors for discourse categories, add loding spinner
ymh <ymh.work@gmail.com>
parents: 401
diff changeset
    72
          });
0a5eef6ad2fe correction, change colors for discourse categories, add loding spinner
ymh <ymh.work@gmail.com>
parents: 401
diff changeset
    73
        },
194
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
    74
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
    75
        didTransition: function() {
199
b7c691c6179d Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents: 194
diff changeset
    76
            // Append body classname depending on the route
194
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
    77
            Ember.$('body').removeClass((this.controller.get('currentPath') || '').replace(/\//g, '-').dasherize());
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
    78
            Ember.run.once(this, function() {
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
    79
                Ember.$('body').addClass((this.controller.get('currentPath') ||'').replace(/\//g, '-').dasherize());
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
    80
            });
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    81
            // change external navigations links
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    82
            if(ENV.APP.navigationLinksSelector) {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    83
                return new RSVP.Promise((resolve) => {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    84
                  setTimeout(() => {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    85
                    let hash = window.location.hash;
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    86
                    if(!hash) {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    87
                        return true;
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    88
                    }
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    89
                    let uriHash = URI(hash.substr(1));
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    90
                    Ember.$(ENV.APP.navigationLinksSelector).each((i, l) => {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    91
                        let uri = URI(Ember.$(l).prop('href'));
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    92
                        if(uri.fragment()) {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    93
                          let urifragment = URI(uri.fragment()).search(uriHash.search());
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    94
                          Ember.$(l).prop('href', uri.fragment(urifragment.href()).href());
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    95
                        }
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    96
                    });
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    97
                    resolve(true);
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    98
                  }, 10);
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    99
                });
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
   100
            }
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
   101
            return true;
194
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
   102
        }
02c6aa9a99d7 Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents: 92
diff changeset
   103
81
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 74
diff changeset
   104
    }
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 74
diff changeset
   105
42
7d091abf82fd add application adapter to simulate REST, using fixtures
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   106
});