在控制后台界面添加应用商店
This commit is contained in:
17
routers/web/admin/appstore.go
Normal file
17
routers/web/admin/appstore.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/modules/templates"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
)
|
||||
|
||||
const tplAdminAppStore templates.TplName = "admin/appstore"
|
||||
|
||||
// AdminAppStore renders the App Store page in admin console
|
||||
func AdminAppStore(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.appstore")
|
||||
ctx.Data["PageIsAdminAppStore"] = true
|
||||
ctx.HTML(http.StatusOK, tplAdminAppStore)
|
||||
}
|
||||
@@ -253,12 +253,17 @@ func AppStoreInstall(ctx *context.Context) {
|
||||
|
||||
// 安装成功
|
||||
if installTarget == "kubeconfig" && kubeconfig != "" {
|
||||
ctx.Flash.Success("应用已成功安装到指定位置")
|
||||
ctx.Flash.Success("应用已成功安装到自定义位置")
|
||||
} else {
|
||||
ctx.Flash.Success("应用配置已准备完成,本地安装功能开发中")
|
||||
ctx.Flash.Success("应用已成功安装到默认位置")
|
||||
}
|
||||
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings/appstore")
|
||||
// 优先根据表单的 redirect_to 回跳(前端会带上当前路径)
|
||||
if redirectTo := ctx.FormString("redirect_to"); redirectTo != "" {
|
||||
ctx.RedirectToCurrentSite(redirectTo)
|
||||
} else {
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings/appstore")
|
||||
}
|
||||
}
|
||||
|
||||
// AppStoreUninstall handles app uninstallation
|
||||
@@ -307,7 +312,13 @@ func AppStoreUninstall(ctx *context.Context) {
|
||||
ctx.Flash.Success("本地卸载功能开发中")
|
||||
}
|
||||
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings/appstore")
|
||||
// 根据来源页面决定重定向位置
|
||||
referer := ctx.Req.Header.Get("Referer")
|
||||
if strings.Contains(referer, "/admin/appstore") {
|
||||
ctx.Redirect(setting.AppSubURL + "/admin/appstore")
|
||||
} else {
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings/appstore")
|
||||
}
|
||||
}
|
||||
|
||||
// AppStoreConfigure handles app configuration
|
||||
@@ -323,7 +334,11 @@ func AppStoreConfigure(ctx *context.Context) {
|
||||
func AppStoreConfigurePost(ctx *context.Context) {
|
||||
// TODO: Handle configuration form submission
|
||||
ctx.Flash.Success("App configuration feature coming soon")
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings/appstore")
|
||||
if redirectTo := ctx.FormString("redirect_to"); redirectTo != "" {
|
||||
ctx.RedirectToCurrentSite(redirectTo)
|
||||
} else {
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings/appstore")
|
||||
}
|
||||
}
|
||||
|
||||
// 添加应用API
|
||||
|
||||
@@ -744,6 +744,9 @@ func registerWebRoutes(m *web.Router) {
|
||||
m.Post("", web.Bind(forms.AdminDashboardForm{}), admin.DashboardPost)
|
||||
m.Post("/logo", web.Bind(forms.AvatarForm{}), admin.LogoPost)
|
||||
|
||||
// Admin App Store entry – renders page that reuses user appstore UI
|
||||
m.Get("/appstore", admin.AdminAppStore)
|
||||
|
||||
m.Get("/self_check", admin.SelfCheck)
|
||||
m.Post("/self_check", admin.SelfCheckPost)
|
||||
|
||||
|
||||
7
templates/admin/appstore.tmpl
Normal file
7
templates/admin/appstore.tmpl
Normal file
@@ -0,0 +1,7 @@
|
||||
{{template "admin/layout_head" (dict "ctxData" . "pageClass" "admin appstore")}}
|
||||
|
||||
{{template "user/settings/appstore_body" .}}
|
||||
|
||||
{{template "admin/layout_footer" .}}
|
||||
|
||||
|
||||
@@ -95,6 +95,10 @@
|
||||
<a class="{{if .PageIsAdminNotices}}active {{end}}item" href="{{AppSubUrl}}/-/admin/notices">
|
||||
{{ctx.Locale.Tr "admin.notices"}}
|
||||
</a>
|
||||
<a class="{{if .PageIsAdminAppStore}}active {{end}}item" href="{{AppSubUrl}}/-/admin/appstore">
|
||||
<i class="shopping cart icon"></i>
|
||||
{{ctx.Locale.Tr "settings.appstore"}}
|
||||
</a>
|
||||
<details class="item toggleable-item" {{if or .PageIsAdminMonitorStats .PageIsAdminMonitorCron .PageIsAdminMonitorQueue .PageIsAdminMonitorTrace}}open{{end}}>
|
||||
<summary>{{ctx.Locale.Tr "admin.monitor"}}</summary>
|
||||
<div class="menu">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{{template "user/settings/layout_head" (dict "ctxData" . "pageClass" "user settings appstore")}}
|
||||
{{define "user/settings/appstore_body"}}
|
||||
<meta name="_csrf" content="{{.CsrfToken}}">
|
||||
|
||||
<style>
|
||||
@@ -863,6 +864,8 @@ function installApp() {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 避免全局 beforeunload 提示:标记当前表单忽略脏检测
|
||||
try { form.classList.add('ignore-dirty'); form.classList.remove('dirty'); } catch(e) {}
|
||||
const installForm = document.createElement('form');
|
||||
installForm.method = 'POST';
|
||||
installForm.action = `/user/settings/appstore/install/${appId}`;
|
||||
@@ -886,6 +889,12 @@ function installApp() {
|
||||
targetInput.name = 'install_target';
|
||||
targetInput.value = installTarget;
|
||||
installForm.appendChild(targetInput);
|
||||
// 带上回跳地址,优先返回提交页面(后台或用户设置页)
|
||||
const redirectInput = document.createElement('input');
|
||||
redirectInput.type = 'hidden';
|
||||
redirectInput.name = 'redirect_to';
|
||||
redirectInput.value = window.location.pathname;
|
||||
installForm.appendChild(redirectInput);
|
||||
if (installTarget === 'kubeconfig') {
|
||||
const kcInput = document.createElement('input');
|
||||
kcInput.type = 'hidden';
|
||||
@@ -944,4 +953,6 @@ async function submitAddApp() {
|
||||
}
|
||||
</script>
|
||||
|
||||
{{template "user/settings/layout_footer" .}}
|
||||
{{end}}
|
||||
{{template "user/settings/appstore_body" .}}
|
||||
{{template "user/settings/layout_footer" .}}
|
||||
Reference in New Issue
Block a user