adddrill.html.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. /**
  3. * The adddrill view file of pivot module of ZenTaoPMS.
  4. * @copyright Copyright 2009-2024 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  5. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  6. * @author Chenxuan Song <songchenxuan@easycorp.ltd>
  7. * @package pivot
  8. * @link https://www.zentao.net
  9. */
  10. namespace zin;
  11. $fnGenTabText = function($tabText)
  12. {
  13. return div
  14. (
  15. setClass('border-b border-gray-100'),
  16. span($tabText, setClass('bg-gray-100 text-base font-medium leading-tight bg-text-padding'))
  17. );
  18. };
  19. $fnGenFieldAndObject = function($drill, $fields) use ($lang)
  20. {
  21. return div(setClass('flex items-center gap-x-4'), div
  22. (
  23. $lang->pivot->drill->selectField
  24. ), div
  25. (
  26. setClass('field-select drill-select-picker'),
  27. picker
  28. (
  29. setID('picker_field'),
  30. set::name('field'),
  31. set::items($fields),
  32. set::value($drill['field']),
  33. on::change()->do('changeField(event)')
  34. ),
  35. div
  36. (
  37. setClass('form-tip hidden text-danger'),
  38. $lang->pivot->stepDrill->fieldEmpty
  39. )
  40. ), div
  41. (
  42. $lang->pivot->drill->selectObject
  43. ), div
  44. (
  45. setClass('object-select drill-select-picker'),
  46. picker
  47. (
  48. setID('picker_object'),
  49. set::name('object'),
  50. set::items($this->bi->getTableList($hasDatavew = false, $withPrefix = false)),
  51. set::value($drill['object']),
  52. on::change()->do('changeObject(event)')
  53. ),
  54. div
  55. (
  56. setClass('form-tip hidden text-danger'),
  57. $lang->pivot->stepDrill->objectEmpty
  58. )
  59. ));
  60. };
  61. $fnGenConditionLine = function($index, $conditionCount, $drillFields, $queryFields, $condition) use ($lang)
  62. {
  63. $drillFieldValue = null;
  64. if($condition['drillAlias'])
  65. {
  66. $parts = array($condition['drillAlias'], $condition['drillObject'], $condition['drillField']);
  67. $parts = array_filter($parts);
  68. $drillFieldValue = implode('.', $parts);
  69. }
  70. return div
  71. (
  72. setClass("flex condition-line items-center gap-x-2"),
  73. set('data-index', $index),
  74. div
  75. (
  76. $lang->pivot->drill->inDrillField
  77. ),
  78. div
  79. (
  80. setClass("drillField-select-{$index} drill-condition-picker"),
  81. inputGroup
  82. (
  83. setID('drillFieldGroup'),
  84. picker
  85. (
  86. setID("picker_drillField$index"),
  87. set::name('drillField[]'),
  88. set::items($drillFields),
  89. set::value($drillFieldValue),
  90. on::change()->do('changeDrillField(event)')
  91. ),
  92. btn
  93. (
  94. setClass('refresh-conditions'),
  95. set::icon('refresh'),
  96. on::click()->do('refreshConditions(event)')
  97. )
  98. ),
  99. div
  100. (
  101. setClass('form-tip hidden text-danger'),
  102. $lang->pivot->stepDrill->drillEmpty
  103. )
  104. ),
  105. div
  106. (
  107. $lang->pivot->drill->equal
  108. ),
  109. div
  110. (
  111. $lang->pivot->drill->inQueryField
  112. ),
  113. div
  114. (
  115. setClass("queryField-select-{$index} drill-condition-picker"),
  116. picker
  117. (
  118. setID("picker_queryField$index"),
  119. set::name('queryField[]'),
  120. set::items($queryFields),
  121. set::value($condition['queryField']),
  122. on::change()->do('changeQueryField(event)')
  123. ),
  124. div
  125. (
  126. setClass('form-tip hidden text-danger'),
  127. $lang->pivot->stepDrill->queryEmpty
  128. )
  129. ),
  130. btnGroup
  131. (
  132. btn
  133. (
  134. setClass('btn btn-link text-gray condition-add'),
  135. set::icon('plus'),
  136. on::click()->do('addCondition(event)')
  137. ),
  138. $conditionCount > 1 ? btn
  139. (
  140. setClass('btn btn-link text-gray condition-delete'),
  141. set::icon('close'),
  142. on::click()->do('deleteCondition(event)')
  143. ) : null
  144. )
  145. );
  146. };
  147. $fnGenConditionLines = function($pivotState, $drill) use ($lang, $fnGenConditionLine)
  148. {
  149. $drillFields = $drill['object'] ? $this->pivot->getDrillFieldList($drill) : array();
  150. $queryFields = $pivotState->getFieldOptions();
  151. $conditions = array();
  152. $index = 1;
  153. if(!empty($drill['condition']))
  154. {
  155. $conditionCount = count($drill['condition']);
  156. foreach($drill['condition'] as $condition)
  157. {
  158. $conditions[] = $fnGenConditionLine($index, $conditionCount, $drillFields, $queryFields, $condition);
  159. $index ++;
  160. }
  161. }
  162. return div
  163. (
  164. setClass('condition-lines flex col gap-y-2'),
  165. $conditions
  166. );
  167. };
  168. $errorMessage = isset($errorMessage) ? $errorMessage : null;
  169. $previewCols = isset($previewCols) ? $previewCols : array();
  170. $previewData = isset($previewData) ? $previewData : array();
  171. $fnGenerateQueryCondition = function($pivotState, $isDefault, $modalIndex) use ($lang, $fnGenTabText, $fnGenFieldAndObject, $fnGenConditionLines, $previewCols, $previewData, $errorMessage, $users)
  172. {
  173. $drill = $isDefault ? $pivotState->defaultDrill : $pivotState->drills[$modalIndex];
  174. $fields = $this->pivot->getFieldList($pivotState, $isDefault ? null : $modalIndex);
  175. return div
  176. (
  177. setID("queryConditionContent$modalIndex"),
  178. setClass('flex col gap-y-4 queryConditionContent'),
  179. $fnGenFieldAndObject($drill, $fields),
  180. div
  181. (
  182. div
  183. (
  184. setClass('drill-condition-tab border-b border-gray-100 flex items-center gap-x-2'),
  185. $fnGenTabText($lang->pivot->drill->setCondition),
  186. sqlBuilderHelpIcon(),
  187. span(setClass('text-gray-500'), $lang->pivot->queryConditionTip)
  188. ),
  189. div
  190. (
  191. setClass('flex'),
  192. div
  193. (
  194. setClass('flex col gap-y-2 border drill-condition py-4'),
  195. div
  196. (
  197. setClass('refer-sql px-4'),
  198. !empty($drill['object']) ? $this->pivot->autoGenReferSQL($drill['object']) : null
  199. ),
  200. div
  201. (
  202. formGroup
  203. (
  204. setClass('where-sql px-4'),
  205. setID("textarea_whereSql"),
  206. set::name('whereSql'),
  207. !empty($drill['whereSql']) ? set::value($drill['whereSql']) : null,
  208. set::control(array('type' => 'textarea', 'rows' => 3)),
  209. set::placeholder($lang->pivot->drillSQLTip),
  210. on::change()->do('changeWhereSQL(event)')
  211. )
  212. ),
  213. div
  214. (
  215. formGroup
  216. (
  217. setClass('error-message'),
  218. set::tipClass('text-danger'),
  219. set::tip($errorMessage)
  220. )
  221. ),
  222. div
  223. (
  224. setClass('flex items-center'),
  225. div(setClass('flex items-center basis-32'), div
  226. (
  227. setClass('text-base font-medium align-self py-1 px-3'),
  228. $lang->pivot->drill->drillCondition
  229. ), sqlBuilderHelpIcon(set::text($lang->pivot->drillConditionTip))),
  230. $fnGenConditionLines($pivotState, $drill)
  231. )
  232. ),
  233. div
  234. (
  235. setClass('border p-3 break-all origin-sql'),
  236. $pivotState->sql
  237. )
  238. )
  239. ),
  240. div
  241. (
  242. div
  243. (
  244. setClass('drill-condition-tab border-b border-gray-100 flex items-center gap-x-2'),
  245. $fnGenTabText($lang->pivot->drill->drillResult),
  246. sqlBuilderHelpIcon(),
  247. span(setClass('text-gray-500'), $lang->pivot->previewResultTip)
  248. ),
  249. div
  250. (
  251. dtable
  252. (
  253. set::height(160),
  254. set::id('drillResult'),
  255. set::cols((array)$previewCols),
  256. set::data((array)$previewData),
  257. set::userMap($users),
  258. set::onRenderCell(jsRaw('window.renderDrillResult')),
  259. set::emptyTip($lang->pivot->drillResultEmptyTip)
  260. )
  261. )
  262. )
  263. );
  264. };
  265. $fnGenerateAddDrillModal = function($pivotState, $modalID) use ($lang, $fnGenerateQueryCondition)
  266. {
  267. $isDefault = $modalID == 'drillModalDefault';
  268. $modalIndex = $isDefault ? substr($modalID, 10) : (int)substr($modalID, 10);
  269. return modal
  270. (
  271. setID($modalID),
  272. setClass('drill-modal'),
  273. setData('backdrop', 'static'),
  274. set::size('lg'),
  275. set::title($lang->pivot->drill->common),
  276. set::titleClass('flex-none'),
  277. to::header
  278. (
  279. sqlBuilderHelpIcon(set::text($lang->pivot->drillModalTip))
  280. ),
  281. $fnGenerateQueryCondition($pivotState, $isDefault, $modalIndex),
  282. set::footerClass('form-actions gap-4 mt-4'),
  283. to::footer
  284. (
  285. btn
  286. (
  287. set::type('ghost'),
  288. setID('previewDrill'),
  289. setClass('px-6 drill-preview squre'),
  290. $lang->pivot->drill->preview,
  291. on::click()->do('previewDrillResult(event)')
  292. ),
  293. btn
  294. (
  295. set::type('ghost'),
  296. setClass('px-6 drill-save squre'),
  297. $lang->pivot->drill->save,
  298. on::click()->do('saveDrill(event)')
  299. )
  300. )
  301. );
  302. };