cms/app-client/app/controllers/application.js
author ymh <ymh.work@gmail.com>
Fri, 04 Nov 2016 19:03:25 +0100
changeset 392 4fbe94af93e8
parent 339 766af1228b05
child 394 48458e099b05
permissions -rw-r--r--
Improve filter service. Centralize filter management in a single point
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(),
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
     8
254
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
     9
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    10
    playerVideoscreenObserver: Ember.observer('player.videoscreen', function() {
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    11
        Ember.$('body').toggleClass('videoscreen', this.get('player').get('videoscreen'));
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    12
    }),
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 253
diff changeset
    13
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    14
    // queryParams: ['location', 'date', 'notice', 'language', 'discourse', 'theme'],
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    15
    // queryParams: Ember.computed('filter.queryParams', 'notice', function() {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    16
    //     const queryParamsList = 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
    17
    //     return _.merge(queryParamsList, {'notice' : this.get('notice')});
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    18
    // }),
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    19
    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
    20
        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
    21
        res.push('notice');
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    22
        return res;
196
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 194
diff changeset
    23
    }),
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 194
diff changeset
    24
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    25
    location: Ember.computed.alias('filter.location'),
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    26
    date: Ember.computed.alias('filter.date'),
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    27
    language: Ember.computed.alias('filter.language'),
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    28
    discourse: Ember.computed.alias('filter.discourse'),
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 339
diff changeset
    29
    theme: Ember.computed.alias('filter.theme'),
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    30
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    31
    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
    32
        var self = this;
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    33
        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
    34
            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
    35
            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
    36
                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
    37
                    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
    38
                });
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
    39
            } 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
    40
                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
    41
            }
245
c9dd78a43b07 Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
    42
        });
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    43
    }),
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    44
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    45
    notice: null,
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    46
    noticeModel: null,
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    47
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    48
    noticeObserver: Ember.observer('notice', function() {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    49
        var self = this;
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    50
        if (this.get('notice')) {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    51
            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
    52
                self.set('noticeModel', model);
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    53
            });
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    54
        }
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    55
    }),
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    56
    noticeModelObserver: Ember.observer('noticeModel', function() {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    57
        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
    58
            this.set('notice', null);
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    59
        }
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    60
    }),
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 227
diff changeset
    61
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    62
    init: function() {
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    63
        this._super(...arguments);
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    64
        this.get('player');
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    65
    },
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    66
190
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    67
    actions: {
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    68
190
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    69
        changeDocument: function(docDirection){
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    70
            var direction = (docDirection === "next") ? 1 : -1;
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    71
            var currentObject = this.get("filteredDocuments").findBy('id', this.get("currentItem").get('id'));
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    72
            if ( currentObject !== 'undefined'){
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    73
                var index = this.get("filteredDocuments").indexOf(currentObject);
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    74
                if ( typeof(this.get("filteredDocuments").objectAt(index+direction)) !== 'undefined'){
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    75
                    return this.set('currentId', this.get("filteredDocuments").objectAt(index+direction).id);
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    76
                }
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    77
            }
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    78
            return this.set('currentId', this.get('filteredDocuments').get('firstObject').id);
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    79
        },
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    80
        play: function(item){
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    81
            this.set("currentId", item.id);
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    82
        }
226ae8f2e8e9 JSLinting on /langues endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    83
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    84
    }
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
    85
});