tango-app-ui-analyse-trax 3.9.2 → 3.9.3

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 (470) hide show
  1. package/.eslintrc.json +37 -0
  2. package/ng-package.json +7 -0
  3. package/package.json +12 -25
  4. package/src/lib/components/action-centre/action-centre.component.html +607 -0
  5. package/src/lib/components/action-centre/action-centre.component.scss +185 -0
  6. package/src/lib/components/action-centre/action-centre.component.spec.ts +23 -0
  7. package/src/lib/components/action-centre/action-centre.component.ts +279 -0
  8. package/src/lib/components/activity-log/activity-log.component.html +84 -0
  9. package/src/lib/components/activity-log/activity-log.component.scss +33 -0
  10. package/src/lib/components/activity-log/activity-log.component.spec.ts +23 -0
  11. package/src/lib/components/activity-log/activity-log.component.ts +137 -0
  12. package/src/lib/components/activity-log-v2/activity-log-v2.component.html +189 -0
  13. package/src/lib/components/activity-log-v2/activity-log-v2.component.scss +162 -0
  14. package/src/lib/components/activity-log-v2/activity-log-v2.component.spec.ts +23 -0
  15. package/src/lib/components/activity-log-v2/activity-log-v2.component.ts +517 -0
  16. package/src/lib/components/activity-log-v2/log-view-popup/date-range-picker/date-range-picker.component.html +19 -0
  17. package/src/lib/components/activity-log-v2/log-view-popup/date-range-picker/date-range-picker.component.scss +148 -0
  18. package/src/lib/components/activity-log-v2/log-view-popup/date-range-picker/date-range-picker.component.spec.ts +23 -0
  19. package/src/lib/components/activity-log-v2/log-view-popup/date-range-picker/date-range-picker.component.ts +141 -0
  20. package/src/lib/components/activity-log-v2/log-view-popup/store-user-dropdown/store-user-dropdown.component.html +42 -0
  21. package/src/lib/components/activity-log-v2/log-view-popup/store-user-dropdown/store-user-dropdown.component.scss +49 -0
  22. package/src/lib/components/activity-log-v2/log-view-popup/store-user-dropdown/store-user-dropdown.component.spec.ts +23 -0
  23. package/src/lib/components/activity-log-v2/log-view-popup/store-user-dropdown/store-user-dropdown.component.ts +22 -0
  24. package/src/lib/components/activity-log-v2/log-view-popup/view-action/view-action.component.html +724 -0
  25. package/src/lib/components/activity-log-v2/log-view-popup/view-action/view-action.component.scss +217 -0
  26. package/src/lib/components/activity-log-v2/log-view-popup/view-action/view-action.component.spec.ts +23 -0
  27. package/src/lib/components/activity-log-v2/log-view-popup/view-action/view-action.component.ts +122 -0
  28. package/src/lib/components/add-checklist/add-checklist.component.html +1459 -0
  29. package/src/lib/components/add-checklist/add-checklist.component.scss +1205 -0
  30. package/src/lib/components/add-checklist/add-checklist.component.spec.ts +23 -0
  31. package/src/lib/components/add-checklist/add-checklist.component.ts +2460 -0
  32. package/src/lib/components/add-checklist/checklist-popup/checklist-popup.component.html +207 -0
  33. package/src/lib/components/add-checklist/checklist-popup/checklist-popup.component.scss +213 -0
  34. package/src/lib/components/add-checklist/checklist-popup/checklist-popup.component.spec.ts +23 -0
  35. package/src/lib/components/add-checklist/checklist-popup/checklist-popup.component.ts +621 -0
  36. package/src/lib/components/add-checklist/counter/counter.component.html +43 -0
  37. package/src/lib/components/add-checklist/counter/counter.component.scss +49 -0
  38. package/src/lib/components/add-checklist/counter/counter.component.spec.ts +23 -0
  39. package/src/lib/components/add-checklist/counter/counter.component.ts +123 -0
  40. package/src/lib/components/add-multitask/add-multitask.component.html +705 -0
  41. package/src/lib/components/add-multitask/add-multitask.component.scss +296 -0
  42. package/src/lib/components/add-multitask/add-multitask.component.spec.ts +23 -0
  43. package/src/lib/components/add-multitask/add-multitask.component.ts +611 -0
  44. package/src/lib/components/add-multitask/ascending-validator.ts +13 -0
  45. package/src/lib/components/add-multitask/bulkcreationmodel/bulkcreationmodel.component.html +197 -0
  46. package/src/lib/components/add-multitask/bulkcreationmodel/bulkcreationmodel.component.scss +31 -0
  47. package/src/lib/components/add-multitask/bulkcreationmodel/bulkcreationmodel.component.spec.ts +23 -0
  48. package/src/lib/components/add-multitask/bulkcreationmodel/bulkcreationmodel.component.ts +285 -0
  49. package/src/lib/components/add-multitask/create-task.data.ts +374 -0
  50. package/src/lib/components/add-multitask/create-task.interface.ts +177 -0
  51. package/src/lib/components/add-multitask/unique-string-validator.ts +13 -0
  52. package/src/lib/components/add-multitask/whitespace-validator.ts +11 -0
  53. package/src/lib/components/add-task/add-task.component.html +654 -0
  54. package/src/lib/components/add-task/add-task.component.scss +536 -0
  55. package/src/lib/components/add-task/add-task.component.spec.ts +23 -0
  56. package/src/lib/components/add-task/add-task.component.ts +569 -0
  57. package/src/lib/components/add-task/ascending-validator.ts +13 -0
  58. package/src/lib/components/add-task/create-task.data.ts +374 -0
  59. package/src/lib/components/add-task/create-task.interface.ts +192 -0
  60. package/src/lib/components/add-task/unique-string-validator.ts +13 -0
  61. package/src/lib/components/add-task/whitespace-validator.ts +11 -0
  62. package/src/lib/components/approval-popup/approval-popup.component.html +25 -0
  63. package/src/lib/components/approval-popup/approval-popup.component.scss +3 -0
  64. package/src/lib/components/approval-popup/approval-popup.component.spec.ts +23 -0
  65. package/src/lib/components/approval-popup/approval-popup.component.ts +26 -0
  66. package/src/lib/components/checklist/checklist.component.html +330 -0
  67. package/src/lib/components/checklist/checklist.component.scss +112 -0
  68. package/src/lib/components/checklist/checklist.component.spec.ts +23 -0
  69. package/src/lib/components/checklist/checklist.component.ts +344 -0
  70. package/src/lib/components/checklist-configure/assign/assign.component.html +665 -0
  71. package/src/lib/components/checklist-configure/assign/assign.component.scss +219 -0
  72. package/src/lib/components/checklist-configure/assign/assign.component.spec.ts +23 -0
  73. package/src/lib/components/checklist-configure/assign/assign.component.ts +932 -0
  74. package/src/lib/components/checklist-configure/checklist-configure.component.html +4340 -0
  75. package/src/lib/components/checklist-configure/checklist-configure.component.scss +2338 -0
  76. package/src/lib/components/checklist-configure/checklist-configure.component.spec.ts +23 -0
  77. package/src/lib/components/checklist-configure/checklist-configure.component.ts +4659 -0
  78. package/src/lib/components/checklistlayout/checklistlayout.component.html +30 -0
  79. package/src/lib/components/checklistlayout/checklistlayout.component.scss +15 -0
  80. package/src/lib/components/checklistlayout/checklistlayout.component.spec.ts +23 -0
  81. package/src/lib/components/checklistlayout/checklistlayout.component.ts +47 -0
  82. package/src/lib/components/chip-dropdown/chip-dropdown.component.html +36 -0
  83. package/src/lib/components/chip-dropdown/chip-dropdown.component.scss +97 -0
  84. package/src/lib/components/chip-dropdown/chip-dropdown.component.spec.ts +23 -0
  85. package/src/lib/components/chip-dropdown/chip-dropdown.component.ts +125 -0
  86. package/src/lib/components/create-task/create-task.component.html +2003 -0
  87. package/src/lib/components/create-task/create-task.component.scss +272 -0
  88. package/src/lib/components/create-task/create-task.component.spec.ts +23 -0
  89. package/src/lib/components/create-task/create-task.component.ts +614 -0
  90. package/src/lib/components/create-task/create-task.data.ts +372 -0
  91. package/src/lib/components/create-task/create-task.interface.ts +182 -0
  92. package/src/lib/components/create-task/validators/ascending-validator.ts +13 -0
  93. package/src/lib/components/create-task/validators/unique-string-validator.ts +13 -0
  94. package/src/lib/components/create-task/validators/whitespace-validator.ts +11 -0
  95. package/src/lib/components/custom-select/custom-select.component.html +44 -0
  96. package/src/lib/components/custom-select/custom-select.component.scss +144 -0
  97. package/src/lib/components/custom-select/custom-select.component.spec.ts +23 -0
  98. package/src/lib/components/custom-select/custom-select.component.ts +265 -0
  99. package/src/lib/components/dashboard/dashboard.component.html +1076 -0
  100. package/src/lib/components/dashboard/dashboard.component.scss +237 -0
  101. package/src/lib/components/dashboard/dashboard.component.spec.ts +23 -0
  102. package/src/lib/components/dashboard/dashboard.component.ts +539 -0
  103. package/src/lib/components/dashboard-info/dashboard-info.component.html +1420 -0
  104. package/src/lib/components/dashboard-info/dashboard-info.component.scss +409 -0
  105. package/src/lib/components/dashboard-info/dashboard-info.component.spec.ts +23 -0
  106. package/src/lib/components/dashboard-info/dashboard-info.component.ts +772 -0
  107. package/src/lib/components/dashboard-info/monthlyperformance-datepicker/monthlyperformance-datepicker.component.html +110 -0
  108. package/src/lib/components/dashboard-info/monthlyperformance-datepicker/monthlyperformance-datepicker.component.scss +260 -0
  109. package/src/lib/components/dashboard-info/monthlyperformance-datepicker/monthlyperformance-datepicker.component.spec.ts +23 -0
  110. package/src/lib/components/dashboard-info/monthlyperformance-datepicker/monthlyperformance-datepicker.component.ts +143 -0
  111. package/src/lib/components/dashboard-layout/dashboard-layout.component.html +1 -0
  112. package/src/lib/components/dashboard-layout/dashboard-layout.component.scss +0 -0
  113. package/src/lib/components/dashboard-layout/dashboard-layout.component.spec.ts +23 -0
  114. package/src/lib/components/dashboard-layout/dashboard-layout.component.ts +10 -0
  115. package/src/lib/components/disabled-select/disabled-select.component.html +44 -0
  116. package/src/lib/components/disabled-select/disabled-select.component.scss +149 -0
  117. package/src/lib/components/disabled-select/disabled-select.component.spec.ts +23 -0
  118. package/src/lib/components/disabled-select/disabled-select.component.ts +146 -0
  119. package/src/lib/components/export-gallery/export-gallery.component.html +175 -0
  120. package/src/lib/components/export-gallery/export-gallery.component.scss +200 -0
  121. package/src/lib/components/export-gallery/export-gallery.component.spec.ts +23 -0
  122. package/src/lib/components/export-gallery/export-gallery.component.ts +263 -0
  123. package/src/lib/components/eye-test-audit/chip-dropdown/chip-dropdown.component.html +36 -0
  124. package/src/lib/components/eye-test-audit/chip-dropdown/chip-dropdown.component.scss +97 -0
  125. package/src/lib/components/eye-test-audit/chip-dropdown/chip-dropdown.component.spec.ts +23 -0
  126. package/src/lib/components/eye-test-audit/chip-dropdown/chip-dropdown.component.ts +104 -0
  127. package/src/lib/components/eye-test-audit/custom-select/custom-select.component.html +44 -0
  128. package/src/lib/components/eye-test-audit/custom-select/custom-select.component.scss +144 -0
  129. package/src/lib/components/eye-test-audit/custom-select/custom-select.component.spec.ts +23 -0
  130. package/src/lib/components/eye-test-audit/custom-select/custom-select.component.ts +265 -0
  131. package/src/lib/components/eye-test-audit/eye-test/eye-test.component.html +1804 -0
  132. package/src/lib/components/eye-test-audit/eye-test/eye-test.component.scss +806 -0
  133. package/src/lib/components/eye-test-audit/eye-test/eye-test.component.spec.ts +23 -0
  134. package/src/lib/components/eye-test-audit/eye-test/eye-test.component.ts +1890 -0
  135. package/src/lib/components/eye-test-audit/eye-test/send-alert/send-alert.component.html +25 -0
  136. package/src/lib/components/eye-test-audit/eye-test/send-alert/send-alert.component.scss +0 -0
  137. package/src/lib/components/eye-test-audit/eye-test/send-alert/send-alert.component.spec.ts +23 -0
  138. package/src/lib/components/eye-test-audit/eye-test/send-alert/send-alert.component.ts +20 -0
  139. package/src/lib/components/eye-test-audit/eye-test-audit/eye-test-audit-routing.module.ts +26 -0
  140. package/src/lib/components/eye-test-audit/eye-test-audit/eye-test-audit.component.html +1 -0
  141. package/src/lib/components/eye-test-audit/eye-test-audit/eye-test-audit.component.scss +0 -0
  142. package/src/lib/components/eye-test-audit/eye-test-audit/eye-test-audit.component.spec.ts +23 -0
  143. package/src/lib/components/eye-test-audit/eye-test-audit/eye-test-audit.component.ts +24 -0
  144. package/src/lib/components/eye-test-audit/eye-test-audit/eye-test-audit.module.ts +44 -0
  145. package/src/lib/components/eye-test-audit/eye-test-audit/settings-audit/settings-audit.component.html +490 -0
  146. package/src/lib/components/eye-test-audit/eye-test-audit/settings-audit/settings-audit.component.scss +721 -0
  147. package/src/lib/components/eye-test-audit/eye-test-audit/settings-audit/settings-audit.component.spec.ts +23 -0
  148. package/src/lib/components/eye-test-audit/eye-test-audit/settings-audit/settings-audit.component.ts +1017 -0
  149. package/src/lib/components/eye-test-audit/eye-test-audit/start-audit/start-audit.component.html +708 -0
  150. package/src/lib/components/eye-test-audit/eye-test-audit/start-audit/start-audit.component.scss +247 -0
  151. package/src/lib/components/eye-test-audit/eye-test-audit/start-audit/start-audit.component.spec.ts +23 -0
  152. package/src/lib/components/eye-test-audit/eye-test-audit/start-audit/start-audit.component.ts +446 -0
  153. package/src/lib/components/eye-test-audit/group-select/group-select.component.html +44 -0
  154. package/src/lib/components/eye-test-audit/group-select/group-select.component.scss +144 -0
  155. package/src/lib/components/eye-test-audit/group-select/group-select.component.spec.ts +23 -0
  156. package/src/lib/components/eye-test-audit/group-select/group-select.component.ts +147 -0
  157. package/src/lib/components/eye-test-audit/reactive-select/reactive-select.component.html +18 -0
  158. package/src/lib/components/eye-test-audit/reactive-select/reactive-select.component.scss +49 -0
  159. package/src/lib/components/eye-test-audit/reactive-select/reactive-select.component.spec.ts +23 -0
  160. package/src/lib/components/eye-test-audit/reactive-select/reactive-select.component.ts +104 -0
  161. package/src/lib/components/eye-test-audit/select-drop/select-drop.component.html +44 -0
  162. package/src/lib/components/eye-test-audit/select-drop/select-drop.component.scss +144 -0
  163. package/src/lib/components/eye-test-audit/select-drop/select-drop.component.spec.ts +23 -0
  164. package/src/lib/components/eye-test-audit/select-drop/select-drop.component.ts +152 -0
  165. package/src/lib/components/eye-test-audit/services/eye-test-audit.service.spec.ts +16 -0
  166. package/src/lib/components/eye-test-audit/services/eye-test-audit.service.ts +190 -0
  167. package/src/lib/components/flag-layout/flag-layout.component.html +1 -0
  168. package/src/lib/components/flag-layout/flag-layout.component.scss +0 -0
  169. package/src/lib/components/flag-layout/flag-layout.component.spec.ts +23 -0
  170. package/src/lib/components/flag-layout/flag-layout.component.ts +10 -0
  171. package/src/lib/components/flags/flags.component.html +473 -0
  172. package/src/lib/components/flags/flags.component.scss +86 -0
  173. package/src/lib/components/flags/flags.component.spec.ts +23 -0
  174. package/src/lib/components/flags/flags.component.ts +280 -0
  175. package/{lib/components/flags/flags.interface.d.ts → src/lib/components/flags/flags.interface.ts} +73 -65
  176. package/src/lib/components/flags-info/flags-info.component.html +6012 -0
  177. package/src/lib/components/flags-info/flags-info.component.scss +278 -0
  178. package/src/lib/components/flags-info/flags-info.component.spec.ts +23 -0
  179. package/src/lib/components/flags-info/flags-info.component.ts +490 -0
  180. package/src/lib/components/flags-info/flags-info.interface.ts +441 -0
  181. package/src/lib/components/flags-info/unattended-pie-chart/unattended-pie-chart.component.html +1 -0
  182. package/src/lib/components/flags-info/unattended-pie-chart/unattended-pie-chart.component.scss +4 -0
  183. package/src/lib/components/flags-info/unattended-pie-chart/unattended-pie-chart.component.ts +78 -0
  184. package/src/lib/components/flags-new/flags-new.component.html +904 -0
  185. package/src/lib/components/flags-new/flags-new.component.scss +121 -0
  186. package/src/lib/components/flags-new/flags-new.component.spec.ts +23 -0
  187. package/src/lib/components/flags-new/flags-new.component.ts +357 -0
  188. package/{lib/components/flags-new/flags-new.interface.d.ts → src/lib/components/flags-new/flags-new.interface.ts} +90 -81
  189. package/src/lib/components/gallery/gallery.component.html +3660 -0
  190. package/src/lib/components/gallery/gallery.component.scss +930 -0
  191. package/src/lib/components/gallery/gallery.component.ts +3527 -0
  192. package/src/lib/components/group-select/group-select.component.html +44 -0
  193. package/src/lib/components/group-select/group-select.component.scss +144 -0
  194. package/src/lib/components/group-select/group-select.component.spec.ts +23 -0
  195. package/src/lib/components/group-select/group-select.component.ts +145 -0
  196. package/src/lib/components/image-popup/image-popup.component.html +11 -0
  197. package/src/lib/components/image-popup/image-popup.component.scss +5 -0
  198. package/src/lib/components/image-popup/image-popup.component.ts +18 -0
  199. package/src/lib/components/lib/custom-select/custom-select.component.html +42 -0
  200. package/src/lib/components/lib/custom-select/custom-select.component.scss +131 -0
  201. package/src/lib/components/lib/custom-select/custom-select.component.spec.ts +23 -0
  202. package/src/lib/components/lib/custom-select/custom-select.component.ts +151 -0
  203. package/src/lib/components/manage-task/manage-task.component.html +265 -0
  204. package/src/lib/components/manage-task/manage-task.component.scss +69 -0
  205. package/src/lib/components/manage-task/manage-task.component.spec.ts +23 -0
  206. package/src/lib/components/manage-task/manage-task.component.ts +267 -0
  207. package/src/lib/components/managechecklist/managechecklist.component.html +176 -0
  208. package/src/lib/components/managechecklist/managechecklist.component.scss +43 -0
  209. package/src/lib/components/managechecklist/managechecklist.component.spec.ts +23 -0
  210. package/src/lib/components/managechecklist/managechecklist.component.ts +176 -0
  211. package/src/lib/components/multi-chip-dropdown/multi-chip-dropdown.component.html +46 -0
  212. package/src/lib/components/multi-chip-dropdown/multi-chip-dropdown.component.scss +181 -0
  213. package/src/lib/components/multi-chip-dropdown/multi-chip-dropdown.component.spec.ts +23 -0
  214. package/src/lib/components/multi-chip-dropdown/multi-chip-dropdown.component.ts +221 -0
  215. package/src/lib/components/multi-date-datepicker/multi-date-datepicker.component.html +36 -0
  216. package/src/lib/components/multi-date-datepicker/multi-date-datepicker.component.scss +89 -0
  217. package/src/lib/components/multi-date-datepicker/multi-date-datepicker.component.spec.ts +23 -0
  218. package/src/lib/components/multi-date-datepicker/multi-date-datepicker.component.ts +118 -0
  219. package/src/lib/components/orders/orders.component.html +203 -0
  220. package/src/lib/components/orders/orders.component.scss +180 -0
  221. package/src/lib/components/orders/orders.component.spec.ts +25 -0
  222. package/src/lib/components/orders/orders.component.ts +197 -0
  223. package/src/lib/components/pagination/pagination.component.html +28 -0
  224. package/src/lib/components/pagination/pagination.component.scss +6 -0
  225. package/src/lib/components/pagination/pagination.component.spec.ts +23 -0
  226. package/src/lib/components/pagination/pagination.component.ts +54 -0
  227. package/src/lib/components/reactive-select/reactive-select.component.html +18 -0
  228. package/src/lib/components/reactive-select/reactive-select.component.scss +48 -0
  229. package/src/lib/components/reactive-select/reactive-select.component.spec.ts +23 -0
  230. package/src/lib/components/reactive-select/reactive-select.component.ts +104 -0
  231. package/src/lib/components/reports/date-picker/date-picker.component.html +54 -0
  232. package/src/lib/components/reports/date-picker/date-picker.component.scss +156 -0
  233. package/src/lib/components/reports/date-picker/date-picker.component.spec.ts +23 -0
  234. package/src/lib/components/reports/date-picker/date-picker.component.ts +60 -0
  235. package/src/lib/components/reports/reports.component.html +225 -0
  236. package/src/lib/components/reports/reports.component.scss +69 -0
  237. package/src/lib/components/reports/reports.component.spec.ts +23 -0
  238. package/src/lib/components/reports/reports.component.ts +334 -0
  239. package/{lib/components/reports/reports.interface.d.ts → src/lib/components/reports/reports.interface.ts} +50 -46
  240. package/src/lib/components/tango-analyse-trax/tango-analyse-trax.component.html +1 -0
  241. package/src/lib/components/tango-analyse-trax/tango-analyse-trax.component.scss +15 -0
  242. package/src/lib/components/tango-analyse-trax/tango-analyse-trax.component.spec.ts +23 -0
  243. package/src/lib/components/tango-analyse-trax/tango-analyse-trax.component.ts +31 -0
  244. package/src/lib/components/task/task.component.html +322 -0
  245. package/src/lib/components/task/task.component.scss +169 -0
  246. package/src/lib/components/task/task.component.spec.ts +23 -0
  247. package/src/lib/components/task/task.component.ts +340 -0
  248. package/src/lib/components/task-configure/task-configure.component.html +737 -0
  249. package/src/lib/components/task-configure/task-configure.component.scss +569 -0
  250. package/src/lib/components/task-configure/task-configure.component.spec.ts +23 -0
  251. package/src/lib/components/task-configure/task-configure.component.ts +1603 -0
  252. package/src/lib/components/task-configure/task-configure.interface.ts +138 -0
  253. package/src/lib/components/task-info/task-info.component.html +390 -0
  254. package/src/lib/components/task-info/task-info.component.scss +56 -0
  255. package/src/lib/components/task-info/task-info.component.spec.ts +23 -0
  256. package/src/lib/components/task-info/task-info.component.ts +400 -0
  257. package/src/lib/components/task-info/taskinfo-edit/taskinfo-edit.component.html +141 -0
  258. package/src/lib/components/task-info/taskinfo-edit/taskinfo-edit.component.scss +460 -0
  259. package/src/lib/components/task-info/taskinfo-edit/taskinfo-edit.component.spec.ts +23 -0
  260. package/src/lib/components/task-info/taskinfo-edit/taskinfo-edit.component.ts +202 -0
  261. package/src/lib/components/task-layout/task-layout.component.html +1 -0
  262. package/src/lib/components/task-layout/task-layout.component.scss +0 -0
  263. package/src/lib/components/task-layout/task-layout.component.spec.ts +23 -0
  264. package/src/lib/components/task-layout/task-layout.component.ts +10 -0
  265. package/src/lib/components/task-logs/task-logs.component.html +97 -0
  266. package/src/lib/components/task-logs/task-logs.component.scss +301 -0
  267. package/src/lib/components/task-logs/task-logs.component.spec.ts +23 -0
  268. package/src/lib/components/task-logs/task-logs.component.ts +80 -0
  269. package/src/lib/components/trax-run-ai-popup/trax-run-ai-popup.component.html +84 -0
  270. package/src/lib/components/trax-run-ai-popup/trax-run-ai-popup.component.scss +229 -0
  271. package/src/lib/components/trax-run-ai-popup/trax-run-ai-popup.component.spec.ts +23 -0
  272. package/src/lib/components/trax-run-ai-popup/trax-run-ai-popup.component.ts +111 -0
  273. package/src/lib/components/trax-store/trax-store.component.html +78 -0
  274. package/src/lib/components/trax-store/trax-store.component.scss +134 -0
  275. package/src/lib/components/trax-store/trax-store.component.spec.ts +23 -0
  276. package/src/lib/components/trax-store/trax-store.component.ts +172 -0
  277. package/src/lib/components/traxpopup/traxpopup.component.html +130 -0
  278. package/src/lib/components/traxpopup/traxpopup.component.scss +225 -0
  279. package/src/lib/components/traxpopup/traxpopup.component.spec.ts +23 -0
  280. package/src/lib/components/traxpopup/traxpopup.component.ts +71 -0
  281. package/src/lib/services/trax.service.spec.ts +16 -0
  282. package/src/lib/services/trax.service.ts +789 -0
  283. package/src/lib/tango-analyse-trax-routing.module.ts +151 -0
  284. package/src/lib/tango-analyse-trax.module.ts +140 -0
  285. package/{public-api.d.ts → src/public-api.ts} +6 -2
  286. package/tsconfig.lib.json +14 -0
  287. package/tsconfig.lib.prod.json +10 -0
  288. package/tsconfig.spec.json +14 -0
  289. package/esm2022/lib/components/action-centre/action-centre.component.mjs +0 -288
  290. package/esm2022/lib/components/activity-log/activity-log.component.mjs +0 -150
  291. package/esm2022/lib/components/activity-log-v2/activity-log-v2.component.mjs +0 -502
  292. package/esm2022/lib/components/activity-log-v2/log-view-popup/date-range-picker/date-range-picker.component.mjs +0 -114
  293. package/esm2022/lib/components/activity-log-v2/log-view-popup/store-user-dropdown/store-user-dropdown.component.mjs +0 -24
  294. package/esm2022/lib/components/activity-log-v2/log-view-popup/view-action/view-action.component.mjs +0 -126
  295. package/esm2022/lib/components/add-checklist/add-checklist.component.mjs +0 -2352
  296. package/esm2022/lib/components/add-checklist/checklist-popup/checklist-popup.component.mjs +0 -612
  297. package/esm2022/lib/components/add-checklist/counter/counter.component.mjs +0 -138
  298. package/esm2022/lib/components/add-multitask/add-multitask.component.mjs +0 -604
  299. package/esm2022/lib/components/add-multitask/ascending-validator.mjs +0 -11
  300. package/esm2022/lib/components/add-multitask/bulkcreationmodel/bulkcreationmodel.component.mjs +0 -297
  301. package/esm2022/lib/components/add-multitask/create-task.data.mjs +0 -372
  302. package/esm2022/lib/components/add-multitask/create-task.interface.mjs +0 -2
  303. package/esm2022/lib/components/add-multitask/unique-string-validator.mjs +0 -10
  304. package/esm2022/lib/components/add-multitask/whitespace-validator.mjs +0 -10
  305. package/esm2022/lib/components/add-task/add-task.component.mjs +0 -561
  306. package/esm2022/lib/components/add-task/ascending-validator.mjs +0 -11
  307. package/esm2022/lib/components/add-task/create-task.data.mjs +0 -372
  308. package/esm2022/lib/components/add-task/create-task.interface.mjs +0 -2
  309. package/esm2022/lib/components/add-task/unique-string-validator.mjs +0 -10
  310. package/esm2022/lib/components/add-task/whitespace-validator.mjs +0 -10
  311. package/esm2022/lib/components/approval-popup/approval-popup.component.mjs +0 -30
  312. package/esm2022/lib/components/checklist/checklist.component.mjs +0 -327
  313. package/esm2022/lib/components/checklist-configure/assign/assign.component.mjs +0 -912
  314. package/esm2022/lib/components/checklist-configure/checklist-configure.component.mjs +0 -4161
  315. package/esm2022/lib/components/checklistlayout/checklistlayout.component.mjs +0 -44
  316. package/esm2022/lib/components/chip-dropdown/chip-dropdown.component.mjs +0 -120
  317. package/esm2022/lib/components/create-task/create-task.component.mjs +0 -585
  318. package/esm2022/lib/components/create-task/create-task.data.mjs +0 -372
  319. package/esm2022/lib/components/create-task/create-task.interface.mjs +0 -2
  320. package/esm2022/lib/components/create-task/validators/ascending-validator.mjs +0 -11
  321. package/esm2022/lib/components/create-task/validators/unique-string-validator.mjs +0 -10
  322. package/esm2022/lib/components/create-task/validators/whitespace-validator.mjs +0 -10
  323. package/esm2022/lib/components/custom-select/custom-select.component.mjs +0 -240
  324. package/esm2022/lib/components/dashboard/dashboard.component.mjs +0 -532
  325. package/esm2022/lib/components/dashboard-info/dashboard-info.component.mjs +0 -741
  326. package/esm2022/lib/components/dashboard-info/monthlyperformance-datepicker/monthlyperformance-datepicker.component.mjs +0 -155
  327. package/esm2022/lib/components/dashboard-layout/dashboard-layout.component.mjs +0 -12
  328. package/esm2022/lib/components/disabled-select/disabled-select.component.mjs +0 -158
  329. package/esm2022/lib/components/export-gallery/export-gallery.component.mjs +0 -266
  330. package/esm2022/lib/components/eye-test-audit/chip-dropdown/chip-dropdown.component.mjs +0 -105
  331. package/esm2022/lib/components/eye-test-audit/custom-select/custom-select.component.mjs +0 -240
  332. package/esm2022/lib/components/eye-test-audit/eye-test/eye-test.component.mjs +0 -1733
  333. package/esm2022/lib/components/eye-test-audit/eye-test/send-alert/send-alert.component.mjs +0 -24
  334. package/esm2022/lib/components/eye-test-audit/eye-test-audit/eye-test-audit-routing.module.mjs +0 -34
  335. package/esm2022/lib/components/eye-test-audit/eye-test-audit/eye-test-audit.component.mjs +0 -27
  336. package/esm2022/lib/components/eye-test-audit/eye-test-audit/eye-test-audit.module.mjs +0 -71
  337. package/esm2022/lib/components/eye-test-audit/eye-test-audit/settings-audit/settings-audit.component.mjs +0 -823
  338. package/esm2022/lib/components/eye-test-audit/eye-test-audit/start-audit/start-audit.component.mjs +0 -412
  339. package/esm2022/lib/components/eye-test-audit/group-select/group-select.component.mjs +0 -157
  340. package/esm2022/lib/components/eye-test-audit/reactive-select/reactive-select.component.mjs +0 -105
  341. package/esm2022/lib/components/eye-test-audit/select-drop/select-drop.component.mjs +0 -162
  342. package/esm2022/lib/components/eye-test-audit/services/eye-test-audit.service.mjs +0 -166
  343. package/esm2022/lib/components/flag-layout/flag-layout.component.mjs +0 -12
  344. package/esm2022/lib/components/flags/flags.component.mjs +0 -263
  345. package/esm2022/lib/components/flags/flags.interface.mjs +0 -2
  346. package/esm2022/lib/components/flags-info/flags-info.component.mjs +0 -452
  347. package/esm2022/lib/components/flags-info/flags-info.interface.mjs +0 -2
  348. package/esm2022/lib/components/flags-info/unattended-pie-chart/unattended-pie-chart.component.mjs +0 -71
  349. package/esm2022/lib/components/flags-new/flags-new.component.mjs +0 -335
  350. package/esm2022/lib/components/flags-new/flags-new.interface.mjs +0 -2
  351. package/esm2022/lib/components/gallery/gallery.component.mjs +0 -3402
  352. package/esm2022/lib/components/group-select/group-select.component.mjs +0 -155
  353. package/esm2022/lib/components/image-popup/image-popup.component.mjs +0 -25
  354. package/esm2022/lib/components/lib/custom-select/custom-select.component.mjs +0 -158
  355. package/esm2022/lib/components/manage-task/manage-task.component.mjs +0 -264
  356. package/esm2022/lib/components/managechecklist/managechecklist.component.mjs +0 -186
  357. package/esm2022/lib/components/multi-chip-dropdown/multi-chip-dropdown.component.mjs +0 -229
  358. package/esm2022/lib/components/multi-date-datepicker/multi-date-datepicker.component.mjs +0 -124
  359. package/esm2022/lib/components/orders/orders.component.mjs +0 -171
  360. package/esm2022/lib/components/pagination/pagination.component.mjs +0 -62
  361. package/esm2022/lib/components/reactive-select/reactive-select.component.mjs +0 -108
  362. package/esm2022/lib/components/reports/date-picker/date-picker.component.mjs +0 -60
  363. package/esm2022/lib/components/reports/reports.component.mjs +0 -300
  364. package/esm2022/lib/components/reports/reports.interface.mjs +0 -2
  365. package/esm2022/lib/components/tango-analyse-trax/tango-analyse-trax.component.mjs +0 -32
  366. package/esm2022/lib/components/task/task.component.mjs +0 -341
  367. package/esm2022/lib/components/task-configure/task-configure.component.mjs +0 -1532
  368. package/esm2022/lib/components/task-configure/task-configure.interface.mjs +0 -2
  369. package/esm2022/lib/components/task-info/task-info.component.mjs +0 -375
  370. package/esm2022/lib/components/task-info/taskinfo-edit/taskinfo-edit.component.mjs +0 -208
  371. package/esm2022/lib/components/task-layout/task-layout.component.mjs +0 -12
  372. package/esm2022/lib/components/task-logs/task-logs.component.mjs +0 -104
  373. package/esm2022/lib/components/trax-run-ai-popup/trax-run-ai-popup.component.mjs +0 -107
  374. package/esm2022/lib/components/trax-store/trax-store.component.mjs +0 -179
  375. package/esm2022/lib/components/traxpopup/traxpopup.component.mjs +0 -70
  376. package/esm2022/lib/services/trax.service.mjs +0 -559
  377. package/esm2022/lib/tango-analyse-trax-routing.module.mjs +0 -153
  378. package/esm2022/lib/tango-analyse-trax.module.mjs +0 -221
  379. package/esm2022/public-api.mjs +0 -6
  380. package/esm2022/tango-app-ui-analyse-trax.mjs +0 -5
  381. package/fesm2022/tango-app-ui-analyse-trax.mjs +0 -28896
  382. package/fesm2022/tango-app-ui-analyse-trax.mjs.map +0 -1
  383. package/index.d.ts +0 -5
  384. package/lib/components/action-centre/action-centre.component.d.ts +0 -68
  385. package/lib/components/activity-log/activity-log.component.d.ts +0 -39
  386. package/lib/components/activity-log-v2/activity-log-v2.component.d.ts +0 -78
  387. package/lib/components/activity-log-v2/log-view-popup/date-range-picker/date-range-picker.component.d.ts +0 -24
  388. package/lib/components/activity-log-v2/log-view-popup/store-user-dropdown/store-user-dropdown.component.d.ts +0 -9
  389. package/lib/components/activity-log-v2/log-view-popup/view-action/view-action.component.d.ts +0 -34
  390. package/lib/components/add-checklist/add-checklist.component.d.ts +0 -121
  391. package/lib/components/add-checklist/checklist-popup/checklist-popup.component.d.ts +0 -45
  392. package/lib/components/add-checklist/counter/counter.component.d.ts +0 -29
  393. package/lib/components/add-multitask/add-multitask.component.d.ts +0 -102
  394. package/lib/components/add-multitask/ascending-validator.d.ts +0 -2
  395. package/lib/components/add-multitask/bulkcreationmodel/bulkcreationmodel.component.d.ts +0 -45
  396. package/lib/components/add-multitask/create-task.data.d.ts +0 -293
  397. package/lib/components/add-multitask/create-task.interface.d.ts +0 -159
  398. package/lib/components/add-multitask/unique-string-validator.d.ts +0 -2
  399. package/lib/components/add-multitask/whitespace-validator.d.ts +0 -2
  400. package/lib/components/add-task/add-task.component.d.ts +0 -89
  401. package/lib/components/add-task/ascending-validator.d.ts +0 -2
  402. package/lib/components/add-task/create-task.data.d.ts +0 -293
  403. package/lib/components/add-task/create-task.interface.d.ts +0 -161
  404. package/lib/components/add-task/unique-string-validator.d.ts +0 -2
  405. package/lib/components/add-task/whitespace-validator.d.ts +0 -2
  406. package/lib/components/approval-popup/approval-popup.component.d.ts +0 -14
  407. package/lib/components/checklist/checklist.component.d.ts +0 -40
  408. package/lib/components/checklist-configure/assign/assign.component.d.ts +0 -105
  409. package/lib/components/checklist-configure/checklist-configure.component.d.ts +0 -325
  410. package/lib/components/checklistlayout/checklistlayout.component.d.ts +0 -15
  411. package/lib/components/chip-dropdown/chip-dropdown.component.d.ts +0 -28
  412. package/lib/components/create-task/create-task.component.d.ts +0 -76
  413. package/lib/components/create-task/create-task.data.d.ts +0 -293
  414. package/lib/components/create-task/create-task.interface.d.ts +0 -163
  415. package/lib/components/create-task/validators/ascending-validator.d.ts +0 -2
  416. package/lib/components/create-task/validators/unique-string-validator.d.ts +0 -2
  417. package/lib/components/create-task/validators/whitespace-validator.d.ts +0 -2
  418. package/lib/components/custom-select/custom-select.component.d.ts +0 -35
  419. package/lib/components/dashboard/dashboard.component.d.ts +0 -80
  420. package/lib/components/dashboard-info/dashboard-info.component.d.ts +0 -117
  421. package/lib/components/dashboard-info/monthlyperformance-datepicker/monthlyperformance-datepicker.component.d.ts +0 -41
  422. package/lib/components/dashboard-layout/dashboard-layout.component.d.ts +0 -5
  423. package/lib/components/disabled-select/disabled-select.component.d.ts +0 -34
  424. package/lib/components/export-gallery/export-gallery.component.d.ts +0 -44
  425. package/lib/components/eye-test-audit/chip-dropdown/chip-dropdown.component.d.ts +0 -26
  426. package/lib/components/eye-test-audit/custom-select/custom-select.component.d.ts +0 -35
  427. package/lib/components/eye-test-audit/eye-test/eye-test.component.d.ts +0 -218
  428. package/lib/components/eye-test-audit/eye-test/send-alert/send-alert.component.d.ts +0 -12
  429. package/lib/components/eye-test-audit/eye-test-audit/eye-test-audit-routing.module.d.ts +0 -7
  430. package/lib/components/eye-test-audit/eye-test-audit/eye-test-audit.component.d.ts +0 -11
  431. package/lib/components/eye-test-audit/eye-test-audit/eye-test-audit.module.d.ts +0 -21
  432. package/lib/components/eye-test-audit/eye-test-audit/settings-audit/settings-audit.component.d.ts +0 -129
  433. package/lib/components/eye-test-audit/eye-test-audit/start-audit/start-audit.component.d.ts +0 -86
  434. package/lib/components/eye-test-audit/group-select/group-select.component.d.ts +0 -33
  435. package/lib/components/eye-test-audit/reactive-select/reactive-select.component.d.ts +0 -32
  436. package/lib/components/eye-test-audit/select-drop/select-drop.component.d.ts +0 -33
  437. package/lib/components/eye-test-audit/services/eye-test-audit.service.d.ts +0 -47
  438. package/lib/components/flag-layout/flag-layout.component.d.ts +0 -5
  439. package/lib/components/flags/flags.component.d.ts +0 -52
  440. package/lib/components/flags-info/flags-info.component.d.ts +0 -73
  441. package/lib/components/flags-info/flags-info.interface.d.ts +0 -430
  442. package/lib/components/flags-info/unattended-pie-chart/unattended-pie-chart.component.d.ts +0 -13
  443. package/lib/components/flags-new/flags-new.component.d.ts +0 -60
  444. package/lib/components/gallery/gallery.component.d.ts +0 -261
  445. package/lib/components/group-select/group-select.component.d.ts +0 -33
  446. package/lib/components/image-popup/image-popup.component.d.ts +0 -11
  447. package/lib/components/lib/custom-select/custom-select.component.d.ts +0 -33
  448. package/lib/components/manage-task/manage-task.component.d.ts +0 -47
  449. package/lib/components/managechecklist/managechecklist.component.d.ts +0 -33
  450. package/lib/components/multi-chip-dropdown/multi-chip-dropdown.component.d.ts +0 -40
  451. package/lib/components/multi-date-datepicker/multi-date-datepicker.component.d.ts +0 -27
  452. package/lib/components/orders/orders.component.d.ts +0 -38
  453. package/lib/components/pagination/pagination.component.d.ts +0 -16
  454. package/lib/components/reactive-select/reactive-select.component.d.ts +0 -32
  455. package/lib/components/reports/date-picker/date-picker.component.d.ts +0 -23
  456. package/lib/components/reports/reports.component.d.ts +0 -55
  457. package/lib/components/tango-analyse-trax/tango-analyse-trax.component.d.ts +0 -14
  458. package/lib/components/task/task.component.d.ts +0 -70
  459. package/lib/components/task-configure/task-configure.component.d.ts +0 -142
  460. package/lib/components/task-configure/task-configure.interface.d.ts +0 -128
  461. package/lib/components/task-info/task-info.component.d.ts +0 -76
  462. package/lib/components/task-info/taskinfo-edit/taskinfo-edit.component.d.ts +0 -61
  463. package/lib/components/task-layout/task-layout.component.d.ts +0 -5
  464. package/lib/components/task-logs/task-logs.component.d.ts +0 -27
  465. package/lib/components/trax-run-ai-popup/trax-run-ai-popup.component.d.ts +0 -26
  466. package/lib/components/trax-store/trax-store.component.d.ts +0 -45
  467. package/lib/components/traxpopup/traxpopup.component.d.ts +0 -24
  468. package/lib/services/trax.service.d.ts +0 -175
  469. package/lib/tango-analyse-trax-routing.module.d.ts +0 -7
  470. package/lib/tango-analyse-trax.module.d.ts +0 -68
@@ -0,0 +1,2460 @@
1
+ import { ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
2
+ import { FormGroup, FormControl, Validators, FormArray, FormBuilder, Form, AbstractControl } from '@angular/forms';
3
+ import { GlobalStateService, PageInfoService } from 'tango-app-ui-global';
4
+ import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
5
+ import { timer,takeUntil, Subject } from 'rxjs';
6
+ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
7
+ import { TraxpopupComponent } from '../traxpopup/traxpopup.component';
8
+ import { ActivatedRoute,Router } from '@angular/router';
9
+ import { ToastService } from 'tango-app-ui-shared';
10
+ import { TraxService } from '../../services/trax.service';
11
+ import { noWhitespaceValidator } from '../create-task/validators/whitespace-validator';
12
+ import { uniqueStringValidator } from '../create-task/validators/unique-string-validator';
13
+ import { rangeValidator } from '../create-task/validators/ascending-validator';
14
+ import { TraxRunAIPopupComponent } from '../trax-run-ai-popup/trax-run-ai-popup.component';
15
+ import dayjs from 'dayjs';
16
+ import { ChecklistPopupComponent } from './checklist-popup/checklist-popup.component';
17
+ import customParseFormat from 'dayjs/plugin/customParseFormat';
18
+ import utc from 'dayjs/plugin/utc.js';
19
+ import timeZone from 'dayjs/plugin/timezone.js';
20
+ dayjs.extend(timeZone);
21
+ dayjs.extend(utc);
22
+ dayjs.extend(customParseFormat);
23
+
24
+
25
+ @Component({
26
+ selector: 'lib-add-checklist',
27
+ templateUrl: './add-checklist.component.html',
28
+ styleUrl: './add-checklist.component.scss'
29
+ })
30
+ export class AddChecklistComponent implements OnInit,OnDestroy {
31
+ @ViewChild('formRef') formRef: ElementRef;
32
+
33
+ ChecklistForm!: FormGroup;
34
+ show: number = 0;
35
+ sectionIndex: number = 0;
36
+ getobject: any;
37
+ editvalue: any;
38
+ nosection:boolean = false;
39
+ showvalue: string;
40
+ refImgQIdx: number = 0;
41
+ checklistLoading: boolean = false;
42
+ popupCount:number = 0;
43
+ clientId:any;
44
+ deletedList:any = [];
45
+ environment:any;
46
+ userType: any;
47
+ maxSectionNumber: any;
48
+ dropdownValue:any =[-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10];
49
+ dayjs = dayjs;
50
+ private detach = new Subject();
51
+ constructor(private pageInfo:PageInfoService,private fb: FormBuilder,private changedetector:ChangeDetectorRef,private dialog:NgbModal,private route:ActivatedRoute,private toast:ToastService,private router:Router,private sopService:TraxService,private gs:GlobalStateService) {
52
+ }
53
+
54
+ ngOnInit(): void {
55
+ this.initChecklist();
56
+ this.setPageData();
57
+ let storageDetails = JSON.parse(localStorage.getItem('header-filters') || '{}');
58
+
59
+ let userInfo = JSON.parse(localStorage.getItem('user-info') || '{}')
60
+ if(userInfo.userType){
61
+ this.userType = userInfo.userType;
62
+ }
63
+
64
+ if(!storageDetails?.client) {
65
+ storageDetails = JSON.parse(localStorage.getItem('client-details') || '{}');
66
+ storageDetails.client = storageDetails.clientId;
67
+ }
68
+ if(storageDetails?.client) {
69
+ this.clientId = storageDetails.client;
70
+ this.route.queryParams.subscribe((params: any) => {
71
+ this.editvalue = params.checklistId;
72
+ if (params.checklistId) {
73
+ this.showvalue = 'edit';
74
+ } else {
75
+ // Open Popup for Get Checklist Name //
76
+
77
+ this.showvalue = 'add'
78
+ }
79
+ if (this.showvalue == 'edit' || params.type) {
80
+ let obj: any = {};
81
+ if (params.checklistId) {
82
+ obj.checkListId = params.checklistId
83
+ } else {
84
+ obj.type = params.type;
85
+ }
86
+ obj.clientId = this.clientId;
87
+ this.checklistLoading = true;
88
+ this.sopService.getconfig(obj).pipe(takeUntil(this.detach))
89
+ .subscribe((res: any) => {
90
+ if(res) {
91
+ if(res.code == 200) {
92
+ this.getobject = res.data.checkListDetails;
93
+ this.formChecklistQuestions();
94
+ } else {
95
+ this.checklistLoading = false;
96
+ }
97
+ } else {
98
+ this.checklistLoading = false;
99
+ }
100
+ },(error) => {
101
+ this.checklistLoading = false;
102
+ });
103
+ } else {
104
+ this.initChecklist();
105
+ }
106
+ });
107
+ }
108
+ this.gs.environment.pipe(takeUntil(this.detach)).subscribe((env) => {
109
+ if (env) {
110
+ this.environment = env;
111
+ }
112
+ });
113
+ }
114
+
115
+ ngOnDestroy(): void {
116
+ this.detach.next(true);
117
+ this.detach.complete();
118
+ }
119
+
120
+ setPageData() {
121
+ this.pageInfo.setTitle("Manage Checklist");
122
+ this.pageInfo.setDescription("Automate or create checklists to improve operational efficiency");
123
+ this.pageInfo.setBreadcrumbs([
124
+ { title: "Tango Trax", path: "/manage/trax/dashboard", isActive: false, isSeparator: false },
125
+ { title: "Tango Trax", path: "/manage/trax/dashboard", isActive: false, isSeparator: true }
126
+ ]);
127
+ }
128
+
129
+ updateInputValue(sectionIndex: number,sectionName: string): void {
130
+ if (sectionName.trim() === '') {
131
+ this.getSectionFormControl(sectionIndex,'name')?.setValue(`Section ${sectionIndex+1}`);
132
+ }
133
+ }
134
+ scrollToQuestion(sectionIndex: number, questionIndex: number): void {
135
+ const questionId = `q-${sectionIndex}-${questionIndex}`;
136
+ setTimeout(() => {
137
+ const questionElement = this.formRef.nativeElement.querySelector(`#${questionId}`);
138
+
139
+ if (questionElement) {
140
+ questionElement.scrollIntoView({ block: 'center', behavior: 'smooth' });
141
+ }
142
+ }, 100);
143
+ }
144
+
145
+ formChecklistQuestions() {
146
+ let sectionsarray: any = [];
147
+ let sections: any[] = [];
148
+ sectionsarray = this.getobject.sections
149
+
150
+ this.maxSectionNumber = Math.max(...sectionsarray.map((ele:any) => ele.sectionNumber ));
151
+ // console.log("this.maxSectionNumber 1=>", this.maxSectionNumber)
152
+ sectionsarray.forEach((i: any,sectionIndex: number) => {
153
+ let questions: any[] = [];
154
+ let sectionNumber = i?.sectionNumber || (sectionIndex + 1)
155
+ i.questions.forEach((j: any,questionIndex: number) => {
156
+ let answer: any[] = [];
157
+ // Normalize stale data: runAI cannot be true without features. Strip the orphan flag so
158
+ // the question doesn't get locked (disableRunAI) by data that can no longer be re-edited.
159
+ j.answers?.forEach((k: any) => {
160
+ if (k?.runAI && (!Array.isArray(k.runAIFeatures) || !k.runAIFeatures.length)) {
161
+ k.runAI = false;
162
+ }
163
+ });
164
+ if (j?.runAI && !j.answers?.some((a: any) => a?.runAI)) {
165
+ j.runAI = false;
166
+ }
167
+ let runAI:any[] = j.answers.filter((ele:any) => ele.runAI);
168
+ // console.log("runAI =>", runAI)
169
+ j.answers?.forEach((k: any,answerIndex: number) => {
170
+ // if(typeof k?.referenceImage =='string' && k?.referenceImage != '' && k.multiReferenceImage.length) {
171
+ // k.multiReferenceImage = [{imageURL:k?.referenceImage,runAI:false}]
172
+ // }
173
+ answer.push(
174
+ this.fb.group({
175
+ ...(!['image','descriptiveImage','multipleImage','linearscale','time','date','image/video'].includes(j?.answerType) && j?.answerType != 'video'? { 'answer': this.fb.control({value:k?.answer,disabled: (this.userType === 'client' ? runAI.length : false) }, [Validators.required,noWhitespaceValidator()]) } : {}),
176
+ 'answeroptionNumber': this.fb.control(answerIndex),
177
+ ...(!['image','descriptiveImage','multipleImage','linearscale'].includes(j?.answerType) && j?.answerType != 'video'? { 'sopFlag': this.fb.control(k?.sopFlag ? k?.sopFlag : false, [Validators.required]) } : {}),
178
+ ...(!['image','descriptiveImage','multipleImage','linearscale'].includes(j?.answerType) && j?.answerType != 'video'? { 'validation': this.fb.control({value:k?.validation,disabled: (this.userType === 'client' ? runAI.length : false) }, [Validators.required]) } : {}),
179
+ ...(!['image','descriptiveImage','multipleImage','linearscale'].includes(j?.answerType) && j?.answerType != 'video'? { 'validationType': this.fb.control({value:k?.validationType,disabled: (this.userType === 'client' ? runAI.length : false) }, this.allowedValuesValidator(["Capture Image", "Capture Multiple Image with description", "Descriptive Answer", "Capture Video"])) } : {}),
180
+ ...(['image','descriptiveImage','multipleImage'].includes(j?.answerType) ? { "multiReferenceImage": this.fb.array(k?.multiReferenceImage || [] ) } : {}),
181
+ ...((['image','descriptiveImage','multipleImage','image/video'].includes(j?.answerType) || j?.answerType == 'video') ? { 'allowUploadfromGallery': this.fb.control({value:j?.allowUploadfromGallery ? true : false,disabled:!!runAI.length}) } : {}),
182
+ ...(['image','descriptiveImage','multipleImage','image/video'].includes(j?.answerType) ? { 'runAI': this.fb.control({value:(k?.runAI) ? k?.runAI : false,disabled: (this.userType === 'client' ? runAI.length : false) }) } : {}),
183
+ ...(['multiplechoicesingle','yes/no'].includes(j?.answerType) ? { 'showLinked': this.fb.control((k?.showLinked) ? k?.showLinked : false) } : {}),
184
+ ...(['multiplechoicesingle','yes/no'].includes(j?.answerType) ? { 'linkedQuestion': this.fb.control((k?.linkedQuestion) ? k?.linkedQuestion : 0) } : {}),
185
+ ...(!['descriptive','image', 'descriptiveImage','multipleImage','date'].includes(j?.answerType) ? { "multiReferenceImage": this.fb.array(k?.multiReferenceImage || [] ) } : {}),
186
+ ...((!['descriptive','image', 'descriptiveImage','video','multipleImage','date','image/video'].includes(j?.answerType)) ? { 'allowUploadfromGallery': this.fb.control({value:k?.allowUploadfromGallery ? true : false,disabled:!!runAI.length}) } : {}),
187
+ ...(!['descriptive','image', 'descriptiveImage','multipleImage','date','image/video'].includes(j?.answerType) ? { 'runAI': this.fb.control({value:(k?.runAI) ? k?.runAI : false,disabled: (this.userType === 'client' ? runAI.length : false) }) } : {}),
188
+ ...(!['date','linearscale','time'].includes(j?.answerType) ? { 'descriptivetype':this.fb.control(k.descriptivetype) } : {}),
189
+ ...(['linearscale'].includes(j?.answerType) ? { 'rangeStart':this.fb.control(k.rangeStart),'rangeEnd':this.fb.control(k.rangeEnd),'minValue':this.fb.control(k.minValue),'maxValue':this.fb.control(k.maxValue),'linearType':this.fb.control(k.linearType) } : {}),
190
+ ...(['date'].includes(j?.answerType) ? { 'historicDate':this.fb.control(k.historicDate),'startDate':this.fb.control(k.startDate),'endDate':this.fb.control(k.endDate)} : {}),
191
+ referenceImage:k?.referenceImage ?? '',
192
+ ...(['image/video'].includes(j?.answerType) && { 'limit':this.fb.control(k.limit),'imageLimit':this.fb.control(k.imageLimit),'videoLimit':this.fb.control(k.videoLimit)}),
193
+ ...(['image','image/video','linearscale','date'].includes(j?.answerType) && { 'matchedCount':this.fb.control(parseInt(k.matchedCount)),'notMatchedCount':this.fb.control(parseInt(k.notMatchedCount))}),
194
+ ...(['multiplechoicesingle','yes/no','multiplechoicemultiple'].includes(j?.answerType) ? { 'complianceScore': this.fb.control(parseInt(k?.complianceScore)) } : {}),
195
+
196
+ "runAIFeatures":this.fb.array(k?.runAIFeatures || []),
197
+ 'runAIDescription': this.fb.control(k?.runAIDescription || ''),
198
+ ...(['date'].includes(j?.answerType) && {
199
+ "qnStartDate": [{
200
+ "startDate": this.dayjs(k.startDate,'DD-MM-YYYY'),
201
+ "endDate": this.dayjs(k.startDate,'DD-MM-YYYY')
202
+ }],
203
+ "qnEndDate": [{
204
+ "startDate": this.dayjs(k.endDate,'DD-MM-YYYY'),
205
+ "endDate": this.dayjs(k.endDate,'DD-MM-YYYY')
206
+ }]
207
+ })
208
+ }, (['linearscale'].includes(j?.answerType) ? { validators: [rangeValidator()] } : {})));
209
+ });
210
+ // if(typeof j.questionReferenceImage == 'string' && j.questionReferenceImage != '') {
211
+ // j.multiQuestionReferenceImage = [{imageURL:j.questionReferenceImage,runAI:false}];
212
+ // }
213
+ questions.push(
214
+ this.fb.group({
215
+ "qno": this.fb.control(questionIndex+1),
216
+ 'qname': this.fb.control({value:j?.qname,disabled:runAI.length}, [Validators.required,noWhitespaceValidator()]),
217
+ "oldQname":this.fb.control(j?.qname, [Validators.required,noWhitespaceValidator()]),
218
+ 'answerType': this.fb.control({value:j?.answerType,disabled:runAI.length}, this.allowedValuesValidator(["descriptive", "yes/no", "multiplechoicesingle", "multiplechoicemultiple", "image", "video","descriptiveImage","multipleImage",'date','linearscale','time','image/video','dropdown'])),
219
+ ...(!['descriptive'].includes(j?.answerType)) ? { 'answers': (['image','descriptiveImage', 'video','multipleImage','time','linearscale','date','image/video'].includes(j?.answerType)) ? answer[0] : this.fb.array(answer,[uniqueStringValidator()]) } : {},
220
+ 'runAI': this.fb.control({value:(['image','descriptiveImage',"multipleImage","image/video"].includes(j?.answerType)) ? (j?.runAI) ? true : false : false,disabled: !!runAI.length}, [Validators.required]),
221
+ 'runAIDefault':this.fb.control(j?.runAI || false),
222
+ 'allowUploadfromGallery': this.fb.control({value:(['image','descriptiveImage','video','multipleImage','image/video'].includes(j?.answerType)) ? (j?.allowUploadfromGallery) ? true : false : false,disabled:!!runAI.length}, [Validators.required]),
223
+ // 'runAIDescription': this.fb.control((['image','descriptiveImage','multipleImage'].includes(j?.answerType)) ? (j?.runAIDescription) : ''),
224
+ 'linkType': this.fb.control(j?.linkType),
225
+ "multiQuestionReferenceImage":this.fb.array(j?.multiQuestionReferenceImage || []),
226
+ // "multiQuestionReferenceImage": [[j?.questionReferenceImage ?? '']],
227
+ 'descriptivetype': this.fb.control({ value: j?.descriptivetype,disabled:!!runAI.length}),
228
+ questionReferenceImage:j?.questionReferenceImage ?? '',
229
+ "runAIFeatures":this.fb.array(j?.runAIFeatures || []),
230
+ disableRunAI:runAI.length ? true : false,
231
+ 'runAIDescription': this.fb.control(j?.runAIDescription || ''),
232
+ "uniqueqno": this.fb.control(j?.uniqueqno || 0),
233
+ "uniqueqid": this.fb.control(j?.uniqueqid || ''),
234
+ 'allowMultiple':this.fb.control(j?.allowMultiple ?? false),
235
+ 'compliance':this.fb.control({
236
+ value: j?.compliance ?? false,
237
+ disabled: ['image','image/video'].includes(j?.answerType) ? !j?.runAI : false
238
+ }),
239
+
240
+ })
241
+ );
242
+ });
243
+ sections.push(
244
+ this.fb.group({
245
+ "name": this.fb.control(i?.name, [Validators.required, Validators.minLength(1),noWhitespaceValidator()]),
246
+ "oldName":this.fb.control(i?.name, [Validators.required, Validators.minLength(1),noWhitespaceValidator()]),
247
+ "sectionNumber": this.fb.control(sectionNumber),
248
+ "questions": this.fb.array(questions),
249
+ "maxQuestionNumber": this.fb.control(i?.maxQuestionNumber || 0),
250
+ }));
251
+ questions = [];
252
+ });
253
+
254
+ this.ChecklistForm = this.fb.group({
255
+ 'checklistName': this.fb.control(this.getobject.checkListName, [Validators.required,noWhitespaceValidator()]),
256
+ 'checklistDescription': this.fb.control(this.getobject.checkListDescription),
257
+ 'sections': this.fb.array(sections)
258
+ });
259
+ sectionsarray.forEach((_: any, sectionIndex: number) => {
260
+ this.getobject.sections[sectionIndex]?.questions?.forEach((_: any, questionIndex: number) => {
261
+ if (this.hasValidationEnabled(sectionIndex, questionIndex)) {
262
+ ((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup)?.get('compliance')?.patchValue(false);
263
+ ((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup)?.get('compliance')?.disable({ emitEvent: false });
264
+ }
265
+ });
266
+ });
267
+ this.ChecklistForm.updateValueAndValidity();
268
+ this.checklistLoading = false;
269
+
270
+ console.log(this.ChecklistForm.value)
271
+
272
+ // console.log(this.ChecklistForm,'form');
273
+ }
274
+
275
+ initChecklist() {
276
+ this.ChecklistForm = this.fb.group({
277
+ 'checklistName': this.fb.control('', [Validators.required,noWhitespaceValidator()]),
278
+ 'checklistDescription': this.fb.control(''),
279
+ 'sections': this.fb.array([
280
+ this.fb.group({
281
+ "name": this.fb.control('Section 1', [Validators.required,Validators.minLength(1),noWhitespaceValidator()]),
282
+ "sectionNumber": this.fb.control(1, [Validators.required]),
283
+ "questions": this.fb.array([
284
+ this.fb.group({
285
+ "qno": this.fb.control(1, [Validators.required]),
286
+ 'qname': this.fb.control('', [Validators.required,noWhitespaceValidator()]),
287
+ 'answerType': this.fb.control('descriptive',
288
+ this.allowedValuesValidator(["descriptive", "yes/no", "multiplechoicesingle", "multiplechoicemultiple","descriptiveImage", "image", "video",'multipleImage','date','linearscale','time','image/video','dropdown'])),
289
+ 'runAI': this.fb.control(false, [Validators.required]),
290
+ 'runAIDescription': this.fb.control(''),
291
+ 'allowUploadfromGallery': this.fb.control(false, [Validators.required]),
292
+ 'linkType': this.fb.control(false, [Validators.required]),
293
+ "multiQuestionReferenceImage":this.fb.array([]),
294
+ 'descriptivetype':this.fb.control('text'),
295
+ 'questionReferenceImage':this.fb.control(''),
296
+ "runAIFeatures":this.fb.array([]),
297
+ "uniqueqno": this.fb.control(0),
298
+ "uniqueqid": this.fb.control(''),
299
+ 'allowMultiple':this.fb.control(false),
300
+ 'compliance':this.fb.control(false),
301
+ })
302
+ ]),
303
+ "maxQuestionNumber": this.fb.control(0),
304
+ })
305
+ ])
306
+ });
307
+ this.checklistLoading = false;
308
+ }
309
+
310
+ allowedValuesValidator(allowedValues: string[]) {
311
+ return (control: any) => {
312
+ const value = control.value;
313
+ if (value && allowedValues.indexOf(value) === -1) {
314
+ return { invalidValue: true };
315
+ }
316
+ return null;
317
+ };
318
+ }
319
+
320
+ addNewSection() {
321
+ let sections = this.ChecklistForm.get('sections') as FormArray;
322
+ let sectionLength = sections.length;
323
+ if(this.maxSectionNumber){
324
+ this.maxSectionNumber++;
325
+ }else{
326
+ this.maxSectionNumber = Math.max(...sections.value.map((ele:any) => ele.sectionNumber ))+1;
327
+ }
328
+ // console.log("this.maxSectionNumber =>", this.maxSectionNumber);
329
+
330
+ (this.ChecklistForm.get('sections') as FormArray).push(
331
+ this.fb.group({
332
+ "name": this.fb.control(`Section ${sectionLength + 1}`, [Validators.required,Validators.minLength(1),noWhitespaceValidator()]),
333
+ "sectionNumber": this.fb.control(this.maxSectionNumber, [Validators.required]),
334
+ // "sectionNumber": this.fb.control(findSecNum + 1, [Validators.required]),
335
+ "questions": this.fb.array([
336
+ this.fb.group({
337
+ "qno": this.fb.control(1, [Validators.required]),
338
+ 'qname': this.fb.control('', [Validators.required,noWhitespaceValidator()]),
339
+ 'answerType': this.fb.control('descriptive',
340
+ this.allowedValuesValidator(["descriptive", "yes/no", "multiplechoicesingle", "multiplechoicemultiple","descriptiveImage", "image", "video",'multipleImage','date','linearscale','time','image/video','dropdown'])),
341
+ 'runAI': this.fb.control(false, [Validators.required]),
342
+ 'runAIDescription': this.fb.control(''),
343
+ 'allowUploadfromGallery': this.fb.control(false, [Validators.required]),
344
+ 'linkType': this.fb.control(false, [Validators.required]),
345
+ "multiQuestionReferenceImage":this.fb.array([]),
346
+ 'descriptivetype':this.fb.control('text'),
347
+ 'questionReferenceImage':this.fb.control(''),
348
+ 'runAIFeatures':this.fb.array([]),
349
+ "uniqueqno": this.fb.control(0),
350
+ "uniqueqid": this.fb.control(''),
351
+ 'allowMultiple':this.fb.control(false),
352
+ 'compliance':this.fb.control(false)
353
+ })
354
+ ]),
355
+ "maxQuestionNumber": this.fb.control(0),
356
+ })
357
+ );
358
+ if(sectionLength == 0) {
359
+ this.show = -1;
360
+ }
361
+ this.accordian(sectionLength);
362
+ this.swalToast('New section added!');
363
+ }
364
+
365
+ removeSection(sectionIndex: number) {
366
+ (this.ChecklistForm.get('sections') as FormArray).removeAt(sectionIndex);
367
+ }
368
+
369
+ dragDrop(sectionIndex: any, event: CdkDragDrop<any[]>) {
370
+ if (event.previousContainer === event.container) {
371
+ moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
372
+ // this.updatelinkedQuestionNo(sectionIndex,event.previousIndex,event.currentIndex)
373
+ this.updateQuestionQnos(sectionIndex);
374
+ } else {
375
+ transferArrayItem(
376
+ event.previousContainer.data,
377
+ event.container.data,
378
+ event.previousIndex,
379
+ event.currentIndex
380
+ );
381
+ }
382
+ }
383
+
384
+ updatelinkedQuestionNo(secIdx:number,prevIdx:number,qnIdx:number) {
385
+ let questions = (this.getSectionFormArray().at(secIdx).get('questions') as FormArray);
386
+ for(let i=0;i<questions.length-1;i++) {
387
+ let answers = ((questions.at(i) as FormGroup).get('answers') as FormArray);
388
+ for(let j=0;j<answers?.length -1;j++) {
389
+ let linked = (answers.at(j) as FormGroup).get('showLinked')?.value;
390
+ if(linked) {
391
+ let linkedNo = (answers.at(j) as FormGroup).get('linkedQuestion')?.value;
392
+ if(linkedNo == prevIdx + 1) {
393
+ (answers.at(j) as FormGroup).get('linkedQuestion')?.setValue(qnIdx + 1);
394
+ }
395
+ else if(linkedNo <= qnIdx + 1) {
396
+ (answers.at(j) as FormGroup).get('linkedQuestion')?.setValue(linkedNo - 1);
397
+ }
398
+
399
+ }
400
+
401
+ }
402
+ }
403
+
404
+ }
405
+
406
+ answerTypeSelection(sectionIndex: any, questionIndex: any, event: any) {
407
+ let selectvalue: string = event.target.value;
408
+
409
+ (((((this.ChecklistForm.get('sections') as FormArray)
410
+ .at(sectionIndex) as FormGroup)
411
+ .get('questions') as FormArray)
412
+ .at(questionIndex) as FormGroup).get("multiQuestionReferenceImage") as FormArray)?.clear();
413
+ if(!['descriptive','multipleImage'].includes(selectvalue)) {
414
+ ((((this.ChecklistForm.get('sections') as FormArray)
415
+ .at(sectionIndex) as FormGroup)
416
+ .get('questions') as FormArray)
417
+ .at(questionIndex) as FormGroup).get('descriptivetype')?.setValue('');
418
+ }
419
+ else {
420
+ ((((this.ChecklistForm.get('sections') as FormArray)
421
+ .at(sectionIndex) as FormGroup)
422
+ .get('questions') as FormArray)
423
+ .at(questionIndex) as FormGroup).get('descriptivetype')?.setValue('text');
424
+ }
425
+ ((((this.ChecklistForm.get('sections') as FormArray)
426
+ .at(sectionIndex) as FormGroup)
427
+ .get('questions') as FormArray)
428
+ .at(questionIndex) as FormGroup).get('compliance')?.setValue(false);
429
+ this.removeQuestionLinked(sectionIndex,questionIndex);
430
+ if (['yes/no','multiplechoicesingle','multiplechoicemultiple','dropdown'].includes(selectvalue)) {
431
+ this.setAnswerAsFormArray(sectionIndex, questionIndex,selectvalue);
432
+ } else if (selectvalue == 'descriptive') {
433
+ } else if (['descriptiveImage','image','video','multipleImage',,'image/video'].includes(selectvalue)) {
434
+ this.setAnswerAsFormGroup(sectionIndex, questionIndex, selectvalue);
435
+ } else if (['date','time','linearscale'].includes(selectvalue)) {
436
+ this.setAnswerAsTime(sectionIndex, questionIndex, selectvalue);
437
+ }
438
+ }
439
+
440
+ setAnswerAsTime(secIdx:number,qnIdx:number,type:string) {
441
+ let question = ((((this.ChecklistForm.get('sections') as FormArray)
442
+ .at(secIdx) as FormGroup)
443
+ .get('questions') as FormArray)
444
+ .at(qnIdx) as FormGroup);
445
+ if(type == 'time') {
446
+ question.setControl('answers',
447
+ this.fb.group({
448
+ 'answer': this.fb.control(''),
449
+ 'answeroptionNumber': this.fb.control(1),
450
+ 'sopFlag': this.fb.control(false),
451
+ 'validation': this.fb.control(false),
452
+ 'validationType': this.fb.control(''),
453
+ 'linkedQuestion':this.fb.control(0),
454
+ 'showLinked':this.fb.control(false),
455
+ "multiReferenceImage": this.fb.array([]),
456
+ 'runAI': this.fb.control(false),
457
+ 'allowUploadfromGallery': this.fb.control(false),
458
+ 'descriptivetype':this.fb.control(''),
459
+ 'runAIFeatures':this.fb.array([]),
460
+ 'runAIDescription': this.fb.control(''),
461
+ }),
462
+ );
463
+ } else if(type == 'linearscale') {
464
+ const answersGroup = this.fb.group({
465
+ 'answer': this.fb.control(''),
466
+ 'answeroptionNumber': this.fb.control(1),
467
+ 'sopFlag': this.fb.control(false),
468
+ 'validation': this.fb.control(false),
469
+ 'validationType': this.fb.control(''),
470
+ 'linkedQuestion':this.fb.control(0),
471
+ 'showLinked':this.fb.control(false),
472
+ "multiReferenceImage": this.fb.array([]),
473
+ 'runAI': this.fb.control(false),
474
+ 'allowUploadfromGallery': this.fb.control(false),
475
+ 'descriptivetype':this.fb.control('number'),
476
+ 'rangeStart':this.fb.control(0),
477
+ 'rangeEnd':this.fb.control(100),
478
+ 'runAIFeatures':this.fb.array([]),
479
+ 'runAIDescription': this.fb.control(''),
480
+ 'linearType':this.fb.control('number'),
481
+ 'minValue':this.fb.control(0),
482
+ 'maxValue':this.fb.control(100),
483
+ 'matchedCount':this.fb.control(0),
484
+ 'notMatchedCount':this.fb.control(0),
485
+ }, { validators: rangeValidator() });
486
+ question.setControl('answers', answersGroup);
487
+ } else {
488
+ question.setControl('answers',
489
+ this.fb.group({
490
+ 'answer': this.fb.control(''),
491
+ 'answeroptionNumber': this.fb.control(1),
492
+ 'sopFlag': this.fb.control(false),
493
+ 'validation': this.fb.control(false),
494
+ 'validationType': this.fb.control(''),
495
+ 'linkedQuestion':this.fb.control(0),
496
+ 'showLinked':this.fb.control(false),
497
+ "multiReferenceImage": this.fb.array([]),
498
+ 'runAI': this.fb.control(false),
499
+ 'allowUploadfromGallery': this.fb.control(false),
500
+ 'historicDate': this.fb.control(false),
501
+ 'descriptivetype':this.fb.control('number'),
502
+ 'runAIFeatures':this.fb.array([]),
503
+ 'runAIDescription': this.fb.control(''),
504
+ 'startDate': this.fb.control(this.dayjs().format('DD-MM-YYYY')),
505
+ 'endDate': this.fb.control(this.dayjs().format('DD-MM-YYYY')),
506
+ 'matchedCount':this.fb.control(0),
507
+ 'notMatchedCount':this.fb.control(0),
508
+ 'qnStartDate': this.fb.control({}),
509
+ 'qnEndDate': this.fb.control({}),
510
+ }),
511
+ );
512
+ }
513
+
514
+
515
+
516
+ // console.log(question);
517
+
518
+ }
519
+
520
+ removeQuestionLinked(secIdx:any,qnIdx:any) {
521
+ let answers = (((this.getSectionFormArray().at(secIdx).get('questions') as FormArray).at(qnIdx) as FormGroup).get('answers') as FormArray);
522
+ if(answers) {
523
+ for(let i=0;i<answers.length;i++){
524
+ let qn = (answers.at(i) as FormGroup).get('linkedQuestion')?.value;
525
+ if(qn) {
526
+ ((this.getSectionFormArray().at(secIdx).get('questions') as FormArray).at(qn - 1) as FormGroup).get('linkType')?.setValue(false);
527
+ }
528
+
529
+ }
530
+ }
531
+ }
532
+
533
+ updateValidationType(event:any,section:number,question:number,answer:number) {
534
+ let questionInfo = ((((this.ChecklistForm.get('sections') as FormArray)
535
+ .at(section) as FormGroup)
536
+ .get('questions') as FormArray)
537
+ .at(question) as FormGroup).get('compliance')?.value;
538
+ let answers = (((((this.ChecklistForm.get('sections') as FormArray)
539
+ .at(section) as FormGroup)
540
+ .get('questions') as FormArray)
541
+ .at(question) as FormGroup).get('answers') as FormArray)?.value;
542
+ // if(!answers.some((ele:any) => ele.runAI) && questionInfo) {
543
+ // const dialogRef = this.dialog.open(TraxpopupComponent,{centered: true, size: 'md'});
544
+ // dialogRef.componentInstance.data = {
545
+ // imagesrc: `<span><svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="0 0 56 56" fill="none">
546
+ // <rect x="4" y="4" width="48" height="48" rx="24" fill="#FEF0C7"/>
547
+ // <rect x="4" y="4" width="48" height="48" rx="24" stroke="#FFFAEB" stroke-width="8"/>
548
+ // <path d="M27.9988 24.0012V28.0012M27.9988 32.0012H28.0088M26.2888 18.8612L17.8188 33.0012C17.6442 33.3036 17.5518 33.6465 17.5508 33.9957C17.5498 34.3449 17.6403 34.6883 17.8132 34.9917C17.9862 35.2951 18.2355 35.5479 18.5365 35.725C18.8375 35.9021 19.1796 35.9973 19.5288 36.0012H36.4688C36.818 35.9973 37.1601 35.9021 37.4611 35.725C37.7621 35.5479 38.0114 35.2951 38.1844 34.9917C38.3573 34.6883 38.4478 34.3449 38.4468 33.9957C38.4458 33.6465 38.3534 33.3036 38.1788 33.0012L29.7088 18.8612C29.5305 18.5673 29.2795 18.3243 28.98 18.1557C28.6805 17.987 28.3425 17.8984 27.9988 17.8984C27.6551 17.8984 27.3171 17.987 27.0176 18.1557C26.7181 18.3243 26.4671 18.5673 26.2888 18.8612Z" stroke="#DC6803" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
549
+ // </svg></span>`,
550
+ // title: `Disabling Compliance Score`,
551
+ // content: `By clicking and enable the validate response, the compliance score configured will be disabled since it works only for Capture Image with Run AI enabled. Are you sure to proceed?`,
552
+ // buttontype: "compliance",
553
+ // };
554
+ // dialogRef.result.then((res) => {
555
+ // if(res == 'confirm') {
556
+ // ((((this.ChecklistForm.get('sections') as FormArray).at(section) as FormGroup).get('questions') as FormArray).at(question) as FormGroup)?.get('compliance')?.patchValue(false);
557
+ // ((((this.ChecklistForm.get('sections') as FormArray).at(section) as FormGroup).get('questions') as FormArray).at(question) as FormGroup)?.get('compliance')?.disable({emitEvent:false});
558
+ // ((((this.ChecklistForm.get('sections') as FormArray).at(section) as FormGroup).get('questions') as FormArray).at(question) as FormGroup)?.get('complianceScore')?.patchValue(0);
559
+ // }
560
+ // });
561
+ // }
562
+ // if(answers.some((ele:any) => ele.runAI) && !this.hasValidationEnabled(section, question)) {
563
+ // ((((this.ChecklistForm.get('sections') as FormArray).at(section) as FormGroup).get('questions') as FormArray).at(question) as FormGroup)?.get('compliance')?.enable();
564
+ // }
565
+ const answerGroup = ((((((this.ChecklistForm.get('sections') as FormArray)
566
+ .at(section) as FormGroup)
567
+ .get('questions') as FormArray)
568
+ .at(question) as FormGroup).get('answers') as FormArray).at(answer) as FormGroup);
569
+ const validationTypeValue = answerGroup.get('validationType')?.value;
570
+ if(validationTypeValue === 'Descriptive Answer') {
571
+ answerGroup.get('descriptivetype')?.setValue('text');
572
+ }
573
+ ((((((this.ChecklistForm.get('sections') as FormArray)
574
+ .at(section) as FormGroup)
575
+ .get('questions') as FormArray)
576
+ .at(question) as FormGroup).get('answers') as FormArray).at(answer) as FormGroup).get('allowUploadfromGallery')?.setValue(false);
577
+ ((((((this.ChecklistForm.get('sections') as FormArray)
578
+ .at(section) as FormGroup)
579
+ .get('questions') as FormArray)
580
+ .at(question) as FormGroup).get('answers') as FormArray).at(answer) as FormGroup).get('runAI')?.setValue(false);
581
+ ((((((this.ChecklistForm.get('sections') as FormArray)
582
+ .at(section) as FormGroup)
583
+ .get('questions') as FormArray)
584
+ .at(question) as FormGroup).get('answers') as FormArray).at(answer) as FormGroup).get('runAIDescription')?.setValue('');
585
+ (((((((this.ChecklistForm.get('sections') as FormArray)
586
+ .at(section) as FormGroup)
587
+ .get('questions') as FormArray)
588
+ .at(question) as FormGroup).get('answers') as FormArray).at(answer) as FormGroup).get('runAIFeatures') as FormArray)?.clear();
589
+ (((((((this.ChecklistForm.get('sections') as FormArray)
590
+ .at(section) as FormGroup)
591
+ .get('questions') as FormArray)
592
+ .at(question) as FormGroup).get('answers') as FormArray).at(answer) as FormGroup).get('multiReferenceImage') as FormArray)?.clear();
593
+ }
594
+
595
+ setAnswerAsFormArray(sectionIndex: number, questionIndex: number,selectvalue: string) {
596
+ let question = ((((this.ChecklistForm.get('sections') as FormArray)
597
+ .at(sectionIndex) as FormGroup)
598
+ .get('questions') as FormArray)
599
+ .at(questionIndex) as FormGroup);
600
+
601
+ if (selectvalue == 'yes/no') {
602
+ question.setControl('answers',
603
+ this.fb.array([
604
+ this.fb.group({
605
+ 'answer': this.fb.control('Yes', [Validators.required,noWhitespaceValidator()]),
606
+ 'answeroptionNumber': this.fb.control(1),
607
+ 'sopFlag': this.fb.control(false, [Validators.required]),
608
+ // 'linkQuestion':this.fb.control(false,[Validators.required]),
609
+ // 'answerInputStyle': this.fb.control('radio',[Validators.required]),
610
+ 'validation': this.fb.control(false, [Validators.required]),
611
+ 'validationType': this.fb.control('Capture Image', this.allowedValuesValidator(["Capture Image", "Capture Multiple Image with description", "Descriptive Answer","Capture Video"])),
612
+ 'linkedQuestion':this.fb.control(0, [Validators.required]),
613
+ 'showLinked':this.fb.control(false, [Validators.required]),
614
+ "multiReferenceImage": this.fb.array([]),
615
+ 'runAI': this.fb.control(false),
616
+ 'allowUploadfromGallery': this.fb.control(false),
617
+ 'descriptivetype':this.fb.control(''),
618
+ "referenceImage":this.fb.control(''),
619
+ "runAIFeatures":this.fb.array([]),
620
+ 'runAIDescription': this.fb.control(''),
621
+ 'complianceScore':this.fb.control(0)
622
+ }),
623
+ this.fb.group({
624
+ 'answer': this.fb.control('No', [Validators.required,noWhitespaceValidator()]),
625
+ 'answeroptionNumber': this.fb.control(2),
626
+ 'sopFlag': this.fb.control(false, [Validators.required]),
627
+ 'validation': this.fb.control(false, [Validators.required]),
628
+ 'validationType': this.fb.control('Capture Image', this.allowedValuesValidator(["Capture Image", "Capture Multiple Image with description", "Descriptive Answer","Capture Video"])),
629
+ 'linkedQuestion':this.fb.control(0, [Validators.required]),
630
+ 'showLinked':this.fb.control(false, [Validators.required]),
631
+ "multiReferenceImage": this.fb.array([]),
632
+ 'runAI': this.fb.control(false),
633
+ 'allowUploadfromGallery': this.fb.control(false),
634
+ 'descriptivetype':this.fb.control(''),
635
+ "referenceImage":this.fb.control(''),
636
+ "runAIFeatures":this.fb.array([]),
637
+ 'runAIDescription': this.fb.control(''),
638
+ 'complianceScore':this.fb.control(0)
639
+ })
640
+ ],uniqueStringValidator())
641
+ );
642
+ } else {
643
+ question.setControl('answers',
644
+ this.fb.array([
645
+ this.fb.group({
646
+ 'answer': this.fb.control('', [Validators.required,noWhitespaceValidator()]),
647
+ 'answeroptionNumber': this.fb.control(1),
648
+ 'sopFlag': this.fb.control(false, [Validators.required]),
649
+ 'validation': this.fb.control(false, [Validators.required]),
650
+ 'validationType': this.fb.control('Capture Image', this.allowedValuesValidator(["Capture Image", "Capture Multiple Image with description", "Descriptive Answer","Capture Video"])),
651
+ ...(selectvalue == 'multiplechoicesingle' ? {"linkedQuestion":this.fb.control(0, [Validators.required]),'showLinked':this.fb.control(false, [Validators.required])} : {}),
652
+ "multiReferenceImage": this.fb.array([]),
653
+ 'runAI': this.fb.control(false),
654
+ 'allowUploadfromGallery': this.fb.control(false),
655
+ 'descriptivetype':this.fb.control(''),
656
+ "referenceImage":this.fb.control(''),
657
+ "runAIFeatures":this.fb.array([]),
658
+ 'runAIDescription': this.fb.control(''),
659
+ 'complianceScore':this.fb.control(0)
660
+ }),
661
+ this.fb.group({
662
+ 'answer': this.fb.control('', [Validators.required,noWhitespaceValidator()]),
663
+ 'answeroptionNumber': this.fb.control(1),
664
+ 'sopFlag': this.fb.control(false, [Validators.required]),
665
+ 'validation': this.fb.control(false, [Validators.required]),
666
+ 'validationType': this.fb.control('Capture Image', this.allowedValuesValidator(["Capture Image", "Capture Multiple Image with description", "Descriptive Answer","Capture Video"])),
667
+ ...(selectvalue == 'multiplechoicesingle' ? {"linkedQuestion":this.fb.control(0, [Validators.required]),'showLinked':this.fb.control(false, [Validators.required])} : {}),
668
+ "multiReferenceImage": this.fb.array([]),
669
+ 'runAI': this.fb.control(false),
670
+ 'allowUploadfromGallery': this.fb.control(false),
671
+ 'descriptivetype':this.fb.control(''),
672
+ "referenceImage":this.fb.control(''),
673
+ "runAIFeatures":this.fb.array([]),
674
+ 'runAIDescription': this.fb.control(''),
675
+ 'complianceScore':this.fb.control(0)
676
+ })
677
+ ],uniqueStringValidator()),
678
+ );
679
+ }
680
+ this.ChecklistForm.updateValueAndValidity();
681
+ }
682
+
683
+ setAnswerAsFormGroup(sectionIndex: number, questionIndex: number, answerType: string) {
684
+ let question = ((((this.ChecklistForm.get('sections') as FormArray)
685
+ .at(sectionIndex) as FormGroup)
686
+ .get('questions') as FormArray)
687
+ .at(questionIndex) as FormGroup)
688
+ if (['image', 'descriptiveImage','multipleImage','image/video'].includes(answerType)) {
689
+ if(['image','image/video'].includes(answerType)) {
690
+ question.get('compliance')?.disable({ emitEvent: false });
691
+ }
692
+ ((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup)
693
+ .get('questions') as FormArray).at(questionIndex) as FormGroup)
694
+ .setControl('answers',
695
+ this.fb.group({
696
+ "multiReferenceImage": this.fb.array([]),
697
+ "referenceImage":this.fb.control(''),
698
+ 'runAI': this.fb.control(false),
699
+ 'allowUploadfromGallery': this.fb.control(false),
700
+ ...(answerType == 'multipleImage' ? {'descriptivetype':this.fb.control('text')}:{}),
701
+ "runAIFeatures":this.fb.array([]),
702
+ 'runAIDescription': this.fb.control(''),
703
+ ...(answerType == 'image/video' && {limit:this.fb.control(false),videoLimit:this.fb.control(1),imageLimit:this.fb.control(1)}),
704
+ ...(['image','image/video'].includes(answerType) && {matchedCount:this.fb.control(0),notMatchedCount:this.fb.control(0)})
705
+ }));
706
+ } else {
707
+ question.setControl('answers', this.fb.group({
708
+ 'allowUploadfromGallery': this.fb.control(false),
709
+ })
710
+ )
711
+ }
712
+ this.ChecklistForm.updateValueAndValidity();
713
+ }
714
+
715
+ loadImageFromDevice(secIdx: number,qIdx: number,event: any,ansIdx:number=-1,ctrlName:string = '',imgIdx:number=-1) {
716
+ if (event.target.files != undefined && event.target.files.length) {
717
+ }
718
+ const input = event.target as HTMLInputElement;
719
+ let formData = new FormData();
720
+ let file: File = event.target.files[0];
721
+ formData.append('file', file, file.name);
722
+ formData.append('clientId',this.clientId)
723
+ this.sopService.imageupload(formData).pipe(takeUntil(this.detach)).subscribe((res: any) => {
724
+ input.value = '';
725
+ const sections = this.ChecklistForm.get('sections') as FormArray | null;
726
+ if (!sections) return null;
727
+
728
+ const section = sections.at(secIdx) as FormGroup | null;
729
+ if (!section) return null;
730
+
731
+ const questions = section.get('questions') as FormArray | null;
732
+ if (!questions) return null;
733
+
734
+ const question = questions.at(qIdx) as FormGroup | null;
735
+
736
+ if (!question) return null;
737
+ if(ctrlName) {
738
+ let refImages;
739
+ if(ctrlName == "multiQuestionReferenceImage") {
740
+ refImages = question.get(ctrlName) as FormArray;
741
+ }
742
+ else {
743
+ let answers
744
+ if(ansIdx != -1) {
745
+ answers = ((question.get('answers') as FormArray).at(ansIdx) as FormGroup);
746
+ }
747
+ else {
748
+ answers = question.get('answers') as FormGroup;
749
+ }
750
+ refImages = answers?.get("multiReferenceImage") as FormArray;
751
+ }
752
+ if(refImages) {
753
+ if(imgIdx != -1) {
754
+ (refImages?.at(imgIdx) as FormGroup)?.setValue({imageURL:res.data.imgUrl,runAI:false})
755
+ }
756
+ else {
757
+ refImages?.push(this.fb.group({imageURL:res.data.imgUrl,runAI:false}))
758
+ }
759
+ }
760
+ }
761
+ else{
762
+ this.getAnswerFormGroup_FormControl(secIdx,qIdx,"multiReferenceImage",ansIdx)?.setValue(res.data.imgUrl);
763
+ }
764
+
765
+ this.ChecklistForm.updateValueAndValidity();
766
+ this.changedetector.detectChanges();
767
+ })
768
+ }
769
+
770
+ clearReferenceImage(secIdx: number,qIdx: number,ansIdx:number=-1,imageIndex:number=-1,ctrlName:string="") {
771
+ // this.getAnswerFormGroup_FormControl(secIdx,qIdx,"referenceImage",ansIdx)?.setValue('');
772
+ // this.getAnswerFormGroup_FormControl(secIdx,qIdx,'runAI',ansIdx)?.setValue(false);
773
+ const sections = this.ChecklistForm.get('sections') as FormArray | null;
774
+ if (!sections) return null;
775
+
776
+ const section = sections.at(secIdx) as FormGroup | null;
777
+ if (!section) return null;
778
+
779
+ const questions = section.get('questions') as FormArray | null;
780
+ if (!questions) return null;
781
+
782
+ const question = questions.at(qIdx) as FormGroup | null;
783
+ if (!question) return null;
784
+ if(imageIndex != -1 && ctrlName) {
785
+ let refImages;
786
+ if(ctrlName == "multiQuestionReferenceImage") {
787
+ refImages = question.get(ctrlName) as FormArray;
788
+ }
789
+ else {
790
+ let answers;
791
+ if(ansIdx != -1) {
792
+ answers = ((question.get('answers') as FormArray).at(ansIdx) as FormGroup)
793
+ }
794
+ else {
795
+ answers = question.get('answers') as FormGroup;
796
+ }
797
+ refImages = answers.get(ctrlName) as FormArray;
798
+ }
799
+ refImages.removeAt(imageIndex);
800
+
801
+ }
802
+ else {
803
+ (question.get("multiReferenceImage") as FormArray)?.clear();
804
+ (question.get("multiQuestionReferenceImage") as FormArray)?.clear();
805
+ }
806
+ }
807
+
808
+ getvalidation(sectionIndex: any, questionIndex: any, addmoreqnIndex: any, event: any) {
809
+ ((((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup).get('answers') as FormArray).at(addmoreqnIndex) as FormGroup).get('validation')?.setValue(event.target.checked);
810
+ if(!event.target.checked) {
811
+ this.runAIOff(sectionIndex, questionIndex, false, addmoreqnIndex);
812
+ (((((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup).get('answers') as FormArray).at(addmoreqnIndex) as FormGroup).get('multiReferenceImage') as FormArray).clear();
813
+ ((((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup).get('answers') as FormArray).at(addmoreqnIndex) as FormGroup).get('runAIDescription')?.setValue('');
814
+ }
815
+ // let answers = (((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup).get('answers') as FormArray).value;
816
+ // let compliance = ((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup)?.get('compliance')?.value;
817
+ // if(!answers.some((ele:any) => ele.runAI) && compliance) {
818
+ // const dialogRef = this.dialog.open(TraxpopupComponent,{centered: true, size: 'md'});
819
+ // dialogRef.componentInstance.data = {
820
+ // imagesrc: `<span><svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="0 0 56 56" fill="none">
821
+ // <rect x="4" y="4" width="48" height="48" rx="24" fill="#FEF0C7"/>
822
+ // <rect x="4" y="4" width="48" height="48" rx="24" stroke="#FFFAEB" stroke-width="8"/>
823
+ // <path d="M27.9988 24.0012V28.0012M27.9988 32.0012H28.0088M26.2888 18.8612L17.8188 33.0012C17.6442 33.3036 17.5518 33.6465 17.5508 33.9957C17.5498 34.3449 17.6403 34.6883 17.8132 34.9917C17.9862 35.2951 18.2355 35.5479 18.5365 35.725C18.8375 35.9021 19.1796 35.9973 19.5288 36.0012H36.4688C36.818 35.9973 37.1601 35.9021 37.4611 35.725C37.7621 35.5479 38.0114 35.2951 38.1844 34.9917C38.3573 34.6883 38.4478 34.3449 38.4468 33.9957C38.4458 33.6465 38.3534 33.3036 38.1788 33.0012L29.7088 18.8612C29.5305 18.5673 29.2795 18.3243 28.98 18.1557C28.6805 17.987 28.3425 17.8984 27.9988 17.8984C27.6551 17.8984 27.3171 17.987 27.0176 18.1557C26.7181 18.3243 26.4671 18.5673 26.2888 18.8612Z" stroke="#DC6803" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
824
+ // </svg></span>`,
825
+ // title: `Disabling Compliance Score`,
826
+ // content: `By clicking and enable the validate response, the compliance score configured will be disabled since it works only for Capture Image with Run AI enabled. Are you sure to proceed?`,
827
+ // buttontype: "compliance",
828
+ // };
829
+ // dialogRef.result.then((res) => {
830
+ // if(res == 'confirm') {
831
+ // ((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup)?.get('compliance')?.patchValue(false);
832
+ // ((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup)?.get('compliance')?.disable({emitEvent:false});
833
+ // ((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup)?.get('complianceScore')?.patchValue(0);
834
+ // }
835
+ // else {
836
+ // ((((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup).get('answers') as FormArray).at(addmoreqnIndex) as FormGroup).get('validation')?.setValue(false);
837
+ // }
838
+ // });
839
+
840
+ // }
841
+ // if(!answers.some((ele:any) => ele.runAI) && !compliance) {
842
+ // if(event.target.checked) {
843
+ // ((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup)?.get('compliance')?.disable({emitEvent:false})
844
+ // }
845
+ // else if(!answers.some((ele:any) => ele.validation)) {
846
+ // ((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup)?.get('compliance')?.enable({emitEvent:false})
847
+ // }
848
+ // }
849
+ }
850
+
851
+ addNewQuestion(sectionIndex: number) {
852
+
853
+ if (this.sectionIndex > -1) {
854
+ if (!(((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions'))) {
855
+ ((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).setControl('questions', this.fb.array([]));
856
+ }
857
+ let questions = (((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup).get('questions') as FormArray);
858
+
859
+ let questionsLength = questions.length;
860
+ questions.push(this.fb.group({
861
+ "qno": this.fb.control(questionsLength + 1,),
862
+ 'qname': this.fb.control('', [Validators.required,noWhitespaceValidator()]),
863
+ 'answerType': this.fb.control('descriptive',
864
+ this.allowedValuesValidator(["descriptive", "yes/no", "multiplechoicesingle", "multiplechoicemultiple","descriptiveImage", "image", "video",'multipleImage','date','linearscale','time','image/video','dropdown'])),
865
+ 'runAI': this.fb.control(false, [Validators.required]),
866
+ 'runAIDescription': this.fb.control(''),
867
+ 'allowUploadfromGallery': this.fb.control(false, [Validators.required]),
868
+ 'linkType': this.fb.control(false, [Validators.required]),
869
+ "multiQuestionReferenceImage":this.fb.array([]),
870
+ 'descriptivetype':this.fb.control('text'),
871
+ 'questionReferenceImage':this.fb.control(''),
872
+ "runAIFeatures":this.fb.array([]),
873
+ "uniqueqno": this.fb.control(0),
874
+ "uniqueqid": this.fb.control(''),
875
+ "allowMultiple":this.fb.control(false),
876
+ 'compliance':this.fb.control(false)
877
+ }));
878
+ this.changedetector.detectChanges();
879
+ this.swalToast('New question added!');
880
+ setTimeout(()=> {
881
+ this.scrollToQuestion(sectionIndex,questionsLength);
882
+ },100);
883
+ }
884
+ }
885
+
886
+ deleteQuestion(sectionIndex: any, questionIndex: any) {
887
+ this.deletedList = [];
888
+ let question = this.getQuestionFormControl(sectionIndex, questionIndex, 'qname')?.value || '';
889
+ let qno = this.getQuestionFormControl(sectionIndex, questionIndex, 'qno')?.value;
890
+ question = question ? question : `Question ${this.getQuestionFormControl(sectionIndex, questionIndex, 'qno')?.value || ''}`;
891
+ question = question.length > 20 ? question.slice(0,20) + '...' : question;
892
+ const dialogRef = this.dialog.open(TraxpopupComponent,{centered: true, size: 'md'});
893
+ dialogRef.componentInstance.data = {
894
+ imagesrc: `<span><svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="0 0 56 56" fill="none"><rect x="4" y="4" width="48" height="48" rx="24" fill="#FEE4E2"/><path d="M28 24V28M28 32H28.01M38 28C38 33.5228 33.5228 38 28 38C22.4772 38 18 33.5228 18 28C18 22.4772 22.4772 18 28 18C33.5228 18 38 22.4772 38 28Z" stroke="#D92D20" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><rect x="4" y="4" width="48" height="48" rx="24" stroke="#FEF3F2" stroke-width="8"/></svg></span>`,
895
+ title: `Delete '${question}'?`,
896
+ content: `Are you sure you want to delete <b>'${question}'</b>? This action cannot be undone.`,
897
+ buttontype: 'delete'
898
+ }
899
+ dialogRef.result.then((res) => {
900
+ if (res == 'delete') {
901
+ let linkedQuestion:any = (((this.getSectionFormArray().at(sectionIndex).get('questions') as FormArray).at(questionIndex) as FormGroup).get('answers') as FormArray);
902
+ let type:any = ((this.getSectionFormArray().at(sectionIndex).get('questions') as FormArray).at(questionIndex) as FormGroup).get('answerType')?.value;
903
+ if(!['descriptive','image', 'descriptiveImage','multipleImage','video','linearscale','time','date'].includes(type)) {
904
+ for(let i=0;i<linkedQuestion?.length;i++) {
905
+ let linkedQn = ((linkedQuestion.at(i) as FormGroup).get('linkedQuestion')?.value);
906
+ if(linkedQn) {
907
+ let no = linkedQn -1;
908
+ ((this.getSectionFormArray().at(sectionIndex).get('questions') as FormArray).at(no) as FormGroup).get('linkType')?.setValue(false);
909
+ if(linkedQn && parseInt(linkedQn) > questionIndex) {
910
+ this.subtractQuestionno(sectionIndex,linkedQn-1)
911
+ }
912
+ }
913
+ }
914
+ }
915
+ (this.getSectionFormControl(sectionIndex, 'questions') as FormArray).removeAt(questionIndex);
916
+ this.removedNestedQuestion(sectionIndex,qno);
917
+ this.updateQuestionQnos(sectionIndex);
918
+ this.swalToast(`${question} has been deleted!`);
919
+ this.changedetector.detectChanges();
920
+ }
921
+ });
922
+
923
+ }
924
+
925
+ subtractQuestionno(sectionIndex:number,questionIndex:any) {
926
+ let linkedQuestionAnswers = (((this.getSectionFormArray().at(sectionIndex).get('questions') as FormArray).at(questionIndex) as FormGroup).get('answers') as FormArray);
927
+ let no = ((this.getSectionFormArray().at(sectionIndex).get('questions') as FormArray).at(questionIndex) as FormGroup).get('qno')?.value;
928
+ this.deletedList.push(no);
929
+ for(let j=0;j<linkedQuestionAnswers?.length;j++) {
930
+ let linkedQn = ((linkedQuestionAnswers.at(j) as FormGroup).get('linkedQuestion')?.value);
931
+ if(linkedQn && parseInt(linkedQn) > questionIndex) {
932
+ ((linkedQuestionAnswers.at(j) as FormGroup).get('linkedQuestion'))?.setValue(linkedQn - 1);
933
+ this.subtractQuestionno(sectionIndex,linkedQn-1);
934
+ }
935
+ }
936
+ }
937
+
938
+ raiseflag(sectionIndex: number, questionIndex: number, ansIdx: number,value: boolean,linkIndex:number = -1,linkAnsIndex:number = -1) {
939
+ let question = ((((this.ChecklistForm.get('sections') as FormArray)?.at(sectionIndex) as FormGroup).get('questions') as FormArray).at(questionIndex) as FormGroup);
940
+ if(value == true) {
941
+ let answers = (question.get('answers') as FormArray).value;
942
+ if(linkIndex == -1) {
943
+ if(answers.filter((x:any)=> x.sopFlag == true).length == (answers.length -1)) {
944
+ ((question.get('answers') as FormArray).at(ansIdx) as FormGroup).addControl('showSOPFlagError',this.fb.control(true));
945
+ timer(5000).subscribe(() => {
946
+ ((question.get('answers') as FormArray).at(ansIdx) as FormGroup).removeControl('showSOPFlagError');
947
+ });
948
+ return;
949
+ }
950
+ }
951
+ else {
952
+ let answers = ((question.get('answers') as FormArray).at(ansIdx) as FormGroup);
953
+ let linkQuestion = ((answers.get('linkQuestionAnswers') as FormArray).at(linkIndex) as FormGroup);
954
+ let linkAnswers = (linkQuestion.get('answers') as FormArray).value
955
+ if(linkAnswers.filter((x:any)=> x.sopFlag == true).length == (linkAnswers.length -1)) {
956
+ ((linkQuestion.get('answers') as FormArray).at(linkAnsIndex) as FormGroup).addControl('showSOPFlagError',this.fb.control(true));
957
+ timer(5000).subscribe(() => {
958
+ ((linkQuestion.get('answers') as FormArray).at(linkAnsIndex) as FormGroup).removeControl('showSOPFlagError');
959
+ });
960
+ return;
961
+ }
962
+ }
963
+ }
964
+ if(linkIndex == -1)
965
+ ((((question.get('answers') as FormArray)?.at(ansIdx) as FormGroup)?.get('sopFlag') as FormControl))?.setValue(value);
966
+ else {
967
+ let answers = ((question.get('answers') as FormArray).at(ansIdx) as FormGroup);
968
+ let linkQuestion = ((answers.get('linkQuestionAnswers') as FormArray).at(linkIndex) as FormGroup);
969
+ ((((linkQuestion.get('answers') as FormArray)?.at(linkAnsIndex) as FormGroup)?.get('sopFlag') as FormControl))?.setValue(value);
970
+ }
971
+ }
972
+
973
+ addNestedQuestion(sectionIndex: number, questionIndex: number, ansIdx: number,value: boolean,linkedQuestionIndex:number=-1,linkedAnswer:number = -1) {
974
+ let answer = (((((this.ChecklistForm.get('sections') as FormArray)
975
+ .at(sectionIndex) as FormGroup)
976
+ .get('questions') as FormArray)
977
+ .at(questionIndex) as FormGroup)
978
+ .get('answers') as FormArray)
979
+ .at(ansIdx) as FormGroup
980
+
981
+
982
+
983
+ if(!answer?.get('linkQuestionAnswers')?.value.length) {
984
+ answer.setControl('linkQuestionAnswers',
985
+ this.fb.array([
986
+ this.fb.group({
987
+ "qno": this.fb.control(1),
988
+ 'qname': this.fb.control('', [Validators.required,noWhitespaceValidator()]),
989
+ 'answerType': this.fb.control('descriptive',
990
+ this.allowedValuesValidator(["descriptive", "yes/no", "multiplechoicesingle", "multiplechoicemultiple","descriptiveImage", "image", "video",'multipleImage','date','linearscale','time','image/video','dropdown'])),
991
+ 'runAI': this.fb.control(false, [Validators.required]),
992
+ 'runAIDescription': this.fb.control(''),
993
+ 'allowUploadfromGallery': this.fb.control(false, [Validators.required]),
994
+ "multiQuestionReferenceImage":this.fb.array([]),
995
+ 'descriptivetype':this.fb.control('text'),
996
+ 'questionReferenceImage':this.fb.control(''),
997
+ 'runAIFeatures':this.fb.array([]),
998
+ "uniqueqno": this.fb.control(0),
999
+ "uniqueqid": this.fb.control(''),
1000
+ "allowMultiple":this.fb.control(false),
1001
+ "compliance":this.fb.control(false),
1002
+ })
1003
+ ])
1004
+ )
1005
+ }
1006
+ else {
1007
+ let nestedQuestion = answer.get('linkQuestionAnswers') as FormArray
1008
+ nestedQuestion.push(this.fb.group({
1009
+ "qno": this.fb.control(1),
1010
+ 'qname': this.fb.control('', [Validators.required,noWhitespaceValidator()]),
1011
+ 'answerType': this.fb.control('descriptive',
1012
+ this.allowedValuesValidator(["descriptive", "yes/no", "multiplechoicesingle", "multiplechoicemultiple","descriptiveImage", "image", "video",'multipleImage','date','linearscale','time','image/video','dropdown'])),
1013
+ 'runAI': this.fb.control(false, [Validators.required]),
1014
+ 'runAIDescription': this.fb.control(''),
1015
+ 'allowUploadfromGallery': this.fb.control(false, [Validators.required]),
1016
+ "multiQuestionReferenceImage":this.fb.array([]),
1017
+ 'descriptivetype':this.fb.control('text'),
1018
+ 'questionReferenceImage':this.fb.control(''),
1019
+ 'runAIFeatures':this.fb.array([]),
1020
+ "uniqueqno": this.fb.control(0),
1021
+ "uniqueqid": this.fb.control(''),
1022
+ "allowMultiple":this.fb.control(false),
1023
+ "compliance":this.fb.control(false),
1024
+ }));
1025
+ }
1026
+ this.ChecklistForm.updateValueAndValidity();
1027
+ }
1028
+
1029
+ accordian(index: any) {
1030
+ if (this.show == index) {
1031
+ this.show = -1;
1032
+ this.sectionIndex = -1;
1033
+ } else {
1034
+ this.show = index;
1035
+ this.sectionIndex = index;
1036
+ }
1037
+ }
1038
+
1039
+ deleteSection(sectionIndex: any) {
1040
+ let section = ((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex) as FormGroup);
1041
+ let sectionLength:any = " " + (section.get('questions') as FormArray).length;
1042
+ let sectionName:string = section.get('name')?.value;
1043
+ sectionName = sectionName.length > 20 ? (sectionName.slice(0, 20) + "...") : sectionName;
1044
+ let question_text = ''
1045
+ if (sectionLength == 1)
1046
+ question_text = 'Question'
1047
+ else
1048
+ question_text = 'Questions'
1049
+ const popupcontent = {
1050
+ displayprop: false,
1051
+ imagesrc: `<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="0 0 56 56" fill="none"><rect x="4" y="4" width="48" height="48" rx="24" fill="#FEE4E2"/><path d="M28 24V28M28 32H28.01M38 28C38 33.5228 33.5228 38 28 38C22.4772 38 18 33.5228 18 28C18 22.4772 22.4772 18 28 18C33.5228 18 38 22.4772 38 28Z" stroke="#D92D20" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><rect x="4" y="4" width="48" height="48" rx="24" stroke="#FEF3F2" stroke-width="8"/></svg>`,
1052
+ title: `Delete '${sectionName} Section'?`,
1053
+ content: `Are you sure you want to delete' <b>'${sectionName}'</b>? with <b>${sectionLength} ${question_text}</b> This action cannot be undone.`,
1054
+ buttontype: 'delete'
1055
+ }
1056
+ const dialogRef = this.dialog.open(TraxpopupComponent,{centered: true, size: 'md'});
1057
+ dialogRef.componentInstance.data = popupcontent
1058
+ dialogRef.result.then((res) => {
1059
+ if (res == 'delete') {
1060
+ (this.ChecklistForm.get('sections') as FormArray).removeAt(sectionIndex)
1061
+ this.changedetector.detectChanges();
1062
+ }
1063
+ });
1064
+ }
1065
+
1066
+ AddMoreAns(sectionindex: any, questionIndex: any,type:string) {
1067
+ let ansoption =
1068
+ ((((this.ChecklistForm.get('sections') as FormArray)
1069
+ .at(sectionindex) as FormGroup)
1070
+ .get('questions') as FormArray)
1071
+ .at(questionIndex)
1072
+ .get('answers') as FormArray);
1073
+ let ansoptionLength = ansoption.length;
1074
+ if (ansoptionLength <= 99) {
1075
+ ansoption.push(
1076
+ this.fb.group({
1077
+ 'answer': this.fb.control(``, [Validators.required,noWhitespaceValidator()]),
1078
+ 'answeroptionNumber': this.fb.control(ansoptionLength + 1),
1079
+ 'sopFlag': this.fb.control(false, [Validators.required]),
1080
+ 'validation': this.fb.control(false, [Validators.required]),
1081
+ 'validationType': this.fb.control('Capture Image', this.allowedValuesValidator(["Capture Image", "Capture Multiple Image with description", "Descriptive Answer","Capture Video"])),
1082
+ "multiReferenceImage": this.fb.array([]),
1083
+ 'allowUploadfromGallery': this.fb.control(false),
1084
+ ...(type == 'multiplechoicesingle' ? {"linkedQuestion":this.fb.control(0, [Validators.required]),'showLinked':this.fb.control(false, [Validators.required])} : {}),
1085
+ 'runAI': this.fb.control(false),
1086
+ 'descriptivetype':this.fb.control(''),
1087
+ ...(type == 'multipleImage' ? {'descriptivetype':this.fb.control('text')}:{}),
1088
+ 'referenceImage':this.fb.control(''),
1089
+ 'runAIFeatures':this.fb.array([]),
1090
+ 'runAIDescription': this.fb.control(''),
1091
+ 'complianceScore':this.fb.control(0)
1092
+ })
1093
+ );
1094
+ }
1095
+ }
1096
+
1097
+ deleteAnswer(sectionIndex: number, questionIndex: number, addmoreqnIndex: number,ansIndex:number = -1) {
1098
+ if(ansIndex != -1) {
1099
+ this.getFormArrayQuestionsAnswer(sectionIndex, questionIndex, 'answers',ansIndex).removeAt(addmoreqnIndex);
1100
+ }
1101
+ else {
1102
+ this.getFormArrayQuestionsAnswer(sectionIndex, questionIndex, 'answers',ansIndex).removeAt(addmoreqnIndex);
1103
+ }
1104
+ this.ChecklistForm.updateValueAndValidity();
1105
+ }
1106
+
1107
+ cloneQuestion(sectionindex: any, questionindex: any) {
1108
+ let cloneQuestion = ((this.getSectionFormControl(sectionindex, 'questions') as FormArray).at(questionindex) as FormGroup).value;
1109
+ let questionLength = (this.getSectionFormControl(sectionindex, 'questions') as FormArray).value;
1110
+ let question: any;
1111
+ let answer: any;
1112
+ if (cloneQuestion.answers) {
1113
+ if (Array.isArray(cloneQuestion.answers) && cloneQuestion.answers.length) {
1114
+ answer = [];
1115
+ cloneQuestion.answers.forEach((k: any) => {
1116
+ answer.push(
1117
+ this.fb.group({
1118
+ ...(!['image', 'descriptiveImage','multipleImage'].includes(cloneQuestion?.answerType) && cloneQuestion?.answerType != 'video' ? { 'answer': this.fb.control(k?.answer, [Validators.required]) } : {}),
1119
+ ...(!['image', 'descriptiveImage','multipleImage'].includes(cloneQuestion?.answerType) && cloneQuestion?.answerType != 'video' ? { 'answeroptionNumber': this.fb.control(k?.answeroptionNumber + 1) } : {}),
1120
+ ...(!['image', 'descriptiveImage','multipleImage'].includes(cloneQuestion?.answerType) && cloneQuestion?.answerType != 'video' ? { 'sopFlag': this.fb.control(k?.sopFlag ? k?.sopFlag : false, [Validators.required]) } : {}),
1121
+ ...(!['image', 'descriptiveImage','multipleImage'].includes(cloneQuestion?.answerType) && cloneQuestion?.answerType != 'video' ? { 'validation': this.fb.control(k?.validation, [Validators.required]) } : {}),
1122
+ ...(!['image', 'descriptiveImage','multipleImage'].includes(cloneQuestion?.answerType) && cloneQuestion?.answerType != 'video' ? { 'validationType': this.fb.control(k?.validationType, this.allowedValuesValidator(["Capture Image", "Capture Multiple Image with description", "Descriptive Answer", "Capture Video"])) } : {}),
1123
+ ...(!['descriptive','image', 'descriptiveImage','multipleImage','date','image/video'].includes(cloneQuestion?.answerType) ? { "multiReferenceImage": this.fb.array(k?.multiReferenceImage) } : {}),
1124
+ ...((!['descriptive','image', 'descriptiveImage','multipleImage','date','image/video'].includes(cloneQuestion?.answerType)) ? { 'allowUploadfromGallery': this.fb.control(k?.allowUploadfromGallery == true ? true : false) } : {}),
1125
+ ...(!['descriptive','image', 'descriptiveImage','multipleImage','date','image/video'].includes(cloneQuestion?.answerType) ? { 'runAI': this.fb.control(k?.runAI ? k?.runAI : false) } : {}),
1126
+ ...(['multiplechoicesingle','yes/no'].includes(cloneQuestion?.answerType) ? { 'showLinked': false } : {}),
1127
+ ...(['multiplechoicesingle','yes/no'].includes(cloneQuestion?.answerType) ? { 'linkedQuestion': 0 } : {}),
1128
+ ...(['multiplechoicesingle','yes/no'].includes(cloneQuestion?.answerType) ? { 'linkedQuestion': 0 } : {}),
1129
+ descriptivetype:this.fb.control(k?.descriptivetype),
1130
+ 'referenceImage':this.fb.control(''),
1131
+ 'runAIFeatures':this.fb.array(k?.runAIFeatures || []),
1132
+ 'runAIDescription': this.fb.control(''),
1133
+ 'complianceScore':this.fb.control(0)
1134
+ }));
1135
+ });
1136
+ } else if(typeof cloneQuestion.answers === 'object' && cloneQuestion.answers !== null) {
1137
+ answer = this.fb.group({
1138
+ ...(['image', 'descriptiveImage','multipleImage','image/video'].includes(cloneQuestion?.answerType) ? { "multiReferenceImage": this.fb.array(cloneQuestion?.answers?.multiReferenceImage) } : {}),
1139
+ ...((['image', 'descriptiveImage','multipleImage','image/video'].includes(cloneQuestion?.answerType) || cloneQuestion?.answerType == 'video') ? { 'allowUploadfromGallery': this.fb.control(cloneQuestion?.answers?.allowUploadfromGallery == true ? true : false) } : {}),
1140
+ ...(['image', 'descriptiveImage','multipleImage','image/video'].includes(cloneQuestion?.answerType) ? { 'runAI': this.fb.control(cloneQuestion?.answers?.runAI ? cloneQuestion?.answers?.runAI : false) } : {}),
1141
+ ...(['multipleImage'].includes(cloneQuestion?.answerType) ? { descriptivetype:this.fb.control(cloneQuestion?.answers?.descriptivetype) } : {}),
1142
+ ...(['linearscale'].includes(cloneQuestion?.answerType) ? {
1143
+ 'linearType':this.fb.control(cloneQuestion?.answers.linearType),'rangeStart':this.fb.control(cloneQuestion?.answers.rangeStart),'rangeEnd':this.fb.control(cloneQuestion?.answers.rangeEnd) } : {}),
1144
+ ...(['date'].includes(cloneQuestion?.answerType) ? { 'historicDate':this.fb.control(cloneQuestion?.answers.historicDate),startDate:this.fb.control(this.dayjs().format('DD-MM-YYYY')),endDate:this.fb.control(this.dayjs().format('DD-MM-YYYY'))} : {}),
1145
+ 'referenceImage':this.fb.control(''),
1146
+ 'runAIFeatures':this.fb.array(cloneQuestion?.answers?.runAIFeatures || []),
1147
+ 'runAIDescription': this.fb.control(cloneQuestion?.answers?.runAIDescription || cloneQuestion?.runAIDescription || ''),
1148
+ ...(['image/video'].includes(cloneQuestion?.answerType) && { 'limit':this.fb.control(cloneQuestion?.answers.limit),'imageLimit':this.fb.control(cloneQuestion?.answers.imageLimit),'videoLimit':this.fb.control(cloneQuestion?.answers.videoLimit)}),
1149
+ ...(['date','linearscale','image','image/video'].includes(cloneQuestion?.answerType) && {matchedCount:this.fb.control(0),notMatchedCount:this.fb.control(0)}),
1150
+ ...(cloneQuestion?.answerType == 'date' && {qnStartDate:this.fb.group({}),qnEndDate:this.fb.group({})})
1151
+ });
1152
+ }
1153
+ }
1154
+ // if(typeof cloneQuestion?.questionReferenceImage == 'string' && cloneQuestion?.questionReferenceImage != '') {
1155
+ // cloneQuestion.multiQuestionReferenceImage = [{imageURL:cloneQuestion?.questionReferenceImage,runAI:false}];
1156
+ // }
1157
+ question = this.fb.group({
1158
+ "qno": this.fb.control(questionLength.length + 1),
1159
+ 'qname': this.fb.control(cloneQuestion?.qname, [Validators.required,noWhitespaceValidator()]),
1160
+ 'answerType': this.fb.control(cloneQuestion?.answerType, this.allowedValuesValidator(["descriptive", "yes/no", "multiplechoicesingle", "multiplechoicemultiple","descriptiveImage", "image", "video",'multipleImage','date','linearscale','time','image/video','dropdown'])),
1161
+ ...(!['descriptive'].includes(cloneQuestion?.answerType) ? { 'answers': (['image','descriptiveImage', 'video','multipleImage','linearscale','time','image/video','date'].includes(cloneQuestion?.answerType)) ? answer : this.fb.array(answer,[uniqueStringValidator()]) } : {}),
1162
+ 'runAI': this.fb.control(cloneQuestion?.runAI, [Validators.required]),
1163
+ 'runAIDescription': this.fb.control(cloneQuestion?.runAIDescription || ''),
1164
+ 'allowUploadfromGallery': this.fb.control(cloneQuestion?.allowUploadfromGallery),
1165
+ 'linkType': this.fb.control(false),
1166
+ 'descriptivetype':this.fb.control(cloneQuestion?.descriptivetype),
1167
+ "multiQuestionReferenceImage":this.fb.array(cloneQuestion?.multiQuestionReferenceImage),
1168
+ 'questionReferenceImage':this.fb.control(''),
1169
+ 'runAIFeatures':this.fb.array(cloneQuestion?.runAIFeatures || []),
1170
+ "uniqueqno": this.fb.control(0),
1171
+ "uniqueqid": this.fb.control(''),
1172
+ "allowMultiple":this.fb.control(false),
1173
+ 'compliance':this.fb.control(false)
1174
+ });
1175
+ const sourceQuestionGroup = ((this.getSectionFormControl(sectionindex, 'questions') as FormArray).at(questionindex) as FormGroup);
1176
+ const sourceQuestionRunAI = sourceQuestionGroup.get('runAI')?.value === true;
1177
+ const sourceComplianceEnabled = sourceQuestionGroup.get('compliance')?.enabled === true;
1178
+ if (!(sourceQuestionRunAI || sourceComplianceEnabled)) {
1179
+ question.get('compliance')?.disable({ emitEvent: false });
1180
+ }
1181
+ // this.updateClonedlinkedQuestionNo(sectionindex, cloneQuestion?.qno);
1182
+ (this.getSectionFormControl(sectionindex, 'questions') as FormArray).insert(cloneQuestion?.qno,question);
1183
+ this.ChecklistForm.updateValueAndValidity();
1184
+ this.updateQuestionQnos(sectionindex);
1185
+ this.swalToast(`Question ${cloneQuestion?.qno} has been duplicated!`);
1186
+ this.changedetector.detectChanges();
1187
+ }
1188
+
1189
+ updateClonedlinkedQuestionNo(secIdx:number,qidx:number) {
1190
+ let questions = (this.getSectionFormArray().at(secIdx).get('questions') as FormArray);
1191
+ for (let i = 0; i < questions.length; i++) {
1192
+ let answers = (questions.at(i) as FormGroup)?.get('answers') as FormArray;
1193
+ if(answers) {
1194
+ for(let j=0;j<answers.length;j++) {
1195
+ let linked = (answers.at(j) as FormGroup)?.get('showLinked')?.value;
1196
+ if(linked) {
1197
+ let questionNo = (answers.at(j) as FormGroup)?.get('linkedQuestion')?.value;
1198
+ if(questionNo > qidx) {
1199
+ (answers.at(j) as FormGroup)?.get('linkedQuestion')?.setValue(questionNo + 1);
1200
+ }
1201
+ }
1202
+ }
1203
+ }
1204
+ }
1205
+ }
1206
+
1207
+ saveChecklistQuestions(type: string) {
1208
+ let checklist = this.ChecklistForm.value;
1209
+ // console.log(checklist,'checklist')
1210
+ if(!this.ChecklistForm.get('checklistName')?.valid) {
1211
+ let err: string = 'Please enter checklist name!';
1212
+ this.swalToast(err,'error');
1213
+ return;
1214
+ }
1215
+
1216
+ if (!this.ChecklistForm.valid) {
1217
+ this.markFormControlsAsTouched(this.ChecklistForm,0);
1218
+ this.scrollToErrors(this.ChecklistForm.get('sections') as FormArray);
1219
+ return;
1220
+ }
1221
+ let sections = checklist.sections;
1222
+ if(type == 'saveAsDraft') {
1223
+ checklist.submitType = 'save';
1224
+ } else {
1225
+ checklist.submitType = 'configure';
1226
+ }
1227
+ if(!sections.length) {
1228
+ let err: string = 'Please add atleast one section!';
1229
+ this.swalToast(err,'error');
1230
+ return;
1231
+ }
1232
+ for (let i = 0; i < sections.length; i++) {
1233
+ if(type == 'configure' && !sections[i].questions.length) {
1234
+ let err: string = 'Please add atleast one question in section!';
1235
+ this.swalToast(err,'error');
1236
+ return;
1237
+ }
1238
+ let findExists = sections.filter((ele:any,index:any) => {
1239
+ if(index != i && sections[i].name.trim() == ele.name.trim())
1240
+ return ele;
1241
+ })
1242
+ if(findExists.length) {
1243
+ this.swalToast(`${sections[i].name} section name is Duplicated` ,'error');
1244
+ return;
1245
+ }
1246
+ for (let j = 0; j < sections[i].questions.length; j++) {
1247
+ let ansType = sections[i].questions[j].answerType;
1248
+ sections[i].questions[j].qname = sections[i].questions[j].qname.trim().replaceAll(/\n/g, '')
1249
+ let findExists = sections[i].questions.filter((ele:any,index:any) => {
1250
+ if(index != j && sections[i].questions[j].qname.trim() == ele.qname.trim())
1251
+ return ele;
1252
+ })
1253
+ if(findExists.length) {
1254
+ this.swalToast(`${sections[i].questions[j].qname} question name is Duplicated` ,'error');
1255
+ return;
1256
+ }
1257
+ if(ansType == 'linearscale') {
1258
+ if(sections[i].questions[j].answers.rangeStart >= sections[i].questions[j].answers.rangeEnd){
1259
+ let err: string = 'Min value must be less than max value.';
1260
+ this.swalToast(err,'error');
1261
+ return;
1262
+ }
1263
+ // if(sections[i].questions[j].answers.linearType != '' ){
1264
+ // if(sections[i].questions[j].answers.minValue > sections[i].questions[j].answers.maxValue) {
1265
+ // let err: string = 'Min value is greater than Max Value.';
1266
+ // this.swalToast(err,'error');
1267
+ // return;
1268
+ // }
1269
+ // }
1270
+ // if(sections[i].questions[j].answers.linearType == 'degree' && (sections[i].questions[j].answers.rangeStart < -273.15 || sections[i].questions[j].answers.rangeEnd < -273.15)) {
1271
+ // let err: string = "Min value shouldn't greater than -273.15";
1272
+ // this.swalToast(err,'error');
1273
+ // return;
1274
+ // }
1275
+ }
1276
+ if(ansType == 'image/video') {
1277
+ if(sections[i].questions[j].answers.limit && (!sections[i].questions[j].answers.imageLimit || !sections[i].questions[j].answers.videoLimit)){
1278
+ let err: string = 'image & video limit is required';
1279
+ this.swalToast(err,'error');
1280
+ return;
1281
+ }
1282
+ }
1283
+ if(ansType != 'descriptive') {
1284
+ delete sections[i].questions[j].descriptivetype;
1285
+ }
1286
+
1287
+ if(ansType == 'date') {
1288
+ if(sections[i].questions[j].compliance && this.dayjs(sections[i].questions[j].answers.startDate,'DD-MM-YYYY') > this.dayjs(sections[i].questions[j].answers.endDate,'DD-MM-YYYY')){
1289
+ let err: string = 'Start date is greater than end date';
1290
+ this.swalToast(err,'error');
1291
+ return;
1292
+ }
1293
+ }
1294
+ if (["multiplechoicemultiple"].includes(ansType)) {
1295
+ for (let k = 0; k < sections[i].questions[j].answers.length; k++) {
1296
+ sections[i].questions[j].answers[k]['showLinked'] = false;
1297
+ sections[i].questions[j].answers[k]['answer'] = sections[i].questions[j].answers[k]['answer'].trim();
1298
+ sections[i].questions[j].answers[k]['linkedQuestion'] = 0;
1299
+ sections[i].questions[j].answers[k]['complianceScore'] = parseInt(sections[i].questions[j].answers[k]['complianceScore']);
1300
+ }
1301
+ sections[i].questions[j].allowUploadfromGallery = false;
1302
+ }
1303
+ if (["multiplechoicesingle","yes/no"].includes(ansType)) {
1304
+ for (let k = 0; k < sections[i].questions[j].answers.length; k++) {
1305
+ sections[i].questions[j].answers[k]['answer'] = sections[i].questions[j].answers[k]['answer'].trim();
1306
+ sections[i].questions[j].answers[k]['complianceScore'] = parseInt(sections[i].questions[j].answers[k]['complianceScore']);
1307
+ }
1308
+ }
1309
+ if (typeof sections[i].questions[j].answers === 'object' &&
1310
+ sections[i].questions[j].answers !== null &&
1311
+ !Array.isArray(sections[i].questions[j].answers) || ['descriptive','date'].includes(ansType)) {
1312
+ let item = {
1313
+ "answer": '',
1314
+ "answeroptionNumber": 1,
1315
+ "sopFlag": false,
1316
+ "validation": false,
1317
+ "validationType": "",
1318
+ "validationAnswer": "",
1319
+ "multiReferenceImage": sections[i].questions[j].answers?.multiReferenceImage ? sections[i].questions[j].answers?.multiReferenceImage : [],
1320
+ "showLinked":false,
1321
+ "linkedQuestion":0,
1322
+ ...(ansType == 'multipleImage' ? {'descriptivetype':sections[i].questions[j].answers?.descriptivetype}:{}),
1323
+ ...(sections[i].questions[j].answerType == 'linearscale' ? {'rangeStart':sections[i].questions[j].answers?.rangeStart,'rangeEnd':sections[i].questions[j].answers?.rangeEnd,'linearType':sections[i].questions[j].answers?.linearType,'minValue':parseInt(sections[i].questions[j].answers?.minValue),'maxValue':parseInt(sections[i].questions[j].answers?.maxValue)}:{}),
1324
+ ...(sections[i].questions[j].answerType == 'date' ? {'historicDate':sections[i].questions[j].answers?.historicDate,'startDate':sections[i].questions[j].answers?.startDate,'endDate':sections[i].questions[j].answers?.endDate}:{}),
1325
+ runAI:sections[i]?.questions[j]?.answers?.runAI ?? false,
1326
+ runAIFeatures:sections[i].questions[j]?.answers?.runAIFeatures ?? [],
1327
+ runAIDescription: sections[i].questions[j]?.answers?.runAIDescription ? sections[i].questions[j]?.answers?.runAIDescription : "",
1328
+ ...(ansType == 'image/video' ? {'limit':sections[i].questions[j].answers?.limit,'videoLimit':sections[i].questions[j].answers?.videoLimit,'imageLimit':sections[i].questions[j].answers?.imageLimit}:{}),
1329
+ ...(['date','linearscale','image','image/video'].includes(sections[i].questions[j].answerType) && {'matchedCount':parseInt(sections[i].questions[j].answers?.matchedCount),'notMatchedCount':parseInt(sections[i].questions[j].answers?.notMatchedCount)})
1330
+ };
1331
+ sections[i].questions[j].allowUploadfromGallery = sections[i].questions[j].answers?.allowUploadfromGallery ? sections[i].questions[j].answers?.allowUploadfromGallery : false;
1332
+ if(ansType == 'multipleImage') {
1333
+ sections[i].questions[j].descriptivetype = sections[i].questions[j].answers?.descriptivetype ? sections[i].questions[j].answers?.descriptivetype : 'text';
1334
+ }
1335
+ if(['multipleImage','image/video'].includes(ansType)) {
1336
+ sections[i].questions[j].multiQuestionReferenceImage = sections[i].questions[j].answers?.multiReferenceImage ? sections[i].questions[j].answers?.multiReferenceImage : [];
1337
+ }
1338
+ sections[i].questions[j].answers = [item];
1339
+ // sections[i].questions[j].runAI = sections[i].questions[j].answers.runAI;
1340
+ // sections[i].questions[j].runAIFeatures = sections[i].questions[j].answers.runAIFeatures;
1341
+ }
1342
+ }
1343
+ }
1344
+ checklist.sections = sections;
1345
+ checklist.checklistName = checklist.checklistName.trim().charAt(0).toUpperCase() + checklist.checklistName.trim().slice(1);
1346
+ checklist.clientId = this.clientId;
1347
+ checklist.checklistName = checklist.checklistName.trim();
1348
+ checklist.checklistDescription = checklist?.checklistDescription ? checklist?.checklistDescription?.trim() : '';
1349
+ this.sopService.createChecklist(checklist).pipe(takeUntil(this.detach)).subscribe((res: any) => {
1350
+ if(res) {
1351
+ if (res?.code == 200) {
1352
+ if(type=='configure') {
1353
+ this.router.navigateByUrl(`/manage/trax/configure?checkListId=${res.data.checklistId}`);
1354
+ } else {
1355
+ this.router.navigateByUrl('/manage/trax/checklist');
1356
+ }
1357
+ } else {
1358
+ this.swalToast('Unable to create checklist!','error');
1359
+ }
1360
+ } else {
1361
+ this.swalToast('Unable to create checklist!','error');
1362
+ }
1363
+ },(error: any) => {
1364
+ let err = error?.error?.error?.message || 'Unable to create checklist!Server Error!';
1365
+ this.swalToast(err,'error');
1366
+ }
1367
+ )
1368
+ }
1369
+
1370
+ saveAsDraftPop(type: string) {
1371
+ this.popupCount = this.popupCount + 1;
1372
+ const dialogRef = this.dialog.open(TraxpopupComponent,{centered: true, size: 'md'});
1373
+ dialogRef.componentInstance.data = {
1374
+ imagesrc: `<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="0 0 56 56" fill="none"><rect x="4" y="4" width="48" height="48" rx="24" fill="#FEF0C7"/><path d="M27.9998 24.0012V28.0012M27.9998 32.0012H28.0098M26.2898 18.8612L17.8198 33.0012C17.6451 33.3036 17.5527 33.6465 17.5518 33.9957C17.5508 34.3449 17.6413 34.6883 17.8142 34.9917C17.9871 35.2951 18.2365 35.5479 18.5375 35.725C18.8385 35.9021 19.1806 35.9973 19.5298 36.0012H36.4698C36.819 35.9973 37.1611 35.9021 37.4621 35.725C37.7631 35.5479 38.0124 35.2951 38.1854 34.9917C38.3583 34.6883 38.4488 34.3449 38.4478 33.9957C38.4468 33.6465 38.3544 33.3036 38.1798 33.0012L29.7098 18.8612C29.5315 18.5673 29.2805 18.3243 28.981 18.1557C28.6814 17.987 28.3435 17.8984 27.9998 17.8984C27.656 17.8984 27.3181 17.987 27.0186 18.1557C26.7191 18.3243 26.468 18.5673 26.2898 18.8612Z" stroke="#DC6803" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><rect x="4" y="4" width="48" height="48" rx="24" stroke="#FFFAEB" stroke-width="8"/></svg>`,
1375
+ title:`Unsaved changes`,
1376
+ content:`Do you want to save as draft?`,
1377
+ buttontype:'draft'
1378
+ }
1379
+ dialogRef.result.then((res)=>{
1380
+ if(!res) {
1381
+ this.popupCount = 0;
1382
+ }
1383
+ if(res) {
1384
+ if(type == 'create') {
1385
+ this.saveChecklistQuestions('saveAsDraft');
1386
+ } else {
1387
+ this.updateChecklistQuestions('saveAsDraft');
1388
+ }
1389
+ }
1390
+ });
1391
+ }
1392
+
1393
+ updateChecklistQuestions(type: string) {
1394
+ let sectionsarray: any = [];
1395
+ let checklist: any;
1396
+
1397
+ if(!this.ChecklistForm.get('checklistName')?.valid) {
1398
+ let err: string = 'Please enter checklist name!';
1399
+ this.swalToast(err,'error');
1400
+ return;
1401
+ }
1402
+
1403
+ // console.log(this.ChecklistForm);
1404
+ // return;
1405
+ checklist = this.ChecklistForm.getRawValue();
1406
+ // console.log(this.ChecklistForm,'form')
1407
+ if (!this.ChecklistForm.valid) {
1408
+ this.markFormControlsAsTouched(this.ChecklistForm,0);
1409
+ this.scrollToErrors(this.ChecklistForm.get('sections') as FormArray);
1410
+ return;
1411
+ }
1412
+ sectionsarray = checklist.sections;
1413
+ if(!this.ChecklistForm.get('checklistName')?.valid) {
1414
+ let err: string = 'Please enter checklist name!';
1415
+ this.swalToast(err,'error');
1416
+ return;
1417
+ }
1418
+ if(type == 'saveAsDraft') {
1419
+ checklist.submitType = 'save';
1420
+ } else {
1421
+ checklist.submitType = 'configure';
1422
+ }
1423
+ if(!sectionsarray.length) {
1424
+ let err: string = 'Please add atleast one section!';
1425
+ this.swalToast(err,'error');
1426
+ return;
1427
+ }
1428
+ for (let i = 0; i < sectionsarray.length; i++) {
1429
+ let sectionName = sectionsarray[i].name;
1430
+ let findExists = sectionsarray.filter((ele:any,index:any) => {
1431
+ if(index != i && sectionName.trim() == ele.name.trim())
1432
+ return ele;
1433
+ })
1434
+ if(findExists.length) {
1435
+ this.swalToast(`${sectionName} section name is Duplicated` ,'error');
1436
+ return;
1437
+ }
1438
+ if(type == 'configure' && !sectionsarray[i].questions.length) {
1439
+ let err: string = 'Please add atleast one question in section!';
1440
+ this.swalToast(err,'error');
1441
+ return;
1442
+ }
1443
+ for (let j = 0; j < sectionsarray[i].questions.length; j++) {
1444
+ sectionsarray[i].questions[j].qname = sectionsarray[i].questions[j].qname.trim().replaceAll(/\n/g, '')
1445
+ let findExists = sectionsarray[i].questions.filter((ele:any,index:any) => {
1446
+ if(index != j && sectionsarray[i].questions[j].qname.trim() == ele.qname.trim())
1447
+ return ele;
1448
+ })
1449
+ if(findExists.length) {
1450
+ this.swalToast(`${sectionsarray[i].questions[j].qname} question name is Duplicated` ,'error');
1451
+ return;
1452
+ }
1453
+ if(sectionsarray[i].questions[j].answerType == 'linearscale') {
1454
+ if(sectionsarray[i].questions[j].answers.rangeStart >= sectionsarray[i].questions[j].answers.rangeEnd){
1455
+ let err: string = 'Min value must be less than max value.';
1456
+ this.swalToast(err,'error');
1457
+ return;
1458
+ }
1459
+ // if(sectionsarray[i].questions[j].answers.linearType != '' ){
1460
+ // if(sectionsarray[i].questions[j].answers.minValue > sectionsarray[i].questions[j].answers.maxvalue) {
1461
+ // let err: string = 'Min value is greater than Max Value.';
1462
+ // this.swalToast(err,'error');
1463
+ // return;
1464
+ // }
1465
+ // }
1466
+ // if(sectionsarray[i].questions[j].answers.linearType == 'degree' && (sectionsarray[i].questions[j].answers.rangeStart < -273.15 || sectionsarray[i].questions[j].answers.rangeEnd < -273.15)) {
1467
+ // let err: string = "Min value shouldn't greater than -273.15";
1468
+ // this.swalToast(err,'error');
1469
+ // return;
1470
+ // }
1471
+ }
1472
+ if(sectionsarray[i].questions[j].answerType == 'date') {
1473
+ if(sectionsarray[i].questions[j].compliance && this.dayjs(sectionsarray[i].questions[j].answers.startDate,'DD-MM-YYYY') > this.dayjs(sectionsarray[i].questions[j].answers.endDate,'DD-MM-YYYY')){
1474
+ let err: string = 'Start date is greater than end date';
1475
+ this.swalToast(err,'error');
1476
+ return;
1477
+ }
1478
+ }
1479
+ if(sectionsarray[i].questions[j].answerType == 'image/video') {
1480
+ if(sectionsarray[i].questions[j].answers.limit && (!sectionsarray[i].questions[j].answers.imageLimit || !sectionsarray[i].questions[j].answers.videoLimit)){
1481
+ let err: string = 'image & video limit is required';
1482
+ this.swalToast(err,'error');
1483
+ return;
1484
+ }
1485
+ }
1486
+ if(sectionsarray[i].questions[j].answerType != 'descriptive') {
1487
+ delete sectionsarray[i].questions[j].descriptivetype;
1488
+ }
1489
+ if (["multiplechoicemultiple"].includes(sectionsarray[i].questions[j].answerType)) {
1490
+ for (let k = 0; k < sectionsarray[i].questions[j].answers.length; k++) {
1491
+ // sectionsarray[i].questions[j].answers[k]['answerInputStyle'] = sectionsarray[i].questions[j].answerType;
1492
+ // sectionsarray[i].questions[j].answers[k]["multiReferenceImage"] = "";
1493
+ // sectionsarray[i].questions[j].answers[k]['allowUploadfromGallery'] = false;
1494
+ // sectionsarray[i].questions[j].answers[k]['validationAnswer'] = "";
1495
+ // sectionsarray[i].questions[j].answers[k]['runAI'] = false;
1496
+ sectionsarray[i].questions[j].answers[k]['answer'] = sectionsarray[i].questions[j].answers[k]['answer'].trim();
1497
+ sectionsarray[i].questions[j].answers[k]['showLinked'] = false;
1498
+ sectionsarray[i].questions[j].answers[k]['linkedQuestion'] = 0;
1499
+ sectionsarray[i].questions[j].answers[k]['complianceScore'] = parseInt(sectionsarray[i].questions[j].answers[k]['complianceScore']);
1500
+ }
1501
+ sectionsarray[i].questions[j].allowUploadfromGallery = false;
1502
+ }
1503
+ if (["multiplechoicesingle","yes/no"].includes(sectionsarray[i].questions[j].answerType)) {
1504
+ for (let k = 0; k < sectionsarray[i].questions[j].answers.length; k++) {
1505
+ sectionsarray[i].questions[j].answers[k]['answer'] = sectionsarray[i].questions[j].answers[k]['answer'].trim();
1506
+ sectionsarray[i].questions[j].answers[k]['complianceScore'] = parseInt(sectionsarray[i].questions[j].answers[k]['complianceScore']);
1507
+ }
1508
+ }
1509
+ if (typeof sectionsarray[i].questions[j].answers === 'object' &&
1510
+ sectionsarray[i].questions[j].answers !== null &&
1511
+ !Array.isArray(sectionsarray[i].questions[j].answers) || ['descriptive','date'].includes(sectionsarray[i].questions[j].answerType)) {
1512
+ let item = {
1513
+ "answer": '',
1514
+ "answeroptionNumber": 1,
1515
+ "sopFlag": false,
1516
+ "validation": false,
1517
+ "validationAnswer": "",
1518
+ "validationType": "",
1519
+ "multiReferenceImage": sectionsarray[i].questions[j].answers?.multiReferenceImage ? sectionsarray[i].questions[j].answers?.multiReferenceImage : [],
1520
+ "showLinked":false,
1521
+ "linkedQuestion":0,
1522
+ referenceImage:'',
1523
+ ...(sectionsarray[i].questions[j].answerType == 'multipleImage' ? {'descriptivetype':sectionsarray[i].questions[j].answers?.descriptivetype}:{}),
1524
+ ...(sectionsarray[i].questions[j].answerType == 'linearscale' ? {'rangeStart':sectionsarray[i].questions[j].answers?.rangeStart,'rangeEnd':sectionsarray[i].questions[j].answers?.rangeEnd,'linearType':sectionsarray[i].questions[j].answers?.linearType,'minValue':parseInt(sectionsarray[i].questions[j].answers?.minValue),'maxValue':parseInt(sectionsarray[i].questions[j].answers?.maxValue)}:{}),
1525
+ ...(sectionsarray[i].questions[j].answerType == 'date' ? {'historicDate':sectionsarray[i].questions[j].answers?.historicDate,'startDate':sectionsarray[i].questions[j].answers?.startDate,'endDate':sectionsarray[i].questions[j].answers?.endDate}:{}),
1526
+ runAI:sectionsarray[i].questions[j]?.answers?.runAI ?? false,
1527
+ runAIFeatures:sectionsarray[i].questions[j]?.answers?.runAIFeatures ?? [],
1528
+ runAIDescription: sectionsarray[i].questions[j]?.answers?.runAIDescription ? sectionsarray[i].questions[j]?.answers?.runAIDescription : "",
1529
+ ...(sectionsarray[i].questions[j].answerType == 'image/video' ? {'limit':sectionsarray[i].questions[j].answers?.limit,'videoLimit':sectionsarray[i].questions[j].answers?.videoLimit,'imageLimit':sectionsarray[i].questions[j].answers?.imageLimit}:{}),
1530
+ ...(['date','linearscale','image','image/video'].includes(sectionsarray[i].questions[j].answerType) && {'matchedCount':parseInt(sectionsarray[i].questions[j].answers?.matchedCount),'notMatchedCount':parseInt(sectionsarray[i].questions[j].answers?.notMatchedCount)})
1531
+
1532
+ // "allowUploadfromGallery": sectionsarray[i].questions[j].answers?.allowUploadfromGallery ? sectionsarray[i].questions[j].answers?.allowUploadfromGallery : false,
1533
+ // "answerInputStyle": sectionsarray[i].questions[j].answers?.answerInputStyle ? sectionsarray[i].questions[j].answers?.answerInputStyle : "",
1534
+ // "runAI": sectionsarray[i].questions[j].answers.runAI ? sectionsarray[i].questions[j].answers.runAI : false,
1535
+ };
1536
+ sectionsarray[i].questions[j].allowUploadfromGallery = sectionsarray[i].questions[j].answers?.allowUploadfromGallery ? sectionsarray[i].questions[j].answers?.allowUploadfromGallery : false;
1537
+ // sectionsarray[i].questions[j].runAI = sectionsarray[i].questions[j].answers.runAI;
1538
+ // sectionsarray[i].questions[j].runAIFeatures = sectionsarray[i].questions[j].answers.runAIFeatures;
1539
+ if(sectionsarray[i].questions[j].answerType == 'multipleImage') {
1540
+ sectionsarray[i].questions[j].descriptivetype = sectionsarray[i].questions[j].answers?.descriptivetype ? sectionsarray[i].questions[j].answers?.descriptivetype : 'text';
1541
+ }
1542
+ if(['multipleImage','image/video'].includes(sectionsarray[i].questions[j].answerType)) {
1543
+ sectionsarray[i].questions[j].multiQuestionReferenceImage = sectionsarray[i].questions[j].answers?.multiReferenceImage ? sectionsarray[i].questions[j].answers?.multiReferenceImage : [];
1544
+ }
1545
+ sectionsarray[i].questions[j].answers = [item];
1546
+ }
1547
+ }
1548
+ }
1549
+ checklist.sections = sectionsarray;
1550
+ checklist.checklistName = checklist.checklistName.trim().charAt(0).toUpperCase() + checklist.checklistName.trim().slice(1);
1551
+ checklist.checklistName = checklist.checklistName.trim();
1552
+ checklist.checklistDescription = checklist?.checklistDescription ? checklist?.checklistDescription?.trim() : '';
1553
+ checklist.clientId = this.clientId;
1554
+ this.sopService.getUpdateChecklist(this.editvalue, checklist).pipe(takeUntil(this.detach)).subscribe((res: any) => {
1555
+ if(res) {
1556
+ if (res?.code == 200) {
1557
+ if(type=='configure') {
1558
+ this.router.navigateByUrl(`/manage/trax/configure?checkListId=${res.data.checklistId}&showEdit=true`);
1559
+ } else {
1560
+ this.router.navigateByUrl('/manage/trax/checklist');
1561
+ }
1562
+ } else {
1563
+ this.swalToast('Unable to update checklist!','error');
1564
+ }
1565
+ } else {
1566
+ this.swalToast('Unable to update checklist!','error');
1567
+ }
1568
+ }, (error) => {
1569
+ let err = error?.error?.error?.message || 'Unable to create checklist!Server Error!';
1570
+ this.swalToast(err,'error');
1571
+ });
1572
+ }
1573
+
1574
+ markFormControlsAsTouched(control: FormGroup | FormArray,sectionIndex?: number) {
1575
+ control.markAsTouched();
1576
+
1577
+ if (control instanceof FormGroup) {
1578
+ for (const controlName in control.controls) {
1579
+ this.markFormControlsAsTouched(control.get(controlName) as FormGroup);
1580
+ }
1581
+ } else if (control instanceof FormArray) {
1582
+ control.controls.forEach(formControl => {
1583
+ this.markFormControlsAsTouched(formControl as FormGroup);
1584
+ });
1585
+ }
1586
+ }
1587
+
1588
+ scrollToErrors(sections: FormArray) {
1589
+ for(let i=0;i<sections.length;i++) {
1590
+ let section = sections.at(i) as FormGroup;
1591
+ if (section.invalid) {
1592
+ let questions = section.get('questions') as FormArray;
1593
+ for(let j=0;j<questions.length;j++) {
1594
+ let question = questions.at(j) as FormGroup;
1595
+ // console.log(question,'question');
1596
+
1597
+ if (question.invalid) {
1598
+ this.show = i;
1599
+ this.scrollToQuestion(i, j);
1600
+ this.swalToast('Please fill out all the fields!','error');
1601
+ return;
1602
+ }
1603
+ }
1604
+ return;
1605
+ }
1606
+ }
1607
+ }
1608
+
1609
+ swalToast(err: string,type?:string,icon?: string) {
1610
+ if(type == 'error') {
1611
+ this.toast.getErrorToast(err);
1612
+ }
1613
+ else {
1614
+ this.toast.getSuccessToast(err);
1615
+ }
1616
+ // Swal.fire({
1617
+ // toast: true,
1618
+ // ...( icon ? { iconHtml: icon } : {}),
1619
+ // // titleText: `Checklist Form Error`,
1620
+ // html: `<div class="row ">
1621
+ // <div class="col-12 mt-2">
1622
+ // <div class="toasttitile">${err}</div>
1623
+ // </div>
1624
+
1625
+ // </div>`,
1626
+ // position: 'bottom',
1627
+ // showConfirmButton: false,
1628
+ // showCloseButton: true,
1629
+ // timer: 6000,
1630
+ // timerProgressBar: true,
1631
+ // didOpen: (toast) => {
1632
+ // toast.addEventListener('mouseenter', Swal.stopTimer)
1633
+ // toast.addEventListener('mouseleave', Swal.resumeTimer)
1634
+ // $("#kt_create_account_form_account_type_personal")?.val('');
1635
+ // this.changedetector.detectChanges();
1636
+ // }
1637
+ // });
1638
+ }
1639
+
1640
+ RunAI(sIdx:number,qIdx: number,ansIdx:number=-1) {
1641
+ let dialogRef: any;
1642
+ let question: any = this.getQuestionFormControl(sIdx,qIdx,'qname')?.value;
1643
+ if(this.getAnswerFormGroup_FormControl(sIdx,qIdx,'runAI',ansIdx)?.value == false) {
1644
+ if(!question || !this.ChecklistForm.get('checklistName')?.value) {
1645
+ let err: string = !question ? 'Please enter question to continue!' : 'Please enter Checklist Name to continue!';
1646
+ this.swalToast(err,'error');
1647
+ this.runAIOff(sIdx, qIdx,false,ansIdx);
1648
+ return;
1649
+ } else {
1650
+ const dialogRef = this.dialog.open(TraxpopupComponent,{centered: true, size: 'md'});
1651
+ dialogRef.componentInstance.data = {
1652
+ imagesrc: `<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="0 0 56 56" fill="none"><rect x="4" y="4" width="48" height="48" rx="24" fill="#D1FADF"/><path d="M23.3564 19.3525C24.1748 18.7327 25.1738 18.3985 26.2004 18.4009C26.5549 18.393 26.9057 18.4746 27.2204 18.6382C27.535 18.8018 27.8033 19.0421 28.0004 19.3369C28.1975 19.0421 28.4658 18.8018 28.7804 18.6382C29.095 18.4746 29.4459 18.393 29.8004 18.4009C30.827 18.3985 31.826 18.7327 32.6444 19.3525C33.2744 19.8421 33.7604 20.5201 33.932 21.3397C34.3256 21.3697 34.6856 21.5329 34.988 21.7789C35.4464 22.1509 35.78 22.7089 35.99 23.2993C36.3188 24.2173 36.4076 25.3873 36.0668 26.3833C36.1532 26.4241 36.2384 26.4721 36.3212 26.5273C36.6512 26.7469 36.902 27.0613 37.0868 27.4321C37.4504 28.1581 37.6004 29.1709 37.6004 30.4009C37.6004 31.7701 37.0784 32.6893 36.416 33.2569C36.0497 33.571 35.6174 33.7986 35.1512 33.9229C35.0312 34.5925 34.6952 35.3677 34.1684 36.0253C33.4844 36.8833 32.4236 37.6009 31.0004 37.6009C29.8724 37.6009 28.9748 36.9769 28.3916 36.3649C28.2522 36.2188 28.1215 36.0645 28.0004 35.9029C27.8793 36.0645 27.7486 36.2188 27.6092 36.3649C27.026 36.9769 26.1296 37.6009 25.0004 37.6009C23.5772 37.6009 22.5176 36.8833 21.8324 36.0253C21.3401 35.414 21.0029 34.6927 20.8496 33.9229C20.3834 33.7986 19.9511 33.571 19.5848 33.2569C18.9224 32.6893 18.4004 31.7689 18.4004 30.4009C18.4004 29.1709 18.5516 28.1569 18.914 27.4321C19.0857 27.0685 19.3497 26.7561 19.6796 26.5261C19.7606 26.4725 19.8457 26.4251 19.934 26.3845C19.5932 25.3861 19.682 24.2173 20.0108 23.2993C20.2208 22.7089 20.5544 22.1509 21.0128 21.7789C21.3152 21.5329 21.6752 21.3709 22.0688 21.3397C22.2416 20.5201 22.7264 19.8421 23.3564 19.3525ZM27.4004 21.4009V21.3889L27.398 21.3289C27.3803 21.0161 27.3181 20.7074 27.2132 20.4121C27.1385 20.1892 27.0113 19.9876 26.8424 19.8241C26.6651 19.6698 26.4352 19.5898 26.2004 19.6009C25.4407 19.5983 24.7009 19.8435 24.0932 20.2993C23.5364 20.7325 23.2004 21.3193 23.2004 22.0009C23.2003 22.0959 23.1777 22.1896 23.1343 22.2741C23.091 22.3587 23.0282 22.4318 22.9511 22.4873C22.874 22.5428 22.7848 22.5793 22.6909 22.5936C22.5969 22.6079 22.5009 22.5997 22.4108 22.5697C22.1852 22.4953 21.9836 22.5373 21.7688 22.7101C21.5336 22.9021 21.3044 23.2429 21.14 23.7025C20.8052 24.6409 20.84 25.7773 21.2996 26.4685C21.3652 26.567 21.4003 26.6826 21.4004 26.8009H22.3004C23.0165 26.8009 23.7032 27.0854 24.2096 27.5917C24.7159 28.0981 25.0004 28.7848 25.0004 29.5009V29.9029C25.4007 30.0445 25.7381 30.323 25.953 30.6892C26.1678 31.0555 26.2463 31.4859 26.1745 31.9044C26.1027 32.3229 25.8852 32.7025 25.5606 32.9762C25.2359 33.2499 24.825 33.4 24.4004 33.4C23.9758 33.4 23.5648 33.2499 23.2402 32.9762C22.9156 32.7025 22.6981 32.3229 22.6263 31.9044C22.5545 31.4859 22.633 31.0555 22.8478 30.6892C23.0627 30.323 23.4001 30.0445 23.8004 29.9029V29.5009C23.8004 28.6729 23.1284 28.0009 22.3004 28.0009H20.2004C20.1287 28.0008 20.0575 27.9878 19.9904 27.9625L19.9868 27.9697C19.7492 28.4437 19.6004 29.2309 19.6004 30.4009C19.6004 31.4317 19.9784 32.0125 20.366 32.3449C20.7824 32.7025 21.2444 32.8009 21.4004 32.8009C21.5595 32.8009 21.7121 32.8641 21.8247 32.9767C21.9372 33.0892 22.0004 33.2418 22.0004 33.4009C22.0004 33.8425 22.2404 34.6141 22.7684 35.2765C23.2832 35.9185 24.0236 36.4009 25.0004 36.4009C25.6724 36.4009 26.2748 36.0253 26.7404 35.5369C26.9696 35.2969 27.1484 35.0485 27.2648 34.8445C27.3178 34.7541 27.3631 34.6593 27.4004 34.5613V25.0009H26.0984C25.9569 25.4012 25.6783 25.7387 25.3121 25.9535C24.9459 26.1683 24.5154 26.2468 24.097 26.175C23.6785 26.1032 23.2988 25.8858 23.0251 25.5611C22.7514 25.2365 22.6013 24.8255 22.6013 24.4009C22.6013 23.9763 22.7514 23.5654 23.0251 23.2407C23.2988 22.9161 23.6785 22.6986 24.097 22.6268C24.5154 22.555 24.9459 22.6335 25.3121 22.8483C25.6783 23.0632 25.9569 23.4006 26.0984 23.8009H27.4004V21.4009ZM28.6004 33.3997V34.5601C28.6377 34.6581 28.683 34.7528 28.736 34.8433C28.8536 35.0473 29.0312 35.2957 29.2592 35.5357C29.726 36.0241 30.3296 36.3997 31.0004 36.3997C31.9772 36.3997 32.7176 35.9173 33.2324 35.2753C33.7604 34.6129 34.0004 33.8413 34.0004 33.3997C34.0004 33.2406 34.0636 33.088 34.1761 32.9755C34.2886 32.8629 34.4413 32.7997 34.6004 32.7997C34.7564 32.7997 35.2184 32.7013 35.6348 32.3437C36.0224 32.0113 36.4004 31.4305 36.4004 30.3997C36.4004 29.2297 36.2504 28.4437 36.014 27.9685C35.9349 27.7916 35.8108 27.6385 35.654 27.5245C35.5189 27.4381 35.3606 27.395 35.2004 27.4009C35.0919 27.4009 34.9854 27.3714 34.8923 27.3156C34.7992 27.2598 34.723 27.1798 34.6717 27.0841C34.6205 26.9884 34.5962 26.8807 34.6014 26.7723C34.6066 26.6638 34.6411 26.5589 34.7012 26.4685C35.162 25.7773 35.1956 24.6409 34.8608 23.7025C34.6964 23.2429 34.4672 22.9009 34.232 22.7101C34.0172 22.5373 33.8156 22.4941 33.59 22.5697C33.4998 22.5997 33.4038 22.6079 33.3099 22.5936C33.216 22.5793 33.1268 22.5428 33.0497 22.4873C32.9726 22.4318 32.9098 22.3587 32.8664 22.2741C32.8231 22.1896 32.8005 22.0959 32.8004 22.0009C32.8004 21.3193 32.4644 20.7325 31.9064 20.2993C31.299 19.8438 30.5596 19.5986 29.8004 19.6009C29.5656 19.5898 29.3356 19.6698 29.1584 19.8241C28.9889 19.9874 28.8613 20.1891 28.7864 20.4121C28.6721 20.7256 28.6093 21.0554 28.6004 21.3889V32.2009H29.5004C30.3284 32.2009 31.0004 31.5289 31.0004 30.7009V28.4989C30.6001 28.3574 30.2627 28.0789 30.0478 27.7126C29.833 27.3464 29.7545 26.916 29.8263 26.4975C29.8981 26.079 30.1156 25.6993 30.4402 25.4257C30.7648 25.152 31.1758 25.0019 31.6004 25.0019C32.025 25.0019 32.4359 25.152 32.7606 25.4257C33.0852 25.6993 33.3027 26.079 33.3745 26.4975C33.4463 26.916 33.3678 27.3464 33.153 27.7126C32.9381 28.0789 32.6007 28.3574 32.2004 28.4989V30.7009C32.2004 31.417 31.9159 32.1038 31.4096 32.6101C30.9032 33.1165 30.2165 33.4009 29.5004 33.4009H28.6004V33.3997ZM23.8004 24.4009C23.8004 24.5601 23.8636 24.7127 23.9761 24.8252C24.0886 24.9377 24.2413 25.0009 24.4004 25.0009C24.5595 25.0009 24.7121 24.9377 24.8247 24.8252C24.9372 24.7127 25.0004 24.5601 25.0004 24.4009C25.0004 24.2418 24.9372 24.0892 24.8247 23.9767C24.7121 23.8641 24.5595 23.8009 24.4004 23.8009C24.2413 23.8009 24.0886 23.8641 23.9761 23.9767C23.8636 24.0892 23.8004 24.2418 23.8004 24.4009ZM31.6004 27.4009C31.7595 27.4009 31.9121 27.3377 32.0247 27.2252C32.1372 27.1127 32.2004 26.9601 32.2004 26.8009C32.2004 26.6418 32.1372 26.4892 32.0247 26.3767C31.9121 26.2641 31.7595 26.2009 31.6004 26.2009C31.4413 26.2009 31.2886 26.2641 31.1761 26.3767C31.0636 26.4892 31.0004 26.6418 31.0004 26.8009C31.0004 26.9601 31.0636 27.1127 31.1761 27.2252C31.2886 27.3377 31.4413 27.4009 31.6004 27.4009ZM24.4004 31.0009C24.2413 31.0009 24.0886 31.0641 23.9761 31.1767C23.8636 31.2892 23.8004 31.4418 23.8004 31.6009C23.8004 31.7601 23.8636 31.9127 23.9761 32.0252C24.0886 32.1377 24.2413 32.2009 24.4004 32.2009C24.5595 32.2009 24.7121 32.1377 24.8247 32.0252C24.9372 31.9127 25.0004 31.7601 25.0004 31.6009C25.0004 31.4418 24.9372 31.2892 24.8247 31.1767C24.7121 31.0641 24.5595 31.0009 24.4004 31.0009Z" fill="#039855"/><rect x="4" y="4" width="48" height="48" rx="24" stroke="#ECFDF3" stroke-width="8"/></svg>`,
1653
+ title: `Run AI on image uploaded`,
1654
+ content: `Use the power of AI to compare and detect anomalies between uploaded and reference image.`,
1655
+ inputlabel1: 'Question',
1656
+ inputtype1: 'text',
1657
+ input1: 'true',
1658
+ inputlabel2: 'Specify your request',
1659
+ inputtype2: 'text',
1660
+ resType: 'custom',
1661
+ input2: 'true',
1662
+ placeholder1: question,
1663
+ placeholder2: 'Please compare the uploaded images a..',
1664
+ buttontype: 'Request'
1665
+ }
1666
+ dialogRef.result.then((res: any) => {
1667
+ if (res && res.status == 'confirm') {
1668
+ let req: any = {
1669
+ checklistName: this.ChecklistForm.get('checklistName')?.value,
1670
+ questionName: question,
1671
+ runAIDescription: res.data.requestText,
1672
+ answerType: "image",
1673
+ referenceImage: this.getAnswerFormGroup_FormControl(sIdx, qIdx, "multiReferenceImage",ansIdx)?.value || '',
1674
+ clientId:this.clientId
1675
+ }
1676
+ this.sopService.runAIInsert(req).pipe(takeUntil(this.detach)).subscribe((apires: any) => {
1677
+ if (apires) {
1678
+ if (apires.code == 200) {
1679
+ if (!this.hasValidationEnabled(sIdx, qIdx)) {
1680
+ ((((this.ChecklistForm.get('sections') as FormArray)
1681
+ .at(sIdx) as FormGroup)
1682
+ .get('questions') as FormArray)
1683
+ .at(qIdx) as FormGroup).get('compliance')?.enable({ onlySelf: true })
1684
+ }
1685
+ console.log(((((this.ChecklistForm.get('sections') as FormArray)
1686
+ .at(sIdx) as FormGroup)
1687
+ .get('questions') as FormArray)
1688
+ .at(qIdx) as FormGroup).get('compliance'))
1689
+ this.getAnswerFormGroup_FormControl(sIdx, qIdx, 'runAI',ansIdx)?.patchValue(true);
1690
+ this.getQuestionFormControl(sIdx, qIdx, 'runAI',ansIdx)?.patchValue(true);
1691
+ this.getQuestionFormControl(sIdx, qIdx, 'runAIDescription',ansIdx)?.patchValue(res.data.requestText);
1692
+ this.swalToast(
1693
+ `<span style="padding-right: 36px;">${apires.data.message}</span>`,
1694
+ `<img src="../../../../assets/Icons/sop-runai-tosticon.svg" />`
1695
+ );
1696
+ // <a
1697
+ // href="/support/view-tickets"
1698
+ // target="_blank"
1699
+ // style="color: var(--primary-700, #009BF3);font-family: Roboto;font-size: 15px;font-weight: 700;text-decoration: underline;cursor: pointer;">
1700
+ // View Ticket
1701
+ // </a>
1702
+ } else {
1703
+ this.runAIOff(sIdx, qIdx,true,ansIdx);
1704
+ }
1705
+ } else {
1706
+ this.runAIOff(sIdx, qIdx,true,ansIdx);
1707
+ }
1708
+ }, (error) => {
1709
+ this.runAIOff(sIdx, qIdx,true,ansIdx);
1710
+ });
1711
+ } else {
1712
+ this.runAIOff(sIdx, qIdx,false,ansIdx);
1713
+ }
1714
+ });
1715
+ }
1716
+ } else {
1717
+ const dialogRef = this.dialog.open(TraxpopupComponent,{centered: true, size: 'md'});
1718
+ dialogRef.componentInstance.data = {
1719
+ imagesrc: `<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="0 0 56 56" fill="none"><rect x="4" y="4" width="48" height="48" rx="24" fill="#D1FADF"/><path d="M23.3564 19.3525C24.1748 18.7327 25.1738 18.3985 26.2004 18.4009C26.5549 18.393 26.9057 18.4746 27.2204 18.6382C27.535 18.8018 27.8033 19.0421 28.0004 19.3369C28.1975 19.0421 28.4658 18.8018 28.7804 18.6382C29.095 18.4746 29.4459 18.393 29.8004 18.4009C30.827 18.3985 31.826 18.7327 32.6444 19.3525C33.2744 19.8421 33.7604 20.5201 33.932 21.3397C34.3256 21.3697 34.6856 21.5329 34.988 21.7789C35.4464 22.1509 35.78 22.7089 35.99 23.2993C36.3188 24.2173 36.4076 25.3873 36.0668 26.3833C36.1532 26.4241 36.2384 26.4721 36.3212 26.5273C36.6512 26.7469 36.902 27.0613 37.0868 27.4321C37.4504 28.1581 37.6004 29.1709 37.6004 30.4009C37.6004 31.7701 37.0784 32.6893 36.416 33.2569C36.0497 33.571 35.6174 33.7986 35.1512 33.9229C35.0312 34.5925 34.6952 35.3677 34.1684 36.0253C33.4844 36.8833 32.4236 37.6009 31.0004 37.6009C29.8724 37.6009 28.9748 36.9769 28.3916 36.3649C28.2522 36.2188 28.1215 36.0645 28.0004 35.9029C27.8793 36.0645 27.7486 36.2188 27.6092 36.3649C27.026 36.9769 26.1296 37.6009 25.0004 37.6009C23.5772 37.6009 22.5176 36.8833 21.8324 36.0253C21.3401 35.414 21.0029 34.6927 20.8496 33.9229C20.3834 33.7986 19.9511 33.571 19.5848 33.2569C18.9224 32.6893 18.4004 31.7689 18.4004 30.4009C18.4004 29.1709 18.5516 28.1569 18.914 27.4321C19.0857 27.0685 19.3497 26.7561 19.6796 26.5261C19.7606 26.4725 19.8457 26.4251 19.934 26.3845C19.5932 25.3861 19.682 24.2173 20.0108 23.2993C20.2208 22.7089 20.5544 22.1509 21.0128 21.7789C21.3152 21.5329 21.6752 21.3709 22.0688 21.3397C22.2416 20.5201 22.7264 19.8421 23.3564 19.3525ZM27.4004 21.4009V21.3889L27.398 21.3289C27.3803 21.0161 27.3181 20.7074 27.2132 20.4121C27.1385 20.1892 27.0113 19.9876 26.8424 19.8241C26.6651 19.6698 26.4352 19.5898 26.2004 19.6009C25.4407 19.5983 24.7009 19.8435 24.0932 20.2993C23.5364 20.7325 23.2004 21.3193 23.2004 22.0009C23.2003 22.0959 23.1777 22.1896 23.1343 22.2741C23.091 22.3587 23.0282 22.4318 22.9511 22.4873C22.874 22.5428 22.7848 22.5793 22.6909 22.5936C22.5969 22.6079 22.5009 22.5997 22.4108 22.5697C22.1852 22.4953 21.9836 22.5373 21.7688 22.7101C21.5336 22.9021 21.3044 23.2429 21.14 23.7025C20.8052 24.6409 20.84 25.7773 21.2996 26.4685C21.3652 26.567 21.4003 26.6826 21.4004 26.8009H22.3004C23.0165 26.8009 23.7032 27.0854 24.2096 27.5917C24.7159 28.0981 25.0004 28.7848 25.0004 29.5009V29.9029C25.4007 30.0445 25.7381 30.323 25.953 30.6892C26.1678 31.0555 26.2463 31.4859 26.1745 31.9044C26.1027 32.3229 25.8852 32.7025 25.5606 32.9762C25.2359 33.2499 24.825 33.4 24.4004 33.4C23.9758 33.4 23.5648 33.2499 23.2402 32.9762C22.9156 32.7025 22.6981 32.3229 22.6263 31.9044C22.5545 31.4859 22.633 31.0555 22.8478 30.6892C23.0627 30.323 23.4001 30.0445 23.8004 29.9029V29.5009C23.8004 28.6729 23.1284 28.0009 22.3004 28.0009H20.2004C20.1287 28.0008 20.0575 27.9878 19.9904 27.9625L19.9868 27.9697C19.7492 28.4437 19.6004 29.2309 19.6004 30.4009C19.6004 31.4317 19.9784 32.0125 20.366 32.3449C20.7824 32.7025 21.2444 32.8009 21.4004 32.8009C21.5595 32.8009 21.7121 32.8641 21.8247 32.9767C21.9372 33.0892 22.0004 33.2418 22.0004 33.4009C22.0004 33.8425 22.2404 34.6141 22.7684 35.2765C23.2832 35.9185 24.0236 36.4009 25.0004 36.4009C25.6724 36.4009 26.2748 36.0253 26.7404 35.5369C26.9696 35.2969 27.1484 35.0485 27.2648 34.8445C27.3178 34.7541 27.3631 34.6593 27.4004 34.5613V25.0009H26.0984C25.9569 25.4012 25.6783 25.7387 25.3121 25.9535C24.9459 26.1683 24.5154 26.2468 24.097 26.175C23.6785 26.1032 23.2988 25.8858 23.0251 25.5611C22.7514 25.2365 22.6013 24.8255 22.6013 24.4009C22.6013 23.9763 22.7514 23.5654 23.0251 23.2407C23.2988 22.9161 23.6785 22.6986 24.097 22.6268C24.5154 22.555 24.9459 22.6335 25.3121 22.8483C25.6783 23.0632 25.9569 23.4006 26.0984 23.8009H27.4004V21.4009ZM28.6004 33.3997V34.5601C28.6377 34.6581 28.683 34.7528 28.736 34.8433C28.8536 35.0473 29.0312 35.2957 29.2592 35.5357C29.726 36.0241 30.3296 36.3997 31.0004 36.3997C31.9772 36.3997 32.7176 35.9173 33.2324 35.2753C33.7604 34.6129 34.0004 33.8413 34.0004 33.3997C34.0004 33.2406 34.0636 33.088 34.1761 32.9755C34.2886 32.8629 34.4413 32.7997 34.6004 32.7997C34.7564 32.7997 35.2184 32.7013 35.6348 32.3437C36.0224 32.0113 36.4004 31.4305 36.4004 30.3997C36.4004 29.2297 36.2504 28.4437 36.014 27.9685C35.9349 27.7916 35.8108 27.6385 35.654 27.5245C35.5189 27.4381 35.3606 27.395 35.2004 27.4009C35.0919 27.4009 34.9854 27.3714 34.8923 27.3156C34.7992 27.2598 34.723 27.1798 34.6717 27.0841C34.6205 26.9884 34.5962 26.8807 34.6014 26.7723C34.6066 26.6638 34.6411 26.5589 34.7012 26.4685C35.162 25.7773 35.1956 24.6409 34.8608 23.7025C34.6964 23.2429 34.4672 22.9009 34.232 22.7101C34.0172 22.5373 33.8156 22.4941 33.59 22.5697C33.4998 22.5997 33.4038 22.6079 33.3099 22.5936C33.216 22.5793 33.1268 22.5428 33.0497 22.4873C32.9726 22.4318 32.9098 22.3587 32.8664 22.2741C32.8231 22.1896 32.8005 22.0959 32.8004 22.0009C32.8004 21.3193 32.4644 20.7325 31.9064 20.2993C31.299 19.8438 30.5596 19.5986 29.8004 19.6009C29.5656 19.5898 29.3356 19.6698 29.1584 19.8241C28.9889 19.9874 28.8613 20.1891 28.7864 20.4121C28.6721 20.7256 28.6093 21.0554 28.6004 21.3889V32.2009H29.5004C30.3284 32.2009 31.0004 31.5289 31.0004 30.7009V28.4989C30.6001 28.3574 30.2627 28.0789 30.0478 27.7126C29.833 27.3464 29.7545 26.916 29.8263 26.4975C29.8981 26.079 30.1156 25.6993 30.4402 25.4257C30.7648 25.152 31.1758 25.0019 31.6004 25.0019C32.025 25.0019 32.4359 25.152 32.7606 25.4257C33.0852 25.6993 33.3027 26.079 33.3745 26.4975C33.4463 26.916 33.3678 27.3464 33.153 27.7126C32.9381 28.0789 32.6007 28.3574 32.2004 28.4989V30.7009C32.2004 31.417 31.9159 32.1038 31.4096 32.6101C30.9032 33.1165 30.2165 33.4009 29.5004 33.4009H28.6004V33.3997ZM23.8004 24.4009C23.8004 24.5601 23.8636 24.7127 23.9761 24.8252C24.0886 24.9377 24.2413 25.0009 24.4004 25.0009C24.5595 25.0009 24.7121 24.9377 24.8247 24.8252C24.9372 24.7127 25.0004 24.5601 25.0004 24.4009C25.0004 24.2418 24.9372 24.0892 24.8247 23.9767C24.7121 23.8641 24.5595 23.8009 24.4004 23.8009C24.2413 23.8009 24.0886 23.8641 23.9761 23.9767C23.8636 24.0892 23.8004 24.2418 23.8004 24.4009ZM31.6004 27.4009C31.7595 27.4009 31.9121 27.3377 32.0247 27.2252C32.1372 27.1127 32.2004 26.9601 32.2004 26.8009C32.2004 26.6418 32.1372 26.4892 32.0247 26.3767C31.9121 26.2641 31.7595 26.2009 31.6004 26.2009C31.4413 26.2009 31.2886 26.2641 31.1761 26.3767C31.0636 26.4892 31.0004 26.6418 31.0004 26.8009C31.0004 26.9601 31.0636 27.1127 31.1761 27.2252C31.2886 27.3377 31.4413 27.4009 31.6004 27.4009ZM24.4004 31.0009C24.2413 31.0009 24.0886 31.0641 23.9761 31.1767C23.8636 31.2892 23.8004 31.4418 23.8004 31.6009C23.8004 31.7601 23.8636 31.9127 23.9761 32.0252C24.0886 32.1377 24.2413 32.2009 24.4004 32.2009C24.5595 32.2009 24.7121 32.1377 24.8247 32.0252C24.9372 31.9127 25.0004 31.7601 25.0004 31.6009C25.0004 31.4418 24.9372 31.2892 24.8247 31.1767C24.7121 31.0641 24.5595 31.0009 24.4004 31.0009Z" fill="#039855"/><rect x="4" y="4" width="48" height="48" rx="24" stroke="#ECFDF3" stroke-width="8"/></svg>`,
1720
+ title: `Don't run AI on image uploaded`,
1721
+ content: `Do you wish to not run AI in the image?`,
1722
+ buttontype: 'confirm'
1723
+ }
1724
+ dialogRef.result.then((res: any) => {
1725
+ if (res) {
1726
+ this.runAIOff(sIdx,qIdx,false,ansIdx);
1727
+ } else {
1728
+ this.getAnswerFormGroup_FormControl(sIdx, qIdx, 'runAI')?.patchValue(true);
1729
+ this.getQuestionFormControl(sIdx, qIdx, 'runAI')?.patchValue(true);
1730
+ }
1731
+ });
1732
+ }
1733
+ }
1734
+
1735
+ runAIOff(sIdx: number, qIdx: number, showError?: boolean,ansIdx:number=-1) {
1736
+ const answerFormGroup = this.getAnswerFormGroup_FormControl(sIdx, qIdx, 'runAI',ansIdx);
1737
+ const sectionQuestion = ((((this.ChecklistForm.get('sections') as FormArray).at(sIdx) as FormGroup).get('questions') as FormArray).at(qIdx) as FormGroup);
1738
+ if (answerFormGroup) {
1739
+ answerFormGroup.patchValue(false);
1740
+ }
1741
+
1742
+ const answersControl = sectionQuestion.get('answers');
1743
+ let answers: FormGroup | null = null;
1744
+ if (ansIdx !== -1 && answersControl instanceof FormArray) {
1745
+ answers = answersControl.at(ansIdx) as FormGroup;
1746
+ } else if (answersControl instanceof FormGroup) {
1747
+ answers = answersControl;
1748
+ }
1749
+ (answers?.get('runAIFeatures') as FormArray)?.clear();
1750
+
1751
+ const questionControl = this.getQuestionFormControl(sIdx, qIdx, 'runAI',ansIdx);
1752
+ if (questionControl) {
1753
+ questionControl.patchValue(false);
1754
+ }
1755
+
1756
+ (answers?.get('runAIDescription') as FormControl)?.setValue('');
1757
+
1758
+ this.unlockQuestionAfterRunAIOff(sIdx, qIdx, ansIdx);
1759
+
1760
+ if (showError) {
1761
+ this.swalToast('Unable to process runAI request! Try again after some time!','error');
1762
+ }
1763
+ }
1764
+
1765
+ unlockQuestionAfterRunAIOff(sIdx: number, qIdx: number, ansIdx: number = -1) {
1766
+ const question = ((((this.ChecklistForm.get('sections') as FormArray)
1767
+ .at(sIdx) as FormGroup)
1768
+ .get('questions') as FormArray)
1769
+ .at(qIdx) as FormGroup);
1770
+
1771
+ const answers = question.get('answers');
1772
+
1773
+ if (answers instanceof FormArray) {
1774
+ const stillLocked = answers.controls.some((a, idx) =>
1775
+ idx !== ansIdx && (a as FormGroup).get('runAI')?.value === true);
1776
+ if (stillLocked) return;
1777
+ }
1778
+
1779
+ question.get('disableRunAI')?.setValue(false, { emitEvent: false });
1780
+
1781
+ ['qname', 'answerType', 'runAI', 'allowUploadfromGallery', 'descriptivetype']
1782
+ .forEach(name => question.get(name)?.enable({ emitEvent: false }));
1783
+
1784
+ if (answers instanceof FormArray) {
1785
+ answers.controls.forEach(ans => {
1786
+ if (ans instanceof FormGroup) {
1787
+ ['answer', 'validation', 'validationType', 'allowUploadfromGallery', 'runAI']
1788
+ .forEach(name => ans.get(name)?.enable({ emitEvent: false }));
1789
+ }
1790
+ });
1791
+ } else if (answers instanceof FormGroup) {
1792
+ ['allowUploadfromGallery', 'runAI']
1793
+ .forEach(name => answers.get(name)?.enable({ emitEvent: false }));
1794
+ }
1795
+
1796
+ this.changedetector.detectChanges();
1797
+ }
1798
+
1799
+
1800
+ getSectionFormArray() {
1801
+ return (this.ChecklistForm.get('sections') as FormArray);
1802
+ }
1803
+
1804
+ getFormControl(formControl: string) {
1805
+ return (this.ChecklistForm.get(formControl) as FormControl);
1806
+ }
1807
+
1808
+ getSectionFormControl(sectionIndex: number, formControlName: string) {
1809
+ return (
1810
+ (this.ChecklistForm.get('sections') as FormArray)
1811
+ .at(sectionIndex) as FormGroup)
1812
+ .get(formControlName);
1813
+ }
1814
+
1815
+ getQuestionFormControl(sectionIndex: number, questionIndex: number, formControlName: string,ansIdx:number = -1) {
1816
+ const sections = this.ChecklistForm.get('sections') as FormArray | null;
1817
+ if (!sections) return null;
1818
+
1819
+ const section = sections.at(sectionIndex) as FormGroup | null;
1820
+ if (!section) return null;
1821
+
1822
+ const questions = section.get('questions') as FormArray | null;
1823
+ if (!questions) return null;
1824
+
1825
+ let question = questions.at(questionIndex) as FormGroup | null;
1826
+ if (!question) return null;
1827
+
1828
+ if(ansIdx != -1) {
1829
+ let answerList = question.get('answers') as FormArray | null;
1830
+ if(!answerList) return null;
1831
+ question = answerList.at(ansIdx) as FormGroup | null;
1832
+ if(!question) return null;
1833
+ }
1834
+
1835
+ const control = question.get(formControlName) as FormControl | null;
1836
+ return control;
1837
+ }
1838
+
1839
+
1840
+ getFormArrayQuestions(sectionIndex: number) {
1841
+ return ((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex).get('questions') as FormArray);
1842
+ }
1843
+
1844
+ // individual question
1845
+ getQuestionsFormGroup(sectionIndex: number, questionIndex: number) {
1846
+ return (((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex).get('questions') as FormArray).at(questionIndex) as FormGroup);
1847
+ }
1848
+
1849
+ getFormArrayQuestionsAnswer(sectionIndex: number, questionIndex: number, formArrayName: string,ansIndex:number = -1,linkquestionIndex:number = -1) {
1850
+ let section = ((this.ChecklistForm.get('sections') as FormArray)?.at(sectionIndex) as FormGroup);
1851
+ let questions = ((section.get('questions') as FormArray)?.at(questionIndex) as FormGroup);
1852
+ if(ansIndex == -1) {
1853
+ return (questions.get(formArrayName) as FormArray);
1854
+ }
1855
+ else {
1856
+ let answers = ((questions.get('answers') as FormArray)?.at(ansIndex) as FormGroup);
1857
+ let linkedIndex = ((answers.get('linkQuestionAnswers') as FormArray).at(linkquestionIndex) as FormGroup);
1858
+ return (linkedIndex.get('answers') as FormArray)
1859
+ }
1860
+ }
1861
+
1862
+ getFormArrayLinkedQuestions(sectionIndex: number, questionIndex: number,answerIndex:number) {
1863
+ let section = ((this.ChecklistForm.get('sections') as FormArray)?.at(sectionIndex) as FormGroup);
1864
+ let questions = ((section.get('questions') as FormArray)?.at(questionIndex) as FormGroup);
1865
+ let answer = (questions.get('answers') as FormArray)?.at(answerIndex) as FormGroup;
1866
+ return (answer.get('linkQuestionAnswers') as FormArray)
1867
+ }
1868
+
1869
+ getQuestionsFormArrayValues(sectionIndex: number): any[] {
1870
+ return ((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex).get('questions') as FormArray).getRawValue() || [];
1871
+ }
1872
+
1873
+ getAnswerFormGroup_FormControl(sectionIndex: number, questionIndex: number, formControlName: string,ansIdx:number= -1) {
1874
+ const sections = this.ChecklistForm.get('sections') as FormArray | null;
1875
+ if (!sections) return null;
1876
+
1877
+ const section = sections.at(sectionIndex) as FormGroup | null;
1878
+ if (!section) return null;
1879
+
1880
+ const questions = section.get('questions') as FormArray | null;
1881
+ if (!questions) return null;
1882
+
1883
+ const question = questions.at(questionIndex) as FormGroup | null;
1884
+ if (!question) return null;
1885
+
1886
+ if(formControlName == "multiQuestionReferenceImage") {
1887
+ const control = question.get(formControlName) as FormArray | null;
1888
+ return control;
1889
+ }
1890
+ else {
1891
+ let answers = question.get('answers') as FormGroup | null;
1892
+ if (!answers) return null;
1893
+
1894
+ if(ansIdx != -1) {
1895
+
1896
+ let answerList = question.get('answers') as FormArray | null;
1897
+ if(!answerList) return null;
1898
+ answers = answerList.at(ansIdx) as FormGroup | null;
1899
+ if (!answers) return null;
1900
+ }
1901
+ const control = answers.get(formControlName) as FormControl | null;
1902
+ return control;
1903
+ }
1904
+
1905
+ }
1906
+
1907
+ removedNestedQuestion(sectionindex: number,qno:any) {
1908
+ let questions = (this.getSectionFormArray().at(sectionindex).get('questions') as FormArray);
1909
+ for (let i = 0; i < questions.length; i++) {
1910
+ let answers = (questions.at(i) as FormGroup)?.get('answers') as FormArray;
1911
+ if(answers) {
1912
+ for(let j=0;j<answers.length;j++) {
1913
+ let linked = (answers.at(j) as FormGroup)?.get('showLinked')?.value;
1914
+ if(linked) {
1915
+ let questionNo = (answers.at(j) as FormGroup)?.get('linkedQuestion')?.value;
1916
+ if(questionNo == qno) {
1917
+ (answers.at(j) as FormGroup)?.get('linkedQuestion')?.setValue(0);
1918
+ (answers.at(j) as FormGroup)?.get('showLinked')?.setValue(false);
1919
+ }
1920
+ }
1921
+ }
1922
+ }
1923
+ }
1924
+ }
1925
+
1926
+ updateQuestionQnos(sectionindex: number) {
1927
+ let questions = (this.getSectionFormArray().at(sectionindex).get('questions') as FormArray);
1928
+ let updatedList:any = [];
1929
+ for (let i = 0; i < questions.length; i++) {
1930
+ let qno = (questions.at(i) as FormGroup)?.get('qno')?.value;
1931
+ if(!this.deletedList.includes(qno)) {
1932
+ let questionArray = questions?.value;
1933
+ for(let qn = 0; qn < questionArray.length ;qn++) {
1934
+ if(!updatedList.includes(qn)) {
1935
+ let item = questionArray[qn];
1936
+ if (!['descriptive', 'image', 'descriptiveImage', 'multipleImage', 'video','linearscale','time','date'].includes(item.answerType)) {
1937
+ for(let ans = 0; ans < item.answers.length ; ans++) {
1938
+ if (item.answers[ans].linkedQuestion == qno) {
1939
+ updatedList.push(qn);
1940
+ (((questions.at(qn) as FormGroup)?.get('answers') as FormArray).at(ans) as FormGroup).get('linkedQuestion')?.setValue(i+1);
1941
+ }
1942
+ }
1943
+ }
1944
+ }
1945
+ }
1946
+ }
1947
+ (questions.at(i) as FormGroup)?.get('qno')?.setValue(i+1);
1948
+ }
1949
+ this.ChecklistForm.updateValueAndValidity();
1950
+ }
1951
+
1952
+ // updateQuestionQnos(sectionindex: number) {
1953
+ // let questions = (this.getSectionFormArray().at(sectionindex).get('questions') as FormArray);
1954
+ // let questionArray = questions?.value;
1955
+ // for (let i = 0; i < questions.length; i++) {
1956
+ // let qno = (questions.at(i) as FormGroup)?.get('qno')?.value;
1957
+ // if(!this.deletedList.includes(qno)) {
1958
+ // for(let qn = 0; qn < questionArray.length ;qn++) {
1959
+ // let item = questionArray[qn];
1960
+ // if (!['descriptive', 'image', 'descriptiveImage', 'multipleImage', 'video','linearscale','time','date'].includes(item.answerType)) {
1961
+ // let findIndex = item.answers.map((item:any, index:any) => (item.linkedQuestion == qno ? index : -1)).filter((index:any) => index !== -1);
1962
+ // if(findIndex.length) {
1963
+ // findIndex.forEach((idx:number) => {
1964
+ // item.answers[idx].checked = true;
1965
+ // (((questions.at(qn) as FormGroup)?.get('answers') as FormArray).at(idx) as FormGroup).get('linkedQuestion')?.setValue(i+1);
1966
+ // })
1967
+ // }
1968
+ // // let findAnsIdx = item.answers.findIndex((ele:any) => ele.linkedQuestion == qno && !item.checked);
1969
+ // // if(findAnsIdx != -1) {
1970
+ // // }
1971
+ // }
1972
+ // }
1973
+ // }
1974
+ // (questions.at(i) as FormGroup)?.get('qno')?.setValue(i+1);
1975
+ // }
1976
+ // this.ChecklistForm.updateValueAndValidity();
1977
+ // }
1978
+
1979
+ getQuestionsAnswerFormGroup(sectionIndex: number, questionIndex: number,ansIndex:number) {
1980
+ return (((((this.ChecklistForm.get('sections') as FormArray).at(sectionIndex).get('questions') as FormArray).at(questionIndex) as FormGroup).get('answers') as FormArray).at(ansIndex) as FormGroup);
1981
+ }
1982
+
1983
+ setActiveQuestion(secIdx: number, questionIndex: number, activestatus: number,answerIndex:number = -1) {
1984
+ if(activestatus == 1) {
1985
+ if(answerIndex != -1) {
1986
+ this.getQuestionsAnswerFormGroup(secIdx,questionIndex,answerIndex).addControl('active',this.fb.control(true));
1987
+ }
1988
+ this.getQuestionsFormGroup(secIdx,questionIndex).addControl('active',this.fb.control(true));
1989
+ } else {
1990
+ if(answerIndex != -1) {
1991
+ this.getQuestionsAnswerFormGroup(secIdx,questionIndex,answerIndex).removeControl('active');
1992
+ }
1993
+ this.getQuestionsFormGroup(secIdx,questionIndex).removeControl('active');
1994
+ }
1995
+ }
1996
+
1997
+ allowAddAnswer(answers: any[]) {
1998
+ return answers.length < 100;
1999
+ }
2000
+
2001
+ getQuestionList(secIdx:number,qntIdx:number,ansIdx:number) {
2002
+ const questionDetails = ((this.ChecklistForm.get('sections') as FormArray).at(secIdx).get('questions') as FormArray).getRawValue() || [];
2003
+ if (!questionDetails.length) return [];
2004
+
2005
+ const currentQno = qntIdx + 1;
2006
+ const singleAnswerTypes = ['video','image','descriptiveImage','multipleImage','linearscale','time','date','image/video'];
2007
+
2008
+ // Build forward link map: source qno -> Set of target qnos.
2009
+ // Also remember the current cell's selection so it stays visible in its own dropdown.
2010
+ const linkMap = new Map<number, Set<number>>();
2011
+ let currentSelection: number | null = null;
2012
+ for (const q of questionDetails) {
2013
+ if (!q?.answers) continue;
2014
+ const answersArray = singleAnswerTypes.includes(q.answerType) ? [q.answers] : q.answers;
2015
+ answersArray.forEach((a: any, idx: number) => {
2016
+ const linked = a?.linkedQuestion ? parseInt(a.linkedQuestion) : 0;
2017
+ if (!linked) return;
2018
+ if (!linkMap.has(q.qno)) linkMap.set(q.qno, new Set());
2019
+ linkMap.get(q.qno)!.add(linked);
2020
+ if (q.qno === currentQno && idx === ansIdx) currentSelection = linked;
2021
+ });
2022
+ }
2023
+
2024
+ // Already-linked targets — union of every recorded link's target.
2025
+ const alreadyLinked = new Set<number>();
2026
+ linkMap.forEach(targets => targets.forEach(t => alreadyLinked.add(t)));
2027
+
2028
+ // Upstream — every qno whose chain transitively reaches currentQno (would cycle).
2029
+ const upstream = new Set<number>();
2030
+ const collectUpstream = (target: number) => {
2031
+ linkMap.forEach((targets, src) => {
2032
+ if (targets.has(target) && !upstream.has(src)) {
2033
+ upstream.add(src);
2034
+ collectUpstream(src);
2035
+ }
2036
+ });
2037
+ };
2038
+ collectUpstream(currentQno);
2039
+
2040
+ const questionList: number[] = [];
2041
+ for (const q of questionDetails) {
2042
+ const qno = q?.qno;
2043
+ if (!qno || qno === currentQno) continue;
2044
+ if (qno === currentSelection) {
2045
+ if (!questionList.includes(qno)) questionList.push(qno);
2046
+ continue;
2047
+ }
2048
+ if (alreadyLinked.has(qno)) continue;
2049
+ if (upstream.has(qno)) continue;
2050
+ if (!questionList.includes(qno)) questionList.push(qno);
2051
+ }
2052
+ return questionList;
2053
+ }
2054
+
2055
+ updateLinked(secIdx:number,qnIdx:number,ansIdx:number) {
2056
+ let linkValue = ((((((this.ChecklistForm.get('sections') as FormArray).at(secIdx) as FormGroup).get('questions') as FormArray).at(qnIdx) as FormGroup).get('answers') as FormArray).at(ansIdx) as FormGroup).get('showLinked')?.value;
2057
+ if(linkValue) {
2058
+ let linkedQuestion = (((((this.ChecklistForm.get('sections') as FormArray).at(secIdx).get('questions') as FormArray).at(qnIdx) as FormGroup).get('answers') as FormArray).at(ansIdx) as FormGroup).get('linkedQuestion')?.value;
2059
+ if(linkedQuestion) {
2060
+ (((this.ChecklistForm.get('sections') as FormArray).at(secIdx).get('questions') as FormArray).at(linkedQuestion - 1) as FormGroup).get('linkType')?.setValue(false);
2061
+ }
2062
+ ((((((this.ChecklistForm.get('sections') as FormArray).at(secIdx) as FormGroup).get('questions') as FormArray).at(qnIdx) as FormGroup).get('answers') as FormArray).at(ansIdx) as FormGroup).get('linkedQuestion')?.setValue(0);
2063
+ }
2064
+
2065
+ if(!linkValue) {
2066
+ ((((((this.ChecklistForm.get('sections') as FormArray).at(secIdx) as FormGroup).get('questions') as FormArray).at(qnIdx) as FormGroup).get('answers') as FormArray).at(ansIdx) as FormGroup).get('validation')?.setValue(false);
2067
+ }
2068
+ const answerGroup = ((((((this.ChecklistForm.get('sections') as FormArray).at(secIdx) as FormGroup).get('questions') as FormArray).at(qnIdx) as FormGroup).get('answers') as FormArray).at(ansIdx) as FormGroup);
2069
+ (answerGroup.get('multiReferenceImage') as FormArray)?.clear();
2070
+ answerGroup.get('referenceImage')?.setValue('');
2071
+ answerGroup.get('runAI')?.setValue(false);
2072
+ (answerGroup.get('runAIFeatures') as FormArray)?.clear();
2073
+ answerGroup.get('runAIDescription')?.setValue('');
2074
+
2075
+ ((((((this.ChecklistForm.get('sections') as FormArray).at(secIdx) as FormGroup).get('questions') as FormArray).at(qnIdx) as FormGroup).get('answers') as FormArray).at(ansIdx) as FormGroup).get('showLinked')?.setValue(!linkValue)
2076
+ }
2077
+
2078
+ updateQuestionType(secIdx:number,qnIdx:number,ansIdx:number,event:any) {
2079
+ let linkedQuestion = (((((this.ChecklistForm.get('sections') as FormArray).at(secIdx).get('questions') as FormArray).at(qnIdx) as FormGroup).get('answers') as FormArray).at(ansIdx) as FormGroup).get('linkedQuestion')?.value;
2080
+ if(linkedQuestion) {
2081
+ (((this.ChecklistForm.get('sections') as FormArray).at(secIdx).get('questions') as FormArray).at(linkedQuestion - 1) as FormGroup).get('linkType')?.setValue(false);
2082
+ }
2083
+ if(event.target.value) {
2084
+ let index = parseInt(event.target.value) - 1;
2085
+ (((this.ChecklistForm.get('sections') as FormArray).at(secIdx).get('questions') as FormArray).at(index) as FormGroup).get('linkType')?.setValue(true);
2086
+ (((((this.ChecklistForm.get('sections') as FormArray).at(secIdx).get('questions') as FormArray).at(qnIdx) as FormGroup).get('answers') as FormArray).at(ansIdx) as FormGroup).get('linkedQuestion')?.setValue(event.target.value);
2087
+ }
2088
+ else {
2089
+ (((((this.ChecklistForm.get('sections') as FormArray).at(secIdx).get('questions') as FormArray).at(qnIdx) as FormGroup).get('answers') as FormArray).at(ansIdx) as FormGroup).get('linkedQuestion')?.setValue(0);
2090
+ (((((this.ChecklistForm.get('sections') as FormArray).at(secIdx).get('questions') as FormArray).at(qnIdx) as FormGroup).get('answers') as FormArray).at(ansIdx) as FormGroup).get('showLinked')?.setValue(false);
2091
+ }
2092
+ }
2093
+
2094
+ selectOption(qno:any,ansLinked:any) {
2095
+ return qno == ansLinked ? true : false;
2096
+ }
2097
+
2098
+ getQuestionName(secIdx:number,qIdx:number) {
2099
+ return ((this.getSectionFormArray().at(secIdx).get('questions') as FormArray).at(qIdx-1) as FormGroup).get('qname')?.value;
2100
+ }
2101
+
2102
+ RunAINew(sIdx:number,qIdx: number,ansIdx:number=-1,event: any) {
2103
+ console.log("event =>", event.target.checked)
2104
+ // if(event.target.checked){
2105
+ let qName: any = this.getQuestionFormControl(sIdx,qIdx,'qname')?.value;
2106
+ let runAIFeatures: any = [];
2107
+ let runAIDescription: any = '';
2108
+ let sectionQuestion = ((((this.ChecklistForm.get('sections') as FormArray).at(sIdx) as FormGroup).get('questions') as FormArray).at(qIdx) as FormGroup);
2109
+ if(ansIdx != -1) {
2110
+ runAIFeatures= this.getAnswerFormGroup_FormControl(sIdx,qIdx,'runAIFeatures',ansIdx)?.value;
2111
+ runAIDescription= this.getAnswerFormGroup_FormControl(sIdx,qIdx,'runAIDescription',ansIdx)?.value;
2112
+ }
2113
+ else {
2114
+ runAIFeatures= ((sectionQuestion.get("answers") as FormGroup).get("runAIFeatures") as FormArray)?.value;
2115
+ runAIDescription= ((sectionQuestion.get("answers") as FormGroup).get("runAIDescription") as FormArray)?.value;
2116
+ }
2117
+ let questionImages;
2118
+ if(ansIdx != -1) {
2119
+ let answers = ((sectionQuestion.get('answers') as FormArray).at(ansIdx) as FormGroup);
2120
+ questionImages = (answers.get('multiReferenceImage') as FormArray)?.value;
2121
+ } else {
2122
+ if(['image','multipleImage','descriptiveImage','image/video'].includes(this.getQuestionFormControl(sIdx,qIdx,'answerType')?.value)) {
2123
+ questionImages = (sectionQuestion.get('answers') as FormGroup).get('multiReferenceImage')?.value;
2124
+ }
2125
+ else {
2126
+ questionImages = (sectionQuestion.get('answers') as FormGroup).get('multiQuestionReferenceImage')?.value;
2127
+ }
2128
+ }
2129
+
2130
+ if(event.target.checked){
2131
+ if (this.getAnswerFormGroup_FormControl(sIdx, qIdx, "runAI", ansIdx)?.value == false) {
2132
+ if (!qName || !this.ChecklistForm.get("checklistName")?.value) {
2133
+ let err: string = !qName
2134
+ ? "Please enter question to continue!"
2135
+ : "Please enter Checklist Name to continue!";
2136
+ this.swalToast(err, "error");
2137
+ this.runAIOff(sIdx, qIdx, false, ansIdx);
2138
+ return;
2139
+ }
2140
+ const dialogRef = this.dialog.open(TraxRunAIPopupComponent, {
2141
+ centered: true,
2142
+ size: "md",
2143
+ backdrop: "static"
2144
+ });
2145
+ dialogRef.componentInstance.data = {
2146
+ imagesrc: `<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="0 0 56 56" fill="none"><rect x="4" y="4" width="48" height="48" rx="24" fill="#D1FADF"/><path d="M23.3564 19.3525C24.1748 18.7327 25.1738 18.3985 26.2004 18.4009C26.5549 18.393 26.9057 18.4746 27.2204 18.6382C27.535 18.8018 27.8033 19.0421 28.0004 19.3369C28.1975 19.0421 28.4658 18.8018 28.7804 18.6382C29.095 18.4746 29.4459 18.393 29.8004 18.4009C30.827 18.3985 31.826 18.7327 32.6444 19.3525C33.2744 19.8421 33.7604 20.5201 33.932 21.3397C34.3256 21.3697 34.6856 21.5329 34.988 21.7789C35.4464 22.1509 35.78 22.7089 35.99 23.2993C36.3188 24.2173 36.4076 25.3873 36.0668 26.3833C36.1532 26.4241 36.2384 26.4721 36.3212 26.5273C36.6512 26.7469 36.902 27.0613 37.0868 27.4321C37.4504 28.1581 37.6004 29.1709 37.6004 30.4009C37.6004 31.7701 37.0784 32.6893 36.416 33.2569C36.0497 33.571 35.6174 33.7986 35.1512 33.9229C35.0312 34.5925 34.6952 35.3677 34.1684 36.0253C33.4844 36.8833 32.4236 37.6009 31.0004 37.6009C29.8724 37.6009 28.9748 36.9769 28.3916 36.3649C28.2522 36.2188 28.1215 36.0645 28.0004 35.9029C27.8793 36.0645 27.7486 36.2188 27.6092 36.3649C27.026 36.9769 26.1296 37.6009 25.0004 37.6009C23.5772 37.6009 22.5176 36.8833 21.8324 36.0253C21.3401 35.414 21.0029 34.6927 20.8496 33.9229C20.3834 33.7986 19.9511 33.571 19.5848 33.2569C18.9224 32.6893 18.4004 31.7689 18.4004 30.4009C18.4004 29.1709 18.5516 28.1569 18.914 27.4321C19.0857 27.0685 19.3497 26.7561 19.6796 26.5261C19.7606 26.4725 19.8457 26.4251 19.934 26.3845C19.5932 25.3861 19.682 24.2173 20.0108 23.2993C20.2208 22.7089 20.5544 22.1509 21.0128 21.7789C21.3152 21.5329 21.6752 21.3709 22.0688 21.3397C22.2416 20.5201 22.7264 19.8421 23.3564 19.3525ZM27.4004 21.4009V21.3889L27.398 21.3289C27.3803 21.0161 27.3181 20.7074 27.2132 20.4121C27.1385 20.1892 27.0113 19.9876 26.8424 19.8241C26.6651 19.6698 26.4352 19.5898 26.2004 19.6009C25.4407 19.5983 24.7009 19.8435 24.0932 20.2993C23.5364 20.7325 23.2004 21.3193 23.2004 22.0009C23.2003 22.0959 23.1777 22.1896 23.1343 22.2741C23.091 22.3587 23.0282 22.4318 22.9511 22.4873C22.874 22.5428 22.7848 22.5793 22.6909 22.5936C22.5969 22.6079 22.5009 22.5997 22.4108 22.5697C22.1852 22.4953 21.9836 22.5373 21.7688 22.7101C21.5336 22.9021 21.3044 23.2429 21.14 23.7025C20.8052 24.6409 20.84 25.7773 21.2996 26.4685C21.3652 26.567 21.4003 26.6826 21.4004 26.8009H22.3004C23.0165 26.8009 23.7032 27.0854 24.2096 27.5917C24.7159 28.0981 25.0004 28.7848 25.0004 29.5009V29.9029C25.4007 30.0445 25.7381 30.323 25.953 30.6892C26.1678 31.0555 26.2463 31.4859 26.1745 31.9044C26.1027 32.3229 25.8852 32.7025 25.5606 32.9762C25.2359 33.2499 24.825 33.4 24.4004 33.4C23.9758 33.4 23.5648 33.2499 23.2402 32.9762C22.9156 32.7025 22.6981 32.3229 22.6263 31.9044C22.5545 31.4859 22.633 31.0555 22.8478 30.6892C23.0627 30.323 23.4001 30.0445 23.8004 29.9029V29.5009C23.8004 28.6729 23.1284 28.0009 22.3004 28.0009H20.2004C20.1287 28.0008 20.0575 27.9878 19.9904 27.9625L19.9868 27.9697C19.7492 28.4437 19.6004 29.2309 19.6004 30.4009C19.6004 31.4317 19.9784 32.0125 20.366 32.3449C20.7824 32.7025 21.2444 32.8009 21.4004 32.8009C21.5595 32.8009 21.7121 32.8641 21.8247 32.9767C21.9372 33.0892 22.0004 33.2418 22.0004 33.4009C22.0004 33.8425 22.2404 34.6141 22.7684 35.2765C23.2832 35.9185 24.0236 36.4009 25.0004 36.4009C25.6724 36.4009 26.2748 36.0253 26.7404 35.5369C26.9696 35.2969 27.1484 35.0485 27.2648 34.8445C27.3178 34.7541 27.3631 34.6593 27.4004 34.5613V25.0009H26.0984C25.9569 25.4012 25.6783 25.7387 25.3121 25.9535C24.9459 26.1683 24.5154 26.2468 24.097 26.175C23.6785 26.1032 23.2988 25.8858 23.0251 25.5611C22.7514 25.2365 22.6013 24.8255 22.6013 24.4009C22.6013 23.9763 22.7514 23.5654 23.0251 23.2407C23.2988 22.9161 23.6785 22.6986 24.097 22.6268C24.5154 22.555 24.9459 22.6335 25.3121 22.8483C25.6783 23.0632 25.9569 23.4006 26.0984 23.8009H27.4004V21.4009ZM28.6004 33.3997V34.5601C28.6377 34.6581 28.683 34.7528 28.736 34.8433C28.8536 35.0473 29.0312 35.2957 29.2592 35.5357C29.726 36.0241 30.3296 36.3997 31.0004 36.3997C31.9772 36.3997 32.7176 35.9173 33.2324 35.2753C33.7604 34.6129 34.0004 33.8413 34.0004 33.3997C34.0004 33.2406 34.0636 33.088 34.1761 32.9755C34.2886 32.8629 34.4413 32.7997 34.6004 32.7997C34.7564 32.7997 35.2184 32.7013 35.6348 32.3437C36.0224 32.0113 36.4004 31.4305 36.4004 30.3997C36.4004 29.2297 36.2504 28.4437 36.014 27.9685C35.9349 27.7916 35.8108 27.6385 35.654 27.5245C35.5189 27.4381 35.3606 27.395 35.2004 27.4009C35.0919 27.4009 34.9854 27.3714 34.8923 27.3156C34.7992 27.2598 34.723 27.1798 34.6717 27.0841C34.6205 26.9884 34.5962 26.8807 34.6014 26.7723C34.6066 26.6638 34.6411 26.5589 34.7012 26.4685C35.162 25.7773 35.1956 24.6409 34.8608 23.7025C34.6964 23.2429 34.4672 22.9009 34.232 22.7101C34.0172 22.5373 33.8156 22.4941 33.59 22.5697C33.4998 22.5997 33.4038 22.6079 33.3099 22.5936C33.216 22.5793 33.1268 22.5428 33.0497 22.4873C32.9726 22.4318 32.9098 22.3587 32.8664 22.2741C32.8231 22.1896 32.8005 22.0959 32.8004 22.0009C32.8004 21.3193 32.4644 20.7325 31.9064 20.2993C31.299 19.8438 30.5596 19.5986 29.8004 19.6009C29.5656 19.5898 29.3356 19.6698 29.1584 19.8241C28.9889 19.9874 28.8613 20.1891 28.7864 20.4121C28.6721 20.7256 28.6093 21.0554 28.6004 21.3889V32.2009H29.5004C30.3284 32.2009 31.0004 31.5289 31.0004 30.7009V28.4989C30.6001 28.3574 30.2627 28.0789 30.0478 27.7126C29.833 27.3464 29.7545 26.916 29.8263 26.4975C29.8981 26.079 30.1156 25.6993 30.4402 25.4257C30.7648 25.152 31.1758 25.0019 31.6004 25.0019C32.025 25.0019 32.4359 25.152 32.7606 25.4257C33.0852 25.6993 33.3027 26.079 33.3745 26.4975C33.4463 26.916 33.3678 27.3464 33.153 27.7126C32.9381 28.0789 32.6007 28.3574 32.2004 28.4989V30.7009C32.2004 31.417 31.9159 32.1038 31.4096 32.6101C30.9032 33.1165 30.2165 33.4009 29.5004 33.4009H28.6004V33.3997ZM23.8004 24.4009C23.8004 24.5601 23.8636 24.7127 23.9761 24.8252C24.0886 24.9377 24.2413 25.0009 24.4004 25.0009C24.5595 25.0009 24.7121 24.9377 24.8247 24.8252C24.9372 24.7127 25.0004 24.5601 25.0004 24.4009C25.0004 24.2418 24.9372 24.0892 24.8247 23.9767C24.7121 23.8641 24.5595 23.8009 24.4004 23.8009C24.2413 23.8009 24.0886 23.8641 23.9761 23.9767C23.8636 24.0892 23.8004 24.2418 23.8004 24.4009ZM31.6004 27.4009C31.7595 27.4009 31.9121 27.3377 32.0247 27.2252C32.1372 27.1127 32.2004 26.9601 32.2004 26.8009C32.2004 26.6418 32.1372 26.4892 32.0247 26.3767C31.9121 26.2641 31.7595 26.2009 31.6004 26.2009C31.4413 26.2009 31.2886 26.2641 31.1761 26.3767C31.0636 26.4892 31.0004 26.6418 31.0004 26.8009C31.0004 26.9601 31.0636 27.1127 31.1761 27.2252C31.2886 27.3377 31.4413 27.4009 31.6004 27.4009ZM24.4004 31.0009C24.2413 31.0009 24.0886 31.0641 23.9761 31.1767C23.8636 31.2892 23.8004 31.4418 23.8004 31.6009C23.8004 31.7601 23.8636 31.9127 23.9761 32.0252C24.0886 32.1377 24.2413 32.2009 24.4004 32.2009C24.5595 32.2009 24.7121 32.1377 24.8247 32.0252C24.9372 31.9127 25.0004 31.7601 25.0004 31.6009C25.0004 31.4418 24.9372 31.2892 24.8247 31.1767C24.7121 31.0641 24.5595 31.0009 24.4004 31.0009Z" fill="#039855"/><rect x="4" y="4" width="48" height="48" rx="24" stroke="#ECFDF3" stroke-width="8"/></svg>`,
2147
+ title: `Run AI on image uploaded`,
2148
+ content: `Use the power of AI to compare and detect anomalies between uploaded and reference image.`,
2149
+ questionName: qName,
2150
+ images: questionImages,
2151
+ environment: this.environment.TraxAnswerCDN,
2152
+ runAIFeatures: runAIFeatures,
2153
+ runAIDescription: runAIDescription,
2154
+ clientId:this.clientId
2155
+ };
2156
+ dialogRef.result.then((res: any) => {
2157
+ if (res != "cancel") {
2158
+ let images: any;
2159
+ let features: any;
2160
+ if (ansIdx != -1) {
2161
+ images = (
2162
+ (sectionQuestion.get("answers") as FormArray).at(
2163
+ ansIdx
2164
+ ) as FormGroup
2165
+ )?.get("multiReferenceImage") as FormArray;
2166
+ features = (
2167
+ (sectionQuestion.get("answers") as FormArray).at(
2168
+ ansIdx
2169
+ ) as FormGroup
2170
+ )?.get("runAIFeatures") as FormArray;
2171
+ ((sectionQuestion.get("answers") as FormArray).at(ansIdx) as FormGroup).get("runAIDescription")?.setValue(res.runAIDescription);
2172
+ } else {
2173
+ images = (sectionQuestion.get("answers") as FormGroup).get(
2174
+ "multiReferenceImage"
2175
+ );
2176
+ features = (sectionQuestion.get("answers") as FormGroup).get("runAIFeatures") as FormArray;
2177
+ (sectionQuestion.get("answers") as FormGroup).get("runAIDescription")?.setValue(res.runAIDescription);
2178
+ }
2179
+ images.clear();
2180
+ res.images.forEach((img: any) => {
2181
+ images.push(
2182
+ this.fb.group({
2183
+ imageURL: img.imageURL,
2184
+ runAI: img.runAI,
2185
+ })
2186
+ );
2187
+ });
2188
+ features.clear();
2189
+ res.runAIFeatures.forEach((ele: any) => {
2190
+ features.push(
2191
+ this.fb.group({
2192
+ featureName: this.fb.control(ele.featureName),
2193
+ lableName: this.fb.control(ele.lableName),
2194
+ })
2195
+ );
2196
+ });
2197
+ this.insertFeatures(res.runAIFeatures);
2198
+ if (!this.hasValidationEnabled(sIdx, qIdx)) {
2199
+ ((((this.ChecklistForm.get('sections') as FormArray)
2200
+ .at(sIdx) as FormGroup)
2201
+ .get('questions') as FormArray)
2202
+ .at(qIdx) as FormGroup).get('compliance')?.enable()
2203
+ }
2204
+ const runAICtrl = this.getAnswerFormGroup_FormControl(sIdx, qIdx, 'runAI', ansIdx);
2205
+ if (runAICtrl && runAICtrl.value !== true) {
2206
+ runAICtrl.setValue(true, { emitEvent: false });
2207
+ }
2208
+ this.changedetector.detectChanges();
2209
+ this.toast.getSuccessToast('RunAI enabled successfully');
2210
+ }
2211
+ else {
2212
+ this.runAIOff(sIdx, qIdx, false, ansIdx);
2213
+ }
2214
+ }, () => {
2215
+ this.runAIOff(sIdx, qIdx, false, ansIdx);
2216
+ });
2217
+ }
2218
+ else {
2219
+ this.runAIOff(sIdx, qIdx, false, ansIdx);
2220
+ this.toast.getSuccessToast('RunAI disabled successfully');
2221
+ return;
2222
+ }
2223
+ }else{
2224
+ const dialogRef = this.dialog.open(TraxpopupComponent,{centered: true, size: 'md', backdrop: "static"});
2225
+ dialogRef.componentInstance.data = {
2226
+ imagesrc: `<span><svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="0 0 56 56" fill="none"><rect x="4" y="4" width="48" height="48" rx="24" fill="#FEE4E2"/><path d="M28 24V28M28 32H28.01M38 28C38 33.5228 33.5228 38 28 38C22.4772 38 18 33.5228 18 28C18 22.4772 22.4772 18 28 18C33.5228 18 38 22.4772 38 28Z" stroke="#D92D20" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><rect x="4" y="4" width="48" height="48" rx="24" stroke="#FEF3F2" stroke-width="8"/></svg></span>`,
2227
+ title: `Run AI Remove`,
2228
+ content: `Are you sure you want to Remove Run AI?`,
2229
+ buttontype: 'remove'
2230
+ }
2231
+ const restoreRunAI = () => {
2232
+ const control = this.getAnswerFormGroup_FormControl(sIdx, qIdx, "runAI", ansIdx);
2233
+ if (control) {
2234
+ control.setValue(true, { emitEvent: true }); // reset to ON
2235
+ }
2236
+ };
2237
+ dialogRef.result.then((res) => {
2238
+ // console.log("res =>", res)
2239
+ if (res == 'delete') {
2240
+ if(['image','image/video'].includes(this.getQuestionFormControl(sIdx,qIdx,'answerType')?.value)){
2241
+ let question = ((((this.ChecklistForm.get('sections') as FormArray)
2242
+ .at(sIdx) as FormGroup)
2243
+ .get('questions') as FormArray)
2244
+ .at(qIdx) as FormGroup)
2245
+ question.get('compliance')?.disable({emitEvent:false})
2246
+ question.get('compliance')?.patchValue(false);}
2247
+ this.runAIOff(sIdx, qIdx, false, ansIdx);
2248
+ this.toast.getSuccessToast('RunAI disabled successfully');
2249
+ }else{
2250
+ restoreRunAI();
2251
+ }
2252
+ }, () => {
2253
+ // Dismissed (ESC / programmatic dismiss) — restore the toggle so it doesn't drift to false with stale features.
2254
+ restoreRunAI();
2255
+ });
2256
+ return;
2257
+ }
2258
+ }
2259
+
2260
+ insertFeatures(data:any) {
2261
+ let params = {
2262
+ clientId: this.clientId,
2263
+ runAIFeatures: data,
2264
+ };
2265
+
2266
+ this.sopService.updateRunAIFeatures(params).pipe(takeUntil(this.detach)).subscribe((res:any) => {
2267
+ if(res && res.code == 200){}
2268
+ })
2269
+ }
2270
+
2271
+
2272
+ onPopup(image:string){
2273
+ let imageRef = this.dialog.open(TraxpopupComponent, { centered: true, size: "md" });
2274
+ imageRef.componentInstance.data = {type:'image',image:this.environment.TraxAnswerCDN+image};
2275
+ imageRef.result.then(() => {});
2276
+ }
2277
+
2278
+ dateRange(event:any,type:string,secIdx:number,qnIdx:number) {
2279
+ if(event.startDate ) {
2280
+ if(type == 'start') {
2281
+ (((((this.ChecklistForm.get('sections') as FormArray)
2282
+ .at(secIdx) as FormGroup)
2283
+ .get('questions') as FormArray)
2284
+ .at(qnIdx) as FormGroup).get('answers') as FormGroup).get('startDate')?.setValue(event.startDate.format('DD-MM-YYYY'));
2285
+ }
2286
+ else {
2287
+ (((((this.ChecklistForm.get('sections') as FormArray)
2288
+ .at(secIdx) as FormGroup)
2289
+ .get('questions') as FormArray)
2290
+ .at(qnIdx) as FormGroup).get('answers') as FormGroup).get('endDate')?.setValue(event.startDate.format('DD-MM-YYYY'));
2291
+ }
2292
+ }
2293
+ }
2294
+
2295
+ /** Returns true when Configure Compliance Score should be disabled.
2296
+ * Disabled when validate response is enabled, EXCEPT when:
2297
+ * - validationType is "Capture Image" and Run AI is enabled, OR
2298
+ * - validationType is "Capture Multiple Image with description" and Run AI is enabled and at least one reference image is added. */
2299
+ hasValidationEnabled(sectionIndex: number, questionIndex: number): boolean {
2300
+ const answers = this.getFormArrayQuestionsAnswer(sectionIndex, questionIndex, 'answers')?.value;
2301
+ if (!Array.isArray(answers)) return false;
2302
+ return false;
2303
+ // return answers.some((a: any) => {
2304
+ // if (!a.validation) return false;
2305
+ // if (a.validationType === 'Capture Image' && a.runAI) return false;
2306
+ // if (
2307
+ // a.validationType === 'Capture Multiple Image with description' &&
2308
+ // a.runAI &&
2309
+ // Array.isArray(a.multiReferenceImage) &&
2310
+ // a.multiReferenceImage.length > 0
2311
+ // ) return false;
2312
+ // return true;
2313
+ // });
2314
+ }
2315
+
2316
+ getComplianceToast(secIdx:number,qnIdx:number,event:any) {
2317
+ if(event.target.checked) {
2318
+ let question = ((((this.ChecklistForm.get('sections') as FormArray)
2319
+ .at(secIdx) as FormGroup)
2320
+ .get('questions') as FormArray)
2321
+ .at(qnIdx) as FormGroup).get('answerType')?.value;
2322
+
2323
+ let answers = ((((this.ChecklistForm.get('sections') as FormArray)
2324
+ .at(secIdx) as FormGroup)
2325
+ .get('questions') as FormArray)
2326
+ .at(qnIdx) as FormGroup).get('answers')?.value;
2327
+
2328
+ if(['multiplechoicemultiple','multiplechoicesingle','yes/no'].includes(question) && answers.some((ele:any) => ele.runAI)) {
2329
+ this.toast.getWarningToast('Compliance score has been enabled for Run AI');
2330
+ }
2331
+ }
2332
+ }
2333
+
2334
+ bulkUploadQuestion() {
2335
+ const dialogRef = this.dialog.open(ChecklistPopupComponent, {
2336
+ centered: true,
2337
+ size: "lg",
2338
+ });
2339
+ dialogRef.componentInstance.checklistData = {
2340
+ checkListName: this.ChecklistForm.value.checklistName,
2341
+ checkListDescription: this.ChecklistForm.value.checklistDescription,
2342
+ clientId: this.clientId,
2343
+ checklistId: this.editvalue,
2344
+ };
2345
+ dialogRef.result.then((res) => {
2346
+ if (res == "reload") {
2347
+ this.checklistLoading = true;
2348
+ this.sopService
2349
+ .getconfig({ checkListId: this.editvalue, clientId: this.clientId })
2350
+ .pipe(takeUntil(this.detach))
2351
+ .subscribe(
2352
+ (res: any) => {
2353
+ if (res) {
2354
+ if (res.code == 200) {
2355
+ this.getobject = res.data.checkListDetails;
2356
+ this.formChecklistQuestions();
2357
+ } else {
2358
+ this.checklistLoading = false;
2359
+ }
2360
+ } else {
2361
+ this.checklistLoading = false;
2362
+ }
2363
+ },
2364
+ (error) => {
2365
+ this.checklistLoading = false;
2366
+ },
2367
+ );
2368
+ }
2369
+ });
2370
+ }
2371
+
2372
+ updateNumber(event: any, secIdx: number, qnIdx: number) {
2373
+ const linearType = event?.target?.value as 'percentage' | 'number' | 'degree';
2374
+ const answers = ((((this.ChecklistForm.get('sections') as FormArray)
2375
+ .at(secIdx) as FormGroup)
2376
+ .get('questions') as FormArray)
2377
+ .at(qnIdx) as FormGroup).get('answers') as FormGroup;
2378
+
2379
+ const defaults: Record<string, { rangeStart: number; rangeEnd: number }> = {
2380
+ percentage: { rangeStart: 0, rangeEnd: 100 },
2381
+ number: { rangeStart: 0, rangeEnd: 100 },
2382
+ degree: { rangeStart: 0, rangeEnd: 100 }, // default 0; user can enter down to -273.15
2383
+ };
2384
+ const { rangeStart, rangeEnd } = defaults[linearType] ?? defaults.number;
2385
+
2386
+ answers.get('rangeStart')?.setValue(rangeStart);
2387
+ answers.get('rangeEnd')?.setValue(rangeEnd);
2388
+
2389
+ const minValue = answers.get('minValue')?.value;
2390
+ const maxValue = answers.get('maxValue')?.value;
2391
+ if (minValue != null && minValue !== '' && Number(minValue) < rangeStart) {
2392
+ answers.get('minValue')?.setValue(rangeStart);
2393
+ } else if (minValue != null && minValue !== '' && Number(minValue) > rangeEnd) {
2394
+ answers.get('minValue')?.setValue(rangeEnd);
2395
+ }
2396
+ if (maxValue != null && maxValue !== '' && Number(maxValue) < rangeStart) {
2397
+ answers.get('maxValue')?.setValue(rangeStart);
2398
+ } else if (maxValue != null && maxValue !== '' && Number(maxValue) > rangeEnd) {
2399
+ answers.get('maxValue')?.setValue(rangeEnd);
2400
+ }
2401
+ }
2402
+
2403
+ onRangeValueInput(event: Event, secIdx: number, qnIdx: number, controlName: 'minValue' | 'maxValue') {
2404
+ const linearType = this.getAnswerFormGroup_FormControl(secIdx, qnIdx, 'linearType')?.value;
2405
+ if (linearType !== 'degree') return;
2406
+
2407
+ const input = event.target as HTMLInputElement;
2408
+ const filtered = input.value.replace(/[^\d.-]/g, '').replace(/(?!^)-/g, '').replace(/(\..*)\./g, '$1');
2409
+ if (filtered !== input.value) {
2410
+ input.value = filtered;
2411
+ const answers = ((((this.ChecklistForm.get('sections') as FormArray)
2412
+ .at(secIdx) as FormGroup)
2413
+ .get('questions') as FormArray)
2414
+ .at(qnIdx) as FormGroup).get('answers') as FormGroup;
2415
+ const val = filtered === '' || filtered === '-' ? filtered : Number(filtered);
2416
+ answers.get(controlName)?.setValue(val, { emitEvent: false });
2417
+ }
2418
+ }
2419
+
2420
+ clampRangeInput(secIdx: number, qnIdx: number, controlName: 'minValue' | 'maxValue') {
2421
+ const answers = ((((this.ChecklistForm.get('sections') as FormArray)
2422
+ .at(secIdx) as FormGroup)
2423
+ .get('questions') as FormArray)
2424
+ .at(qnIdx) as FormGroup).get('answers') as FormGroup;
2425
+
2426
+ const rangeStart = answers.get('rangeStart')?.value;
2427
+ const rangeEnd = answers.get('rangeEnd')?.value;
2428
+
2429
+ if (rangeStart == null || rangeEnd == null) return;
2430
+
2431
+ const control = answers.get(controlName);
2432
+ const value = control?.value;
2433
+
2434
+ if (value === '' || value === '-' || (typeof value === 'number' && Number.isNaN(value))) {
2435
+ control?.setValue(rangeStart);
2436
+ } else if (value != null) {
2437
+ const numValue = Number(value);
2438
+ if (!Number.isNaN(numValue)) {
2439
+ if (numValue < rangeStart) {
2440
+ control?.setValue(rangeStart);
2441
+ } else if (numValue > rangeEnd) {
2442
+ control?.setValue(rangeEnd);
2443
+ }
2444
+ } else {
2445
+ control?.setValue(rangeStart);
2446
+ }
2447
+ }
2448
+ }
2449
+
2450
+ updateLimit(event:any,secIdx:number,qnIdx:number) {
2451
+ (((((this.ChecklistForm.get('sections') as FormArray)
2452
+ .at(secIdx) as FormGroup)
2453
+ .get('questions') as FormArray)
2454
+ .at(qnIdx) as FormGroup).get('answers') as FormGroup).get('imageLimit')?.setValue(0);
2455
+ (((((this.ChecklistForm.get('sections') as FormArray)
2456
+ .at(secIdx) as FormGroup)
2457
+ .get('questions') as FormArray)
2458
+ .at(qnIdx) as FormGroup).get('answers') as FormGroup).get('videoLimit')?.setValue(0);
2459
+ }
2460
+ }