import { CommonModule } from '@angular/common';
import { Component, EventEmitter, Input, Output, NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class DataTableComponent {
constructor() {
this.deleteRow = new EventEmitter();
this.updateRow = new EventEmitter();
this.data = {};
this.displayed = [];
this.perpage = 10;
this.page = 1;
this.checked = [];
this.checkAll = false;
this.dialogue = false;
this.dialogeData = {};
}
/**
* @return {?}
*/
ngOnInit() {
this.processData();
}
/**
* @param {?} e
* @param {?} id
* @return {?}
*/
selected(e, id) {
if (e.target.checked) {
this.checked.push(id);
}
}
/**
* @return {?}
*/
deleteSelected() {
if (this.checked.length > 0) {
this.deleteRow.emit(this.checked);
this.dataSource = this.dataSource.filter((value, index, array) => {
return !this.checked.includes(value.id);
});
this.checked = [];
this.paginate(this.page);
}
}
/**
* @return {?}
*/
totalItems() {
if (this.total > this.perpage) {
return Math.ceil(this.total / this.perpage);
}
else {
return 1;
}
}
/**
* @param {?} page
* @return {?}
*/
paginate(page) {
/** @type {?} */
const start = (this.perpage * page) - this.perpage;
/** @type {?} */
const end = (this.perpage * page);
// console.log(start, end);
this.data['data'] = this.dataSource.slice(start, end);
// console.log(this.data);
}
/**
* @param {?} perPage
* @return {?}
*/
pageOnChange(perPage) {
this.perpage = perPage;
this.page = 1;
//console.log(perPage);
this.paginate(this.page);
}
/**
* @return {?}
*/
previousPage() {
if (this.page > 1) {
this.page--;
}
this.paginate(this.page);
}
/**
* @return {?}
*/
nextPage() {
if (this.page + 1 <= this.totalItems()) {
this.page++;
}
this.paginate(this.page);
}
/**
* @param {?} id
* @return {?}
*/
showUpdate(id) {
this.dialogue = true;
// console.log('Showing the updates');
this.data.data.forEach((value) => {
if (value.id === id) {
this.dialogeData = value;
}
});
}
/**
* @return {?}
*/
closeDialogue() {
this.dialogue ? this.dialogue = false : this.dialogue = true;
this.dialogeData = {};
}
/**
* @param {?} dialogeData
* @return {?}
*/
submitUpdateRow(dialogeData) {
this.updateRow.emit(dialogeData);
}
/**
* @return {?}
*/
processData() {
if (this.dataSource && this.dataSource.length > 0) {
this.total = this.dataSource.length;
if (this.headers.thead && this.headers.thead.length > 0) {
this.data['headers'] = this.headers.thead;
this.displayed = this.headers.displayed;
}
else {
console.warn('No headers data for table provided');
}
this.paginate(this.page);
}
else {
console.warn('No data for table provided');
}
}
}
DataTableComponent.decorators = [
{ type: Component, args: [{
selector: 'json-table',
template: "
\n
\n \n
\n
\n\n \n\n\n
\n\n
\n",
styles: [".data-table{box-shadow:0 5px 5px -3px rgba(0,0,0,.2),0 8px 10px 1px rgba(0,0,0,.14),0 3px 14px 2px rgba(0,0,0,.12);margin:10px;border-radius:8px;background:#fff;padding-top:8px}.data-table .search{width:100%;height:42px;border:none;outline:0;text-align:left;border-bottom:1px solid rgba(0,0,0,.12)}.data-table table{display:table;border-collapse:separate;border-spacing:2px;border-color:grey;width:100%;background:#fff}.data-table table tbody td:first-of-type,.data-table table tbody th:first-of-type,.data-table table thead td:first-of-type,.data-table table thead th:first-of-type{padding-left:24px!important;padding-right:24px!important}.data-table table thead{display:table-header-group;vertical-align:middle;border-color:inherit}.data-table table thead tr{height:56px}.data-table table tbody{display:table-row-group;vertical-align:middle;border-color:inherit}.data-table table tbody tr{height:48px;color:rgba(0,0,0,.87)}.data-table table th{padding:0;color:rgba(0,0,0,.54);border-bottom:1px solid rgba(0,0,0,.12)}.data-table table tfoot{display:table-footer-group;vertical-align:middle;border-color:inherit}.data-table .footer{display:flex;height:40px;border-top:1px solid rgba(0,0,0,.12)}.data-table .footer .spacer{flex-grow:1}.data-table .footer .delete{width:120px;background:0 0}.data-table .footer .delete button{height:80%;background:0 0;border:none;outline:0;cursor:pointer;transition:.25s linear;border-radius:4px;margin-left:5px;margin-top:4px}.data-table .footer .delete button:hover{background-color:#fbab33;color:#fff}.data-table .footer .data-pagination{padding-right:20px;padding-top:4px}.data-table .footer .data-pagination select{outline:0;background:0 0;padding:4px}.data-table .footer .data-pagination .link-button{border:none;outline:0;background:0 0}.data-table .footer .data-pagination .link-button:hover{text-decoration:underline}.data-table .update{transition:.5s linear;position:fixed;height:100vh;width:100vw;background:rgba(212,212,212,.51);top:0;left:0;display:flex;align-items:center;justify-content:center}.data-table .update .update-box{box-shadow:0 5px 5px -3px rgba(0,0,0,.2),0 8px 10px 1px rgba(0,0,0,.14),0 3px 14px 2px rgba(0,0,0,.12);background:#fff;padding:8px;border-radius:4px;width:250px}.data-table .update .f-x{display:flex;flex-direction:column}.data-table .update .f-y{display:flex;flex-direction:column;margin-top:6px}.data-table .update input[type=text]{margin-right:4px;padding:4px}"]
}] }
];
/** @nocollapse */
DataTableComponent.ctorParameters = () => [];
DataTableComponent.propDecorators = {
dataSource: [{ type: Input }],
headers: [{ type: Input }],
update: [{ type: Input }],
deleteRow: [{ type: Output }],
updateRow: [{ type: Output }]
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
class JSONTableModule {
}
JSONTableModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule,
FormsModule
],
declarations: [DataTableComponent],
exports: [DataTableComponent]
},] }
];
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
export { JSONTableModule, DataTableComponent as ɵa };
//# sourceMappingURL=angular-json-table.js.map