mirror of
				https://github.com/datahub-project/datahub.git
				synced 2025-11-03 20:27:50 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import Component from '@ember/component';
 | 
						|
import { computed } from '@ember/object';
 | 
						|
 | 
						|
export default Component.extend({
 | 
						|
  tagName: 'th',
 | 
						|
  classNameBindings: ['isColumnActive'],
 | 
						|
  columnName: '',
 | 
						|
  sortColumnWithName: '',
 | 
						|
  sortDirection: null,
 | 
						|
 | 
						|
  isColumnActive: computed('sortColumnWithName', 'columnName', function() {
 | 
						|
    const { sortColumnWithName, columnName } = this.getProperties('sortColumnWithName', 'columnName');
 | 
						|
    return sortColumnWithName && sortColumnWithName === columnName;
 | 
						|
  }),
 | 
						|
 | 
						|
  click() {
 | 
						|
    const { columnName, sortDirection, isColumnActive } = this.getProperties(
 | 
						|
      'columnName',
 | 
						|
      'sortDirection',
 | 
						|
      'isColumnActive'
 | 
						|
    );
 | 
						|
 | 
						|
    if (columnName) {
 | 
						|
      let updatedSortDirection;
 | 
						|
      // if this column is not active, default sort direction to ascending, else toggle sort direction
 | 
						|
      if (!isColumnActive) {
 | 
						|
        updatedSortDirection = 'asc';
 | 
						|
      } else {
 | 
						|
        updatedSortDirection = sortDirection === 'asc' ? 'desc' : 'asc';
 | 
						|
      }
 | 
						|
 | 
						|
      this.get('sortDidChange')(columnName, updatedSortDirection);
 | 
						|
      this.set('sortDirection', updatedSortDirection);
 | 
						|
    }
 | 
						|
  }
 | 
						|
});
 |