All files / addon/components/bootstrap/tables/header -column-header.js

52.63% Statements 10/19
40% Branches 4/10
66.67% Functions 4/6
52.63% Lines 10/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62                                                            8x 8x 8x 8x                 8x 8x 8x         10x 8x               10x      
import Component from '@ember/component';
import layout from '../../../../templates/components/bootstrap/tables/header/-column-header';
import { computed, get } from '@ember/object';
import { task } from 'ember-concurrency';
import { isPresent, isEqual } from '@ember/utils';
import { notEmpty, not } from '@ember/object/computed';
 
export default Component.extend({
  layout,
  tagName: 'th',
  column: null,
  label: null,
  sortingCriteria: null,
 
  columnSortingEnabled: notEmpty('sortingCriteria'),
  activeSortColumn: computed('sortingCriteria', 'sortField', function() {
    const columnCriteia = this.get('sortingCriteria');
    const tableCriteia = this.get('sortField');
    return isEqual(tableCriteia, columnCriteia);
  }),
  sortReverseReverse: not('sortReverse'),
  nextSortDirection: computed('sortReverseReverse', 'activeSortColumn', function() {
    if(this.get('activeSortColumn')) {
      return this.get('sortReverseReverse');
    } else {
      return false;
    }
  }),
 
  calculateLabelTask: task(function * (column) {
    const label = yield get(column, 'headerLabel');
    const field = yield get(column, 'cellValueKey');
    Eif(isPresent(label)) {
      return label;
    } else if (isPresent(field)) {
      return field;
    } else {
      return null;
    }
  }).restartable(),
 
  calculateSortingTask: task(function * (column) {
    const sortingCriteria = yield get(column, 'sortingCriteriaValue');
    Eif(isPresent(sortingCriteria)) {
      return sortingCriteria;
    }
  }).restartable(),
 
  calculateColumnTask: task(function * (column) {
    if(isPresent(column)) {
      return yield this.setProperties({
        label: yield this.get('calculateLabelTask').perform(column),
        sortingCriteria: yield this.get('calculateSortingTask').perform(column)
      });
    }
  }).restartable(),
 
  didReceiveAttrs() {
    this.get('calculateColumnTask').perform(this.get('column'));
  },
});