tailjng 0.0.31 → 0.0.33

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.
@@ -27,7 +27,7 @@ Authors:
27
27
  License:
28
28
  This project is licensed under the BSD 3-Clause - see the LICENSE file for more details.
29
29
 
30
- Version: 0.0.31
30
+ Version: 0.0.33
31
31
  Creation Date: 2025-01-04
32
32
  ===============================================`
33
33
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailjng",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^19.2.0",
6
6
  "@angular/core": "^19.2.0",
@@ -1,4 +1,4 @@
1
- import { Component, forwardRef, Input } from '@angular/core';
1
+ import { Component, forwardRef, Input, OnChanges, SimpleChanges } from '@angular/core';
2
2
  import { CommonModule } from '@angular/common';
3
3
  import { LucideAngularModule } from 'lucide-angular';
4
4
  import { JIconsService } from 'tailjng';
@@ -6,6 +6,7 @@ import { FormsModule, NG_VALUE_ACCESSOR, ReactiveFormsModule, ControlValueAccess
6
6
 
7
7
  @Component({
8
8
  selector: 'JInputCheckbox',
9
+ standalone: true,
9
10
  imports: [CommonModule, LucideAngularModule, FormsModule, ReactiveFormsModule],
10
11
  templateUrl: './input-checkbox.component.html',
11
12
  styleUrls: ['./input-checkbox.component.css'],
@@ -17,7 +18,7 @@ import { FormsModule, NG_VALUE_ACCESSOR, ReactiveFormsModule, ControlValueAccess
17
18
  }
18
19
  ]
19
20
  })
20
- export class JInputCheckboxComponent implements ControlValueAccessor {
21
+ export class JInputCheckboxComponent implements OnChanges, ControlValueAccessor {
21
22
 
22
23
  @Input() title!: string;
23
24
  @Input() icon: any;
@@ -29,20 +30,23 @@ export class JInputCheckboxComponent implements ControlValueAccessor {
29
30
  @Input() column: any;
30
31
 
31
32
  @Input() getValue: (item: any, column: any) => boolean = () => false;
32
- @Input() onCheckboxChange: (item: any, column: any) => void = () => { };
33
+ @Input() onCheckboxChange: (item: any, column: any, value: boolean) => void = () => { };
33
34
 
34
- // ControlValueAccessor methods
35
+ innerValue: boolean = false;
35
36
  onChange: any = () => { };
36
37
  onTouched: any = () => { };
37
38
 
38
- innerValue: boolean = false;
39
-
40
- constructor(
41
- public readonly iconsService: JIconsService
42
- ) {
39
+ constructor(public readonly iconsService: JIconsService) {
43
40
  this.icon = this.iconsService.icons.check;
44
41
  }
45
42
 
43
+ ngOnChanges(changes: SimpleChanges): void {
44
+ if ((changes['item'] || changes['column']) && this.item && this.column) {
45
+ this.innerValue = this.getValue(this.item, this.column);
46
+ this.onChange(this.innerValue);
47
+ }
48
+ }
49
+
46
50
 
47
51
  /**
48
52
  * writeValue - To write a value to the component
@@ -50,7 +54,9 @@ export class JInputCheckboxComponent implements ControlValueAccessor {
50
54
  */
51
55
  writeValue(value: any): void {
52
56
  if (value !== undefined) {
53
- this.innerValue = value;
57
+ this.innerValue = !!value;
58
+ } else if (this.item && this.column) {
59
+ this.innerValue = this.getValue(this.item, this.column);
54
60
  }
55
61
  }
56
62
 
@@ -60,7 +66,7 @@ export class JInputCheckboxComponent implements ControlValueAccessor {
60
66
  * registerOnChange - To register the change callback function
61
67
  * @param fn
62
68
  */
63
- registerOnChange(fn: (value: any) => void): void {
69
+ registerOnChange(fn: any): void {
64
70
  this.onChange = fn;
65
71
  }
66
72
 
@@ -70,7 +76,7 @@ export class JInputCheckboxComponent implements ControlValueAccessor {
70
76
  * registerOnTouched - To register the touched callback function
71
77
  * @param fn
72
78
  */
73
- registerOnTouched(fn: () => void): void {
79
+ registerOnTouched(fn: any): void {
74
80
  this.onTouched = fn;
75
81
  }
76
82
 
@@ -80,14 +86,14 @@ export class JInputCheckboxComponent implements ControlValueAccessor {
80
86
  * onCheckboxChangeHandler - To handle the checkbox change event
81
87
  * @param event
82
88
  */
83
- onCheckboxChangeHandler(event: Event): void {
89
+ onCheckboxChangeHandler(event: Event) {
84
90
  const target = event.target as HTMLInputElement;
85
91
  const newValue = target.checked;
86
92
 
87
93
  this.innerValue = newValue;
88
94
 
89
95
  if (this.onCheckboxChange) {
90
- this.onCheckboxChange(this.item, this.column);
96
+ this.onCheckboxChange(this.item, this.column, newValue);
91
97
  }
92
98
 
93
99
  this.onChange(newValue);
@@ -413,11 +413,10 @@
413
413
  <JInputCheckbox
414
414
  [item]="group"
415
415
  [column]="column"
416
- [getValue]="getValue.bind(this)"
417
- [onCheckboxChange]="onCheckboxChange.bind(this)"
416
+ [getValue]="getValue.bind(this)"
417
+ [onCheckboxChange]="onCheckboxChange.bind(this)"
418
418
  [iconSize]="20"
419
419
  [disabled]="column?.isDisabled ?? false"
420
- [(ngModel)]="group[column.key]"
421
420
  />
422
421
  }
423
422
 
@@ -381,29 +381,53 @@ export class JCompleteCrudTableComponent implements OnInit {
381
381
  // =====================================================
382
382
  // Change state in boolean fields
383
383
  // =====================================================
384
-
385
- // MMethod to change the state of a checkbox
386
384
  onCheckboxChange(item: any, column: TableColumn<any>) {
387
385
 
388
- // Get the ID field name based on dataProperty
389
- const idField = `id_${this.mainEndpoint}`;
386
+ let key = column.key;
387
+ let recordId: any;
388
+ let endpoint = this.mainEndpoint;
389
+
390
+ // Verificar si es key compuesta
391
+ if (key.includes('.')) {
392
+ const parts = key.split('.');
393
+ const parent = parts[0];
394
+ const lastKey = parts[parts.length - 1];
390
395
 
391
- // Get the record ID
392
- const recordId = item[idField];
396
+ key = lastKey;
397
+
398
+ // El id corresponde a la tabla padre
399
+ recordId = item[`id_${parent}`];
400
+
401
+ // El endpoint también debe ser la tabla padre
402
+ endpoint = parent;
403
+ } else {
404
+ // key simple
405
+ recordId = item[`id_${this.mainEndpoint}`];
406
+ }
393
407
 
394
- // Get the current boolean value
408
+ // Obtener el valor actual
395
409
  const currentValue = this.getValue(item, column);
396
410
 
397
411
  const formData: EnableBoolean<any> = {
398
- key: column.key,
412
+ key: key,
399
413
  value: currentValue,
400
414
  values: [currentValue, !currentValue]
401
- }
415
+ };
402
416
 
403
- // Update state
404
- this.genericService.enable<any>({ endpoint: this.mainEndpoint, id: recordId, data: formData }).subscribe({
417
+ // Llamar al servicio
418
+ this.genericService.enable<any>({ endpoint, id: recordId, data: formData }).subscribe({
405
419
  next: (response) => {
406
- item[column.key] = !currentValue;
420
+ // Actualizar localmente el valor
421
+ if (column.key.includes('.')) {
422
+ const parts = column.key.split('.');
423
+ const parent = parts[0];
424
+ const lastKey = parts[parts.length - 1];
425
+
426
+ // Actualizar objeto anidado
427
+ item[parent] = { ...item[parent], [lastKey]: !currentValue };
428
+ } else {
429
+ item[key] = !currentValue;
430
+ }
407
431
 
408
432
  this.alertToastService.AlertToast({
409
433
  type: "success",
@@ -411,7 +435,7 @@ export class JCompleteCrudTableComponent implements OnInit {
411
435
  description: response.msg,
412
436
  });
413
437
  }
414
- })
438
+ });
415
439
  }
416
440
 
417
441
  // Change active or inactive
@@ -874,7 +898,7 @@ export class JCompleteCrudTableComponent implements OnInit {
874
898
  return copy;
875
899
  }
876
900
 
877
- // MMethod to save the editing of the item
901
+ // Method to save the editing of the item
878
902
  onSaveRow(item: any): void {
879
903
 
880
904
  // Get the name of the entity's id