* Add origin sheet function.
This commit is contained in:
@@ -139,10 +139,16 @@ function checkFormSetting()
|
||||
*/
|
||||
function validate(showError = false)
|
||||
{
|
||||
var pivot = DataStorage.pivot;
|
||||
var pivot = DataStorage.pivot;
|
||||
var formSettings = pivot.settings;
|
||||
/* Code for temporary */
|
||||
var isReady = true;
|
||||
var isReady = true;
|
||||
var firstErrDom = null;
|
||||
|
||||
if("summary" in formSettings && formSettings.summary == 'notuse')
|
||||
{
|
||||
if(isReady) $('#datagrid-tip').addClass('hidden');
|
||||
return true;
|
||||
}
|
||||
|
||||
/* check group settings. */
|
||||
var exist = false;
|
||||
@@ -164,6 +170,8 @@ function validate(showError = false)
|
||||
var error = '<div id="groupLabel" class="text-danger help-text">' + moreThanOneLang + '</div>';
|
||||
tr.find('#group1').addClass('has-error');
|
||||
tr.find('#group1').next().after(error);
|
||||
|
||||
firstErrDom = tr.find('#group1').parents('tr');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +191,9 @@ function validate(showError = false)
|
||||
{
|
||||
var error = '<div id="column' + index + 'Label" class="text-danger help-text">' + notemptyLang.replace('%s', pivotLang.step2.columnField) + '</div>';
|
||||
$column.find('#column').addClass('has-error');
|
||||
$column.find('#column').next().after(error);
|
||||
$column.find('#column').parent().after(error);
|
||||
|
||||
if(!firstErrDom) firstErrDom = $column.find('#column').parents('.column');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,11 +205,14 @@ function validate(showError = false)
|
||||
var error = '<div id="stat' + index + 'Label" class="text-danger help-text">' + notemptyLang.replace('%s', pivotLang.step2.calcMode) + '</div>';
|
||||
$column.find('#stat').addClass('has-error');
|
||||
$column.find('#stat').next().after(error);
|
||||
|
||||
if(!firstErrDom) firstErrDom = $column.find('#stat').parents('.column');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(isReady) $('#datagrid-tip').addClass('hidden');
|
||||
if(!isReady && firstErrDom) firstErrDom[0].scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' })
|
||||
return isReady;
|
||||
}
|
||||
|
||||
@@ -436,7 +449,7 @@ function setDateField(query)
|
||||
var target = $(query).parents('table, #queryFilters, #filterItems,#filterForm').find('[data-index="' + $period.attr('data-index') + '"]').find('#default:visible');
|
||||
if(target.length)
|
||||
{
|
||||
target.val($(this).attr('href').replace('#', '$'));
|
||||
target.val($(this).attr('href').replace('#', '$')).trigger('change');
|
||||
$period.hide();
|
||||
}
|
||||
event.stopPropagation();
|
||||
@@ -447,6 +460,10 @@ function setDateField(query)
|
||||
if(query == '.form-date') $(query).datepicker();
|
||||
if(query == '.form-datetime') $(query).datetimepicker();
|
||||
|
||||
var dateVal = $(query).val();
|
||||
$(query).val('').datetimepicker('update').trigger('mousedown');
|
||||
$(query).val(dateVal);
|
||||
|
||||
$(query).on('show', function(e)
|
||||
{
|
||||
var $e = $(e.target);
|
||||
|
||||
@@ -1377,6 +1377,98 @@ class pivotModel extends model
|
||||
return array($data, $configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gen sheet by origin sql.
|
||||
*
|
||||
* @param array $fields
|
||||
* @param array $settings
|
||||
* @param string $sql
|
||||
* @param array $filters
|
||||
* @param array $langs
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function genOriginSheet($fields, $settings, $sql, $filters, $langs = array())
|
||||
{
|
||||
$sql = $this->initVarFilter($filters, $sql);
|
||||
|
||||
/* Process rows. */
|
||||
$connectSQL = '';
|
||||
if(!empty($filters) && !isset($filters[0]['from']))
|
||||
{
|
||||
$wheres = array();
|
||||
foreach($filters as $field => $filter)
|
||||
{
|
||||
$wheres[] = "tt.`$field` {$filter['operator']} {$filter['value']}";
|
||||
}
|
||||
|
||||
$whereStr = implode(' and ', $wheres);
|
||||
$connectSQL .= " where $whereStr";
|
||||
}
|
||||
|
||||
$this->app->loadClass('sqlparser', true);
|
||||
$parser = new sqlparser($sql);
|
||||
$statement = $parser->statements[0];
|
||||
if(!$statement->limit)
|
||||
{
|
||||
$statement->limit = new stdclass();
|
||||
$statement->limit->offset = 0;
|
||||
$statement->limit->rowCount = 99999999;
|
||||
}
|
||||
$sql = $statement->build();
|
||||
|
||||
$columnSQL = "select * from ($sql) tt" . $connectSQL;
|
||||
$rows = $this->dao->query($columnSQL)->fetchAll();
|
||||
$rows = json_decode(json_encode($rows), true);
|
||||
|
||||
$cols = array();
|
||||
$clientLang = $this->app->getClientLang();
|
||||
/* Build cols. */
|
||||
foreach($fields as $field)
|
||||
{
|
||||
$key = $field['field'];
|
||||
|
||||
$col = new stdclass();
|
||||
$col->name = $key;
|
||||
$col->isGroup = true;
|
||||
|
||||
$fieldObject = $field['object'];
|
||||
$relatedField = $field['field'];
|
||||
|
||||
$colLabel = $key;
|
||||
if($fieldObject)
|
||||
{
|
||||
$this->app->loadLang($fieldObject);
|
||||
if(isset($this->lang->$fieldObject->$relatedField)) $colLabel = $this->lang->$fieldObject->$relatedField;
|
||||
}
|
||||
|
||||
if(isset($langs[$key]) and !empty($langs[$key][$clientLang])) $colLabel = $langs[$key][$clientLang];
|
||||
$col->label = $colLabel;
|
||||
|
||||
$cols[0][] = $col;
|
||||
}
|
||||
|
||||
$fieldOptions = $this->getFieldsOptions($fields, $sql);
|
||||
foreach($rows as $key => $row)
|
||||
{
|
||||
foreach($row as $field => $value)
|
||||
{
|
||||
$optionList = isset($fieldOptions[$field]) ? $fieldOptions[$field] : array();
|
||||
$row[$field] = isset($optionList[$value]) ? $optionList[$value] : $value;
|
||||
}
|
||||
|
||||
$rows[$key] = $row;
|
||||
}
|
||||
|
||||
$data = new stdclass();
|
||||
$data->cols = $cols;
|
||||
$data->array = $rows;
|
||||
|
||||
$configs = array_fill(0, count($rows), array_fill(0, count($fields), 1));
|
||||
|
||||
return array($data, $configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化分组信息。
|
||||
* Init groups info.
|
||||
|
||||
@@ -166,7 +166,14 @@ class pivotZen extends pivot
|
||||
$fields = json_decode(json_encode($pivot->fieldSettings), true);
|
||||
$langs = json_decode($pivot->langs, true) ?? array();
|
||||
|
||||
list($data, $configs) = $this->pivot->genSheet($fields, $pivot->settings, $sql, $filterFormat, $langs);
|
||||
if(isset($pivot->settings['summary']) and $pivot->settings['summary'] =='notuse')
|
||||
{
|
||||
list($data, $configs) = $this->pivot->genOriginSheet($fields, $pivot->settings, $sql, $filterFormat, $langs);
|
||||
}
|
||||
else
|
||||
{
|
||||
list($data, $configs) = $this->pivot->genSheet($fields, $pivot->settings, $sql, $filterFormat, $langs);
|
||||
}
|
||||
|
||||
$this->view->pivotName = $pivot->name;
|
||||
$this->view->currentMenu = $groupID . '_' . $pivot->id;
|
||||
|
||||
Reference in New Issue
Block a user