Skip to content

Commit 0b2604b

Browse files
committed
introduce window.config.PageData to pass template data to javascript module and small refactor
move legacy window.ActivityTopAuthors to window.config.PageData.ActivityTopAuthors make HTML structure more IDE-friendly in footer.tmpl and head.tmpl remove incorrect <style class="list-search-style"></style> in head.tmpl use log.Error instead of log.Critical in admin user search
1 parent d5adeee commit 0b2604b

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

models/user.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond {
16691669
}
16701670
cond = cond.And(twoFactorCond)
16711671
} else {
1672-
log.Critical("Unknown admin user search filter: %v=%v", filterKey, filterValue)
1672+
log.Error("Unknown admin user search filter: %v=%v", filterKey, filterValue)
16731673
}
16741674
}
16751675
}

templates/admin/user/list.tmpl

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@
6363
<script>
6464
<!-- /* eslint-disable */ -->
6565
(function() {
66-
window.giteaContext = window.giteaContext || {};
67-
window.giteaContext.adminUserListSearchForm = {
66+
window.config.PageData.adminUserListSearchForm = {
6867
statusFilterMap: {{.StatusFilterMap}},
6968
sortType: {{.SortType}} || 'oldest'
7069
}

templates/base/footer.tmpl

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
{{/*
1+
{{if false}}
2+
{{/* to make html structure "likely" complete to prevent IDE warnings */}}
23
<html>
34
<body>
45
<div>
5-
*/}}
6+
{{end}}
67

78
{{template "custom/body_inner_post" .}}
89

templates/base/head.tmpl

+5-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
},
4545
EnableTimetracking: {{if EnableTimetracking}}true{{else}}false{{end}},
4646
PageIsProjects: {{if .PageIsProjects }}true{{else}}false{{end}},
47+
PageData: {}, // to store page related data, eg: pass variables to javascript module
4748
{{if .RequireTribute}}
4849
tributeValues: Array.from(new Map([
4950
{{ range .Participants }}
@@ -75,7 +76,6 @@
7576
.ui.secondary.menu .dropdown.item > .menu { margin-top: 0; }
7677
</style>
7778
</noscript>
78-
<style class="list-search-style"></style>
7979
{{if .PageIsUserProfile}}
8080
<meta property="og:title" content="{{.Owner.Name}}" />
8181
<meta property="og:type" content="profile" />
@@ -134,8 +134,10 @@
134134
{{template "base/head_navbar" .}}
135135
</div><!-- end bar -->
136136
{{end}}
137-
{{/*
137+
138+
{{if false}}
139+
{{/* to make html structure "likely" complete to prevent IDE warnings */}}
138140
</div>
139141
</body>
140142
</html>
141-
*/}}
143+
{{end}}

templates/repo/activity.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
</div>
111111
<div class="ui attached segment" id="app">
112112
<script type="text/javascript">
113-
var ActivityTopAuthors = {{Json .ActivityTopAuthors | SafeJS}};
113+
window.config.PageData.ActivityTopAuthors = {{Json .ActivityTopAuthors | SafeJS}};
114114
</script>
115115
<activity-top-authors :data="activityTopAuthors" />
116116
</div>

web_src/js/features/admin-users.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
export function initAdminUserListSearchForm() {
2-
if (!$('.admin').length) return;
3-
if (!window.giteaContext || !window.giteaContext.adminUserListSearchForm) return;
2+
const searchForm = window.config.PageData.adminUserListSearchForm;
3+
if (!searchForm) return;
44

55
const $form = $('#user-list-search-form');
66
if (!$form.length) return;
77

8-
const searchForm = window.giteaContext.adminUserListSearchForm;
9-
108
$form.find(`button[name=sort][value=${searchForm.sortType}]`).addClass('active');
119

1210
if (searchForm.statusFilterMap) {

web_src/js/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {initMarkupContent, initCommentContent} from './markup/content.js';
2727
import {stripTags, mqBinarySearch} from './utils.js';
2828
import {svg, svgs} from './svg.js';
2929

30-
const {AppSubUrl, AssetUrlPrefix, csrf} = window.config;
30+
const {AppSubUrl, AssetUrlPrefix, csrf, PageData} = window.config;
3131

3232
let previewFileModes;
3333
const commentMDEditors = {};
@@ -3439,7 +3439,7 @@ function initVueApp() {
34393439
searchLimit: Number((document.querySelector('meta[name=_search_limit]') || {}).content),
34403440
suburl: AppSubUrl,
34413441
uid: Number((document.querySelector('meta[name=_context_uid]') || {}).content),
3442-
activityTopAuthors: window.ActivityTopAuthors || [],
3442+
activityTopAuthors: PageData.ActivityTopAuthors || [],
34433443
};
34443444
},
34453445
});

0 commit comments

Comments
 (0)