kempo 2.9.4 → 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/Dialog.js +1 -1
- package/dist/components/Icon.js +1 -1
- package/dist/components/Search.js +1 -1
- 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 -0
- 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 -0
- package/dist/components/tableControls/FirstPage.js +1 -0
- package/dist/components/tableControls/HiddenCount.js +1 -0
- package/dist/components/tableControls/Hide.js +1 -0
- 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 -0
- package/dist/components/tableControls/ShowHideFields.js +1 -0
- package/dist/components/tableControls/TableControl.js +1 -0
- package/dist/index.js +1 -1
- package/dist/kempo-styles.css +1 -1
- package/dist/kempo-vars.css +1 -1
- package/docs/components/sortable.html +96 -0
- package/docs/components/table.html +108 -182
- package/docs/components/tableControls.html +77 -0
- package/docs/components/tableCustomFields.html +112 -0
- package/docs/components/tableFetchRecords.html +114 -0
- package/docs/components/tableFieldSortHide.html +75 -0
- package/docs/components/tablePagination.html +100 -0
- package/docs/components/tableRecordEditing.html +144 -0
- package/docs/components/tableRecordFiltering.html +75 -0
- package/docs/components/tableRecordHiding.html +80 -0
- package/docs/components/tableRecordSearching.html +75 -0
- package/docs/components/tableRecordSelection.html +75 -0
- package/docs/components/tableRowControls.html +78 -0
- 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/check.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/hide.svg +1 -0
- package/docs/icons/last.svg +1 -0
- package/docs/icons/show.svg +1 -0
- package/docs/icons/table-visibility.svg +1 -0
- package/docs/kempo/components/Dialog.js +1 -1
- package/docs/kempo/components/Icon.js +1 -1
- package/docs/kempo/components/Search.js +1 -1
- 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 -0
- 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 -0
- package/docs/kempo/components/tableControls/FirstPage.js +1 -0
- package/docs/kempo/components/tableControls/HiddenCount.js +1 -0
- package/docs/kempo/components/tableControls/Hide.js +1 -0
- 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 -0
- 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/docs/kempo/kempo-styles.css +1 -1
- package/docs/kempo/kempo-vars.css +1 -1
- package/icons/arrow-down.svg +1 -0
- package/icons/arrow-up.svg +1 -0
- package/icons/check.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/hide.svg +1 -0
- package/icons/last.svg +1 -0
- package/icons/show.svg +1 -0
- package/icons/table-visibility.svg +1 -0
- package/package.json +1 -1
- package/src/components/Dialog.js +12 -4
- package/src/components/Icon.js +3 -1
- package/src/components/Sortable.js +169 -0
- package/src/components/Table.js +703 -247
- package/src/components/tableControls/DeleteRecord.js +43 -0
- package/src/components/tableControls/DeleteSelected.js +36 -24
- package/src/components/tableControls/Edit.js +84 -0
- 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 +129 -0
- package/src/components/tableControls/FirstPage.js +69 -0
- package/src/components/tableControls/HiddenCount.js +37 -0
- package/src/components/tableControls/Hide.js +40 -0
- package/src/components/tableControls/LastPage.js +67 -0
- package/src/components/tableControls/NextPage.js +69 -0
- package/src/components/tableControls/PageSelect.js +55 -34
- package/src/components/tableControls/PageSize.js +31 -17
- 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 +37 -0
- package/src/components/tableControls/TableControl.js +51 -0
- package/src/kempo-styles.css +7 -0
- package/src/kempo-vars.css +2 -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,36 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { onEvent } from '../../utils/element.js';
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
|
+
import { onEvent, offEvent } from '../../utils/element.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const deleteSelected = Symbol('deleteSelected'),
|
|
5
|
+
updateButtonState = Symbol('updateButtonState');
|
|
6
|
+
export default class DeleteSelected extends TableControl {
|
|
7
|
+
constructor() {
|
|
6
8
|
super();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
|
|
10
|
+
/* Private Methods */
|
|
11
|
+
this[deleteSelected] = this.deleteSelected.bind(this);
|
|
12
|
+
this[updateButtonState] = (()=>{
|
|
13
|
+
this.shadowRoot.getElementById('deleteSelectedButton').disabled = this.table.getSelectedRecords().length === 0;
|
|
14
|
+
}).bind(this);
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/* Init */
|
|
18
|
+
|
|
9
19
|
}
|
|
10
20
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
onEvent(
|
|
16
|
-
onEvent(this.table, 'selectionChange',
|
|
21
|
+
/* Lifecycle Callbacks */
|
|
22
|
+
async render(force = false) {
|
|
23
|
+
if (await super.render(force)) {
|
|
24
|
+
this[updateButtonState]();
|
|
25
|
+
onEvent(this.shadowRoot.getElementById('deleteSelectedButton'), 'click', this[deleteSelected]);
|
|
26
|
+
onEvent(this.table, 'selectionChange', this[updateButtonState]);
|
|
17
27
|
return true;
|
|
18
28
|
}
|
|
19
29
|
return false;
|
|
20
30
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
selectedIndexes.forEach(index => this.table.deleteRecord(index));
|
|
26
|
-
this.table.selectedIndexes = [];
|
|
27
|
-
this.table.renderRecords();
|
|
28
|
-
this.updateButtonState();
|
|
31
|
+
disconnectedCallback(){
|
|
32
|
+
super.disconnectedCallback();
|
|
33
|
+
offEvent(this.shadowRoot.getElementById('deleteSelectedButton'), 'click', this[deleteSelected]);
|
|
34
|
+
offEvent(this.table, 'selectionChange', this[updateButtonState]);
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
/* Public Methods */
|
|
38
|
+
deleteSelected() {
|
|
39
|
+
this.table.deleteSelected();
|
|
40
|
+
this[updateButtonState]();
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
get shadowTemplate() {
|
|
@@ -48,10 +55,15 @@ export default class DeleteSelected extends Component {
|
|
|
48
55
|
width: max-content;
|
|
49
56
|
align-items: baseline;
|
|
50
57
|
}
|
|
51
|
-
|
|
58
|
+
#deleteSelectedButton {
|
|
52
59
|
display: flex;
|
|
53
60
|
align-items: center;
|
|
54
61
|
}
|
|
62
|
+
#deleteSelectedButton:disabled,
|
|
63
|
+
#deleteSelectedButton[disabled] {
|
|
64
|
+
cursor: not-allowed;
|
|
65
|
+
opacity: 0.5;
|
|
66
|
+
}
|
|
55
67
|
`;
|
|
56
68
|
}
|
|
57
69
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
|
+
import { offEvent, onEvent } from '../../utils/element.js';
|
|
3
|
+
|
|
4
|
+
const editRecord = Symbol('editRecord'),
|
|
5
|
+
saveRecord = Symbol('saveRecord'),
|
|
6
|
+
cancelEdit = Symbol('cancelEdit');
|
|
7
|
+
export default class Edit extends TableControl {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/* Private Methods */
|
|
13
|
+
this[editRecord] = this.editRecord.bind(this);
|
|
14
|
+
this[saveRecord] = this.saveRecord.bind(this);
|
|
15
|
+
this[cancelEdit] = this.cancelEdit.bind(this);
|
|
16
|
+
|
|
17
|
+
/* Init */
|
|
18
|
+
this.registerAttributes({
|
|
19
|
+
editing: false
|
|
20
|
+
});
|
|
21
|
+
this.maxWidth = 80;
|
|
22
|
+
}
|
|
23
|
+
async render(force = false) {
|
|
24
|
+
if (await super.render(force)) {
|
|
25
|
+
const record = this.record;
|
|
26
|
+
if(record){
|
|
27
|
+
this.editing = this.table.recordIsEditing(record)
|
|
28
|
+
}
|
|
29
|
+
onEvent(this.shadowRoot.getElementById('editButton'), 'click', this[editRecord]);
|
|
30
|
+
onEvent(this.shadowRoot.getElementById('saveButton'), 'click', this[saveRecord]);
|
|
31
|
+
onEvent(this.shadowRoot.getElementById('cancelButton'), 'click', this[cancelEdit]);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
disconnectedCallback(){
|
|
37
|
+
super.disconnectedCallback();
|
|
38
|
+
offEvent(this.shadowRoot.getElementById('editButton'), 'click', this[editRecord]);
|
|
39
|
+
offEvent(this.shadowRoot.getElementById('saveButton'), 'click', this[saveRecord]);
|
|
40
|
+
offEvent(this.shadowRoot.getElementById('cancelButton'), 'click', this[cancelEdit]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* Public Methods */
|
|
44
|
+
editRecord() {
|
|
45
|
+
this.table.editRecord(this.record);
|
|
46
|
+
}
|
|
47
|
+
saveRecord() {
|
|
48
|
+
this.table.saveEditedRecord(this.record);
|
|
49
|
+
}
|
|
50
|
+
cancelEdit() {
|
|
51
|
+
this.table.cancelEditedRecord(this.record);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get shadowTemplate() {
|
|
55
|
+
return /*html*/`
|
|
56
|
+
<button id="editButton" class="icon-btn no-btn">
|
|
57
|
+
<k-icon name="edit"></k-icon>
|
|
58
|
+
</button>
|
|
59
|
+
<button id="saveButton" class="icon-btn no-btn bg-success">
|
|
60
|
+
<k-icon name="check"></k-icon>
|
|
61
|
+
</button>
|
|
62
|
+
<button id="cancelButton" class="icon-btn no-btn bg-danger">
|
|
63
|
+
<k-icon name="close"></k-icon>
|
|
64
|
+
</button>
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get shadowStyles() {
|
|
69
|
+
return /*css*/`
|
|
70
|
+
${super.shadowStyles}
|
|
71
|
+
:host {
|
|
72
|
+
display: inline-flex;
|
|
73
|
+
width: max-content;
|
|
74
|
+
align-items: baseline;
|
|
75
|
+
}
|
|
76
|
+
:host([editing]) #editButton,
|
|
77
|
+
:host(:not([editing])) #cancelButton,
|
|
78
|
+
:host(:not([editing])) #saveButton {
|
|
79
|
+
display: none !important;
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
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);
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
|
+
import Dialog from '../Dialog.js';
|
|
3
|
+
import { offEvent, onEvent } from '../../utils/element.js';
|
|
4
|
+
|
|
5
|
+
const table = Symbol('table'),
|
|
6
|
+
clickHandler = Symbol('clickHandler');
|
|
7
|
+
export default class Filters extends TableControl {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
/* Private Methods */
|
|
12
|
+
this[clickHandler] = this.revealFilters.bind(this);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* Lifecycle Callbacks */
|
|
16
|
+
async render(force = false) {
|
|
17
|
+
if (await super.render(force)) {
|
|
18
|
+
onEvent(this.shadowRoot.getElementById('filterBtn'), 'click', this[clickHandler]);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
disconnectedCallback(){
|
|
24
|
+
super.disconnectedCallback();
|
|
25
|
+
offEvent(this.shadowRoot.getElementById('filterBtn'), 'click', this[clickHandler]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Public Methods */
|
|
29
|
+
revealFilters() {
|
|
30
|
+
function formatFilter({field, condition, value}) {
|
|
31
|
+
const conditionLabel = {
|
|
32
|
+
eq: 'equals',
|
|
33
|
+
ne: 'does not equal',
|
|
34
|
+
gt: 'is greater than',
|
|
35
|
+
gte: 'is greater than or equal to',
|
|
36
|
+
lt: 'is less than',
|
|
37
|
+
lte: 'is less than or equal to',
|
|
38
|
+
contains: 'contains',
|
|
39
|
+
starts: 'starts with',
|
|
40
|
+
ends: 'ends with'
|
|
41
|
+
}[condition];
|
|
42
|
+
return /*html*/`<li
|
|
43
|
+
data-field="${field}"
|
|
44
|
+
data-condition="${condition}"
|
|
45
|
+
data-value="${value}"
|
|
46
|
+
>
|
|
47
|
+
${field} ${conditionLabel} ${value}
|
|
48
|
+
<button class="remove-filter no-btn pq">
|
|
49
|
+
<k-icon name="close"></k-icon>
|
|
50
|
+
</button>
|
|
51
|
+
</li>`;
|
|
52
|
+
}
|
|
53
|
+
const $dialog = Dialog.create( /*html*/`
|
|
54
|
+
<h3 slot="title" class="m0 pyh px">Filters</h3>
|
|
55
|
+
<div class="p">
|
|
56
|
+
${this.table.filters.length === 0 ? /*html*/`
|
|
57
|
+
<p>No Current Filters.</p>
|
|
58
|
+
` : /*html*/`
|
|
59
|
+
<h5>Current Filters</h5>
|
|
60
|
+
<ul id="currentFilters">${
|
|
61
|
+
this.table.filters.map(formatFilter).join('')
|
|
62
|
+
}</ul>
|
|
63
|
+
`}
|
|
64
|
+
<hr />
|
|
65
|
+
<h5>Add A Filter</h5>
|
|
66
|
+
<form id="addFilter">
|
|
67
|
+
<select id="filterField" class="mb">${
|
|
68
|
+
this.table.fields.map(({name, label}) => /*html*/`<option value="${name}">${label}</option>`).join('')
|
|
69
|
+
}</select>
|
|
70
|
+
<select id="filterCondition" class="mb">${
|
|
71
|
+
Object.entries({
|
|
72
|
+
eq: 'equals',
|
|
73
|
+
ne: 'does not equal',
|
|
74
|
+
gt: 'is greater than',
|
|
75
|
+
gte: 'is greater than or equal to',
|
|
76
|
+
lt: 'is less than',
|
|
77
|
+
lte: 'is less than or equal to',
|
|
78
|
+
contains: 'contains',
|
|
79
|
+
starts: 'starts with',
|
|
80
|
+
ends: 'ends with'
|
|
81
|
+
}).map(([key, value]) => /*html*/`<option value="${key}" ${key==='contains'?'selected':''}>${value}</option>`).join('')
|
|
82
|
+
}</select>
|
|
83
|
+
<input id="filterValue" type="text" class="mb" />
|
|
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
|
+
`}
|
|
88
|
+
</form>
|
|
89
|
+
</div>
|
|
90
|
+
`, {
|
|
91
|
+
width: '600px'
|
|
92
|
+
});
|
|
93
|
+
const $form = $dialog.querySelector('#addFilter');
|
|
94
|
+
onEvent($form, 'submit', (e) => {
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
this.table.addFilter(
|
|
97
|
+
$form.filterField.value,
|
|
98
|
+
$form.filterCondition.value,
|
|
99
|
+
$form.filterValue.value
|
|
100
|
+
);
|
|
101
|
+
$dialog.close();
|
|
102
|
+
this.revealFilters();
|
|
103
|
+
});
|
|
104
|
+
onEvent($dialog, 'click', (e) => {
|
|
105
|
+
if(e.target.closest('button')?.classList.contains('remove-filter')){
|
|
106
|
+
const $li = e.target.closest('li');
|
|
107
|
+
if($li){
|
|
108
|
+
const {field, condition, value} = $li.dataset;
|
|
109
|
+
this.table.removeFilter(field, condition, value);
|
|
110
|
+
$dialog.close();
|
|
111
|
+
this.revealFilters();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if(e.target.id === 'clearFilters'){
|
|
115
|
+
this.table.removeAllFilters();
|
|
116
|
+
$dialog.close();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
get shadowTemplate() {
|
|
122
|
+
return /*html*/`
|
|
123
|
+
<button id="filterBtn" class="no-btn icon-btn">
|
|
124
|
+
<k-icon name="filter"></k-icon>
|
|
125
|
+
</button>
|
|
126
|
+
`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
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);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import TableControl from './TableControl.js';
|
|
2
|
+
import { offEvent, onEvent } from '../../utils/element.js';
|
|
3
|
+
|
|
4
|
+
const hiddenChangeHandler = Symbol('hiddenChangeHandler');
|
|
5
|
+
export default class HiddenCount extends TableControl {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
|
|
9
|
+
/* Private Methods */
|
|
10
|
+
this[hiddenChangeHandler] = (()=>{
|
|
11
|
+
this.shadowRoot.getElementById('hiddenCount').textContent = this.table.getHiddenRecords().length;
|
|
12
|
+
}).bind(this);
|
|
13
|
+
|
|
14
|
+
/* Init */
|
|
15
|
+
this.classList.add('mq');
|
|
16
|
+
}
|
|
17
|
+
async render(force = false) {
|
|
18
|
+
if (await super.render(force)) {
|
|
19
|
+
this[hiddenChangeHandler]()
|
|
20
|
+
onEvent(this.table, 'recordHidden recordShown', this[hiddenChangeHandler]);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
disconnectedCallback(){
|
|
26
|
+
super.disconnectedCallback();
|
|
27
|
+
offEvent(this.table, 'recordHidden recordShown', this[hiddenChangeHandler]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* Shadow DOM */
|
|
31
|
+
get shadowTemplate() {
|
|
32
|
+
return /*html*/`
|
|
33
|
+
<span id="hiddenCount"></span> Hidden Records
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
window.customElements.define('k-tc-hidden-count', HiddenCount);
|