import Ember from 'ember';

/**
 * @module mixins
 * @class sl-filter-controller
 */
export default Ember.Mixin.create( {

    /**
     * Controller actions hash
     *
     * @property {object} actions
     */
    actions: {

        /**
         * Apply filter settings to the underlying data
         *
         * @method actions.applyFilter
         */
        applyFilter: function () {
            var filters = this.get( 'filters' ),
                gridFilters = this.get( 'gridFilterProperties' ),
                self = this;

            gridFilters.clear();

            Ember.keys( filters ).forEach( function( key ) {
                var filter = self.get( 'filters.' + key );

                if ( Ember.get( filter, 'value' )) {
                    gridFilters.pushObject( filter );
                }
            });

            if( gridFilters.length ){
                this.set( 'filterApplied', true );
            }
       },

        /**
         * Clear all the grid filter settings
         *
         * @method actions.clearAll
         */
        clearAll: function() {
            var gridFilters = this.get( 'gridFilterProperties' ),
                self = this;

            Ember.keys( this.get( 'filters' )).forEach( function( key ) {
                var filter = self.get( 'filters' )[ key ];

                Ember.set( filter, 'value', null );
                gridFilters.removeObject( filter );
            });

            this.set( 'filterApplied', false );
        },

        /**
         * Clear a specific filter
         *
         * @method actions.clearFilter
         * @param {string} key - The key for the filter to clear
         */
        clearFilter: function( key ) {
            var filter = this.get( 'filters.' + key ),
                gridFilters = this.get( 'gridFilterProperties' ),
                self = this;

            gridFilters.removeObject( filter );
            this.set( 'filters.' + key + '.value', null );

            if ( !gridFilters.get( 'length' )) {

                Ember.run.next( function() {
                    self.set( 'filterApplied', false );
                });
            }
        },

        /**
         * Trigger a collapse of the surrounding tab panel
         *
         * @method actions.closeFilterTab
         */
        closeFilterTab: function() {
            this.send( 'toggleFilter' );
        },

        /**
         * Change filter settings
         *
         * @method actions.modifyFilter
         */
        modifyFilter: function() {
            this.set( 'filterApplied', false );
        }
    }
});

@@ -379,17 +379,16 @@
 function
- 
 () %7B%0A   
@@ -404,24 +404,28 @@
 var filters 
+    
 = this.get( 
@@ -516,32 +516,39 @@
            self 
+       
 = this;%0A%0A       
@@ -744,16 +744,17 @@
 value' )
+ 
 ) %7B%0A    
@@ -874,16 +874,17 @@
 length )
+ 
 %7B%0A      
@@ -945,24 +945,25 @@
    %7D%0A       
+ 
 %7D,%0A%0A        
@@ -1181,32 +1181,39 @@
            self 
+       
 = this;%0A%0A       
@@ -1250,16 +1250,17 @@
 lters' )
+ 
 ).forEac
@@ -1757,16 +1757,21 @@
  filter 
+     
 = this.g
@@ -1881,16 +1881,23 @@
    self 
+       
 = this;%0A
@@ -2054,13 +2054,13 @@
 h' )
+ 
 ) %7B%0A
-%0A
     

Refactor to follow style guidelines