diff options
author | TimedIn <git@timedin.net> | 2024-10-08 10:39:52 +0200 |
---|---|---|
committer | forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> | 2024-10-11 03:39:54 +0200 |
commit | 6d2c29ae85ba0d99a68fd6f801acc4ac56e604d3 (patch) | |
tree | 0669ef338d96bdb0574c56f8e376f4939eaf9a7f /web_src | |
parent | Merge pull request '[v9.0/forgejo] i18n: update of translations from Codeberg... (diff) | |
download | forgejo-6d2c29ae85ba0d99a68fd6f801acc4ac56e604d3.tar.xz forgejo-6d2c29ae85ba0d99a68fd6f801acc4ac56e604d3.zip |
feat: "assign to me" button on PRs and issues
includes:
Tests for assignees on issues
Move assignees selector of new Issue to assignees.tmpl
(cherry picked from commit 2feb3d03d73a89c0d52a174c92915ca3930f08a7)
Diffstat (limited to 'web_src')
-rw-r--r-- | web_src/js/features/repo-issue.js | 54 | ||||
-rw-r--r-- | web_src/js/features/repo-legacy.js | 22 |
2 files changed, 56 insertions, 20 deletions
diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index feba449c16..c4bd70b71d 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -12,6 +12,26 @@ import {emojiHTML} from './emoji.js'; const {appSubUrl} = window.config; +// if there are draft comments, confirm before reloading, to avoid losing comments +export function reloadConfirmDraftComment() { + const commentTextareas = [ + document.querySelector('.edit-content-zone:not(.tw-hidden) textarea'), + document.querySelector('#comment-form textarea'), + ]; + for (const textarea of commentTextareas) { + // Most users won't feel too sad if they lose a comment with 10 chars, they can re-type these in seconds. + // But if they have typed more (like 50) chars and the comment is lost, they will be very unhappy. + if (textarea && textarea.value.trim().length > 10) { + textarea.parentElement.scrollIntoView(); + if (!window.confirm('Page will be reloaded, but there are draft comments. Continuing to reload will discard the comments. Continue?')) { + return; + } + break; + } + } + window.location.reload(); +} + export function initRepoIssueTimeTracking() { $(document).on('click', '.issue-add-time', () => { $('.issue-start-time-modal').modal({ @@ -668,6 +688,40 @@ export function initRepoIssueBranchSelect() { }); } +export function initRepoIssueAssignMe() { + // Assign to me button + document.querySelector('.ui.assignees.list .item.no-select .select-assign-me') + ?.addEventListener('click', (e) => { + e.preventDefault(); + const selectMe = e.target; + const noSelect = selectMe.parentElement; + const selectorList = document.querySelector('.ui.select-assignees .menu'); + + if (selectMe.getAttribute('data-action') === 'update') { + (async () => { + await updateIssuesMeta( + selectMe.getAttribute('data-update-url'), + selectMe.getAttribute('data-action'), + selectMe.getAttribute('data-issue-id'), + selectMe.getAttribute('data-id'), + ); + reloadConfirmDraftComment(); + })(); + } else { + for (const item of selectorList.querySelectorAll('.item')) { + if (item.getAttribute('data-id') === selectMe.getAttribute('data-id')) { + item.classList.add('checked'); + item.querySelector('.octicon-check').classList.remove('tw-invisible'); + } + } + document.querySelector(selectMe.getAttribute('data-id-selector')).classList.remove('tw-hidden'); + noSelect.classList.add('tw-hidden'); + document.querySelector(selectorList.getAttribute('data-id')).value = selectMe.getAttribute('data-id'); + return false; + } + }); +} + export function initSingleCommentEditor($commentForm) { // pages: // * normal new issue/pr page, no status-button diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index b25fc28dea..cb92fcedb5 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -4,6 +4,7 @@ import { initRepoIssueComments, initRepoIssueDependencyDelete, initRepoIssueReferenceIssue, initRepoIssueTitleEdit, initRepoIssueWipToggle, initRepoPullRequestUpdate, updateIssuesMeta, handleReply, initIssueTemplateCommentEditors, initSingleCommentEditor, + initRepoIssueAssignMe, reloadConfirmDraftComment, } from './repo-issue.js'; import {initUnicodeEscapeButton} from './repo-unicode-escape.js'; import {svg} from '../svg.js'; @@ -29,26 +30,6 @@ import {POST, GET} from '../modules/fetch.js'; const {csrfToken} = window.config; -// if there are draft comments, confirm before reloading, to avoid losing comments -function reloadConfirmDraftComment() { - const commentTextareas = [ - document.querySelector('.edit-content-zone:not(.tw-hidden) textarea'), - document.querySelector('#comment-form textarea'), - ]; - for (const textarea of commentTextareas) { - // Most users won't feel too sad if they lose a comment with 10 chars, they can re-type these in seconds. - // But if they have typed more (like 50) chars and the comment is lost, they will be very unhappy. - if (textarea && textarea.value.trim().length > 10) { - textarea.parentElement.scrollIntoView(); - if (!window.confirm('Page will be reloaded, but there are draft comments. Continuing to reload will discard the comments. Continue?')) { - return; - } - break; - } - } - window.location.reload(); -} - export function initRepoCommentForm() { const $commentForm = $('.comment.form'); if (!$commentForm.length) return; @@ -243,6 +224,7 @@ export function initRepoCommentForm() { // Init labels and assignees initListSubmits('select-label', 'labels'); initListSubmits('select-assignees', 'assignees'); + initRepoIssueAssignMe(); initListSubmits('select-assignees-modify', 'assignees'); initListSubmits('select-reviewers-modify', 'assignees'); |