cms/app-client/app/components/playlist-component.js
author Chloe Laisne <chloe.laisne@gmail.com>
Sun, 03 Jul 2016 13:13:10 +0200
changeset 216 c174124d1849
parent 215 82878d132784
child 227 5c9250f55f4b
permissions -rw-r--r--
/discours and /chrono design changes Playlist-component error when no items returned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
196
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     1
import Ember from 'ember';
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     2
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     3
export default Ember.Component.extend({
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     4
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
     5
    classNames: ['playlist-component'],
200
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
     6
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
     7
    filter: Ember.inject.service(),
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
     8
    player: Ember.inject.service(),
200
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
     9
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    10
    documents: Ember.computed('model', 'filter.location', 'filter.language', 'filter.discourse', 'filter.date', 'filter.theme', function() {
201
9ae2cf79d167 Quickfix this is undefined
Chloe Laisne <chloe.laisne@gmail.com>
parents: 200
diff changeset
    11
        var self = this;
200
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    12
        var documents = this.get('model');
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    13
        if (this.get('filter.date').length > 0) {
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    14
            var copy = documents;
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    15
            documents.map(function(document) {
201
9ae2cf79d167 Quickfix this is undefined
Chloe Laisne <chloe.laisne@gmail.com>
parents: 200
diff changeset
    16
                if (self.get('filter.date').indexOf(document.get('created')) === -1){
200
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    17
                    copy = copy.without(document);
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    18
                }
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    19
            });
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    20
            documents = copy;
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    21
        }
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    22
        if (this.get('filter.discourse')) {
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    23
            documents = documents.filterBy('type', this.get('filter.discourse'));
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    24
        }
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    25
        if (this.get('filter.language')) {
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    26
            documents = documents.filterBy('language', this.get('filter.language'));
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    27
        }
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    28
        if (this.get('filter.location')) {
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    29
            documents = documents.filterBy('spatial', this.get('filter.location'));
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    30
        }
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    31
        if (this.get('filter.theme')) {
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    32
            documents = documents.filterBy('thematique', this.get('filter.theme'));
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    33
        }
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    34
        return documents;
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    35
    }),
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    36
215
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    37
    documentsLoaded: Ember.observer('documents', function() {
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    38
        this.get('player').set('items', this.get('documents').map(function(document) {
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    39
            return document.get('id');
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    40
        }));
216
c174124d1849 /discours and /chrono design changes
Chloe Laisne <chloe.laisne@gmail.com>
parents: 215
diff changeset
    41
        if(this.get('player').get('items').length) {
c174124d1849 /discours and /chrono design changes
Chloe Laisne <chloe.laisne@gmail.com>
parents: 215
diff changeset
    42
            this.get('player').set('item', this.get('player').get('items')[0]);    
c174124d1849 /discours and /chrono design changes
Chloe Laisne <chloe.laisne@gmail.com>
parents: 215
diff changeset
    43
        }
215
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    44
    }).on('init'),
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    45
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    46
    init: function() {
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    47
        this._super(...arguments);
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    48
    },
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    49
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    50
    didRender: function() {
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    51
        this._super(...arguments);
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    52
        this.$().find('ul').height(Ember.$('.corpus-app-wrapper').outerHeight() - (Ember.$('.filter-component').outerHeight() + this.$().find('h2').outerHeight()));
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    53
    },
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    54
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    55
    actions: {
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    56
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    57
        setItem: function(id) {
215
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    58
            this.get('player').trigger('reset', id);
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    59
        }
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    60
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    61
    }
196
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    62
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    63
});