angular-json-table.umd.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('@angular/forms')) :
  3. typeof define === 'function' && define.amd ? define('angular-json-table', ['exports', '@angular/common', '@angular/core', '@angular/forms'], factory) :
  4. (factory((global['angular-json-table'] = {}),global.ng.common,global.ng.core,global.ng.forms));
  5. }(this, (function (exports,common,core,forms) { 'use strict';
  6. /**
  7. * @fileoverview added by tsickle
  8. * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
  9. */
  10. var DataTableComponent = /** @class */ (function () {
  11. function DataTableComponent() {
  12. this.deleteRow = new core.EventEmitter();
  13. this.updateRow = new core.EventEmitter();
  14. this.data = {};
  15. this.displayed = [];
  16. this.perpage = 10;
  17. this.page = 1;
  18. this.checked = [];
  19. this.checkAll = false;
  20. this.dialogue = false;
  21. this.dialogeData = {};
  22. }
  23. /**
  24. * @return {?}
  25. */
  26. DataTableComponent.prototype.ngOnInit = /**
  27. * @return {?}
  28. */
  29. function () {
  30. this.processData();
  31. };
  32. /**
  33. * @param {?} e
  34. * @param {?} id
  35. * @return {?}
  36. */
  37. DataTableComponent.prototype.selected = /**
  38. * @param {?} e
  39. * @param {?} id
  40. * @return {?}
  41. */
  42. function (e, id) {
  43. if (e.target.checked) {
  44. this.checked.push(id);
  45. }
  46. };
  47. /**
  48. * @return {?}
  49. */
  50. DataTableComponent.prototype.deleteSelected = /**
  51. * @return {?}
  52. */
  53. function () {
  54. var _this = this;
  55. if (this.checked.length > 0) {
  56. this.deleteRow.emit(this.checked);
  57. this.dataSource = this.dataSource.filter(function (value, index, array) {
  58. return !_this.checked.includes(value.id);
  59. });
  60. this.checked = [];
  61. this.paginate(this.page);
  62. }
  63. };
  64. /**
  65. * @return {?}
  66. */
  67. DataTableComponent.prototype.totalItems = /**
  68. * @return {?}
  69. */
  70. function () {
  71. if (this.total > this.perpage) {
  72. return Math.ceil(this.total / this.perpage);
  73. }
  74. else {
  75. return 1;
  76. }
  77. };
  78. /**
  79. * @param {?} page
  80. * @return {?}
  81. */
  82. DataTableComponent.prototype.paginate = /**
  83. * @param {?} page
  84. * @return {?}
  85. */
  86. function (page) {
  87. /** @type {?} */
  88. var start = (this.perpage * page) - this.perpage;
  89. /** @type {?} */
  90. var end = (this.perpage * page);
  91. // console.log(start, end);
  92. this.data['data'] = this.dataSource.slice(start, end);
  93. // console.log(this.data);
  94. };
  95. /**
  96. * @param {?} perPage
  97. * @return {?}
  98. */
  99. DataTableComponent.prototype.pageOnChange = /**
  100. * @param {?} perPage
  101. * @return {?}
  102. */
  103. function (perPage) {
  104. this.perpage = perPage;
  105. this.page = 1;
  106. //console.log(perPage);
  107. this.paginate(this.page);
  108. };
  109. /**
  110. * @return {?}
  111. */
  112. DataTableComponent.prototype.previousPage = /**
  113. * @return {?}
  114. */
  115. function () {
  116. if (this.page > 1) {
  117. this.page--;
  118. }
  119. this.paginate(this.page);
  120. };
  121. /**
  122. * @return {?}
  123. */
  124. DataTableComponent.prototype.nextPage = /**
  125. * @return {?}
  126. */
  127. function () {
  128. if (this.page + 1 <= this.totalItems()) {
  129. this.page++;
  130. }
  131. this.paginate(this.page);
  132. };
  133. /**
  134. * @param {?} id
  135. * @return {?}
  136. */
  137. DataTableComponent.prototype.showUpdate = /**
  138. * @param {?} id
  139. * @return {?}
  140. */
  141. function (id) {
  142. var _this = this;
  143. this.dialogue = true;
  144. // console.log('Showing the updates');
  145. this.data.data.forEach(function (value) {
  146. if (value.id === id) {
  147. _this.dialogeData = value;
  148. }
  149. });
  150. };
  151. /**
  152. * @return {?}
  153. */
  154. DataTableComponent.prototype.closeDialogue = /**
  155. * @return {?}
  156. */
  157. function () {
  158. this.dialogue ? this.dialogue = false : this.dialogue = true;
  159. this.dialogeData = {};
  160. };
  161. /**
  162. * @param {?} dialogeData
  163. * @return {?}
  164. */
  165. DataTableComponent.prototype.submitUpdateRow = /**
  166. * @param {?} dialogeData
  167. * @return {?}
  168. */
  169. function (dialogeData) {
  170. this.updateRow.emit(dialogeData);
  171. };
  172. /**
  173. * @return {?}
  174. */
  175. DataTableComponent.prototype.processData = /**
  176. * @return {?}
  177. */
  178. function () {
  179. if (this.dataSource && this.dataSource.length > 0) {
  180. this.total = this.dataSource.length;
  181. if (this.headers.thead && this.headers.thead.length > 0) {
  182. this.data['headers'] = this.headers.thead;
  183. this.displayed = this.headers.displayed;
  184. }
  185. else {
  186. console.warn('No headers data for table provided');
  187. }
  188. this.paginate(this.page);
  189. }
  190. else {
  191. console.warn('No data for table provided');
  192. }
  193. };
  194. DataTableComponent.decorators = [
  195. { type: core.Component, args: [{
  196. selector: 'json-table',
  197. template: "<div *ngIf=\"data\" class=\"data-table\">\n <div *ngIf=\"false\">\n <input type=\"text\" class=\"search\" placeholder=\"Search for details\">\n </div>\n <table>\n <thead>\n <tr>\n <th style=\"width: 4%\">&nbsp;</th>\n <th style=\"width: 4%\">#</th>\n <th *ngFor=\"let header of data.headers\" style=\"text-align:left\">{{header}}</th>\n <th *ngIf=\"update\">&nbsp;</th>\n </tr>\n </thead>\n <tbody>\n\n <tr *ngFor=\"let row of data.data; let i = index\">\n <td><input type=\"checkbox\" [checked]=\"checkAll\" (change)=\"selected($event,row.id)\"></td>\n <td>{{ i+1 }}</td>\n <td *ngFor=\"let attr of displayed\" >{{row[attr]}}</td>\n <td *ngIf=\"update\" style=\"text-align:center\">\n <span (click)=\"showUpdate(row.id)\">\uD83D\uDD89</span>\n </td>\n </tr>\n\n </tbody>\n <tfoot></tfoot>\n </table>\n\n <div class=\"footer\">\n <div class=\"delete\">\n <button (click)=\"deleteSelected()\">Delete {{checked.length}} rows</button>\n </div>\n\n <div class=\"spacer\">\n\n </div>\n\n <div class=\"data-pagination\">\n <select (change)=\"pageOnChange(device.value)\" #device>\n <option value=\"10\">10</option>\n <option value=\"15\">15</option>\n <option value=\"20\">20</option>\n <option value=\"100\">100</option>\n </select>\n | Showing {{page}} of {{totalItems()}} |\n <button class=\"link-button\" (click)=\"previousPage()\">Previous</button>\n -\n <button class=\"link-button\" (click)=\"nextPage()\">Next</button>\n </div>\n </div>\n\n\n <div *ngIf=\"update && dialogue\" class=\"update\" (click)=\"closeDialogue()\">\n\n <div class=\"update-box\" (click)=\"$event.stopPropagation()\">\n <h2>Edit the Row</h2>\n <form #customForm=\"ngForm\" novalidate (ngSubmit)=\"submitUpdateRow(dialogeData); closeDialogue()\">\n <div class=\"f-x\">\n <ng-container *ngFor=\"let attr of displayed; let i = index\">\n <div *ngIf=\"attr!='id' \" class=\"f-y\">\n <label>{{data.headers[i]}}</label>\n <input type=\"text\" [value]=\"dialogeData[attr]\" [placeholder]=\"attr\" [name]=\"attr\"\n [(ngModel)]=\"dialogeData[attr]\">\n </div>\n </ng-container>\n </div>\n <footer>\n <br>\n <button type=\"submit\">Update the row</button>\n <button type=\"button\" (click)=\"closeDialogue()\">Cancel</button>\n </footer>\n </form>\n </div>\n </div>\n\n</div>\n",
  198. 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}"]
  199. }] }
  200. ];
  201. /** @nocollapse */
  202. DataTableComponent.ctorParameters = function () { return []; };
  203. DataTableComponent.propDecorators = {
  204. dataSource: [{ type: core.Input }],
  205. headers: [{ type: core.Input }],
  206. update: [{ type: core.Input }],
  207. deleteRow: [{ type: core.Output }],
  208. updateRow: [{ type: core.Output }]
  209. };
  210. return DataTableComponent;
  211. }());
  212. /**
  213. * @fileoverview added by tsickle
  214. * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
  215. */
  216. var JSONTableModule = /** @class */ (function () {
  217. function JSONTableModule() {
  218. }
  219. JSONTableModule.decorators = [
  220. { type: core.NgModule, args: [{
  221. imports: [
  222. common.CommonModule,
  223. forms.FormsModule
  224. ],
  225. declarations: [DataTableComponent],
  226. exports: [DataTableComponent]
  227. },] }
  228. ];
  229. return JSONTableModule;
  230. }());
  231. /**
  232. * @fileoverview added by tsickle
  233. * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
  234. */
  235. /**
  236. * @fileoverview added by tsickle
  237. * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
  238. */
  239. exports.JSONTableModule = JSONTableModule;
  240. exports.ɵa = DataTableComponent;
  241. Object.defineProperty(exports, '__esModule', { value: true });
  242. })));
  243. //# sourceMappingURL=angular-json-table.umd.js.map