mirror of
https://gitea.com/gitea/gitea-mirror.git
synced 2026-03-20 11:50:27 +00:00
fix(repo): unify DEFAULT_SHOW_FULL_NAME output in templates and dropdown (#36597)
The design of DefaultShowFullName has some problems, which make the UI inconsistent, see the new comment in code This PR does a clean up for various legacy problems, and clarify some "user name display" behaviors. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -6,13 +6,14 @@ package repo
|
||||
import (
|
||||
"bytes"
|
||||
"html"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/avatars"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
"code.gitea.io/gitea/modules/htmlutil"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/templates"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
|
||||
@@ -53,29 +54,25 @@ func GetContentHistoryList(ctx *context.Context) {
|
||||
// value is historyId
|
||||
var results []map[string]any
|
||||
for _, item := range items {
|
||||
var actionText string
|
||||
var actionHTML template.HTML
|
||||
if item.IsDeleted {
|
||||
actionTextDeleted := ctx.Locale.TrString("repo.issues.content_history.deleted")
|
||||
actionText = "<i data-history-is-deleted='1'>" + actionTextDeleted + "</i>"
|
||||
actionHTML = htmlutil.HTMLFormat(`<i data-history-is-deleted="1">%s</i>`, ctx.Locale.TrString("repo.issues.content_history.deleted"))
|
||||
} else if item.IsFirstCreated {
|
||||
actionText = ctx.Locale.TrString("repo.issues.content_history.created")
|
||||
actionHTML = ctx.Locale.Tr("repo.issues.content_history.created")
|
||||
} else {
|
||||
actionText = ctx.Locale.TrString("repo.issues.content_history.edited")
|
||||
actionHTML = ctx.Locale.Tr("repo.issues.content_history.edited")
|
||||
}
|
||||
|
||||
username := item.UserName
|
||||
if setting.UI.DefaultShowFullName && strings.TrimSpace(item.UserFullName) != "" {
|
||||
username = strings.TrimSpace(item.UserFullName)
|
||||
var fullNameHTML template.HTML
|
||||
userName, fullName := item.UserName, strings.TrimSpace(item.UserFullName)
|
||||
if fullName != "" {
|
||||
fullNameHTML = htmlutil.HTMLFormat(` (<span class="tw-inline-flex tw-max-w-[160px]"><span class="gt-ellipsis">%s</span></span>)`, fullName)
|
||||
}
|
||||
|
||||
src := html.EscapeString(item.UserAvatarLink)
|
||||
class := avatars.DefaultAvatarClass + " tw-mr-2"
|
||||
name := html.EscapeString(username)
|
||||
avatarHTML := string(templates.AvatarHTML(src, 28, class, username))
|
||||
timeSinceHTML := string(templates.TimeSince(item.EditedUnix))
|
||||
|
||||
avatarHTML := templates.AvatarHTML(item.UserAvatarLink, 24, avatars.DefaultAvatarClass+" tw-mr-2", userName)
|
||||
timeSinceHTML := templates.TimeSince(item.EditedUnix)
|
||||
results = append(results, map[string]any{
|
||||
"name": avatarHTML + "<strong>" + name + "</strong> " + actionText + " " + timeSinceHTML,
|
||||
"name": htmlutil.HTMLFormat("%s <strong>%s</strong>%s %s %s", avatarHTML, userName, fullNameHTML, actionHTML, timeSinceHTML),
|
||||
"value": item.HistoryID,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
shared_user "code.gitea.io/gitea/routers/web/shared/user"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
)
|
||||
@@ -34,7 +33,7 @@ func IssuePullPosters(ctx *context.Context) {
|
||||
func issuePosters(ctx *context.Context, isPullList bool) {
|
||||
repo := ctx.Repo.Repository
|
||||
search := strings.TrimSpace(ctx.FormString("q"))
|
||||
posters, err := repo_model.GetIssuePostersWithSearch(ctx, repo, isPullList, search, setting.UI.DefaultShowFullName)
|
||||
posters, err := repo_model.GetIssuePostersWithSearch(ctx, repo, isPullList, search)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
@@ -54,9 +53,7 @@ func issuePosters(ctx *context.Context, isPullList bool) {
|
||||
resp.Results = make([]*userSearchInfo, len(posters))
|
||||
for i, user := range posters {
|
||||
resp.Results[i] = &userSearchInfo{UserID: user.ID, UserName: user.Name, AvatarLink: user.AvatarLink(ctx)}
|
||||
if setting.UI.DefaultShowFullName {
|
||||
resp.Results[i].FullName = user.FullName
|
||||
}
|
||||
resp.Results[i].FullName = user.FullName
|
||||
}
|
||||
ctx.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user