* Code for task#106653, #106654.
This commit is contained in:
+12
-81
@@ -59,106 +59,39 @@ class chart extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取筛选器表单。
|
||||
* Ajax get filter form html.
|
||||
*
|
||||
* @param int $chartID
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function ajaxGetFilterForm($chartID)
|
||||
public function ajaxGetFilterForm()
|
||||
{
|
||||
$fieldList = $this->post->fieldList;
|
||||
$filters = $this->post->filters;
|
||||
$fieldSettings = $this->post->fieldSettings;
|
||||
$langs = $this->post->langs;
|
||||
$sql = $this->post->sql;
|
||||
$clientLang = $this->app->getClientLang();
|
||||
$filters = $this->post->filters;
|
||||
|
||||
$fieldPairs = array();
|
||||
foreach($fieldList as $field => $fieldName)
|
||||
{
|
||||
$fieldObject = $fieldSettings[$field]['object'];
|
||||
$relatedField = $fieldSettings[$field]['field'];
|
||||
|
||||
$this->app->loadLang($fieldObject);
|
||||
$fieldPairs[$field] = isset($this->lang->$fieldObject->$relatedField) ? $this->lang->$fieldObject->$relatedField : $field;
|
||||
|
||||
if(!isset($langs[$field])) continue;
|
||||
if(!empty($langs[$field][$clientLang])) $fieldPairs[$field] = $langs[$field][$clientLang];
|
||||
}
|
||||
/* 获取关联字段下拉菜单数据。*/
|
||||
/* Get the options for the related field in filter. */
|
||||
$fields = $this->chartZen->getOptions4SelectField();
|
||||
|
||||
$htmls = array();
|
||||
foreach($filters as $filter)
|
||||
{
|
||||
$field = $filter['field'];
|
||||
$type = $filter['type'];
|
||||
$default = isset($filter['default']) ? $filter['default'] : '';
|
||||
|
||||
$options = array();
|
||||
if($type == 'select')
|
||||
{
|
||||
$fieldSetting = $fieldSettings[$field];
|
||||
$options = $this->chart->getSysOptions(zget($fieldSetting, 'type', ''), zget($fieldSetting, 'object', ''), zget($fieldSetting, 'field', ''), $sql);
|
||||
}
|
||||
$field = $filter['field'];
|
||||
$type = $filter['type'];
|
||||
|
||||
$filterHtml = array();
|
||||
|
||||
/* field html */
|
||||
$filterHtml['field'] = html::select('field', $fieldPairs, $field, "class='form-control picker-select' onchange='initFilterForm(this, this.value)'");
|
||||
$filterHtml['field'] = html::select('field', $fields, $field, "class='form-control picker-select' onchange='initFilterForm(this, this.value)'");
|
||||
|
||||
/* default html */
|
||||
$filterHtml['default'] = '';
|
||||
|
||||
if($type == 'input') $filterHtml['default'] .= html::input('default', $default, "class='form-control' onchange='changeDefault(this,this.value)'");
|
||||
if($type == 'date' or $type == 'datetime')
|
||||
{
|
||||
if(empty($default)) $default = array('begin' => '', 'end' => '');
|
||||
$class = $type == 'date' ? 'form-date' : 'form-datetime';
|
||||
$filterHtml['default'] .= '<div class="input-group">';
|
||||
$filterHtml['default'] .= html::input('default[begin]', $default['begin'], "class='form-control $class default-begin' placeholder='{$this->lang->chart->unlimited}' onchange='changeDefault(this,this.value)'");
|
||||
$filterHtml['default'] .= "<span class='input-group-addon fix-border borderBox' style='border-radius: 0px;'>{$this->lang->chart->colon}</span>";
|
||||
$filterHtml['default'] .= html::input('default[end]', $default['end'], "class='form-control $class default-end' placeholder='{$this->lang->chart->unlimited}' onchange='changeDefault(this,this.value)'");
|
||||
$filterHtml['default'] .= '</div>';
|
||||
}
|
||||
if($type == 'select') $filterHtml['default'] = html::select('default[]', $options, $default, "class='form-control picker-select' onchange='changeDefault(this,this.value)' multiple");
|
||||
if($type == 'condition')
|
||||
{
|
||||
$operator = isset($filter['operator']) ? $filter['operator'] : '';
|
||||
$value = isset($filter['value']) ? $filter['value'] : '';
|
||||
$hidden = strpos($operator, 'NULL') !== false ? 'hidden' : '';
|
||||
$filterHtml['default'] = "<div class='conditionGroup' style='display:flex'>";
|
||||
$filterHtml['default'] .= html::select('operator', $this->config->bi->conditionList, $operator, "class='form-control picker-select' onchange='changeCondition(this,this.value)'");
|
||||
$filterHtml['default'] .= html::input('value', $value, "class='form-control $hidden' onchange='changeConditionValue(this,this.value)'");
|
||||
$filterHtml['default'] .= "<div/>";
|
||||
}
|
||||
$filterHtml['default'] = $this->chartZen->getHTML('default', $type, $filter);
|
||||
|
||||
/* type html */
|
||||
$filterHtml['type'] = html::select('type', $this->lang->chart->fieldTypeList, $type, "class='form-control picker-select' onchange='changeType(this, this.value)'");
|
||||
|
||||
/* filter item html */
|
||||
$filterHtml['item'] = '';
|
||||
if($type == 'input') $filterHtml['item'] .= html::input('default', $default, "class='form-control'");
|
||||
if($type == 'date' or $type == 'datetime')
|
||||
{
|
||||
if(empty($default)) $default = array('begin' => '', 'end' => '');
|
||||
$class = $type == 'date' ? 'form-date' : 'form-datetime';
|
||||
$filterHtml['item'] .= '<div class="input-group">';
|
||||
$filterHtml['item'] .= "<input type='text' name='default[begin]' id='default[begin]' value='{$default['begin']}' class='form-control $class default-begin' autocomplete='off' placeholder='{$this->lang->chart->unlimited}' onchange='changeDefault(this, this.value)'>";
|
||||
$filterHtml['item'] .= '<span class="input-group-addon fix-border borderBox" style="border-radius: 0px;">' . $this->lang->chart->colon . '</span>';
|
||||
$filterHtml['item'] .= "<input type='text' name='default[end]' id='default[end]' value='{$default['end']}' class='form-control $class default-end' autocomplete='off' placeholder='{$this->lang->chart->unlimited}' onchange='changeDefault(this, this.value)'>";
|
||||
$filterHtml['item'] .= '</div>';
|
||||
}
|
||||
if($type == 'select') $filterHtml['item'] .= html::select('default', $options, $default, "class='form-control picker-select' multiple");
|
||||
if($type == 'condition')
|
||||
{
|
||||
$operator = isset($filter['operator']) ? $filter['operator'] : '';
|
||||
$value = isset($filter['value']) ? $filter['value'] : '';
|
||||
$hidden = strpos($operator, 'NULL') !== false ? 'hidden' : '';
|
||||
$filterHtml['item'] = "<div class='conditionGroup' style='display:flex'>";
|
||||
$filterHtml['item'] .= html::select('operator', $this->config->bi->conditionList, $operator, "class='form-control picker-select' onchange='changeCondition(this,this.value, true)'");
|
||||
$filterHtml['item'] .= html::input('value', $value, "class='form-control $hidden'");
|
||||
$filterHtml['item'] .= "<div/>";
|
||||
}
|
||||
$filterHtml['item'] = $this->chartZen->getHTML('item', $type, $filter);
|
||||
|
||||
$htmls[] = $filterHtml;
|
||||
}
|
||||
@@ -167,6 +100,7 @@ class chart extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图表。
|
||||
* Ajax get chart.
|
||||
*
|
||||
* @access public
|
||||
@@ -176,13 +110,10 @@ class chart extends control
|
||||
{
|
||||
$post = fixer::input('post')->skipSpecial('settings,filters,sql,langs')->get();
|
||||
|
||||
$chartID = $post->id;
|
||||
$settings = current($post->settings);
|
||||
$type = $settings['type'];
|
||||
$filters = isset($_POST['searchFilters']) ? $_POST['searchFilters'] : (isset($_POST['filters']) ? $post->filters : array());
|
||||
|
||||
$chart = $this->chart->getByID($chartID);
|
||||
|
||||
$filterFormat = $this->chart->getFilterFormat($filters);
|
||||
|
||||
$sql = str_replace(';', '', "$post->sql");
|
||||
|
||||
@@ -47,4 +47,95 @@ class chartZen extends chart
|
||||
|
||||
return $chart;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取筛选器表单中关联字段下拉菜单数据。
|
||||
* Get the options for the related field in filter.
|
||||
*
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions4SelectField(): array
|
||||
{
|
||||
$options = array();
|
||||
$fieldList = $this->post->fieldList;
|
||||
$fieldSettings = $this->post->fieldSettings;
|
||||
$langs = $this->post->langs;
|
||||
$clientLang = $this->app->getClientLang();
|
||||
|
||||
foreach($fieldList as $field => $fieldName)
|
||||
{
|
||||
$fieldObject = $fieldSettings[$field]['object'];
|
||||
$relatedField = $fieldSettings[$field]['field'];
|
||||
|
||||
$this->app->loadLang($fieldObject);
|
||||
$options[$field] = isset($this->lang->$fieldObject->$relatedField) ? $this->lang->$fieldObject->$relatedField : $field;
|
||||
|
||||
if(!isset($langs[$field])) continue;
|
||||
if(!empty($langs[$field][$clientLang])) $options[$field] = $langs[$field][$clientLang];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取筛选器中默认值和查询的HTML。
|
||||
* Get the HTML for the default value and search in filter.
|
||||
*
|
||||
* @param string $key default|item
|
||||
* @param string $type input|date|datetime|select|condition
|
||||
* @param array $filter
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function getHTML(string $key, string $type, array $filter): string
|
||||
{
|
||||
$html = '';
|
||||
$default = isset($filter['default']) ? $filter['default'] : '';
|
||||
|
||||
if($type == 'input')
|
||||
{
|
||||
$onChange = $key == 'default' ? "onchange='changeDefault(this,this.value)'" : '';
|
||||
$html = html::input('default', $default, "class='form-control' $onChange");
|
||||
}
|
||||
|
||||
if($type == 'date' || $type == 'datetime')
|
||||
{
|
||||
if(empty($default)) $default = array('begin' => '', 'end' => '');
|
||||
$class = $type == 'date' ? 'form-date' : 'form-datetime';
|
||||
|
||||
$html = '<div class="input-group">';
|
||||
$html .= html::input('default[begin]', $default['begin'], "class='form-control $class default-begin' autocomplete='off' placeholder='{$this->lang->chart->unlimited}' onchange='changeDefault(this, this.value)'");
|
||||
$html .= "<span class='input-group-addon fix-border borderBox' style='border-radius: 0px;'>{$this->lang->chart->colon}</span>";
|
||||
$html .= html::input('default[end]', $default['end'], "class='form-control $class default-end' autocomplete='off' placeholder='{$this->lang->chart->unlimited}' onchange='changeDefault(this, this.value)'");
|
||||
$html .= '</div>';
|
||||
}
|
||||
|
||||
if($type == 'select')
|
||||
{
|
||||
$options = array();
|
||||
$fieldSettings = $this->post->fieldSettings;
|
||||
$fieldSetting = $fieldSettings[$field];
|
||||
$options = $this->chart->getSysOptions(zget($fieldSetting, 'type', ''), zget($fieldSetting, 'object', ''), zget($fieldSetting, 'field', ''), $this->post->sql);
|
||||
$onChange = $key == 'default' ? "onchange='changeDefault(this, this.value)'" : '';
|
||||
|
||||
$html = html::select('default[]', $options, $default, "class='form-control picker-select' $onChange multiple");
|
||||
}
|
||||
|
||||
if($type == 'condition')
|
||||
{
|
||||
$operator = isset($filter['operator']) ? $filter['operator'] : '';
|
||||
$value = isset($filter['value']) ? $filter['value'] : '';
|
||||
$hidden = strpos($operator, 'NULL') !== false ? 'hidden' : '';
|
||||
$onChange = $key == 'default' ? "onchange='changeConditionValue(this,this.value)'" : '';
|
||||
$showSearch = $key == 'item' ? true : false;
|
||||
|
||||
$html = "<div class='conditionGroup' style='display:flex'>";
|
||||
$html .= html::select('operator', $this->config->bi->conditionList, $operator, "class='form-control picker-select' onchange='changeCondition(this, this.value, $showSearch)'");
|
||||
$html .= html::input('value', $value, "class='form-control $hidden' $onChange");
|
||||
$html .= "<div/>";
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user