{{template "repo/header" .}} -
-

- {{DateTime "long" .DateFrom}} - {{DateTime "long" .DateUntil}} - - -

-
- - {{if (or (.Permission.CanRead $.UnitTypeIssues) (.Permission.CanRead $.UnitTypePullRequests))}} -

{{ctx.Locale.Tr "repo.activity.overview"}}

-
- {{if .Permission.CanRead $.UnitTypePullRequests}} -
- {{if gt .Activity.ActivePRCount 0}} -
- - -
- {{else}} -
- -
- {{end}} - {{ctx.Locale.TrN .Activity.ActivePRCount "repo.activity.active_prs_count_1" "repo.activity.active_prs_count_n" .Activity.ActivePRCount | Safe}} -
- {{end}} - {{if .Permission.CanRead $.UnitTypeIssues}} -
- {{if gt .Activity.ActiveIssueCount 0}} -
- - -
- {{else}} -
- -
- {{end}} - {{ctx.Locale.TrN .Activity.ActiveIssueCount "repo.activity.active_issues_count_1" "repo.activity.active_issues_count_n" .Activity.ActiveIssueCount | Safe}} -
- {{end}} +
+
+ {{template "repo/navbar" .}}
-
- {{if .Permission.CanRead $.UnitTypePullRequests}} - - {{svg "octicon-git-pull-request"}} {{.Activity.MergedPRCount}}
- {{ctx.Locale.TrN .Activity.MergedPRCount "repo.activity.merged_prs_count_1" "repo.activity.merged_prs_count_n"}} -
- - {{svg "octicon-git-branch"}} {{.Activity.OpenedPRCount}}
- {{ctx.Locale.TrN .Activity.OpenedPRCount "repo.activity.opened_prs_count_1" "repo.activity.opened_prs_count_n"}} -
- {{end}} - {{if .Permission.CanRead $.UnitTypeIssues}} - - {{svg "octicon-issue-closed"}} {{.Activity.ClosedIssueCount}}
- {{ctx.Locale.TrN .Activity.ClosedIssueCount "repo.activity.closed_issues_count_1" "repo.activity.closed_issues_count_n"}} -
- - {{svg "octicon-issue-opened"}} {{.Activity.OpenedIssueCount}}
- {{ctx.Locale.TrN .Activity.OpenedIssueCount "repo.activity.new_issues_count_1" "repo.activity.new_issues_count_n"}} -
- {{end}} +
+ {{if .PageIsPulse}}{{template "repo/pulse" .}}{{end}} + {{if .PageIsContributors}}{{template "repo/contributors" .}}{{end}}
- {{end}} - - {{if .Permission.CanRead $.UnitTypeCode}} - {{if eq .Activity.Code.CommitCountInAllBranches 0}} -
-

{{ctx.Locale.Tr "repo.activity.no_git_activity"}}

-
- {{end}} - {{if gt .Activity.Code.CommitCountInAllBranches 0}} -
-
- {{ctx.Locale.Tr "repo.activity.git_stats_exclude_merges"}} - {{ctx.Locale.TrN .Activity.Code.AuthorCount "repo.activity.git_stats_author_1" "repo.activity.git_stats_author_n" .Activity.Code.AuthorCount}} - {{ctx.Locale.TrN .Activity.Code.AuthorCount "repo.activity.git_stats_pushed_1" "repo.activity.git_stats_pushed_n"}} - {{ctx.Locale.TrN .Activity.Code.CommitCount "repo.activity.git_stats_commit_1" "repo.activity.git_stats_commit_n" .Activity.Code.CommitCount}} - {{ctx.Locale.Tr "repo.activity.git_stats_push_to_branch" .Repository.DefaultBranch}} - {{ctx.Locale.TrN .Activity.Code.CommitCountInAllBranches "repo.activity.git_stats_commit_1" "repo.activity.git_stats_commit_n" .Activity.Code.CommitCountInAllBranches}} - {{ctx.Locale.Tr "repo.activity.git_stats_push_to_all_branches"}} - {{ctx.Locale.Tr "repo.activity.git_stats_on_default_branch" .Repository.DefaultBranch}} - {{ctx.Locale.TrN .Activity.Code.ChangedFiles "repo.activity.git_stats_file_1" "repo.activity.git_stats_file_n" .Activity.Code.ChangedFiles}} - {{ctx.Locale.TrN .Activity.Code.ChangedFiles "repo.activity.git_stats_files_changed_1" "repo.activity.git_stats_files_changed_n"}} - {{ctx.Locale.Tr "repo.activity.git_stats_additions"}} - {{ctx.Locale.TrN .Activity.Code.Additions "repo.activity.git_stats_addition_1" "repo.activity.git_stats_addition_n" .Activity.Code.Additions}} - {{ctx.Locale.Tr "repo.activity.git_stats_and_deletions"}} - {{ctx.Locale.TrN .Activity.Code.Deletions "repo.activity.git_stats_deletion_1" "repo.activity.git_stats_deletion_n" .Activity.Code.Deletions}}. -
-
-
-
-
- {{end}} - {{end}} - - {{if gt .Activity.PublishedReleaseCount 0}} -

- {{svg "octicon-tag" 16 "gt-mr-3"}} - {{ctx.Locale.Tr "repo.activity.title.releases_published_by" - (ctx.Locale.TrN .Activity.PublishedReleaseCount "repo.activity.title.releases_1" "repo.activity.title.releases_n" .Activity.PublishedReleaseCount) - (ctx.Locale.TrN .Activity.PublishedReleaseAuthorCount "repo.activity.title.user_1" "repo.activity.title.user_n" .Activity.PublishedReleaseAuthorCount) - }} -

-
- {{range .Activity.PublishedReleases}} -

- {{ctx.Locale.Tr "repo.activity.published_release_label"}} - {{.TagName}} - {{if not .IsTag}} - {{.Title | RenderEmoji $.Context | RenderCodeBlock}} - {{end}} - {{TimeSinceUnix .CreatedUnix ctx.Locale}} -

- {{end}} -
- {{end}} - - {{if gt .Activity.MergedPRCount 0}} -

- {{svg "octicon-git-pull-request" 16 "gt-mr-3"}} - {{ctx.Locale.Tr "repo.activity.title.prs_merged_by" - (ctx.Locale.TrN .Activity.MergedPRCount "repo.activity.title.prs_1" "repo.activity.title.prs_n" .Activity.MergedPRCount) - (ctx.Locale.TrN .Activity.MergedPRAuthorCount "repo.activity.title.user_1" "repo.activity.title.user_n" .Activity.MergedPRAuthorCount) - }} -

-
- {{range .Activity.MergedPRs}} -

- {{ctx.Locale.Tr "repo.activity.merged_prs_label"}} - #{{.Index}} {{.Issue.Title | RenderEmoji $.Context | RenderCodeBlock}} - {{TimeSinceUnix .MergedUnix ctx.Locale}} -

- {{end}} -
- {{end}} - - {{if gt .Activity.OpenedPRCount 0}} -

- {{svg "octicon-git-branch" 16 "gt-mr-3"}} - {{ctx.Locale.Tr "repo.activity.title.prs_opened_by" - (ctx.Locale.TrN .Activity.OpenedPRCount "repo.activity.title.prs_1" "repo.activity.title.prs_n" .Activity.OpenedPRCount) - (ctx.Locale.TrN .Activity.OpenedPRAuthorCount "repo.activity.title.user_1" "repo.activity.title.user_n" .Activity.OpenedPRAuthorCount) - }} -

-
- {{range .Activity.OpenedPRs}} -

- {{ctx.Locale.Tr "repo.activity.opened_prs_label"}} - #{{.Index}} {{.Issue.Title | RenderEmoji $.Context | RenderCodeBlock}} - {{TimeSinceUnix .Issue.CreatedUnix ctx.Locale}} -

- {{end}} -
- {{end}} - - {{if gt .Activity.ClosedIssueCount 0}} -

- {{svg "octicon-issue-closed" 16 "gt-mr-3"}} - {{ctx.Locale.Tr "repo.activity.title.issues_closed_from" - (ctx.Locale.TrN .Activity.ClosedIssueCount "repo.activity.title.issues_1" "repo.activity.title.issues_n" .Activity.ClosedIssueCount) - (ctx.Locale.TrN .Activity.ClosedIssueAuthorCount "repo.activity.title.user_1" "repo.activity.title.user_n" .Activity.ClosedIssueAuthorCount) - }} -

-
- {{range .Activity.ClosedIssues}} -

- {{ctx.Locale.Tr "repo.activity.closed_issue_label"}} - #{{.Index}} {{.Title | RenderEmoji $.Context | RenderCodeBlock}} - {{TimeSinceUnix .ClosedUnix ctx.Locale}} -

- {{end}} -
- {{end}} - - {{if gt .Activity.OpenedIssueCount 0}} -

- {{svg "octicon-issue-opened" 16 "gt-mr-3"}} - {{ctx.Locale.Tr "repo.activity.title.issues_created_by" - (ctx.Locale.TrN .Activity.OpenedIssueCount "repo.activity.title.issues_1" "repo.activity.title.issues_n" .Activity.OpenedIssueCount) - (ctx.Locale.TrN .Activity.OpenedIssueAuthorCount "repo.activity.title.user_1" "repo.activity.title.user_n" .Activity.OpenedIssueAuthorCount) - }} -

-
- {{range .Activity.OpenedIssues}} -

- {{ctx.Locale.Tr "repo.activity.new_issue_label"}} - #{{.Index}} {{.Title | RenderEmoji $.Context | RenderCodeBlock}} - {{TimeSinceUnix .CreatedUnix ctx.Locale}} -

- {{end}} -
- {{end}} - - {{if gt .Activity.UnresolvedIssueCount 0}} -

- {{svg "octicon-comment-discussion" 16 "gt-mr-3"}} - {{ctx.Locale.TrN .Activity.UnresolvedIssueCount "repo.activity.title.unresolved_conv_1" "repo.activity.title.unresolved_conv_n" .Activity.UnresolvedIssueCount}} -

-
- {{range .Activity.UnresolvedIssues}} -

- {{ctx.Locale.Tr "repo.activity.unresolved_conv_label"}} - #{{.Index}} - {{if .IsPull}} - {{.Title | RenderEmoji $.Context | RenderCodeBlock}} - {{else}} - {{.Title | RenderEmoji $.Context | RenderCodeBlock}} - {{end}} - {{TimeSinceUnix .UpdatedUnix ctx.Locale}} -

- {{end}} -
- {{end}}
{{template "base/footer" .}} + diff --git a/templates/repo/contributors.tmpl b/templates/repo/contributors.tmpl new file mode 100644 index 0000000000..49a251c1f9 --- /dev/null +++ b/templates/repo/contributors.tmpl @@ -0,0 +1,13 @@ +{{if .Permission.CanRead $.UnitTypeCode}} +
+
+{{end}} diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 6fe0b39b52..086ffd85ff 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -5,9 +5,9 @@
{{template "repo/icon" .}}
{{if .IsArchived}} diff --git a/templates/repo/icon.tmpl b/templates/repo/icon.tmpl index 5a80b959d0..a001f81891 100644 --- a/templates/repo/icon.tmpl +++ b/templates/repo/icon.tmpl @@ -1,10 +1,10 @@ {{$avatarLink := (.RelAvatarLink ctx)}} {{if $avatarLink}} - {{.FullName}} + {{.FullName}} {{else if $.IsMirror}} - {{svg "octicon-mirror" 32}} + {{svg "octicon-mirror" 24}} {{else if $.IsFork}} - {{svg "octicon-repo-forked" 32}} + {{svg "octicon-repo-forked" 24}} {{else}} - {{svg "octicon-repo" 32}} + {{svg "octicon-repo" 24}} {{end}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 6c13eef023..22f67ade7b 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -2,7 +2,7 @@ {{template "repo/issue/branch_selector_field" .}} {{if .Issue.IsPull}} -
- +
{{end}} diff --git a/templates/user/settings/keys_principal.tmpl b/templates/user/settings/keys_principal.tmpl index 513afc2b61..a7ab12dd78 100644 --- a/templates/user/settings/keys_principal.tmpl +++ b/templates/user/settings/keys_principal.tmpl @@ -44,7 +44,7 @@
{{.CsrfTokenHtml}}
- +
diff --git a/templates/user/settings/keys_ssh.tmpl b/templates/user/settings/keys_ssh.tmpl index 01afb54c82..9a49cc4e8b 100644 --- a/templates/user/settings/keys_ssh.tmpl +++ b/templates/user/settings/keys_ssh.tmpl @@ -11,11 +11,11 @@ {{.CsrfTokenHtml}}
- +
- +
diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index 1f32aed0e8..d1c68656b6 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -22,8 +22,8 @@
- -

{{.SignedUser.Email}}

+ +

{{.SignedUser.Email}}

@@ -42,11 +42,11 @@
- +
- +
- - + +
diff --git a/templates/webhook/new.tmpl b/templates/webhook/new.tmpl index 60c729eee3..63bd8363b4 100644 --- a/templates/webhook/new.tmpl +++ b/templates/webhook/new.tmpl @@ -1,7 +1,12 @@

{{.CustomHeaderTitle}} -
- {{template "shared/webhook/icon" .ctxData}} +

diff --git a/tests/integration/auth_ldap_test.go b/tests/integration/auth_ldap_test.go index 2d69dfcfd7..3a5fdb97a6 100644 --- a/tests/integration/auth_ldap_test.go +++ b/tests/integration/auth_ldap_test.go @@ -179,7 +179,7 @@ func TestLDAPUserSignin(t *testing.T) { assert.Equal(t, u.UserName, htmlDoc.GetInputValueByName("name")) assert.Equal(t, u.FullName, htmlDoc.GetInputValueByName("full_name")) - assert.Equal(t, u.Email, htmlDoc.Find(`label[for="email"]`).Siblings().First().Text()) + assert.Equal(t, u.Email, htmlDoc.Find("#signed-user-email").Text()) } func TestLDAPAuthChange(t *testing.T) { diff --git a/web_src/css/base.css b/web_src/css/base.css index ea32aac6f7..0d547f16ff 100644 --- a/web_src/css/base.css +++ b/web_src/css/base.css @@ -413,6 +413,13 @@ ol.ui.list li, color: var(--color-text-light-2); } +/* extend fomantic style '.ui.dropdown > .text > img' to include svg.img */ +.ui.dropdown > .text > .img { + margin-left: 0; + float: none; + margin-right: 0.78571429rem; +} + .ui.dropdown > .text > .description, .ui.dropdown .menu > .item > .description { color: var(--color-text-light-2); diff --git a/web_src/js/components/.eslintrc.yaml b/web_src/js/components/.eslintrc.yaml index 0cab470f6b..0d233442bc 100644 --- a/web_src/js/components/.eslintrc.yaml +++ b/web_src/js/components/.eslintrc.yaml @@ -7,6 +7,10 @@ extends: - plugin:vue/vue3-recommended - plugin:vue-scoped-css/vue3-recommended +parserOptions: + sourceType: module + ecmaVersion: latest + env: browser: true diff --git a/web_src/js/components/RepoContributors.vue b/web_src/js/components/RepoContributors.vue new file mode 100644 index 0000000000..fa1545b3df --- /dev/null +++ b/web_src/js/components/RepoContributors.vue @@ -0,0 +1,443 @@ + + + diff --git a/web_src/js/features/common-organization.js b/web_src/js/features/common-organization.js index 352e824b05..442714a3d6 100644 --- a/web_src/js/features/common-organization.js +++ b/web_src/js/features/common-organization.js @@ -1,14 +1,13 @@ -import $ from 'jquery'; import {initCompLabelEdit} from './comp/LabelEdit.js'; import {toggleElem} from '../utils/dom.js'; export function initCommonOrganization() { - if ($('.organization').length === 0) { + if (!document.querySelectorAll('.organization').length) { return; } - $('.organization.settings.options #org_name').on('input', function () { - const nameChanged = $(this).val().toLowerCase() !== $(this).attr('data-org-name').toLowerCase(); + document.querySelector('.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); }); diff --git a/web_src/js/features/comp/QuickSubmit.js b/web_src/js/features/comp/QuickSubmit.js index 2587375a71..e6d7080bcf 100644 --- a/web_src/js/features/comp/QuickSubmit.js +++ b/web_src/js/features/comp/QuickSubmit.js @@ -1,5 +1,3 @@ -import $ from 'jquery'; - export function handleGlobalEnterQuickSubmit(target) { const form = target.closest('form'); if (form) { @@ -8,14 +6,9 @@ export function handleGlobalEnterQuickSubmit(target) { return; } - if (form.classList.contains('form-fetch-action')) { - form.dispatchEvent(new SubmitEvent('submit', {bubbles: true, cancelable: true})); - return; - } - // here use the event to trigger the submit event (instead of calling `submit()` method directly) // otherwise the `areYouSure` handler won't be executed, then there will be an annoying "confirm to leave" dialog - $(form).trigger('submit'); + form.dispatchEvent(new SubmitEvent('submit', {bubbles: true, cancelable: true})); } else { // if no form, then the editor is for an AJAX request, dispatch an event to the target, let the target's event handler to do the AJAX request. // the 'ce-' prefix means this is a CustomEvent diff --git a/web_src/js/features/comp/WebHookEditor.js b/web_src/js/features/comp/WebHookEditor.js index f4c82898fd..86d21dc815 100644 --- a/web_src/js/features/comp/WebHookEditor.js +++ b/web_src/js/features/comp/WebHookEditor.js @@ -1,43 +1,41 @@ -import $ from 'jquery'; +import {POST} from '../../modules/fetch.js'; import {hideElem, showElem, toggleElem} from '../../utils/dom.js'; -const {csrfToken} = window.config; - export function initCompWebHookEditor() { - if ($('.new.webhook').length === 0) { + if (!document.querySelectorAll('.new.webhook').length) { return; } - $('.events.checkbox input').on('change', function () { - if ($(this).is(':checked')) { - showElem($('.events.fields')); - } - }); - $('.non-events.checkbox input').on('change', function () { - if ($(this).is(':checked')) { - hideElem($('.events.fields')); - } - }); + for (const input of document.querySelectorAll('.events.checkbox input')) { + input.addEventListener('change', function () { + if (this.checked) { + showElem('.events.fields'); + } + }); + } + + for (const input of document.querySelectorAll('.non-events.checkbox input')) { + input.addEventListener('change', function () { + if (this.checked) { + hideElem('.events.fields'); + } + }); + } const updateContentType = function () { - const visible = $('#http_method').val() === 'POST'; - toggleElem($('#content_type').parent().parent(), visible); + const visible = document.getElementById('http_method').value === 'POST'; + toggleElem(document.getElementById('content_type').parentNode.parentNode, visible); }; updateContentType(); - $('#http_method').on('change', () => { - updateContentType(); - }); + + document.getElementById('http_method').addEventListener('change', updateContentType); // Test delivery - $('#test-delivery').on('click', function () { - const $this = $(this); - $this.addClass('loading disabled'); - $.post($this.data('link'), { - _csrf: csrfToken - }).done( - setTimeout(() => { - window.location.href = $this.data('redirect'); - }, 5000) - ); + document.getElementById('test-delivery')?.addEventListener('click', async function () { + this.classList.add('loading', 'disabled'); + await POST(this.getAttribute('data-link')); + setTimeout(() => { + window.location.href = this.getAttribute('data-redirect'); + }, 5000); }); } diff --git a/web_src/js/features/contextpopup.js b/web_src/js/features/contextpopup.js index 23a620b8a2..51363b810a 100644 --- a/web_src/js/features/contextpopup.js +++ b/web_src/js/features/contextpopup.js @@ -1,11 +1,10 @@ -import $ from 'jquery'; import {createApp} from 'vue'; import ContextPopup from '../components/ContextPopup.vue'; import {parseIssueHref} from '../utils.js'; import {createTippy} from '../modules/tippy.js'; export function initContextPopups() { - const refIssues = $('.ref-issue'); + const refIssues = document.querySelectorAll('.ref-issue'); attachRefIssueContextPopup(refIssues); } diff --git a/web_src/js/features/contributors.js b/web_src/js/features/contributors.js new file mode 100644 index 0000000000..66185ac315 --- /dev/null +++ b/web_src/js/features/contributors.js @@ -0,0 +1,28 @@ +import {createApp} from 'vue'; + +export async function initRepoContributors() { + const el = document.getElementById('repo-contributors-chart'); + if (!el) return; + + const {default: RepoContributors} = await import(/* webpackChunkName: "contributors-graph" */'../components/RepoContributors.vue'); + try { + const View = createApp(RepoContributors, { + locale: { + filterLabel: el.getAttribute('data-locale-filter-label'), + contributionType: { + commits: el.getAttribute('data-locale-contribution-type-commits'), + additions: el.getAttribute('data-locale-contribution-type-additions'), + deletions: el.getAttribute('data-locale-contribution-type-deletions'), + }, + + loadingTitle: el.getAttribute('data-locale-loading-title'), + loadingTitleFailed: el.getAttribute('data-locale-loading-title-failed'), + loadingInfo: el.getAttribute('data-locale-loading-info'), + } + }); + View.mount(el); + } catch (err) { + console.error('RepoContributors failed to load', err); + el.textContent = el.getAttribute('data-locale-component-failed-to-load'); + } +} diff --git a/web_src/js/features/repo-code.js b/web_src/js/features/repo-code.js index 306f38829f..a142313211 100644 --- a/web_src/js/features/repo-code.js +++ b/web_src/js/features/repo-code.js @@ -194,7 +194,7 @@ export function initRepoCodeView() { const blob = await $.get(`${url}?${query}&anchor=${anchor}`); currentTarget.closest('tr').outerHTML = blob; }); - $(document).on('click', '.copy-line-permalink', async (e) => { - await clippie(toAbsoluteUrl(e.currentTarget.getAttribute('data-url'))); + $(document).on('click', '.copy-line-permalink', async ({currentTarget}) => { + await clippie(toAbsoluteUrl(currentTarget.getAttribute('data-url'))); }); } diff --git a/web_src/js/features/repo-issue-list.js b/web_src/js/features/repo-issue-list.js index ca20cfbe38..efc7671204 100644 --- a/web_src/js/features/repo-issue-list.js +++ b/web_src/js/features/repo-issue-list.js @@ -69,16 +69,12 @@ function initRepoIssueListCheckboxes() { } } - updateIssuesMeta( - url, - action, - issueIDs, - elementId, - ).then(() => { + try { + await updateIssuesMeta(url, action, issueIDs, elementId); window.location.reload(); - }).catch((reason) => { - showErrorToast(reason.responseJSON.error); - }); + } catch (err) { + showErrorToast(err.responseJSON?.error ?? err.message); + } }); } diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 6908e0c912..3437565c80 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -344,19 +344,15 @@ export async function updateIssuesMeta(url, action, issueIds, elementId) { export function initRepoIssueComments() { if ($('.repository.view.issue .timeline').length === 0) return; - $('.re-request-review').on('click', function (e) { + $('.re-request-review').on('click', async function (e) { e.preventDefault(); const url = $(this).data('update-url'); const issueId = $(this).data('issue-id'); const id = $(this).data('id'); const isChecked = $(this).hasClass('checked'); - updateIssuesMeta( - url, - isChecked ? 'detach' : 'attach', - issueId, - id, - ).then(() => window.location.reload()); + await updateIssuesMeta(url, isChecked ? 'detach' : 'attach', issueId, id); + window.location.reload(); }); $(document).on('click', (event) => { diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 08fe21190a..ce1bff11a2 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -205,12 +205,15 @@ export function initRepoCommentForm() { $listMenu.find('.no-select.item').on('click', function (e) { e.preventDefault(); if (hasUpdateAction) { - updateIssuesMeta( - $listMenu.data('update-url'), - 'clear', - $listMenu.data('issue-id'), - '', - ).then(reloadConfirmDraftComment); + (async () => { + await updateIssuesMeta( + $listMenu.data('update-url'), + 'clear', + $listMenu.data('issue-id'), + '', + ); + reloadConfirmDraftComment(); + })(); } $(this).parent().find('.item').each(function () { @@ -248,12 +251,15 @@ export function initRepoCommentForm() { $(this).addClass('selected active'); if (hasUpdateAction) { - updateIssuesMeta( - $menu.data('update-url'), - '', - $menu.data('issue-id'), - $(this).data('id'), - ).then(reloadConfirmDraftComment); + (async () => { + await updateIssuesMeta( + $menu.data('update-url'), + '', + $menu.data('issue-id'), + $(this).data('id'), + ); + reloadConfirmDraftComment(); + })(); } let icon = ''; @@ -281,12 +287,15 @@ export function initRepoCommentForm() { }); if (hasUpdateAction) { - updateIssuesMeta( - $menu.data('update-url'), - '', - $menu.data('issue-id'), - $(this).data('id'), - ).then(reloadConfirmDraftComment); + (async () => { + await updateIssuesMeta( + $menu.data('update-url'), + '', + $menu.data('issue-id'), + $(this).data('id'), + ); + reloadConfirmDraftComment(); + })(); } $list.find('.selected').html(''); diff --git a/web_src/js/features/sshkey-helper.js b/web_src/js/features/sshkey-helper.js index 099b54d3a6..3960eefe8e 100644 --- a/web_src/js/features/sshkey-helper.js +++ b/web_src/js/features/sshkey-helper.js @@ -1,12 +1,10 @@ -import $ from 'jquery'; - export function initSshKeyFormParser() { -// Parse SSH Key - $('#ssh-key-content').on('change paste keyup', function () { - const arrays = $(this).val().split(' '); - const $title = $('#ssh-key-title'); - if ($title.val() === '' && arrays.length === 3 && arrays[2] !== '') { - $title.val(arrays[2]); + // Parse SSH Key + document.getElementById('ssh-key-content')?.addEventListener('input', function () { + const arrays = this.value.split(' '); + const title = document.getElementById('ssh-key-title'); + if (!title.value && arrays.length === 3 && arrays[2] !== '') { + title.value = arrays[2]; } }); } diff --git a/web_src/js/features/user-settings.js b/web_src/js/features/user-settings.js index d49bf39275..0dd908f34a 100644 --- a/web_src/js/features/user-settings.js +++ b/web_src/js/features/user-settings.js @@ -1,18 +1,19 @@ -import $ from 'jquery'; import {hideElem, showElem} from '../utils/dom.js'; export function initUserSettings() { - if ($('.user.settings.profile').length > 0) { - $('#username').on('keyup', function () { - const $prompt = $('#name-change-prompt'); - const $prompt_redirect = $('#name-change-redirect-prompt'); - if ($(this).val().toString().toLowerCase() !== $(this).data('name').toString().toLowerCase()) { - showElem($prompt); - showElem($prompt_redirect); - } else { - hideElem($prompt); - hideElem($prompt_redirect); - } - }); - } + if (document.querySelectorAll('.user.settings.profile').length === 0) return; + + const usernameInput = document.getElementById('username'); + if (!usernameInput) return; + usernameInput.addEventListener('input', function () { + const prompt = document.getElementById('name-change-prompt'); + const promptRedirect = document.getElementById('name-change-redirect-prompt'); + if (this.value.toLowerCase() !== this.getAttribute('data-name').toLowerCase()) { + showElem(prompt); + showElem(promptRedirect); + } else { + hideElem(prompt); + hideElem(promptRedirect); + } + }); } diff --git a/web_src/js/htmx.js b/web_src/js/htmx.js index 92400d1cbe..5ca3018308 100644 --- a/web_src/js/htmx.js +++ b/web_src/js/htmx.js @@ -1,6 +1,9 @@ import * as htmx from 'htmx.org'; import {showErrorToast} from './modules/toast.js'; +// https://github.com/bigskysoftware/idiomorph#htmx +import 'idiomorph/dist/idiomorph-ext.js'; + // https://htmx.org/reference/#config htmx.config.requestClass = 'is-loading'; htmx.config.scrollIntoViewOnBoost = false; diff --git a/web_src/js/index.js b/web_src/js/index.js index 4713618506..078f9fc9df 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -83,6 +83,7 @@ import {initGiteaFomantic} from './modules/fomantic.js'; import {onDomReady} from './utils/dom.js'; import {initRepoIssueList} from './features/repo-issue-list.js'; import {initCommonIssueListQuickGoto} from './features/common-issue-list.js'; +import {initRepoContributors} from './features/contributors.js'; import {initRepoDiffCommitBranchesAndTags} from './features/repo-diff-commit.js'; import {initDirAuto} from './modules/dirauto.js'; @@ -172,6 +173,7 @@ onDomReady(() => { initRepoWikiForm(); initRepository(); initRepositoryActionView(); + initRepoContributors(); initCommitStatuses(); initCaptcha(); diff --git a/web_src/js/markup/tasklist.js b/web_src/js/markup/tasklist.js index ad1c6964a7..00076bce58 100644 --- a/web_src/js/markup/tasklist.js +++ b/web_src/js/markup/tasklist.js @@ -1,4 +1,4 @@ -import $ from 'jquery'; +import {POST} from '../modules/fetch.js'; const preventListener = (e) => e.preventDefault(); @@ -55,12 +55,11 @@ export function initMarkupTasklist() { const updateUrl = editContentZone.getAttribute('data-update-url'); const context = editContentZone.getAttribute('data-context'); - await $.post(updateUrl, { - ignore_attachments: true, - _csrf: window.config.csrfToken, - content: newContent, - context - }); + const requestBody = new FormData(); + requestBody.append('ignore_attachments', 'true'); + requestBody.append('content', newContent); + requestBody.append('context', context); + await POST(updateUrl, {data: requestBody}); rawContent.textContent = newContent; } catch (err) { diff --git a/web_src/js/modules/fetch.js b/web_src/js/modules/fetch.js index b3529d27fc..2191a8d4db 100644 --- a/web_src/js/modules/fetch.js +++ b/web_src/js/modules/fetch.js @@ -8,19 +8,17 @@ const safeMethods = new Set(['GET', 'HEAD', 'OPTIONS', 'TRACE']); // fetch wrapper, use below method name functions and the `data` option to pass in data // which will automatically set an appropriate headers. For json content, only object // and array types are currently supported. -export function request(url, {method = 'GET', headers = {}, data, body, ...other} = {}) { - let contentType; - if (!body) { - if (data instanceof FormData || data instanceof URLSearchParams) { - body = data; - } else if (isObject(data) || Array.isArray(data)) { - contentType = 'application/json'; - body = JSON.stringify(data); - } +export function request(url, {method = 'GET', data, headers = {}, ...other} = {}) { + let body, contentType; + if (data instanceof FormData || data instanceof URLSearchParams) { + body = data; + } else if (isObject(data) || Array.isArray(data)) { + contentType = 'application/json'; + body = JSON.stringify(data); } const headersMerged = new Headers({ - ...(!safeMethods.has(method.toUpperCase()) && {'x-csrf-token': csrfToken}), + ...(!safeMethods.has(method) && {'x-csrf-token': csrfToken}), ...(contentType && {'content-type': contentType}), }); @@ -31,8 +29,8 @@ export function request(url, {method = 'GET', headers = {}, data, body, ...other return fetch(url, { method, headers: headersMerged, - ...(body && {body}), ...other, + ...(body && {body}), }); } diff --git a/web_src/js/utils/time.js b/web_src/js/utils/time.js new file mode 100644 index 0000000000..3284e893e1 --- /dev/null +++ b/web_src/js/utils/time.js @@ -0,0 +1,46 @@ +import dayjs from 'dayjs'; + +// Returns an array of millisecond-timestamps of start-of-week days (Sundays) +export function startDaysBetween(startDate, endDate) { + // Ensure the start date is a Sunday + while (startDate.getDay() !== 0) { + startDate.setDate(startDate.getDate() + 1); + } + + const start = dayjs(startDate); + const end = dayjs(endDate); + const startDays = []; + + let current = start; + while (current.isBefore(end)) { + startDays.push(current.valueOf()); + // we are adding 7 * 24 hours instead of 1 week because we don't want + // date library to use local time zone to calculate 1 week from now. + // local time zone is problematic because of daylight saving time (dst) + // used on some countries + current = current.add(7 * 24, 'hour'); + } + + return startDays; +} + +export function firstStartDateAfterDate(inputDate) { + if (!(inputDate instanceof Date)) { + throw new Error('Invalid date'); + } + const dayOfWeek = inputDate.getDay(); + const daysUntilSunday = 7 - dayOfWeek; + const resultDate = new Date(inputDate.getTime()); + resultDate.setDate(resultDate.getDate() + daysUntilSunday); + return resultDate.valueOf(); +} + +export function fillEmptyStartDaysWithZeroes(startDays, data) { + const result = {}; + + for (const startDay of startDays) { + result[startDay] = data[startDay] || {'week': startDay, 'additions': 0, 'deletions': 0, 'commits': 0}; + } + + return Object.values(result); +} diff --git a/web_src/js/utils/time.test.js b/web_src/js/utils/time.test.js new file mode 100644 index 0000000000..dd1114ce7f --- /dev/null +++ b/web_src/js/utils/time.test.js @@ -0,0 +1,15 @@ +import {startDaysBetween} from './time.js'; + +test('startDaysBetween', () => { + expect(startDaysBetween(new Date('2024-02-15'), new Date('2024-04-18'))).toEqual([ + 1708214400000, + 1708819200000, + 1709424000000, + 1710028800000, + 1710633600000, + 1711238400000, + 1711843200000, + 1712448000000, + 1713052800000, + ]); +}); diff --git a/webpack.config.js b/webpack.config.js index 3779e860d9..d4700ebe2b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -173,9 +173,13 @@ export default { ], }, plugins: [ + new webpack.ProvidePlugin({ // for htmx extensions + htmx: 'htmx.org', + }), new DefinePlugin({ __VUE_OPTIONS_API__: true, // at the moment, many Vue components still use the Vue Options API __VUE_PROD_DEVTOOLS__: false, // do not enable devtools support in production + __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false, // https://github.com/vuejs/vue-cli/pull/7443 }), new VueLoaderPlugin(), new MiniCssExtractPlugin({ @@ -210,6 +214,7 @@ export default { override: { 'khroma@*': {licenseName: 'MIT'}, // https://github.com/fabiospampinato/khroma/pull/33 'htmx.org@1.9.10': {licenseName: 'BSD-2-Clause'}, // "BSD 2-Clause" -> "BSD-2-Clause" + 'idiomorph@0.3.0': {licenseName: 'BSD-2-Clause'}, // "BSD 2-Clause" -> "BSD-2-Clause" }, emitError: true, allow: '(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT OR ISC OR CPAL-1.0 OR Unlicense OR EPL-1.0 OR EPL-2.0)',