* Code for port.

This commit is contained in:
tanghucheng
2022-07-27 17:23:17 +08:00
parent cb6339024e
commit c890f41b49
3 changed files with 153 additions and 55 deletions
+20
View File
@@ -123,5 +123,25 @@ class port extends control
}
}
/**
* ajaxGetOptions
*
* @param string $model
* @param string $field
* @param string $value
* @param string $index
* @access public
* @return void
*/
public function ajaxGetOptions($model = '', $field = '', $value = '', $index = '')
{
$this->app->loadConfig($model);
$fields = $this->config->$model->templateFields;
$fieldList = $this->port->initFieldList($model, $fields, false);
if(!isset($fieldList[$field]['values'][''])) $fieldList[$field]['values'][''] = '';
$multiple = $fieldList[$field]['control'] == 'multiple' ? 'multiple' : '';
return print(html::select($field. "[$index]", $fieldList[$field]['values'], $value, "class='form-control picker-select' $multiple"));
}
}
+71 -1
View File
@@ -907,6 +907,37 @@ class portModel extends model
return $fields;
}
/**
* Get view datas.
*
* @param string $model
* @param string $datas
* @param string $title
* @param int $pagerID
* @param int $maxImport
* @access public
* @return void
*/
public function getViewDatas($model = '', $datas = '', $title = '', $pagerID = 1, $maxImport = 0, $insert)
{
$suhosinInfo = $this->checkSuhosinInfo($datas->datas);
$fields = $this->config->$model->templateFields;
$datas->title = $title ? $title : $this->lang->port->showImport;
$datas->requiredFields = $this->config->$model->create->requiredFields;
$datas->allPager = isset($datas->allPager) ? $datas->allPager : 1;
$datas->pagerID = $pagerID;
$datas->isEndPage = $pagerID >= $datas->allPager;
$datas->maxImport = $maxImport;
$datas->dataInsert = $insert;
$datas->fields = $this->initFieldList($model, $fields, false);
$datas->suhosinInfo = $suhosinInfo;
$datas->model = $model;
return $datas;
}
/**
* Update children datas.
*
@@ -1053,8 +1084,10 @@ class portModel extends model
* @access public
* @return void
*/
public function saveImportDatas($model, $datas)
public function saveImportDatas($model, $datas = '')
{
if(empty($datas)) $datas = $this->initPostFields($model);
foreach($datas as $key => $data)
{
$subDatas = array();
@@ -1135,4 +1168,41 @@ class portModel extends model
$modelConfig->listFields = isset($modelConfig->listFields) ? $modelConfig->listFields : $portConfig->listFields;
}
/**
* Read excel and format data .
*
* @param string $model
* @param int $pagerID
* @param int $maxImport
* @access public
* @return void
*/
public function readExcel($model = '', $pagerID = 1, $maxImport = 0)
{
/* Bulid import paris (field => name) .*/
$fields = $this->getImportFields('bug');
/* Check tmpfile. */
$tmpFile = $this->checkTmpFile();
/* If tmpfile not isset create tmpfile .*/
if(!$tmpFile)
{
$rows = $this->checkRowsFromExcel();
$bugData = $this->processRows4Fields($rows, $fields);
$bugData = $this->getNatureDatas('bug', $bugData);
$this->createTmpFile($bugData);
}
else
{
$bugData = $this->getDatasByFile($tmpFile);
}
/* Get page by datas.*/
return $this->getPageDatas($bugData, $pagerID, $maxImport);
}
}
+62 -54
View File
@@ -1,18 +1,30 @@
<?php
$title = $datas->title;
$requiredFields = $datas->requiredFields;
$allCount = $datas->allCount;
$allPager = $datas->allPager;
$pagerID = $datas->pagerID;
$isEndPage = $datas->isEndPage;
$maxImport = $datas->maxImport;
$dataInsert = $datas->dataInsert;
$fields = $datas->fields;
$suhosinInfo = $datas->suhosinInfo;
$model = $datas->model;
$datas = $datas->datas;
?>
<?php include $app->getModuleRoot() . 'common/view/header.html.php';?>
<style>
form{overflow-x: scroll}
.c-pri, .c-estStarted, .c-deadline{width:100px;}
.c-estimate {width:150px;}
.c-story{width:150px;}
.c-team {width:100px; padding:0px 0px 8px 0px !important;}
.c-estimate-1 {width:50px;padding:0px 0px 8px 8px !important;}
th {width:150px;}
.c-pri, .c-severity, .c-deadline, .c-openedBuild{width:100px;}
.c-steps {width:150px;}
</style>
<?php if(isset($suhosinInfo)):?>
<?php if(!empty($suhosinInfo)):?>
<div class='alert alert-info'><?php echo $suhosinInfo?></div>
<?php elseif(empty($maxImport) and $allCount > $this->config->file->maxImport):?>
<div id="mainContent" class="main-content">
<div class="main-header">
<h2><?php echo $lang->task->import;?></h2>
<h2><?php echo $lang->port->import;?></h2>
</div>
<p><?php echo sprintf($lang->file->importSummary, $allCount, html::input('maxImport', $config->file->maxImport, "style='width:50px'"), ceil($allCount / $config->file->maxImport));?></p>
<p><?php echo html::commonButton($lang->import, "id='import'", 'btn btn-primary');?></p>
@@ -24,49 +36,37 @@ $(function()
{
if(parseInt($('#maxImport').val())) $('#times').html(Math.ceil(parseInt($('#allCount').html()) / parseInt($('#maxImport').val())));
});
$('#import').click(function(){
$.cookie('maxImport', $('#maxImport').val());
location.href = "<?php echo $url;?>";
$('#import').click(function()
{
$.cookie('maxImport', $('#maxImport').val())
window.location.reload();
})
});
</script>
<?php else:?>
<?php js::set('requiredFields', $requiredFields);?>
<?php js::set('page', 'showImport');?>
<div id="mainContent" class="main-content">
<div class="main-header clearfix">
<h2><?php echo $lang->task->import;?></h2>
<h2><?php echo $lang->port->import;?></h2>
</div>
<form class='main-form' target='hiddenwin' method='post'>
<table class='table table-form' id='showData'>
<thead>
<tr>
<th class='w-70px'> <?php echo $lang->task->id?></th>
<th class='w-70px'> <?php echo $lang->port->id?></th>
<?php foreach($fields as $key => $value):?>
<?php if($value['control'] != 'hidden'):?>
<th class='c-<?php echo $key?>' id='<?php echo $key;?>'> <?php echo $value['title'];?></th>
<?php endif;?>
<?php endforeach;?>
<?php
if(!empty($appendFields))
{
foreach($appendFields as $field)
{
if(!$field->show) continue;
$width = ($field->width && $field->width != 'auto' ? $field->width . 'px' : 'auto');
$required = strpos(",$field->rules,", ",$notEmptyRule->id,") !== false ? 'required' : '';
echo "<th class='$required' style='width: $width'>$field->name</th>";
}
}
?>
</tr>
</thead>
<tbody>
<?php
$insert = true;
$addID = 1;
$hasMultiple = false;
$insert = true;
$addID = 1;
$colspan = 1;
?>
<?php foreach($datas as $key => $object):?>
<tr class='text-top'>
@@ -79,19 +79,24 @@ $(function()
}
else
{
$sub = (strpos($object->name, '>') === 0) ? " <sub style='vertical-align:sub;color:red'>{$lang->port->children}</sub>" : " <sub style='vertical-align:sub;color:gray'>{$lang->task->new}</sub>";
echo $addID++ . $sub;
echo $addID++ . " <sub style='vertical-align:sub;color:gray'>{$lang->port->new}</sub>";
}
?>
</td>
<?php foreach($fields as $field => $value):?>
<?php if(!isset($value['values'][''])) $value['values'][''] = '';?>
<?php if($value['control'] != 'hidden') $colspan ++?>
<?php if($value['control'] == 'select'):?>
<td><?php echo html::select("{$field}[$key]", $value['values'], !empty($object->$field) ? $object->$field : '', "class='form-control chosen'")?></td>
<?php $selected = !empty($object->$field) ? $object->$field : '';$list = array();?>
<?php if($value['values'][$selected]) $list = array($selected => $value['values'][$selected]);?>
<?php if(!$value['values'][$selected] and $value['values'][0]) $list = array_slice($value['values'], 0, 1);?>
<td><?php echo html::select("{$field}[$key]", $list, $selected, "class='form-control picker-select' data-field='{$field}' data-key='$key'")?></td>
<?php elseif($value['control'] == 'multiple'):?>
<?php if(!isset($value['values'][''])) $value['values'][''] = '';?>
<td><?php echo html::select("{$field}[$key][]", $value['values'], !empty($object->$field) ? $object->$field : '', "multiple class='form-control chosen'")?></td>
<td><?php echo html::select("{$field}[$key][]", $value['values'], !empty($object->$field) ? $object->$field : '', "class='form-control picker-select' data-field='{$field}' data-key='$key' multiple")?></td>
<?php elseif($value['control'] == 'date'):?>
<?php $dateMatch = $this->config->port->dateMatch;?>
@@ -112,27 +117,15 @@ $(function()
<?php endif;?>
<?php endforeach;?>
<?php
if(!empty($appendFields))
{
$this->loadModel('flow');
foreach($appendFields as $field)
{
if(!$field->show) continue;
$value = $field->defaultValue ? $field->defaultValue : zget($task, $field->field, '');
echo '<td>' . $this->flow->buildControl($field, $value, "$field->field[$key]", true) . '</td>';
}
}
?>
</tr>
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan='10' class='text-center form-actions'>
<td colspan='<?php echo $colspan;?>' class='text-center form-actions'>
<?php
$submitText = $isEndPage ? $this->lang->save : $this->lang->file->saveAndNext;
$isStartPage = $pagerID == 1 ? true : false;
$submitText = $isEndPage ? $this->lang->save : $this->lang->file->saveAndNext;
if(!$insert and $dataInsert === '')
{
echo "<button type='button' data-toggle='modal' data-target='#importNoticeModal' class='btn btn-primary btn-wide'>{$submitText}</button>";
@@ -144,7 +137,7 @@ $(function()
}
echo html::hidden('isEndPage', $isEndPage ? 1 : 0);
echo html::hidden('pagerID', $pagerID);
echo ' &nbsp; ' . html::a("javascript:history.back(-1)", $lang->goback, '', "class='btn btn-back btn-wide'");
echo html::a("javascript:history.back(-1)", $lang->goback, '', "class='btn btn-back btn-wide'");
echo ' &nbsp; ' . sprintf($lang->file->importPager, $allCount, $pagerID, $allPager);
?>
</td>
@@ -156,12 +149,27 @@ $(function()
</div>
<?php endif;?>
<script>
$.ajaxSetup({async: false});
$('#showData').on('mouseenter', '.picker', function(e){
var myPicker = $(this);
var field = myPicker.prev().attr('data-field');
var id = myPicker.prev().attr('id');
var index = myPicker.prev().attr('data-key');
var value = myPicker.prev().val();
if($('#' + id).attr('isInit')) return;
$.get(createLink('port', 'ajaxGetOptions', 'model=<?php echo $model;?>&field=' + field + '&value=' + value + '&index=' + index), function(data)
{
$('#' + id).parent().html(data);
$('#' + id).picker({chosenMode: true});
$('#' + id).attr('isInit', true);
});
})
$(function()
{
$.fixedTableHead('#showData');
<?php if($hasMultiple):?>
$('th.estimate').addClass('text-center w-250px');
<?php endif;?>
$("#showData th").each(function()
{
if(requiredFields.indexOf(this.id) !== -1) $("#" + this.id).addClass('required');