show.html.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. /**
  3. * The show view file of pivot module of ZenTaoPMS.
  4. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(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 Gang Liu <liugang@easycorp.ltd>
  7. * @package pivot
  8. * @link https://www.zentao.net
  9. */
  10. namespace zin;
  11. jsVar('currentGroup', $currentGroup);
  12. jsVar('pivotID', $pivot->id);
  13. jsVar('drillModalTitle', $this->lang->pivot->stepDrill->drillView);
  14. $fnGenerateFilters = function() use($pivot, $showOrigin, $lang)
  15. {
  16. $hasFilter = !empty($pivot->filters);
  17. if(!$hasFilter) return div(setID('conditions'), setClass('mb-4'));
  18. $filters = array();
  19. foreach($pivot->filters as $filter)
  20. {
  21. $type = $filter['type'];
  22. $name = $filter['name'];
  23. $field = $filter['field'];
  24. $value = zget($filter, 'default', '');
  25. $from = zget($filter, 'from');
  26. $items = $this->getFilterOptionUrl($filter, $pivot->sql, (array)$pivot->fieldSettings);
  27. if($showOrigin)
  28. {
  29. $filters[] = filter(set(array('title' => $name, 'type' => 'input', 'name' => $field, 'value' => $value)));
  30. }
  31. elseif($from == 'query')
  32. {
  33. $filters[] = filter(set(array('title' => $name, 'type' => $type, 'name' => $field, 'value' => $value, 'items' => $items, 'multiple' => $type == 'multipleselect' ? true : false)));
  34. }
  35. else
  36. {
  37. $filters[] = resultFilter(set(array('title' => $name, 'type' => $type, 'name' => $field, 'value' => $value, 'items' => $items)));
  38. }
  39. }
  40. $isSingleFilter = count($filters) == 1;
  41. return div
  42. (
  43. setID('conditions'),
  44. setClass('flex justify-start bg-canvas mt-4 mb-2 w-full', array('flex-wrap' => $isSingleFilter, 'items-center' => !$isSingleFilter), $showOrigin ? 'hidden' : null),
  45. $isSingleFilter ? $filters : div
  46. (
  47. setClass('flex flex-wrap w-full'),
  48. $filters
  49. ),
  50. button(setClass('btn primary mb-2'), on::click('loadCustomPivot'), $lang->pivot->query)
  51. );
  52. };
  53. $generateData = function() use ($lang, $groupID, $pivotName, $pivot, $data, $configs, $showOrigin, $fnGenerateFilters, $hasVersionMark)
  54. {
  55. $clickable = $this->config->edition != 'open';
  56. $emptyTip = $this->pivot->isFiltersAllEmpty($pivot->filters) ? $lang->pivot->filterEmptyVal : $lang->error->noData;
  57. list($cols, $rows, $cellSpan) = $this->loadModel('bi')->convertDataForDtable($data, $configs, $pivot->version, 'published');
  58. return array
  59. (
  60. panel
  61. (
  62. setID('pivotPanel'),
  63. $this->app->rawMethod != 'versions' ? set::title($pivotName) : null,
  64. set::shadow(false),
  65. set::headingClass('h-12'),
  66. set::bodyClass('pt-0'),
  67. to::titleSuffix
  68. (
  69. setClass(array('hidden' => $this->app->rawMethod == 'versions')),
  70. icon
  71. (
  72. setClass('cursor-pointer', array('hidden' => !$pivot->desc)),
  73. setData(array('toggle' => 'tooltip', 'title' => $pivot->desc, 'placement' => 'right', 'className' => 'text-gray border border-light', 'type' => 'white')),
  74. 'help'
  75. )
  76. /**
  77. span
  78. (
  79. set::style(array('font-weight' => 'normal')),
  80. setClass(array('hidden' => !hasPriv('pivot', 'design') || !$pivot->versionChange || $hasVersionMark)),
  81. $lang->pivot->tipNewVersion . $lang->comma,
  82. h::a
  83. (
  84. $lang->pivot->checkNewVersion,
  85. set('data-toggle', 'modal'),
  86. set('data-size', 'lg'),
  87. set::href($this->createLink('pivot', 'versions', "groupID={$groupID}&pivotID={$pivot->id}"))
  88. )
  89. )
  90. */
  91. ),
  92. toolbar
  93. (
  94. setClass(array('hidden' => $this->app->rawMethod == 'versions')),
  95. item(setID('origin-query'), setClass('ghost'), set::icon('exchange'), set::text($lang->pivot->showOrigin), on::click("toggleShowMode('origin')")),
  96. item(setID('pivot-query'), setClass('ghost hidden'), set::icon('exchange'), set::text($lang->pivot->showPivot), on::click("toggleShowMode('group')")),
  97. item(set(array
  98. (
  99. 'text' => $lang->pivot->designAB,
  100. 'icon' => 'design',
  101. 'class' => array('ghost', 'hidden' => !hasPriv('pivot', 'design') || !$clickable),
  102. 'url' => inlink('design', "id=$pivot->id"),
  103. 'data-confirm' => $this->pivot->checkIFChartInUse($pivot->id, 'pivot') ? array('message' => $lang->pivot->confirm->design, 'icon' => 'icon-exclamation-sign', 'iconClass' => 'warning-pale rounded-full icon-2x') : null
  104. ))),
  105. item(set(array
  106. (
  107. 'text' => $lang->edit,
  108. 'icon' => 'edit',
  109. 'class' => array('ghost', 'hidden' => !hasPriv('pivot', 'edit') || !$clickable),
  110. 'url' => inlink('edit', "id=$pivot->id", '', true),
  111. 'data-toggle' => 'modal',
  112. 'data-size' => 'sm'
  113. ))),
  114. item(set(array
  115. (
  116. 'text' => $lang->delete,
  117. 'icon' => 'trash',
  118. 'class' => array('ghost ajax-submit', 'hidden' => !hasPriv('pivot', 'delete') || !$clickable),
  119. 'url' => inlink('delete', "id=$pivot->id"),
  120. 'data-confirm' => array('message' => $lang->pivot->deleteTip, 'icon' => 'icon-exclamation-sign', 'iconClass' => 'warning-pale rounded-full icon-2x')
  121. )))
  122. ),
  123. div(setClass('divider')),
  124. $fnGenerateFilters(),
  125. dtable
  126. (
  127. set::bordered(true),
  128. set::height(jsRaw('window.getHeight')),
  129. set::cols($cols),
  130. set::data($rows),
  131. set::emptyTip($emptyTip),
  132. set::rowHover(false),
  133. set::colHover(false),
  134. set::onCellClick(jsRaw('clickCell')),
  135. set::rowKey('ROW_ID'),
  136. set::plugins(array('header-group', 'cellspan')),
  137. set::cellSpanOptions($cellSpan),
  138. set::getCellSpan(jsRaw(<<<JS
  139. function(cell)
  140. {
  141. const options = this.options.cellSpanOptions[cell.col.name];
  142. if(options)
  143. {
  144. const rowSpan = cell.row.data[options.rowspan ?? 'rowspan'] ?? 1;
  145. const colSpan = cell.row.data[options.colspan ?? 'colspan'] ?? 1;
  146. return {rowSpan, colSpan};
  147. }
  148. }
  149. JS
  150. )),
  151. set::onRenderCell(jsRaw(<<<JS
  152. function(result, {row, col})
  153. {
  154. if(result)
  155. {
  156. let values = result.shift();
  157. let isDrill = row.data.isDrill[col.name];
  158. let isTotal = row.data.isTotal;
  159. if(col.setting.colspan && typeof(values.type) != 'undefined' && values.type == 'a')
  160. {
  161. values = values.props['children'];
  162. result.push({className: 'gap-0 p-0.5'});
  163. values.forEach((value, index) =>
  164. result.push({
  165. html: value + '' || !Number.isNaN(value) ? (isDrill && index == 0 ? "<a href='#'>" + `\${value}` + '</a>' : `\${value}`) : '&nbsp;',
  166. className: 'flex justify-center items-center h-full w-1/2' + (index == 0 ? ' border-r': ''),
  167. style: 'border-color: var(--dtable-border-color)' + (isTotal ? '; background-color: var(--color-surface-light);' : '')
  168. })
  169. );
  170. }
  171. else
  172. {
  173. if(!isDrill && values?.type == 'a') values = values.props.children;
  174. if(isTotal)
  175. {
  176. result.push({className: 'gap-0 p-0.5'});
  177. values = {
  178. html: values + '',
  179. className: 'flex justify-center items-center h-full w-full',
  180. style: 'border-color: var(--dtable-border-color)' + (isTotal ? '; background-color: var(--color-surface-light);' : '')
  181. };
  182. }
  183. result.push(values);
  184. }
  185. }
  186. return result;
  187. }
  188. JS
  189. ))
  190. ),
  191. div(setID('exportData'), setClass('hidden'), rawContent(), html($this->pivot->buildPivotTable($data, $configs)))
  192. )
  193. );
  194. };