| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- namespace zin;
- class pivotTable extends wg
- {
- /**
- * @var mixed[]
- */
- protected static $defineProps = array(
- 'title?: string',
- 'class?: string',
- 'width?: string',
- 'cols?: array',
- 'data?: array',
- 'cellSpan?: array',
- 'filters?: array',
- 'onRenderCell?: function',
- 'onCellClick?: function'
- );
- /**
- * @var mixed[]
- */
- protected static $defineBlocks = array(
- 'heading' => array()
- );
- public static function getPageCSS()
- {
- return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
- }
- public static function getPageJS()
- {
- return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
- }
- protected function buildFilters()
- {
- global $lang;
- list($filters) = $this->prop(array('filters'));
- if(empty($filters)) return div(setID('conditions'), setClass('mb-4'));
- return div
- (
- setID('conditions'),
- setClass('flex justify-start bg-canvas mt-4 mb-2 w-full' . (count($filters) == 1 ? ' flex-wrap' : ' items-center')),
- count($filters) == 1 ? $filters : div
- (
- setClass('flex flex-wrap w-full'),
- $filters
- ),
- button(setClass('btn primary mb-2 load-custom-pivot'), $lang->pivot->query)
- );
- }
- protected function buildDTable()
- {
- global $lang;
- list($cols, $data, $cellSpan, $filters, $onRenderCell, $onCellClick) = $this->prop(array('cols', 'data', 'cellSpan', 'filters', 'onRenderCell', 'onCellClick'));
- $filterCount = count($filters);
- $filterAllEmpty = $filterCount ? empty(array_filter(array_column($filters, 'default'))) : false;
- $emptyTip = $filterAllEmpty ? $lang->pivot->filterEmptyVal : $lang->pivot->noPivotTip;
- if(empty($onRenderCell)) $onRenderCell = jsRaw(<<<JS
- function(result, {row, col})
- {
- if(result)
- {
- let values = result.shift();
- let isDrill = row.data.isDrill[col.name];
- let isTotal = row.data.isTotal;
- if(col.setting.colspan && typeof(values.type) != 'undefined' && values.type == 'a')
- {
- values = values.props['children'];
- result.push({className: 'gap-0 p-0.5'});
- values.forEach((value, index) =>
- result.push({
- html: value || !Number.isNaN(value) ? (isDrill && index == 0 ? "<a href='#'>" + `\${value}` + '</a>' : `\${value}`) : ' ',
- className: 'flex justify-center items-center h-full w-1/2' + (index == 0 ? ' border-r': ''),
- style: 'border-color: var(--dtable-border-color)' + (isTotal ? '; background-color: var(--color-surface-light);' : '')
- })
- );
- }
- else
- {
- if(!isDrill && values?.type == 'a') values = values.props.children;
- if(isTotal)
- {
- result.push({className: 'gap-0 p-0.5'});
- values = {
- html: values,
- className: 'flex justify-center items-center h-full w-full',
- style: 'border-color: var(--dtable-border-color)' + (isTotal ? '; background-color: var(--color-surface-light);' : '')
- };
- }
- result.push(values);
- }
- }
- return result;
- }
- JS
- );
- return dtable
- (
- setID('designTable'),
- set::bordered(true),
- set::height(jsRaw("() => getHeight(800, $filterCount)")),
- set::cols($cols),
- set::data($data),
- set::emptyTip($emptyTip),
- set::rowHover(false),
- set::colHover(false),
- set::onRenderCell($onRenderCell),
- set::onCellClick($onCellClick),
- set::rowKey('ROW_ID'),
- set::plugins(array('header-group', 'cellspan')),
- set::getCellSpan(jsRaw(<<<JS
- function(cell)
- {
- const options = this.options.cellSpanOptions[cell.col.name];
- if(options)
- {
- const rowSpan = cell.row.data[options.rowspan ?? 'rowspan'] ?? 1;
- const colSpan = cell.row.data[options.colspan ?? 'colspan'] ?? 1;
- return {rowSpan, colSpan};
- }
- console.log(options);
- }
- JS
- )),
- set::cellSpanOptions($cellSpan)
- );
- }
- protected function build()
- {
- global $lang;
- list($title, $class, $width) = $this->prop(array('title', 'class', 'width'));
- return div
- (
- setClass('dtable-content bg-canvas', $class),
- setStyle('width', $width),
- panel
- (
- set::title($title),
- set::shadow(false),
- set::bodyClass('pt-0 panel-body-height'),
- $this->buildFilters(),
- $this->buildDTable(),
- set::headingClass('h-12 border-b'),
- to::heading($this->block('heading'))
- )
- );
- }
- }
|