From 65ce2f47299d3dbc3c27ec127d92526e1e32b393 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Mon, 7 Aug 2023 16:16:12 +0800 Subject: [PATCH] * Adjust bind user page style to be consistent with gitlab page. --- module/gitea/control.php | 44 +++++++++++++--- module/gitea/js/binduser.js | 24 +++++++++ module/gitea/model.php | 8 +-- module/gitea/view/binduser.html.php | 82 +++++++++++++++++------------ module/gogs/control.php | 44 +++++++++++++--- module/gogs/js/binduser.js | 24 +++++++++ module/gogs/model.php | 8 +-- module/gogs/view/binduser.html.php | 82 +++++++++++++++++------------ 8 files changed, 228 insertions(+), 88 deletions(-) create mode 100644 module/gitea/js/binduser.js create mode 100644 module/gogs/js/binduser.js diff --git a/module/gitea/control.php b/module/gitea/control.php index 4e4090360c..37969d7993 100644 --- a/module/gitea/control.php +++ b/module/gitea/control.php @@ -175,10 +175,11 @@ class gitea extends control * Bind gitea user to zentao users. * * @param int $giteaID + * @param string $type * @access public * @return void */ - public function bindUser($giteaID) + public function bindUser($giteaID, $type = 'all') { $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); $userPairs = $this->loadModel('user')->getPairs('noclosed|noletter'); @@ -190,11 +191,42 @@ class gitea extends control return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer)); } - $this->view->title = $this->lang->gitea->bindUser; - $this->view->userPairs = $userPairs; - $this->view->giteaUsers = $this->gitea->apiGetUsers($giteaID); - $this->view->bindedUsers = $this->gitea->getUserAccountIdPairs($giteaID); - $this->view->matchedResult = $this->gitea->getMatchedUsers($giteaID, $this->view->giteaUsers, $zentaoUsers); + $giteaUsers = $this->gitea->apiGetUsers($giteaID); + $bindedUsers = $this->gitea->getUserAccountIdPairs($giteaID); + $matchedResult = $this->gitea->getMatchedUsers($giteaID, $giteaUsers, $zentaoUsers); + + foreach($giteaUsers as $userID => &$user) + { + $user->binded = 0; + $user->zentaoUsers = array('' => ''); + $user->zentaoAccount = isset($matchedResult[$user->id]) ? $matchedResult[$user->id]->zentaoAccount : ''; + if($user->zentaoAccount) + { + $user->zentaoUsers += array($user->zentaoAccount => zget($userPairs, $user->zentaoAccount)); + if(isset($bindedUsers[$user->zentaoAccount]) && $bindedUsers[$user->zentaoAccount] == $user->id) + { + $user->binded = 1; + if(!isset($bindedUsers[$user->zentaoAccount])) $user->binded = 2; + } + } + + if($type == 'notBind' && $user->binded > 0) + { + unset($giteaUsers[$userID]); + } + elseif($type == 'binded' && $user->binded == 0) + { + unset($giteaUsers[$userID]); + } + + } + + $this->view->title = $this->lang->gitea->bindUser; + $this->view->userPairs = array('' => '') + $userPairs; + $this->view->giteaUsers = $giteaUsers; + $this->view->giteaID = $giteaID; + $this->view->type = $type; + $this->view->zentaoUsers = $zentaoUsers; $this->display(); } diff --git a/module/gitea/js/binduser.js b/module/gitea/js/binduser.js new file mode 100644 index 0000000000..014d06eeb1 --- /dev/null +++ b/module/gitea/js/binduser.js @@ -0,0 +1,24 @@ +$(document).ready(function() +{ + $('.gitlab-user-bind').change(function() + { + var user = zentaoUsers[$(this).val()]; + if(user !== undefined) + { + $(this).parent().parent().find('.email').text(user.email) + } + }); + + $(document).on('click', '.zentao-users .chosen-container', function() + { + var $obj = $(this).prev('select'); + var value = $obj.val(); + if($obj.hasClass('filled')) return false; + + $obj.empty(); + $obj.append($('#userList').html()); + $obj.val(value); + $obj.addClass('filled'); + $obj.trigger("chosen:updated"); + }) +}); diff --git a/module/gitea/model.php b/module/gitea/model.php index 06782ea84f..33cf575853 100644 --- a/module/gitea/model.php +++ b/module/gitea/model.php @@ -342,8 +342,8 @@ class giteaModel extends model { if(isset($bindedUsers[$giteaUser->account])) { - $giteaUser->zentaoAccount = $bindedUsers[$giteaUser->account]; - $matchedUsers[] = $giteaUser; + $giteaUser->zentaoAccount = $bindedUsers[$giteaUser->account]; + $matchedUsers[$giteaUser->id] = $giteaUser; continue; } @@ -355,8 +355,8 @@ class giteaModel extends model $matchedZentaoUsers = array_unique($matchedZentaoUsers); if(count($matchedZentaoUsers) == 1) { - $giteaUser->zentaoAccount = current($matchedZentaoUsers); - $matchedUsers[] = $giteaUser; + $giteaUser->zentaoAccount = current($matchedZentaoUsers); + $matchedUsers[$giteaUser->id] = $giteaUser; } } diff --git a/module/gitea/view/binduser.html.php b/module/gitea/view/binduser.html.php index bac7b14aae..96f9ea3d88 100644 --- a/module/gitea/view/binduser.html.php +++ b/module/gitea/view/binduser.html.php @@ -11,60 +11,66 @@ */ ?> +createLink('gitea', 'browse', ""); ?> +
-
-

gitea->bindUser;?>

+
+ ' . $lang->goback, $browseLink, 'self', "data-app='{$app->tab}'", 'btn btn-secondary'); + + $allLink = $this->createLink('gitea', 'binduser', "giteaID={$giteaID}&type=all"); + $bindedLink = $this->createLink('gitea', 'binduser', "giteaID={$giteaID}&type=binded"); + $notBindLink = $this->createLink('gitea', 'binduser', "giteaID={$giteaID}&type=notBind"); + if($type == 'all') + { + echo html::linkButton('' . $lang->gitea->all . "" . count($giteaUsers) . "", $allLink, 'self', "data-app='{$app->tab}'", 'btn btn-info active'); + echo html::linkButton('' . $lang->gitea->notBind, $notBindLink, 'self', "data-app='{$app->tab}'", 'btn btn-info'); + echo html::linkButton('' . $lang->gitea->binded, $bindedLink, 'self', "data-app='{$app->tab}'", 'btn btn-info'); + } + else if($type == 'binded') + { + echo html::linkButton('' . $lang->gitea->all, $allLink, 'self', "data-app='{$app->tab}'", 'btn btn-info'); + echo html::linkButton('' . $lang->gitea->notBind, $notBindLink, 'self', "data-app='{$app->tab}'", 'btn btn-info'); + echo html::linkButton('' . $lang->gitea->binded . "" . count($giteaUsers) . "", $bindedLink, 'self', "data-app='{$app->tab}'", 'btn btn-info active'); + } + else + { + echo html::linkButton('' . $lang->gitea->all, $allLink, 'self', "data-app='{$app->tab}'", 'btn btn-info'); + echo html::linkButton('' . $lang->gitea->notBind . "" . count($giteaUsers) . "", $notBindLink, 'self', "data-app='{$app->tab}'", 'btn btn-info active'); + echo html::linkButton('' . $lang->gitea->binded, $bindedLink, 'self', "data-app='{$app->tab}'", 'btn btn-info'); + } + ?>
- +
- - + + - zentaoAccount)) continue;?> - account]", $giteaUser->realname);?> + id]", $giteaUser->realname);?> - - - - - - - - zentaoAccount)) continue;?> - account]", $giteaUser->realname);?> - - + + - - - @@ -82,4 +88,12 @@ + diff --git a/module/gogs/control.php b/module/gogs/control.php index b0c57072ff..de711ca7a2 100644 --- a/module/gogs/control.php +++ b/module/gogs/control.php @@ -174,10 +174,11 @@ class gogs extends control * Bind gogs user to zentao users. * * @param int $gogsID + * @param string $type * @access public * @return void */ - public function bindUser($gogsID) + public function bindUser($gogsID, $type = 'all') { $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); $userPairs = $this->loadModel('user')->getPairs('noclosed|noletter'); @@ -189,11 +190,42 @@ class gogs extends control return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer)); } - $this->view->title = $this->lang->gogs->bindUser; - $this->view->userPairs = $userPairs; - $this->view->gogsUsers = $this->gogs->apiGetUsers($gogsID); - $this->view->bindedUsers = $this->gogs->getUserAccountIdPairs($gogsID); - $this->view->matchedResult = $this->gogs->getMatchedUsers($gogsID, $this->view->gogsUsers, $zentaoUsers); + $gogsUsers = $this->gogs->apiGetUsers($gogsID); + $bindedUsers = $this->gogs->getUserAccountIdPairs($gogsID); + $matchedResult = $this->gogs->getMatchedUsers($gogsID, $gogsUsers, $zentaoUsers); + + foreach($gogsUsers as $userID => &$user) + { + $user->binded = 0; + $user->zentaoUsers = array('' => ''); + $user->zentaoAccount = isset($matchedResult[$user->id]) ? $matchedResult[$user->id]->zentaoAccount : ''; + if($user->zentaoAccount) + { + $user->zentaoUsers += array($user->zentaoAccount => zget($userPairs, $user->zentaoAccount)); + if(isset($bindedUsers[$user->zentaoAccount]) && $bindedUsers[$user->zentaoAccount] == $user->id) + { + $user->binded = 1; + if(!isset($bindedUsers[$user->zentaoAccount])) $user->binded = 2; + } + } + + if($type == 'notBind' && $user->binded > 0) + { + unset($gogsUsers[$userID]); + } + elseif($type == 'binded' && $user->binded == 0) + { + unset($gogsUsers[$userID]); + } + + } + + $this->view->title = $this->lang->gogs->bindUser; + $this->view->userPairs = array('' => '') + $userPairs; + $this->view->gogsUsers = $gogsUsers; + $this->view->gogsID = $gogsID; + $this->view->type = $type; + $this->view->zentaoUsers = $zentaoUsers; $this->display(); } diff --git a/module/gogs/js/binduser.js b/module/gogs/js/binduser.js new file mode 100644 index 0000000000..014d06eeb1 --- /dev/null +++ b/module/gogs/js/binduser.js @@ -0,0 +1,24 @@ +$(document).ready(function() +{ + $('.gitlab-user-bind').change(function() + { + var user = zentaoUsers[$(this).val()]; + if(user !== undefined) + { + $(this).parent().parent().find('.email').text(user.email) + } + }); + + $(document).on('click', '.zentao-users .chosen-container', function() + { + var $obj = $(this).prev('select'); + var value = $obj.val(); + if($obj.hasClass('filled')) return false; + + $obj.empty(); + $obj.append($('#userList').html()); + $obj.val(value); + $obj.addClass('filled'); + $obj.trigger("chosen:updated"); + }) +}); diff --git a/module/gogs/model.php b/module/gogs/model.php index 15d63c1f58..db7c56326c 100644 --- a/module/gogs/model.php +++ b/module/gogs/model.php @@ -298,8 +298,8 @@ class gogsModel extends model { if(isset($bindedUsers[$gogsUser->account])) { - $gogsUser->zentaoAccount = $bindedUsers[$gogsUser->account]; - $matchedUsers[] = $gogsUser; + $gogsUser->zentaoAccount = $bindedUsers[$gogsUser->account]; + $matchedUsers[$giteaUser->id] = $gogsUser; continue; } @@ -311,8 +311,8 @@ class gogsModel extends model $matchedZentaoUsers = array_unique($matchedZentaoUsers); if(count($matchedZentaoUsers) == 1) { - $gogsUser->zentaoAccount = current($matchedZentaoUsers); - $matchedUsers[] = $gogsUser; + $gogsUser->zentaoAccount = current($matchedZentaoUsers); + $matchedUsers[$giteaUser->id] = $gogsUser; } } diff --git a/module/gogs/view/binduser.html.php b/module/gogs/view/binduser.html.php index c9d68f3527..875d08bfc6 100644 --- a/module/gogs/view/binduser.html.php +++ b/module/gogs/view/binduser.html.php @@ -11,60 +11,66 @@ */ ?> +createLink('gogs', 'browse', ""); ?> +
-
-

gogs->bindUser;?>

+
+ ' . $lang->goback, $browseLink, 'self', "data-app='{$app->tab}'", 'btn btn-secondary'); + + $allLink = $this->createLink('gogs', 'binduser', "gogsID={$gogsID}&type=all"); + $bindedLink = $this->createLink('gogs', 'binduser', "gogsID={$gogsID}&type=binded"); + $notBindLink = $this->createLink('gogs', 'binduser', "gogsID={$gogsID}&type=notBind"); + if($type == 'all') + { + echo html::linkButton('' . $lang->gogs->all . "" . count($gogsUsers) . "", $allLink, 'self', "data-app='{$app->tab}'", 'btn btn-info active'); + echo html::linkButton('' . $lang->gogs->notBind, $notBindLink, 'self', "data-app='{$app->tab}'", 'btn btn-info'); + echo html::linkButton('' . $lang->gogs->binded, $bindedLink, 'self', "data-app='{$app->tab}'", 'btn btn-info'); + } + else if($type == 'binded') + { + echo html::linkButton('' . $lang->gogs->all, $allLink, 'self', "data-app='{$app->tab}'", 'btn btn-info'); + echo html::linkButton('' . $lang->gogs->notBind, $notBindLink, 'self', "data-app='{$app->tab}'", 'btn btn-info'); + echo html::linkButton('' . $lang->gogs->binded . "" . count($gogsUsers) . "", $bindedLink, 'self', "data-app='{$app->tab}'", 'btn btn-info active'); + } + else + { + echo html::linkButton('' . $lang->gogs->all, $allLink, 'self', "data-app='{$app->tab}'", 'btn btn-info'); + echo html::linkButton('' . $lang->gogs->notBind . "" . count($gogsUsers) . "", $notBindLink, 'self', "data-app='{$app->tab}'", 'btn btn-info active'); + echo html::linkButton('' . $lang->gogs->binded, $bindedLink, 'self', "data-app='{$app->tab}'", 'btn btn-info'); + } + ?>
-
gitea->giteaAvatar;?> gitea->giteaAccount;?> gitea->giteaEmail;?>gitea->zentaoAccount;?>gitea->zentaoEmail;?>gitea->zentaoAccount;?> gitea->bindingStatus;?>
avatar, "height=40");?> - realname;?> -
- account;?> +
+ avatar, "height=20 width=20 class='img-circle'");?> + realname . '@' . $giteaUser->account;?> email;?>account]", $userPairs, '', "class='form-control select chosen'" );?>gitea->notBind;?>
avatar, "height=40");?>id]", $giteaUser->zentaoUsers, $giteaUser->zentaoAccount, "class='form-control select chosen gitea-user-bind'" );?> - realname;?> -
- account;?> -
email;?>account]", $userPairs, $giteaUser->zentaoAccount, "class='form-control select chosen'" );?> - zentaoAccount])):?> - zentaoAccount, '');?> - + binded === 1):?> gitea->binded;?> - + binded === 2):?> ' . $lang->gitea->bindedError . '';?> - - gitea->notBind;?> + ' . $lang->gitea->notBind . '';?>
+
- - + + - zentaoAccount)) continue;?> - account]", $gogsUser->realname);?> + id]", $gogsUser->realname);?> - - - - - - - - zentaoAccount)) continue;?> - account]", $gogsUser->realname);?> - - + + - - - @@ -82,4 +88,12 @@ +
gogs->gogsAvatar;?> gogs->gogsAccount;?> gogs->gogsEmail;?>gogs->zentaoAccount;?>gogs->zentaoEmail;?>gogs->zentaoAccount;?> gogs->bindingStatus;?>
avatar, "height=40");?> - realname;?> -
- account;?> +
+ avatar, "height=20 width=20 class='img-circle'");?> + realname . '@' . $gogsUser->account;?> email;?>account]", $userPairs, '', "class='form-control select chosen'" );?>gogs->notBind;?>
avatar, "height=40");?>id]", $gogsUser->zentaoUsers, $gogsUser->zentaoAccount, "class='form-control select chosen gogs-user-bind'" );?> - realname;?> -
- account;?> -
email;?>account]", $userPairs, $gogsUser->zentaoAccount, "class='form-control select chosen'" );?> - zentaoAccount])):?> - zentaoAccount, '');?> - + binded === 1):?> gogs->binded;?> - + binded === 2):?> ' . $lang->gogs->bindedError . '';?> - - gogs->notBind;?> + ' . $lang->gogs->notBind . '';?>