Skip to content

Commit 10c1665

Browse files
committed
fix
1 parent 67c1a07 commit 10c1665

File tree

4 files changed

+46
-15
lines changed

4 files changed

+46
-15
lines changed

templates/admin/self_check.tmpl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
{{template "admin/layout_head" (dict "ctxData" . "pageClass" "admin config")}}
1+
{{template "admin/layout_head" (dict "ctxData" . "pageClass" "admin")}}
22

33
<div class="admin-setting-content">
44
<h4 class="ui top attached header">
55
{{ctx.Locale.Tr "admin.self_check"}}
66
</h4>
77

88
{{if .StartupProblems}}
9-
<div class="ui attached segment">
9+
<div class="ui attached segment self-check-problem">
1010
<div class="ui warning message">
1111
<div>{{ctx.Locale.Tr "admin.self_check.startup_warnings"}}</div>
1212
<ul class="tw-w-full">{{range .StartupProblems}}<li>{{.}}</li>{{end}}</ul>
1313
</div>
1414
</div>
1515
{{end}}
1616

17+
<div class="ui attached segment tw-hidden self-check-problem self-check-by-frontend"></div>
18+
1719
{{if .DatabaseCheckHasProblems}}
18-
<div class="ui attached segment">
20+
<div class="ui attached segment self-check-problem">
1921
{{if .DatabaseType.IsMySQL}}
2022
<div class="tw-p-2">{{ctx.Locale.Tr "admin.self_check.database_fix_mysql"}}</div>
2123
{{else if .DatabaseType.IsMSSQL}}
@@ -29,22 +31,22 @@
2931
{{end}}
3032
{{if .DatabaseCheckInconsistentCollationColumns}}
3133
<div class="ui red message">
32-
{{ctx.Locale.Tr "admin.self_check.database_inconsistent_collation_columns" .DatabaseCheckResult.DatabaseCollation}}
33-
<ul class="tw-w-full">
34-
{{range .DatabaseCheckInconsistentCollationColumns}}
35-
<li>{{.}}</li>
36-
{{end}}
37-
</ul>
34+
<details>
35+
<summary>{{ctx.Locale.Tr "admin.self_check.database_inconsistent_collation_columns" .DatabaseCheckResult.DatabaseCollation}}</summary>
36+
<ul class="tw-w-full">
37+
{{range .DatabaseCheckInconsistentCollationColumns}}
38+
<li>{{.}}</li>
39+
{{end}}
40+
</ul>
41+
</details>
3842
</div>
3943
{{end}}
4044
</div>
4145
{{end}}
42-
43-
{{if and (not .StartupProblems) (not .DatabaseCheckHasProblems)}}
44-
<div class="ui attached segment">
46+
{{/* only shown when there is no visible "self-check-problem" */}}
47+
<div class="ui attached segment tw-hidden self-check-no-problem">
4548
{{ctx.Locale.Tr "admin.self_check.no_problem_found"}}
4649
</div>
47-
{{end}}
4850
</div>
4951

5052
{{template "admin/layout_footer" .}}

web_src/js/bootstrap.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ export function showGlobalErrorMessage(msg) {
2222
let msgDiv = msgContainer.querySelector(`.js-global-error[data-global-error-msg-compact="${msgCompact}"]`);
2323
if (!msgDiv) {
2424
const el = document.createElement('div');
25-
el.innerHTML = `<div class="ui container negative message center aligned js-global-error tw-mt-[15px] tw-whitespace-pre-line"></div>`;
25+
el.innerHTML = `<div class="ui container js-global-error tw-my-4"><div class="ui negative message tw-text-center tw-whitespace-pre-line"></div></div>`;
2626
msgDiv = el.childNodes[0];
2727
}
2828
// merge duplicated messages into "the message (count)" format
2929
const msgCount = Number(msgDiv.getAttribute(`data-global-error-msg-count`)) + 1;
3030
msgDiv.setAttribute(`data-global-error-msg-compact`, msgCompact);
3131
msgDiv.setAttribute(`data-global-error-msg-count`, msgCount.toString());
32-
msgDiv.textContent = msg + (msgCount > 1 ? ` (${msgCount})` : '');
32+
msgDiv.querySelector('.ui.message').textContent = msg + (msgCount > 1 ? ` (${msgCount})` : '');
3333
msgContainer.prepend(msgDiv);
3434
}
3535

@@ -49,6 +49,8 @@ function processWindowErrorEvent({error, reason, message, type, filename, lineno
4949
const assetBaseUrl = String(new URL(__webpack_public_path__, window.location.origin));
5050
const {runModeIsProd} = window.config ?? {};
5151

52+
console.log(error, reason);
53+
5254
// `error` and `reason` are not guaranteed to be errors. If the value is falsy, it is likely a
5355
// non-critical event from the browser. We log them but don't show them to users. Examples:
5456
// - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#observation_errors
@@ -60,6 +62,7 @@ function processWindowErrorEvent({error, reason, message, type, filename, lineno
6062
}
6163

6264
if (err instanceof Error) {
65+
6366
// If the error stack trace does not include the base URL of our script assets, it likely came
6467
// from a browser extension or inline script. Do not show such errors in production.
6568
if (!err.stack?.includes(assetBaseUrl) && runModeIsProd) return;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {toggleElem} from '../../utils/dom.js';
2+
import {POST} from '../../modules/fetch.js';
3+
4+
const {appSubUrl} = window.config;
5+
6+
export async function initAdminSelfCheck() {
7+
const elAdminSelfCheckFrontend = document.querySelector('.page-content.admin .self-check-by-frontend');
8+
if (!elAdminSelfCheckFrontend) return;
9+
10+
const resp = await POST(`${appSubUrl}/admin/selfcheck/with-frontend`, {
11+
data: new URLSearchParams({
12+
locationOrigin: window.location.origin,
13+
now: Date.now(),
14+
}),
15+
});
16+
17+
const json = await resp.json();
18+
console.log(json);
19+
20+
// only show the "no problem" if there is no visible "self-check-problem"
21+
const elContent = document.querySelector('.page-content.admin .admin-setting-content:not(.tw-hidden)');
22+
const hasProblem = Boolean(elContent.querySelectorAll('.self-check-problem').length);
23+
toggleElem(elContent.querySelector('.self-check-no-problem'), !hasProblem);
24+
}

web_src/js/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import {initRepoDiffCommitBranchesAndTags} from './features/repo-diff-commit.js'
8787
import {initDirAuto} from './modules/dirauto.js';
8888
import {initRepositorySearch} from './features/repo-search.js';
8989
import {initColorPickers} from './features/colorpicker.js';
90+
import {initAdminSelfCheck} from './features/admin/selfcheck.js';
9091

9192
// Init Gitea's Fomantic settings
9293
initGiteaFomantic();
@@ -132,6 +133,7 @@ onDomReady(() => {
132133
initAdminEmails();
133134
initAdminUserListSearchForm();
134135
initAdminConfigs();
136+
initAdminSelfCheck();
135137

136138
initDashboardRepoList();
137139

0 commit comments

Comments
 (0)