Skip to content

Commit a03abb5

Browse files
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-show
2 parents f03359e + f35e2b0 commit a03abb5

14 files changed

+109
-113
lines changed

web_src/js/features/admin/common.ts

+53-52
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,50 @@ import {POST} from '../../modules/fetch.ts';
55

66
const {appSubUrl} = window.config;
77

8-
function onSecurityProtocolChange() {
9-
if (Number(document.querySelector('#security_protocol')?.value) > 0) {
8+
function onSecurityProtocolChange(): void {
9+
if (Number(document.querySelector<HTMLInputElement>('#security_protocol')?.value) > 0) {
1010
showElem('.has-tls');
1111
} else {
1212
hideElem('.has-tls');
1313
}
1414
}
1515

16-
export function initAdminCommon() {
16+
export function initAdminCommon(): void {
1717
if (!document.querySelector('.page-content.admin')) return;
1818

1919
// check whether appUrl(ROOT_URL) is correct, if not, show an error message
2020
checkAppUrl();
2121

2222
// New user
2323
if ($('.admin.new.user').length > 0 || $('.admin.edit.user').length > 0) {
24-
document.querySelector('#login_type')?.addEventListener('change', function () {
25-
if (this.value?.substring(0, 1) === '0') {
26-
document.querySelector('#user_name')?.removeAttribute('disabled');
27-
document.querySelector('#login_name')?.removeAttribute('required');
24+
document.querySelector<HTMLInputElement>('#login_type')?.addEventListener('change', function () {
25+
if (this.value?.startsWith('0')) {
26+
document.querySelector<HTMLInputElement>('#user_name')?.removeAttribute('disabled');
27+
document.querySelector<HTMLInputElement>('#login_name')?.removeAttribute('required');
2828
hideElem('.non-local');
2929
showElem('.local');
30-
document.querySelector('#user_name')?.focus();
30+
document.querySelector<HTMLInputElement>('#user_name')?.focus();
3131

3232
if (this.getAttribute('data-password') === 'required') {
3333
document.querySelector('#password')?.setAttribute('required', 'required');
3434
}
3535
} else {
36-
if (document.querySelector('.admin.edit.user')) {
37-
document.querySelector('#user_name')?.setAttribute('disabled', 'disabled');
36+
if (document.querySelector<HTMLDivElement>('.admin.edit.user')) {
37+
document.querySelector<HTMLInputElement>('#user_name')?.setAttribute('disabled', 'disabled');
3838
}
39-
document.querySelector('#login_name')?.setAttribute('required', 'required');
39+
document.querySelector<HTMLInputElement>('#login_name')?.setAttribute('required', 'required');
4040
showElem('.non-local');
4141
hideElem('.local');
42-
document.querySelector('#login_name')?.focus();
42+
document.querySelector<HTMLInputElement>('#login_name')?.focus();
4343

44-
document.querySelector('#password')?.removeAttribute('required');
44+
document.querySelector<HTMLInputElement>('#password')?.removeAttribute('required');
4545
}
4646
});
4747
}
4848

4949
function onUsePagedSearchChange() {
50-
const searchPageSizeElements = document.querySelectorAll('.search-page-size');
51-
if (document.querySelector('#use_paged_search').checked) {
50+
const searchPageSizeElements = document.querySelectorAll<HTMLDivElement>('.search-page-size');
51+
if (document.querySelector<HTMLInputElement>('#use_paged_search').checked) {
5252
showElem('.search-page-size');
5353
for (const el of searchPageSizeElements) {
5454
el.querySelector('input')?.setAttribute('required', 'required');
@@ -61,28 +61,28 @@ export function initAdminCommon() {
6161
}
6262
}
6363

64-
function onOAuth2Change(applyDefaultValues) {
64+
function onOAuth2Change(applyDefaultValues: boolean) {
6565
hideElem('.open_id_connect_auto_discovery_url, .oauth2_use_custom_url');
66-
for (const input of document.querySelectorAll('.open_id_connect_auto_discovery_url input[required]')) {
66+
for (const input of document.querySelectorAll<HTMLInputElement>('.open_id_connect_auto_discovery_url input[required]')) {
6767
input.removeAttribute('required');
6868
}
6969

70-
const provider = document.querySelector('#oauth2_provider').value;
70+
const provider = document.querySelector<HTMLInputElement>('#oauth2_provider').value;
7171
switch (provider) {
7272
case 'openidConnect':
73-
document.querySelector('.open_id_connect_auto_discovery_url input').setAttribute('required', 'required');
73+
document.querySelector<HTMLInputElement>('.open_id_connect_auto_discovery_url input').setAttribute('required', 'required');
7474
showElem('.open_id_connect_auto_discovery_url');
7575
break;
7676
default: {
77-
const elProviderCustomUrlSettings = document.querySelector(`#${provider}_customURLSettings`);
77+
const elProviderCustomUrlSettings = document.querySelector<HTMLInputElement>(`#${provider}_customURLSettings`);
7878
if (!elProviderCustomUrlSettings) break; // some providers do not have custom URL settings
7979
const couldChangeCustomURLs = elProviderCustomUrlSettings.getAttribute('data-available') === 'true';
8080
const mustProvideCustomURLs = elProviderCustomUrlSettings.getAttribute('data-required') === 'true';
8181
if (couldChangeCustomURLs) {
8282
showElem('.oauth2_use_custom_url'); // show the checkbox
8383
}
8484
if (mustProvideCustomURLs) {
85-
document.querySelector('#oauth2_use_custom_url').checked = true; // make the checkbox checked
85+
document.querySelector<HTMLInputElement>('#oauth2_use_custom_url').checked = true; // make the checkbox checked
8686
}
8787
break;
8888
}
@@ -91,17 +91,17 @@ export function initAdminCommon() {
9191
}
9292

9393
function onOAuth2UseCustomURLChange(applyDefaultValues) {
94-
const provider = document.querySelector('#oauth2_provider').value;
94+
const provider = document.querySelector<HTMLInputElement>('#oauth2_provider').value;
9595
hideElem('.oauth2_use_custom_url_field');
96-
for (const input of document.querySelectorAll('.oauth2_use_custom_url_field input[required]')) {
96+
for (const input of document.querySelectorAll<HTMLInputElement>('.oauth2_use_custom_url_field input[required]')) {
9797
input.removeAttribute('required');
9898
}
9999

100100
const elProviderCustomUrlSettings = document.querySelector(`#${provider}_customURLSettings`);
101-
if (elProviderCustomUrlSettings && document.querySelector('#oauth2_use_custom_url').checked) {
101+
if (elProviderCustomUrlSettings && document.querySelector<HTMLInputElement>('#oauth2_use_custom_url').checked) {
102102
for (const custom of ['token_url', 'auth_url', 'profile_url', 'email_url', 'tenant']) {
103103
if (applyDefaultValues) {
104-
document.querySelector(`#oauth2_${custom}`).value = document.querySelector(`#${provider}_${custom}`).value;
104+
document.querySelector<HTMLInputElement>(`#oauth2_${custom}`).value = document.querySelector<HTMLInputElement>(`#${provider}_${custom}`).value;
105105
}
106106
const customInput = document.querySelector(`#${provider}_${custom}`);
107107
if (customInput && customInput.getAttribute('data-available') === 'true') {
@@ -115,58 +115,59 @@ export function initAdminCommon() {
115115
}
116116

117117
function onEnableLdapGroupsChange() {
118-
toggleElem(document.querySelector('#ldap-group-options'), $('.js-ldap-group-toggle')[0].checked);
118+
const checked = document.querySelector<HTMLInputElement>('.js-ldap-group-toggle')?.checked;
119+
toggleElem(document.querySelector('#ldap-group-options'), checked);
119120
}
120121

121122
// New authentication
122-
if (document.querySelector('.admin.new.authentication')) {
123-
document.querySelector('#auth_type')?.addEventListener('change', function () {
123+
if (document.querySelector<HTMLDivElement>('.admin.new.authentication')) {
124+
document.querySelector<HTMLInputElement>('#auth_type')?.addEventListener('change', function () {
124125
hideElem('.ldap, .dldap, .smtp, .pam, .oauth2, .has-tls, .search-page-size, .sspi');
125126

126-
for (const input of document.querySelectorAll('.ldap input[required], .binddnrequired input[required], .dldap input[required], .smtp input[required], .pam input[required], .oauth2 input[required], .has-tls input[required], .sspi input[required]')) {
127+
for (const input of document.querySelectorAll<HTMLInputElement>('.ldap input[required], .binddnrequired input[required], .dldap input[required], .smtp input[required], .pam input[required], .oauth2 input[required], .has-tls input[required], .sspi input[required]')) {
127128
input.removeAttribute('required');
128129
}
129130

130-
document.querySelector('.binddnrequired')?.classList.remove('required');
131+
document.querySelector<HTMLDivElement>('.binddnrequired')?.classList.remove('required');
131132

132133
const authType = this.value;
133134
switch (authType) {
134135
case '2': // LDAP
135136
showElem('.ldap');
136-
for (const input of document.querySelectorAll('.binddnrequired input, .ldap div.required:not(.dldap) input')) {
137+
for (const input of document.querySelectorAll<HTMLInputElement>('.binddnrequired input, .ldap div.required:not(.dldap) input')) {
137138
input.setAttribute('required', 'required');
138139
}
139140
document.querySelector('.binddnrequired')?.classList.add('required');
140141
break;
141142
case '3': // SMTP
142143
showElem('.smtp');
143144
showElem('.has-tls');
144-
for (const input of document.querySelectorAll('.smtp div.required input, .has-tls')) {
145+
for (const input of document.querySelectorAll<HTMLInputElement>('.smtp div.required input, .has-tls')) {
145146
input.setAttribute('required', 'required');
146147
}
147148
break;
148149
case '4': // PAM
149150
showElem('.pam');
150-
for (const input of document.querySelectorAll('.pam input')) {
151+
for (const input of document.querySelectorAll<HTMLInputElement>('.pam input')) {
151152
input.setAttribute('required', 'required');
152153
}
153154
break;
154155
case '5': // LDAP
155156
showElem('.dldap');
156-
for (const input of document.querySelectorAll('.dldap div.required:not(.ldap) input')) {
157+
for (const input of document.querySelectorAll<HTMLInputElement>('.dldap div.required:not(.ldap) input')) {
157158
input.setAttribute('required', 'required');
158159
}
159160
break;
160161
case '6': // OAuth2
161162
showElem('.oauth2');
162-
for (const input of document.querySelectorAll('.oauth2 div.required:not(.oauth2_use_custom_url,.oauth2_use_custom_url_field,.open_id_connect_auto_discovery_url) input')) {
163+
for (const input of document.querySelectorAll<HTMLInputElement>('.oauth2 div.required:not(.oauth2_use_custom_url,.oauth2_use_custom_url_field,.open_id_connect_auto_discovery_url) input')) {
163164
input.setAttribute('required', 'required');
164165
}
165166
onOAuth2Change(true);
166167
break;
167168
case '7': // SSPI
168169
showElem('.sspi');
169-
for (const input of document.querySelectorAll('.sspi div.required input')) {
170+
for (const input of document.querySelectorAll<HTMLInputElement>('.sspi div.required input')) {
170171
input.setAttribute('required', 'required');
171172
}
172173
break;
@@ -180,39 +181,39 @@ export function initAdminCommon() {
180181
}
181182
});
182183
$('#auth_type').trigger('change');
183-
document.querySelector('#security_protocol')?.addEventListener('change', onSecurityProtocolChange);
184-
document.querySelector('#use_paged_search')?.addEventListener('change', onUsePagedSearchChange);
185-
document.querySelector('#oauth2_provider')?.addEventListener('change', () => onOAuth2Change(true));
186-
document.querySelector('#oauth2_use_custom_url')?.addEventListener('change', () => onOAuth2UseCustomURLChange(true));
184+
document.querySelector<HTMLInputElement>('#security_protocol')?.addEventListener('change', onSecurityProtocolChange);
185+
document.querySelector<HTMLInputElement>('#use_paged_search')?.addEventListener('change', onUsePagedSearchChange);
186+
document.querySelector<HTMLInputElement>('#oauth2_provider')?.addEventListener('change', () => onOAuth2Change(true));
187+
document.querySelector<HTMLInputElement>('#oauth2_use_custom_url')?.addEventListener('change', () => onOAuth2UseCustomURLChange(true));
187188
$('.js-ldap-group-toggle').on('change', onEnableLdapGroupsChange);
188189
}
189190
// Edit authentication
190-
if (document.querySelector('.admin.edit.authentication')) {
191-
const authType = document.querySelector('#auth_type')?.value;
191+
if (document.querySelector<HTMLDivElement>('.admin.edit.authentication')) {
192+
const authType = document.querySelector<HTMLInputElement>('#auth_type')?.value;
192193
if (authType === '2' || authType === '5') {
193-
document.querySelector('#security_protocol')?.addEventListener('change', onSecurityProtocolChange);
194+
document.querySelector<HTMLInputElement>('#security_protocol')?.addEventListener('change', onSecurityProtocolChange);
194195
$('.js-ldap-group-toggle').on('change', onEnableLdapGroupsChange);
195196
onEnableLdapGroupsChange();
196197
if (authType === '2') {
197-
document.querySelector('#use_paged_search')?.addEventListener('change', onUsePagedSearchChange);
198+
document.querySelector<HTMLInputElement>('#use_paged_search')?.addEventListener('change', onUsePagedSearchChange);
198199
}
199200
} else if (authType === '6') {
200-
document.querySelector('#oauth2_provider')?.addEventListener('change', () => onOAuth2Change(true));
201-
document.querySelector('#oauth2_use_custom_url')?.addEventListener('change', () => onOAuth2UseCustomURLChange(false));
201+
document.querySelector<HTMLInputElement>('#oauth2_provider')?.addEventListener('change', () => onOAuth2Change(true));
202+
document.querySelector<HTMLInputElement>('#oauth2_use_custom_url')?.addEventListener('change', () => onOAuth2UseCustomURLChange(false));
202203
onOAuth2Change(false);
203204
}
204205
}
205206

206-
if (document.querySelector('.admin.authentication')) {
207+
if (document.querySelector<HTMLDivElement>('.admin.authentication')) {
207208
$('#auth_name').on('input', function () {
208209
// appSubUrl is either empty or is a path that starts with `/` and doesn't have a trailing slash.
209-
document.querySelector('#oauth2-callback-url').textContent = `${window.location.origin}${appSubUrl}/user/oauth2/${encodeURIComponent(this.value)}/callback`;
210+
document.querySelector('#oauth2-callback-url').textContent = `${window.location.origin}${appSubUrl}/user/oauth2/${encodeURIComponent((this as HTMLInputElement).value)}/callback`;
210211
}).trigger('input');
211212
}
212213

213214
// Notice
214-
if (document.querySelector('.admin.notice')) {
215-
const detailModal = document.querySelector('#detail-modal');
215+
if (document.querySelector<HTMLDivElement>('.admin.notice')) {
216+
const detailModal = document.querySelector<HTMLDivElement>('#detail-modal');
216217

217218
// Attach view detail modals
218219
$('.view-detail').on('click', function () {
@@ -223,7 +224,7 @@ export function initAdminCommon() {
223224
});
224225

225226
// Select actions
226-
const checkboxes = document.querySelectorAll('.select.table .ui.checkbox input');
227+
const checkboxes = document.querySelectorAll<HTMLInputElement>('.select.table .ui.checkbox input');
227228

228229
$('.select.action').on('click', function () {
229230
switch ($(this).data('action')) {
@@ -244,7 +245,7 @@ export function initAdminCommon() {
244245
break;
245246
}
246247
});
247-
document.querySelector('#delete-selection')?.addEventListener('click', async function (e) {
248+
document.querySelector<HTMLButtonElement>('#delete-selection')?.addEventListener('click', async function (e) {
248249
e.preventDefault();
249250
this.classList.add('is-loading', 'disabled');
250251
const data = new FormData();

web_src/js/features/admin/config.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import {POST} from '../../modules/fetch.ts';
33

44
const {appSubUrl} = window.config;
55

6-
export function initAdminConfigs() {
7-
const elAdminConfig = document.querySelector('.page-content.admin.config');
6+
export function initAdminConfigs(): void {
7+
const elAdminConfig = document.querySelector<HTMLDivElement>('.page-content.admin.config');
88
if (!elAdminConfig) return;
99

10-
for (const el of elAdminConfig.querySelectorAll('input[type="checkbox"][data-config-dyn-key]')) {
10+
for (const el of elAdminConfig.querySelectorAll<HTMLInputElement>('input[type="checkbox"][data-config-dyn-key]')) {
1111
el.addEventListener('change', async () => {
1212
try {
1313
const resp = await POST(`${appSubUrl}/-/admin/config`, {
14-
data: new URLSearchParams({key: el.getAttribute('data-config-dyn-key'), value: el.checked}),
14+
data: new URLSearchParams({key: el.getAttribute('data-config-dyn-key'), value: String(el.checked)}),
1515
});
16-
const json = await resp.json();
16+
const json: Record<string, any> = await resp.json();
1717
if (json.errorMessage) throw new Error(json.errorMessage);
1818
} catch (ex) {
1919
showTemporaryTooltip(el, ex.toString());

web_src/js/features/admin/emails.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import $ from 'jquery';
22

3-
export function initAdminEmails() {
4-
function linkEmailAction(e) {
3+
export function initAdminEmails(): void {
4+
$('.link-email-action').on('click', (e) => {
55
const $this = $(this);
66
$('#form-uid').val($this.data('uid'));
77
$('#form-email').val($this.data('email'));
88
$('#form-primary').val($this.data('primary'));
99
$('#form-activate').val($this.data('activate'));
1010
$('#change-email-modal').modal('show');
1111
e.preventDefault();
12-
}
13-
$('.link-email-action').on('click', linkEmailAction);
12+
});
1413
}

web_src/js/features/admin/selfcheck.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ export async function initAdminSelfCheck() {
77
const elCheckByFrontend = document.querySelector('#self-check-by-frontend');
88
if (!elCheckByFrontend) return;
99

10-
const elContent = document.querySelector('.page-content.admin .admin-setting-content');
10+
const elContent = document.querySelector<HTMLDivElement>('.page-content.admin .admin-setting-content');
1111

1212
// send frontend self-check request
1313
const resp = await POST(`${appSubUrl}/-/admin/self_check`, {
1414
data: new URLSearchParams({
1515
location_origin: window.location.origin,
16-
now: Date.now(), // TODO: check time difference between server and client
16+
now: String(Date.now()), // TODO: check time difference between server and client
1717
}),
1818
});
19-
const json = await resp.json();
19+
const json: Record<string, any> = await resp.json();
2020
toggleElem(elCheckByFrontend, Boolean(json.problems?.length));
2121
for (const problem of json.problems ?? []) {
2222
const elProblem = document.createElement('div');

web_src/js/features/admin/users.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export function initAdminUserListSearchForm() {
1+
export function initAdminUserListSearchForm(): void {
22
const searchForm = window.config.pageData.adminUserListSearchForm;
33
if (!searchForm) return;
44

5-
const form = document.querySelector('#user-list-search-form');
5+
const form = document.querySelector<HTMLFormElement>('#user-list-search-form');
66
if (!form) return;
77

88
for (const button of form.querySelectorAll(`button[name=sort][value="${searchForm.SortType}"]`)) {
@@ -12,23 +12,23 @@ export function initAdminUserListSearchForm() {
1212
if (searchForm.StatusFilterMap) {
1313
for (const [k, v] of Object.entries(searchForm.StatusFilterMap)) {
1414
if (!v) continue;
15-
for (const input of form.querySelectorAll(`input[name="status_filter[${k}]"][value="${v}"]`)) {
15+
for (const input of form.querySelectorAll<HTMLInputElement>(`input[name="status_filter[${k}]"][value="${v}"]`)) {
1616
input.checked = true;
1717
}
1818
}
1919
}
2020

21-
for (const radio of form.querySelectorAll('input[type=radio]')) {
21+
for (const radio of form.querySelectorAll<HTMLInputElement>('input[type=radio]')) {
2222
radio.addEventListener('click', () => {
2323
form.submit();
2424
});
2525
}
2626

27-
const resetButtons = form.querySelectorAll('.j-reset-status-filter');
27+
const resetButtons = form.querySelectorAll<HTMLAnchorElement>('.j-reset-status-filter');
2828
for (const button of resetButtons) {
2929
button.addEventListener('click', (e) => {
3030
e.preventDefault();
31-
for (const input of form.querySelectorAll('input[type=radio]')) {
31+
for (const input of form.querySelectorAll<HTMLInputElement>('input[type=radio]')) {
3232
if (input.name.startsWith('status_filter[')) {
3333
input.checked = false;
3434
}

0 commit comments

Comments
 (0)