* Add old datatable.

This commit is contained in:
wangyuting
2024-03-06 16:39:19 +08:00
parent a40920ab01
commit 537dfb882e
7 changed files with 500 additions and 9 deletions
+113
View File
@@ -194,6 +194,119 @@ class datatable extends control
$this->display();
}
/**
* Save config
*
* @access public
* @return void
*/
public function ajaxOldSave()
{
if(!empty($_POST))
{
$account = $this->app->user->account;
if($account == 'guest') return $this->send(array('result' => 'fail', 'target' => $target, 'message' => 'guest.'));
$name = 'datatable.' . $this->post->target . '.' . $this->post->name;
$this->loadModel('setting')->setItem($account . '.' . $name, $this->post->value);
if($this->post->allModule !== false) $this->setting->setItem("$account.execution.task.allModule", $this->post->allModule);
if($this->post->showBranch !== false) $this->setting->setItem($account . '.' . $this->post->currentModule . '.' . $this->post->currentMethod . '.showBranch', $this->post->showBranch);
if($this->post->global) $this->setting->setItem('system.' . $name, $this->post->value);
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => 'dao error.'));
return $this->send(array('result' => 'success'));
}
}
/**
* custom fields.
*
* @param string $module
* @param string $method
* @param string $extra
* @access public
* @return void
*/
public function ajaxOldCustom(string $module, string $method, string $extra = '')
{
$moduleName = $module;
$target = $module . ucfirst($method);
$mode = isset($this->config->datatable->$target->mode) ? $this->config->datatable->$target->mode : 'table';
$key = $mode == 'datatable' ? 'cols' : 'tablecols';
if($module == 'testtask')
{
$this->loadModel('testcase');
$this->app->loadConfig('testtask');
$this->config->testcase->datatable->defaultField = $this->config->testtask->datatable->defaultField;
$this->config->testcase->datatable->fieldList['actions']['width'] = '100';
$this->config->testcase->datatable->fieldList['status']['width'] = '90';
}
if($module == 'testcase')
{
$this->loadModel('testcase');
unset($this->config->testcase->datatable->fieldList['assignedTo']);
}
$this->view->module = $module;
$this->view->method = $method;
$this->view->mode = $mode;
$module = zget($this->config->datatable->moduleAlias, "$module-$method", $module);
$setting = '';
if(isset($this->config->datatable->$target->$key)) $setting = $this->config->datatable->$target->$key;
if(empty($setting))
{
$this->loadModel($module);
$setting = json_encode($this->config->$module->datatable->defaultField);
}
$cols = $this->datatable->getOldFieldList($module);
if($module == 'story' && $extra != 'requirement') unset($cols['SRS']);
if($extra == 'requirement')
{
unset($cols['plan']);
unset($cols['stage']);
unset($cols['taskCount']);
unset($cols['bugCount']);
unset($cols['caseCount']);
unset($cols['URS']);
$cols['title']['title'] = str_replace($this->lang->SRCommon, $this->lang->URCommon, $this->lang->story->title);
}
if($moduleName == 'project' and $method == 'bug')
{
$project = $this->loadModel('project')->getByID($this->session->project);
if(!$project->multiple) unset($cols['execution']);
if(!$project->hasProduct and $project->model != 'scrum') unset($cols['plan']);
if(!$project->hasProduct) unset($cols['branch']);
}
if($moduleName == 'execution' and $method == 'bug')
{
$execution = $this->loadModel('execution')->getByID($this->session->execution);
$project = $this->loadModel('project')->getByID($execution->project);
if(!$project->hasProduct and $project->model != 'scrum') unset($cols['plan']);
if(!$project->hasProduct) unset($cols['branch']);
}
if($moduleName == 'execution' and $method == 'story')
{
$execution = $this->loadModel('execution')->getByID($this->session->execution);
if(!$execution->hasProduct and !$execution->multiple) unset($cols['plan']);
if(!$execution->hasProduct) unset($cols['branch']);
}
if($extra == 'unsetStory' and isset($cols['story'])) unset($cols['story']);
$this->view->cols = $cols;
$this->view->setting = $setting;
$this->display();
}
/**
* 恢复自定义项为默认配置。
* Ajax reset cols.
+162
View File
@@ -148,6 +148,121 @@ class datatableModel extends model
return $fieldSetting;
}
/**
* Get field list.
*
* @param string $module
* @access public
* @return array
*/
public function getOldFieldList(string $module)
{
if(!isset($this->config->$module)) $this->loadModel($module);
if($this->session->hasProduct == 0 and (strpos($this->config->datatable->noProductModule, ",$module,") !== false))
{
$productIndex = array_search('product', $this->config->$module->datatable->defaultField);
if($productIndex) unset($this->config->$module->datatable->defaultField[$productIndex]);
if(isset($this->config->$module->datatable->fieldList['product'])) unset($this->config->$module->datatable->fieldList['product']);
}
if($this->session->currentProductType === 'normal') unset($this->config->$module->datatable->fieldList['branch']);
foreach($this->config->$module->datatable->fieldList as $field => $items)
{
if($field === 'branch')
{
if($this->session->currentProductType === 'branch') $this->config->$module->datatable->fieldList[$field]['title'] = $this->lang->datatable->branch;
if($this->session->currentProductType === 'platform') $this->config->$module->datatable->fieldList[$field]['title'] = $this->lang->datatable->platform;
continue;
}
$title = zget($this->lang->$module, $items['title'], zget($this->lang, $items['title'], $items['title']));
$this->config->$module->datatable->fieldList[$field]['title'] = $title;
}
if($this->config->edition != 'open')
{
$fields = $this->loadModel('workflowfield')->getList($module);
foreach($fields as $field)
{
if($field->buildin) continue;
$this->config->$module->datatable->fieldList[$field->field]['title'] = $field->name;
$this->config->$module->datatable->fieldList[$field->field]['width'] = '120';
$this->config->$module->datatable->fieldList[$field->field]['fixed'] = 'no';
$this->config->$module->datatable->fieldList[$field->field]['required'] = 'no';
}
}
return $this->config->$module->datatable->fieldList;
}
/**
* Get save setting field.
*
* @param string $module
* @access public
* @return object
*/
public function getOldSetting(string $module)
{
$method = $this->app->getMethodName();
$datatableId = $module . ucfirst($method);
$mode = isset($this->config->datatable->$datatableId->mode) ? $this->config->datatable->$datatableId->mode : 'table';
$key = $mode == 'datatable' ? 'cols' : 'tablecols';
$module = zget($this->config->datatable->moduleAlias, "$module-$method", $module);
if(!isset($this->config->$module)) $this->loadModel($module);
if(isset($this->config->datatable->$datatableId->$key)) $setting = json_decode($this->config->datatable->$datatableId->$key);
$fieldList = $this->getOldFieldList($module);
if(empty($setting))
{
$setting = $this->config->$module->datatable->defaultField;
$order = 1;
foreach($setting as $key => $value)
{
$id = $value;
$set = new stdclass();;
$set->order = $order++;
$set->id = $id;
$set->show = true;
$set->width = $fieldList[$id]['width'];
$set->fixed = $fieldList[$id]['fixed'];
$set->title = $fieldList[$id]['title'];
$set->sort = isset($fieldList[$id]['sort']) ? $fieldList[$id]['sort'] : 'yes';
$set->name = isset($fieldList[$id]['name']) ? $fieldList[$id]['name'] : '';
if(isset($fieldList[$id]['minWidth'])) $set->minWidth = $fieldList[$id]['minWidth'];
if(isset($fieldList[$id]['maxWidth'])) $set->maxWidth = $fieldList[$id]['maxWidth'];
if(isset($fieldList[$id]['pri'])) $set->pri = $fieldList[$id]['pri'];
$setting[$key] = $set;
}
}
else
{
foreach($setting as $key => $set)
{
if(!isset($fieldList[$set->id]))
{
unset($setting[$key]);
continue;
}
if($this->session->currentProductType === 'normal' and $set->id === 'branch')
{
unset($setting[$key]);
continue;
}
if($set->id == 'actions') $set->width = $fieldList[$set->id]['width'];
$set->title = $fieldList[$set->id]['title'];
$set->sort = isset($fieldList[$set->id]['sort']) ? $fieldList[$set->id]['sort'] : 'yes';
}
}
usort($setting, array('datatableModel', 'sortOldCols'));
return $setting;
}
/**
* 获取期望的配置项。
* Format fields by config.
@@ -202,6 +317,21 @@ class datatableModel extends model
return $a['order'] - $b['order'];
}
/**
* Sort old cols.
*
* @param object $a
* @param object $b
* @static
* @access public
* @return int
*/
public static function sortOldCols(object $a, object $b)
{
if(!isset($a->order)) return 0;
return $a->order - $b->order;
}
/**
* 打印表格标题。
* Print table head.
@@ -259,4 +389,36 @@ class datatableModel extends model
echo '</th>';
}
}
/**
* Set fixed field width
*
* @param array $setting
* @param int $minLeftWidth
* @param int $minRightWidth
* @access public
* @return array
*/
public function setFixedFieldWidth(array $setting, int $minLeftWidth = 550, int $minRightWidth = 140)
{
$widths['leftWidth'] = 30;
$widths['rightWidth'] = 0;
$hasLeftAuto = false;
$hasRightAuto = false;
foreach($setting as $key => $value)
{
if($value->fixed != 'no')
{
if($value->fixed == 'left' and $value->width == 'auto') $hasLeftAuto = true;
if($value->fixed == 'right' and $value->width == 'auto') $hasRightAuto = true;
$widthKey = $value->fixed . 'Width';
if(!isset($widths[$widthKey])) $widths[$widthKey] = 0;
$widths[$widthKey] += (int)trim($value->width, 'px');
}
}
if($widths['leftWidth'] <= 550 and $hasLeftAuto) $widths['leftWidth'] = 550;
if($widths['rightWidth'] <= 0 and $hasRightAuto) $widths['rightWidth'] = 140;
return $widths;
}
}
@@ -0,0 +1,215 @@
<?php
/**
* The view file of datatable module of ZenTaoPMS.
*
* @copyright Copyright 2014-2014 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
* @license business(商业软件)
* @author Hao sun <sunhao@cnezsoft.com>
* @package datatable
* @version $Id$
* @link https://www.zentao.net
*/
?>
<style>
.cols-list {margin-bottom: 10px;}
.cols-list .col {border: 1px solid #ddd; height: 30px; line-height: 29px; padding: 0 10px; border-bottom: none; background: #fff; float:none; padding-left: 6px;}
.cols-list .checkbox-primary {display: inline-block; position: relative; top: -1px;}
.cols-list .checkbox-primary > label {padding: 0; width: 21px;}
.cols-list .col.drag-shadow {border: 1px solid #ddd;}
.cols-list {border-bottom: 1px solid #ddd}
.cols-list .col:hover {background: #E9F2FB}
.cols-list .col.require:hover {background: none}
.cols-list .col .actions {line-height: 30px; vertical-align: top;}
.cols-list .col .form-control {display: inline-block; width: 50px; padding: 0px 5px; height: 20px; line-height: 20px; border-color: transparent; position: relative; top: -2px}
.cols-list .col .form-control:hover {border-color: #ddd}
.cols-list .col .form-control[disabled] {background: none}
.cols-list .col .form-control[disabled]:hover {border-color: transparent;}
.cols-list .col .btn {padding: 0px 5px; position: relative; top: -1px}
.cols-list .col .btn.show-hide {font-size: 13px}
.cols-list .col .title {cursor: pointer; display: inline-block; width: 500px;}
.cols-list .col .title-bar {white-space:nowrap; cursor: pointer; display: inline-block; width: 300px; background: #f1f1f1; border-left: 1px solid #ddd; border-right: 1px solid #ddd; padding-left: 6px; position: relative; max-width: 500px; min-width: 30px}
.cols-list .col .title .icon-move {width: 20px; height: 20px; line-height: 20px; text-align: center; position: relative; left: 3px;}
.cols-list .col:hover .title-bar {background: #eee; transition: width 0.3s;}
.cols-list .col.require .title {cursor: default;}
.cols-list .col.disabled .title {opacity: 0.5;}
.cols-list .col.disabled .title strong {font-weight: normal;}
.cols-list .col.disabled .icon-ok {opacity: 0.05;}
.cols-list .col .label-hide {color: #03c; background: none}
.cols-list .col .label-show {color: #fff; background: #aaa}
.cols-list .col.disabled .label-hide {color: #fff; background: #aaa}
.cols-list .col.disabled .label-show {color: #03c; background: none}
.cols-list .col.drop-to, .cols-list .col.drag-from {opacity: 0.5; visibility: visible; background: #e5e5e5}
.cols-list .col .btn.disabled, .cols-list .col.disabled .btn.disabled, .cols-list .col .btn.disabled .label-hide {border: none; color: #aaa; cursor: not-allowed; background: none}
.cols-list .col .icon-move {opacity: 0; transition:all 0.2s; cursor: move;}
.cols-list .col:hover .icon-move {opacity: 0.7;}
.cols-list.sort-disabled .icon-move {display: none;}
#customDatatable .form-actions {margin-top: 10px;}
#customDatatable .form-actions .checkbox-primary {margin-bottom: 10px; margin-left: 7px;}
</style>
<div class='modal-dialog' id='customDatatable' style='width: 800px'>
<div class='modal-content'>
<div class='modal-header'>
<button class="close" data-dismiss="modal"><i class="icon icon-close"></i></button>
<h4 class='modal-title'>
<?php echo $lang->datatable->custom?>
&nbsp; <small><?php echo $lang->datatable->customTip ?></small>
</h4>
</div>
<div class='modal-body'>
<div id='colsFixedLeft' class='cols-list'></div>
<div id='colsFixedFlex' class='cols-list'></div>
<div id='colsFixedRight' class='cols-list'></div>
<div class='cols-list template' id="originCols">
<?php foreach ($cols as $key => $col):?>
<?php
$required = $col['required'] == 'yes';
$fixed = $col['fixed'];
$autoWidth = $col['width'] == 'auto';
?>
<div class='clearfix col<?php echo ($required ? ' require' : '') . (' fixed-' . $fixed) ?>' data-key='<?php echo $key?>' data-fixed='<?php echo $fixed?>' data-width='<?php echo $col['width']?>'>
<div class='actions pull-right' <?php if($autoWidth) echo "style='padding-right: 11px'";?>>
<?php if(isset($col['name'])) echo html::hidden('name', $col['name'])?>
<span><span class='text-muted'><?php echo $lang->datatable->width?></span> <input type='text' id='width' class='form-control' value='<?php echo $col['width']?>'><?php echo $autoWidth ? '&nbsp;' : 'px' ?></span>
</div>
<div class="checkbox-primary<?php echo $required ? ' disabled' : '';?>"><label></label></div>
<span class='title'><span class='title-bar'><strong><?php echo $col['title']?></strong><i class='icon-move'></i></span></span> <?php if($required) echo "<span class='text-muted'>({$lang->datatable->required})</span>"?>
</div>
<?php endforeach;?>
</div>
<div class='form-actions text-left'>
<?php if(common::hasPriv('datatable', 'setGlobal')) echo html::checkbox('global', array(1 => $lang->datatable->setGlobal));?>
<button type='button' class='btn btn-wide btn-primary btn-save' id='btnSaveCustom'><?php echo $lang->save ?></button>
<button type='button' class='btn btn-wide' data-dismiss='modal'><?php echo $lang->close ?></button>
<button type='button' class='btn btn-wide' id='resetBtn'><?php echo $lang->datatable->reset ?></button>
</div>
</div>
</div>
</div>
<?php
js::set('resetText', $lang->datatable->reset);
js::set('resetGlobalText', $lang->datatable->resetGlobal);
?>
<script>
$(function()
{
var setting = JSON.parse('<?php echo $setting;?>');
var $cols = $('#originCols .col').addClass('disabled');
$cols.filter('.fixed-left').appendTo('#colsFixedLeft');
$cols.filter('.fixed-flex, .fixed-no').appendTo('#colsFixedFlex');
$cols.filter('.fixed-right').appendTo('#colsFixedRight');
$('#originCols').remove();
$('[data-key=actions] #width').attr('disabled', 'disabled');
if(typeof setting[0] === 'string')
{
var newSetting = [];
$('.col').each(function(idx)
{
var $col = $(this);
var id = $col.data('key');
newSetting.push({id: id, order: idx, show: $.inArray(id, setting) > -1});
});
setting = newSetting;
}
setting.sort(function(a, b)
{
if(a.order !== undefined && b.order !== undefined)
{
if(typeof a.order === 'string') a.order = parseInt(a.order);
if(typeof b.order === 'string') b.order = parseInt(b.order);
return a.order - b.order;
}
return 0;
});
for(var i = 0; i< setting.length; i++)
{
var col = setting[i];
if(typeof col === 'string')
{
col = {id: col, disabled: false};
}
var $col = $cols.filter('[data-key=' + col.id + ']');
$col.toggleClass('disabled', !col.show).attr('data-order', col.order);
$col.find('.checkbox-primary').toggleClass('checked', !!col.show);
if(col.width) $col.find('input#width').val(col.width.replace('px', ''));
}
$('.cols-list').on('click', '.col:not(.require) .title, .col:not(.require) .checkbox-primary', function()
{
var $col = $(this).closest('.col').toggleClass('disabled');
$col.find('.checkbox-primary').toggleClass('checked', !$col.hasClass('disabled'));
}).each(function()
{
var $list = $(this),
$cols = $list.children('.col');
if($cols.length < 2)
{
$list.addClass('sort-disabled');
}
else
{
$cols.detach().sort(function(a, b)
{
return $(a).data('order') - $(b).data('order');
}).appendTo($list);
$list.sortable({trigger: '.title', selector: '.col'});
}
}).on('keyup change', 'input#width', function()
{
renderColWidth($(this).closest('.col'));
});
function renderColWidth($col)
{
var width = $col.find('input#width').val();
if(width == 'auto')
{
width = '500';
}
else
{
width = parseInt(width);
if(isNaN(width))
{
width = $col.data('width');
}
if(width == 'auto') width = '500';
}
$col.find('.title-bar').css('width', width);
}
$('.col').each(function(){renderColWidth($(this));});
$('#btnSaveCustom').on('click', function()
{
var setting = $('.col').map(function(index)
{
var $col = $(this);
var sets = {id: $col.data('key'), order: index + 1, show: !$col.hasClass('disabled'), width: $col.find('input#width').val(), fixed: $col.data('fixed')};
if(sets.width !== 'auto') sets.width += 'px';
if($col.find('#name').size() > 0) sets.name = $col.find('#name').val();
return sets;
}).get();
window.saveDatatableConfig('<?php echo $mode == 'table' ? 'tablecols' : 'cols';?>', setting, true, $('#global1').prop('checked') ? 1 : 0);
});
$('#resetBtn').on("click", function()
{
var system = $('#global1').prop('checked') ? 1 : 0;
var param = "<?php echo "module=$module&method=$method"?>&system=" + system;
hiddenwin.location.href = createLink('datatable', 'ajaxReset', param);
})
$('#global1').change(function()
{
if($(this).prop('checked'))$('#resetBtn').text(resetGlobalText);
if(!$(this).prop('checked'))$('#resetBtn').text(resetText);
})
});
</script>