@codex-ts/core-lib 1.0.0 → 1.0.1

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.
Files changed (77) hide show
  1. package/{dist/core-lib/fesm2022/core-lib.mjs → fesm2022/codex-ts-core-lib.mjs} +1 -1
  2. package/fesm2022/codex-ts-core-lib.mjs.map +1 -0
  3. package/package.json +42 -63
  4. package/dist/core-lib/fesm2022/core-lib.mjs.map +0 -1
  5. package/ng-package.json +0 -7
  6. package/src/index.ts +0 -44
  7. package/src/lib/components/base-form.component.ts +0 -328
  8. package/src/lib/components/base-list-page.component.ts +0 -327
  9. package/src/lib/components/base-page.component.ts +0 -33
  10. package/src/lib/components/base-tabbed-form.component.ts +0 -345
  11. package/src/lib/components/formly/core-formly.module.ts +0 -34
  12. package/src/lib/components/formly/field.interface.ts +0 -15
  13. package/src/lib/components/formly/form-field.wrapper.ts +0 -94
  14. package/src/lib/components/formly/formly.constants.ts +0 -14
  15. package/src/lib/components/formly/primeng-formly.module.ts +0 -77
  16. package/src/lib/components/formly/types/checkbox.type.ts +0 -43
  17. package/src/lib/components/formly/types/date.type.ts +0 -88
  18. package/src/lib/components/formly/types/multiselect.type.ts +0 -61
  19. package/src/lib/components/formly/types/numeric-input.type.ts +0 -45
  20. package/src/lib/components/formly/types/radio.type.ts +0 -47
  21. package/src/lib/components/formly/types/select.type.ts +0 -54
  22. package/src/lib/components/formly/types/text-input.type.ts +0 -33
  23. package/src/lib/components/formly/types/textarea.type.ts +0 -37
  24. package/src/lib/constants/app.constants.ts +0 -15
  25. package/src/lib/constants/app.messages.ts +0 -36
  26. package/src/lib/enums/component-context.enum.ts +0 -6
  27. package/src/lib/enums/tabbed-form-type.enum.ts +0 -4
  28. package/src/lib/models/pagination/filter-criteria.interface.ts +0 -19
  29. package/src/lib/models/pagination/page-request.interface.ts +0 -13
  30. package/src/lib/models/pagination/page.interface.ts +0 -9
  31. package/src/lib/models/pagination/sort-criteria.interface.ts +0 -4
  32. package/src/lib/pipes/indian-date.pipe.ts +0 -46
  33. package/src/lib/services/base-crud.service.ts +0 -81
  34. package/src/lib/services/entity-registry.service.ts +0 -51
  35. package/src/lib/services/entity.service.ts +0 -10
  36. package/src/lib/services/enum-registry.service.ts +0 -66
  37. package/src/lib/services/formly-config.service.ts +0 -50
  38. package/src/lib/services/http-utility.service.example.ts +0 -253
  39. package/src/lib/services/http-utility.service.md +0 -175
  40. package/src/lib/services/http-utility.service.ts +0 -389
  41. package/src/lib/services/notification.service.ts +0 -35
  42. package/src/lib/services/reference-data-provider.service.ts +0 -28
  43. package/src/lib/services/utils.service.ts +0 -154
  44. /package/{dist/core-lib/index.d.ts → index.d.ts} +0 -0
  45. /package/{dist/core-lib/lib → lib}/components/base-form.component.d.ts +0 -0
  46. /package/{dist/core-lib/lib → lib}/components/base-list-page.component.d.ts +0 -0
  47. /package/{dist/core-lib/lib → lib}/components/base-page.component.d.ts +0 -0
  48. /package/{dist/core-lib/lib → lib}/components/base-tabbed-form.component.d.ts +0 -0
  49. /package/{dist/core-lib/lib → lib}/components/formly/core-formly.module.d.ts +0 -0
  50. /package/{dist/core-lib/lib → lib}/components/formly/form-field.wrapper.d.ts +0 -0
  51. /package/{dist/core-lib/lib → lib}/components/formly/formly.constants.d.ts +0 -0
  52. /package/{dist/core-lib/lib → lib}/components/formly/types/checkbox.type.d.ts +0 -0
  53. /package/{dist/core-lib/lib → lib}/components/formly/types/date.type.d.ts +0 -0
  54. /package/{dist/core-lib/lib → lib}/components/formly/types/multiselect.type.d.ts +0 -0
  55. /package/{dist/core-lib/lib → lib}/components/formly/types/numeric-input.type.d.ts +0 -0
  56. /package/{dist/core-lib/lib → lib}/components/formly/types/radio.type.d.ts +0 -0
  57. /package/{dist/core-lib/lib → lib}/components/formly/types/select.type.d.ts +0 -0
  58. /package/{dist/core-lib/lib → lib}/components/formly/types/text-input.type.d.ts +0 -0
  59. /package/{dist/core-lib/lib → lib}/components/formly/types/textarea.type.d.ts +0 -0
  60. /package/{dist/core-lib/lib → lib}/constants/app.constants.d.ts +0 -0
  61. /package/{dist/core-lib/lib → lib}/constants/app.messages.d.ts +0 -0
  62. /package/{dist/core-lib/lib → lib}/enums/component-context.enum.d.ts +0 -0
  63. /package/{dist/core-lib/lib → lib}/enums/tabbed-form-type.enum.d.ts +0 -0
  64. /package/{dist/core-lib/lib → lib}/models/pagination/filter-criteria.interface.d.ts +0 -0
  65. /package/{dist/core-lib/lib → lib}/models/pagination/page-request.interface.d.ts +0 -0
  66. /package/{dist/core-lib/lib → lib}/models/pagination/page.interface.d.ts +0 -0
  67. /package/{dist/core-lib/lib → lib}/models/pagination/sort-criteria.interface.d.ts +0 -0
  68. /package/{dist/core-lib/lib → lib}/pipes/indian-date.pipe.d.ts +0 -0
  69. /package/{dist/core-lib/lib → lib}/services/base-crud.service.d.ts +0 -0
  70. /package/{dist/core-lib/lib → lib}/services/entity-registry.service.d.ts +0 -0
  71. /package/{dist/core-lib/lib → lib}/services/entity.service.d.ts +0 -0
  72. /package/{dist/core-lib/lib → lib}/services/enum-registry.service.d.ts +0 -0
  73. /package/{dist/core-lib/lib → lib}/services/formly-config.service.d.ts +0 -0
  74. /package/{dist/core-lib/lib → lib}/services/http-utility.service.d.ts +0 -0
  75. /package/{dist/core-lib/lib → lib}/services/notification.service.d.ts +0 -0
  76. /package/{dist/core-lib/lib → lib}/services/reference-data-provider.service.d.ts +0 -0
  77. /package/{dist/core-lib/lib → lib}/services/utils.service.d.ts +0 -0
@@ -1,88 +0,0 @@
1
- import { Component } from '@angular/core';
2
- import { CommonModule } from '@angular/common';
3
- import { ReactiveFormsModule } from '@angular/forms';
4
- import { FieldType, FormlyModule } from '@ngx-formly/core';
5
- import { DatePickerModule } from 'primeng/datepicker';
6
- import { formatDate } from '@angular/common';
7
-
8
- @Component({
9
- selector: 'formly-field-date',
10
- standalone: true,
11
- imports: [
12
- CommonModule,
13
- ReactiveFormsModule,
14
- FormlyModule,
15
- DatePickerModule
16
- ],
17
- template: `
18
- <p-datepicker
19
- [formControl]="$any(formControl)"
20
- [formlyAttributes]="field"
21
- [showIcon]="true"
22
- [dateFormat]="props['dateFormat'] || 'dd-mm-yy'"
23
- [showTime]="props['showTime'] || false"
24
- [touchUI]="props['touchUI'] || false"
25
- [placeholder]="props['placeholder'] || ''"
26
- [minDate]="props['minDate']"
27
- [maxDate]="props['maxDate']"
28
- [showOnFocus]="false"
29
- [todayButtonStyleClass]="'p-button-secondary'"
30
- [clearButtonStyleClass]="'p-button-secondary'"
31
- styleClass="w-full"
32
- (onSelect)="onDateSelect($event)"
33
- (onInput)="onDateInput($event)">
34
- </p-datepicker>
35
- `
36
- })
37
- export class DateType extends FieldType {
38
- override defaultOptions = {
39
- props: {
40
- dateFormat: 'dd-mm-yy',
41
- showTime: false,
42
- touchUI: false,
43
- placeholder: '',
44
- showButtonBar: true,
45
- }
46
- };
47
-
48
- onDateSelect(event: Date): void {
49
- this.formatAndSetDate(event);
50
- }
51
-
52
- onDateInput(event: any): void {
53
- const inputValue = event.target.value.trim();
54
- if (this.isValidDateInput(inputValue, this.props['dateFormat'] || 'dd-mm-yy')) {
55
- const parsedDate = this.parseDate(inputValue, this.props['dateFormat'] || 'dd-mm-yy');
56
- if (parsedDate) {
57
- this.formatAndSetDate(parsedDate);
58
- }
59
- } else {
60
- this.formControl?.setErrors({ invalidDate: true });
61
- }
62
- }
63
-
64
- private formatAndSetDate(date: Date): void {
65
- if (this.formControl) {
66
- const formattedDate = formatDate(date, 'dd-MM-yyyy', 'en-US');
67
- this.formControl.setValue(formattedDate);
68
- }
69
- }
70
-
71
- private parseDate(value: string, format: string): Date | null {
72
- const parts = value.split(/[-/]/); // Split by common delimiters
73
- if (parts.length === 3) {
74
- const [day, month, year] = format === 'dd-mm-yy'
75
- ? [parseInt(parts[0], 10), parseInt(parts[1], 10) - 1, parseInt(parts[2], 10)]
76
- : [parseInt(parts[1], 10), parseInt(parts[0], 10) - 1, parseInt(parts[2], 10)];
77
- return new Date(year, month, day);
78
- }
79
- return null;
80
- }
81
-
82
- private isValidDateInput(value: string, format: string): boolean {
83
- const dateRegex = format === 'dd-mm-yy'
84
- ? /^\d{2}-\d{2}-\d{4}$/
85
- : /^\d{2}\/\d{2}\/\d{4}$/;
86
- return dateRegex.test(value);
87
- }
88
- }
@@ -1,61 +0,0 @@
1
- import { Component } from '@angular/core';
2
- import { CommonModule } from '@angular/common';
3
- import { ReactiveFormsModule } from '@angular/forms';
4
- import { FieldType, FormlyModule } from '@ngx-formly/core';
5
- import { MultiSelectModule } from 'primeng/multiselect';
6
- import { Observable, isObservable, of } from 'rxjs';
7
-
8
- interface SelectOption {
9
- value: any;
10
- label: string;
11
- [key: string]: any;
12
- }
13
-
14
- @Component({
15
- selector: 'formly-field-multiselect',
16
- standalone: true,
17
- imports: [
18
- CommonModule,
19
- ReactiveFormsModule,
20
- FormlyModule,
21
- MultiSelectModule
22
- ],
23
- template: `
24
- <ng-container *ngIf="options$ | async as options">
25
- <p-multiSelect
26
- [formControl]="$any(formControl)"
27
- [formlyAttributes]="field"
28
- [options]="options"
29
- [optionLabel]="props['optionLabel'] || 'label'"
30
- [optionValue]="props['optionValue'] || 'value'"
31
- [placeholder]="props['placeholder'] || 'Select'"
32
- [filter]="props['filter'] || true"
33
- [filterBy]="props['filterBy'] || 'label'"
34
- [maxSelectedLabels]="props['maxSelectedLabels'] || 2"
35
- [showToggleAll]="props['showToggleAll'] || true"
36
- [virtualScroll]="props['virtualScroll'] || false"
37
- [display]="props['display'] || 'chip'"
38
- styleClass="w-full">
39
- </p-multiSelect>
40
- </ng-container>
41
- `
42
- })
43
- export class MultiselectType extends FieldType {
44
- get options$(): Observable<SelectOption[]> {
45
- const options = this.props['options'];
46
- return isObservable(options) ? options : of(options || []);
47
- }
48
-
49
- override defaultOptions = {
50
- props: {
51
- options: [] as SelectOption[],
52
- optionLabel: 'label',
53
- optionValue: 'value',
54
- placeholder: 'Select',
55
- filter: false,
56
- maxSelectedLabels: 3,
57
- showToggleAll: true,
58
- virtualScroll: false
59
- }
60
- };
61
- }
@@ -1,45 +0,0 @@
1
- import { Component } from '@angular/core';
2
- import { CommonModule } from '@angular/common';
3
- import { ReactiveFormsModule } from '@angular/forms';
4
- import { FieldType, FormlyModule } from '@ngx-formly/core';
5
- import { InputNumberModule } from 'primeng/inputnumber';
6
-
7
- @Component({
8
- selector: 'formly-field-numeric-input',
9
- standalone: true,
10
- imports: [
11
- CommonModule,
12
- ReactiveFormsModule,
13
- FormlyModule,
14
- InputNumberModule
15
- ],
16
- template: `
17
- <p-inputNumber
18
- [formControl]="$any(formControl)"
19
- [formlyAttributes]="field"
20
- [placeholder]="props['placeholder'] || ''"
21
- [min]="props['min'] || 0"
22
- [max]="props['max']"
23
- [minFractionDigits]="props['minFractionDigits'] || 0"
24
- [maxFractionDigits]="props['maxFractionDigits'] || 0"
25
- [prefix]="props['prefix'] || ''"
26
- [suffix]="props['suffix'] || ''"
27
- [useGrouping]="props['useGrouping'] ?? true"
28
- [showButtons]="true"
29
- class="w-full">
30
- </p-inputNumber>
31
- `
32
- })
33
- export class NumericInputType extends FieldType {
34
- override defaultOptions = {
35
- props: {
36
- min: undefined,
37
- max: undefined,
38
- minFractionDigits: 0,
39
- maxFractionDigits: 0,
40
- prefix: '',
41
- suffix: '',
42
- useGrouping: true
43
- }
44
- };
45
- }
@@ -1,47 +0,0 @@
1
- import { Component } from '@angular/core';
2
- import { CommonModule } from '@angular/common';
3
- import { ReactiveFormsModule } from '@angular/forms';
4
- import { FormlyModule, FieldType } from '@ngx-formly/core';
5
- import { RadioButtonModule } from 'primeng/radiobutton';
6
- import { Observable, isObservable, of } from 'rxjs';
7
-
8
- interface RadioOption {
9
- value: any;
10
- label: string;
11
- }
12
-
13
- @Component({
14
- selector: 'formly-field-radio',
15
- standalone: true,
16
- imports: [
17
- CommonModule,
18
- ReactiveFormsModule,
19
- FormlyModule,
20
- RadioButtonModule
21
- ],
22
- template: `
23
- <div class="flex flex-column gap-1">
24
- <ng-container *ngIf="options$ | async as options">
25
- <div *ngFor="let option of options; let i = index" class="flex align-items-center gap-2">
26
- <p-radioButton
27
- [name]="field.name || ''"
28
- [value]="option.value"
29
- [formControl]="$any(formControl)"
30
- [formlyAttributes]="field"
31
- [size]="'small'"
32
- [inputId]="field.key + '_' + i">
33
- </p-radioButton>
34
- <label [for]="field.key + '_' + i" class="p-radio-label cursor-pointer">
35
- {{option.label}}
36
- </label>
37
- </div>
38
- </ng-container>
39
- </div>
40
- `
41
- })
42
- export class RadioType extends FieldType {
43
- get options$(): Observable<RadioOption[]> {
44
- const options = this.props['options'];
45
- return isObservable(options) ? options : of(options || []);
46
- }
47
- }
@@ -1,54 +0,0 @@
1
- import { Component } from '@angular/core';
2
- import { CommonModule } from '@angular/common';
3
- import { ReactiveFormsModule } from '@angular/forms';
4
- import { FieldType, FormlyModule } from '@ngx-formly/core';
5
- import { SelectModule } from 'primeng/select';
6
- import { Observable, of, isObservable } from 'rxjs';
7
-
8
- interface SelectOption {
9
- value: any;
10
- label: string;
11
- [key: string]: any; // For additional properties
12
- }
13
-
14
- @Component({
15
- selector: 'formly-field-select',
16
- standalone: true,
17
- imports: [
18
- CommonModule,
19
- ReactiveFormsModule,
20
- FormlyModule,
21
- SelectModule
22
- ],
23
- template: `
24
- <ng-container *ngIf="options$ | async as options">
25
- <p-select
26
- [formControl]="$any(formControl)"
27
- [formlyAttributes]="field"
28
- [options]="options"
29
- [virtualScroll]="false"
30
- [showClear]="false"
31
- [placeholder]="props['placeholder'] || 'Select'"
32
- styleClass="w-full">
33
- </p-select>
34
- </ng-container>
35
- `
36
- })
37
- export class SelectType extends FieldType {
38
- get options$(): Observable<SelectOption[]> {
39
- const options = this.props['options'];
40
- return isObservable(options) ? options : of(options || []);
41
- }
42
-
43
- override defaultOptions = {
44
- props: {
45
- options: [],
46
- optionLabel: 'label',
47
- optionValue: 'value',
48
- placeholder: 'Select',
49
- showClear: false,
50
- filter: false,
51
- virtualScroll: false
52
- }
53
- };
54
- }
@@ -1,33 +0,0 @@
1
- import { Component } from '@angular/core';
2
- import { CommonModule } from '@angular/common';
3
- import { ReactiveFormsModule } from '@angular/forms';
4
- import { FieldType, FormlyModule } from '@ngx-formly/core';
5
- import { InputTextModule } from 'primeng/inputtext';
6
-
7
- @Component({
8
- selector: 'formly-field-text-input',
9
- standalone: true,
10
- imports: [
11
- CommonModule,
12
- ReactiveFormsModule,
13
- FormlyModule,
14
- InputTextModule
15
- ],
16
- template: `
17
- <input pInputText
18
- [type]="props['type'] || 'text'"
19
- [formControl]="$any(formControl)"
20
- [formlyAttributes]="field"
21
- [placeholder]="props['placeholder'] || ''"
22
- [attr.aria-label]="props['label'] || props['placeholder'] || ''"
23
- class="w-full"/>
24
- `
25
- })
26
- export class TextInputType extends FieldType {
27
- override defaultOptions = {
28
- props: {
29
- type: 'text',
30
- placeholder: ''
31
- }
32
- };
33
- }
@@ -1,37 +0,0 @@
1
- import { Component } from '@angular/core';
2
- import { CommonModule } from '@angular/common';
3
- import { ReactiveFormsModule } from '@angular/forms';
4
- import { FieldType, FormlyModule } from '@ngx-formly/core';
5
- import { Textarea } from 'primeng/inputtextarea';
6
-
7
- @Component({
8
- selector: 'formly-field-textarea',
9
- standalone: true,
10
- imports: [
11
- CommonModule,
12
- ReactiveFormsModule,
13
- FormlyModule,
14
- Textarea
15
- ],
16
- template: `
17
- <textarea pInputTextarea
18
- [formControl]="$any(formControl)"
19
- [formlyAttributes]="field"
20
- [rows]="props['rows'] || 3"
21
- [cols]="props['cols']"
22
- [autoResize]="props['autoResize']"
23
- [placeholder]="props['placeholder'] || ''"
24
- class="w-full">
25
- </textarea>
26
- `
27
- })
28
- export class TextareaType extends FieldType {
29
- override defaultOptions = {
30
- props: {
31
- rows: 3,
32
- cols: undefined,
33
- autoResize: true,
34
- placeholder: ''
35
- }
36
- };
37
- }
@@ -1,15 +0,0 @@
1
- export class AppConstants {
2
- static readonly FORM = {
3
- MODE: 'mode',
4
- UUID: 'uuid',
5
- NEW: 'new'
6
- } as const;
7
-
8
- static readonly PAGE_MODE = {
9
- CREATE: 'create',
10
- EDIT: 'edit',
11
- VIEW: 'view'
12
- } as const;
13
- }
14
-
15
- export type PageMode = typeof AppConstants.PAGE_MODE[keyof typeof AppConstants.PAGE_MODE];
@@ -1,36 +0,0 @@
1
- export const AppMessages = {
2
- COMMON: {
3
- ERROR: {
4
- GENERAL: 'An error occurred',
5
- INVALID_INPUT: 'Invalid input provided',
6
- REQUIRED_FIELD: 'This field is required'
7
- },
8
- SUCCESS: {
9
- SAVE: 'saved successfully',
10
- UPDATE: 'updated successfully',
11
- DELETE: 'deleted successfully'
12
- }
13
- },
14
- FORM: {
15
- ERROR: {
16
- INIT: 'Failed to initialize form',
17
- SAVE: 'Failed to save',
18
- LOAD: 'Failed to load',
19
- VALIDATION: 'Please fill in all required fields correctly'
20
- },
21
- SUCCESS: {
22
- SAVE: 'saved successfully'
23
- }
24
- },
25
- LIST: {
26
- ERROR: {
27
- LOAD: 'Failed to load',
28
- DELETE: 'Failed to delete',
29
- NAVIGATION: 'Navigation failed',
30
- INVALID_ID: 'Cannot perform action without ID'
31
- },
32
- SUCCESS: {
33
- DELETE: 'deleted successfully'
34
- }
35
- }
36
- } as const;
@@ -1,6 +0,0 @@
1
- export enum ComponentContext {
2
- STANDALONE = 'STANDALONE',
3
- TABBED = 'TABBED',
4
- MODAL = 'MODAL',
5
- EMBEDDED = 'EMBEDDED'
6
- }
@@ -1,4 +0,0 @@
1
- export enum TabbedFormType {
2
- STANDARD = 'STANDARD',
3
- LIST = 'LIST'
4
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * Matches backend FilterCriteria and FilterOperator
3
- */
4
- export type FilterOperator =
5
- | 'EQUALS'
6
- | 'NOT_EQUALS'
7
- | 'CONTAINS'
8
- | 'STARTS_WITH'
9
- | 'ENDS_WITH'
10
- | 'LESS_THAN'
11
- | 'LESS_THAN_EQUALS'
12
- | 'GREATER_THAN'
13
- | 'GREATER_THAN_EQUALS';
14
-
15
- export interface FilterCriteria {
16
- field: string;
17
- value: string; // Backend expects all values as strings
18
- operator: FilterOperator;
19
- }
@@ -1,13 +0,0 @@
1
- import { FilterCriteria } from './filter-criteria.interface';
2
- import { SortCriteria } from './sort-criteria.interface';
3
-
4
- export interface PageRequest {
5
- page?: number;
6
- size?: number;
7
- sorts?: SortCriteria[];
8
- filters?: FilterCriteria[];
9
- }
10
-
11
- // Re-export for convenience
12
- export type { FilterCriteria } from './filter-criteria.interface';
13
- export type { SortCriteria } from './sort-criteria.interface';
@@ -1,9 +0,0 @@
1
- export interface Page<T> {
2
- content: T[];
3
- page:{
4
- totalElements: number;
5
- totalPages: number;
6
- size: number;
7
- number: number;
8
- }
9
- }
@@ -1,4 +0,0 @@
1
- export interface SortCriteria {
2
- field: string;
3
- direction: 'asc' | 'desc';
4
- }
@@ -1,46 +0,0 @@
1
- import { Pipe, PipeTransform } from '@angular/core';
2
- import { DatePipe } from '@angular/common';
3
-
4
- type DateFormat = 'default' | 'short' | 'medium';
5
-
6
- @Pipe({
7
- name: 'indianDate',
8
- standalone: true
9
- })
10
- export class IndianDatePipe implements PipeTransform {
11
- constructor(private datePipe: DatePipe) {}
12
-
13
- transform(value: string | null, format: DateFormat = 'default'): string | null {
14
- if (!value) return null;
15
-
16
- // First validate dd-MM-yyyy format
17
- const dateRegex = /^(0[1-9]|[12][0-9]|3[01])-(0[1-9]|1[0-2])-\d{4}$/;
18
- if (!dateRegex.test(value)) {
19
- throw new Error(`Invalid date format: ${value}. Expected format: dd-MM-yyyy`);
20
- }
21
-
22
- // Validate real date
23
- const [day, month, year] = value.split('-').map(Number);
24
- const date = new Date(year, month - 1, day);
25
- if (
26
- date.getFullYear() !== year ||
27
- date.getMonth() !== month - 1 ||
28
- date.getDate() !== day
29
- ) {
30
- throw new Error(`Invalid date: ${value}`);
31
- }
32
-
33
- // Apply requested format
34
- switch (format) {
35
- case 'short':
36
- // Pad with leading zeros for consistent format
37
- const paddedDay = day.toString().padStart(2, '0');
38
- const paddedMonth = month.toString().padStart(2, '0');
39
- return `${paddedDay}-${paddedMonth}-${year}`; // 10-03-2025
40
- case 'medium':
41
- return this.datePipe.transform(date, 'dd MMM yyyy'); // 10 Jan 2019
42
- default:
43
- return value; // original dd-MM-yyyy
44
- }
45
- }
46
- }
@@ -1,81 +0,0 @@
1
- import { HttpParams, HttpErrorResponse } from '@angular/common/http';
2
- import { Observable, throwError } from 'rxjs';
3
- import { HttpUtilityService } from './http-utility.service';
4
- import { UtilsService } from './utils.service';
5
- import { MessageService } from 'primeng/api';
6
- import { Page } from '../models/pagination/page.interface';
7
- import { PageRequest } from '../models/pagination/page-request.interface';
8
- import { EntityService } from './entity.service';
9
-
10
- export abstract class BaseCrudService<T extends { uuid: string }> implements EntityService<T> {
11
- // Use the loading state from HttpUtilityService
12
- get loading$() {
13
- return this.httpUtility.loading$;
14
- }
15
-
16
- protected apiUrl: string;
17
-
18
- /**
19
- * Creates an instance of BaseCrudService.
20
- * @param httpUtility - Service for making HTTP requests
21
- * @param utilsService - Utility service for common operations
22
- * @param resourcePath - API resource path (e.g., 'customers', 'products')
23
- * @param backendBaseUrl - Base URL for the backend API
24
- * @param messageService - Optional service for showing messages
25
- */
26
- protected constructor(
27
- protected httpUtility: HttpUtilityService,
28
- protected utilsService: UtilsService,
29
- protected resourcePath: string,
30
- protected backendBaseUrl: string,
31
- protected messageService: MessageService | undefined
32
- ) {
33
- this.apiUrl = this.joinUrls(backendBaseUrl, resourcePath);
34
- }
35
-
36
- /**
37
- * Joins URL parts ensuring no double slashes
38
- */
39
- private joinUrls(...parts: string[]): string {
40
- return parts.map(part => part.replace(/^\/+|\/+$/g, '')).join('/');
41
- }
42
-
43
- getAll(pageRequest?: PageRequest): Observable<Page<T>> {
44
- if (pageRequest) {
45
- return this.httpUtility.post<Page<T>>(`${this.apiUrl}/page`, pageRequest);
46
- } else {
47
- return this.httpUtility.get<Page<T>>(this.apiUrl);
48
- }
49
- }
50
-
51
- getById(uuid: string): Observable<T> {
52
- if (!this.utilsService.isValidUUID(uuid)) {
53
- this.utilsService.showError('Invalid UUID format', this.messageService);
54
- return throwError(() => new Error('Invalid UUID format'));
55
- }
56
-
57
- return this.httpUtility.get<T>(`${this.apiUrl}/${uuid}`);
58
- }
59
-
60
- create(entity: Omit<T, 'uuid'>): Observable<T> {
61
- return this.httpUtility.post<T>(this.apiUrl, entity);
62
- }
63
-
64
- update(uuid: string, entity: Omit<T, 'uuid'>): Observable<T> {
65
- if (!this.utilsService.isValidUUID(uuid)) {
66
- this.utilsService.showError('Invalid UUID format', this.messageService);
67
- return throwError(() => new Error('Invalid UUID format'));
68
- }
69
-
70
- return this.httpUtility.put<T>(`${this.apiUrl}/${uuid}`, entity);
71
- }
72
-
73
- delete(uuid: string): Observable<void> {
74
- if (!this.utilsService.isValidUUID(uuid)) {
75
- this.utilsService.showError('Invalid UUID format', this.messageService);
76
- return throwError(() => new Error('Invalid UUID format'));
77
- }
78
-
79
- return this.httpUtility.delete<void>(`${this.apiUrl}/${uuid}`);
80
- }
81
- }
@@ -1,51 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import { Observable, map } from 'rxjs';
3
- import { HttpUtilityService } from './http-utility.service';
4
- import { ReferenceDataProviderService } from './reference-data-provider.service';
5
-
6
- export interface ReferenceDto {
7
- key: string;
8
- displayLabel: string;
9
- data?: any;
10
- }
11
-
12
- @Injectable({
13
- providedIn: 'root'
14
- })
15
- export class EntityRegistryService {
16
- constructor(
17
- private httpUtility: HttpUtilityService,
18
- private dataProvider: ReferenceDataProviderService
19
- ) {}
20
-
21
- /**
22
- * Gets reference options for an entity, suitable for select/dropdown components
23
- * @param entityName The name of the entity (e.g., 'customers', 'departments')
24
- * @returns Observable of options array with label/value pairs
25
- */
26
- getEntityOptions(entityName: string): Observable<{ label: string; value: string; data?: any; }[]> {
27
- console.log('getEntityOptions', entityName);
28
- const url = this.dataProvider.getReferenceEndpoint(entityName);
29
-
30
- if (!url) {
31
- console.warn(`No endpoint configured for entity: ${entityName}`);
32
- return new Observable(subscriber => {
33
- subscriber.next([]);
34
- subscriber.complete();
35
- });
36
- }
37
-
38
- return this.httpUtility.get<ReferenceDto[]>(url, {
39
- retries: 1,
40
- timeoutMs: 10000,
41
- }).pipe(
42
- map((items) =>
43
- items?.map((item) => ({
44
- label: item.displayLabel,
45
- value: item.key,
46
- data: item.data,
47
- })) || []
48
- )
49
- );
50
- }
51
- }
@@ -1,10 +0,0 @@
1
- import { Observable } from 'rxjs';
2
-
3
- /**
4
- * Interface for basic CRUD operations that all entity services must implement
5
- */
6
- export interface EntityService<T> {
7
- create(data: Omit<T, 'uuid'>): Observable<T>;
8
- update(uuid: string, data: Omit<T, 'uuid'>): Observable<T>;
9
- getById(uuid: string): Observable<T>;
10
- }