@cccteam/ccc-lib 0.0.13 → 0.0.15

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 (226) hide show
  1. package/eslint.config.js +32 -0
  2. package/ng-package.json +11 -0
  3. package/package.json +7 -68
  4. package/src/auth-authentication-guard/authentication.guard.ts +40 -0
  5. package/src/auth-authentication-guard/ng-package.json +6 -0
  6. package/src/auth-authorization-guard/authorization.guard.ts +17 -0
  7. package/src/auth-authorization-guard/ng-package.json +6 -0
  8. package/src/auth-forms/ccc-field/ccc-field.component.html +1 -0
  9. package/src/auth-forms/ccc-field/ccc-field.component.scss +0 -0
  10. package/src/auth-forms/ccc-field/ccc-field.component.spec.ts +22 -0
  11. package/src/auth-forms/ccc-field/ccc-field.component.ts +74 -0
  12. package/src/auth-forms/form-helpers.ts +39 -0
  13. package/src/auth-forms/{public-api.d.ts → index.ts} +1 -0
  14. package/src/auth-forms/ng-package.json +6 -0
  15. package/src/auth-has-permission/has-permission.directive.ts +34 -0
  16. package/src/auth-has-permission/ng-package.json +6 -0
  17. package/src/auth-service/auth.service.ts +92 -0
  18. package/src/auth-service/ng-package.json +6 -0
  19. package/src/ccc-camel-case-to-title/camel-case-to-title.pipe.ts +23 -0
  20. package/src/ccc-camel-case-to-title/index.ts +1 -0
  21. package/src/ccc-camel-case-to-title/ng-package.json +6 -0
  22. package/src/ccc-grid/ccc-grid.component.ts +155 -0
  23. package/src/ccc-grid/index.ts +3 -0
  24. package/src/ccc-grid/ng-package.json +6 -0
  25. package/src/ccc-grid/table-button/table-button.component.html +16 -0
  26. package/src/ccc-grid/table-button/table-button.component.scss +5 -0
  27. package/src/ccc-grid/table-button/table-button.component.spec.ts +22 -0
  28. package/src/ccc-grid/table-button/table-button.component.ts +49 -0
  29. package/src/ccc-resource/can-deactivate.guard.ts +41 -0
  30. package/src/ccc-resource/compound-resource/compound-resource.component.html +57 -0
  31. package/src/ccc-resource/compound-resource/compound-resource.component.scss +86 -0
  32. package/src/ccc-resource/compound-resource/compound-resource.component.spec.ts +22 -0
  33. package/src/ccc-resource/compound-resource/compound-resource.component.ts +158 -0
  34. package/src/ccc-resource/concat-fns.ts +162 -0
  35. package/src/ccc-resource/empty-readonly-field/empty-readonly-field.component.html +12 -0
  36. package/src/ccc-resource/empty-readonly-field/empty-readonly-field.component.scss +0 -0
  37. package/src/ccc-resource/empty-readonly-field/empty-readonly-field.component.spec.ts +23 -0
  38. package/src/ccc-resource/empty-readonly-field/empty-readonly-field.component.ts +17 -0
  39. package/src/ccc-resource/form-state.service.ts +24 -0
  40. package/src/ccc-resource/format-fns.ts +49 -0
  41. package/src/ccc-resource/gui-constants.ts +88 -0
  42. package/src/ccc-resource/index.ts +23 -0
  43. package/src/ccc-resource/leave-page-confirmation-modal/leave-page-confirmation-modal.component.html +8 -0
  44. package/src/ccc-resource/leave-page-confirmation-modal/leave-page-confirmation-modal.component.scss +0 -0
  45. package/src/ccc-resource/leave-page-confirmation-modal/leave-page-confirmation-modal.component.spec.ts +22 -0
  46. package/src/ccc-resource/leave-page-confirmation-modal/leave-page-confirmation-modal.component.ts +12 -0
  47. package/src/ccc-resource/ng-package.json +6 -0
  48. package/src/ccc-resource/operation-types.ts +19 -0
  49. package/src/ccc-resource/padding-element/padding-element.component.html +1 -0
  50. package/src/ccc-resource/padding-element/padding-element.component.scss +3 -0
  51. package/src/ccc-resource/padding-element/padding-element.component.spec.ts +22 -0
  52. package/src/ccc-resource/padding-element/padding-element.component.ts +20 -0
  53. package/src/ccc-resource/resource-array-view/resource-array-view.component.html +81 -0
  54. package/src/ccc-resource/resource-array-view/resource-array-view.component.scss +21 -0
  55. package/src/ccc-resource/resource-array-view/resource-array-view.component.spec.ts +22 -0
  56. package/src/ccc-resource/resource-array-view/resource-array-view.component.ts +143 -0
  57. package/src/ccc-resource/resource-base/resource-base.component.spec.ts +22 -0
  58. package/src/ccc-resource/resource-base/resource-base.component.ts +11 -0
  59. package/src/ccc-resource/resource-cache.service.ts +232 -0
  60. package/src/ccc-resource/resource-create/resource-create.component.html +31 -0
  61. package/src/ccc-resource/resource-create/resource-create.component.scss +130 -0
  62. package/src/ccc-resource/resource-create/resource-create.component.spec.ts +22 -0
  63. package/src/ccc-resource/resource-create/resource-create.component.ts +303 -0
  64. package/src/ccc-resource/resource-field/base-field.directive.ts +102 -0
  65. package/src/ccc-resource/resource-field/fields/boolean-field/boolean-field.component.html +16 -0
  66. package/src/ccc-resource/resource-field/fields/boolean-field/boolean-field.component.scss +0 -0
  67. package/src/ccc-resource/resource-field/fields/boolean-field/boolean-field.component.spec.ts +22 -0
  68. package/src/ccc-resource/resource-field/fields/boolean-field/boolean-field.component.ts +15 -0
  69. package/src/ccc-resource/resource-field/fields/computed-field/computed-field.component.html +13 -0
  70. package/src/ccc-resource/resource-field/fields/computed-field/computed-field.component.scss +0 -0
  71. package/src/ccc-resource/resource-field/fields/computed-field/computed-field.component.spec.ts +23 -0
  72. package/src/ccc-resource/resource-field/fields/computed-field/computed-field.component.ts +50 -0
  73. package/src/ccc-resource/resource-field/fields/date-field/date-field.component.html +22 -0
  74. package/src/ccc-resource/resource-field/fields/date-field/date-field.component.scss +0 -0
  75. package/src/ccc-resource/resource-field/fields/date-field/date-field.component.spec.ts +22 -0
  76. package/src/ccc-resource/resource-field/fields/date-field/date-field.component.ts +14 -0
  77. package/src/ccc-resource/resource-field/fields/enumerated-field/enumerated-field.component.html +71 -0
  78. package/src/ccc-resource/resource-field/fields/enumerated-field/enumerated-field.component.scss +9 -0
  79. package/src/ccc-resource/resource-field/fields/enumerated-field/enumerated-field.component.spec.ts +22 -0
  80. package/src/ccc-resource/resource-field/fields/enumerated-field/enumerated-field.component.ts +207 -0
  81. package/src/ccc-resource/resource-field/fields/nullboolean-field/nullboolean-field.component.html +38 -0
  82. package/src/ccc-resource/resource-field/fields/nullboolean-field/nullboolean-field.component.scss +3 -0
  83. package/src/ccc-resource/resource-field/fields/nullboolean-field/nullboolean-field.component.spec.ts +22 -0
  84. package/src/ccc-resource/resource-field/fields/nullboolean-field/nullboolean-field.component.ts +87 -0
  85. package/src/ccc-resource/resource-field/fields/number-field/number-field.component.html +23 -0
  86. package/src/ccc-resource/resource-field/fields/number-field/number-field.component.scss +6 -0
  87. package/src/ccc-resource/resource-field/fields/number-field/number-field.component.spec.ts +22 -0
  88. package/src/ccc-resource/resource-field/fields/number-field/number-field.component.ts +14 -0
  89. package/src/ccc-resource/resource-field/fields/text-field/text-field.component.html +29 -0
  90. package/src/ccc-resource/resource-field/fields/text-field/text-field.component.scss +6 -0
  91. package/src/ccc-resource/resource-field/fields/text-field/text-field.component.spec.ts +22 -0
  92. package/src/ccc-resource/resource-field/fields/text-field/text-field.component.ts +23 -0
  93. package/src/ccc-resource/resource-field/resource-field.component.html +112 -0
  94. package/src/ccc-resource/resource-field/resource-field.component.scss +7 -0
  95. package/src/ccc-resource/resource-field/resource-field.component.spec.ts +22 -0
  96. package/src/ccc-resource/resource-field/resource-field.component.ts +214 -0
  97. package/src/ccc-resource/resource-layout/resource-layout.component.html +73 -0
  98. package/src/ccc-resource/resource-layout/resource-layout.component.scss +26 -0
  99. package/src/ccc-resource/resource-layout/resource-layout.component.spec.ts +22 -0
  100. package/src/ccc-resource/resource-layout/resource-layout.component.ts +176 -0
  101. package/src/ccc-resource/resource-list/ resource-list.component.spec.ts +22 -0
  102. package/src/ccc-resource/resource-list/resource-list.component.html +27 -0
  103. package/src/ccc-resource/resource-list/resource-list.component.scss +67 -0
  104. package/src/ccc-resource/resource-list/resource-list.component.ts +376 -0
  105. package/src/ccc-resource/resource-list-create/resource-list-create.component.html +71 -0
  106. package/src/ccc-resource/resource-list-create/resource-list-create.component.scss +9 -0
  107. package/src/ccc-resource/resource-list-create/resource-list-create.component.spec.ts +22 -0
  108. package/src/ccc-resource/resource-list-create/resource-list-create.component.ts +103 -0
  109. package/src/ccc-resource/resource-resolver/resource-resolver.component.html +1 -0
  110. package/src/ccc-resource/resource-resolver/resource-resolver.component.scss +0 -0
  111. package/src/ccc-resource/resource-resolver/resource-resolver.component.spec.ts +22 -0
  112. package/src/ccc-resource/resource-resolver/resource-resolver.component.ts +69 -0
  113. package/src/ccc-resource/resource-store.service.ts +93 -0
  114. package/src/ccc-resource/resource-view/resource-view.component.html +133 -0
  115. package/src/ccc-resource/resource-view/resource-view.component.scss +150 -0
  116. package/src/ccc-resource/resource-view/resource-view.component.spec.ts +22 -0
  117. package/src/ccc-resource/resource-view/resource-view.component.ts +354 -0
  118. package/src/ccc-resource/resources-helpers.ts +262 -0
  119. package/src/ccc-resource/utils/validator-utils.ts +6 -0
  120. package/{fesm2022/cccteam-ccc-lib.mjs → src/index.ts} +32 -11
  121. package/src/internal-types/index.ts +1 -0
  122. package/src/internal-types/ng-package.json +6 -0
  123. package/src/types/auth.actions.ts +46 -0
  124. package/src/types/configs.ts +952 -0
  125. package/src/types/constants.ts +1 -0
  126. package/src/types/core.actions.ts +33 -0
  127. package/src/types/{public-api.d.ts → index.ts} +3 -0
  128. package/src/types/ng-package.json +6 -0
  129. package/src/types/notification-message.ts +20 -0
  130. package/src/types/{permissions.d.ts → permissions.ts} +9 -9
  131. package/src/types/{session-info.d.ts → session-info.ts} +4 -3
  132. package/src/types/tokens.ts +20 -0
  133. package/src/ui-alert/alert.component.html +13 -0
  134. package/src/ui-alert/alert.component.scss +48 -0
  135. package/src/ui-alert/alert.component.spec.ts +22 -0
  136. package/src/ui-alert/alert.component.ts +35 -0
  137. package/src/ui-alert/ng-package.json +6 -0
  138. package/src/ui-core-service/index.ts +1 -0
  139. package/src/ui-core-service/ng-package.json +6 -0
  140. package/src/ui-core-service/ui-core.service.ts +34 -0
  141. package/src/ui-interceptor/api.interceptor.spec.ts +16 -0
  142. package/src/ui-interceptor/api.interceptor.ts +45 -0
  143. package/src/ui-interceptor/ng-package.json +6 -0
  144. package/src/ui-notification-service/ng-package.json +6 -0
  145. package/src/ui-notification-service/notification.service.ts +59 -0
  146. package/src/ui-sidenav/ng-package.json +6 -0
  147. package/src/ui-sidenav/sidenav.component.html +60 -0
  148. package/src/ui-sidenav/sidenav.component.scss +99 -0
  149. package/src/ui-sidenav/sidenav.component.spec.ts +22 -0
  150. package/src/ui-sidenav/sidenav.component.ts +64 -0
  151. package/src/util-request-options/ng-package.json +6 -0
  152. package/src/util-request-options/request-options.ts +17 -0
  153. package/tsconfig.lib.json +13 -0
  154. package/tsconfig.lib.prod.json +11 -0
  155. package/tsconfig.spec.json +15 -0
  156. package/cccteam-ccc-lib-0.0.13.tgz +0 -0
  157. package/fesm2022/cccteam-ccc-lib-src-auth-authentication-guard.mjs +0 -44
  158. package/fesm2022/cccteam-ccc-lib-src-auth-authentication-guard.mjs.map +0 -1
  159. package/fesm2022/cccteam-ccc-lib-src-auth-authorization-guard.mjs +0 -24
  160. package/fesm2022/cccteam-ccc-lib-src-auth-authorization-guard.mjs.map +0 -1
  161. package/fesm2022/cccteam-ccc-lib-src-auth-forms.mjs +0 -118
  162. package/fesm2022/cccteam-ccc-lib-src-auth-forms.mjs.map +0 -1
  163. package/fesm2022/cccteam-ccc-lib-src-auth-has-permission.mjs +0 -51
  164. package/fesm2022/cccteam-ccc-lib-src-auth-has-permission.mjs.map +0 -1
  165. package/fesm2022/cccteam-ccc-lib-src-auth-service.mjs +0 -56
  166. package/fesm2022/cccteam-ccc-lib-src-auth-service.mjs.map +0 -1
  167. package/fesm2022/cccteam-ccc-lib-src-auth-state.mjs +0 -109
  168. package/fesm2022/cccteam-ccc-lib-src-auth-state.mjs.map +0 -1
  169. package/fesm2022/cccteam-ccc-lib-src-types.mjs +0 -137
  170. package/fesm2022/cccteam-ccc-lib-src-types.mjs.map +0 -1
  171. package/fesm2022/cccteam-ccc-lib-src-ui-alert.mjs +0 -48
  172. package/fesm2022/cccteam-ccc-lib-src-ui-alert.mjs.map +0 -1
  173. package/fesm2022/cccteam-ccc-lib-src-ui-core-state.mjs +0 -100
  174. package/fesm2022/cccteam-ccc-lib-src-ui-core-state.mjs.map +0 -1
  175. package/fesm2022/cccteam-ccc-lib-src-ui-interceptor.mjs +0 -48
  176. package/fesm2022/cccteam-ccc-lib-src-ui-interceptor.mjs.map +0 -1
  177. package/fesm2022/cccteam-ccc-lib-src-ui-notification-service.mjs +0 -57
  178. package/fesm2022/cccteam-ccc-lib-src-ui-notification-service.mjs.map +0 -1
  179. package/fesm2022/cccteam-ccc-lib-src-ui-sidenav.mjs +0 -70
  180. package/fesm2022/cccteam-ccc-lib-src-ui-sidenav.mjs.map +0 -1
  181. package/fesm2022/cccteam-ccc-lib-src-util-request-options.mjs +0 -19
  182. package/fesm2022/cccteam-ccc-lib-src-util-request-options.mjs.map +0 -1
  183. package/fesm2022/cccteam-ccc-lib.mjs.map +0 -1
  184. package/index.d.ts +0 -5
  185. package/public-api.d.ts +0 -13
  186. package/src/auth-authentication-guard/authentication.guard.d.ts +0 -3
  187. package/src/auth-authentication-guard/index.d.ts +0 -5
  188. package/src/auth-authorization-guard/authorization.guard.d.ts +0 -3
  189. package/src/auth-authorization-guard/index.d.ts +0 -5
  190. package/src/auth-forms/ccc-field/ccc-field.component.d.ts +0 -25
  191. package/src/auth-forms/form-helpers.d.ts +0 -16
  192. package/src/auth-forms/index.d.ts +0 -5
  193. package/src/auth-has-permission/has-permission.directive.d.ts +0 -12
  194. package/src/auth-has-permission/index.d.ts +0 -5
  195. package/src/auth-service/auth.service.d.ts +0 -24
  196. package/src/auth-service/index.d.ts +0 -5
  197. package/src/auth-state/auth.state.d.ts +0 -27
  198. package/src/auth-state/index.d.ts +0 -5
  199. package/src/auth-state/public-api.d.ts +0 -1
  200. package/src/types/auth.actions.d.ts +0 -41
  201. package/src/types/core.actions.d.ts +0 -31
  202. package/src/types/index.d.ts +0 -5
  203. package/src/types/notification-message.d.ts +0 -18
  204. package/src/types/tokens.d.ts +0 -13
  205. package/src/ui-alert/alert.component.d.ts +0 -13
  206. package/src/ui-alert/index.d.ts +0 -5
  207. package/src/ui-core-state/core.state.d.ts +0 -28
  208. package/src/ui-core-state/index.d.ts +0 -5
  209. package/src/ui-core-state/public-api.d.ts +0 -1
  210. package/src/ui-interceptor/api.interceptor.d.ts +0 -12
  211. package/src/ui-interceptor/index.d.ts +0 -5
  212. package/src/ui-notification-service/index.d.ts +0 -5
  213. package/src/ui-notification-service/notification.service.d.ts +0 -30
  214. package/src/ui-sidenav/index.d.ts +0 -5
  215. package/src/ui-sidenav/sidenav.component.d.ts +0 -31
  216. package/src/util-request-options/index.d.ts +0 -5
  217. package/src/util-request-options/request-options.d.ts +0 -8
  218. /package/src/auth-authentication-guard/{public-api.d.ts → index.ts} +0 -0
  219. /package/src/auth-authorization-guard/{public-api.d.ts → index.ts} +0 -0
  220. /package/src/auth-has-permission/{public-api.d.ts → index.ts} +0 -0
  221. /package/src/auth-service/{public-api.d.ts → index.ts} +0 -0
  222. /package/src/ui-alert/{public-api.d.ts → index.ts} +0 -0
  223. /package/src/ui-interceptor/{public-api.d.ts → index.ts} +0 -0
  224. /package/src/ui-notification-service/{public-api.d.ts → index.ts} +0 -0
  225. /package/src/ui-sidenav/{public-api.d.ts → index.ts} +0 -0
  226. /package/src/util-request-options/{public-api.d.ts → index.ts} +0 -0
@@ -0,0 +1,112 @@
1
+ <div [class.hidden-field]="!showField()">
2
+ @if (showEmptyField()) {
3
+ <ccc-empty-readonly-field [label]="fieldConfig().label"></ccc-empty-readonly-field>
4
+ } @else {
5
+ @switch (fieldMeta().displayType) {
6
+ @case ('date') {
7
+ <ccc-date-field
8
+ [form]="form()"
9
+ [fieldConfig]="fieldConfig()"
10
+ [editMode]="mode()"
11
+ [fieldClass]="fieldClass()"
12
+ [meta]="meta()"
13
+ [pristineValue]="pristineValue()"
14
+ [relatedData]="data()"
15
+ [fieldMeta]="fieldMeta()"
16
+ [showField]="showField()">
17
+ </ccc-date-field>
18
+ }
19
+
20
+ @case ('civildate') {
21
+ <ccc-date-field
22
+ [form]="form()"
23
+ [fieldConfig]="fieldConfig()"
24
+ [editMode]="mode()"
25
+ [fieldClass]="fieldClass()"
26
+ [meta]="meta()"
27
+ [pristineValue]="pristineValue()"
28
+ [relatedData]="data()"
29
+ [fieldMeta]="fieldMeta()"
30
+ [showField]="showField()">
31
+ </ccc-date-field>
32
+ }
33
+
34
+ @case ('number') {
35
+ <ccc-number-field
36
+ [form]="form()"
37
+ [fieldConfig]="fieldConfig()"
38
+ [editMode]="mode()"
39
+ [fieldClass]="fieldClass()"
40
+ [meta]="meta()"
41
+ [pristineValue]="pristineValue()"
42
+ [relatedData]="data()"
43
+ [fieldMeta]="fieldMeta()"
44
+ [showField]="showField()">
45
+ </ccc-number-field>
46
+ }
47
+
48
+ @case ('boolean') {
49
+ <ng-container *ngTemplateOutlet="booleanFragment"></ng-container>
50
+ }
51
+ @case ('nullboolean') {
52
+ <ng-container *ngTemplateOutlet="booleanFragment"></ng-container>
53
+ }
54
+
55
+ @case ('enumerated') {
56
+ <ccc-enumerated-field
57
+ [form]="form()"
58
+ [fieldConfig]="fieldConfig()"
59
+ [editMode]="mode()"
60
+ [fieldClass]="fieldClass()"
61
+ [meta]="meta()"
62
+ [pristineValue]="pristineValue()"
63
+ [relatedData]="data()"
64
+ [fieldMeta]="fieldMeta()"
65
+ [showField]="showField()">
66
+ </ccc-enumerated-field>
67
+ }
68
+
69
+ @default {
70
+ <ccc-text-field
71
+ [form]="form()"
72
+ [fieldConfig]="fieldConfig()"
73
+ [editMode]="mode()"
74
+ [fieldClass]="fieldClass()"
75
+ [meta]="meta()"
76
+ [pristineValue]="pristineValue()"
77
+ [relatedData]="data()"
78
+ [fieldMeta]="fieldMeta()"
79
+ [showField]="showField()">
80
+ </ccc-text-field>
81
+ }
82
+ }
83
+ }
84
+ </div>
85
+
86
+ <ng-template #booleanFragment>
87
+ @if (booleanEditDisplayType() === 'boolean') {
88
+ <ccc-boolean-field
89
+ [form]="form()"
90
+ [fieldConfig]="fieldConfig()"
91
+ [editMode]="mode()"
92
+ [fieldClass]="fieldClass()"
93
+ [meta]="meta()"
94
+ [pristineValue]="pristineValue()"
95
+ [relatedData]="data()"
96
+ [fieldMeta]="fieldMeta()"
97
+ [showField]="showField()">
98
+ </ccc-boolean-field>
99
+ } @else if (booleanEditDisplayType() === 'nullboolean') {
100
+ <ccc-nullboolean-field
101
+ [form]="form()"
102
+ [fieldConfig]="fieldConfig()"
103
+ [editMode]="mode()"
104
+ [fieldClass]="fieldClass()"
105
+ [meta]="meta()"
106
+ [pristineValue]="pristineValue()"
107
+ [relatedData]="data()"
108
+ [fieldMeta]="fieldMeta()"
109
+ [showField]="showField()">
110
+ </ccc-nullboolean-field>
111
+ }
112
+ </ng-template>
@@ -0,0 +1,7 @@
1
+ .checkbox {
2
+ margin-top: 10px;
3
+ }
4
+
5
+ .dirty-input {
6
+ background-color: #00617f26;
7
+ }
@@ -0,0 +1,22 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { ResourceFieldComponent } from './resource-field.component';
4
+
5
+ xdescribe('ResourceFieldComponent', () => {
6
+ let component: ResourceFieldComponent;
7
+ let fixture: ComponentFixture<ResourceFieldComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ imports: [ResourceFieldComponent],
12
+ }).compileComponents();
13
+
14
+ fixture = TestBed.createComponent(ResourceFieldComponent);
15
+ component = fixture.componentInstance;
16
+ fixture.detectChanges();
17
+ });
18
+
19
+ it('should create', () => {
20
+ expect(component).toBeTruthy();
21
+ });
22
+ });
@@ -0,0 +1,214 @@
1
+ import { NgTemplateOutlet } from '@angular/common';
2
+ import {
3
+ ChangeDetectionStrategy,
4
+ Component,
5
+ computed,
6
+ effect,
7
+ HostBinding,
8
+ input,
9
+ Signal,
10
+ untracked,
11
+ } from '@angular/core';
12
+ import { FormGroup, Validators } from '@angular/forms';
13
+ import { MatFormFieldModule } from '@angular/material/form-field';
14
+ import { DataType, FieldElement, FieldMeta, Meta, RecordData, ValidDisplayTypes } from '@cccteam/ccc-lib/src/types';
15
+ import { EmptyReadonlyFieldComponent } from '../empty-readonly-field/empty-readonly-field.component';
16
+ import { validatorsPresent } from '../gui-constants';
17
+ import { BooleanFieldComponent } from './fields/boolean-field/boolean-field.component';
18
+ import { DateFieldComponent } from './fields/date-field/date-field.component';
19
+ import { EnumeratedFieldComponent } from './fields/enumerated-field/enumerated-field.component';
20
+ import { NullBooleanFieldComponent } from './fields/nullboolean-field/nullboolean-field.component';
21
+ import { NumberFieldComponent } from './fields/number-field/number-field.component';
22
+ import { TextFieldComponent } from './fields/text-field/text-field.component';
23
+
24
+ @Component({
25
+ selector: 'ccc-resource-field',
26
+ imports: [
27
+ DateFieldComponent,
28
+ BooleanFieldComponent,
29
+ TextFieldComponent,
30
+ NumberFieldComponent,
31
+ EnumeratedFieldComponent,
32
+ MatFormFieldModule,
33
+ EmptyReadonlyFieldComponent,
34
+ NullBooleanFieldComponent,
35
+ NgTemplateOutlet,
36
+ ],
37
+ templateUrl: './resource-field.component.html',
38
+ styleUrl: './resource-field.component.scss',
39
+ changeDetection: ChangeDetectionStrategy.OnPush,
40
+ })
41
+ export class ResourceFieldComponent {
42
+ fieldConfig = input.required<FieldElement>();
43
+ meta = input.required<Meta>();
44
+ fieldClass = input<string>();
45
+ editMode = input<'edit' | 'view'>('edit');
46
+ form = input.required<FormGroup>();
47
+ formDataState = input<RecordData>();
48
+ pristineValue = input<DataType | null>();
49
+ data = input<RecordData>();
50
+ previouslyNulled: boolean | null = null;
51
+
52
+ fieldMeta: Signal<FieldMeta> = computed(() => {
53
+ return (
54
+ (this.meta().fields?.find((field) => field.fieldName === this.fieldConfig().name) as FieldMeta) ||
55
+ ({} as FieldMeta)
56
+ );
57
+ });
58
+
59
+ mode = computed(() => {
60
+ if (this.fieldConfig().readOnly) {
61
+ return 'view';
62
+ }
63
+ return this.editMode();
64
+ });
65
+
66
+ showField = computed(() => {
67
+ const shouldRender = this.fieldConfig().shouldRender;
68
+ const conditionallyNull = this.fieldConfig().nullIfConditionallyHidden;
69
+ const isForeignKeyDefault = this.fieldConfig().default?.type === 'foreignKey';
70
+
71
+ if (typeof shouldRender === 'boolean') {
72
+ return shouldRender && !isForeignKeyDefault;
73
+ }
74
+ const formValues = this.formDataState();
75
+ if (!formValues) {
76
+ return true;
77
+ }
78
+
79
+ console.debug('Field: ', this.fieldConfig().name, ' | Values to be used in showField calculation ', formValues);
80
+
81
+ try {
82
+ const showField = shouldRender(formValues) && !isForeignKeyDefault;
83
+
84
+ if (!conditionallyNull) {
85
+ return showField;
86
+ }
87
+
88
+ const formControlName = this.fieldConfig()?.name;
89
+ const control = this.form()?.controls[formControlName];
90
+ const pristineFieldValue = this.data()?.[formControlName];
91
+ const previouslyNulled = this.previouslyNulled;
92
+
93
+ untracked(() => {
94
+ if (!showField && !previouslyNulled) {
95
+ this.previouslyNulled = true;
96
+ control?.setValue(null);
97
+ }
98
+
99
+ if (showField && previouslyNulled) {
100
+ this.previouslyNulled = false;
101
+ control?.setValue(pristineFieldValue);
102
+ }
103
+ });
104
+
105
+ return showField;
106
+ } catch (e) {
107
+ console.error('Failed to calculate value for should Render function for field: ', this.fieldConfig().name);
108
+ console.error(e);
109
+ return true;
110
+ }
111
+ });
112
+
113
+ showEmptyField = computed(() => {
114
+ const editMode = this.mode();
115
+ const showField = this.showField();
116
+
117
+ if (!showField || editMode === 'edit') {
118
+ return false;
119
+ }
120
+
121
+ const form = this.form();
122
+ const config = this.fieldConfig();
123
+ const meta = this.fieldMeta();
124
+ if (form === undefined || config === undefined || meta === undefined) {
125
+ return false;
126
+ }
127
+
128
+ if (meta.displayType === 'nullboolean') {
129
+ return false;
130
+ }
131
+
132
+ const value = form.get(config.name)?.value;
133
+ // TODO: In phase 3 of visual updates, allow control of which
134
+ // values can trigger the empty field display on a per field basis
135
+ if (value === null || value === '') {
136
+ return true;
137
+ }
138
+
139
+ return false;
140
+ });
141
+
142
+ @HostBinding('class') class = '';
143
+
144
+ booleanEditDisplayType: Signal<BooleanDisplayTypes> = computed(() => {
145
+ const fieldConfig = this.fieldConfig();
146
+ const fieldMeta = this.fieldMeta();
147
+ const form = this.form();
148
+
149
+ if (fieldConfig === undefined || fieldMeta === undefined || form === undefined) {
150
+ return 'boolean';
151
+ }
152
+
153
+ const control = form.get(fieldConfig.name);
154
+ if (control === null) {
155
+ console.warn("Unable to find control for field '" + fieldConfig.name + "' to determine boolean display type");
156
+ return 'boolean';
157
+ }
158
+
159
+ // Frontend forcing users to make a choice displays nullboolean to
160
+ // trigger form validation - users must interact and explicitly
161
+ // choose a true or false value
162
+ if (control.hasValidator(Validators.required) || fieldMeta.displayType === 'nullboolean') {
163
+ return 'nullboolean';
164
+ }
165
+
166
+ return 'boolean';
167
+ });
168
+
169
+ constructor() {
170
+ effect(() => {
171
+ this.class = this.showField() ? 'col-' + this.fieldConfig()?.cols : 'hidden-field';
172
+ });
173
+
174
+ effect(() => {
175
+ const getValidators = this.fieldConfig().validators;
176
+
177
+ if (typeof getValidators !== 'function') {
178
+ return;
179
+ }
180
+
181
+ const formValues = this.formDataState();
182
+
183
+ if (!formValues) {
184
+ return;
185
+ }
186
+
187
+ console.debug('Field: ', this.fieldConfig().name, ' | Values to be used in validators calculation ', formValues);
188
+
189
+ try {
190
+ const newValidators = getValidators(formValues);
191
+
192
+ const formControlName = this.fieldConfig().name;
193
+ const control = this.form().get(formControlName);
194
+
195
+ if (control === null) {
196
+ throw new Error(`Control with name ${this.fieldConfig().name} not found during forceRequired calculation`);
197
+ }
198
+
199
+ const addValidators = !validatorsPresent(control, newValidators);
200
+
201
+ if (addValidators) {
202
+ control.setValidators(newValidators);
203
+ control.updateValueAndValidity();
204
+ }
205
+ } catch (e) {
206
+ console.error('Failed to calculate value for forceRequired function for field: ', this.fieldConfig().name);
207
+ console.error(e);
208
+ return;
209
+ }
210
+ });
211
+ }
212
+ }
213
+
214
+ type BooleanDisplayTypes = Extract<ValidDisplayTypes, 'boolean' | 'nullboolean'>;
@@ -0,0 +1,73 @@
1
+ <div class="section {{ parentClass() }}" [class.hidden-field]="!showLayout()">
2
+ @let parentElement = element();
3
+ @if (children().length > 0) {
4
+ <div
5
+ class="section-elements dense-1 resource-layout-container"
6
+ [class]="layoutNestingDepth() % 2 === 0 ? 'resource-layout-container-even' : 'resource-layout-container-odd'">
7
+ @if (parentElement.type !== 'padding' && parentElement.label !== '') {
8
+ <div class="label">{{ parentElement.label }}</div>
9
+ }
10
+ @for (elementField of children(); track elementField) {
11
+ @let childElement = elementField;
12
+ @if (childElement.type === 'section') {
13
+ @if (layoutNestingDepth() < maxLayoutNestingDepth) {
14
+ <ccc-resource-layout-template
15
+ [layoutNestingDepth]="layoutNestingDepth() + 1"
16
+ [element]="childElement"
17
+ [meta]="meta()"
18
+ [fieldClass]="fieldClass()"
19
+ [editMode]="editMode()"
20
+ [form]="form()"
21
+ [formDataState]="formDataState()"
22
+ [pristineValue]="pristineValue()"
23
+ [relatedData]="relatedData()"
24
+ [parentClass]="parentClass()">
25
+ </ccc-resource-layout-template>
26
+ }
27
+ } @else if (childElement.type === 'field') {
28
+ <ccc-resource-field
29
+ [meta]="meta()"
30
+ [fieldClass]="fieldClass()"
31
+ [fieldConfig]="childElement"
32
+ [editMode]="editMode()"
33
+ [form]="form()"
34
+ [formDataState]="formDataState()"
35
+ [pristineValue]="pristineValue()"
36
+ [data]="relatedData()">
37
+ </ccc-resource-field>
38
+ } @else if (childElement.type === 'computedDisplayField') {
39
+ <ccc-computed-field
40
+ [fieldClass]="fieldClass()"
41
+ [fieldConfig]="childElement"
42
+ [formDataState]="formDataState()"></ccc-computed-field>
43
+ } @else if (childElement.type === 'padding') {
44
+ <ccc-padding-element [paddingElement]="childElement"></ccc-padding-element>
45
+ }
46
+ }
47
+ </div>
48
+ } @else {
49
+ @if (parentElement.type === 'field') {
50
+ <div
51
+ class="section-elements dense-1 resource-layout-container"
52
+ [class]="layoutNestingDepth() % 2 === 0 ? 'resource-layout-container-even' : 'resource-layout-container-odd'">
53
+ <ccc-resource-field
54
+ [meta]="meta()"
55
+ [fieldClass]="fieldClass()"
56
+ [fieldConfig]="parentElement"
57
+ [editMode]="editMode()"
58
+ [form]="form()"
59
+ [formDataState]="formDataState()"
60
+ [pristineValue]="pristineValue()"
61
+ [data]="relatedData()">
62
+ </ccc-resource-field>
63
+ </div>
64
+ } @else if (parentElement.type === 'computedDisplayField') {
65
+ <ccc-computed-field
66
+ [fieldClass]="fieldClass()"
67
+ [fieldConfig]="parentElement"
68
+ [formDataState]="formDataState()"></ccc-computed-field>
69
+ } @else if (parentElement.type === 'padding') {
70
+ <ccc-padding-element [paddingElement]="parentElement"></ccc-padding-element>
71
+ }
72
+ }
73
+ </div>
@@ -0,0 +1,26 @@
1
+ .section {
2
+ margin-top: 15px;
3
+ }
4
+
5
+ .section-elements {
6
+ display: flex;
7
+ flex-wrap: wrap;
8
+ padding-bottom: 4px;
9
+ }
10
+
11
+ .label {
12
+ position: absolute;
13
+ top: -15px;
14
+ left: 20px;
15
+ height: 20px;
16
+ background-color: var(--layout-label-background-color);
17
+ border-radius: 8px;
18
+ margin: 0px 10px 0px 10px;
19
+ padding: 0px 10px 0px 10px;
20
+ text-align: center;
21
+ z-index: 10;
22
+ font-weight: 500;
23
+ font:
24
+ 18px 'Roboto',
25
+ sans-serif;
26
+ }
@@ -0,0 +1,22 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { ResourceLayoutComponent } from './resource-layout.component';
4
+
5
+ describe('ResourceLayoutComponent', () => {
6
+ let component: ResourceLayoutComponent;
7
+ let fixture: ComponentFixture<ResourceLayoutComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ imports: [ResourceLayoutComponent],
12
+ }).compileComponents();
13
+
14
+ fixture = TestBed.createComponent(ResourceLayoutComponent);
15
+ component = fixture.componentInstance;
16
+ fixture.detectChanges();
17
+ });
18
+
19
+ it('should create', () => {
20
+ expect(component).toBeTruthy();
21
+ });
22
+ });
@@ -0,0 +1,176 @@
1
+ import { Component, computed, effect, HostBinding, input, model, OnInit, untracked } from '@angular/core';
2
+ import { FormGroup } from '@angular/forms';
3
+ import { ConfigElement, DataType, FieldElement, Meta, RecordData } from '@cccteam/ccc-lib/src/types';
4
+ import { flattenElements, maxLayoutNestingDepth } from '../gui-constants';
5
+ import { PaddingElementComponent } from '../padding-element/padding-element.component';
6
+ import { ComputedFieldComponent } from '../resource-field/fields/computed-field/computed-field.component';
7
+ import { ResourceFieldComponent } from '../resource-field/resource-field.component';
8
+
9
+ @Component({
10
+ selector: 'ccc-resource-layout-template',
11
+ imports: [PaddingElementComponent, ResourceFieldComponent, ComputedFieldComponent],
12
+ templateUrl: './resource-layout.component.html',
13
+ styleUrls: ['./resource-layout.component.scss'],
14
+ })
15
+ export class ResourceLayoutComponent implements OnInit {
16
+ element = input.required<ConfigElement>();
17
+ meta = input.required<Meta>();
18
+ fieldClass = input<string>();
19
+ editMode = input.required<'edit' | 'view'>();
20
+ form = input.required<FormGroup>();
21
+ formDataState = model<RecordData>();
22
+ pristineValue = input<DataType | null>('');
23
+ relatedData = input<RecordData>();
24
+ parentClass = input<string>();
25
+ layoutNestingDepth = input<number>(1);
26
+
27
+ maxLayoutNestingDepth = maxLayoutNestingDepth;
28
+
29
+ children = computed(() => {
30
+ const element = this.element();
31
+ if (element.type === 'section') {
32
+ return element.children;
33
+ }
34
+ return [];
35
+ });
36
+
37
+ layoutChildrenConfig = computed(() => {
38
+ return flattenElements(this.children());
39
+ });
40
+ previouslyNulled = false;
41
+
42
+ nullIfConditionallyHidden = computed(() => {
43
+ const element = this.element();
44
+ if (element.type === 'field') {
45
+ return element.nullIfConditionallyHidden;
46
+ }
47
+ if (element.type === 'section') {
48
+ return element.nullAllChildrenIfConditionallyHidden;
49
+ }
50
+ return false;
51
+ });
52
+
53
+ showLayout = computed(() => {
54
+ const element = this.element();
55
+ const shouldRender = element.shouldRender;
56
+ const conditionallyNull = this.nullIfConditionallyHidden();
57
+ const form = this.form();
58
+ const label = 'label' in element ? element.label : 'padding';
59
+ const isForeignKeyDefault = element.type === 'field' && element.default?.type === 'foreignKey';
60
+
61
+ if (typeof shouldRender === 'boolean') {
62
+ return shouldRender && !isForeignKeyDefault;
63
+ }
64
+
65
+ const formValues = this.formDataState();
66
+ if (!formValues) {
67
+ return true;
68
+ }
69
+
70
+ console.debug('Layout: ', label, ' | Values to be used in showLayout calculation ', formValues);
71
+ try {
72
+ const showLayout = shouldRender(formValues) && !isForeignKeyDefault;
73
+
74
+ if (!conditionallyNull) {
75
+ return showLayout;
76
+ }
77
+ const previouslyNulled = this.previouslyNulled;
78
+
79
+ untracked(() => {
80
+ this.layoutChildrenConfig().forEach((configElement) => {
81
+ const isFormControl = configElement.type === 'field';
82
+ if (!isFormControl) {
83
+ return;
84
+ }
85
+
86
+ const control = form?.controls[configElement.name];
87
+ const pristineFieldValue = this.relatedData()?.[configElement.name];
88
+
89
+ if (!showLayout && !previouslyNulled) {
90
+ this.previouslyNulled = true;
91
+ control?.setValue(null);
92
+ }
93
+
94
+ if (showLayout && previouslyNulled) {
95
+ this.previouslyNulled = false;
96
+ control?.setValue(pristineFieldValue);
97
+ }
98
+ });
99
+ });
100
+
101
+ return showLayout;
102
+ } catch (e) {
103
+ console.error('Failed to calculate value for should Render function for layout: ', label);
104
+ console.error(e);
105
+ return true;
106
+ }
107
+ });
108
+
109
+ @HostBinding('class') class = '';
110
+
111
+ constructor() {
112
+ // TODO: Remove this effect once Angular supports signals in Reactive forms to obtain changes to form values.
113
+ // This effect has been necessary because translating from Observables to Signals, specifically via an input signal
114
+ // doesn't have a clean solution
115
+
116
+ effect((onCleanup) => {
117
+ const element = this.element();
118
+ if (element === undefined) {
119
+ return;
120
+ }
121
+ const currentForm = this.form();
122
+ const shouldRender = element.shouldRender;
123
+ const nestingDepth = this.layoutNestingDepth();
124
+ const layoutChildren = this.layoutChildrenConfig();
125
+ const label = 'label' in element ? element.label : 'padding';
126
+ if (!this.shouldInitializeFormData(currentForm, nestingDepth, shouldRender, layoutChildren)) {
127
+ return;
128
+ }
129
+ console.debug('USAGE | New subscription for formValuesSignal created for layout: ', label);
130
+
131
+ this.formDataState.set(currentForm.getRawValue());
132
+ const subscription = currentForm.valueChanges.subscribe((value) => {
133
+ this.formDataState.set(value);
134
+ });
135
+
136
+ onCleanup(() => {
137
+ console.debug('USAGE | Unsubscribing from valueChanges for layout: ', label);
138
+ subscription.unsubscribe();
139
+ });
140
+ });
141
+ }
142
+
143
+ ngOnInit(): void {
144
+ this.class = 'col-' + this.element().cols;
145
+ }
146
+
147
+ shouldInitializeFormData(
148
+ form: FormGroup,
149
+ layoutNestingDepth: number,
150
+ shouldRender: ConfigElement['shouldRender'],
151
+ layoutChildren: ConfigElement[],
152
+ ): boolean {
153
+ const childrenNeedFormDataState = layoutChildren.some((config) => {
154
+ const shouldRenderIsFunction = typeof config.shouldRender === 'function';
155
+ const isComputedField = config.type === 'computedDisplayField';
156
+ let validatorsIsFunction = false;
157
+
158
+ const castConfig = config as FieldElement;
159
+ if (castConfig.validators && typeof castConfig.validators === 'function') {
160
+ validatorsIsFunction = true;
161
+ }
162
+
163
+ return shouldRenderIsFunction || isComputedField || validatorsIsFunction;
164
+ });
165
+
166
+ if (!form || layoutNestingDepth > 1) {
167
+ return false;
168
+ }
169
+
170
+ if (!childrenNeedFormDataState && typeof shouldRender !== 'function') {
171
+ return false;
172
+ }
173
+
174
+ return true;
175
+ }
176
+ }
@@ -0,0 +1,22 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { ResourceListComponent } from './resource-list.component';
4
+
5
+ xdescribe('ResourceListComponent', () => {
6
+ let component: ResourceListComponent;
7
+ let fixture: ComponentFixture<ResourceListComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ imports: [ResourceListComponent],
12
+ }).compileComponents();
13
+
14
+ fixture = TestBed.createComponent(ResourceListComponent);
15
+ component = fixture.componentInstance;
16
+ fixture.detectChanges();
17
+ });
18
+
19
+ it('should create', () => {
20
+ expect(component).toBeTruthy();
21
+ });
22
+ });