[feat] Toast Message

This commit is contained in:
Faris Ansari 2018-03-02 21:22:36 +05:30
parent 470ab90fef
commit 128a674ad6
4 changed files with 69 additions and 35 deletions

View File

@ -87,6 +87,14 @@ export default class BodyRenderer {
this.clusterize.append(data); this.clusterize.append(data);
} }
showToastMessage(message) {
this.instance.toastMessage.innerHTML = `<span>${message}</span>`;
}
clearToastMessage() {
this.instance.toastMessage.innerHTML = '';
}
getDataForClusterize(rows) { getDataForClusterize(rows) {
return rows.map((row) => this.rowmanager.getRowHTML(row, row.meta)); return rows.map((row) => this.rowmanager.getRowHTML(row, row.meta));
} }

View File

@ -52,23 +52,25 @@ class DataTable {
prepareDom() { prepareDom() {
this.wrapper.innerHTML = ` this.wrapper.innerHTML = `
<div class="data-table"> <div class="data-table">
<table class="data-table-header"> <table class="data-table-header">
</table> </table>
<div class="body-scrollable"> <div class="body-scrollable">
</div> </div>
<div class="freeze-container"> <div class="freeze-container">
<span>${this.options.freezeMessage}</span> <span>${this.options.freezeMessage}</span>
</div> </div>
<div class="data-table-footer"> <div class="data-table-footer">
</div> </div>
</div> <div class="toast-message"></div>
`; </div>
`;
this.datatableWrapper = $('.data-table', this.wrapper); this.datatableWrapper = $('.data-table', this.wrapper);
this.header = $('.data-table-header', this.wrapper); this.header = $('.data-table-header', this.wrapper);
this.bodyScrollable = $('.body-scrollable', this.wrapper); this.bodyScrollable = $('.body-scrollable', this.wrapper);
this.freezeContainer = $('.freeze-container', this.wrapper); this.freezeContainer = $('.freeze-container', this.wrapper);
this.toastMessage = $('.toast-message', this.wrapper);
} }
refresh(data) { refresh(data) {
@ -108,6 +110,14 @@ class DataTable {
this.style.setDimensions(); this.style.setDimensions();
} }
showToastMessage(message) {
this.bodyRenderer.showToastMessage(message);
}
clearToastMessage() {
this.bodyRenderer.clearToastMessage();
}
getColumn(colIndex) { getColumn(colIndex) {
return this.datamanager.getColumn(colIndex); return this.datamanager.getColumn(colIndex);
} }

View File

@ -12,7 +12,8 @@ export default class RowManager {
linkProperties(this, this.instance, [ linkProperties(this, this.instance, [
'options', 'options',
'wrapper', 'wrapper',
'bodyScrollable' 'bodyScrollable',
'bodyRenderer'
]); ]);
this.bindEvents(); this.bindEvents();
@ -71,16 +72,15 @@ export default class RowManager {
return []; return [];
} }
return this.checkMap let out = [];
.map((c, rowIndex) => { for (let rowIndex in this.checkMap) {
if (c) { const checked = this.checkMap[rowIndex];
return rowIndex; if (checked === 1) {
} out.push(rowIndex)
return null; }
}) }
.filter(c => {
return c !== null || c !== undefined; return out;
});
} }
highlightCheckedRows() { highlightCheckedRows() {
@ -101,6 +101,7 @@ export default class RowManager {
}); });
// highlight row // highlight row
this.highlightRow(rowIndex, toggle); this.highlightRow(rowIndex, toggle);
this.showCheckStatus();
} }
checkAll(toggle) { checkAll(toggle) {
@ -119,6 +120,16 @@ export default class RowManager {
}); });
// highlight all // highlight all
this.highlightAll(toggle); this.highlightAll(toggle);
this.showCheckStatus();
}
showCheckStatus() {
const checkedRows = this.getCheckedRows();
if (checkedRows.length > 0) {
this.bodyRenderer.showToastMessage(checkedRows.length + ' rows selected');
} else {
this.bodyRenderer.clearToastMessage();
}
} }
highlightRow(rowIndex, toggle = true) { highlightRow(rowIndex, toggle = true) {

View File

@ -7,6 +7,7 @@
--light-bg: #f5f7fa; --light-bg: #f5f7fa;
--light-red: #FD8B8B; --light-red: #FD8B8B;
--text-color: #000000; --text-color: #000000;
--text-light: #dfe2e5;
--spacer-1: 0.25rem; --spacer-1: 0.25rem;
--spacer-2: 0.5rem; --spacer-2: 0.5rem;
@ -41,7 +42,6 @@
} }
/* styling */ /* styling */
width: 100%;
position: relative; position: relative;
overflow: auto; overflow: auto;
@ -78,19 +78,24 @@
} }
} }
.trash-container {
position: absolute;
bottom: 0;
left: 30%;
right: 30%;
height: 70px;
background: palevioletred;
opacity: 0.5;
}
.hide { .hide {
display: none; display: none;
} }
.toast-message {
position: absolute;
bottom: var(--spacer-3);
left: 50%;
transform: translateX(-50%);
span {
display: inline-block;
background-color: rgba(0, 0, 0, 0.8);
color: var(--text-light);
border-radius: 3px;
padding: var(--spacer-2) var(--spacer-3);
}
}
} }
.body-scrollable { .body-scrollable {
@ -272,4 +277,4 @@
body.data-table-resize { body.data-table-resize {
cursor: col-resize; cursor: col-resize;
} }