forked from adopted-ember-addons/ember-light-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.js
117 lines (98 loc) · 2.76 KB
/
base.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import Component from '@ember/component';
import { computed } from '@ember/object';
import { isEmpty } from '@ember/utils';
import layout from 'ember-light-table/templates/components/columns/base';
import DraggableColumnMixin from 'ember-light-table/mixins/draggable-column';
import cssStyleify from 'ember-light-table/utils/css-styleify';
/**
* @module Light Table
* @submodule Column Types
*/
/**
* @module Column Types
* @class Base Column
*/
const Column = Component.extend(DraggableColumnMixin, {
layout,
tagName: 'th',
classNames: ['lt-column'],
attributeBindings: ['style', 'colspan', 'rowspan'],
classNameBindings: ['align', 'isGroupColumn:lt-group-column', 'isHideable', 'isSortable', 'isSorted', 'isResizable', 'isResizing', 'isDraggable', 'column.classNames'],
isGroupColumn: computed.readOnly('column.isGroupColumn'),
isSortable: computed.readOnly('column.sortable'),
isSorted: computed.readOnly('column.sorted'),
isHideable: computed.readOnly('column.hideable'),
isResizable: computed.readOnly('column.resizable'),
isDraggable: computed.readOnly('column.draggable'),
isResizing: false,
style: computed('column.width', function() {
return cssStyleify(this.get('column').getProperties(['width']));
}),
align: computed('column.align', function() {
return `align-${this.get('column.align')}`;
}),
/**
* @property label
* @type {String}
*/
label: computed.oneWay('column.label'),
/**
* @property table
* @type {Table}
*/
table: null,
/**
* @property column
* @type {Column}
*/
column: null,
/**
* @property tableActions
* @type {Object}
*/
tableActions: null,
/**
* @property extra
* @type {Object}
*/
extra: null,
/**
* @property sortIcons
* @type {Object}
*/
sortIcons: null,
/**
* @property sortIconProperty
* @type {String|null}
* @private
*/
sortIconProperty: computed('column.{sortable,sorted,ascending}', function() {
let sorted = this.get('column.sorted');
if (sorted) {
let ascending = this.get('column.ascending');
return ascending ? 'iconAscending' : 'iconDescending';
}
let sortable = this.get('column.sortable');
return sortable ? 'iconSortable' : null;
}),
/**
* @property colspan
* @type {Number}
*/
colspan: computed('column', 'column.visibleSubColumns.[]', function() {
let subColumns = this.get('column.visibleSubColumns');
return !isEmpty(subColumns) ? subColumns.length : 1;
}),
/**
* @property rowspan
* @type {Number}
*/
rowspan: computed('column.visibleSubColumns.[]', function() {
let subColumns = this.get('column.visibleSubColumns');
return !isEmpty(subColumns) ? 1 : 2;
})
});
Column.reopenClass({
positionalParams: ['column']
});
export default Column;