From c22d07df4dc4d5baf21d6840c592c89282c10397 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Thu, 30 Jun 2022 13:57:15 +0800 Subject: [PATCH 01/15] Add select all checkbox function --- templates/repo/issue/list.tmpl | 4 ++++ web_src/js/features/common-issue.js | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 04f7dcd6ae0d8..ca10ac2fbe4ac 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -28,6 +28,10 @@
+
+ + +
{{template "repo/issue/openclose" .}}
diff --git a/web_src/js/features/common-issue.js b/web_src/js/features/common-issue.js index e894816fb6b06..e4af32e1d78ac 100644 --- a/web_src/js/features/common-issue.js +++ b/web_src/js/features/common-issue.js @@ -2,14 +2,35 @@ import $ from 'jquery'; import {updateIssuesMeta} from './repo-issue.js'; export function initCommonIssue() { - $('.issue-checkbox').on('click', () => { - const numChecked = $('.issue-checkbox').children('input:checked').length; - if (numChecked > 0) { + $('.issue-checkbox,.issue-checkbox-all').on('click', (e) => { + const issuecheckbox = $('.issue-checkbox input'); + let allcheckbox; + if (e.currentTarget.className.indexOf('issue-checkbox-all') !== -1) { + allcheckbox = $('.issue-checkbox-all input'); + if (allcheckbox.prop('checked')) { + const selected = $('.issue-checkbox input:checked'); + $('.issue-checkbox input:not(:checked)').prop('checked', 1); + selected.prop('checked', 0); + } else { + $('.issue-checkbox input:checked').prop('checked', 0); + } + } + if (e.shiftKey && config.checkboxfirst !== undefined) { + for (let i = config.checkboxfirst + 1, j = issuecheckbox.index($(e.currentTarget).find('input')); i < j; i++) { + issuecheckbox[i].checked = 1; + } + delete config.checkboxfirst; + } else { + config.checkboxfirst = issuecheckbox.index($(e.currentTarget).find('input')); + } + if (issuecheckbox.is(':checked')) { $('#issue-filters').addClass('hide'); $('#issue-actions').removeClass('hide'); + $('#issue-actions .six').prepend($('.issue-checkbox-all')) } else { $('#issue-filters').removeClass('hide'); $('#issue-actions').addClass('hide'); + $('#issue-filters .six').prepend($('.issue-checkbox-all')) } }); From 732a690c0c7df84829281abdc4921a33fd9a0b30 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Thu, 30 Jun 2022 14:14:03 +0800 Subject: [PATCH 02/15] Fix lint problem --- web_src/js/features/common-issue.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/web_src/js/features/common-issue.js b/web_src/js/features/common-issue.js index e4af32e1d78ac..5e9cbe4c9b114 100644 --- a/web_src/js/features/common-issue.js +++ b/web_src/js/features/common-issue.js @@ -5,7 +5,7 @@ export function initCommonIssue() { $('.issue-checkbox,.issue-checkbox-all').on('click', (e) => { const issuecheckbox = $('.issue-checkbox input'); let allcheckbox; - if (e.currentTarget.className.indexOf('issue-checkbox-all') !== -1) { + if (e.currentTarget.className.includes('issue-checkbox-all')) { allcheckbox = $('.issue-checkbox-all input'); if (allcheckbox.prop('checked')) { const selected = $('.issue-checkbox input:checked'); @@ -15,22 +15,22 @@ export function initCommonIssue() { $('.issue-checkbox input:checked').prop('checked', 0); } } - if (e.shiftKey && config.checkboxfirst !== undefined) { - for (let i = config.checkboxfirst + 1, j = issuecheckbox.index($(e.currentTarget).find('input')); i < j; i++) { + if (e.shiftKey && window.config.checkboxfirst !== undefined) { + for (let i = window.config.checkboxfirst + 1, j = issuecheckbox.index($(e.currentTarget).find('input')); i < j; i++) { issuecheckbox[i].checked = 1; } - delete config.checkboxfirst; + delete window.config.checkboxfirst; } else { - config.checkboxfirst = issuecheckbox.index($(e.currentTarget).find('input')); + window.config.checkboxfirst = issuecheckbox.index($(e.currentTarget).find('input')); } if (issuecheckbox.is(':checked')) { $('#issue-filters').addClass('hide'); $('#issue-actions').removeClass('hide'); - $('#issue-actions .six').prepend($('.issue-checkbox-all')) + $('#issue-actions .six').prepend($('.issue-checkbox-all')); } else { $('#issue-filters').removeClass('hide'); $('#issue-actions').addClass('hide'); - $('#issue-filters .six').prepend($('.issue-checkbox-all')) + $('#issue-filters .six').prepend($('.issue-checkbox-all')); } }); From f9c2e5a71553388ace2c99138a3dbf591daa6a8c Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Thu, 30 Jun 2022 14:37:45 +0800 Subject: [PATCH 03/15] Remove a variable defined --- web_src/js/features/common-issue.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/web_src/js/features/common-issue.js b/web_src/js/features/common-issue.js index 5e9cbe4c9b114..e2e8f3f31ce61 100644 --- a/web_src/js/features/common-issue.js +++ b/web_src/js/features/common-issue.js @@ -4,10 +4,8 @@ import {updateIssuesMeta} from './repo-issue.js'; export function initCommonIssue() { $('.issue-checkbox,.issue-checkbox-all').on('click', (e) => { const issuecheckbox = $('.issue-checkbox input'); - let allcheckbox; if (e.currentTarget.className.includes('issue-checkbox-all')) { - allcheckbox = $('.issue-checkbox-all input'); - if (allcheckbox.prop('checked')) { + if ($('.issue-checkbox-all input').prop('checked')) { const selected = $('.issue-checkbox input:checked'); $('.issue-checkbox input:not(:checked)').prop('checked', 1); selected.prop('checked', 0); From 62e9f31ef0bf27482897d772d46e5b52d3ca4131 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Mon, 4 Jul 2022 15:19:20 +0800 Subject: [PATCH 04/15] Remove config name to storage global variable --- web_src/js/features/common-issue.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web_src/js/features/common-issue.js b/web_src/js/features/common-issue.js index e2e8f3f31ce61..e608839b80630 100644 --- a/web_src/js/features/common-issue.js +++ b/web_src/js/features/common-issue.js @@ -13,13 +13,13 @@ export function initCommonIssue() { $('.issue-checkbox input:checked').prop('checked', 0); } } - if (e.shiftKey && window.config.checkboxfirst !== undefined) { - for (let i = window.config.checkboxfirst + 1, j = issuecheckbox.index($(e.currentTarget).find('input')); i < j; i++) { + if (e.shiftKey && window.checkboxfirst !== undefined) { + for (let i = window.checkboxfirst + 1, j = issuecheckbox.index($(e.currentTarget).find('input')); i < j; i++) { issuecheckbox[i].checked = 1; } - delete window.config.checkboxfirst; + delete window.checkboxfirst; } else { - window.config.checkboxfirst = issuecheckbox.index($(e.currentTarget).find('input')); + window.checkboxfirst = issuecheckbox.index($(e.currentTarget).find('input')); } if (issuecheckbox.is(':checked')) { $('#issue-filters').addClass('hide'); From c29bb794b6bd047b8bd987cc580ab98c902518c0 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Mon, 4 Jul 2022 15:31:28 +0800 Subject: [PATCH 05/15] split checkbox click event function --- web_src/js/features/common-issue.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/web_src/js/features/common-issue.js b/web_src/js/features/common-issue.js index e608839b80630..df3e2d1d0ad4c 100644 --- a/web_src/js/features/common-issue.js +++ b/web_src/js/features/common-issue.js @@ -2,17 +2,8 @@ import $ from 'jquery'; import {updateIssuesMeta} from './repo-issue.js'; export function initCommonIssue() { - $('.issue-checkbox,.issue-checkbox-all').on('click', (e) => { + function checkboxOperate(e) { const issuecheckbox = $('.issue-checkbox input'); - if (e.currentTarget.className.includes('issue-checkbox-all')) { - if ($('.issue-checkbox-all input').prop('checked')) { - const selected = $('.issue-checkbox input:checked'); - $('.issue-checkbox input:not(:checked)').prop('checked', 1); - selected.prop('checked', 0); - } else { - $('.issue-checkbox input:checked').prop('checked', 0); - } - } if (e.shiftKey && window.checkboxfirst !== undefined) { for (let i = window.checkboxfirst + 1, j = issuecheckbox.index($(e.currentTarget).find('input')); i < j; i++) { issuecheckbox[i].checked = 1; @@ -30,6 +21,17 @@ export function initCommonIssue() { $('#issue-actions').addClass('hide'); $('#issue-filters .six').prepend($('.issue-checkbox-all')); } + } + + $('.issue-checkbox').on('click', (e) => { + checkboxOperate(e); + }); + + $('.issue-checkbox-all').on('click', (e) => { + const selected = $('.issue-checkbox input:checked'); + $('.issue-checkbox input:not(:checked)').prop('checked', 1); + selected.prop('checked', 0); + checkboxOperate(e); }); $('.issue-action').on('click', async function () { From 82a398525fd2da4ec318dcadf03834d9b723edb2 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Tue, 5 Jul 2022 08:19:32 +0800 Subject: [PATCH 06/15] Update web_src/js/features/common-issue.js Co-authored-by: Gusted --- web_src/js/features/common-issue.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/web_src/js/features/common-issue.js b/web_src/js/features/common-issue.js index df3e2d1d0ad4c..221efd4b839fc 100644 --- a/web_src/js/features/common-issue.js +++ b/web_src/js/features/common-issue.js @@ -23,9 +23,7 @@ export function initCommonIssue() { } } - $('.issue-checkbox').on('click', (e) => { - checkboxOperate(e); - }); + $('.issue-checkbox').on('click', checkboxOperate); $('.issue-checkbox-all').on('click', (e) => { const selected = $('.issue-checkbox input:checked'); From d9659db7f1e694ec2048175b0e90f224d582a355 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Tue, 5 Jul 2022 08:19:48 +0800 Subject: [PATCH 07/15] Update web_src/js/features/common-issue.js Co-authored-by: Gusted --- web_src/js/features/common-issue.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/common-issue.js b/web_src/js/features/common-issue.js index 221efd4b839fc..a102611562a73 100644 --- a/web_src/js/features/common-issue.js +++ b/web_src/js/features/common-issue.js @@ -2,7 +2,7 @@ import $ from 'jquery'; import {updateIssuesMeta} from './repo-issue.js'; export function initCommonIssue() { - function checkboxOperate(e) { + const checkboxOperate = (e) => { const issuecheckbox = $('.issue-checkbox input'); if (e.shiftKey && window.checkboxfirst !== undefined) { for (let i = window.checkboxfirst + 1, j = issuecheckbox.index($(e.currentTarget).find('input')); i < j; i++) { From 25fa1d85920d668ce07c3f8be2cac796a50ddd95 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Tue, 5 Jul 2022 10:02:18 +0800 Subject: [PATCH 08/15] Adjust global variable to private --- web_src/js/features/common-issue.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web_src/js/features/common-issue.js b/web_src/js/features/common-issue.js index a102611562a73..6d8fe55d63bc2 100644 --- a/web_src/js/features/common-issue.js +++ b/web_src/js/features/common-issue.js @@ -2,15 +2,15 @@ import $ from 'jquery'; import {updateIssuesMeta} from './repo-issue.js'; export function initCommonIssue() { + let checkboxfirst; const checkboxOperate = (e) => { const issuecheckbox = $('.issue-checkbox input'); - if (e.shiftKey && window.checkboxfirst !== undefined) { - for (let i = window.checkboxfirst + 1, j = issuecheckbox.index($(e.currentTarget).find('input')); i < j; i++) { + if (e.shiftKey && checkboxfirst !== undefined) { + for (let i = checkboxfirst + 1, j = issuecheckbox.index($(e.currentTarget).find('input')); i < j; i++) { issuecheckbox[i].checked = 1; } - delete window.checkboxfirst; } else { - window.checkboxfirst = issuecheckbox.index($(e.currentTarget).find('input')); + checkboxfirst = issuecheckbox.index($(e.currentTarget).find('input')); } if (issuecheckbox.is(':checked')) { $('#issue-filters').addClass('hide'); From f3265102e4bed0cdf013e6ccb981e8134847d733 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Tue, 5 Jul 2022 10:04:53 +0800 Subject: [PATCH 09/15] Fix lint issue --- web_src/js/features/common-issue.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/common-issue.js b/web_src/js/features/common-issue.js index 6d8fe55d63bc2..27de129fb08ec 100644 --- a/web_src/js/features/common-issue.js +++ b/web_src/js/features/common-issue.js @@ -21,7 +21,7 @@ export function initCommonIssue() { $('#issue-actions').addClass('hide'); $('#issue-filters .six').prepend($('.issue-checkbox-all')); } - } + }; $('.issue-checkbox').on('click', checkboxOperate); From e29f54267ee2f774a68375129d8cbc2cb04b208e Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Fri, 8 Jul 2022 13:19:41 +0800 Subject: [PATCH 10/15] Add permission condition for checkbox select all --- templates/repo/issue/list.tmpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index ca10ac2fbe4ac..84ecce8528688 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -28,10 +28,12 @@
+ {{if $.CanWriteIssuesOrPulls}}
+ {{end}} {{template "repo/issue/openclose" .}}
From 942bf9f213bc20cc780563d4f5308a81f1327b3e Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Sat, 9 Jul 2022 12:30:22 +0800 Subject: [PATCH 11/15] Update templates/repo/issue/list.tmpl Co-authored-by: Gusted --- templates/repo/issue/list.tmpl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 84ecce8528688..b37e7438c5678 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -29,10 +29,10 @@
{{if $.CanWriteIssuesOrPulls}} -
- - -
+
+ + +
{{end}} {{template "repo/issue/openclose" .}}
From 5d9fb502104ee569f2c7a2cb50a3671308548da0 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Sat, 9 Jul 2022 19:00:20 +0800 Subject: [PATCH 12/15] Remove range select function --- web_src/js/features/common-issue.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/web_src/js/features/common-issue.js b/web_src/js/features/common-issue.js index 27de129fb08ec..275951e0e3460 100644 --- a/web_src/js/features/common-issue.js +++ b/web_src/js/features/common-issue.js @@ -2,17 +2,8 @@ import $ from 'jquery'; import {updateIssuesMeta} from './repo-issue.js'; export function initCommonIssue() { - let checkboxfirst; - const checkboxOperate = (e) => { - const issuecheckbox = $('.issue-checkbox input'); - if (e.shiftKey && checkboxfirst !== undefined) { - for (let i = checkboxfirst + 1, j = issuecheckbox.index($(e.currentTarget).find('input')); i < j; i++) { - issuecheckbox[i].checked = 1; - } - } else { - checkboxfirst = issuecheckbox.index($(e.currentTarget).find('input')); - } - if (issuecheckbox.is(':checked')) { + const checkboxOperate = () => { + if ($('.issue-checkbox input').is(':checked')) { $('#issue-filters').addClass('hide'); $('#issue-actions').removeClass('hide'); $('#issue-actions .six').prepend($('.issue-checkbox-all')); From 01f3f0f14d5a45fee9f1452e9469a955b1efecf2 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Thu, 28 Jul 2022 14:30:50 +0800 Subject: [PATCH 13/15] Remove invert selection func --- web_src/js/features/common-issue.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web_src/js/features/common-issue.js b/web_src/js/features/common-issue.js index 275951e0e3460..e4f95457336df 100644 --- a/web_src/js/features/common-issue.js +++ b/web_src/js/features/common-issue.js @@ -14,12 +14,12 @@ export function initCommonIssue() { } }; - $('.issue-checkbox').on('click', checkboxOperate); + const checkboxpart = $('.issue-checkbox'); + checkboxpart.on('click', checkboxOperate); - $('.issue-checkbox-all').on('click', (e) => { - const selected = $('.issue-checkbox input:checked'); - $('.issue-checkbox input:not(:checked)').prop('checked', 1); - selected.prop('checked', 0); + const checkboxall = $('.issue-checkbox-all'); + checkboxall.on('click', (e) => { + checkboxpart.find('input').prop('checked', checkboxall.find('input').prop('checked')); checkboxOperate(e); }); From 456da24aab6001a6f25ff3ea25c6336418df2ef3 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 28 Jul 2022 15:49:00 +0800 Subject: [PATCH 14/15] refactor --- web_src/js/features/common-issue.js | 39 ++++++++++++++++++----------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/web_src/js/features/common-issue.js b/web_src/js/features/common-issue.js index e4f95457336df..4a62089c60ca5 100644 --- a/web_src/js/features/common-issue.js +++ b/web_src/js/features/common-issue.js @@ -2,25 +2,34 @@ import $ from 'jquery'; import {updateIssuesMeta} from './repo-issue.js'; export function initCommonIssue() { - const checkboxOperate = () => { - if ($('.issue-checkbox input').is(':checked')) { - $('#issue-filters').addClass('hide'); - $('#issue-actions').removeClass('hide'); - $('#issue-actions .six').prepend($('.issue-checkbox-all')); + const $issueSelectAllWrapper = $('.issue-checkbox-all'); + const $issueSelectAll = $('.issue-checkbox-all input'); + const $issueCheckboxes = $('.issue-checkbox input'); + + const syncIssueSelectionState = () => { + const $checked = $issueCheckboxes.filter(':checked'); + const anyChecked = $checked.length !== 0; + const allChecked = anyChecked && $checked.length === $issueCheckboxes.length; + + if (allChecked) { + $issueSelectAll.prop({'checked': true, 'indeterminate': false}); + } else if (anyChecked) { + $issueSelectAll.prop({'checked': false, 'indeterminate': true}); } else { - $('#issue-filters').removeClass('hide'); - $('#issue-actions').addClass('hide'); - $('#issue-filters .six').prepend($('.issue-checkbox-all')); + $issueSelectAll.prop({'checked': false, 'indeterminate': false}); } + // if any issue is selected, show the action panel, otherwise show the filter panel + $('#issue-filters').toggle(!anyChecked); + $('#issue-actions').toggle(anyChecked); + // there are two panels but only one select-all checkbox, so move the checkbox to the visible panel + $('#issue-filters, #issue-actions').filter(':visible').find('.column:first').prepend($issueSelectAllWrapper); }; - const checkboxpart = $('.issue-checkbox'); - checkboxpart.on('click', checkboxOperate); + $issueCheckboxes.on('change', syncIssueSelectionState); - const checkboxall = $('.issue-checkbox-all'); - checkboxall.on('click', (e) => { - checkboxpart.find('input').prop('checked', checkboxall.find('input').prop('checked')); - checkboxOperate(e); + $issueSelectAll.on('change', () => { + $issueCheckboxes.prop('checked', $issueSelectAll.is(':checked')); + syncIssueSelectionState(); }); $('.issue-action').on('click', async function () { @@ -51,7 +60,7 @@ export function initCommonIssue() { }); // NOTICE: This event trigger targets Firefox caching behaviour, as the checkboxes stay - // checked after reload trigger ckecked event, if checkboxes are checked on load + // checked after reload trigger checked event, if checkboxes are checked on load $('.issue-checkbox input[type="checkbox"]:checked').first().each((_, e) => { e.checked = false; $(e).trigger('click'); From 95608a2026270e1ad0eba2f56627d9827e4501f7 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 28 Jul 2022 16:00:01 +0800 Subject: [PATCH 15/15] make checkbox "vertical-align: middle" --- templates/repo/issue/list.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index b37e7438c5678..2a53239f1c6f7 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -29,7 +29,7 @@
{{if $.CanWriteIssuesOrPulls}} -
+