mirror of
https://github.com/go-gitea/gitea
synced 2025-07-19 08:48:37 +00:00
Enable Typescript noImplicitThis
(#33250)
- Enable https://www.typescriptlang.org/tsconfig/#noImplicitThis - Wrap Vue Template-Syntax SFCs in [`defineComponent`](https://vuejs.org/api/general#definecomponent) which makes type inference and linter work better - Move `createApp` calls outside the SFCs into separate files - Use [`PropType`](https://vuejs.org/api/utility-types#proptype-t) where appropriate - Some top-level component properties changed order as dictated by the linter - Fix all tsc and lint issues that popped up during these refactors
This commit is contained in:
@@ -6,7 +6,7 @@ export function initCommonOrganization() {
|
||||
return;
|
||||
}
|
||||
|
||||
document.querySelector('.organization.settings.options #org_name')?.addEventListener('input', function () {
|
||||
document.querySelector<HTMLInputElement>('.organization.settings.options #org_name')?.addEventListener('input', function () {
|
||||
const nameChanged = this.value.toLowerCase() !== this.getAttribute('data-org-name').toLowerCase();
|
||||
toggleElem('#org-name-change-prompt', nameChanged);
|
||||
});
|
||||
|
@@ -6,7 +6,7 @@ export function initCompWebHookEditor() {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const input of document.querySelectorAll('.events.checkbox input')) {
|
||||
for (const input of document.querySelectorAll<HTMLInputElement>('.events.checkbox input')) {
|
||||
input.addEventListener('change', function () {
|
||||
if (this.checked) {
|
||||
showElem('.events.fields');
|
||||
@@ -14,7 +14,7 @@ export function initCompWebHookEditor() {
|
||||
});
|
||||
}
|
||||
|
||||
for (const input of document.querySelectorAll('.non-events.checkbox input')) {
|
||||
for (const input of document.querySelectorAll<HTMLInputElement>('.non-events.checkbox input')) {
|
||||
input.addEventListener('change', function () {
|
||||
if (this.checked) {
|
||||
hideElem('.events.fields');
|
||||
@@ -34,7 +34,7 @@ export function initCompWebHookEditor() {
|
||||
}
|
||||
|
||||
// Test delivery
|
||||
document.querySelector('#test-delivery')?.addEventListener('click', async function () {
|
||||
document.querySelector<HTMLButtonElement>('#test-delivery')?.addEventListener('click', async function () {
|
||||
this.classList.add('is-loading', 'disabled');
|
||||
await POST(this.getAttribute('data-link'));
|
||||
setTimeout(() => {
|
||||
|
9
web_src/js/features/dashboard.ts
Normal file
9
web_src/js/features/dashboard.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import {createApp} from 'vue';
|
||||
import DashboardRepoList from '../components/DashboardRepoList.vue';
|
||||
|
||||
export function initDashboardRepoList() {
|
||||
const el = document.querySelector('#dashboard-repo-list');
|
||||
if (el) {
|
||||
createApp(DashboardRepoList).mount(el);
|
||||
}
|
||||
}
|
@@ -27,7 +27,7 @@ function initPreInstall() {
|
||||
const dbName = document.querySelector<HTMLInputElement>('#db_name');
|
||||
|
||||
// Database type change detection.
|
||||
document.querySelector('#db_type').addEventListener('change', function () {
|
||||
document.querySelector<HTMLInputElement>('#db_type').addEventListener('change', function () {
|
||||
const dbType = this.value;
|
||||
hideElem('div[data-db-setting-for]');
|
||||
showElem(`div[data-db-setting-for=${dbType}]`);
|
||||
@@ -59,26 +59,26 @@ function initPreInstall() {
|
||||
}
|
||||
|
||||
// TODO: better handling of exclusive relations.
|
||||
document.querySelector('#offline-mode input').addEventListener('change', function () {
|
||||
document.querySelector<HTMLInputElement>('#offline-mode input').addEventListener('change', function () {
|
||||
if (this.checked) {
|
||||
document.querySelector<HTMLInputElement>('#disable-gravatar input').checked = true;
|
||||
document.querySelector<HTMLInputElement>('#federated-avatar-lookup input').checked = false;
|
||||
}
|
||||
});
|
||||
document.querySelector('#disable-gravatar input').addEventListener('change', function () {
|
||||
document.querySelector<HTMLInputElement>('#disable-gravatar input').addEventListener('change', function () {
|
||||
if (this.checked) {
|
||||
document.querySelector<HTMLInputElement>('#federated-avatar-lookup input').checked = false;
|
||||
} else {
|
||||
document.querySelector<HTMLInputElement>('#offline-mode input').checked = false;
|
||||
}
|
||||
});
|
||||
document.querySelector('#federated-avatar-lookup input').addEventListener('change', function () {
|
||||
document.querySelector<HTMLInputElement>('#federated-avatar-lookup input').addEventListener('change', function () {
|
||||
if (this.checked) {
|
||||
document.querySelector<HTMLInputElement>('#disable-gravatar input').checked = false;
|
||||
document.querySelector<HTMLInputElement>('#offline-mode input').checked = false;
|
||||
}
|
||||
});
|
||||
document.querySelector('#enable-openid-signin input').addEventListener('change', function () {
|
||||
document.querySelector<HTMLInputElement>('#enable-openid-signin input').addEventListener('change', function () {
|
||||
if (this.checked) {
|
||||
if (!document.querySelector<HTMLInputElement>('#disable-registration input').checked) {
|
||||
document.querySelector<HTMLInputElement>('#enable-openid-signup input').checked = true;
|
||||
@@ -87,7 +87,7 @@ function initPreInstall() {
|
||||
document.querySelector<HTMLInputElement>('#enable-openid-signup input').checked = false;
|
||||
}
|
||||
});
|
||||
document.querySelector('#disable-registration input').addEventListener('change', function () {
|
||||
document.querySelector<HTMLInputElement>('#disable-registration input').addEventListener('change', function () {
|
||||
if (this.checked) {
|
||||
document.querySelector<HTMLInputElement>('#enable-captcha input').checked = false;
|
||||
document.querySelector<HTMLInputElement>('#enable-openid-signup input').checked = false;
|
||||
@@ -95,7 +95,7 @@ function initPreInstall() {
|
||||
document.querySelector<HTMLInputElement>('#enable-openid-signup input').checked = true;
|
||||
}
|
||||
});
|
||||
document.querySelector('#enable-captcha input').addEventListener('change', function () {
|
||||
document.querySelector<HTMLInputElement>('#enable-captcha input').addEventListener('change', function () {
|
||||
if (this.checked) {
|
||||
document.querySelector<HTMLInputElement>('#disable-registration input').checked = false;
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ export function initViewedCheckboxListenerFor() {
|
||||
|
||||
// The checkbox consists of a div containing the real checkbox with its label and the CSRF token,
|
||||
// hence the actual checkbox first has to be found
|
||||
const checkbox = form.querySelector('input[type=checkbox]');
|
||||
const checkbox = form.querySelector<HTMLInputElement>('input[type=checkbox]');
|
||||
checkbox.addEventListener('input', function() {
|
||||
// Mark the file as viewed visually - will especially change the background
|
||||
if (this.checked) {
|
||||
|
47
web_src/js/features/repo-actions.ts
Normal file
47
web_src/js/features/repo-actions.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import {createApp} from 'vue';
|
||||
import RepoActionView from '../components/RepoActionView.vue';
|
||||
|
||||
export function initRepositoryActionView() {
|
||||
const el = document.querySelector('#repo-action-view');
|
||||
if (!el) return;
|
||||
|
||||
// TODO: the parent element's full height doesn't work well now,
|
||||
// but we can not pollute the global style at the moment, only fix the height problem for pages with this component
|
||||
const parentFullHeight = document.querySelector<HTMLElement>('body > div.full.height');
|
||||
if (parentFullHeight) parentFullHeight.style.paddingBottom = '0';
|
||||
|
||||
const view = createApp(RepoActionView, {
|
||||
runIndex: el.getAttribute('data-run-index'),
|
||||
jobIndex: el.getAttribute('data-job-index'),
|
||||
actionsURL: el.getAttribute('data-actions-url'),
|
||||
locale: {
|
||||
approve: el.getAttribute('data-locale-approve'),
|
||||
cancel: el.getAttribute('data-locale-cancel'),
|
||||
rerun: el.getAttribute('data-locale-rerun'),
|
||||
rerun_all: el.getAttribute('data-locale-rerun-all'),
|
||||
scheduled: el.getAttribute('data-locale-runs-scheduled'),
|
||||
commit: el.getAttribute('data-locale-runs-commit'),
|
||||
pushedBy: el.getAttribute('data-locale-runs-pushed-by'),
|
||||
artifactsTitle: el.getAttribute('data-locale-artifacts-title'),
|
||||
areYouSure: el.getAttribute('data-locale-are-you-sure'),
|
||||
confirmDeleteArtifact: el.getAttribute('data-locale-confirm-delete-artifact'),
|
||||
showTimeStamps: el.getAttribute('data-locale-show-timestamps'),
|
||||
showLogSeconds: el.getAttribute('data-locale-show-log-seconds'),
|
||||
showFullScreen: el.getAttribute('data-locale-show-full-screen'),
|
||||
downloadLogs: el.getAttribute('data-locale-download-logs'),
|
||||
status: {
|
||||
unknown: el.getAttribute('data-locale-status-unknown'),
|
||||
waiting: el.getAttribute('data-locale-status-waiting'),
|
||||
running: el.getAttribute('data-locale-status-running'),
|
||||
success: el.getAttribute('data-locale-status-success'),
|
||||
failure: el.getAttribute('data-locale-status-failure'),
|
||||
cancelled: el.getAttribute('data-locale-status-cancelled'),
|
||||
skipped: el.getAttribute('data-locale-status-skipped'),
|
||||
blocked: el.getAttribute('data-locale-status-blocked'),
|
||||
},
|
||||
logsAlwaysAutoScroll: el.getAttribute('data-locale-logs-always-auto-scroll'),
|
||||
logsAlwaysExpandRunning: el.getAttribute('data-locale-logs-always-expand-running'),
|
||||
},
|
||||
});
|
||||
view.mount(el);
|
||||
}
|
@@ -2,7 +2,7 @@ import {createTippy} from '../modules/tippy.ts';
|
||||
import {toggleElem} from '../utils/dom.ts';
|
||||
|
||||
export function initRepoEllipsisButton() {
|
||||
for (const button of document.querySelectorAll('.js-toggle-commit-body')) {
|
||||
for (const button of document.querySelectorAll<HTMLButtonElement>('.js-toggle-commit-body')) {
|
||||
button.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
const expanded = this.getAttribute('aria-expanded') === 'true';
|
||||
|
@@ -89,7 +89,7 @@ export function initRepoTopicBar() {
|
||||
url: `${appSubUrl}/explore/topics/search?q={query}`,
|
||||
throttle: 500,
|
||||
cache: false,
|
||||
onResponse(res) {
|
||||
onResponse(this: any, res: any) {
|
||||
const formattedResponse = {
|
||||
success: false,
|
||||
results: [],
|
||||
|
@@ -216,7 +216,7 @@ export function initRepoIssueCodeCommentCancel() {
|
||||
|
||||
export function initRepoPullRequestUpdate() {
|
||||
// Pull Request update button
|
||||
const pullUpdateButton = document.querySelector('.update-button > button');
|
||||
const pullUpdateButton = document.querySelector<HTMLButtonElement>('.update-button > button');
|
||||
if (!pullUpdateButton) return;
|
||||
|
||||
pullUpdateButton.addEventListener('click', async function (e) {
|
||||
|
@@ -79,21 +79,21 @@ function initRepoSettingsGitHook() {
|
||||
function initRepoSettingsBranches() {
|
||||
if (!document.querySelector('.repository.settings.branches')) return;
|
||||
|
||||
for (const el of document.querySelectorAll('.toggle-target-enabled')) {
|
||||
for (const el of document.querySelectorAll<HTMLInputElement>('.toggle-target-enabled')) {
|
||||
el.addEventListener('change', function () {
|
||||
const target = document.querySelector(this.getAttribute('data-target'));
|
||||
target?.classList.toggle('disabled', !this.checked);
|
||||
});
|
||||
}
|
||||
|
||||
for (const el of document.querySelectorAll('.toggle-target-disabled')) {
|
||||
for (const el of document.querySelectorAll<HTMLInputElement>('.toggle-target-disabled')) {
|
||||
el.addEventListener('change', function () {
|
||||
const target = document.querySelector(this.getAttribute('data-target'));
|
||||
if (this.checked) target?.classList.add('disabled'); // only disable, do not auto enable
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelector('#dismiss_stale_approvals')?.addEventListener('change', function () {
|
||||
document.querySelector<HTMLInputElement>('#dismiss_stale_approvals')?.addEventListener('change', function () {
|
||||
document.querySelector('#ignore_stale_approvals_box')?.classList.toggle('disabled', this.checked);
|
||||
});
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
export function initSshKeyFormParser() {
|
||||
// Parse SSH Key
|
||||
document.querySelector('#ssh-key-content')?.addEventListener('input', function () {
|
||||
document.querySelector<HTMLTextAreaElement>('#ssh-key-content')?.addEventListener('input', function () {
|
||||
const arrays = this.value.split(' ');
|
||||
const title = document.querySelector<HTMLInputElement>('#ssh-key-title');
|
||||
if (!title.value && arrays.length === 3 && arrays[2] !== '') {
|
||||
|
@@ -13,7 +13,7 @@ export function initUserSettings() {
|
||||
|
||||
initUserSettingsAvatarCropper();
|
||||
|
||||
const usernameInput = document.querySelector('#username');
|
||||
const usernameInput = document.querySelector<HTMLInputElement>('#username');
|
||||
if (!usernameInput) return;
|
||||
usernameInput.addEventListener('input', function () {
|
||||
const prompt = document.querySelector('#name-change-prompt');
|
||||
|
Reference in New Issue
Block a user