cms/app-client/app/controllers/application.js
author ymh <ymh.work@gmail.com>
Sun, 04 Dec 2016 00:23:52 +0100
changeset 465 9df336529b2f
parent 462 ebd8269781fa
child 532 1190ea937f2d
permissions -rw-r--r--
make filter and theme visualisatiion change on filter modification
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,
415
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    11
    currentUrl: '',
404
0a5eef6ad2fe correction, change colors for discourse categories, add loding spinner
ymh <ymh.work@gmail.com>
parents: 401
diff changeset
    12
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    13
    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
    14
    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
    15
      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
    16
    }),
254
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    17
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    18
    playerVideoscreenObserver: Ember.observer('player.videoscreen', function() {
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    19
        Ember.$('body').toggleClass('videoscreen', this.get('player').get('videoscreen'));
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    20
    }),
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    21
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    22
    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
    23
        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
    24
        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
    25
        res.push('page');
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    26
        return res;
196
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 194
diff changeset
    27
    }),
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 194
diff changeset
    28
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
    29
    // 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
    30
    // 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
    31
    // 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
    32
    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
    33
    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
    34
    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
    35
    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
    36
    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
    37
401
9ff56cc0c656 reset pagination when filter change, translate player button
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    38
    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
    39
        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
    40
        // need to reset pagination
9ff56cc0c656 reset pagination when filter change, translate player button
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    41
        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
    42
    }),
414
5c6c526a7fc1 Display for single notice, preparation for share link
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    43
    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
    44
        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
    45
        // need to reset pagination
9ff56cc0c656 reset pagination when filter change, translate player button
ymh <ymh.work@gmail.com>
parents: 394
diff changeset
    46
        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
    47
    }),
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    48
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    49
    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
    50
        var self = this;
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    51
        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
    52
            self.get('player').set('model', model);
462
ebd8269781fa support transcript in pdf
ymh <ymh.work@gmail.com>
parents: 415
diff changeset
    53
            let transcript = self.get('player').get('model').get('transcript');
ebd8269781fa support transcript in pdf
ymh <ymh.work@gmail.com>
parents: 415
diff changeset
    54
            if (transcript && transcript.format === "application/pdf") {
ebd8269781fa support transcript in pdf
ymh <ymh.work@gmail.com>
parents: 415
diff changeset
    55
                self.get('player').set('transcript', transcript.url);
ebd8269781fa support transcript in pdf
ymh <ymh.work@gmail.com>
parents: 415
diff changeset
    56
                self.get('player').set('transcriptIframe', true);
ebd8269781fa support transcript in pdf
ymh <ymh.work@gmail.com>
parents: 415
diff changeset
    57
            }
ebd8269781fa support transcript in pdf
ymh <ymh.work@gmail.com>
parents: 415
diff changeset
    58
            else if (transcript) {
ebd8269781fa support transcript in pdf
ymh <ymh.work@gmail.com>
parents: 415
diff changeset
    59
                self.get('player').set('transcriptIframe', false);
321
aefaad270b9b reimplement ThemeController using ES requests to be able to sort by label
ymh <ymh.work@gmail.com>
parents: 254
diff changeset
    60
                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
    61
                    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
    62
                });
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
    63
            } else {
462
ebd8269781fa support transcript in pdf
ymh <ymh.work@gmail.com>
parents: 415
diff changeset
    64
                self.get('player').set('transcriptIframe', false);
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
    65
                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
    66
            }
245
c9dd78a43b07 Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
    67
        });
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    68
    }),
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    69
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    70
    notice: null,
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    71
    noticeModel: null,
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
    noticeObserver: Ember.observer('notice', function() {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    74
        var self = this;
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    75
        if (this.get('notice')) {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    76
            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
    77
                self.set('noticeModel', model);
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    78
            });
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    79
        }
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    80
    }),
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    81
    noticeModelObserver: Ember.observer('noticeModel', function() {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    82
        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
    83
            this.set('notice', null);
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    84
        }
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    85
    }),
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    86
415
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    87
    targetUrlChanged: Ember.observer('target.url', function() {
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    88
        Ember.run.next(this, function() {
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    89
            this.set('currentUrl', window.location.href);
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    90
        });
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    91
    }),
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    92
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    93
    init: function() {
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    94
        this._super(...arguments);
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    95
        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
    96
        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
    97
    },
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    98
190
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    99
    actions: {
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
   100
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
   101
        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
   102
            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
   103
            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
   104
                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
   105
            } 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
   106
                page = page + 1;
190
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
   107
            }
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
   108
            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
   109
            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
   110
            this.propertyDidChange('page');
190
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
   111
        },
394
48458e099b05 make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents: 392
diff changeset
   112
190
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
   113
        play: function(item){
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
   114
            this.set("currentId", item.id);
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
   115
        }
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
   116
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
   117
    }
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
   118
});