* Code for dtable.

This commit is contained in:
Yagami
2023-02-15 10:54:42 +08:00
parent abba42925e
commit 8bc4f664d4
6 changed files with 59 additions and 150 deletions
+4 -5
View File
@@ -189,29 +189,28 @@ $config->execution->datatable->fieldList['id']['fixed'] = 'left';
$config->execution->datatable->fieldList['id']['width'] = '70';
$config->execution->datatable->fieldList['id']['required'] = 'yes';
$config->execution->datatable->fieldList['id']['sortType'] = true;
$config->execution->datatable->fieldList['id']['checkbox'] = true;
$config->execution->datatable->fieldList['name']['name'] = 'name';
$config->execution->datatable->fieldList['name']['title'] = $lang->execution->name;
$config->execution->datatable->fieldList['name']['width'] = 356;
$config->execution->datatable->fieldList['name']['width'] = '356';
$config->execution->datatable->fieldList['name']['type'] = 'html';
$config->execution->datatable->fieldList['name']['flex'] = 1;
$config->execution->datatable->fieldList['name']['fixed'] = 'left';
$config->execution->datatable->fieldList['name']['nestedToggle'] = true;
$config->execution->datatable->fieldList['name']['checkbox'] = true;
$config->execution->datatable->fieldList['name']['iconRender'] = true;
$config->execution->datatable->fieldList['name']['sortType'] = true;
$config->execution->datatable->fieldList['name']['required'] = 'yes';
if(!isset($config->setCode) or $config->setCode == 1)
{
$config->execution->datatable->fieldList['code']['title'] = 'execCode';
$config->execution->datatable->fieldList['code']['width'] = '120';
$config->execution->datatable->fieldList['code']['width'] = '140';
$config->execution->datatable->fieldList['code']['fixed'] = 'left';
$config->execution->datatable->fieldList['code']['required'] = 'no';
}
$config->execution->datatable->fieldList['project']['title'] = 'project';
$config->execution->datatable->fieldList['project']['width'] = '200';
$config->execution->datatable->fieldList['project']['flex'] = 1;
$config->execution->datatable->fieldList['project']['required'] = 'no';
$config->execution->datatable->fieldList['status']['title'] = 'execStatus';
+2
View File
@@ -46,3 +46,5 @@ canvas {height: 28px;}
#executionsForm td.c-name.delay {padding-right: 55px;}
#myTable .dtable-header, #executionsForm .dtable-rows {z-index: 4;}
#executionsForm .table-header .btn-toolbar {background: rgb(241, 245, 249); right: -3px;}
.table-footer .pager{z-index: 10}
+8 -119
View File
@@ -1,117 +1,21 @@
$(function()
{
$("#" + status + "Tab").addClass('btn-active-text');
$(document).on('click', '.plan-toggle', function(e)
$('.table-footer .check-all').on('click', function()
{
var id = $(this).data('id');
var $toggle = $(this);
var isCollapsed = $toggle.toggleClass('collapsed').hasClass('collapsed');
$toggle.closest('#executionsForm').find('tr.parent-' + id).toggle(!isCollapsed);
e.stopPropagation();
e.preventDefault();
});
if($('#executionList thead th.c-name').width() < 260) $('#executionList thead th.c-name').width(260);
$('#executionTableList').on('sort.sortable', function(e, data)
{
var list = '';
for(i = 0; i < data.list.length; i++) list += $(data.list[i].item).attr('data-id') + ',';
$.post(createLink('execution', 'updateOrder'), {'executions' : list, 'orderBy' : orderBy});
});
toggleFold('#executionsForm', unfoldExecutions, 0, 'execution');
$('.table td.has-child > .plan-toggle').each(function()
{
var fold = $(this).hasClass('collapsed');
var parentID = $(this).closest('tr').attr('data-id');
if(fold)
if($(this).hasClass('checked'))
{
$('.parent-' + parentID).hide();
$(this).closest('td').removeClass('parent');
$(this).removeClass('checked');
$('.dtable-row').removeClass('is-checked');
$('.has-checkbox input[type="checkbox"]').prop('checked', false);
}
else
{
$('.parent-' + parentID).show();
$(this).closest('td').addClass('parent');
}
});
/* Expand and fold substages. */
$('.table td.has-child > .plan-toggle').click(function()
{
var parentID = $(this).closest('tr').attr('data-id');
$('.parent-' + parentID).toggle();
if($('.parent-' + parentID).css('display') == 'none')
{
$(this).closest('td').removeClass('parent');
}
else
{
$(this).closest('td').addClass('parent');
}
});
$(document).on('click', "#toggleFold", function()
{
var fold = $(this).hasClass('collapsed');
if(fold)
{
$('.has-child.c-name.flex').removeClass('parent');
$('.table td.has-child > .plan-toggle').addClass('collapsed');
}
else
{
$('.has-child.c-name.flex').addClass('parent');
$('.table td.has-child > .plan-toggle').removeClass('collapsed');
}
});
/* Update table summary text. */
$('#executionsForm').table(
{
statisticCreator: function(table)
{
var $table = table.getTable();
var $checkedRows = $table.find(table.isDataTable ? '.datatable-row-left.checked' : 'tbody>tr.checked');
var $originTable = table.isDataTable ? table.$.find('.datatable-origin') : null;
var checkedTotal = $checkedRows.length;
var $rows = checkedTotal ? $checkedRows : $table.find(table.isDataTable ? '.datatable-rows .datatable-row-left' : 'tbody>tr');
var checkedWait = 0;
var checkedDoing = 0;
var executionIDList = [];
$rows.each(function()
{
var $row = $(this);
if($originTable) $row = $originTable.find('tbody>tr[data-id="' + $row.data('id') + '"]');
var data = $row.data();
executionIDList.push(data.id);
if(data.status === 'wait') checkedWait++;
if(data.status === 'doing') checkedDoing++;
});
if(status != 'all') return (checkedTotal ? checkedExecutions : executionSummary).replace('%s', $rows.length);
return (checkedTotal ? checkedSummary : pageSummary).replace('%total%', $rows.length).replace('%wait%', checkedWait).replace('%doing%', checkedDoing);
$(this).addClass('checked');
$('.dtable-row').addClass('is-checked');
$('.has-checkbox input[type="checkbox"]').prop('checked', true);
}
})
$('input[name^="showEdit"]').click(function()
{
$.cookie('showExecutionBatchEdit', $(this).is(':checked') ? 1 : 0, {expires: config.cookieLife, path: config.webRoot});
setCheckbox();
});
setCheckbox();
$('#executionTableList tr').on('click', function(e)
{
if($.cookie('showExecutionBatchEdit') != 1) e.stopPropagation();
});
});
/**
@@ -127,18 +31,3 @@ function byProduct(productID, projectID, status)
{
location.href = createLink('project', 'all', "status=" + status + "&project=" + projectID + "&orderBy=" + orderBy + '&productID=' + productID);
}
/**
* Set batch edit checkbox.
*
* @access public
* @return void
*/
function setCheckbox()
{
$('#executionsForm .checkbox-primary').hide();
$('.check-all, .sortable tr').removeClass('checked');
$(":checkbox[name^='executionIDList']").prop('checked', false);
$('#executionsForm').removeClass('has-row-checked');
if($.cookie('showExecutionBatchEdit') == 1) $('#executionsForm .checkbox-primary').show();
}
+16 -11
View File
@@ -1682,10 +1682,7 @@ class executionModel extends model
}
}
if($this->app->moduleName != 'execution' and $this->app->methodName != 'all')
{
foreach($childList as $id) unset($executions[$id]);
}
foreach($childList as $id) unset($executions[$id]);
return array_values($executions);
}
@@ -5218,15 +5215,12 @@ class executionModel extends model
continue;
}
if($set->id == 'actions') $set->width = $fieldList[$set->id]['width'];
$set->name = $set->id;
$set->title = $fieldList[$set->id]['title'];
if(isset($fieldList[$set->id]['checkbox'])) $set->checkbox = $fieldList[$set->id]['checkbox'];
if(isset($fieldList[$set->id]['nestedToggle'])) $set->nestedToggle = $fieldList[$set->id]['nestedToggle'];
if(isset($fieldList[$set->id]['fixed'])) $set->fixed = $fieldList[$set->id]['fixed'];
if(isset($fieldList[$set->id]['width'])) $set->width = $fieldList[$set->id]['width'];
if(isset($fieldList[$set->id]['type'])) $set->type = $fieldList[$set->id]['type'];
if(isset($fieldList[$set->id]['sortType'])) $set->sortType = $fieldList[$set->id]['sortType'];
if(isset($fieldList[$set->id]['flex'])) $set->flex = $fieldList[$set->id]['flex'];
@@ -5234,6 +5228,8 @@ class executionModel extends model
if(isset($fieldList[$set->id]['maxWidth'])) $set->maxWidth = $fieldList[$set->id]['maxWidth'];
if(isset($fieldList[$set->id]['pri'])) $set->pri = $fieldList[$set->id]['pri'];
$set->width = str_replace('px', '', $set->width);
unset($set->id);
}
@@ -5255,15 +5251,14 @@ class executionModel extends model
*/
public function generateRow($executions, $users, $productID)
{
$canBatchEdit = common::hasPriv('execution', 'batchEdit');
$rows = array();
foreach($executions as $id => $execution)
{
$label = $execution->type == 'stage' ? 'label-warning' : 'label-info';
$link = $execution->type == 'kanban' ? helper::createLink('execution', 'kanban', "id=$execution->id") : helper::createLink('execution', 'task', "id=$execution->id");
$execution->name = "<span class='project-type-label label label-outline $label'>{$this->lang->execution->typeList[$execution->type]}</span> " . html::a($link, $execution->name);
$execution->project = $execution->projectName;
$execution->parent = $execution->parent ? $execution->parent : '';
$execution->parent = ($execution->parent and $execution->grade > 1) ? $execution->parent : '';
$execution->asParent = !empty($execution->children);
$execution->status = zget($this->lang->execution->statusList, $execution->status);
$execution->PM = zget($users, $execution->PM);
@@ -5271,9 +5266,19 @@ class executionModel extends model
$execution->estimate = $execution->hours->totalEstimate;
$execution->consumed = $execution->hours->totalConsumed;
$execution->left = $execution->hours->totalLeft;
$children = isset($execution->children) ? $execution->children : array();
unset($execution->children);
$rows[] = $execution;
if(!empty($children))
{
$rows = array_merge($rows, $this->generateRow($children, $users, $productID));
}
}
return $executions;
return $rows;
}
/*
+28 -14
View File
@@ -7,23 +7,17 @@ css::import($jsRoot . 'dtable/min.css');
$cols = $this->execution->generateCol();
$executions = $this->execution->generateRow($executionStats, $users, $productID);
$sortLink = $this->createLink('execution', 'all', "status=$status&orderBy={orderBy}&productID=$productID&param=$param&recTotal=$pager->recTotal&recPerPage=$pager->recPerPage&pageID=$pager->pageID");
js::set('sortLink', $sortLink);
js::set('cols', json_encode($cols));
js::set('data', json_encode($executions));
js::set('orderBy', $orderBy);
js::set('status', $status);
js::set('unfoldExecutions', array());
js::set('from', $from);
/* Replace Iteration to Execution. */
js::set('checkedSummary', str_replace($lang->executionCommon, $lang->execution->common, $lang->execution->checkedExecSummary));
js::set('pageSummary', str_replace($lang->executionCommon, $lang->execution->common, $lang->execution->pageExecSummary));
js::set('executionSummary', str_replace($lang->executionCommon, $lang->execution->common, $lang->execution->executionSummary));
js::set('checkedExecutions', str_replace($lang->executionCommon, $lang->execution->common, $lang->execution->checkedExecutions));
/* Set unfold parent executionID. */
js::set('unfoldAll', $lang->execution->treeLevel['all']);
js::set('foldAll', $lang->execution->treeLevel['root']);
js::set('isCNLang', !$this->loadModel('common')->checkNotCN())
js::set('isCNLang', !$this->loadModel('common')->checkNotCN());
?>
<?php $canBatchEdit = common::hasPriv('execution', 'batchEdit');?>
@@ -53,7 +47,6 @@ js::set('isCNLang', !$this->loadModel('common')->checkNotCN())
<?php if($status == $key) $label .= " <span class='label label-light label-badge'>{$pager->recTotal}</span>";?>
<?php echo html::a($this->createLink($this->app->rawModule, $this->app->rawMethod, "status=$key&orderBy=$orderBy&productID=$productID"), $label, '', "class='btn btn-link' id='{$key}Tab' data-app='$from'");?>
<?php endforeach;?>
<?php if($canBatchEdit) echo html::checkbox('showEdit', array('1' => $lang->execution->editAction), $showBatchEdit);?>
<a class="btn btn-link querybox-toggle" id='bysearchTab'><i class="icon icon-search muted"></i> <?php echo $lang->execution->byQuery;?></a>
</div>
<div class='btn-toolbar pull-right'>
@@ -76,26 +69,47 @@ js::set('isCNLang', !$this->loadModel('common')->checkNotCN())
</p>
</div>
<?php else:?>
<form class='main-table' id='executionsForm' method='post' action='<?php echo inLink('batchEdit');?>'>
<form class='main-table' id='' method='post' action='<?php echo inLink('batchEdit');?>'>
<div class="table-header fixed-right">
<nav class="btn-toolbar pull-right setting"></nav>
</div>
<div id="myTable"></div>
<div class='table-footer'>
<?php $pager->show('right', 'pagerjs');?>
<div class="checkbox-primary check-all"><label><?php echo $lang->selectAll?></label></div>
<div class="table-actions btn-toolbar">
<?php
if($canBatchEdit)
{
$actionLink = $this->createLink('project', 'batchEdit');
$misc = "data-form-action='$actionLink'";
echo html::commonButton($lang->edit, $misc);
}
?>
</div>
<?php $pager->show('right', 'pagerjs');?>
</div>
</form>
<script>
cols = JSON.parse(cols);
data = JSON.parse(data);
console.log(cols);
const options = {
height: 'auto',
striped: true,
plugins: ['nested'],
plugins: ['nested', 'checkable'],
checkOnClickRow: true,
sortLink: createSortLink,
cols: cols,
data: data,
};
function createSortLink(col)
{
var sort = col.name + '_asc';
if(sort == orderBy) sort = col.name + '_desc';
return sortLink.replace('{orderBy}', sort);
}
$('#myTable').dtable(options);
</script>
<?php endif;?>
+1 -1
View File
File diff suppressed because one or more lines are too long