tuain-ng-forms-lib 12.0.53 → 12.0.58

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.
@@ -1,6 +1,6 @@
1
1
  import { Component, Input, EventEmitter, Output, ChangeDetectionStrategy, NgModule } from '@angular/core';
2
- import { Subject, ReplaySubject } from 'rxjs';
3
2
  import { __awaiter } from 'tslib';
3
+ import { Subject, ReplaySubject } from 'rxjs';
4
4
  import yn from 'yn';
5
5
  import { nanoid } from 'nanoid';
6
6
  import { CommonModule } from '@angular/common';
@@ -247,24 +247,156 @@ SubSectionComponent.propDecorators = {
247
247
  formManager: [{ type: Input }]
248
248
  };
249
249
 
250
- class FieldSearch {
251
- constructor(filterDefinition) {
252
- this.fieldCode = filterDefinition.fieldCode;
253
- this.fieldAlias = filterDefinition.fieldAlias || filterDefinition.fieldCode;
254
- this.fieldTitle = filterDefinition.fieldTitle;
255
- this.fieldTypeCode = filterDefinition.fieldTypeCode;
256
- this.operators = filterDefinition.operators;
257
- this.alignment = filterDefinition.alignment;
258
- this.format = filterDefinition.format;
250
+ const INLINE_ACTION$1 = 'INLINE';
251
+ class LibTableRecordActionComponent {
252
+ constructor() {
253
+ this.actionSelected = new EventEmitter();
254
+ }
255
+ ngOnInit() {
256
+ this.start();
257
+ }
258
+ start() { }
259
+ onActivate() {
260
+ const tableEvent = {
261
+ actionCode: this.action.actionCode,
262
+ recordId: this.recordId,
263
+ recordData: this.recordData,
264
+ };
265
+ this.actionSelected.emit(tableEvent);
266
+ }
267
+ class() { }
268
+ }
269
+ LibTableRecordActionComponent.decorators = [
270
+ { type: Component, args: [{
271
+ selector: 'lib-table-record-action',
272
+ template: `<ng-content></ng-content>`,
273
+ changeDetection: ChangeDetectionStrategy.OnPush
274
+ },] }
275
+ ];
276
+ LibTableRecordActionComponent.ctorParameters = () => [];
277
+ LibTableRecordActionComponent.propDecorators = {
278
+ recordId: [{ type: Input }],
279
+ recordData: [{ type: Input }],
280
+ action: [{ type: Input }],
281
+ actionSelected: [{ type: Output }]
282
+ };
283
+
284
+ class LibTableRecordFieldComponent {
285
+ ngOnInit() {
286
+ this.start();
259
287
  }
288
+ start() { }
260
289
  }
261
- class Filter {
290
+ LibTableRecordFieldComponent.decorators = [
291
+ { type: Component, args: [{
292
+ selector: 'lib-table-record-field',
293
+ template: `<ng-content></ng-content>`,
294
+ changeDetection: ChangeDetectionStrategy.OnPush
295
+ },] }
296
+ ];
297
+ LibTableRecordFieldComponent.propDecorators = {
298
+ fieldCode: [{ type: Input }],
299
+ fieldType: [{ type: Input }],
300
+ fieldValue: [{ type: Input }]
301
+ };
302
+
303
+ const changeViewAttributes = ['visibleRecords', 'currentPage', 'recordsPerPage', 'sorting'];
304
+ class LibTableComponent {
262
305
  constructor() {
263
- this.filterModeSimple = true;
264
- this.advancedFilter = [];
265
- this.simpleFilterWords = [];
306
+ this.currentPageRecords = [];
307
+ this.globalFilterString = '';
308
+ this.globalSearch = false;
309
+ this.selectedRecords = [];
310
+ this.selectionBackend = false;
311
+ this.allSelected = false;
312
+ this.currentPage = 1;
313
+ this.loaded = false;
314
+ this.selectable = false;
315
+ this.hasActions = false;
316
+ }
317
+ ngOnInit() {
318
+ var _a;
319
+ if (this.table) {
320
+ this.formConfig = (_a = this.table) === null || _a === void 0 ? void 0 : _a._formConfig;
321
+ this.tableFieldStyles = this.formConfig.tableFieldStyles;
322
+ this.selectable = this.table.selectable;
323
+ this.hasActions = this.table.hasActions();
324
+ this.inlineActions = this.table.getActions(this.formConfig.tableActions.inline);
325
+ this.globalActions = this.table.getActions(this.formConfig.tableActions.global);
326
+ this.selectionActions = this.table.getActions(this.formConfig.tableActions.selection);
327
+ // Inicialización de campos mapeados del objeto
328
+ const mapping = Object.entries(this.formConfig.componentTableAttrMap);
329
+ for (let index = 0; index < mapping.length; index++) {
330
+ const [tableAttrRaw, compAttrRaw] = mapping[index];
331
+ const tableAttr = tableAttrRaw.toString();
332
+ const compAttr = compAttrRaw.toString();
333
+ this.syncAttribute(compAttr, this.table[tableAttr]);
334
+ }
335
+ // Subscripción a cambios en atributos
336
+ this.table.attributeChange.subscribe(event => {
337
+ const { name: tableAttr, value } = event;
338
+ const compAttr = this.formConfig.componentTableAttrMap[tableAttr];
339
+ this.syncAttribute(compAttr, value);
340
+ });
341
+ }
342
+ this.start();
343
+ }
344
+ start() { }
345
+ tableGlobalAction(actionCode) { this.table.notifyGlobalAction(actionCode); }
346
+ tableSelectionAction(actionCode) { this.table.notifySelectionAction(actionCode); }
347
+ tableActionSelected(actionEvent) { this.table.notifyInlineAction(actionEvent); }
348
+ changePage(requestedPage) { !this.clientPaging && this.table.notifyGetDataAction(requestedPage); }
349
+ tableSelectionToggle(recordId) { this.table.notifyRecordSelection(recordId); }
350
+ toggleSelectAll() { return (this.allSelected) ? this.table.unSelectAll() : this.table.selectAll(); }
351
+ globalFilterCompleted() { this.changePage(1); }
352
+ syncAttribute(name, value) {
353
+ try {
354
+ // this.hasOwnProperty(name)
355
+ this[name] = value;
356
+ }
357
+ catch (e) {
358
+ console.log('Error asignando valor a un atributo del objeto');
359
+ }
360
+ if (changeViewAttributes.includes(name)) {
361
+ this.updateTableView();
362
+ }
363
+ }
364
+ globalFilterChanged() {
365
+ var _a, _b;
366
+ this.table.setGlobalFilterString((_b = (_a = this.globalFilterString) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '');
367
+ if (this.clientPaging) {
368
+ this.table.setAttr('currentPage', 1);
369
+ this.table.updateVisibleRecords();
370
+ }
371
+ }
372
+ tableColumnSort(columnName) {
373
+ this.table.setRequiredOrder(columnName);
374
+ return this.clientPaging ? this.table.localSortData() : this.table.notifyGetDataAction();
375
+ }
376
+ updateTableView() {
377
+ let currentPageRecords = this.visibleRecords;
378
+ if (this.clientPaging) {
379
+ currentPageRecords = currentPageRecords.map((record, i) => (Object.assign({ id: i + 1 }, record)))
380
+ .slice((this.currentPage - 1) * this.recordsPerPage, (this.currentPage - 1) * this.recordsPerPage + this.recordsPerPage);
381
+ this.totalRecordsNumber = this.visibleRecords.length;
382
+ }
383
+ this.currentPageRecords = currentPageRecords;
266
384
  }
267
385
  }
386
+ LibTableComponent.decorators = [
387
+ { type: Component, args: [{
388
+ selector: 'lib-table',
389
+ template: `<ng-content></ng-content>`,
390
+ changeDetection: ChangeDetectionStrategy.OnPush
391
+ },] }
392
+ ];
393
+ LibTableComponent.propDecorators = {
394
+ table: [{ type: Input }],
395
+ tableRecords: [{ type: Input }],
396
+ disabled: [{ type: Input }],
397
+ state: [{ type: Input }],
398
+ waiting: [{ type: Input }]
399
+ };
268
400
 
269
401
  const NO_ERROR = '00';
270
402
  const HEADER$1 = 'HEADER';
@@ -289,6 +421,7 @@ const operators = {
289
421
  CONTENT: 'Contiene',
290
422
  NOT_CONTENT: 'No Contiene',
291
423
  BETWEEN: 'Entre',
424
+ IN: 'En'
292
425
  };
293
426
 
294
427
  class FormElement {
@@ -367,1087 +500,836 @@ class FormElement {
367
500
  get editable() { return !this.disabled; }
368
501
  }
369
502
 
370
- class RecordTableColumn {
371
- constructor(recTableColReceived, formConfig) {
372
- var _a, _b, _c;
373
- this._formConfig = formConfig;
374
- if (recTableColReceived) {
375
- this.fieldCode = recTableColReceived.fieldCode;
376
- this.fieldTitle = recTableColReceived.fieldTitle;
377
- this.fieldType = recTableColReceived.fieldTypeCode || this._formConfig.fieldTypes.text;
378
- const defaultTypeAlignment = (this._formConfig.tableFieldStyles[this.fieldType] != null) ? this._formConfig.tableFieldStyles[this.fieldType]['text-align'] : 'left';
379
- this.fieldAlignment = (recTableColReceived.alignment != null) ? recTableColReceived.alignment.toLowerCase() : defaultTypeAlignment;
380
- this.visible = (_a = recTableColReceived === null || recTableColReceived === void 0 ? void 0 : recTableColReceived.visible) !== null && _a !== void 0 ? _a : true;
381
- this.sortable = (_b = recTableColReceived === null || recTableColReceived === void 0 ? void 0 : recTableColReceived.sortable) !== null && _b !== void 0 ? _b : false;
382
- this.fieldFormat = recTableColReceived.format || '';
383
- this.customAttributes = (_c = recTableColReceived === null || recTableColReceived === void 0 ? void 0 : recTableColReceived.customAttributes) !== null && _c !== void 0 ? _c : {};
384
- }
385
- }
386
- }
387
-
388
- class TableAction {
389
- constructor(actionDefinition) {
390
- var _a, _b;
391
- this.actionCode = actionDefinition.actionCode;
392
- this.actionTitle = actionDefinition.actionTitle;
503
+ const HEADER = 'HEADER';
504
+ class FormAction extends FormElement {
505
+ constructor(actionDefinition, formConfig) {
506
+ var _a;
507
+ super(actionDefinition, formConfig);
508
+ this._actionActivated = new Subject();
509
+ this.inProgress = false;
510
+ this.elementType = elementTypes.action;
511
+ this.actionCode = actionDefinition.actionCode ? actionDefinition.actionCode.toString() : '';
512
+ this.actionName = actionDefinition.actionTitle;
393
513
  this.iconName = actionDefinition.iconName || this.actionCode;
394
- this.actionType = actionDefinition.actionType || 'STANDARD';
395
- this.actionClass = actionDefinition.actionClass || 'INLINE';
396
- this.newState = actionDefinition.newState;
397
- this.stateField = actionDefinition.stateField || '';
398
- this.visibleStates = actionDefinition.visibleStates || [];
399
- this.enabledStates = actionDefinition.enabledStates || [];
514
+ this.setCustomAttribute('location', actionDefinition.position || HEADER);
400
515
  this.backend = (_a = actionDefinition === null || actionDefinition === void 0 ? void 0 : actionDefinition.serverAction) !== null && _a !== void 0 ? _a : false;
401
- this.restrictedOnField = actionDefinition.fieldRestrictedCode || '';
402
- this.restrictedOnValue = actionDefinition.valueRestricted || '';
516
+ this.newState = actionDefinition === null || actionDefinition === void 0 ? void 0 : actionDefinition.newState;
517
+ this.restrictedOnField = actionDefinition.fieldRestrictedCode ? actionDefinition.fieldRestrictedCode.toString() : '';
403
518
  this.restrictedOnOperator = actionDefinition.operatorRestricted || '';
404
- this.customAttributes = (_b = actionDefinition === null || actionDefinition === void 0 ? void 0 : actionDefinition.customAttributes) !== null && _b !== void 0 ? _b : {};
405
- }
406
- supportMode(state) { return this.viewOnState(state); }
407
- viewOnState(state) { return this.visibleStates.includes(state); }
408
- enabledOnState(state) { return this.enabledStates.includes(state); }
409
- }
410
-
411
- class TableRecordData {
412
- constructor(recordReceived, recordDefinition, selectionFieldName = null) {
413
- this.recordData = {};
414
- const { tableRecordId, recordData } = recordReceived;
415
- this.recordId = tableRecordId;
416
- this.selected = false;
417
- this.recordData = {};
418
- if (!recordDefinition || recordDefinition.length === 0 || !recordData || recordData.length === 0) {
419
- return;
420
- }
421
- const fieldNames = recordDefinition.map(column => column.fieldCode);
422
- if (Array.isArray(recordData)) {
423
- const rawRecordData = recordData.filter(fieldData => fieldData.fieldCode && fieldNames.includes(fieldData.fieldCode));
424
- rawRecordData.forEach(fieldData => {
425
- const { fieldCode, fieldValue } = fieldData;
426
- const fieldDef = recordDefinition.find(column => column.fieldCode === fieldCode);
427
- this.recordData[fieldCode] = fieldValue !== null && fieldValue !== void 0 ? fieldValue : '';
428
- if (fieldCode === selectionFieldName) {
429
- this.selected = fieldValue;
430
- }
431
- });
432
- }
433
- else {
434
- const fields = Object.keys(recordData);
435
- fields.forEach(fieldCode => {
436
- const fieldValue = recordData[fieldCode];
437
- const fieldDef = recordDefinition.find(column => column.fieldCode === fieldCode);
438
- this.recordData[fieldCode] = fieldValue !== null && fieldValue !== void 0 ? fieldValue : '';
439
- });
440
- }
441
- }
442
- toggleSelect() { this.selected = !this.selected; }
443
- select() { this.selected = true; }
444
- unselect() { this.selected = false; }
445
- get recordIdKey() {
446
- return (typeof this.recordId === 'object')
447
- ? JSON.stringify(this.recordId) : this.recordId;
448
- }
449
- getFieldValue(fieldCode) {
450
- return (fieldCode && this.recordData[fieldCode])
451
- ? this.recordData[fieldCode] : null;
452
- }
453
- hasPattern(words) {
454
- if (!words || words.length === 0) {
455
- return true;
456
- }
457
- for (const fieldCode in this.recordData) {
458
- if (this.recordData.hasOwnProperty(fieldCode)) {
459
- for (const word of words) {
460
- const term = word.toUpperCase();
461
- const fieldValue = this.recordData[fieldCode];
462
- if (fieldValue.toString().toUpperCase().includes(term)) {
463
- return true;
464
- }
465
- }
466
- }
467
- }
468
- return false;
519
+ this.restrictedOnValue = actionDefinition.valueRestricted || '';
520
+ this.customValidation = () => true;
469
521
  }
470
- hasCondition(advancedFilter) {
471
- var _a;
472
- if (!advancedFilter || advancedFilter.length === 0) {
473
- return true;
474
- }
475
- for (const condition of advancedFilter) {
476
- const fieldCode = condition.fieldSearch.fieldCode;
477
- if (this.recordData.hasOwnProperty(fieldCode)) {
478
- const fieldValue = this.recordData[fieldCode].toString().toUpperCase();
479
- const conditionField1Value = (_a = condition === null || condition === void 0 ? void 0 : condition.fieldValue1) === null || _a === void 0 ? void 0 : _a.toString().toUpperCase();
480
- const conditionField2Value = condition.fieldValue2.toString().toUpperCase();
481
- if (condition.operator === operators.G && fieldValue <= conditionField1Value) {
482
- return false;
483
- }
484
- if (condition.operator === operators.L && fieldValue >= conditionField1Value) {
485
- return false;
486
- }
487
- if (condition.operator === operators.GE && fieldValue < conditionField1Value) {
488
- return false;
489
- }
490
- if (condition.operator === operators.LE && fieldValue > conditionField1Value) {
491
- return false;
492
- }
493
- if (condition.operator === operators.EQ) {
494
- return fieldValue === conditionField1Value;
495
- }
496
- if (condition.operator === operators.NOT_EQ && fieldValue === conditionField1Value) {
497
- return false;
498
- }
499
- if (condition.operator === operators.CONTENT && !fieldValue.includes(conditionField1Value)) {
500
- return false;
501
- }
502
- if (condition.operator === operators.NOT_CONTENT && fieldValue.includes(conditionField1Value)) {
503
- return false;
504
- }
505
- if (condition.operator === operators.BETWEEN && (fieldValue < conditionField1Value
506
- || fieldValue > conditionField2Value)) {
507
- return false;
508
- }
522
+ get actionActivated() { return this._actionActivated; }
523
+ start() { this.inProgress = true; }
524
+ stop() { this.inProgress = false; }
525
+ notifyActivation() { this._actionActivated.next(this.actionCode); }
526
+ updateFromServer(receivedAction) {
527
+ for (const propertyName in receivedAction) {
528
+ if (propertyName !== 'actionCode' && propertyName !== 'actionId') {
529
+ this[propertyName] = receivedAction[propertyName];
509
530
  }
510
531
  }
511
- return true;
512
532
  }
533
+ setCustomValidation(callback) { this.customValidation = () => callback(); }
513
534
  }
514
535
 
515
- const TABLE_SORT_ASCENDING = 'asc';
516
- const TABLE_SORT_DESCENDING = 'desc';
517
- const TABLE_FILTER_TYPES = {
518
- simpleFilterChange: 'SIMPLE_CHANGE',
519
- simpleFilterFinish: 'SIMPLE_FINISH',
520
- complexFilterAdd: 'COMPLEX_ADD',
521
- complexFilterRemove: 'COMPLEX_REMOVE',
522
- };
523
- class RecordTable extends FormElement {
524
- constructor(tableReceived, formConfig) {
525
- var _a, _b, _c, _d, _e, _f;
526
- super(tableReceived, formConfig);
527
- this._inlineActionTrigger = new Subject();
528
- this._globalActionTrigger = new Subject();
529
- this._recordSelectionTrigger = new Subject();
530
- this._selectionActionTrigger = new Subject();
531
- this._getDataTrigger = new Subject();
536
+ const UNDEFINED = 'undefined';
537
+ const DEFAULT_ERROR_TYPE = 'error';
538
+ const DEFAULT_CAPTURE_TYPE = 'INPUT';
539
+ const DEFAULT_ALIGNMENT = 'left';
540
+ const STD_MAX_LENGTH = 50;
541
+ const BIG_MAX_LENGTH = 500;
542
+ const fldAttr = {
543
+ validateOnServer: 'validateOnServer',
544
+ value: '_value',
545
+ minValue: '_minValue',
546
+ maxValue: '_maxValue',
547
+ maxLength: '_maxLength',
548
+ onValidation: '_onValidation',
549
+ focus: 'focus',
550
+ intrinsicErrorMessage: '_intrinsicErrorMessage',
551
+ code: 'fieldCode',
552
+ info: 'fieldInfo',
553
+ defaultValue: 'defaultValue',
554
+ defaultEditable: 'defaultEditable',
555
+ visibleLabel: 'visibleLabel',
556
+ required: 'fieldRequired',
557
+ hasChanged: 'hasChanged',
558
+ outputOnly: 'outputOnly',
559
+ captureType: 'captureType',
560
+ title: 'fieldTitle',
561
+ type: 'fieldType',
562
+ alignment: 'fieldAlignment',
563
+ format: 'fieldFormat',
564
+ externalValue: 'externalValue',
565
+ tooltipText: 'tooltipText',
566
+ errorType: 'errorType',
567
+ errorCode: 'errorCode',
568
+ errorMessage: 'errorMessage',
569
+ options: 'fieldOptions',
570
+ };
571
+ class FieldDescriptor extends FormElement {
572
+ constructor(inputFieldReceived, formConfig) {
573
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
574
+ super(inputFieldReceived, formConfig);
575
+ this._editionFinish = new Subject();
576
+ this._editionPartial = new Subject();
577
+ this._detailRequest = new Subject();
532
578
  this._attributeChange = new Subject();
533
- this._tableColumnObj = {};
534
- this._actionsObj = {};
535
- this.tableRecordObj = {};
536
- this.allSelected = false;
537
- this.elementType = elementTypes.table;
538
- this.waiting = false;
539
- this.currentPage = 1;
540
- this.totalPages = 1;
541
- this.requestedPage = 1;
542
- this.columns = [];
543
- this._tableColumnObj = {};
544
- this._actions = [];
545
- this._actionsObj = {};
546
- this.tableRecords = [];
547
- this.setAttr('allSelected', false);
548
- this.setAttr('filterObject', new Filter());
549
- this.setAttr('filterConfig', []);
550
- this.setAttr('tableCode', tableReceived.tableCode);
551
- this.tableTitle = tableReceived.tableTitle;
552
- this.setAttr('clientPaging', (_a = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.clientPaging) !== null && _a !== void 0 ? _a : true);
553
- this.setAttr('simpleFilter', (_b = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.simpleFilter) !== null && _b !== void 0 ? _b : false);
554
- this.setAttr('complexFilter', false);
555
- this._appendPages = (_c = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.append) !== null && _c !== void 0 ? _c : false;
556
- this.selectable = (_d = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectable) !== null && _d !== void 0 ? _d : false;
557
- this.setAttr('selectionBackend', (_e = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectionBackend) !== null && _e !== void 0 ? _e : false);
558
- this.setAttr('sortable', (_f = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.sortable) !== null && _f !== void 0 ? _f : false);
559
- this.setAttr('sorting', { columnName: '', direction: '' });
560
- this.setAttr('recordsPerPage', formConfig.defaultRecordsPerPage);
561
- if (tableReceived.fields) {
562
- const columns = [];
563
- for (const columnReceived of tableReceived.fields) {
564
- const columnDefinition = new RecordTableColumn(columnReceived, this._formConfig);
565
- columns.push(columnDefinition);
566
- this._tableColumnObj[columnDefinition.fieldCode] = columnDefinition;
567
- }
568
- this.setAttr('columns', columns);
569
- }
570
- if (tableReceived.actions) {
571
- const tableActions = tableReceived.actions.map(objDef => {
572
- let visibleStates = objDef.visibleStates;
573
- let enabledStates = objDef.enabledStates;
574
- if (!visibleStates) {
575
- visibleStates = (objDef.actionModes || '').split(',')
576
- .map(state => state.trim())
577
- .filter(state => state.length > 0);
578
- enabledStates = (objDef.actionModes || '').split(',')
579
- .map(state => state.trim())
580
- .filter(state => state.length > 0);
581
- }
582
- return Object.assign(Object.assign({}, objDef), { visibleStates, enabledStates });
583
- });
584
- for (const actionReceived of tableActions) {
585
- const inlineAction = new TableAction(actionReceived);
586
- this._actions.push(inlineAction);
587
- this._actionsObj[inlineAction.actionCode] = inlineAction;
588
- }
589
- }
590
- if (tableReceived.filters && tableReceived.filters.length > 0) {
591
- this.setAttr('complexFilter', true);
592
- const filterConfig = this.filterConfig;
593
- for (const filterReceived of tableReceived.filters) {
594
- const filterItem = new FieldSearch(filterReceived);
595
- filterConfig.push(filterItem);
596
- }
597
- this.setAttr('filterConfig', filterConfig);
579
+ this.elementType = elementTypes.field;
580
+ const fld = (inputFieldReceived) ? inputFieldReceived : {};
581
+ this.setAttr(fldAttr.code, fld.fieldCode);
582
+ this.setAttr(fldAttr.title, (_a = fld.fieldTitle) !== null && _a !== void 0 ? _a : this.fieldCode);
583
+ this.setAttr(fldAttr.captureType, (_b = fld.captureType) !== null && _b !== void 0 ? _b : DEFAULT_CAPTURE_TYPE);
584
+ this.setAttr(fldAttr.defaultValue, (_c = fld.defaultValue) !== null && _c !== void 0 ? _c : null);
585
+ const defaultTypeAlignment = (this._formConfig.tableFieldStyles[this.fieldType] != null)
586
+ ? this._formConfig.tableFieldStyles[this.fieldType]['text-align'] : DEFAULT_ALIGNMENT;
587
+ const fieldAlignment = (fld.alignment != null) ? fld.alignment.toLowerCase() : defaultTypeAlignment;
588
+ this.setAttr(fldAttr.alignment, fieldAlignment);
589
+ this.setAttr(fldAttr.info, fld.info || '');
590
+ let fieldFormat;
591
+ try {
592
+ fieldFormat = (fld.format) ? new RegExp(fld.format) : null;
598
593
  }
599
- if (this.selectable) {
600
- this.selectionField = this.columns
601
- .find(column => column.fieldCode === (tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectionField));
594
+ catch (e) {
595
+ fieldFormat = null;
602
596
  }
597
+ this.setAttr(fldAttr.format, fieldFormat);
598
+ this.setAttr(fldAttr.validateOnServer, (_d = fld.serverAction) !== null && _d !== void 0 ? _d : false);
599
+ this.setAttr(fldAttr.tooltipText, fld.tooltip || '');
600
+ this.setAttr(fldAttr.defaultEditable, this.enabled);
601
+ this.setAttr(fldAttr.required, (_e = fld.required) !== null && _e !== void 0 ? _e : false);
602
+ this.setError(fld.errorCode, fld.errorMessage, (_f = fld.errorType) !== null && _f !== void 0 ? _f : DEFAULT_ERROR_TYPE);
603
+ this.setAttr(fldAttr.outputOnly, (_g = fld.outputOnly) !== null && _g !== void 0 ? _g : false);
604
+ const maxLength = (_h = fld.maxLength) !== null && _h !== void 0 ? _h : (this.captureType === 'TEXTAREA' ? BIG_MAX_LENGTH : STD_MAX_LENGTH);
605
+ this.setAttr(fldAttr.maxLength, maxLength);
606
+ this.setAttr(fldAttr.intrinsicErrorMessage, (_j = this._formConfig.fieldTypeErrMsg[this.fieldType]) !== null && _j !== void 0 ? _j : this._formConfig.fieldTypeErrMsg.DEFAULT);
607
+ this.setFieldType(fld.fieldTypeCode);
608
+ this.setEditable((_k = fld.editable) !== null && _k !== void 0 ? _k : true);
609
+ this.setVisibleLabel((_l = fld.visibleLabel) !== null && _l !== void 0 ? _l : true);
610
+ this.setVisibility(fld.visible);
611
+ this.setFieldOptions(fld.fieldOptions);
612
+ this.setValue(fld.fieldValue || this.defaultValue || '');
603
613
  }
604
- get inlineActionTrigger() { return this._inlineActionTrigger; }
605
- get globalActionTrigger() { return this._globalActionTrigger; }
606
- get selectionActionTrigger() { return this._selectionActionTrigger; }
607
- get recordSelectionTrigger() { return this._recordSelectionTrigger; }
608
- get getDataTrigger() { return this._getDataTrigger; }
614
+ get name() { return this.fieldCode; }
615
+ get editionFinish() { return this._editionFinish; }
609
616
  get attributeChange() { return this._attributeChange; }
610
- get hasActions() { return (this._actions.length > 0); }
611
- get selectionFieldName() { var _a, _b; return (_b = (_a = this.selectionField) === null || _a === void 0 ? void 0 : _a.fieldCode) !== null && _b !== void 0 ? _b : null; }
612
- get columnNames() { return Object.keys(this._tableColumnObj); }
613
- get records() { return this.visibleRecords; }
614
- set records(records) { this.replaceRecords(records); }
615
- get selectedRecords() {
616
- return this.tableRecords.filter(rec => rec.selected)
617
- .map(rec => rec.recordId);
618
- }
619
- setAttr(name, value) {
620
- this[name] = value;
621
- if (this._formConfig.monitoredTableAttributes.includes(name)) {
622
- this._attributeChange.next({ name, value });
623
- }
624
- }
625
- appendRecords(records) { this.setTableRecords(records, true); }
626
- replaceRecords(records) { this.setTableRecords(records, false); }
627
- columnDefinition(fieldCode) { return this._tableColumnObj[fieldCode]; }
628
- putOnWait() { this.waiting = true; }
629
- freeWaiting() { this.waiting = false; }
630
- getActionObject(actionCode) { return this.getAction(actionCode); }
631
- notifyGlobalAction(actionCode) {
632
- const tableEvent = {
633
- tableCode: this.tableCode,
634
- actionCode,
635
- actionDetail: null
636
- };
637
- this._globalActionTrigger.next(tableEvent);
638
- }
639
- notifyInlineAction(tableActionEvent) {
640
- const tableEvent = {
641
- tableCode: this.tableCode,
642
- actionCode: tableActionEvent.actionCode,
643
- actionDetail: {
644
- recordId: tableActionEvent.recordId,
645
- recordData: tableActionEvent.recordData
646
- }
647
- };
648
- this._inlineActionTrigger.next(tableEvent);
649
- }
650
- notifyRecordSelection(recordId) {
651
- const record = this.getTableRecord(recordId);
652
- if (!record) {
653
- return;
654
- }
655
- record.toggleSelect();
656
- const tableEvent = {
657
- tableCode: this.tableCode,
658
- actionCode: null,
659
- actionDetail: {
660
- recordId: record.recordId,
661
- recordData: record.recordData
662
- }
663
- };
664
- this.recordSelectionTrigger.next(tableEvent);
665
- }
666
- notifySelectionAction(actionCode) {
667
- const tableEvent = {
668
- tableCode: this.tableCode,
669
- actionCode,
670
- actionDetail: {
671
- selectedRecords: this.selectedRecords
672
- }
673
- };
674
- this._selectionActionTrigger.next(tableEvent);
675
- }
676
- notifyGetDataAction(requestedPage = null) {
677
- this.updateVisibleRecords();
678
- this.requestedPage = requestedPage || this.currentPage;
679
- const tableEvent = {
680
- tableCode: this.tableCode,
681
- actionCode: null,
682
- actionDetail: null,
683
- };
684
- this._getDataTrigger.next(tableEvent);
685
- }
686
- clean() {
687
- this.visibleRecords = [];
688
- this.tableRecords = [];
689
- this.tableRecordObj = {};
690
- }
691
- selectAll() {
692
- this.setAttr('allSelected', true);
693
- this.tableRecords.forEach(record => record.select());
694
- }
695
- unSelectAll() {
696
- this.setAttr('allSelected', false);
697
- this.tableRecords.forEach(record => record.unselect());
698
- }
699
- setTableRecords(tableRecords, append) {
700
- var _a;
701
- if (!append) {
702
- this.clean();
703
- }
704
- const newRecordsObj = Object.assign({}, this.tableRecordObj);
705
- const newRecords = [...this.tableRecords];
706
- for (const tableRecord of tableRecords) {
707
- const recordReceived = new TableRecordData(tableRecord, this.columns, (_a = this.selectionField) === null || _a === void 0 ? void 0 : _a.fieldCode);
708
- const recordIdKey = recordReceived.recordIdKey;
709
- newRecords.push(recordReceived);
710
- newRecordsObj[recordIdKey] = recordReceived;
711
- }
712
- this.tableRecords = newRecords;
713
- this.tableRecordObj = newRecordsObj;
714
- this.updateVisibleRecords();
715
- }
716
- updateVisibleRecords() {
717
- if (!this.clientPaging || !this.tableRecords || this.tableRecords.length === 0) {
718
- this.setAttr('visibleRecords', this.tableRecords);
719
- }
720
- const recordsVisible = (this.filterObject.filterModeSimple)
721
- ? this.tableRecords.filter(record => record.hasPattern(this.filterObject.simpleFilterWords))
722
- : this.tableRecords.filter(record => record.hasCondition(this.filterObject.advancedFilter));
723
- this.setAttr('visibleRecords', recordsVisible);
724
- }
725
- updateFromServer(tableReceived) {
726
- this.visible = (tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.visible) || true;
727
- this.setAttr('currentPage', parseInt(tableReceived.currentPage, 10) || 1);
728
- this.totalPages = tableReceived.totalPages || 1;
729
- this.setAttr('recordsPerPage', tableReceived.recordsPerPage);
730
- this.recordsNumber = tableReceived.recordsNumber;
731
- this.setAttr('totalRecordsNumber', tableReceived.totalRecordsNumber);
732
- this.setAttr('sorting', {
733
- columnName: tableReceived.sortingColumn || '',
734
- direction: tableReceived.sortingDirection || ''
735
- });
736
- this.requestedPage = 1;
737
- this.waiting = false;
738
- this.clean();
739
- if (this._appendPages) {
740
- this.replaceRecords(tableReceived.tableRecords);
741
- }
742
- else {
743
- this.appendRecords(tableReceived.tableRecords);
744
- }
745
- }
746
- getTableRecord(recordId) {
747
- const recordIdKey = (typeof recordId === 'object') ? JSON.stringify(recordId) : recordId;
748
- return (this.tableRecordObj && recordId && this.tableRecordObj[recordId])
749
- ? this.tableRecordObj[recordId] : null;
750
- }
751
- getAction(actionCode) {
752
- return (this._actionsObj && actionCode && this._actionsObj[actionCode])
753
- ? this._actionsObj[actionCode] : null;
754
- }
755
- getActions(actionClass = this._formConfig.tableActions.inline, actionTypes = null) {
756
- return this._actions.filter(actionDef => {
757
- const typeIncluded = (actionTypes) ? actionTypes.includes(actionDef.actionType) : true;
758
- return actionDef.actionClass === actionClass && typeIncluded;
759
- });
760
- }
761
- // Filtros
762
- set simpleFilterText(filterText) {
763
- let terms = (filterText) ? filterText.split(' ') : null;
764
- if (terms && terms.length > 0) {
765
- terms = terms.filter((term) => term !== '');
766
- }
767
- this.filterObject.filterModeSimple = true;
768
- this.filterObject.simpleFilterWords = terms || [];
769
- }
770
- changeFilterMode(toSimple) {
771
- this.filterObject.filterModeSimple = toSimple;
772
- }
773
- addFilterRestriction(filterTerm) {
774
- this.filterObject.advancedFilter.push(filterTerm);
775
- }
776
- removeFilterRestriction(fieldCode) {
777
- const filterIndex = this.filterObject.advancedFilter.findIndex((filterDef) => {
778
- return filterDef.fieldSearch.fieldCode === fieldCode;
779
- });
780
- const filterToRemove = this.filterObject.advancedFilter[filterIndex];
781
- this.filterObject.advancedFilter.splice(filterIndex, 1);
782
- return filterToRemove;
783
- }
784
- get availableFilters() {
785
- return this.filterConfig.filter((fieldSearch) => {
786
- const currentFilter = this.filterObject.advancedFilter.find((filterItem) => {
787
- return filterItem.fieldSearch.fieldCode === fieldSearch.fieldCode;
788
- });
789
- return !currentFilter;
790
- });
791
- }
792
- get currentFilter() {
793
- const compactFilter = {};
794
- if (this.filterObject.filterModeSimple) {
795
- compactFilter.simpleFilterWords = this.filterObject.simpleFilterWords;
617
+ get editionPartial() { return this._editionPartial; }
618
+ get detailRequest() { return this._detailRequest; }
619
+ get info() { return this.fieldInfo; }
620
+ get validating() { return this._onValidation; }
621
+ set validating(isValidating) { this.setAttr(fldAttr.onValidation, isValidating); }
622
+ focus() { this.setAttr(fldAttr.focus, true); }
623
+ setIntrinsicErrorMessage(message) { this.setAttr(fldAttr.intrinsicErrorMessage, message); }
624
+ set intrinsicErrorMessage(message) { this.setIntrinsicErrorMessage(message); }
625
+ get fieldValue() { return this.getValue(); }
626
+ getRequired() { return this.required; }
627
+ setRequired(required) { this.required = required; }
628
+ get required() { return this.fieldRequired; }
629
+ set required(required) { this.setAttr(fldAttr.required, required !== null && required !== void 0 ? required : false); }
630
+ get maxLength() { return (this._maxLength > 0) ? this._maxLength.toString() : ''; }
631
+ set maxLength(requiredMaxLength) {
632
+ if (typeof requiredMaxLength === 'string') {
633
+ this.setAttr(fldAttr.maxLength, parseInt(requiredMaxLength, 10));
796
634
  }
797
- else {
798
- compactFilter.advancedFilter = [];
799
- this.filterObject.advancedFilter.forEach((condition) => {
800
- const simplifiedCondition = {
801
- fieldCode: condition.fieldSearch.fieldCode,
802
- fieldAlias: condition.fieldSearch.fieldAlias,
803
- operator: condition.operator,
804
- fieldValue1: condition.fieldValue1,
805
- fieldValue2: condition.fieldValue2,
806
- };
807
- compactFilter.advancedFilter.push(simplifiedCondition);
808
- });
635
+ else if (typeof requiredMaxLength === 'number') {
636
+ this.setAttr(fldAttr.maxLength, requiredMaxLength);
809
637
  }
810
- return compactFilter;
811
638
  }
812
- // Ordenamiento
813
- setRequiredOrder(columnField) {
814
- if (columnField !== this.sorting.columnName) {
815
- this.setAttr('sorting', {
816
- columnName: columnField,
817
- direction: TABLE_SORT_ASCENDING
818
- });
819
- }
820
- else {
821
- const tableSort = this.sorting;
822
- tableSort.direction = (tableSort.direction === TABLE_SORT_ASCENDING) ? TABLE_SORT_DESCENDING : TABLE_SORT_ASCENDING;
823
- this.setAttr('sorting', tableSort);
824
- }
639
+ get value() { return this.getValue(); }
640
+ set value(newValue) { this.setValue(newValue); }
641
+ notifyEditionPartial() {
642
+ const intrinsicValidation = true;
643
+ this._editionPartial.next({ code: this.fieldCode, intrinsicValidation });
825
644
  }
826
- localSortData() {
827
- if (!this.sorting.columnName || !this.sorting.direction) {
828
- return;
645
+ notifyEditionFinish() {
646
+ var _a, _b, _c, _d, _e;
647
+ let intrinsicValidation = true;
648
+ const fieldDefaultFormat = (_b = (_a = this._formConfig.fieldTypesPatterns) === null || _a === void 0 ? void 0 : _a[this.fieldType]) !== null && _b !== void 0 ? _b : null;
649
+ const fieldValue = this.getValue();
650
+ if (fieldValue && (fieldDefaultFormat || this.fieldFormat)) {
651
+ intrinsicValidation = ((_c = fieldDefaultFormat === null || fieldDefaultFormat === void 0 ? void 0 : fieldDefaultFormat.test(fieldValue)) !== null && _c !== void 0 ? _c : true)
652
+ && ((_e = (_d = this.fieldFormat) === null || _d === void 0 ? void 0 : _d.test(fieldValue)) !== null && _e !== void 0 ? _e : true);
653
+ if (!intrinsicValidation) {
654
+ this.setError('99', this._intrinsicErrorMessage);
655
+ }
829
656
  }
830
- this.tableRecords.sort((a, b) => this.recordCompare(a, b, this.sorting.columnName, this.sorting.direction));
831
- this.updateVisibleRecords();
832
- }
833
- recordCompare(recordA, recordB, columnCompare, direction) {
834
- const recordAColumn = recordA.getFieldValue(columnCompare);
835
- const recordBColumn = recordB.getFieldValue(columnCompare);
836
- let result = 0;
837
- if (recordAColumn < recordBColumn) {
838
- result = -1;
657
+ if (intrinsicValidation && fieldValue && this._minValue && fieldValue < this._minValue) {
658
+ intrinsicValidation = false;
659
+ this.setError('99', 'Campo con valor inferior al mínimo');
839
660
  }
840
- else if (recordAColumn > recordBColumn) {
841
- result = 1;
661
+ if (intrinsicValidation && fieldValue && this._maxValue && fieldValue > this._maxValue) {
662
+ intrinsicValidation = false;
663
+ this.setError('99', 'Campo con valor superior al máximo');
842
664
  }
843
- return direction === TABLE_SORT_ASCENDING ? result : -result;
844
- }
845
- }
846
-
847
- class LibTableFilterComponent {
848
- constructor() {
849
- this.simpleSearchString = '';
850
- this.filterObject = new Filter();
851
- this.complexIsCollapsed = true;
852
- this.filterChanged = new EventEmitter();
853
- }
854
- ngOnInit() {
855
- this.start();
665
+ this._editionFinish.next({ code: this.fieldCode, intrinsicValidation });
856
666
  }
857
- start() { }
858
- filterHasChanged(changeType) {
859
- this.complexIsCollapsed = true;
860
- const eventType = (changeType === 'change')
861
- ? TABLE_FILTER_TYPES.simpleFilterFinish
862
- : TABLE_FILTER_TYPES.simpleFilterChange;
863
- const tableFilterEvent = {
864
- eventType,
865
- simpleFilterString: this.simpleSearchString,
866
- complexFilterItem: null,
867
- itemName: null,
868
- };
869
- this.filterChanged.emit(tableFilterEvent);
870
- }
871
- selectField() {
872
- this.selectedOperator = '';
873
- this.filterValue1 = '';
874
- this.filterValue2 = '';
875
- this.filterFieldConfig = this.complexFilterConfig.find((filterConfig) => filterConfig.fieldCode === this.selectedField);
876
- this.possibleOperators = [];
877
- if (this.filterFieldConfig && this.filterFieldConfig.operators) {
878
- this.possibleOperators = this.filterFieldConfig.operators;
879
- }
880
- }
881
- addFilterField() {
882
- const filterCondition = {
883
- fieldSearch: this.filterFieldConfig,
884
- operator: this.selectedOperator,
885
- fieldValue1: this.filterValue1,
886
- fieldValue2: this.filterValue2,
887
- };
888
- const tableFilterEvent = {
889
- eventType: TABLE_FILTER_TYPES.complexFilterAdd,
890
- simpleFilterString: null,
891
- complexFilterItem: filterCondition,
892
- itemName: null,
893
- };
894
- this.filterChanged.emit(tableFilterEvent);
895
- this.clearFilterField();
896
- }
897
- clearFilterField() {
898
- this.selectedField = '';
899
- this.selectedOperator = '';
900
- this.selectedOperator = '';
901
- this.filterValue1 = '';
902
- this.filterValue2 = '';
903
- this.possibleOperators = [];
904
- }
905
- removeFilterField(fieldCode) {
906
- const tableFilterEvent = {
907
- eventType: TABLE_FILTER_TYPES.complexFilterRemove,
908
- simpleFilterString: null,
909
- complexFilterItem: null,
910
- itemName: fieldCode,
911
- };
912
- this.filterChanged.emit(tableFilterEvent);
913
- // Se elimina de la configuración de filtro local
914
- const idx = this.filterObject.advancedFilter.findIndex(def => def.fieldSearch.fieldCode === fieldCode);
915
- if (idx >= 0) {
916
- const filterToRemove = this.filterObject.advancedFilter[idx];
917
- this.selectedField = filterToRemove.fieldSearch.fieldCode;
918
- this.selectField();
919
- this.selectedOperator = filterToRemove.operator;
920
- this.filterValue1 = filterToRemove.fieldValue1;
921
- this.filterValue2 = filterToRemove.fieldValue2;
922
- this.filterObject.advancedFilter.splice(idx, 1);
667
+ setAttr(name, value) {
668
+ this[name] = value;
669
+ if (this._formConfig.monitoredFieldAttributes.includes(name)) {
670
+ this._attributeChange.next({ name, value });
923
671
  }
924
672
  }
925
- }
926
- LibTableFilterComponent.decorators = [
927
- { type: Component, args: [{
928
- selector: 'lib-table-filter',
929
- template: `<ng-content></ng-content>`
930
- },] }
931
- ];
932
- LibTableFilterComponent.propDecorators = {
933
- simpleFilter: [{ type: Input }],
934
- complexFilter: [{ type: Input }],
935
- complexFilterConfig: [{ type: Input }],
936
- filterChanged: [{ type: Output }]
937
- };
938
-
939
- const INLINE_ACTION$1 = 'INLINE';
940
- class LibTableRecordActionComponent {
941
- constructor() {
942
- this.actionSelected = new EventEmitter();
943
- }
944
- ngOnInit() {
945
- this.start();
946
- }
947
- start() { }
948
- onActivate() {
949
- const tableEvent = {
950
- actionCode: this.action.actionCode,
951
- recordId: this.recordId,
952
- recordData: this.recordData,
673
+ notifyEditionDetailRequest(detail) {
674
+ const detailEvent = {
675
+ code: this.fieldCode,
676
+ detail,
953
677
  };
954
- this.actionSelected.emit(tableEvent);
955
- }
956
- class() { }
957
- }
958
- LibTableRecordActionComponent.decorators = [
959
- { type: Component, args: [{
960
- selector: 'lib-table-record-action',
961
- template: `<ng-content></ng-content>`,
962
- changeDetection: ChangeDetectionStrategy.OnPush
963
- },] }
964
- ];
965
- LibTableRecordActionComponent.ctorParameters = () => [];
966
- LibTableRecordActionComponent.propDecorators = {
967
- recordId: [{ type: Input }],
968
- recordData: [{ type: Input }],
969
- action: [{ type: Input }],
970
- actionSelected: [{ type: Output }]
971
- };
972
-
973
- class LibTableRecordFieldComponent {
974
- ngOnInit() {
975
- this.start();
678
+ this._detailRequest.next(detailEvent);
976
679
  }
977
- start() { }
978
- }
979
- LibTableRecordFieldComponent.decorators = [
980
- { type: Component, args: [{
981
- selector: 'lib-table-record-field',
982
- template: `<ng-content></ng-content>`,
983
- changeDetection: ChangeDetectionStrategy.OnPush
984
- },] }
985
- ];
986
- LibTableRecordFieldComponent.propDecorators = {
987
- fieldCode: [{ type: Input }],
988
- fieldType: [{ type: Input }],
989
- fieldValue: [{ type: Input }]
990
- };
991
-
992
- class LibTableComponent {
993
- constructor() {
994
- this.loaded = false;
995
- this.selectable = false;
996
- this.hasActions = false;
680
+ setVisibleLabel(visibleLabel) { this.setAttr(fldAttr.visibleLabel, visibleLabel); }
681
+ showLabel() { this.setVisibleLabel(true); }
682
+ hideLabel() { this.setVisibleLabel(false); }
683
+ setChanged(hasChanged) { this.setAttr(fldAttr.hasChanged, hasChanged); }
684
+ changed() { this.setChanged(true); }
685
+ setLabel(label) { this.setAttr(fldAttr.title, label); }
686
+ clean() { this.setValue(this.defaultValue || ''); this.resetError(); }
687
+ get backend() { return this.validateOnServer; }
688
+ setEditable(editable = true) { (editable) ? this.enable() : this.disable(); }
689
+ hasError() { return this.errorCode !== NO_ERROR; }
690
+ resetError() { (this.errorCode !== NO_ERROR) && this.setError(NO_ERROR, null); }
691
+ setError(code, message, type = DEFAULT_ERROR_TYPE) {
692
+ this.setAttr(fldAttr.errorCode, code !== null && code !== void 0 ? code : NO_ERROR);
693
+ this.setAttr(fldAttr.errorType, (this.errorCode === NO_ERROR) ? '' : type);
694
+ this.setAttr(fldAttr.errorMessage, message !== null && message !== void 0 ? message : '');
997
695
  }
998
- ngOnInit() {
999
- var _a, _b;
1000
- if (this.table) {
1001
- this.formConfig = (_a = this.table) === null || _a === void 0 ? void 0 : _a._formConfig;
1002
- this.tableFieldStyles = this.formConfig.tableFieldStyles;
1003
- this.selectable = this.table.selectable;
1004
- this.hasActions = this.table.hasActions;
1005
- this.inlineActions = this.table.getActions(this.formConfig.tableActions.inline);
1006
- this.globalActions = this.table.getActions(this.formConfig.tableActions.global);
1007
- this.selectionActions = this.table.getActions(this.formConfig.tableActions.selection);
1008
- // Inicialización de campos mapeados del objeto
1009
- const mapping = Object.entries(this.formConfig.componentTableAttrMap);
1010
- for (let index = 0; index < mapping.length; index++) {
1011
- const [tableAttr, compAttr] = mapping[index];
1012
- this[compAttr.toString()] = (_b = this.table) === null || _b === void 0 ? void 0 : _b[tableAttr.toString()];
1013
- }
1014
- // Subscripción a cambios en atributos
1015
- this.table.attributeChange.subscribe(event => {
1016
- const { name: tableAttr, value } = event;
1017
- const compAttr = this.formConfig.componentTableAttrMap[tableAttr];
1018
- this.hasOwnProperty(compAttr) && (this[compAttr] = value);
1019
- });
696
+ getError() { return { type: this.errorType, code: this.errorCode, message: this.errorMessage }; }
697
+ get error() { return this.getError(); }
698
+ set error(errorObj) { var _a; this.setError(errorObj.code, errorObj.message, (_a = errorObj.type) !== null && _a !== void 0 ? _a : DEFAULT_ERROR_TYPE); }
699
+ getErrorCode() { return this.getError().code; }
700
+ setErrorCode(code) { this.setError(code, this.errorMessage); }
701
+ getErrorMessage() { return this.getError().message; }
702
+ setErrorMessage(msg) { this.setError(this.errorCode, msg); }
703
+ get empty() { return this.isEmpty(); }
704
+ isEmpty() {
705
+ const fieldCurrentValue = this.getValue();
706
+ if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
707
+ return true;
708
+ }
709
+ if ((this.fieldType === this._formConfig.fieldTypes.array || this.fieldType === this._formConfig.fieldTypes.phone)
710
+ && Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
711
+ return true;
1020
712
  }
1021
- this.start();
1022
- }
1023
- start() { }
1024
- tableGlobalAction(actionCode) {
1025
- this.table.notifyGlobalAction(actionCode);
713
+ ;
714
+ return fieldCurrentValue === '';
1026
715
  }
1027
- tableSelectionAction(actionCode) {
1028
- this.table.notifySelectionAction(actionCode);
716
+ getValue() {
717
+ if (this.fieldType === this._formConfig.fieldTypes.boolean
718
+ || this.fieldType === this._formConfig.fieldTypes.check) {
719
+ return yn(this._value);
720
+ }
721
+ return this._value;
1029
722
  }
1030
- tableActionSelected(actionEvent) {
1031
- this.table.notifyInlineAction(actionEvent);
723
+ getOptionText() {
724
+ var _a, _b, _c;
725
+ return (_c = (_b = (_a = this.fieldOptions) === null || _a === void 0 ? void 0 : _a.find(item => item.fieldOptionId === this._value)) === null || _b === void 0 ? void 0 : _b.fieldOptionValue) !== null && _c !== void 0 ? _c : null;
1032
726
  }
1033
- tableColumnSort(columnFieldCode) {
1034
- this.table.setRequiredOrder(columnFieldCode);
1035
- if (this.clientPaging) {
1036
- return this.table.localSortData();
727
+ updateFromServer(fld) {
728
+ var _a;
729
+ const fieldKeys = Object.keys(fld);
730
+ for (let index = 0; index < fieldKeys.length; index++) {
731
+ const attrName = fieldKeys[index];
732
+ const attrValue = fld[attrName];
733
+ (attrName === this._formConfig.apiFieldAttrs.visible) && this.setVisibility(attrValue);
734
+ (attrName === this._formConfig.apiFieldAttrs.labelVisible) && this.setVisibleLabel(fld.visibleLabel);
735
+ (attrName === this._formConfig.apiFieldAttrs.required) && this.setAttr(fldAttr.required, (_a = fld.required) !== null && _a !== void 0 ? _a : false);
736
+ (attrName === this._formConfig.apiFieldAttrs.errorCode) && this.setAttr(fldAttr.errorCode, fld.errorCode);
737
+ (attrName === this._formConfig.apiFieldAttrs.errorMessage) && this.setAttr(fldAttr.errorMessage, fld.errorMessage);
738
+ (attrName === this._formConfig.apiFieldAttrs.tooltip) && this.setAttr(fldAttr.tooltipText, fld.tooltip);
739
+ (attrName === this._formConfig.apiFieldAttrs.info) && this.setAttr(fldAttr.info, fld.info);
740
+ (attrName === this._formConfig.apiFieldAttrs.editable) && this.setEditable(fld.editable);
741
+ (attrName === this._formConfig.apiFieldAttrs.title) && this.setLabel(fld.fieldTitle.toString());
742
+ (attrName === this._formConfig.apiFieldAttrs.value) && (this.setValue(fld.fieldValue) && this.setChanged(false));
743
+ (attrName === this._formConfig.apiFieldAttrs.options) && this.setFieldOptions(fld.fieldOptions);
744
+ (attrName === this._formConfig.apiFieldAttrs.captureType) && this.setAttr(fldAttr.captureType, fld.captureType || 'INPUT');
745
+ (attrName === this._formConfig.apiFieldAttrs.type) && this.setFieldType(fld.fieldTypeCode);
746
+ (attrName === this._formConfig.apiFieldAttrs.maxLength) && this.setAttr(fldAttr.maxLength, fld.maxLength);
1037
747
  }
1038
- this.table.notifyGetDataAction();
1039
748
  }
1040
- changePage(requestedPage) {
1041
- if (!this.clientPaging) {
1042
- this.table.notifyGetDataAction(requestedPage);
749
+ setFieldType(inputFieldType) {
750
+ this.setAttr(fldAttr.type, inputFieldType);
751
+ }
752
+ setMinValue(inputMinValue) {
753
+ let minValue = inputMinValue;
754
+ if (this.fieldType === this._formConfig.fieldTypes.date) {
755
+ minValue = new Date(minValue);
1043
756
  }
757
+ this.setAttr(fldAttr.minValue, minValue);
1044
758
  }
1045
- get records() {
1046
- const currentPageRecords = this.visibleRecords;
1047
- if (this.clientPaging && currentPageRecords && currentPageRecords.length > 0) {
1048
- this.totalRecordsNumber = currentPageRecords.length;
1049
- return currentPageRecords.map((record, i) => (Object.assign({ id: i + 1 }, record)))
1050
- .slice((this.currentPage - 1) * this.recordsPerPage, (this.currentPage - 1) * this.recordsPerPage + this.recordsPerPage);
759
+ setMaxValue(inputMaxValue) {
760
+ let maxValue = inputMaxValue;
761
+ if (this.fieldType === this._formConfig.fieldTypes.date) {
762
+ maxValue = new Date(maxValue);
1051
763
  }
1052
- return currentPageRecords;
764
+ this.setAttr(fldAttr.maxValue, maxValue);
765
+ }
766
+ getFieldOptions() {
767
+ return this.fieldOptions.map(option => {
768
+ const optionCopy = Object.assign({}, option);
769
+ return optionCopy;
770
+ });
1053
771
  }
1054
- applyCurrentFilter(tableFilterEvent) {
1055
- const { eventType } = tableFilterEvent;
1056
- let triggerDataUpdate = false;
1057
- if (eventType === TABLE_FILTER_TYPES.simpleFilterChange || eventType === TABLE_FILTER_TYPES.simpleFilterFinish) {
1058
- this.table.simpleFilterText = tableFilterEvent.simpleFilterString.trim();
1059
- if (this.clientPaging) {
1060
- this.table.setAttr('currentPage', 1);
1061
- this.table.updateVisibleRecords();
772
+ setFieldOptions(newOptions) {
773
+ var _a;
774
+ if ((this.captureType !== 'LIST' && this.captureType !== 'RADIO')
775
+ || typeof newOptions === UNDEFINED || !newOptions
776
+ || !Array.isArray(newOptions)) {
777
+ return;
778
+ }
779
+ let fieldOptions = newOptions.map(option => {
780
+ if (option.text !== undefined && option.text !== null
781
+ && option.value !== undefined && option.value !== null) {
782
+ return { fieldOptionValue: option.text, fieldOptionId: option.value };
783
+ }
784
+ return Object.assign({}, option);
785
+ });
786
+ fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
787
+ && fieldOptions.length > 0) ? fieldOptions : [];
788
+ this.setAttr(fldAttr.options, fieldOptions);
789
+ if (this._value) {
790
+ if (this.fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
791
+ const fieldValue = (_a = this._value) === null || _a === void 0 ? void 0 : _a.filter(item => this.fieldOptions.find(opt => opt.fieldOptionId === item));
792
+ this.setAttr(fldAttr.value, fieldValue);
1062
793
  }
1063
- else if (eventType === TABLE_FILTER_TYPES.simpleFilterFinish) {
1064
- triggerDataUpdate = true;
794
+ else {
795
+ const valInOptions = this.fieldOptions
796
+ .find(item => item.fieldOptionId === this._value);
797
+ if (!valInOptions) {
798
+ this.setValue('');
799
+ }
1065
800
  }
1066
801
  }
1067
- if (eventType === TABLE_FILTER_TYPES.complexFilterAdd) {
1068
- this.table.addFilterRestriction(tableFilterEvent.complexFilterItem);
802
+ if (this.fieldRequired && this.fieldOptions.length === 1) {
803
+ this.setValue(this.fieldOptions[0].fieldOptionId);
1069
804
  }
1070
- if (eventType === TABLE_FILTER_TYPES.complexFilterRemove) {
1071
- this.table.removeFilterRestriction(tableFilterEvent.itemName);
805
+ }
806
+ setValue(newValue, widgetUpdate = true) {
807
+ if (typeof newValue === UNDEFINED || newValue === null) {
808
+ return true;
1072
809
  }
1073
- if (triggerDataUpdate) {
1074
- const tableGetDataEvent = {
1075
- tableCode: this.table.tableCode,
1076
- requestedPage: 1,
1077
- };
1078
- this.table.notifyGetDataAction(tableGetDataEvent);
810
+ let newFinalValue;
811
+ if (this.fieldType === this._formConfig.fieldTypes.boolean
812
+ || this.fieldType === this._formConfig.fieldTypes.check) {
813
+ newFinalValue = yn(newValue);
1079
814
  }
1080
- }
1081
- tableSelectionToggle(recordId) {
1082
- this.table.notifyRecordSelection(recordId);
1083
- }
1084
- toggleSelectAll() {
1085
- if (this.allSelected) {
1086
- this.table.unSelectAll();
815
+ else if (this.fieldType === this._formConfig.fieldTypes.array
816
+ || this.fieldType === this._formConfig.fieldTypes.map) {
817
+ if (newValue === null || newValue === '') {
818
+ newFinalValue = [];
819
+ }
820
+ else if (Array.isArray(newValue)) {
821
+ newFinalValue = newValue;
822
+ }
823
+ else {
824
+ newFinalValue = newValue.toString().split(',');
825
+ }
1087
826
  }
1088
827
  else {
1089
- this.table.selectAll();
828
+ newFinalValue = newValue;
829
+ }
830
+ if (this._value !== newFinalValue) {
831
+ this.setChanged(true);
832
+ if (widgetUpdate) {
833
+ this.setAttr(fldAttr.value, newFinalValue);
834
+ }
835
+ else {
836
+ this._value = newFinalValue;
837
+ }
838
+ }
839
+ return true;
840
+ }
841
+ }
842
+
843
+ class RecordTableColumn {
844
+ constructor(recTableColReceived, formConfig) {
845
+ var _a, _b, _c;
846
+ this._formConfig = formConfig;
847
+ if (recTableColReceived) {
848
+ this.fieldCode = recTableColReceived.fieldCode;
849
+ this.fieldTitle = recTableColReceived.fieldTitle;
850
+ this.fieldType = recTableColReceived.fieldTypeCode || this._formConfig.fieldTypes.text;
851
+ const defaultTypeAlignment = (this._formConfig.tableFieldStyles[this.fieldType] != null) ? this._formConfig.tableFieldStyles[this.fieldType]['text-align'] : 'left';
852
+ this.fieldAlignment = (recTableColReceived.alignment != null) ? recTableColReceived.alignment.toLowerCase() : defaultTypeAlignment;
853
+ this.visible = (_a = recTableColReceived === null || recTableColReceived === void 0 ? void 0 : recTableColReceived.visible) !== null && _a !== void 0 ? _a : true;
854
+ this.sortable = (_b = recTableColReceived === null || recTableColReceived === void 0 ? void 0 : recTableColReceived.sortable) !== null && _b !== void 0 ? _b : false;
855
+ this.fieldFormat = recTableColReceived.format || '';
856
+ this.customAttributes = (_c = recTableColReceived === null || recTableColReceived === void 0 ? void 0 : recTableColReceived.customAttributes) !== null && _c !== void 0 ? _c : {};
1090
857
  }
1091
858
  }
1092
- get availableFilters() {
1093
- return this.table.availableFilters;
859
+ addFilterDefinition(filterDefinition) {
860
+ var _a;
861
+ this.filterDef = {
862
+ operators: filterDefinition.operators,
863
+ options: (_a = filterDefinition.options) !== null && _a !== void 0 ? _a : null,
864
+ };
865
+ }
866
+ get filterDefinition() {
867
+ return this.filterDef;
868
+ }
869
+ addFilter(columnValues, operator) {
870
+ this.filterSetup = {
871
+ fieldCode: this.fieldCode,
872
+ operator: operator !== null && operator !== void 0 ? operator : this.filterDef.operators[0],
873
+ values: columnValues,
874
+ };
875
+ }
876
+ get filter() {
877
+ return this.filterSetup;
1094
878
  }
1095
- get selectedRecords() {
1096
- return this.table.selectedRecords;
879
+ removeFilter() {
880
+ this.filterSetup = null;
1097
881
  }
1098
882
  }
1099
- LibTableComponent.decorators = [
1100
- { type: Component, args: [{
1101
- selector: 'lib-table',
1102
- template: `<ng-content></ng-content>`,
1103
- changeDetection: ChangeDetectionStrategy.OnPush
1104
- },] }
1105
- ];
1106
- LibTableComponent.propDecorators = {
1107
- table: [{ type: Input }],
1108
- tableRecords: [{ type: Input }],
1109
- disabled: [{ type: Input }],
1110
- state: [{ type: Input }],
1111
- waiting: [{ type: Input }]
1112
- };
1113
883
 
1114
- const HEADER = 'HEADER';
1115
- class FormAction extends FormElement {
1116
- constructor(actionDefinition, formConfig) {
1117
- var _a;
1118
- super(actionDefinition, formConfig);
1119
- this._actionActivated = new Subject();
1120
- this.inProgress = false;
1121
- this.elementType = elementTypes.action;
1122
- this.actionCode = actionDefinition.actionCode ? actionDefinition.actionCode.toString() : '';
1123
- this.actionName = actionDefinition.actionTitle;
884
+ class TableAction {
885
+ constructor(actionDefinition) {
886
+ var _a, _b;
887
+ this.actionCode = actionDefinition.actionCode;
888
+ this.actionTitle = actionDefinition.actionTitle;
1124
889
  this.iconName = actionDefinition.iconName || this.actionCode;
1125
- this.setCustomAttribute('location', actionDefinition.position || HEADER);
890
+ this.actionType = actionDefinition.actionType || 'STANDARD';
891
+ this.actionClass = actionDefinition.actionClass || 'INLINE';
892
+ this.newState = actionDefinition.newState;
893
+ this.stateField = actionDefinition.stateField || '';
894
+ this.visibleStates = actionDefinition.visibleStates || [];
895
+ this.enabledStates = actionDefinition.enabledStates || [];
1126
896
  this.backend = (_a = actionDefinition === null || actionDefinition === void 0 ? void 0 : actionDefinition.serverAction) !== null && _a !== void 0 ? _a : false;
1127
- this.newState = actionDefinition === null || actionDefinition === void 0 ? void 0 : actionDefinition.newState;
1128
- this.restrictedOnField = actionDefinition.fieldRestrictedCode ? actionDefinition.fieldRestrictedCode.toString() : '';
1129
- this.restrictedOnOperator = actionDefinition.operatorRestricted || '';
897
+ this.restrictedOnField = actionDefinition.fieldRestrictedCode || '';
1130
898
  this.restrictedOnValue = actionDefinition.valueRestricted || '';
1131
- this.customValidation = () => true;
1132
- }
1133
- get actionActivated() { return this._actionActivated; }
1134
- start() { this.inProgress = true; }
1135
- stop() { this.inProgress = false; }
1136
- notifyActivation() { this._actionActivated.next(this.actionCode); }
1137
- updateFromServer(receivedAction) {
1138
- for (const propertyName in receivedAction) {
1139
- if (propertyName !== 'actionCode' && propertyName !== 'actionId') {
1140
- this[propertyName] = receivedAction[propertyName];
1141
- }
1142
- }
899
+ this.restrictedOnOperator = actionDefinition.operatorRestricted || '';
900
+ this.customAttributes = (_b = actionDefinition === null || actionDefinition === void 0 ? void 0 : actionDefinition.customAttributes) !== null && _b !== void 0 ? _b : {};
1143
901
  }
1144
- setCustomValidation(callback) { this.customValidation = () => callback(); }
902
+ supportMode(state) { return this.viewOnState(state); }
903
+ viewOnState(state) { return this.visibleStates.includes(state); }
904
+ enabledOnState(state) { return this.enabledStates.includes(state); }
1145
905
  }
1146
906
 
1147
- const UNDEFINED = 'undefined';
1148
- const DEFAULT_ERROR_TYPE = 'error';
1149
- const DEFAULT_CAPTURE_TYPE = 'INPUT';
1150
- const DEFAULT_ALIGNMENT = 'left';
1151
- const STD_MAX_LENGTH = 50;
1152
- const BIG_MAX_LENGTH = 500;
1153
- const fldAttr = {
1154
- validateOnServer: 'validateOnServer',
1155
- value: '_value',
1156
- minValue: '_minValue',
1157
- maxValue: '_maxValue',
1158
- maxLength: '_maxLength',
1159
- onValidation: '_onValidation',
1160
- focus: 'focus',
1161
- intrinsicErrorMessage: '_intrinsicErrorMessage',
1162
- code: 'fieldCode',
1163
- info: 'fieldInfo',
1164
- defaultValue: 'defaultValue',
1165
- defaultEditable: 'defaultEditable',
1166
- visibleLabel: 'visibleLabel',
1167
- required: 'fieldRequired',
1168
- hasChanged: 'hasChanged',
1169
- outputOnly: 'outputOnly',
1170
- captureType: 'captureType',
1171
- title: 'fieldTitle',
1172
- type: 'fieldType',
1173
- alignment: 'fieldAlignment',
1174
- format: 'fieldFormat',
1175
- externalValue: 'externalValue',
1176
- tooltipText: 'tooltipText',
1177
- errorType: 'errorType',
1178
- errorCode: 'errorCode',
1179
- errorMessage: 'errorMessage',
1180
- options: 'fieldOptions',
1181
- };
1182
- class FieldDescriptor extends FormElement {
1183
- constructor(inputFieldReceived, formConfig) {
1184
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1185
- super(inputFieldReceived, formConfig);
1186
- this._editionFinish = new Subject();
1187
- this._editionPartial = new Subject();
1188
- this._detailRequest = new Subject();
1189
- this._attributeChange = new Subject();
1190
- this.elementType = elementTypes.field;
1191
- const fld = (inputFieldReceived) ? inputFieldReceived : {};
1192
- this.setAttr(fldAttr.code, fld.fieldCode);
1193
- this.setAttr(fldAttr.title, (_a = fld.fieldTitle) !== null && _a !== void 0 ? _a : this.fieldCode);
1194
- this.setAttr(fldAttr.captureType, (_b = fld.captureType) !== null && _b !== void 0 ? _b : DEFAULT_CAPTURE_TYPE);
1195
- this.setAttr(fldAttr.defaultValue, (_c = fld.defaultValue) !== null && _c !== void 0 ? _c : null);
1196
- const defaultTypeAlignment = (this._formConfig.tableFieldStyles[this.fieldType] != null)
1197
- ? this._formConfig.tableFieldStyles[this.fieldType]['text-align'] : DEFAULT_ALIGNMENT;
1198
- const fieldAlignment = (fld.alignment != null) ? fld.alignment.toLowerCase() : defaultTypeAlignment;
1199
- this.setAttr(fldAttr.alignment, fieldAlignment);
1200
- this.setAttr(fldAttr.info, fld.info || '');
1201
- let fieldFormat;
1202
- try {
1203
- fieldFormat = (fld.format) ? new RegExp(fld.format) : null;
907
+ class TableRecordData {
908
+ constructor(recordReceived, recordDefinition, selectionFieldName = null) {
909
+ this.recordData = {};
910
+ const { tableRecordId, recordData } = recordReceived;
911
+ this.recordId = tableRecordId;
912
+ this.selected = false;
913
+ this.recordData = {};
914
+ if (!recordDefinition || recordDefinition.length === 0 || !recordData || recordData.length === 0) {
915
+ return;
1204
916
  }
1205
- catch (e) {
1206
- fieldFormat = null;
917
+ const fieldNames = recordDefinition.map(column => column.fieldCode);
918
+ if (Array.isArray(recordData)) {
919
+ const rawRecordData = recordData.filter(fieldData => fieldData.fieldCode && fieldNames.includes(fieldData.fieldCode));
920
+ rawRecordData.forEach(fieldData => {
921
+ const { fieldCode, fieldValue } = fieldData;
922
+ const fieldDef = recordDefinition.find(column => column.fieldCode === fieldCode);
923
+ this.recordData[fieldCode] = fieldValue !== null && fieldValue !== void 0 ? fieldValue : '';
924
+ if (fieldCode === selectionFieldName) {
925
+ this.selected = fieldValue;
926
+ }
927
+ });
928
+ }
929
+ else {
930
+ const fields = Object.keys(recordData);
931
+ fields.forEach(fieldCode => {
932
+ const fieldValue = recordData[fieldCode];
933
+ const fieldDef = recordDefinition.find(column => column.fieldCode === fieldCode);
934
+ this.recordData[fieldCode] = fieldValue !== null && fieldValue !== void 0 ? fieldValue : '';
935
+ });
1207
936
  }
1208
- this.setAttr(fldAttr.format, fieldFormat);
1209
- this.setAttr(fldAttr.validateOnServer, (_d = fld.serverAction) !== null && _d !== void 0 ? _d : false);
1210
- this.setAttr(fldAttr.tooltipText, fld.tooltip || '');
1211
- this.setAttr(fldAttr.defaultEditable, this.enabled);
1212
- this.setAttr(fldAttr.required, (_e = fld.required) !== null && _e !== void 0 ? _e : false);
1213
- this.setError(fld.errorCode, fld.errorMessage, (_f = fld.errorType) !== null && _f !== void 0 ? _f : DEFAULT_ERROR_TYPE);
1214
- this.setAttr(fldAttr.outputOnly, (_g = fld.outputOnly) !== null && _g !== void 0 ? _g : false);
1215
- const maxLength = (_h = fld.maxLength) !== null && _h !== void 0 ? _h : (this.captureType === 'TEXTAREA' ? BIG_MAX_LENGTH : STD_MAX_LENGTH);
1216
- this.setAttr(fldAttr.maxLength, maxLength);
1217
- this.setAttr(fldAttr.intrinsicErrorMessage, (_j = this._formConfig.fieldTypeErrMsg[this.fieldType]) !== null && _j !== void 0 ? _j : this._formConfig.fieldTypeErrMsg.DEFAULT);
1218
- this.setFieldType(fld.fieldTypeCode);
1219
- this.setEditable((_k = fld.editable) !== null && _k !== void 0 ? _k : true);
1220
- this.setVisibleLabel((_l = fld.visibleLabel) !== null && _l !== void 0 ? _l : true);
1221
- this.setVisibility(fld.visible);
1222
- this.setFieldOptions(fld.fieldOptions);
1223
- this.setValue(fld.fieldValue || this.defaultValue || '');
1224
937
  }
1225
- get name() { return this.fieldCode; }
1226
- get editionFinish() { return this._editionFinish; }
1227
- get attributeChange() { return this._attributeChange; }
1228
- get editionPartial() { return this._editionPartial; }
1229
- get detailRequest() { return this._detailRequest; }
1230
- get info() { return this.fieldInfo; }
1231
- get validating() { return this._onValidation; }
1232
- set validating(isValidating) { this.setAttr(fldAttr.onValidation, isValidating); }
1233
- focus() { this.setAttr(fldAttr.focus, true); }
1234
- setIntrinsicErrorMessage(message) { this.setAttr(fldAttr.intrinsicErrorMessage, message); }
1235
- set intrinsicErrorMessage(message) { this.setIntrinsicErrorMessage(message); }
1236
- get fieldValue() { return this.getValue(); }
1237
- getRequired() { return this.required; }
1238
- setRequired(required) { this.required = required; }
1239
- get required() { return this.fieldRequired; }
1240
- set required(required) { this.setAttr(fldAttr.required, required !== null && required !== void 0 ? required : false); }
1241
- get maxLength() { return (this._maxLength > 0) ? this._maxLength.toString() : ''; }
1242
- set maxLength(requiredMaxLength) {
1243
- if (typeof requiredMaxLength === 'string') {
1244
- this.setAttr(fldAttr.maxLength, parseInt(requiredMaxLength, 10));
938
+ toggleSelect() { this.selected = !this.selected; }
939
+ select() { this.selected = true; }
940
+ unselect() { this.selected = false; }
941
+ get recordIdKey() {
942
+ return (typeof this.recordId === 'object')
943
+ ? JSON.stringify(this.recordId) : this.recordId;
944
+ }
945
+ getFieldValue(fieldCode) {
946
+ return (fieldCode && this.recordData[fieldCode])
947
+ ? this.recordData[fieldCode] : null;
948
+ }
949
+ hasPattern(words) {
950
+ if (!words || words.length === 0) {
951
+ return true;
1245
952
  }
1246
- else if (typeof requiredMaxLength === 'number') {
1247
- this.setAttr(fldAttr.maxLength, requiredMaxLength);
953
+ for (const fieldCode in this.recordData) {
954
+ if (this.recordData.hasOwnProperty(fieldCode)) {
955
+ for (const word of words) {
956
+ const term = word.toUpperCase();
957
+ const fieldValue = this.recordData[fieldCode];
958
+ if (fieldValue.toString().toUpperCase().includes(term)) {
959
+ return true;
960
+ }
961
+ }
962
+ }
1248
963
  }
964
+ return false;
1249
965
  }
1250
- get value() { return this.getValue(); }
1251
- set value(newValue) { this.setValue(newValue); }
1252
- notifyEditionPartial() {
1253
- const intrinsicValidation = true;
1254
- this._editionPartial.next({ code: this.fieldCode, intrinsicValidation });
966
+ hasCondition(columnFilters) {
967
+ if (!columnFilters || columnFilters.length === 0) {
968
+ return true;
969
+ }
970
+ for (const condition of columnFilters) {
971
+ const { fieldCode, operator, values } = condition;
972
+ if (this.recordData.hasOwnProperty(fieldCode)) {
973
+ const fieldValue = this.recordData[fieldCode];
974
+ const stringValue = fieldValue.toString().toUpperCase();
975
+ if (operator === operators.G && fieldValue <= values[0]) {
976
+ return false;
977
+ }
978
+ if (operator === operators.L && fieldValue >= values[0]) {
979
+ return false;
980
+ }
981
+ if (operator === operators.GE && fieldValue < values[0]) {
982
+ return false;
983
+ }
984
+ if (operator === operators.LE && fieldValue > values[0]) {
985
+ return false;
986
+ }
987
+ if (operator === operators.IN && !values.include(fieldValue)) {
988
+ return false;
989
+ }
990
+ if (operator === operators.EQ) {
991
+ return fieldValue === values[0];
992
+ }
993
+ if (operator === operators.NOT_EQ && fieldValue === values[0]) {
994
+ return false;
995
+ }
996
+ if (operator === operators.CONTENT && !stringValue.includes(values[0].toString().toUpperCase())) {
997
+ return false;
998
+ }
999
+ if (operator === operators.NOT_CONTENT && stringValue.includes(values[0].toString().toUpperCase())) {
1000
+ return false;
1001
+ }
1002
+ if (operator === operators.BETWEEN && (fieldValue < values[0] || fieldValue > values[1])) {
1003
+ return false;
1004
+ }
1005
+ }
1006
+ }
1007
+ return true;
1255
1008
  }
1256
- notifyEditionFinish() {
1257
- var _a, _b, _c, _d, _e;
1258
- let intrinsicValidation = true;
1259
- const fieldDefaultFormat = (_b = (_a = this._formConfig.fieldTypesPatterns) === null || _a === void 0 ? void 0 : _a[this.fieldType]) !== null && _b !== void 0 ? _b : null;
1260
- const fieldValue = this.getValue();
1261
- if (fieldValue && (fieldDefaultFormat || this.fieldFormat)) {
1262
- intrinsicValidation = ((_c = fieldDefaultFormat === null || fieldDefaultFormat === void 0 ? void 0 : fieldDefaultFormat.test(fieldValue)) !== null && _c !== void 0 ? _c : true)
1263
- && ((_e = (_d = this.fieldFormat) === null || _d === void 0 ? void 0 : _d.test(fieldValue)) !== null && _e !== void 0 ? _e : true);
1264
- if (!intrinsicValidation) {
1265
- this.setError('99', this._intrinsicErrorMessage);
1009
+ }
1010
+
1011
+ const TABLE_SORT_ASCENDING = 'asc';
1012
+ const TABLE_SORT_DESCENDING = 'desc';
1013
+ class RecordTable extends FormElement {
1014
+ constructor(tableReceived, formConfig) {
1015
+ var _a, _b, _c, _d, _e, _f;
1016
+ super(tableReceived, formConfig);
1017
+ this._inlineActionTrigger = new Subject();
1018
+ this._globalActionTrigger = new Subject();
1019
+ this._recordSelectionTrigger = new Subject();
1020
+ this._selectionActionTrigger = new Subject();
1021
+ this._getDataTrigger = new Subject();
1022
+ this._attributeChange = new Subject();
1023
+ this._tableColumnObj = {};
1024
+ this._actionsObj = {};
1025
+ // Mecanismos de filtrado nueva versión
1026
+ this.globalFilterStrings = [];
1027
+ this.tableRecordObj = {};
1028
+ this.allSelected = false;
1029
+ this.elementType = elementTypes.table;
1030
+ this.waiting = false;
1031
+ this.currentPage = 1;
1032
+ this.totalPages = 1;
1033
+ this.requestedPage = 1;
1034
+ this.columns = [];
1035
+ this._tableColumnObj = {};
1036
+ this._actions = [];
1037
+ this._actionsObj = {};
1038
+ this.tableRecords = [];
1039
+ this.globalSearch = false;
1040
+ this.tableTitle = tableReceived.tableTitle;
1041
+ this._appendPages = (_a = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.append) !== null && _a !== void 0 ? _a : false;
1042
+ this.selectable = (_b = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectable) !== null && _b !== void 0 ? _b : false;
1043
+ this.setAttr('allSelected', false);
1044
+ this.setAttr('tableCode', tableReceived.tableCode);
1045
+ this.setAttr('clientPaging', (_c = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.clientPaging) !== null && _c !== void 0 ? _c : true);
1046
+ this.setAttr('globalSearch', (_d = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.simpleFilter) !== null && _d !== void 0 ? _d : false);
1047
+ this.setAttr('selectionBackend', (_e = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectionBackend) !== null && _e !== void 0 ? _e : false);
1048
+ this.setAttr('sortable', (_f = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.sortable) !== null && _f !== void 0 ? _f : false);
1049
+ this.setAttr('sorting', { columnName: '', direction: '' });
1050
+ this.setAttr('recordsPerPage', formConfig.defaultRecordsPerPage);
1051
+ if (tableReceived.fields) {
1052
+ const columns = [];
1053
+ for (const columnReceived of tableReceived.fields) {
1054
+ const columnDefinition = new RecordTableColumn(columnReceived, this._formConfig);
1055
+ columns.push(columnDefinition);
1056
+ this._tableColumnObj[columnDefinition.fieldCode] = columnDefinition;
1266
1057
  }
1058
+ this.setAttr('columns', columns);
1267
1059
  }
1268
- if (intrinsicValidation && fieldValue && this._minValue && fieldValue < this._minValue) {
1269
- intrinsicValidation = false;
1270
- this.setError('99', 'Campo con valor inferior al mínimo');
1060
+ if (tableReceived.actions) {
1061
+ const tableActions = tableReceived.actions.map(objDef => {
1062
+ let visibleStates = objDef.visibleStates;
1063
+ let enabledStates = objDef.enabledStates;
1064
+ if (!visibleStates) {
1065
+ visibleStates = (objDef.actionModes || '').split(',')
1066
+ .map(state => state.trim())
1067
+ .filter(state => state.length > 0);
1068
+ enabledStates = (objDef.actionModes || '').split(',')
1069
+ .map(state => state.trim())
1070
+ .filter(state => state.length > 0);
1071
+ }
1072
+ return Object.assign(Object.assign({}, objDef), { visibleStates, enabledStates });
1073
+ });
1074
+ for (const actionReceived of tableActions) {
1075
+ const inlineAction = new TableAction(actionReceived);
1076
+ this._actions.push(inlineAction);
1077
+ this._actionsObj[inlineAction.actionCode] = inlineAction;
1078
+ }
1271
1079
  }
1272
- if (intrinsicValidation && fieldValue && this._maxValue && fieldValue > this._maxValue) {
1273
- intrinsicValidation = false;
1274
- this.setError('99', 'Campo con valor superior al máximo');
1080
+ this.selectionField = (this.selectable) ? tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectionField : null;
1081
+ // Filtros predefinidos en el formulario
1082
+ if (tableReceived.filters) {
1083
+ for (let index = 0; index < tableReceived.filters.length; index++) {
1084
+ this.addFilterDefinition(tableReceived.filters[index]);
1085
+ }
1275
1086
  }
1276
- this._editionFinish.next({ code: this.fieldCode, intrinsicValidation });
1277
1087
  }
1088
+ get columnNames() { return Object.keys(this._tableColumnObj); }
1089
+ get inlineActionTrigger() { return this._inlineActionTrigger; }
1090
+ get globalActionTrigger() { return this._globalActionTrigger; }
1091
+ get selectionActionTrigger() { return this._selectionActionTrigger; }
1092
+ get recordSelectionTrigger() { return this._recordSelectionTrigger; }
1093
+ get getDataTrigger() { return this._getDataTrigger; }
1094
+ get attributeChange() { return this._attributeChange; }
1095
+ hasActions() { return (this._actions.length > 0); }
1096
+ getSelectedRecords() { return this.tableRecords.filter(rec => rec.selected).map(rec => rec.recordId); }
1097
+ activateGlobalSearch() { this.globalSearch = true; }
1098
+ inactivateGlobalSearch() { this.globalSearch = false; }
1099
+ columnDefinition(fieldCode) { return this._tableColumnObj[fieldCode]; }
1100
+ putOnWait() { this.waiting = true; }
1101
+ freeWaiting() { this.waiting = false; }
1278
1102
  setAttr(name, value) {
1279
1103
  this[name] = value;
1280
- if (this._formConfig.monitoredFieldAttributes.includes(name)) {
1104
+ if (this._formConfig.monitoredTableAttributes.includes(name)) {
1281
1105
  this._attributeChange.next({ name, value });
1282
1106
  }
1283
1107
  }
1284
- notifyEditionDetailRequest(detail) {
1285
- const detailEvent = {
1286
- code: this.fieldCode,
1287
- detail,
1108
+ notifyGlobalAction(actionCode) {
1109
+ const tableEvent = {
1110
+ tableCode: this.tableCode,
1111
+ actionCode,
1112
+ actionDetail: null
1113
+ };
1114
+ this._globalActionTrigger.next(tableEvent);
1115
+ }
1116
+ notifyInlineAction(tableActionEvent) {
1117
+ const tableEvent = {
1118
+ tableCode: this.tableCode,
1119
+ actionCode: tableActionEvent.actionCode,
1120
+ actionDetail: {
1121
+ recordId: tableActionEvent.recordId,
1122
+ recordData: tableActionEvent.recordData
1123
+ }
1124
+ };
1125
+ this._inlineActionTrigger.next(tableEvent);
1126
+ }
1127
+ notifyRecordSelection(recordId) {
1128
+ const record = this.getTableRecord(recordId);
1129
+ if (!record) {
1130
+ return;
1131
+ }
1132
+ record.toggleSelect();
1133
+ const tableEvent = {
1134
+ tableCode: this.tableCode,
1135
+ actionCode: null,
1136
+ actionDetail: {
1137
+ recordId: record.recordId,
1138
+ recordData: record.recordData
1139
+ }
1140
+ };
1141
+ this.recordSelectionTrigger.next(tableEvent);
1142
+ }
1143
+ notifySelectionAction(actionCode) {
1144
+ const tableEvent = {
1145
+ tableCode: this.tableCode,
1146
+ actionCode,
1147
+ actionDetail: {
1148
+ selectedRecords: this.selectedRecords
1149
+ }
1150
+ };
1151
+ this._selectionActionTrigger.next(tableEvent);
1152
+ }
1153
+ notifyGetDataAction(requestedPage = null) {
1154
+ this.updateVisibleRecords();
1155
+ this.requestedPage = requestedPage || this.currentPage;
1156
+ const tableEvent = {
1157
+ tableCode: this.tableCode,
1158
+ actionCode: null,
1159
+ actionDetail: null,
1288
1160
  };
1289
- this._detailRequest.next(detailEvent);
1161
+ this._getDataTrigger.next(tableEvent);
1162
+ return null;
1290
1163
  }
1291
- setVisibleLabel(visibleLabel) { this.setAttr(fldAttr.visibleLabel, visibleLabel); }
1292
- showLabel() { this.setVisibleLabel(true); }
1293
- hideLabel() { this.setVisibleLabel(false); }
1294
- setChanged(hasChanged) { this.setAttr(fldAttr.hasChanged, hasChanged); }
1295
- changed() { this.setChanged(true); }
1296
- setLabel(label) { this.setAttr(fldAttr.title, label); }
1297
- clean() { this.setValue(this.defaultValue || ''); this.resetError(); }
1298
- get backend() { return this.validateOnServer; }
1299
- setEditable(editable = true) { (editable) ? this.enable() : this.disable(); }
1300
- hasError() { return this.errorCode !== NO_ERROR; }
1301
- resetError() { (this.errorCode !== NO_ERROR) && this.setError(NO_ERROR, null); }
1302
- setError(code, message, type = DEFAULT_ERROR_TYPE) {
1303
- this.setAttr(fldAttr.errorCode, code !== null && code !== void 0 ? code : NO_ERROR);
1304
- this.setAttr(fldAttr.errorType, (this.errorCode === NO_ERROR) ? '' : type);
1305
- this.setAttr(fldAttr.errorMessage, message !== null && message !== void 0 ? message : '');
1164
+ clean() {
1165
+ this.visibleRecords = [];
1166
+ this.tableRecords = [];
1167
+ this.unSelectAll();
1168
+ this.tableRecordObj = {};
1306
1169
  }
1307
- getError() { return { type: this.errorType, code: this.errorCode, message: this.errorMessage }; }
1308
- get error() { return this.getError(); }
1309
- set error(errorObj) { var _a; this.setError(errorObj.code, errorObj.message, (_a = errorObj.type) !== null && _a !== void 0 ? _a : DEFAULT_ERROR_TYPE); }
1310
- getErrorCode() { return this.getError().code; }
1311
- setErrorCode(code) { this.setError(code, this.errorMessage); }
1312
- getErrorMessage() { return this.getError().message; }
1313
- setErrorMessage(msg) { this.setError(this.errorCode, msg); }
1314
- get empty() { return this.isEmpty(); }
1315
- isEmpty() {
1316
- const fieldCurrentValue = this.getValue();
1317
- if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
1318
- return true;
1170
+ selectAll() {
1171
+ this.setAttr('allSelected', true);
1172
+ this.tableRecords.forEach(record => record.select());
1173
+ this.setAttr('selectedRecords', this.getSelectedRecords());
1174
+ return true;
1175
+ }
1176
+ unSelectAll() {
1177
+ this.setAttr('allSelected', false);
1178
+ this.tableRecords.forEach(record => record.unselect());
1179
+ this.setAttr('selectedRecords', this.getSelectedRecords());
1180
+ return true;
1181
+ }
1182
+ setTableRecords(tableRecords, append) {
1183
+ if (!append) {
1184
+ this.clean();
1319
1185
  }
1320
- if ((this.fieldType === this._formConfig.fieldTypes.array || this.fieldType === this._formConfig.fieldTypes.phone)
1321
- && Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
1322
- return true;
1186
+ const newRecordsObj = Object.assign({}, this.tableRecordObj);
1187
+ const newRecords = [...this.tableRecords];
1188
+ for (const tableRecord of tableRecords) {
1189
+ const recordReceived = new TableRecordData(tableRecord, this.columns, this.selectionField);
1190
+ const recordIdKey = recordReceived.recordIdKey;
1191
+ newRecords.push(recordReceived);
1192
+ newRecordsObj[recordIdKey] = recordReceived;
1323
1193
  }
1324
- ;
1325
- return fieldCurrentValue === '';
1194
+ this.tableRecords = newRecords;
1195
+ this.setAttr('selectedRecords', this.getSelectedRecords());
1196
+ this.tableRecordObj = newRecordsObj;
1197
+ this.updateVisibleRecords();
1326
1198
  }
1327
- getValue() {
1328
- if (this.fieldType === this._formConfig.fieldTypes.boolean
1329
- || this.fieldType === this._formConfig.fieldTypes.check) {
1330
- return yn(this._value);
1199
+ appendRecords(records) { this.setTableRecords(records, true); }
1200
+ replaceRecords(records) { this.setTableRecords(records, false); }
1201
+ updateVisibleRecords() {
1202
+ var _a;
1203
+ if (!this.clientPaging || !this.tableRecords || ((_a = this.tableRecords) === null || _a === void 0 ? void 0 : _a.length) === 0) {
1204
+ this.setAttr('visibleRecords', this.tableRecords);
1205
+ }
1206
+ else {
1207
+ this.setAttr('visibleRecords', this.getFilteredRecords());
1331
1208
  }
1332
- return this._value;
1333
- }
1334
- getOptionText() {
1335
- var _a, _b, _c;
1336
- return (_c = (_b = (_a = this.fieldOptions) === null || _a === void 0 ? void 0 : _a.find(item => item.fieldOptionId === this._value)) === null || _b === void 0 ? void 0 : _b.fieldOptionValue) !== null && _c !== void 0 ? _c : null;
1337
1209
  }
1338
- updateFromServer(fld) {
1210
+ updateFromServer(tableReceived) {
1339
1211
  var _a;
1340
- const fieldKeys = Object.keys(fld);
1341
- for (let index = 0; index < fieldKeys.length; index++) {
1342
- const attrName = fieldKeys[index];
1343
- const attrValue = fld[attrName];
1344
- (attrName === this._formConfig.apiFieldAttrs.visible) && this.setVisibility(attrValue);
1345
- (attrName === this._formConfig.apiFieldAttrs.labelVisible) && this.setVisibleLabel(fld.visibleLabel);
1346
- (attrName === this._formConfig.apiFieldAttrs.required) && this.setAttr(fldAttr.required, (_a = fld.required) !== null && _a !== void 0 ? _a : false);
1347
- (attrName === this._formConfig.apiFieldAttrs.errorCode) && this.setAttr(fldAttr.errorCode, fld.errorCode);
1348
- (attrName === this._formConfig.apiFieldAttrs.errorMessage) && this.setAttr(fldAttr.errorMessage, fld.errorMessage);
1349
- (attrName === this._formConfig.apiFieldAttrs.tooltip) && this.setAttr(fldAttr.tooltipText, fld.tooltip);
1350
- (attrName === this._formConfig.apiFieldAttrs.info) && this.setAttr(fldAttr.info, fld.info);
1351
- (attrName === this._formConfig.apiFieldAttrs.editable) && this.setEditable(fld.editable);
1352
- (attrName === this._formConfig.apiFieldAttrs.title) && this.setLabel(fld.fieldTitle.toString());
1353
- (attrName === this._formConfig.apiFieldAttrs.value) && (this.setValue(fld.fieldValue) && this.setChanged(false));
1354
- (attrName === this._formConfig.apiFieldAttrs.options) && this.setFieldOptions(fld.fieldOptions);
1355
- (attrName === this._formConfig.apiFieldAttrs.captureType) && this.setAttr(fldAttr.captureType, fld.captureType || 'INPUT');
1356
- (attrName === this._formConfig.apiFieldAttrs.type) && this.setFieldType(fld.fieldTypeCode);
1357
- (attrName === this._formConfig.apiFieldAttrs.maxLength) && this.setAttr(fldAttr.maxLength, fld.maxLength);
1212
+ this.requestedPage = 1;
1213
+ this.clean();
1214
+ this.visible = (tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.visible) || true;
1215
+ this.totalPages = tableReceived.totalPages || 1;
1216
+ this.recordsNumber = tableReceived.recordsNumber;
1217
+ this.setAttr('currentPage', (_a = +(tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.currentPage)) !== null && _a !== void 0 ? _a : 1);
1218
+ this.setAttr('recordsPerPage', +tableReceived.recordsPerPage);
1219
+ this.setAttr('totalRecordsNumber', +tableReceived.totalRecordsNumber);
1220
+ this.setAttr('sorting', {
1221
+ columnName: tableReceived.sortingColumn || '',
1222
+ direction: tableReceived.sortingDirection || ''
1223
+ });
1224
+ this.waiting = false;
1225
+ if (this._appendPages) {
1226
+ this.replaceRecords(tableReceived.tableRecords);
1358
1227
  }
1359
- }
1360
- setFieldType(inputFieldType) {
1361
- this.setAttr(fldAttr.type, inputFieldType);
1362
- }
1363
- setMinValue(inputMinValue) {
1364
- let minValue = inputMinValue;
1365
- if (this.fieldType === this._formConfig.fieldTypes.date) {
1366
- minValue = new Date(minValue);
1228
+ else {
1229
+ this.appendRecords(tableReceived.tableRecords);
1367
1230
  }
1368
- this.setAttr(fldAttr.minValue, minValue);
1231
+ this.updateVisibleRecords();
1369
1232
  }
1370
- setMaxValue(inputMaxValue) {
1371
- let maxValue = inputMaxValue;
1372
- if (this.fieldType === this._formConfig.fieldTypes.date) {
1373
- maxValue = new Date(maxValue);
1374
- }
1375
- this.setAttr(fldAttr.maxValue, maxValue);
1233
+ getTableRecord(recordId) {
1234
+ const recordIdKey = (typeof recordId === 'object') ? JSON.stringify(recordId) : recordId;
1235
+ return (this.tableRecordObj && recordId && this.tableRecordObj[recordId])
1236
+ ? this.tableRecordObj[recordId] : null;
1376
1237
  }
1377
- getFieldOptions() {
1378
- return this.fieldOptions.map(option => {
1379
- const optionCopy = Object.assign({}, option);
1380
- return optionCopy;
1238
+ getAction(actionCode) {
1239
+ return (this._actionsObj && actionCode && this._actionsObj[actionCode])
1240
+ ? this._actionsObj[actionCode] : null;
1241
+ }
1242
+ getActions(actionClass = this._formConfig.tableActions.inline, actionTypes = null) {
1243
+ return this._actions.filter(actionDef => {
1244
+ const typeIncluded = (actionTypes) ? actionTypes.includes(actionDef.actionType) : true;
1245
+ return actionDef.actionClass === actionClass && typeIncluded;
1381
1246
  });
1382
1247
  }
1383
- setFieldOptions(newOptions) {
1248
+ // Filtros
1249
+ setGlobalFilterString(text) {
1384
1250
  var _a;
1385
- if ((this.captureType !== 'LIST' && this.captureType !== 'RADIO')
1386
- || typeof newOptions === UNDEFINED || !newOptions
1387
- || !Array.isArray(newOptions)) {
1388
- return;
1389
- }
1390
- let fieldOptions = newOptions.map(option => {
1391
- if (option.text !== undefined && option.text !== null
1392
- && option.value !== undefined && option.value !== null) {
1393
- return { fieldOptionValue: option.text, fieldOptionId: option.value };
1394
- }
1395
- return Object.assign({}, option);
1396
- });
1397
- fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
1398
- && fieldOptions.length > 0) ? fieldOptions : [];
1399
- this.setAttr(fldAttr.options, fieldOptions);
1400
- if (this._value) {
1401
- if (this.fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
1402
- const fieldValue = (_a = this._value) === null || _a === void 0 ? void 0 : _a.filter(item => this.fieldOptions.find(opt => opt.fieldOptionId === item));
1403
- this.setAttr(fldAttr.value, fieldValue);
1404
- }
1405
- else {
1406
- const valInOptions = this.fieldOptions
1407
- .find(item => item.fieldOptionId === this._value);
1408
- if (!valInOptions) {
1409
- this.setValue('');
1410
- }
1411
- }
1251
+ this.globalFilterStrings = (_a = text.split(' ').filter(t => t && t.trim().length > 0).map(t => t.trim())) !== null && _a !== void 0 ? _a : [];
1252
+ }
1253
+ addFilterDefinition(filterDefinition) {
1254
+ const tableColumn = this.columnDefinition(filterDefinition.fieldCode);
1255
+ tableColumn && tableColumn.addFilterDefinition(filterDefinition);
1256
+ }
1257
+ getFilteredRecords() {
1258
+ let filteredRecords = this.tableRecords;
1259
+ if (this.globalFilterStrings.length > 0) {
1260
+ filteredRecords = filteredRecords.filter(record => record.hasPattern(this.globalFilterStrings));
1412
1261
  }
1413
- if (this.fieldRequired && this.fieldOptions.length === 1) {
1414
- this.setValue(this.fieldOptions[0].fieldOptionId);
1262
+ const columnFilters = this.columns.filter(column => column.filter).map(column => column.filter);
1263
+ if (columnFilters.length > 0) {
1264
+ filteredRecords = filteredRecords.filter(record => record.hasCondition(columnFilters));
1415
1265
  }
1266
+ return filteredRecords;
1416
1267
  }
1417
- setValue(newValue, widgetUpdate = true) {
1418
- if (typeof newValue === UNDEFINED || newValue === null) {
1419
- return true;
1268
+ addColumnFilter(columnName, columnValues, operator = null) {
1269
+ var _a;
1270
+ const tableColumn = this.columnDefinition(columnName);
1271
+ const columnFilterDefinition = (_a = tableColumn === null || tableColumn === void 0 ? void 0 : tableColumn.filterDefinition) !== null && _a !== void 0 ? _a : null;
1272
+ if (!columnFilterDefinition) {
1273
+ return null;
1420
1274
  }
1421
- let newFinalValue;
1422
- if (this.fieldType === this._formConfig.fieldTypes.boolean
1423
- || this.fieldType === this._formConfig.fieldTypes.check) {
1424
- newFinalValue = yn(newValue);
1275
+ tableColumn && tableColumn.addFilter(columnValues, operator);
1276
+ this.updateVisibleRecords();
1277
+ }
1278
+ removeColumnFilter(columnName) {
1279
+ const tableColumn = this.columnDefinition(columnName);
1280
+ tableColumn && tableColumn.removeFilter();
1281
+ this.updateVisibleRecords();
1282
+ }
1283
+ get currentFilter() {
1284
+ const compactFilter = {
1285
+ simpleFilterWords: this.globalFilterStrings,
1286
+ advancedFilter: [],
1287
+ };
1288
+ const columnFilters = this.columns.filter(column => column.filter).map(column => column.filter);
1289
+ for (let index = 0; index < columnFilters.length; index++) {
1290
+ const columnFilter = columnFilters[index];
1291
+ compactFilter.advancedFilter.push({
1292
+ fieldCode: columnFilter.fieldCode,
1293
+ operator: columnFilter.operator,
1294
+ fieldValue1: columnFilter.values[0],
1295
+ fieldValue2: columnFilter.values[1],
1296
+ });
1425
1297
  }
1426
- else if (this.fieldType === this._formConfig.fieldTypes.array
1427
- || this.fieldType === this._formConfig.fieldTypes.map) {
1428
- if (newValue === null || newValue === '') {
1429
- newFinalValue = [];
1430
- }
1431
- else if (Array.isArray(newValue)) {
1432
- newFinalValue = newValue;
1433
- }
1434
- else {
1435
- newFinalValue = newValue.toString().split(',');
1436
- }
1298
+ return compactFilter;
1299
+ }
1300
+ // Ordenamiento de registros local
1301
+ setRequiredOrder(columnField) {
1302
+ if (columnField !== this.sorting.columnName) {
1303
+ this.setAttr('sorting', {
1304
+ columnName: columnField,
1305
+ direction: TABLE_SORT_ASCENDING
1306
+ });
1437
1307
  }
1438
1308
  else {
1439
- newFinalValue = newValue;
1309
+ const tableSort = this.sorting;
1310
+ tableSort.direction = (tableSort.direction === TABLE_SORT_ASCENDING) ? TABLE_SORT_DESCENDING : TABLE_SORT_ASCENDING;
1311
+ this.setAttr('sorting', tableSort);
1440
1312
  }
1441
- if (this._value !== newFinalValue) {
1442
- this.setChanged(true);
1443
- if (widgetUpdate) {
1444
- this.setAttr(fldAttr.value, newFinalValue);
1445
- }
1446
- else {
1447
- this._value = newFinalValue;
1448
- }
1313
+ }
1314
+ localSortData() {
1315
+ if (!this.sorting.columnName || !this.sorting.direction) {
1316
+ return;
1449
1317
  }
1450
- return true;
1318
+ this.tableRecords.sort((a, b) => this.recordCompare(a, b, this.sorting.columnName, this.sorting.direction));
1319
+ this.unSelectAll();
1320
+ this.updateVisibleRecords();
1321
+ }
1322
+ recordCompare(recordA, recordB, columnCompare, direction) {
1323
+ const recordAColumn = recordA.getFieldValue(columnCompare);
1324
+ const recordBColumn = recordB.getFieldValue(columnCompare);
1325
+ let result = 0;
1326
+ if (recordAColumn < recordBColumn) {
1327
+ result = -1;
1328
+ }
1329
+ else if (recordAColumn > recordBColumn) {
1330
+ result = 1;
1331
+ }
1332
+ return direction === TABLE_SORT_ASCENDING ? result : -result;
1451
1333
  }
1452
1334
  }
1453
1335
 
@@ -3562,7 +3444,6 @@ const COMPONENTS = [
3562
3444
  FormHeaderComponent,
3563
3445
  SectionComponent,
3564
3446
  SubSectionComponent,
3565
- LibTableFilterComponent,
3566
3447
  LibTableRecordActionComponent,
3567
3448
  LibTableRecordFieldComponent,
3568
3449
  LibTableComponent
@@ -3585,5 +3466,5 @@ TuainNgFormsLibModule.decorators = [
3585
3466
  * Generated bundle index. Do not edit.
3586
3467
  */
3587
3468
 
3588
- export { ActionComponent, BasicFormComponent, ElementComponent, FieldComponent, FormErrorComponent, FormHeaderComponent, LibEventManagerService, LibFileManagementService, LibFormManagerService, LibTableComponent, LibTableFilterComponent, LibTableRecordActionComponent, LibTableRecordFieldComponent, SectionComponent, SubSectionComponent, TuainNgFormsLibModule };
3469
+ export { ActionComponent, BasicFormComponent, ElementComponent, FieldComponent, FormErrorComponent, FormHeaderComponent, LibEventManagerService, LibFileManagementService, LibFormManagerService, LibTableComponent, LibTableRecordActionComponent, LibTableRecordFieldComponent, SectionComponent, SubSectionComponent, TuainNgFormsLibModule };
3589
3470
  //# sourceMappingURL=tuain-ng-forms-lib.js.map