Skip to content

Commit

Permalink
introduce window.config.PageData to pass template data to javascript …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
wxiaoguang committed Aug 25, 2021
1 parent d5adeee commit 0b2604b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond {
}
cond = cond.And(twoFactorCond)
} else {
log.Critical("Unknown admin user search filter: %v=%v", filterKey, filterValue)
log.Error("Unknown admin user search filter: %v=%v", filterKey, filterValue)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions templates/admin/user/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@
<script>
<!-- /* eslint-disable */ -->
(function() {
window.giteaContext = window.giteaContext || {};
window.giteaContext.adminUserListSearchForm = {
window.config.PageData.adminUserListSearchForm = {
statusFilterMap: {{.StatusFilterMap}},
sortType: {{.SortType}} || 'oldest'
}
Expand Down
5 changes: 3 additions & 2 deletions templates/base/footer.tmpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{{/*
{{if false}}
{{/* to make html structure "likely" complete to prevent IDE warnings */}}
<html>
<body>
<div>
*/}}
{{end}}

{{template "custom/body_inner_post" .}}

Expand Down
8 changes: 5 additions & 3 deletions templates/base/head.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
},
EnableTimetracking: {{if EnableTimetracking}}true{{else}}false{{end}},
PageIsProjects: {{if .PageIsProjects }}true{{else}}false{{end}},
PageData: {}, // to store page related data, eg: pass variables to javascript module
{{if .RequireTribute}}
tributeValues: Array.from(new Map([
{{ range .Participants }}
Expand Down Expand Up @@ -75,7 +76,6 @@
.ui.secondary.menu .dropdown.item > .menu { margin-top: 0; }
</style>
</noscript>
<style class="list-search-style"></style>
{{if .PageIsUserProfile}}
<meta property="og:title" content="{{.Owner.Name}}" />
<meta property="og:type" content="profile" />
Expand Down Expand Up @@ -134,8 +134,10 @@
{{template "base/head_navbar" .}}
</div><!-- end bar -->
{{end}}
{{/*

{{if false}}
{{/* to make html structure "likely" complete to prevent IDE warnings */}}
</div>
</body>
</html>
*/}}
{{end}}
2 changes: 1 addition & 1 deletion templates/repo/activity.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
</div>
<div class="ui attached segment" id="app">
<script type="text/javascript">
var ActivityTopAuthors = {{Json .ActivityTopAuthors | SafeJS}};
window.config.PageData.ActivityTopAuthors = {{Json .ActivityTopAuthors | SafeJS}};
</script>
<activity-top-authors :data="activityTopAuthors" />
</div>
Expand Down
6 changes: 2 additions & 4 deletions web_src/js/features/admin-users.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
export function initAdminUserListSearchForm() {
if (!$('.admin').length) return;
if (!window.giteaContext || !window.giteaContext.adminUserListSearchForm) return;
const searchForm = window.config.PageData.adminUserListSearchForm;
if (!searchForm) return;

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

const searchForm = window.giteaContext.adminUserListSearchForm;

$form.find(`button[name=sort][value=${searchForm.sortType}]`).addClass('active');

if (searchForm.statusFilterMap) {
Expand Down
4 changes: 2 additions & 2 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {initMarkupContent, initCommentContent} from './markup/content.js';
import {stripTags, mqBinarySearch} from './utils.js';
import {svg, svgs} from './svg.js';

const {AppSubUrl, AssetUrlPrefix, csrf} = window.config;
const {AppSubUrl, AssetUrlPrefix, csrf, PageData} = window.config;

let previewFileModes;
const commentMDEditors = {};
Expand Down Expand Up @@ -3439,7 +3439,7 @@ function initVueApp() {
searchLimit: Number((document.querySelector('meta[name=_search_limit]') || {}).content),
suburl: AppSubUrl,
uid: Number((document.querySelector('meta[name=_context_uid]') || {}).content),
activityTopAuthors: window.ActivityTopAuthors || [],
activityTopAuthors: PageData.ActivityTopAuthors || [],
};
},
});
Expand Down

0 comments on commit 0b2604b

Please sign in to comment.