cms/app-client/app/components/playlist-component.js
author Chloe Laisne <chloe.laisne@gmail.com>
Tue, 28 Jun 2016 22:11:38 +0200
changeset 210 08ad36c693b1
parent 209 35cb7200bb0a
child 212 f2c6080a73aa
permissions -rw-r--r--
Player design
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
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    37
    didRender: function() {
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    38
        this._super(...arguments);
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    39
        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
    40
    },
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    41
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    42
    actions: {
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    43
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    44
        setItem: function(id) {
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    45
            this.get('player').set('itemId', id);
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    46
        }
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    47
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    48
    }
196
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    49
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    50
});