cms/app-client/app/controllers/application.js
author ymh <ymh.work@gmail.com>
Sat, 12 Nov 2016 17:21:25 +0100
changeset 414 5c6c526a7fc1
parent 404 0a5eef6ad2fe
child 415 0046797e0411
permissions -rw-r--r--
Display for single notice, preparation for share link
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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';
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
     2
import _ from 'lodash/lodash';
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
     3
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
     4
export default Ember.Controller.extend({
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
     5
254
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
     6
    player: Ember.inject.service(),
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
     7
    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
     8
    constants: Ember.inject.service(),
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
     9
404
0a5eef6ad2fe correction, change colors for discourse categories, add loding spinner
ymh <ymh.work@gmail.com>
parents: 401
diff changeset
    10
    isLoading: false,
0a5eef6ad2fe correction, change colors for discourse categories, add loding spinner
ymh <ymh.work@gmail.com>
parents: 401
diff changeset
    11
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    12
    page: 1,
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    13
    limit: Ember.computed(function() {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    14
      return 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
    15
    }),
254
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    16
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    17
    playerVideoscreenObserver: Ember.observer('player.videoscreen', function() {
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    18
        Ember.$('body').toggleClass('videoscreen', this.get('player').get('videoscreen'));
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    19
    }),
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    20
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    21
    queryParams : Ember.computed('filter.queryParams', function() {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    22
        var res = _.clone(this.get('filter').get('queryParams'));
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    23
        res.push('notice');
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    24
        res.push('page');
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    25
        return res;
196
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 194
diff changeset
    26
    }),
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 194
diff changeset
    27
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    28
    // this has to be done because queryParameters can not be computed properties...
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    29
    // Of course, we rather had computed properties.
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    30
    // c.f. : https://github.com/emberjs/ember.js/issues/11592
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    31
    date: null,
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    32
    discourse: null,
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    33
    language: null,
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    34
    location: null,
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    35
    theme: null,
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    36
401
9ff56cc0c656 reset pagination when filter change, translate player button
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    37
    localObserver: Ember.observer('language', 'date', 'date.[]', 'discourse', 'discourse.[]', 'location', 'theme', 'theme.[]', function() {
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    38
        this.get('filter').setProperties(this.getProperties('language', 'date', 'discourse', 'theme', 'location'));
401
9ff56cc0c656 reset pagination when filter change, translate player button
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    39
        // need to reset pagination
9ff56cc0c656 reset pagination when filter change, translate player button
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    40
        this.set("page", 1);
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    41
    }),
414
5c6c526a7fc1 Display for single notice, preparation for share link
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    42
    filterObserver: Ember.observer('filter', 'filter.language', 'filter.date', 'filter.date.[]', 'filter.discourse', 'filter.discourse.[]', 'filter.location', 'filter.theme', 'filter.theme.[]',function() {
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    43
        this.setProperties(this.get('filter').getProperties('language', 'date', 'discourse', 'theme', 'location'));
401
9ff56cc0c656 reset pagination when filter change, translate player button
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    44
        // need to reset pagination
9ff56cc0c656 reset pagination when filter change, translate player button
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    45
        this.set("page", 1);
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    46
    }),
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    47
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    48
    itemObserver: Ember.observer('player.item', function() {
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    49
        var self = this;
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    50
        this.store.findRecord('document', this.get('player').get('item'), { reload: true }).then(function(model){
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    51
            self.get('player').set('model', model);
253
0be9770b09b4 Hide/show transcript button in the player - Do not request transscript when property is null in the document request
Chloe Laisne <chloe.laisne@gmail.com>
parents: 245
diff changeset
    52
            if (self.get('player').get('model').get('transcript')) {
321
aefaad270b9b reimplement ThemeController using ES requests to be able to sort by label
ymh <ymh.work@gmail.com>
parents: 254
diff changeset
    53
                self.store.findRecord('transcript', self.get('player').get('item')).then(function(model) {
253
0be9770b09b4 Hide/show transcript button in the player - Do not request transscript when property is null in the document request
Chloe Laisne <chloe.laisne@gmail.com>
parents: 245
diff changeset
    54
                    self.get('player').set('transcript', model);
0be9770b09b4 Hide/show transcript button in the player - Do not request transscript when property is null in the document request
Chloe Laisne <chloe.laisne@gmail.com>
parents: 245
diff changeset
    55
                });
0be9770b09b4 Hide/show transcript button in the player - Do not request transscript when property is null in the document request
Chloe Laisne <chloe.laisne@gmail.com>
parents: 245
diff changeset
    56
            } else {
0be9770b09b4 Hide/show transcript button in the player - Do not request transscript when property is null in the document request
Chloe Laisne <chloe.laisne@gmail.com>
parents: 245
diff changeset
    57
                self.get('player').set('transcript', null);
0be9770b09b4 Hide/show transcript button in the player - Do not request transscript when property is null in the document request
Chloe Laisne <chloe.laisne@gmail.com>
parents: 245
diff changeset
    58
            }
245
c9dd78a43b07 Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
    59
        });
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    60
    }),
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    61
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    62
    notice: null,
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    63
    noticeModel: null,
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    64
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    65
    noticeObserver: Ember.observer('notice', function() {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    66
        var self = this;
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    67
        if (this.get('notice')) {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    68
            this.store.findRecord('document', this.get('notice'), { reload: true }).then(function(model){
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    69
                self.set('noticeModel', model);
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    70
            });
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    71
        }
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    72
    }),
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    73
    noticeModelObserver: Ember.observer('noticeModel', function() {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    74
        if (!this.get('noticeModel')) {
321
aefaad270b9b reimplement ThemeController using ES requests to be able to sort by label
ymh <ymh.work@gmail.com>
parents: 254
diff changeset
    75
            this.set('notice', null);
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    76
        }
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    77
    }),
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    78
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    79
    init: function() {
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    80
        this._super(...arguments);
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    81
        this.get('player');
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    82
        this.get('filter');
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    83
    },
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    84
190
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    85
    actions: {
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    86
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    87
        setPageQueryparams: function(type) {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    88
            var page = this.get('page');
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    89
            if(type === 'previous') {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    90
                page = page - 1;
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    91
            } else if(type === 'next') {
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    92
                page = page + 1;
190
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    93
            }
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    94
            this.propertyWillChange('page');
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    95
            this.set('page', page);
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    96
            this.propertyDidChange('page');
190
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    97
        },
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    98
190
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    99
        play: function(item){
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
   100
            this.set("currentId", item.id);
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
   101
        }
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
   102
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
   103
    }
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
   104
});