mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-04 08:17:24 -05:00
Improve user search display name (#29002)
I tripped over this strange method and I don't think we need that workaround to fix the value. old: ![grafik](https://github.com/go-gitea/gitea/assets/1666336/c8b6797b-eb45-4dec-99db-1b0649a34ec5) new: ![grafik](https://github.com/go-gitea/gitea/assets/1666336/ab1a65ae-de5b-4ce4-9813-3b8b39c7922e) --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
3a66762130
commit
c3e462921e
@ -11,14 +11,6 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RemoveUsernameParameterSuffix returns the username parameter without the (fullname) suffix - leaving just the username
|
|
||||||
func RemoveUsernameParameterSuffix(name string) string {
|
|
||||||
if index := strings.Index(name, " ("); index >= 0 {
|
|
||||||
name = name[:index]
|
|
||||||
}
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
|
|
||||||
// SanitizeFlashErrorString will sanitize a flash error string
|
// SanitizeFlashErrorString will sanitize a flash error string
|
||||||
func SanitizeFlashErrorString(x string) string {
|
func SanitizeFlashErrorString(x string) string {
|
||||||
return strings.ReplaceAll(html.EscapeString(x), "\n", "<br>")
|
return strings.ReplaceAll(html.EscapeString(x), "\n", "<br>")
|
||||||
|
@ -11,12 +11,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRemoveUsernameParameterSuffix(t *testing.T) {
|
|
||||||
assert.Equal(t, "foobar", RemoveUsernameParameterSuffix("foobar (Foo Bar)"))
|
|
||||||
assert.Equal(t, "foobar", RemoveUsernameParameterSuffix("foobar"))
|
|
||||||
assert.Equal(t, "", RemoveUsernameParameterSuffix(""))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestIsExternalURL(t *testing.T) {
|
func TestIsExternalURL(t *testing.T) {
|
||||||
setting.AppURL = "https://try.gitea.io/"
|
setting.AppURL = "https://try.gitea.io/"
|
||||||
type test struct {
|
type test struct {
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
"code.gitea.io/gitea/routers/utils"
|
|
||||||
shared_user "code.gitea.io/gitea/routers/web/shared/user"
|
shared_user "code.gitea.io/gitea/routers/web/shared/user"
|
||||||
"code.gitea.io/gitea/services/convert"
|
"code.gitea.io/gitea/services/convert"
|
||||||
"code.gitea.io/gitea/services/forms"
|
"code.gitea.io/gitea/services/forms"
|
||||||
@ -127,7 +126,7 @@ func TeamsAction(ctx *context.Context) {
|
|||||||
ctx.Error(http.StatusNotFound)
|
ctx.Error(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uname := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.FormString("uname")))
|
uname := strings.ToLower(ctx.FormString("uname"))
|
||||||
var u *user_model.User
|
var u *user_model.User
|
||||||
u, err = user_model.GetUserByName(ctx, uname)
|
u, err = user_model.GetUserByName(ctx, uname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,7 +17,6 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
repo_module "code.gitea.io/gitea/modules/repository"
|
repo_module "code.gitea.io/gitea/modules/repository"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/routers/utils"
|
|
||||||
"code.gitea.io/gitea/services/mailer"
|
"code.gitea.io/gitea/services/mailer"
|
||||||
org_service "code.gitea.io/gitea/services/org"
|
org_service "code.gitea.io/gitea/services/org"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
@ -52,7 +51,7 @@ func Collaboration(ctx *context.Context) {
|
|||||||
|
|
||||||
// CollaborationPost response for actions for a collaboration of a repository
|
// CollaborationPost response for actions for a collaboration of a repository
|
||||||
func CollaborationPost(ctx *context.Context) {
|
func CollaborationPost(ctx *context.Context) {
|
||||||
name := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.FormString("collaborator")))
|
name := strings.ToLower(ctx.FormString("collaborator"))
|
||||||
if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
|
if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
|
||||||
ctx.Redirect(setting.AppSubURL + ctx.Req.URL.EscapedPath())
|
ctx.Redirect(setting.AppSubURL + ctx.Req.URL.EscapedPath())
|
||||||
return
|
return
|
||||||
@ -144,7 +143,7 @@ func AddTeamPost(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
name := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.FormString("team")))
|
name := strings.ToLower(ctx.FormString("team"))
|
||||||
if len(name) == 0 {
|
if len(name) == 0 {
|
||||||
ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration")
|
ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration")
|
||||||
return
|
return
|
||||||
|
@ -196,10 +196,14 @@ a.label,
|
|||||||
.ui.search > .results {
|
.ui.search > .results {
|
||||||
background: var(--color-body);
|
background: var(--color-body);
|
||||||
border-color: var(--color-secondary);
|
border-color: var(--color-secondary);
|
||||||
|
overflow-wrap: anywhere; /* allow text to wrap as fomantic limits this to 18em width */
|
||||||
}
|
}
|
||||||
|
|
||||||
.ui.search > .results .result {
|
.ui.search > .results .result {
|
||||||
background: var(--color-body);
|
background: var(--color-body);
|
||||||
|
border-color: var(--color-secondary);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ui.search > .results .result .title {
|
.ui.search > .results .result .title {
|
||||||
|
@ -2128,14 +2128,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#search-user-box .results .result .image {
|
#search-user-box .results .result .image {
|
||||||
float: left;
|
order: 0;
|
||||||
margin-right: 8px;
|
margin-right: 12px;
|
||||||
width: 2em;
|
width: 2em;
|
||||||
height: 2em;
|
height: 2em;
|
||||||
|
min-width: 2em;
|
||||||
|
min-height: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#search-user-box .results .result .content {
|
#search-user-box .results .result .content {
|
||||||
margin: 6px 0; /* this trick is used to align with the sibling avatar image */
|
margin: 0; /* remove margin reserved for avatar because we move it to left via `order: 0` */
|
||||||
}
|
}
|
||||||
|
|
||||||
.ui.menu .item > img:not(.ui) {
|
.ui.menu .item > img:not(.ui) {
|
||||||
|
@ -17,14 +17,13 @@ export function initCompSearchUserBox() {
|
|||||||
const searchQuery = $searchUserBox.find('input').val();
|
const searchQuery = $searchUserBox.find('input').val();
|
||||||
const searchQueryUppercase = searchQuery.toUpperCase();
|
const searchQueryUppercase = searchQuery.toUpperCase();
|
||||||
$.each(response.data, (_i, item) => {
|
$.each(response.data, (_i, item) => {
|
||||||
let title = item.login;
|
|
||||||
if (item.full_name && item.full_name.length > 0) {
|
|
||||||
title += ` (${htmlEscape(item.full_name)})`;
|
|
||||||
}
|
|
||||||
const resultItem = {
|
const resultItem = {
|
||||||
title,
|
title: item.login,
|
||||||
image: item.avatar_url
|
image: item.avatar_url
|
||||||
};
|
};
|
||||||
|
if (item.full_name) {
|
||||||
|
resultItem.description = htmlEscape(item.full_name);
|
||||||
|
}
|
||||||
if (searchQueryUppercase === item.login.toUpperCase()) {
|
if (searchQueryUppercase === item.login.toUpperCase()) {
|
||||||
items.unshift(resultItem);
|
items.unshift(resultItem);
|
||||||
} else {
|
} else {
|
||||||
|
@ -52,9 +52,9 @@ export function initRepoSettingSearchTeamBox() {
|
|||||||
onResponse(response) {
|
onResponse(response) {
|
||||||
const items = [];
|
const items = [];
|
||||||
$.each(response.data, (_i, item) => {
|
$.each(response.data, (_i, item) => {
|
||||||
const title = `${item.name} (${item.permission} access)`;
|
|
||||||
items.push({
|
items.push({
|
||||||
title,
|
title: item.name,
|
||||||
|
description: `${item.permission} access` // TODO: translate this string
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user