cms/app-client/app/components/playlist-component.js
author Chloe Laisne <chloe.laisne@gmail.com>
Thu, 23 Jun 2016 17:09:32 +0200
changeset 200 a441c40f9c5e
parent 196 7550cb541901
child 201 9ae2cf79d167
permissions -rw-r--r--
Fix playlist filtering Minor design changes

import Ember from 'ember';

export default Ember.Component.extend({

	classNames: ['playlist-component'],

	filter: Ember.inject.service(),

	documents: Ember.computed('model', 'filter.location', 'filter.language', 'filter.discourse', 'filter.date', 'filter.theme', function() {
        var documents = this.get('model');
        if (this.get('filter.date').length > 0) {
            var copy = documents;
            documents.map(function(document) {
                if (this.get('filter.date').indexOf(document.get('created')) === -1){
                    copy = copy.without(document);
                }
            });
            documents = copy;
        }
        if (this.get('filter.discourse')) {
            documents = documents.filterBy('type', this.get('filter.discourse'));
        }
        if (this.get('filter.language')) {
            documents = documents.filterBy('language', this.get('filter.language'));
        }
        if (this.get('filter.location')) {
            documents = documents.filterBy('spatial', this.get('filter.location'));
        }
        if (this.get('filter.theme')) {
            documents = documents.filterBy('thematique', this.get('filter.theme'));
        }
        return documents;
    }),

	didRender: function() {
		this._super(...arguments);
		this.$().find('ul').height(Ember.$('.corpus-app-wrapper').outerHeight() - (Ember.$('.filter-component').outerHeight() + this.$().find('h2').outerHeight()));
	}

});