From f1eb3784d0879bffd40f5cc7be9206b912125035 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 14 Oct 2021 18:12:40 +0800 Subject: [PATCH] refactor PageData to pageData --- docs/content/doc/developers/guidelines-frontend.md | 2 +- modules/context/context.go | 4 ++-- templates/base/head.tmpl | 2 +- templates/repo/issue/view_content.tmpl | 2 +- web_src/js/components/DashboardRepoList.js | 4 ++-- web_src/js/components/RepoActivityTopAuthors.vue | 2 +- web_src/js/features/admin-users.js | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/content/doc/developers/guidelines-frontend.md b/docs/content/doc/developers/guidelines-frontend.md index 300f02b0e0..d141153329 100644 --- a/docs/content/doc/developers/guidelines-frontend.md +++ b/docs/content/doc/developers/guidelines-frontend.md @@ -36,7 +36,7 @@ Guidelines specialized for Gitea: 3. HTML ids and classes used in JavaScript should be unique for the whole project, and should contain 2-3 feature related keywords. We recommend to use the `js-` prefix for classes that are only used in JavaScript. 4. jQuery events across different features should use their own namespaces. 5. CSS styling for classes provided by frameworks should not be overwritten. Always use new class-names to overwrite framework styles. We recommend to use the `us-` prefix for user defined styles. -6. The backend can pass complex data to the frontend by using `ctx.PageData["myModuleData"] = map{}` +6. The backend can pass complex data to the frontend by using `ctx.PageData["myModuleData"] = map[]{}` 7. Simple pages and SEO-related pages use Go HTML Template render to generate static Fomantic-UI HTML output. Complex pages can use Vue2 (or Vue3 in future). ## Legacy Problems and Solutions diff --git a/modules/context/context.go b/modules/context/context.go index b733eadad0..a1155980d1 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -51,7 +51,7 @@ type Context struct { Resp ResponseWriter Req *http.Request Data map[string]interface{} // data used by MVC templates - PageData map[string]interface{} // data used by JavaScript modules in one page + PageData map[string]interface{} // data used by JavaScript modules in one page, it's `window.config.pageData` Render Render translation.Locale Cache cache.Cache @@ -648,7 +648,7 @@ func Contexter() func(next http.Handler) http.Handler { "IsProd": setting.IsProd(), }, } - // PageData is passed by reference, and it will be rendered to `window.config.PageData` in `head.tmpl` for JavaScript modules + // PageData is passed by reference, and it will be rendered to `window.config.pageData` in `head.tmpl` for JavaScript modules ctx.PageData = map[string]interface{}{} ctx.Data["PageData"] = ctx.PageData diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index dc42736d1d..80bb121c6b 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -26,7 +26,7 @@ CustomEmojis: {{CustomEmojis}}, UseServiceWorker: {{UseServiceWorker}}, csrf: '{{.CsrfToken}}', - PageData: {{ .PageData }}, + pageData: {{ .PageData }}, HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}}, SimpleMDE: {{if .RequireSimpleMDE}}true{{else}}false{{end}}, Tribute: {{if .RequireTribute}}true{{else}}false{{end}}, diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 95c9296174..9ad6bee651 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -9,7 +9,7 @@ {{end}} - + diff --git a/web_src/js/components/DashboardRepoList.js b/web_src/js/components/DashboardRepoList.js index 559fa1d1be..7ae62af0a0 100644 --- a/web_src/js/components/DashboardRepoList.js +++ b/web_src/js/components/DashboardRepoList.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import {initVueSvg, vueDelimiters} from './VueComponentLoader.js'; -const {AppSubUrl, AssetUrlPrefix, PageData} = window.config; +const {AppSubUrl, AssetUrlPrefix, pageData} = window.config; function initVueComponents() { Vue.component('repo-search', { @@ -350,7 +350,7 @@ function initVueComponents() { function initDashboardRepoList() { const el = document.getElementById('dashboard-repo-list'); - const dashboardRepoListData = PageData.dashboardRepoList || null; + const dashboardRepoListData = pageData.dashboardRepoList || null; if (!el || !dashboardRepoListData) return; initVueSvg(); diff --git a/web_src/js/components/RepoActivityTopAuthors.vue b/web_src/js/components/RepoActivityTopAuthors.vue index a5975f4f63..d510695b1d 100644 --- a/web_src/js/components/RepoActivityTopAuthors.vue +++ b/web_src/js/components/RepoActivityTopAuthors.vue @@ -68,7 +68,7 @@ const sfc = { // * home_link: (...) // * login: (...) // * name: (...) - activityTopAuthors: window.config.PageData.repoActivityTopAuthors || [], + activityTopAuthors: window.config.pageData.repoActivityTopAuthors || [], }), computed: { graphPoints() { diff --git a/web_src/js/features/admin-users.js b/web_src/js/features/admin-users.js index b01c66afe2..5863c5480f 100644 --- a/web_src/js/features/admin-users.js +++ b/web_src/js/features/admin-users.js @@ -1,5 +1,5 @@ export function initAdminUserListSearchForm() { - const searchForm = window.config.PageData.adminUserListSearchForm; + const searchForm = window.config.pageData.adminUserListSearchForm; if (!searchForm) return; const $form = $('#user-list-search-form');