From 2854ddfa011069f087e6bca6ec665db40b88fb0b Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 1 Feb 2024 01:29:54 +0000 Subject: [PATCH 1/5] fix --- routers/web/shared/user/header.go | 7 ++++ routers/web/user/profile.go | 16 +++++++-- templates/org/home.tmpl | 35 +----------------- .../shared/user/org_profile_big_avatar.tmpl | 36 +++++++++++++++++++ 4 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 templates/shared/user/org_profile_big_avatar.tmpl diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go index a2c0abb47e4a1..697fcd01837f9 100644 --- a/routers/web/shared/user/header.go +++ b/routers/web/shared/user/header.go @@ -30,6 +30,13 @@ func prepareContextForCommonProfile(ctx *context.Context) { ctx.Data["FeedURL"] = ctx.ContextUser.HomeLink() } +// PrepareContextForProfileBigAvatar set the context for big avatar view on the org profile page +func PrepareContextForOrgProfileBigAvatar(ctx *context.Context) { + prepareContextForCommonProfile(ctx) + + ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID) +} + // PrepareContextForProfileBigAvatar set the context for big avatar view on the profile page func PrepareContextForProfileBigAvatar(ctx *context.Context) { prepareContextForCommonProfile(ctx) diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 73ab93caed5a5..c26775bc553c3 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -28,7 +28,8 @@ import ( ) const ( - tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar" + tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar" + tplOrgProfileBigAvatar base.TplName = "shared/user/org_profile_big_avatar" ) // OwnerProfile render profile page for a user or a organization (aka, repo owner) @@ -318,6 +319,15 @@ func Action(ctx *context.Context) { return } - shared_user.PrepareContextForProfileBigAvatar(ctx) - ctx.HTML(http.StatusOK, tplProfileBigAvatar) + if ctx.ContextUser.IsIndividual() { + shared_user.PrepareContextForProfileBigAvatar(ctx) + ctx.HTML(http.StatusOK, tplProfileBigAvatar) + return + } else if ctx.ContextUser.IsOrganization() { + shared_user.PrepareContextForOrgProfileBigAvatar(ctx) + ctx.HTML(http.StatusOK, tplOrgProfileBigAvatar) + return + } + log.Error("Failed to apply action %q: unsupport context user type: %s", ctx.FormString("action"), ctx.ContextUser.Type) + ctx.Error(http.StatusBadRequest, fmt.Sprintf("Action %q failed", ctx.FormString("action"))) } diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index fc65d4691cbe7..63c2801686373 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -1,39 +1,6 @@ {{template "base/head" .}}
-
- {{ctx.AvatarUtils.Avatar .Org 140 "org-avatar"}} -
-
- {{.Org.DisplayName}} - - {{if .Org.Visibility.IsLimited}}{{ctx.Locale.Tr "org.settings.visibility.limited_shortname"}}{{end}} - {{if .Org.Visibility.IsPrivate}}{{ctx.Locale.Tr "org.settings.visibility.private_shortname"}}{{end}} - -
- {{if $.RenderedDescription}}
{{$.RenderedDescription|Str2html}}
{{end}} -
- {{if .Org.Location}}
{{svg "octicon-location"}} {{.Org.Location}}
{{end}} - {{if .Org.Website}}
{{svg "octicon-link"}} {{.Org.Website}}
{{end}} - {{if $.IsSigned}} - {{if .Org.Email}}
{{svg "octicon-mail"}} {{.Org.Email}}
{{end}} - {{end}} -
-
- -
+ {{template "shared/user/org_profile_big_avatar" .}} {{template "org/menu" .}} diff --git a/templates/shared/user/org_profile_big_avatar.tmpl b/templates/shared/user/org_profile_big_avatar.tmpl new file mode 100644 index 0000000000000..b2a1b412884d1 --- /dev/null +++ b/templates/shared/user/org_profile_big_avatar.tmpl @@ -0,0 +1,36 @@ +
+ {{ctx.AvatarUtils.Avatar .ContextUser 140 "org-avatar"}} +
+
+ {{.ContextUser.DisplayName}} + + {{if .ContextUser.Visibility.IsLimited}}{{ctx.Locale.Tr "org.settings.visibility.limited_shortname"}}{{end}} + {{if .ContextUser.Visibility.IsPrivate}}{{ctx.Locale.Tr "org.settings.visibility.private_shortname"}}{{end}} + +
+ {{if $.RenderedDescription}}
{{$.RenderedDescription|Str2html}}
{{end}} +
+ {{if .ContextUser.Location}}
{{svg "octicon-location"}} {{.ContextUser.Location}}
{{end}} + {{if .ContextUser.Website}}
{{svg "octicon-link"}} {{.ContextUser.Website}}
{{end}} + {{if $.IsSigned}} + {{if .ContextUser.Email}}
{{svg "octicon-mail"}} {{.ContextUser.Email}}
{{end}} + {{end}} +
+
+ +
\ No newline at end of file From 1a17ca723a750a6973539188410a26444e7ba82c Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 1 Feb 2024 01:49:02 +0000 Subject: [PATCH 2/5] fix Description --- routers/web/org/home.go | 14 ++------------ routers/web/shared/user/header.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 8bf02b2c42a74..7e9022aee229a 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -20,6 +20,7 @@ import ( "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/routers/web/shared/user" shared_user "code.gitea.io/gitea/routers/web/shared/user" ) @@ -41,22 +42,11 @@ func Home(ctx *context.Context) { if ctx.Written() { return } - + user.PrepareContextForOrgProfileBigAvatar(ctx) org := ctx.Org.Organization ctx.Data["PageIsUserProfile"] = true ctx.Data["Title"] = org.DisplayName() - if len(org.Description) != 0 { - desc, err := markdown.RenderString(&markup.RenderContext{ - Ctx: ctx, - Metas: map[string]string{"mode": "document"}, - }, org.Description) - if err != nil { - ctx.ServerError("RenderString", err) - return - } - ctx.Data["RenderedDescription"] = desc - } var orderBy db.SearchOrderBy ctx.Data["SortType"] = ctx.FormString("sort") diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go index 697fcd01837f9..1c0d01b3a9aed 100644 --- a/routers/web/shared/user/header.go +++ b/routers/web/shared/user/header.go @@ -35,6 +35,18 @@ func PrepareContextForOrgProfileBigAvatar(ctx *context.Context) { prepareContextForCommonProfile(ctx) ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID) + + if len(ctx.ContextUser.Description) != 0 { + desc, err := markdown.RenderString(&markup.RenderContext{ + Ctx: ctx, + Metas: map[string]string{"mode": "document"}, + }, ctx.ContextUser.Description) + if err != nil { + ctx.ServerError("RenderString", err) + return + } + ctx.Data["RenderedDescription"] = desc + } } // PrepareContextForProfileBigAvatar set the context for big avatar view on the profile page From f06f4581856f660513d741badf65d12d5039d14e Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 1 Feb 2024 02:15:33 +0000 Subject: [PATCH 3/5] fix lint --- routers/web/org/home.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 7e9022aee229a..495c6a95dcf9c 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -20,7 +20,6 @@ import ( "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" - "code.gitea.io/gitea/routers/web/shared/user" shared_user "code.gitea.io/gitea/routers/web/shared/user" ) @@ -42,7 +41,7 @@ func Home(ctx *context.Context) { if ctx.Written() { return } - user.PrepareContextForOrgProfileBigAvatar(ctx) + shared_user.PrepareContextForOrgProfileBigAvatar(ctx) org := ctx.Org.Organization ctx.Data["PageIsUserProfile"] = true From a86df0638b5a8f5882b1c4bfc4a74c67b5e54ec6 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 1 Feb 2024 02:35:28 +0000 Subject: [PATCH 4/5] fix lint --- templates/shared/user/org_profile_big_avatar.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/shared/user/org_profile_big_avatar.tmpl b/templates/shared/user/org_profile_big_avatar.tmpl index b2a1b412884d1..3a53e1aa1a899 100644 --- a/templates/shared/user/org_profile_big_avatar.tmpl +++ b/templates/shared/user/org_profile_big_avatar.tmpl @@ -33,4 +33,4 @@ {{end}}
- \ No newline at end of file + From 56a477f1bbd25f65110d92932f086d1eea72b279 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 1 Feb 2024 07:39:20 +0000 Subject: [PATCH 5/5] only refresh follow button --- routers/web/org/home.go | 13 ++++++- routers/web/shared/user/header.go | 19 ---------- routers/web/user/profile.go | 8 ++-- templates/org/home.tmpl | 37 ++++++++++++++++++- .../shared/user/org_profile_big_avatar.tmpl | 36 ------------------ 5 files changed, 52 insertions(+), 61 deletions(-) delete mode 100644 templates/shared/user/org_profile_big_avatar.tmpl diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 495c6a95dcf9c..8bf02b2c42a74 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -41,11 +41,22 @@ func Home(ctx *context.Context) { if ctx.Written() { return } - shared_user.PrepareContextForOrgProfileBigAvatar(ctx) + org := ctx.Org.Organization ctx.Data["PageIsUserProfile"] = true ctx.Data["Title"] = org.DisplayName() + if len(org.Description) != 0 { + desc, err := markdown.RenderString(&markup.RenderContext{ + Ctx: ctx, + Metas: map[string]string{"mode": "document"}, + }, org.Description) + if err != nil { + ctx.ServerError("RenderString", err) + return + } + ctx.Data["RenderedDescription"] = desc + } var orderBy db.SearchOrderBy ctx.Data["SortType"] = ctx.FormString("sort") diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go index 1c0d01b3a9aed..a2c0abb47e4a1 100644 --- a/routers/web/shared/user/header.go +++ b/routers/web/shared/user/header.go @@ -30,25 +30,6 @@ func prepareContextForCommonProfile(ctx *context.Context) { ctx.Data["FeedURL"] = ctx.ContextUser.HomeLink() } -// PrepareContextForProfileBigAvatar set the context for big avatar view on the org profile page -func PrepareContextForOrgProfileBigAvatar(ctx *context.Context) { - prepareContextForCommonProfile(ctx) - - ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID) - - if len(ctx.ContextUser.Description) != 0 { - desc, err := markdown.RenderString(&markup.RenderContext{ - Ctx: ctx, - Metas: map[string]string{"mode": "document"}, - }, ctx.ContextUser.Description) - if err != nil { - ctx.ServerError("RenderString", err) - return - } - ctx.Data["RenderedDescription"] = desc - } -} - // PrepareContextForProfileBigAvatar set the context for big avatar view on the profile page func PrepareContextForProfileBigAvatar(ctx *context.Context) { prepareContextForCommonProfile(ctx) diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index c26775bc553c3..e7f133e98161e 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -28,8 +28,8 @@ import ( ) const ( - tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar" - tplOrgProfileBigAvatar base.TplName = "shared/user/org_profile_big_avatar" + tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar" + tplFollowUnfollow base.TplName = "shared/user/follow_unfollow" ) // OwnerProfile render profile page for a user or a organization (aka, repo owner) @@ -324,8 +324,8 @@ func Action(ctx *context.Context) { ctx.HTML(http.StatusOK, tplProfileBigAvatar) return } else if ctx.ContextUser.IsOrganization() { - shared_user.PrepareContextForOrgProfileBigAvatar(ctx) - ctx.HTML(http.StatusOK, tplOrgProfileBigAvatar) + ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID) + ctx.HTML(http.StatusOK, tplFollowUnfollow) return } log.Error("Failed to apply action %q: unsupport context user type: %s", ctx.FormString("action"), ctx.ContextUser.Type) diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 63c2801686373..322be3271d3e4 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -1,6 +1,41 @@ {{template "base/head" .}}
- {{template "shared/user/org_profile_big_avatar" .}} +
+ {{ctx.AvatarUtils.Avatar .Org 140 "org-avatar"}} +
+
+ {{.Org.DisplayName}} + + {{if .Org.Visibility.IsLimited}}{{ctx.Locale.Tr "org.settings.visibility.limited_shortname"}}{{end}} + {{if .Org.Visibility.IsPrivate}}{{ctx.Locale.Tr "org.settings.visibility.private_shortname"}}{{end}} + +
+ {{if $.RenderedDescription}}
{{$.RenderedDescription|Str2html}}
{{end}} +
+ {{if .Org.Location}}
{{svg "octicon-location"}} {{.Org.Location}}
{{end}} + {{if .Org.Website}}
{{svg "octicon-link"}} {{.Org.Website}}
{{end}} + {{if $.IsSigned}} + {{if .Org.Email}}
{{svg "octicon-mail"}} {{.Org.Email}}
{{end}} + {{end}} +
+
+ +
{{template "org/menu" .}} diff --git a/templates/shared/user/org_profile_big_avatar.tmpl b/templates/shared/user/org_profile_big_avatar.tmpl deleted file mode 100644 index 3a53e1aa1a899..0000000000000 --- a/templates/shared/user/org_profile_big_avatar.tmpl +++ /dev/null @@ -1,36 +0,0 @@ -
- {{ctx.AvatarUtils.Avatar .ContextUser 140 "org-avatar"}} -
-
- {{.ContextUser.DisplayName}} - - {{if .ContextUser.Visibility.IsLimited}}{{ctx.Locale.Tr "org.settings.visibility.limited_shortname"}}{{end}} - {{if .ContextUser.Visibility.IsPrivate}}{{ctx.Locale.Tr "org.settings.visibility.private_shortname"}}{{end}} - -
- {{if $.RenderedDescription}}
{{$.RenderedDescription|Str2html}}
{{end}} -
- {{if .ContextUser.Location}}
{{svg "octicon-location"}} {{.ContextUser.Location}}
{{end}} - {{if .ContextUser.Website}}
{{svg "octicon-link"}} {{.ContextUser.Website}}
{{end}} - {{if $.IsSigned}} - {{if .ContextUser.Email}}
{{svg "octicon-mail"}} {{.ContextUser.Email}}
{{end}} - {{end}} -
-
- -