All files / addon/components/bootstrap/tables -table.js

46.15% Statements 6/13
50% Branches 3/6
60% Functions 3/5
46.15% Lines 6/13

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                                                  4x 4x 2x 2x                                     4x       4x                  
import Component from '@ember/component';
import layout from '../../../templates/components/bootstrap/tables/-table';
import { BuilderForPropTypes, BuilderForPropDefaults } from 'ember-bootstrap-controls/utils/prop-definition-tools';
import { notEmpty, or, alias } from '@ember/object/computed';
import { isPresent, isEqual } from '@ember/utils';
import { task } from 'ember-concurrency';
import { get } from '@ember/object';
import { propDefinitions } from './table-with-pagination';
 
export default Component.extend({
  layout,
  propTypes: BuilderForPropTypes(propDefinitions),
  tagName: 'table',
  // classNames: propDefinitions.classNames.default,
 
  archiveEnabled: notEmpty('onArchive'),
  deleteEnabled: notEmpty('onDelete'),
  editEnabled: notEmpty('onEdit'),
  showEnabled: notEmpty('onShow'),
  actionsEnabled: or('deleteEnabled', 'editEnabled', 'showEnabled', 'archiveEnabled'),
 
  sortingRows: alias('onSortTask.isRunning'),
  sortingEnabled: notEmpty('onSort'),
 
  calculateSortingTask: task(function * () {
    const rowsData = yield this.get('rowsData');
    if(isPresent(rowsData)) {
      const sortingInformation = yield get(rowsData, 'meta.sort');
      Iif(isPresent(sortingInformation)) {
        const sortReverse = yield get(sortingInformation, 'reverse');
        this.setProperties({
          sortField: yield get(sortingInformation, 'criteria'),
          sortReverse: isEqual('true', sortReverse),
        });
      }
    }
  }).restartable(),
 
  onSortTask: task(function * (sortCriteria, sortReverse) {
    const onSort = yield this.get('onSort');
    const currentSortCriteria = yield this.get('sortField');
    if(isPresent(onSort)) {
      return yield onSort(sortCriteria, sortReverse, currentSortCriteria);
    }
  }).restartable(),
 
  didReceiveAttrs() {
    this.get('calculateSortingTask').perform();
  },
 
  getDefaultProps() {
    return BuilderForPropDefaults(propDefinitions)
  },
 
  actions: {
    onSort(sortCriteria, sortReverse) {
      return this.get('onSortTask').perform(sortCriteria, sortReverse);
    }
  }
});