tuain-ng-forms-lib 12.0.52 → 12.0.57

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