kempo 2.10.0 → 2.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Sortable.js +1 -0
- package/dist/components/Table.js +1 -1
- package/dist/components/tableControls/DeleteRecord.js +1 -0
- package/dist/components/tableControls/DeleteSelected.js +1 -1
- package/dist/components/tableControls/Edit.js +1 -1
- package/dist/components/tableControls/ExportCSV.js +1 -0
- package/dist/components/tableControls/ExportJson.js +1 -0
- package/dist/components/tableControls/FieldSortHide.js +1 -0
- package/dist/components/tableControls/Filters.js +1 -1
- package/dist/components/tableControls/FirstPage.js +1 -0
- package/dist/components/tableControls/HiddenCount.js +1 -1
- package/dist/components/tableControls/Hide.js +1 -1
- package/dist/components/tableControls/LastPage.js +1 -0
- package/dist/components/tableControls/NextPage.js +1 -0
- package/dist/components/tableControls/PageSelect.js +1 -1
- package/dist/components/tableControls/PageSize.js +1 -1
- package/dist/components/tableControls/PrevPage.js +1 -0
- package/dist/components/tableControls/Search.js +1 -0
- package/dist/components/tableControls/SelectCount.js +1 -1
- package/dist/components/tableControls/ShowAll.js +1 -1
- package/dist/components/tableControls/ShowHideFields.js +1 -0
- package/dist/components/tableControls/TableControl.js +1 -0
- package/dist/index.js +1 -1
- package/docs/components/sortable.html +96 -0
- package/docs/components/table.html +32 -7
- package/docs/components/tableControls.html +10 -24
- package/docs/components/tableFetchRecords.html +114 -0
- package/docs/components/tableFieldSortHide.html +75 -0
- package/docs/components/tablePagination.html +33 -25
- package/docs/components/tableRecordEditing.html +8 -8
- package/docs/components/tableRecordFiltering.html +6 -13
- package/docs/components/tableRecordHiding.html +10 -14
- package/docs/components/tableRecordSearching.html +75 -0
- package/docs/components/tableRecordSelection.html +8 -19
- package/docs/components/tableRowControls.html +10 -35
- package/docs/components/tableSorting.html +73 -0
- package/docs/icons/arrow-down.svg +1 -0
- package/docs/icons/arrow-up.svg +1 -0
- package/docs/icons/drag-handle.svg +1 -0
- package/docs/icons/export-file.svg +1 -0
- package/docs/icons/first.svg +1 -0
- package/docs/icons/last.svg +1 -0
- package/docs/icons/table-visibility.svg +1 -0
- package/docs/kempo/components/Sortable.js +1 -0
- package/docs/kempo/components/Table.js +1 -1
- package/docs/kempo/components/tableControls/DeleteRecord.js +1 -0
- package/docs/kempo/components/tableControls/DeleteSelected.js +1 -1
- package/docs/kempo/components/tableControls/Edit.js +1 -1
- package/docs/kempo/components/tableControls/ExportCSV.js +1 -0
- package/docs/kempo/components/tableControls/ExportJson.js +1 -0
- package/docs/kempo/components/tableControls/FieldSortHide.js +1 -0
- package/docs/kempo/components/tableControls/Filters.js +1 -1
- package/docs/kempo/components/tableControls/FirstPage.js +1 -0
- package/docs/kempo/components/tableControls/HiddenCount.js +1 -1
- package/docs/kempo/components/tableControls/Hide.js +1 -1
- package/docs/kempo/components/tableControls/LastPage.js +1 -0
- package/docs/kempo/components/tableControls/NextPage.js +1 -0
- package/docs/kempo/components/tableControls/PageSelect.js +1 -1
- package/docs/kempo/components/tableControls/PageSize.js +1 -1
- package/docs/kempo/components/tableControls/PrevPage.js +1 -0
- package/docs/kempo/components/tableControls/Search.js +1 -0
- package/docs/kempo/components/tableControls/SelectCount.js +1 -1
- package/docs/kempo/components/tableControls/ShowAll.js +1 -1
- package/docs/kempo/components/tableControls/ShowHideFields.js +1 -0
- package/docs/kempo/components/tableControls/TableControl.js +1 -0
- package/docs/kempo/index.js +1 -1
- package/icons/arrow-down.svg +1 -0
- package/icons/arrow-up.svg +1 -0
- package/icons/drag-handle.svg +1 -0
- package/icons/export-file.svg +1 -0
- package/icons/first.svg +1 -0
- package/icons/last.svg +1 -0
- package/icons/table-visibility.svg +1 -0
- package/package.json +1 -1
- package/src/components/Sortable.js +169 -0
- package/src/components/Table.js +421 -295
- package/src/components/tableControls/DeleteRecord.js +43 -0
- package/src/components/tableControls/DeleteSelected.js +11 -13
- package/src/components/tableControls/Edit.js +22 -26
- package/src/components/tableControls/ExportCSV.js +91 -0
- package/src/components/tableControls/ExportJson.js +62 -0
- package/src/components/tableControls/FieldSortHide.js +77 -0
- package/src/components/tableControls/Filters.js +18 -17
- package/src/components/tableControls/FirstPage.js +69 -0
- package/src/components/tableControls/HiddenCount.js +10 -15
- package/src/components/tableControls/Hide.js +12 -15
- package/src/components/tableControls/LastPage.js +67 -0
- package/src/components/tableControls/NextPage.js +69 -0
- package/src/components/tableControls/PageSelect.js +20 -23
- package/src/components/tableControls/PageSize.js +12 -15
- package/src/components/tableControls/PrevPage.js +69 -0
- package/src/components/tableControls/Search.js +49 -0
- package/src/components/tableControls/SelectCount.js +5 -10
- package/src/components/tableControls/ShowAll.js +9 -12
- package/src/components/tableControls/TableControl.js +51 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
|
+
import '../Icon.js';
|
|
3
|
+
import { onEvent, offEvent } from '../../utils/element.js';
|
|
4
|
+
|
|
5
|
+
const clickHandler = Symbol('clickHandler');
|
|
6
|
+
export default class DeleteRecord extends TableControl {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
/* Private Methods */
|
|
11
|
+
this[clickHandler] = this.delete.bind(this);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* Lifecycle Callbacks */
|
|
15
|
+
async render(force = false){
|
|
16
|
+
if(await super.render(force)){
|
|
17
|
+
onEvent(this.shadowRoot.getElementById('delete'), 'click', this[clickHandler]);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
disconnectedCallback(){
|
|
23
|
+
super.disconnectedCallback();
|
|
24
|
+
offEvent(this.shadowRoot.getElementById('delete'), 'click', this[clickHandler]);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* Public Methods */
|
|
28
|
+
delete(){
|
|
29
|
+
if(this.record){
|
|
30
|
+
this.table.deleteRecord(this.record)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* Shadow DOM */
|
|
35
|
+
get shadowTemplate(){
|
|
36
|
+
return /*html*/`
|
|
37
|
+
<button id="delete" class="no-btn icon-btn">
|
|
38
|
+
<slot><k-icon name="delete"></k-icon></slot>
|
|
39
|
+
</button>
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
window.customElements.define('k-tc-delete-record', DeleteRecord);
|
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
2
|
import { onEvent, offEvent } from '../../utils/element.js';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
deleteSelected = Symbol('deleteSelected'),
|
|
4
|
+
const deleteSelected = Symbol('deleteSelected'),
|
|
6
5
|
updateButtonState = Symbol('updateButtonState');
|
|
7
|
-
export default class DeleteSelected extends
|
|
8
|
-
constructor(
|
|
6
|
+
export default class DeleteSelected extends TableControl {
|
|
7
|
+
constructor() {
|
|
9
8
|
super();
|
|
10
9
|
|
|
11
|
-
/* Private Members */
|
|
12
|
-
this[table] = _table;
|
|
13
|
-
|
|
14
10
|
/* Private Methods */
|
|
15
11
|
this[deleteSelected] = this.deleteSelected.bind(this);
|
|
16
12
|
this[updateButtonState] = (()=>{
|
|
17
|
-
this.shadowRoot.getElementById('deleteSelectedButton').disabled = this
|
|
13
|
+
this.shadowRoot.getElementById('deleteSelectedButton').disabled = this.table.getSelectedRecords().length === 0;
|
|
18
14
|
}).bind(this);
|
|
19
15
|
|
|
20
16
|
|
|
21
17
|
/* Init */
|
|
22
|
-
|
|
18
|
+
|
|
23
19
|
}
|
|
20
|
+
|
|
24
21
|
/* Lifecycle Callbacks */
|
|
25
22
|
async render(force = false) {
|
|
26
23
|
if (await super.render(force)) {
|
|
27
24
|
this[updateButtonState]();
|
|
28
25
|
onEvent(this.shadowRoot.getElementById('deleteSelectedButton'), 'click', this[deleteSelected]);
|
|
29
|
-
onEvent(this
|
|
26
|
+
onEvent(this.table, 'selectionChange', this[updateButtonState]);
|
|
30
27
|
return true;
|
|
31
28
|
}
|
|
32
29
|
return false;
|
|
@@ -34,11 +31,12 @@ export default class DeleteSelected extends Component {
|
|
|
34
31
|
disconnectedCallback(){
|
|
35
32
|
super.disconnectedCallback();
|
|
36
33
|
offEvent(this.shadowRoot.getElementById('deleteSelectedButton'), 'click', this[deleteSelected]);
|
|
37
|
-
offEvent(this
|
|
34
|
+
offEvent(this.table, 'selectionChange', this[updateButtonState]);
|
|
38
35
|
}
|
|
39
36
|
|
|
37
|
+
/* Public Methods */
|
|
40
38
|
deleteSelected() {
|
|
41
|
-
this
|
|
39
|
+
this.table.deleteSelected();
|
|
42
40
|
this[updateButtonState]();
|
|
43
41
|
}
|
|
44
42
|
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
2
|
import { offEvent, onEvent } from '../../utils/element.js';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
record = Symbol('record'),
|
|
6
|
-
editRecord = Symbol('editRecord'),
|
|
4
|
+
const editRecord = Symbol('editRecord'),
|
|
7
5
|
saveRecord = Symbol('saveRecord'),
|
|
8
6
|
cancelEdit = Symbol('cancelEdit');
|
|
9
|
-
export default class Edit extends
|
|
10
|
-
constructor(
|
|
7
|
+
export default class Edit extends TableControl {
|
|
8
|
+
constructor() {
|
|
11
9
|
super();
|
|
12
10
|
|
|
13
|
-
/* Private Members */
|
|
14
|
-
this[table] = _table;
|
|
15
|
-
this[record] = _record;
|
|
16
11
|
|
|
17
12
|
/* Private Methods */
|
|
18
13
|
this[editRecord] = this.editRecord.bind(this);
|
|
@@ -21,13 +16,16 @@ export default class Edit extends Component {
|
|
|
21
16
|
|
|
22
17
|
/* Init */
|
|
23
18
|
this.registerAttributes({
|
|
24
|
-
editing:
|
|
19
|
+
editing: false
|
|
25
20
|
});
|
|
26
|
-
|
|
27
|
-
this.classList.add('mxq');
|
|
21
|
+
this.maxWidth = 80;
|
|
28
22
|
}
|
|
29
23
|
async render(force = false) {
|
|
30
24
|
if (await super.render(force)) {
|
|
25
|
+
const record = this.record;
|
|
26
|
+
if(record){
|
|
27
|
+
this.editing = this.table.recordIsEditing(record)
|
|
28
|
+
}
|
|
31
29
|
onEvent(this.shadowRoot.getElementById('editButton'), 'click', this[editRecord]);
|
|
32
30
|
onEvent(this.shadowRoot.getElementById('saveButton'), 'click', this[saveRecord]);
|
|
33
31
|
onEvent(this.shadowRoot.getElementById('cancelButton'), 'click', this[cancelEdit]);
|
|
@@ -42,47 +40,45 @@ export default class Edit extends Component {
|
|
|
42
40
|
offEvent(this.shadowRoot.getElementById('cancelButton'), 'click', this[cancelEdit]);
|
|
43
41
|
}
|
|
44
42
|
|
|
43
|
+
/* Public Methods */
|
|
45
44
|
editRecord() {
|
|
46
|
-
this
|
|
45
|
+
this.table.editRecord(this.record);
|
|
47
46
|
}
|
|
48
47
|
saveRecord() {
|
|
49
|
-
this
|
|
48
|
+
this.table.saveEditedRecord(this.record);
|
|
50
49
|
}
|
|
51
50
|
cancelEdit() {
|
|
52
|
-
this
|
|
51
|
+
this.table.cancelEditedRecord(this.record);
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
get shadowTemplate() {
|
|
56
55
|
return /*html*/`
|
|
57
|
-
<button id="editButton" class="
|
|
56
|
+
<button id="editButton" class="icon-btn no-btn">
|
|
58
57
|
<k-icon name="edit"></k-icon>
|
|
59
58
|
</button>
|
|
60
|
-
<button id="
|
|
61
|
-
<k-icon name="close"></k-icon>
|
|
62
|
-
</button>
|
|
63
|
-
<button id="saveButton" class="pq no-btn bg-success">
|
|
59
|
+
<button id="saveButton" class="icon-btn no-btn bg-success">
|
|
64
60
|
<k-icon name="check"></k-icon>
|
|
65
61
|
</button>
|
|
62
|
+
<button id="cancelButton" class="icon-btn no-btn bg-danger">
|
|
63
|
+
<k-icon name="close"></k-icon>
|
|
64
|
+
</button>
|
|
66
65
|
`;
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
get shadowStyles() {
|
|
70
69
|
return /*css*/`
|
|
70
|
+
${super.shadowStyles}
|
|
71
71
|
:host {
|
|
72
72
|
display: inline-flex;
|
|
73
73
|
width: max-content;
|
|
74
74
|
align-items: baseline;
|
|
75
75
|
}
|
|
76
|
-
button {
|
|
77
|
-
display: flex;
|
|
78
|
-
align-items: center;
|
|
79
|
-
}
|
|
80
76
|
:host([editing]) #editButton,
|
|
81
77
|
:host(:not([editing])) #cancelButton,
|
|
82
78
|
:host(:not([editing])) #saveButton {
|
|
83
|
-
display: none;
|
|
79
|
+
display: none !important;
|
|
84
80
|
}
|
|
85
81
|
`;
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
|
-
window.customElements.define('k-
|
|
84
|
+
window.customElements.define('k-tc-edit', Edit);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
|
+
import '../Icon.js';
|
|
3
|
+
import { onEvent, offEvent } from '../../utils/element.js';
|
|
4
|
+
|
|
5
|
+
const clickHandler = Symbol('clickHandler');
|
|
6
|
+
export default class ExportCsv extends TableControl {
|
|
7
|
+
constructor() {
|
|
8
|
+
super({
|
|
9
|
+
maxWidth: 136
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/* Private Methods */
|
|
13
|
+
this[clickHandler] = this.export.bind(this);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* Lifecycle Callbacks */
|
|
17
|
+
async render(force = false){
|
|
18
|
+
if(await super.render(force)){
|
|
19
|
+
onEvent(this.shadowRoot.getElementById('export'), 'click', this[clickHandler]);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
disconnectedCallback(){
|
|
25
|
+
super.disconnectedCallback();
|
|
26
|
+
offEvent(this.shadowRoot.getElementById('export'), 'click', this[clickHandler]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* Public Methods */
|
|
30
|
+
getCSV(){
|
|
31
|
+
const table = this.table;
|
|
32
|
+
let csv = '';
|
|
33
|
+
if(table){
|
|
34
|
+
const fields = [];
|
|
35
|
+
table.fields.forEach( ({name, calculator}) => {
|
|
36
|
+
if(!calculator){
|
|
37
|
+
fields.push(name);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
csv += fields.join(',') + '\n';
|
|
41
|
+
if(this.record){
|
|
42
|
+
const record = this.record;
|
|
43
|
+
const row = [];
|
|
44
|
+
fields.forEach( field => {
|
|
45
|
+
row.push(record[field]);
|
|
46
|
+
});
|
|
47
|
+
csv += row.join(',') + '\n';
|
|
48
|
+
} else {
|
|
49
|
+
table.records.forEach( record => {
|
|
50
|
+
const row = [];
|
|
51
|
+
fields.forEach( field => {
|
|
52
|
+
row.push(record[field]);
|
|
53
|
+
});
|
|
54
|
+
csv += row.join(',') + '\n';
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return csv;
|
|
59
|
+
}
|
|
60
|
+
export(){
|
|
61
|
+
const data = this.getCSV();
|
|
62
|
+
const record = this.record;
|
|
63
|
+
if(record){
|
|
64
|
+
const blob = new Blob([data], {type: 'application/json'});
|
|
65
|
+
const url = URL.createObjectURL(blob);
|
|
66
|
+
const a = document.createElement('a');
|
|
67
|
+
a.href = url;
|
|
68
|
+
a.download = 'data.json';
|
|
69
|
+
a.click();
|
|
70
|
+
URL.revokeObjectURL(url);
|
|
71
|
+
} else {
|
|
72
|
+
const blob = new Blob([data], {type: 'application/json'});
|
|
73
|
+
const url = URL.createObjectURL(blob);
|
|
74
|
+
const a = document.createElement('a');
|
|
75
|
+
a.href = url;
|
|
76
|
+
a.download = 'data.json';
|
|
77
|
+
a.click();
|
|
78
|
+
URL.revokeObjectURL(url);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* Shadow DOM */
|
|
83
|
+
get shadowTemplate(){
|
|
84
|
+
return /*html*/`
|
|
85
|
+
<button id="export" class="no-btn ph">
|
|
86
|
+
<slot><k-icon name="export-file"></k-icon> Export CSV</slot>
|
|
87
|
+
</button>
|
|
88
|
+
`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
window.customElements.define('k-tc-export-csv', ExportCsv);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
|
+
import '../Icon.js';
|
|
3
|
+
import { onEvent, offEvent } from '../../utils/element.js';
|
|
4
|
+
|
|
5
|
+
const clickHandler = Symbol('clickHandler');
|
|
6
|
+
export default class ExportJson extends TableControl {
|
|
7
|
+
constructor() {
|
|
8
|
+
super({
|
|
9
|
+
maxWidth: 136
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/* Private Methods */
|
|
13
|
+
this[clickHandler] = this.export.bind(this);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* Lifecycle Callbacks */
|
|
17
|
+
async render(force = false){
|
|
18
|
+
if(await super.render(force)){
|
|
19
|
+
onEvent(this.shadowRoot.getElementById('export'), 'click', this[clickHandler]);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
disconnectedCallback(){
|
|
25
|
+
super.disconnectedCallback();
|
|
26
|
+
offEvent(this.shadowRoot.getElementById('export'), 'click', this[clickHandler]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* Public Methods */
|
|
30
|
+
export(){
|
|
31
|
+
const record = this.record;
|
|
32
|
+
if(record){
|
|
33
|
+
const data = JSON.stringify(record);
|
|
34
|
+
const blob = new Blob([data], {type: 'application/json'});
|
|
35
|
+
const url = URL.createObjectURL(blob);
|
|
36
|
+
const a = document.createElement('a');
|
|
37
|
+
a.href = url;
|
|
38
|
+
a.download = 'data.json';
|
|
39
|
+
a.click();
|
|
40
|
+
URL.revokeObjectURL(url);
|
|
41
|
+
} else {
|
|
42
|
+
const data = JSON.stringify(this.table.records);
|
|
43
|
+
const blob = new Blob([data], {type: 'application/json'});
|
|
44
|
+
const url = URL.createObjectURL(blob);
|
|
45
|
+
const a = document.createElement('a');
|
|
46
|
+
a.href = url;
|
|
47
|
+
a.download = 'data.json';
|
|
48
|
+
a.click();
|
|
49
|
+
URL.revokeObjectURL(url);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Shadow DOM */
|
|
54
|
+
get shadowTemplate(){
|
|
55
|
+
return /*html*/`
|
|
56
|
+
<button id="export" class="no-btn ph">
|
|
57
|
+
<slot><k-icon name="export-file"></k-icon> Export JSON</slot>
|
|
58
|
+
</button>
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
window.customElements.define('k-tc-export-json', ExportJson);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
|
+
import { onEvent, offEvent } from '../../utils/element.js';
|
|
3
|
+
import Dialog from '../Dialog.js';
|
|
4
|
+
|
|
5
|
+
const clickHandler = Symbol('clickHandler');
|
|
6
|
+
export default class FieldSortHide extends TableControl {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
/* Private Methods */
|
|
11
|
+
this[clickHandler] = this.openDialog.bind(this);
|
|
12
|
+
}
|
|
13
|
+
async render(force = false) {
|
|
14
|
+
if (await super.render(force)) {
|
|
15
|
+
onEvent(this.shadowRoot.getElementById('sort'), 'click', this[clickHandler]);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
disconnectedCallback() {
|
|
21
|
+
super.disconnectedCallback();
|
|
22
|
+
offEvent(this.shadowRoot.getElementById('sort'), 'click', this[clickHandler]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
openDialog() {
|
|
26
|
+
import('../Sortable.js')
|
|
27
|
+
const $dialog = Dialog.create(/*html*/`
|
|
28
|
+
<h3 class="m0 ph" slot="title">Show / Hide Fields</h3>
|
|
29
|
+
<div class="m">
|
|
30
|
+
<k-sortable id="sorting">
|
|
31
|
+
${this.table.fields.map(field => /*html*/`
|
|
32
|
+
<k-sortable-item data-field="${field.name}">
|
|
33
|
+
<label class="field pb0">
|
|
34
|
+
<input
|
|
35
|
+
class="field-visibility"
|
|
36
|
+
data-field="${field.name}"
|
|
37
|
+
type="checkbox"
|
|
38
|
+
${field.hidden ? '' : 'checked'}
|
|
39
|
+
style="height: 1.25rem; width: 1.25rem"
|
|
40
|
+
/>
|
|
41
|
+
${field.label}
|
|
42
|
+
</label>
|
|
43
|
+
</k-sortable-item>
|
|
44
|
+
`).join('')}
|
|
45
|
+
</k-sortable>
|
|
46
|
+
</div>
|
|
47
|
+
`, {
|
|
48
|
+
width: '400px',
|
|
49
|
+
cancelText: 'Close'
|
|
50
|
+
});
|
|
51
|
+
onEvent($dialog, 'click', (event) => {
|
|
52
|
+
if (!event.target.closest('.field')) return;
|
|
53
|
+
const $input = event.target.closest('.field-visibility');
|
|
54
|
+
if ($input) {
|
|
55
|
+
const fieldName = $input.getAttribute('data-field');
|
|
56
|
+
this.table.setFieldHiddenState(fieldName, !$input.checked);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const $sorting = $dialog.querySelector('#sorting');
|
|
60
|
+
onEvent($sorting, 'sort', () => {
|
|
61
|
+
const newOrder = Array.from($sorting.querySelectorAll('k-sortable-item')).map(item => item.getAttribute('data-field'));
|
|
62
|
+
this.table.reorderFields(newOrder);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get shadowTemplate() {
|
|
67
|
+
return /*html*/`
|
|
68
|
+
<button
|
|
69
|
+
id="sort"
|
|
70
|
+
class="no-btn icon-btn"
|
|
71
|
+
>
|
|
72
|
+
<k-icon name="table-visibility"></k-icon>
|
|
73
|
+
</button>
|
|
74
|
+
`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
window.customElements.define('k-tc-field-sort-hide', FieldSortHide);
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
2
|
import Dialog from '../Dialog.js';
|
|
3
3
|
import { offEvent, onEvent } from '../../utils/element.js';
|
|
4
4
|
|
|
5
5
|
const table = Symbol('table'),
|
|
6
6
|
clickHandler = Symbol('clickHandler');
|
|
7
|
-
export default class Filters extends
|
|
8
|
-
constructor(
|
|
7
|
+
export default class Filters extends TableControl {
|
|
8
|
+
constructor() {
|
|
9
9
|
super();
|
|
10
10
|
|
|
11
|
-
/* Private Members */
|
|
12
|
-
this[table] = _table;
|
|
13
|
-
|
|
14
11
|
/* Private Methods */
|
|
15
12
|
this[clickHandler] = this.revealFilters.bind(this);
|
|
16
|
-
|
|
17
|
-
/* Init */
|
|
18
|
-
this.classList.add('mxq');
|
|
19
13
|
}
|
|
20
14
|
|
|
21
15
|
/* Lifecycle Callbacks */
|
|
@@ -59,19 +53,19 @@ export default class Filters extends Component {
|
|
|
59
53
|
const $dialog = Dialog.create( /*html*/`
|
|
60
54
|
<h3 slot="title" class="m0 pyh px">Filters</h3>
|
|
61
55
|
<div class="p">
|
|
62
|
-
${this
|
|
56
|
+
${this.table.filters.length === 0 ? /*html*/`
|
|
63
57
|
<p>No Current Filters.</p>
|
|
64
58
|
` : /*html*/`
|
|
65
59
|
<h5>Current Filters</h5>
|
|
66
60
|
<ul id="currentFilters">${
|
|
67
|
-
this
|
|
61
|
+
this.table.filters.map(formatFilter).join('')
|
|
68
62
|
}</ul>
|
|
69
63
|
`}
|
|
70
64
|
<hr />
|
|
71
65
|
<h5>Add A Filter</h5>
|
|
72
66
|
<form id="addFilter">
|
|
73
67
|
<select id="filterField" class="mb">${
|
|
74
|
-
this
|
|
68
|
+
this.table.fields.map(({name, label}) => /*html*/`<option value="${name}">${label}</option>`).join('')
|
|
75
69
|
}</select>
|
|
76
70
|
<select id="filterCondition" class="mb">${
|
|
77
71
|
Object.entries({
|
|
@@ -87,7 +81,10 @@ export default class Filters extends Component {
|
|
|
87
81
|
}).map(([key, value]) => /*html*/`<option value="${key}" ${key==='contains'?'selected':''}>${value}</option>`).join('')
|
|
88
82
|
}</select>
|
|
89
83
|
<input id="filterValue" type="text" class="mb" />
|
|
90
|
-
<button type="submit" class="btn primary">Add Filter</button>
|
|
84
|
+
<button type="submit" class="btn primary mb mr">Add Filter</button>
|
|
85
|
+
${this.table.filters.length === 0 ? '' : /*html*/`
|
|
86
|
+
<button type="button" id="clearFilters" class="btn danger mb mr">Clear All Filters</button>
|
|
87
|
+
`}
|
|
91
88
|
</form>
|
|
92
89
|
</div>
|
|
93
90
|
`, {
|
|
@@ -96,7 +93,7 @@ export default class Filters extends Component {
|
|
|
96
93
|
const $form = $dialog.querySelector('#addFilter');
|
|
97
94
|
onEvent($form, 'submit', (e) => {
|
|
98
95
|
e.preventDefault();
|
|
99
|
-
this
|
|
96
|
+
this.table.addFilter(
|
|
100
97
|
$form.filterField.value,
|
|
101
98
|
$form.filterCondition.value,
|
|
102
99
|
$form.filterValue.value
|
|
@@ -109,20 +106,24 @@ export default class Filters extends Component {
|
|
|
109
106
|
const $li = e.target.closest('li');
|
|
110
107
|
if($li){
|
|
111
108
|
const {field, condition, value} = $li.dataset;
|
|
112
|
-
this
|
|
109
|
+
this.table.removeFilter(field, condition, value);
|
|
113
110
|
$dialog.close();
|
|
114
111
|
this.revealFilters();
|
|
115
112
|
}
|
|
116
113
|
}
|
|
114
|
+
if(e.target.id === 'clearFilters'){
|
|
115
|
+
this.table.removeAllFilters();
|
|
116
|
+
$dialog.close();
|
|
117
|
+
}
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
get shadowTemplate() {
|
|
121
122
|
return /*html*/`
|
|
122
|
-
<button id="filterBtn" class="no-btn
|
|
123
|
+
<button id="filterBtn" class="no-btn icon-btn">
|
|
123
124
|
<k-icon name="filter"></k-icon>
|
|
124
125
|
</button>
|
|
125
126
|
`;
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
|
-
window.customElements.define('k-
|
|
129
|
+
window.customElements.define('k-tc-filters', Filters);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
|
+
import { onEvent, offEvent } from '../../utils/element.js';
|
|
3
|
+
|
|
4
|
+
const clickHandler = Symbol('clickHandler'),
|
|
5
|
+
handlePageChange = Symbol('handlePageChange');
|
|
6
|
+
export default class FirstPage extends TableControl {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
/* Private Methods */
|
|
11
|
+
this[clickHandler] = this.goToFirstPage.bind(this);
|
|
12
|
+
this[handlePageChange] = (()=>{
|
|
13
|
+
const table = this.table;
|
|
14
|
+
if(!table || table.getCurrentPage() === 1){
|
|
15
|
+
this.shadowRoot.getElementById('firstPage').disabled = true;
|
|
16
|
+
} else {
|
|
17
|
+
this.shadowRoot.getElementById('firstPage').disabled = false;
|
|
18
|
+
}
|
|
19
|
+
}).bind(this);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* Lifecycle Callback */
|
|
23
|
+
async render(force = false) {
|
|
24
|
+
if(await super.render(force)) {
|
|
25
|
+
onEvent(this.shadowRoot.getElementById('firstPage'), 'click', this[clickHandler]);
|
|
26
|
+
this[handlePageChange]();
|
|
27
|
+
onEvent(this.table, 'pageChange', this[handlePageChange]);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
disconnectedCallback(){
|
|
33
|
+
super.disconnectedCallback();
|
|
34
|
+
offEvent(this.shadowRoot.getElementById('firstPage'), 'click', this[clickHandler]);
|
|
35
|
+
offEvent(this.table, 'pageChange', this[handlePageChange]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* Public Methods */
|
|
39
|
+
goToFirstPage(){
|
|
40
|
+
const table = this.table;
|
|
41
|
+
if(table){
|
|
42
|
+
table.firstPage();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* Shadow DOM */
|
|
47
|
+
get shadowTemplate(){
|
|
48
|
+
return /*html*/`
|
|
49
|
+
<button
|
|
50
|
+
id="firstPage"
|
|
51
|
+
class="no-btn icon-btn"
|
|
52
|
+
>
|
|
53
|
+
<slot><k-icon name="first"></k-icon></slot>
|
|
54
|
+
</button>
|
|
55
|
+
`;
|
|
56
|
+
}
|
|
57
|
+
get shadowStyles(){
|
|
58
|
+
return /*css*/`
|
|
59
|
+
${super.shadowStyles}
|
|
60
|
+
#firstPage[disabled] {
|
|
61
|
+
cursor: inherit;
|
|
62
|
+
opacity: 0.5;
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
window.customElements.define('k-tc-first-page', FirstPage);
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
2
|
import { offEvent, onEvent } from '../../utils/element.js';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export default class HiddenCount extends Component {
|
|
8
|
-
constructor(_table, _record) {
|
|
4
|
+
const hiddenChangeHandler = Symbol('hiddenChangeHandler');
|
|
5
|
+
export default class HiddenCount extends TableControl {
|
|
6
|
+
constructor() {
|
|
9
7
|
super();
|
|
10
8
|
|
|
11
|
-
/* Private Members */
|
|
12
|
-
this[table] = _table;
|
|
13
|
-
this[record] = _record;
|
|
14
|
-
|
|
15
9
|
/* Private Methods */
|
|
16
10
|
this[hiddenChangeHandler] = (()=>{
|
|
17
|
-
this.shadowRoot.getElementById('hiddenCount').textContent = this
|
|
11
|
+
this.shadowRoot.getElementById('hiddenCount').textContent = this.table.getHiddenRecords().length;
|
|
18
12
|
}).bind(this);
|
|
19
13
|
|
|
20
14
|
/* Init */
|
|
@@ -23,20 +17,21 @@ export default class HiddenCount extends Component {
|
|
|
23
17
|
async render(force = false) {
|
|
24
18
|
if (await super.render(force)) {
|
|
25
19
|
this[hiddenChangeHandler]()
|
|
26
|
-
onEvent(this
|
|
20
|
+
onEvent(this.table, 'recordHidden recordShown', this[hiddenChangeHandler]);
|
|
27
21
|
return true;
|
|
28
22
|
}
|
|
29
23
|
return false;
|
|
30
24
|
}
|
|
31
25
|
disconnectedCallback(){
|
|
32
26
|
super.disconnectedCallback();
|
|
33
|
-
offEvent(this
|
|
27
|
+
offEvent(this.table, 'recordHidden recordShown', this[hiddenChangeHandler]);
|
|
34
28
|
}
|
|
35
29
|
|
|
30
|
+
/* Shadow DOM */
|
|
36
31
|
get shadowTemplate() {
|
|
37
32
|
return /*html*/`
|
|
38
|
-
<span id="hiddenCount"></span
|
|
33
|
+
<span id="hiddenCount"></span> Hidden Records
|
|
39
34
|
`;
|
|
40
35
|
}
|
|
41
36
|
}
|
|
42
|
-
window.customElements.define('k-
|
|
37
|
+
window.customElements.define('k-tc-hidden-count', HiddenCount);
|