* Adjust display style.

This commit is contained in:
dingguodong
2021-06-15 16:36:57 +08:00
parent 8ff0636eac
commit 50a934f3c4
4 changed files with 48 additions and 81 deletions

View File

@@ -24,8 +24,6 @@ class gitlab extends control
*/ */
public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{ {
if(common::hasPriv('gitlab', 'create')) $this->lang->TRActions = html::a(helper::createLink('gitlab', 'create'), "<i class='icon icon-plus'></i> " . $this->lang->gitlab->create, '', "class='btn btn-primary'");
$this->app->loadClass('pager', $static = true); $this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID); $pager = new pager($recTotal, $recPerPage, $pageID);
@@ -50,12 +48,18 @@ class gitlab extends control
{ {
if($_POST) if($_POST)
{ {
$tokenValid = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token); if(strpos($host, 'http') !== 0) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError))));
if($tokenValid['result'] == 'fail') $this->send($tokenValid); if(!$this->post->token) $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError))));
$user = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token);
if(!is_object($user)) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError))));
if(isset($user->is_admin) and $user->is_admin == true) $this->send(array('result' => 'success'));
$this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError))));
$gitlabID = $this->gitlab->create(); $gitlabID = $this->gitlab->create();
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $gitlabID));
$this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
} }
@@ -76,10 +80,11 @@ class gitlab extends control
public function bindUser($id) public function bindUser($id)
{ {
$gitlab = $this->gitlab->getByID($id); $gitlab = $this->gitlab->getByID($id);
$this->view->title = $this->lang->gitlab->bind; $this->view->title = $this->lang->gitlab->bindUser;
$this->view->zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account');
$this->view->gitlabUsers = $this->gitlab->apiGetUsers($gitlab); $this->view->userPairs = $this->loadModel('user')->getPairs();
$this->view->matchedInfo = $this->gitlab->getMatchedUsers($this->view->gitlabUsers); $this->view->gitlabUsers = $this->gitlab->apiGetUsers($gitlab);
$this->view->matchedResult = $this->gitlab->getMatchedUsers($this->view->gitlabUsers, $zentaoUsers);
$this->display(); $this->display();
} }

View File

@@ -4,9 +4,11 @@ $lang->gitlab->common = 'Gitlab';
$lang->gitlab->browse = '浏览gitlab'; $lang->gitlab->browse = '浏览gitlab';
$lang->gitlab->create = '添加gitlab'; $lang->gitlab->create = '添加gitlab';
$lang->gitlab->edit = '编辑gitlab'; $lang->gitlab->edit = '编辑gitlab';
$lang->gitlab->bind = '绑定用户'; $lang->gitlab->bindUser = '绑定用户';
$lang->gitlab->delete = '删除'; $lang->gitlab->delete = '删除';
$lang->gitlab->confirmDelete = '确认删除该gitlab吗'; $lang->gitlab->confirmDelete = '确认删除该gitlab吗';
$lang->gitlab->gitlabAccount = 'gitlab用户';
$lang->gitlab->zentaoAccount = '禅道用户';
$lang->gitlab->browseAction = 'gitlab列表'; $lang->gitlab->browseAction = 'gitlab列表';
$lang->gitlab->deleteAction = '删除gitlab'; $lang->gitlab->deleteAction = '删除gitlab';

View File

@@ -80,14 +80,8 @@ class gitlabModel extends model
*/ */
public function apiGetCurrentUser($host, $token) public function apiGetCurrentUser($host, $token)
{ {
if(strpos($host, 'http') !== 0) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)));
if(!$this->post->token) return array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)));
$api = rtrim($host, '/') . "/api/v4/user?private_token=$token"; $api = rtrim($host, '/') . "/api/v4/user?private_token=$token";
$response = json_decode(commonModel::http($api)); return json_decode(commonModel::http($api));
if(!is_object($response)) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)));
if(isset($response->is_admin) and $response->is_admin == true) return array('result' => 'success');
return array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)));
} }
/** /**
@@ -114,17 +108,15 @@ class gitlabModel extends model
$user->realname = $gitlabUser->name; $user->realname = $gitlabUser->name;
$user->account = $gitlabUser->username; $user->account = $gitlabUser->username;
$user->email = $gitlabUser->email; $user->email = $gitlabUser->email;
$user->avatar = $gitlabUser->avatar_url;
$users[] = $user; $users[] = $user;
} }
a($users);
return $users; return $users;
} }
public function getMatchedUsers($gitlabUsers) public function getMatchedUsers($gitlabUsers, $zentaoUsers)
{ {
$zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account');
$matches = new stdclass; $matches = new stdclass;
foreach($gitlabUsers as $gitlabUser) foreach($gitlabUsers as $gitlabUser)
{ {
@@ -136,7 +128,8 @@ class gitlabModel extends model
} }
} }
foreach($gitlabUser as $gitlabUser) $matchedUsers = array();
foreach($gitlabUsers as $gitlabUser)
{ {
$matchedZentaoUsers = array(); $matchedZentaoUsers = array();
if(isset($matches->accounts[$gitlabUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$gitlabUser->account]); if(isset($matches->accounts[$gitlabUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$gitlabUser->account]);
@@ -146,15 +139,11 @@ class gitlabModel extends model
$matchedZentaoUsers = array_unique($matchedZentaoUsers); $matchedZentaoUsers = array_unique($matchedZentaoUsers);
if(count($matchedZentaoUsers) == 1) if(count($matchedZentaoUsers) == 1)
{ {
$matchedUsers[$gitlabUser->id] = current($matchedZentaoUsers); $gitlabUser->zentaoAccount = current($matchedZentaoUsers);
} $matchedUsers[] = $gitlabUser;
else
{
$unmatchedUsers[$gitlabUser->id] = $gitlabUser;
} }
} }
return $matchedUsers;
return array('matched' => $matchedUsers, 'unmatched' => $unmatchedUsers);
} }
/** /**

View File

@@ -17,20 +17,35 @@
</div> </div>
<form method='post' class='load-indicator main-form' enctype='multipart/form-data' target='hiddenwin' id="batchCreateForm"> <form method='post' class='load-indicator main-form' enctype='multipart/form-data' target='hiddenwin' id="batchCreateForm">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-form"> <table class="table table-form w-500px">
<thead> <thead>
<tr> <tr>
<th class='col-id'><?php echo $lang->gitlab->gitlabAccount;?></th> <th class='w-150px'><?php echo $lang->gitlab->gitlabAccount;?></th>
<th class='col-id'><?php echo $lang->gitlab->zentaoAccount;?></th> <th class='w-150px'><?php echo $lang->gitlab->zentaoAccount;?></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach($gitlabUsers as $gitlabUser):?> <?php foreach($gitlabUsers as $gitlabUser):?>
<?php <?php if(isset($gitlabUser->zentaoAccount)) continue;?>
?> <tr>
<tr class="template"> <td>
<td>$idPlus</td> <?php echo html::image($gitlabUser->avatar, "height=40");?>
<td class='text-left<?php echo zget($visibleFields, $product->type, ' hidden')?>'><?php echo html::select('branch[$id]', $branches, $branch, "class='form-control chosen' onchange='setModuleAndPlan(this.value, $productID, \$id)'");?></td> <strong>
<?php echo html::hidden('gitlabUsers[]', $gitlabUser->id) . $gitlabUser->realname;?>
<br><?php echo "(" . $gitlabUser->account . ") &lt;" . $gitlabUser->email . "&gt;"; ?>
</strong>
</td>
<td><?php echo html::select('zentaoUsers[]', $userPairs, '', "class='form-control select chosen'" );?></td>
</tr>
<?php endforeach;?>
<?php foreach($gitlabUsers as $gitlabUser):?>
<?php if(!isset($gitlabUser->zentaoAccount)) continue;?>
<tr>
<td>
<strong><?php echo html::hidden('gitlabUsers[]', $gitlabUser->id) . $gitlabUser->realname;?></strong>
<p><?php echo "(" . $gitlabUser->account . ") &lt;" . $gitlabUser->email . "&gt;"; ?></p>
</td>
<td><?php echo html::select('zentaoUsers[]', $userPairs, $gitlabUser->zentaoAccount, "class='form-control select chosen'" );?></td>
</tr> </tr>
<?php endforeach;?> <?php endforeach;?>
</tbody> </tbody>
@@ -46,48 +61,4 @@
</div> </div>
</form> </form>
</div> </div>
<script>
$(function()
{
var imageTitles = <?php echo empty($titles) ? '""' : json_encode($titles);?>;
var storyTitles = <?php echo empty($titles) ? '""' : json_encode(array_keys($titles));?>;
$('#batchCreateForm').batchActionForm(
{
idEnd: <?php echo max((empty($titles) ? 0 : count($titles)), 9)?>,
rowCreator: function($row, index)
{
$row.find('select.chosen,select.picker-select').each(function()
{
var $select = $(this);
if($select.hasClass('picker-select')) $select.parent().find('.picker').remove();
if(index == 0) $select.find("option[value='ditto']").remove();
if(index > 0) $select.val('ditto');
if($select.attr('id').indexOf('branch') >= 0) $select.val('<?php echo $branch;?>')
$select.chosen();
setTimeout(function()
{
$select.next('.chosen-container').find('.chosen-drop').width($select.closest('td').width() + 50);
}, 200);
});
var storyTitle = storyTitles && storyTitles[index];
if (storyTitle !== undefined && storyTitle !== null)
{
$row.find('.input-story-title').val(storyTitle).after('<input type="hidden" name="uploadImage[' + index + ']" id="uploadImage[' + index + ']" value="' + imageTitles[storyTitle] + '">');
}
}
});
$(document).on('change', "#mainContent select[name^=needReview]", function()
{
select = $(this).parent('td').next('td').children("select[name^=reviewer]");
$(select).removeAttr('disabled');
if($(this).val() == 0) $(select).attr('disabled', 'disabled');
$(select).trigger("chosen:updated");
})
});
</script>
<?php if(isset($execution)) js::set('execution', $execution);?>
<?php js::set('storyType', $type);?>
<?php include '../../common/view/pastetext.html.php';?>
<?php include '../../common/view/footer.html.php';?> <?php include '../../common/view/footer.html.php';?>