dataview.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. "use strict";
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  4. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  5. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  6. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7. };
  8. var __metadata = (this && this.__metadata) || function (k, v) {
  9. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var core_1 = require("@angular/core");
  13. var common_1 = require("@angular/common");
  14. var objectutils_1 = require("../utils/objectutils");
  15. var shared_1 = require("../common/shared");
  16. var paginator_1 = require("../paginator/paginator");
  17. var filterutils_1 = require("../utils/filterutils");
  18. var DataView = /** @class */ (function () {
  19. function DataView(el) {
  20. this.el = el;
  21. this.layout = 'list';
  22. this.pageLinks = 5;
  23. this.paginatorPosition = 'bottom';
  24. this.alwaysShowPaginator = true;
  25. this.paginatorDropdownScrollHeight = '200px';
  26. this.currentPageReportTemplate = '{currentPage} of {totalPages}';
  27. this.emptyMessage = 'No records found';
  28. this.onLazyLoad = new core_1.EventEmitter();
  29. this.trackBy = function (index, item) { return item; };
  30. this.loadingIcon = 'pi pi-spinner';
  31. this.first = 0;
  32. this.onPage = new core_1.EventEmitter();
  33. this.onSort = new core_1.EventEmitter();
  34. this._sortOrder = 1;
  35. }
  36. DataView.prototype.ngOnInit = function () {
  37. if (this.lazy) {
  38. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  39. }
  40. this.initialized = true;
  41. };
  42. Object.defineProperty(DataView.prototype, "sortField", {
  43. get: function () {
  44. return this._sortField;
  45. },
  46. set: function (val) {
  47. this._sortField = val;
  48. //avoid triggering lazy load prior to lazy initialization at onInit
  49. if (!this.lazy || this.initialized) {
  50. this.sort();
  51. }
  52. },
  53. enumerable: true,
  54. configurable: true
  55. });
  56. Object.defineProperty(DataView.prototype, "sortOrder", {
  57. get: function () {
  58. return this._sortOrder;
  59. },
  60. set: function (val) {
  61. this._sortOrder = val;
  62. //avoid triggering lazy load prior to lazy initialization at onInit
  63. if (!this.lazy || this.initialized) {
  64. this.sort();
  65. }
  66. },
  67. enumerable: true,
  68. configurable: true
  69. });
  70. DataView.prototype.ngAfterContentInit = function () {
  71. var _this = this;
  72. this.templates.forEach(function (item) {
  73. switch (item.getType()) {
  74. case 'listItem':
  75. _this.listItemTemplate = item.template;
  76. break;
  77. case 'gridItem':
  78. _this.gridItemTemplate = item.template;
  79. break;
  80. case 'paginatorleft':
  81. _this.paginatorLeftTemplate = item.template;
  82. break;
  83. case 'paginatorright':
  84. _this.paginatorRightTemplate = item.template;
  85. break;
  86. }
  87. });
  88. this.updateItemTemplate();
  89. };
  90. DataView.prototype.updateItemTemplate = function () {
  91. switch (this.layout) {
  92. case 'list':
  93. this.itemTemplate = this.listItemTemplate;
  94. break;
  95. case 'grid':
  96. this.itemTemplate = this.gridItemTemplate;
  97. break;
  98. }
  99. };
  100. Object.defineProperty(DataView.prototype, "value", {
  101. get: function () {
  102. return this._value;
  103. },
  104. set: function (val) {
  105. this._value = val;
  106. this.updateTotalRecords();
  107. if (!this.lazy && this.hasFilter()) {
  108. this.filter(this.filterValue);
  109. }
  110. },
  111. enumerable: true,
  112. configurable: true
  113. });
  114. DataView.prototype.changeLayout = function (layout) {
  115. this.layout = layout;
  116. this.updateItemTemplate();
  117. };
  118. DataView.prototype.updateTotalRecords = function () {
  119. this.totalRecords = this.lazy ? this.totalRecords : (this._value ? this._value.length : 0);
  120. };
  121. DataView.prototype.paginate = function (event) {
  122. this.first = event.first;
  123. this.rows = event.rows;
  124. if (this.lazy) {
  125. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  126. }
  127. this.onPage.emit({
  128. first: this.first,
  129. rows: this.rows
  130. });
  131. };
  132. DataView.prototype.sort = function () {
  133. var _this = this;
  134. this.first = 0;
  135. if (this.lazy) {
  136. this.onLazyLoad.emit(this.createLazyLoadMetadata());
  137. }
  138. else if (this.value) {
  139. this.value.sort(function (data1, data2) {
  140. var value1 = objectutils_1.ObjectUtils.resolveFieldData(data1, _this.sortField);
  141. var value2 = objectutils_1.ObjectUtils.resolveFieldData(data2, _this.sortField);
  142. var result = null;
  143. if (value1 == null && value2 != null)
  144. result = -1;
  145. else if (value1 != null && value2 == null)
  146. result = 1;
  147. else if (value1 == null && value2 == null)
  148. result = 0;
  149. else if (typeof value1 === 'string' && typeof value2 === 'string')
  150. result = value1.localeCompare(value2);
  151. else
  152. result = (value1 < value2) ? -1 : (value1 > value2) ? 1 : 0;
  153. return (_this.sortOrder * result);
  154. });
  155. if (this.hasFilter()) {
  156. this.filter(this.filterValue);
  157. }
  158. }
  159. this.onSort.emit({
  160. sortField: this.sortField,
  161. sortOrder: this.sortOrder
  162. });
  163. };
  164. DataView.prototype.isEmpty = function () {
  165. var data = this.filteredValue || this.value;
  166. return data == null || data.length == 0;
  167. };
  168. DataView.prototype.createLazyLoadMetadata = function () {
  169. return {
  170. first: this.first,
  171. rows: this.rows,
  172. sortField: this.sortField,
  173. sortOrder: this.sortOrder
  174. };
  175. };
  176. DataView.prototype.getBlockableElement = function () {
  177. return this.el.nativeElement.children[0];
  178. };
  179. DataView.prototype.filter = function (filter, filterMatchMode) {
  180. if (filterMatchMode === void 0) { filterMatchMode = "contains"; }
  181. this.filterValue = filter;
  182. if (this.value && this.value.length) {
  183. var searchFields = this.filterBy.split(',');
  184. this.filteredValue = filterutils_1.FilterUtils.filter(this.value, searchFields, filter, filterMatchMode);
  185. if (this.filteredValue.length === this.value.length) {
  186. this.filteredValue = null;
  187. }
  188. if (this.paginator) {
  189. this.first = 0;
  190. this.totalRecords = this.filteredValue ? this.filteredValue.length : this.value ? this.value.length : 0;
  191. }
  192. }
  193. };
  194. DataView.prototype.hasFilter = function () {
  195. return this.filterValue && this.filterValue.trim().length > 0;
  196. };
  197. __decorate([
  198. core_1.Input(),
  199. __metadata("design:type", String)
  200. ], DataView.prototype, "layout", void 0);
  201. __decorate([
  202. core_1.Input(),
  203. __metadata("design:type", Boolean)
  204. ], DataView.prototype, "paginator", void 0);
  205. __decorate([
  206. core_1.Input(),
  207. __metadata("design:type", Number)
  208. ], DataView.prototype, "rows", void 0);
  209. __decorate([
  210. core_1.Input(),
  211. __metadata("design:type", Number)
  212. ], DataView.prototype, "totalRecords", void 0);
  213. __decorate([
  214. core_1.Input(),
  215. __metadata("design:type", Number)
  216. ], DataView.prototype, "pageLinks", void 0);
  217. __decorate([
  218. core_1.Input(),
  219. __metadata("design:type", Array)
  220. ], DataView.prototype, "rowsPerPageOptions", void 0);
  221. __decorate([
  222. core_1.Input(),
  223. __metadata("design:type", String)
  224. ], DataView.prototype, "paginatorPosition", void 0);
  225. __decorate([
  226. core_1.Input(),
  227. __metadata("design:type", Boolean)
  228. ], DataView.prototype, "alwaysShowPaginator", void 0);
  229. __decorate([
  230. core_1.Input(),
  231. __metadata("design:type", Object)
  232. ], DataView.prototype, "paginatorDropdownAppendTo", void 0);
  233. __decorate([
  234. core_1.Input(),
  235. __metadata("design:type", String)
  236. ], DataView.prototype, "paginatorDropdownScrollHeight", void 0);
  237. __decorate([
  238. core_1.Input(),
  239. __metadata("design:type", String)
  240. ], DataView.prototype, "currentPageReportTemplate", void 0);
  241. __decorate([
  242. core_1.Input(),
  243. __metadata("design:type", Boolean)
  244. ], DataView.prototype, "showCurrentPageReport", void 0);
  245. __decorate([
  246. core_1.Input(),
  247. __metadata("design:type", Boolean)
  248. ], DataView.prototype, "lazy", void 0);
  249. __decorate([
  250. core_1.Input(),
  251. __metadata("design:type", String)
  252. ], DataView.prototype, "emptyMessage", void 0);
  253. __decorate([
  254. core_1.Output(),
  255. __metadata("design:type", core_1.EventEmitter)
  256. ], DataView.prototype, "onLazyLoad", void 0);
  257. __decorate([
  258. core_1.Input(),
  259. __metadata("design:type", Object)
  260. ], DataView.prototype, "style", void 0);
  261. __decorate([
  262. core_1.Input(),
  263. __metadata("design:type", String)
  264. ], DataView.prototype, "styleClass", void 0);
  265. __decorate([
  266. core_1.Input(),
  267. __metadata("design:type", Function)
  268. ], DataView.prototype, "trackBy", void 0);
  269. __decorate([
  270. core_1.Input(),
  271. __metadata("design:type", String)
  272. ], DataView.prototype, "filterBy", void 0);
  273. __decorate([
  274. core_1.Input(),
  275. __metadata("design:type", Boolean)
  276. ], DataView.prototype, "loading", void 0);
  277. __decorate([
  278. core_1.Input(),
  279. __metadata("design:type", String)
  280. ], DataView.prototype, "loadingIcon", void 0);
  281. __decorate([
  282. core_1.Input(),
  283. __metadata("design:type", Number)
  284. ], DataView.prototype, "first", void 0);
  285. __decorate([
  286. core_1.Output(),
  287. __metadata("design:type", core_1.EventEmitter)
  288. ], DataView.prototype, "onPage", void 0);
  289. __decorate([
  290. core_1.Output(),
  291. __metadata("design:type", core_1.EventEmitter)
  292. ], DataView.prototype, "onSort", void 0);
  293. __decorate([
  294. core_1.ContentChild(shared_1.Header, { static: false }),
  295. __metadata("design:type", Object)
  296. ], DataView.prototype, "header", void 0);
  297. __decorate([
  298. core_1.ContentChild(shared_1.Footer, { static: false }),
  299. __metadata("design:type", Object)
  300. ], DataView.prototype, "footer", void 0);
  301. __decorate([
  302. core_1.ContentChildren(shared_1.PrimeTemplate),
  303. __metadata("design:type", core_1.QueryList)
  304. ], DataView.prototype, "templates", void 0);
  305. __decorate([
  306. core_1.Input(),
  307. __metadata("design:type", String),
  308. __metadata("design:paramtypes", [String])
  309. ], DataView.prototype, "sortField", null);
  310. __decorate([
  311. core_1.Input(),
  312. __metadata("design:type", Number),
  313. __metadata("design:paramtypes", [Number])
  314. ], DataView.prototype, "sortOrder", null);
  315. __decorate([
  316. core_1.Input(),
  317. __metadata("design:type", Array),
  318. __metadata("design:paramtypes", [Array])
  319. ], DataView.prototype, "value", null);
  320. DataView = __decorate([
  321. core_1.Component({
  322. selector: 'p-dataView',
  323. template: "\n <div [ngClass]=\"{'ui-dataview ui-widget': true, 'ui-dataview-list': (layout === 'list'), 'ui-dataview-grid': (layout === 'grid')}\" [ngStyle]=\"style\" [class]=\"styleClass\">\n <div class=\"ui-dataview-loading ui-widget-overlay\" *ngIf=\"loading\"></div>\n <div class=\"ui-dataview-loading-content\" *ngIf=\"loading\">\n <i [class]=\"'ui-dataview-loading-icon pi-spin ' + loadingIcon\"></i>\n </div>\n <div class=\"ui-dataview-header ui-widget-header ui-corner-top\">\n <ng-content select=\"p-header\"></ng-content>\n </div>\n <p-paginator [rows]=\"rows\" [first]=\"first\" [totalRecords]=\"totalRecords\" [pageLinkSize]=\"pageLinks\" [alwaysShow]=\"alwaysShowPaginator\"\n (onPageChange)=\"paginate($event)\" styleClass=\"ui-paginator-top\" [rowsPerPageOptions]=\"rowsPerPageOptions\" *ngIf=\"paginator && (paginatorPosition === 'top' || paginatorPosition =='both')\"\n [dropdownAppendTo]=\"paginatorDropdownAppendTo\" [dropdownScrollHeight]=\"paginatorDropdownScrollHeight\" [templateLeft]=\"paginatorLeftTemplate\" [templateRight]=\"paginatorRightTemplate\"\n [currentPageReportTemplate]=\"currentPageReportTemplate\" [showCurrentPageReport]=\"showCurrentPageReport\"></p-paginator>\n <div class=\"ui-dataview-content ui-widget-content\">\n <div class=\"ui-g\">\n <ng-template ngFor let-rowData let-rowIndex=\"index\" [ngForOf]=\"paginator ? ((filteredValue||value) | slice:(lazy ? 0 : first):((lazy ? 0 : first) + rows)) : (filteredValue||value)\" [ngForTrackBy]=\"trackBy\">\n <ng-container *ngTemplateOutlet=\"itemTemplate; context: {$implicit: rowData, rowIndex: rowIndex}\"></ng-container>\n </ng-template>\n <div *ngIf=\"isEmpty()\" class=\"ui-g-12 ui-dataview-emptymessage\">{{emptyMessage}}</div>\n </div>\n </div>\n <p-paginator [rows]=\"rows\" [first]=\"first\" [totalRecords]=\"totalRecords\" [pageLinkSize]=\"pageLinks\" [alwaysShow]=\"alwaysShowPaginator\"\n (onPageChange)=\"paginate($event)\" styleClass=\"ui-paginator-bottom\" [rowsPerPageOptions]=\"rowsPerPageOptions\" *ngIf=\"paginator && (paginatorPosition === 'bottom' || paginatorPosition =='both')\"\n [dropdownAppendTo]=\"paginatorDropdownAppendTo\" [dropdownScrollHeight]=\"paginatorDropdownScrollHeight\" [templateLeft]=\"paginatorLeftTemplate\" [templateRight]=\"paginatorRightTemplate\"\n [currentPageReportTemplate]=\"currentPageReportTemplate\" [showCurrentPageReport]=\"showCurrentPageReport\"></p-paginator>\n <div class=\"ui-dataview-footer ui-widget-header ui-corner-bottom\" *ngIf=\"footer\">\n <ng-content select=\"p-footer\"></ng-content>\n </div>\n </div>\n "
  324. }),
  325. __metadata("design:paramtypes", [core_1.ElementRef])
  326. ], DataView);
  327. return DataView;
  328. }());
  329. exports.DataView = DataView;
  330. var DataViewLayoutOptions = /** @class */ (function () {
  331. function DataViewLayoutOptions(dv) {
  332. this.dv = dv;
  333. }
  334. DataViewLayoutOptions.prototype.changeLayout = function (event, layout) {
  335. this.dv.changeLayout(layout);
  336. event.preventDefault();
  337. };
  338. __decorate([
  339. core_1.Input(),
  340. __metadata("design:type", Object)
  341. ], DataViewLayoutOptions.prototype, "style", void 0);
  342. __decorate([
  343. core_1.Input(),
  344. __metadata("design:type", String)
  345. ], DataViewLayoutOptions.prototype, "styleClass", void 0);
  346. DataViewLayoutOptions = __decorate([
  347. core_1.Component({
  348. selector: 'p-dataViewLayoutOptions',
  349. template: "\n <div [ngClass]=\"'ui-dataview-layout-options ui-selectbutton ui-buttonset'\" [ngStyle]=\"style\" [class]=\"styleClass\">\n <a tabindex=\"0\" class=\"ui-button ui-button-icon-only ui-state-default\" (click)=\"changeLayout($event, 'list')\" (keydown.enter)=\"changeLayout($event, 'list')\"\n [ngClass]=\"{'ui-state-active': dv.layout === 'list'}\">\n <i class=\"pi pi-bars ui-button-icon-left\"></i>\n <span class=\"ui-button-text ui-clickable\">ui-btn</span>\n </a><a tabindex=\"0\" class=\"ui-button ui-button-icon-only ui-state-default\" (click)=\"changeLayout($event, 'grid')\" (keydown.enter)=\"changeLayout($event, 'grid')\"\n [ngClass]=\"{'ui-state-active': dv.layout === 'grid'}\">\n <i class=\"pi pi-th-large ui-button-icon-left\"></i>\n <span class=\"ui-button-text ui-clickable\">ui-btn</span>\n </a>\n </div>\n "
  350. }),
  351. __metadata("design:paramtypes", [DataView])
  352. ], DataViewLayoutOptions);
  353. return DataViewLayoutOptions;
  354. }());
  355. exports.DataViewLayoutOptions = DataViewLayoutOptions;
  356. var DataViewModule = /** @class */ (function () {
  357. function DataViewModule() {
  358. }
  359. DataViewModule = __decorate([
  360. core_1.NgModule({
  361. imports: [common_1.CommonModule, shared_1.SharedModule, paginator_1.PaginatorModule],
  362. exports: [DataView, shared_1.SharedModule, DataViewLayoutOptions],
  363. declarations: [DataView, DataViewLayoutOptions]
  364. })
  365. ], DataViewModule);
  366. return DataViewModule;
  367. }());
  368. exports.DataViewModule = DataViewModule;
  369. //# sourceMappingURL=dataview.js.map