1
1
mirror of https://github.com/go-gitea/gitea synced 2024-06-02 17:35:49 +00:00

refactor PageData to pageData

This commit is contained in:
wxiaoguang 2021-10-14 18:12:40 +08:00
parent b0c049427b
commit f1eb3784d0
7 changed files with 9 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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}},

View File

@ -9,7 +9,7 @@
{{end}}
<!-- I know, there is probably a better way to do this (moved from sidebar.tmpl, original author: 6543 @ 2021-02-28) -->
<!-- Agree, there should be a better way, eg: introduce window.config.PageData (original author: wxiaoguang @ 2021-09-05) -->
<!-- Agree, there should be a better way, eg: introduce window.config.pageData (original author: wxiaoguang @ 2021-09-05) -->
<input type="hidden" id="repolink" value="{{$.RepoRelPath}}">
<input type="hidden" id="repoId" value="{{.Repository.ID}}">
<input type="hidden" id="issueIndex" value="{{.Issue.Index}}"/>

View File

@ -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();

View File

@ -68,7 +68,7 @@ const sfc = {
// * home_link: (...)
// * login: (...)
// * name: (...)
activityTopAuthors: window.config.PageData.repoActivityTopAuthors || [],
activityTopAuthors: window.config.pageData.repoActivityTopAuthors || [],
}),
computed: {
graphPoints() {

View File

@ -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');