From 155b8b53041d016f3aa6025040817b09502de488 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Mon, 27 Feb 2023 14:21:04 +0800 Subject: [PATCH 1/9] hide target selector if tag exists --- options/locale/locale_en-US.ini | 2 ++ templates/repo/release/new.tmpl | 33 ++++++++++++++++++------------- web_src/js/features/tag-editor.js | 29 +++++++++++++++++++++++++++ web_src/js/index.js | 3 +++ 4 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 web_src/js/features/tag-editor.js diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 1d1a0f588d256..29ac96c76b200 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2288,6 +2288,8 @@ release.edit_subheader = Releases organize project versions. release.tag_name = Tag name release.target = Target release.tag_helper = Choose an existing tag or create a new tag. +release.tag_helper_new = New tag. This tag will be created from the target. +release.tag_helper_existing = Existing tag. release.title = Title release.content = Content release.prerelease_desc = Mark as Pre-Release diff --git a/templates/repo/release/new.tmpl b/templates/repo/release/new.tmpl index 37d7ca032196e..8d8b86a55f437 100644 --- a/templates/repo/release/new.tmpl +++ b/templates/repo/release/new.tmpl @@ -20,22 +20,27 @@ {{.tag_name}}@{{.tag_target}} {{else}} - @ - diff --git a/web_src/js/features/tag-editor.js b/web_src/js/features/tag-editor.js new file mode 100644 index 0000000000000..80a3fc86db753 --- /dev/null +++ b/web_src/js/features/tag-editor.js @@ -0,0 +1,29 @@ +import $ from 'jquery'; + +export function initTagNameEditor() { + const el = document.getElementById('tag-name-editor'); + if (!el) return; + + const existingTags = JSON.parse(el.getAttribute('data-existing-tags')) + if (!Array.isArray(existingTags)) return + + const defaultTagHelperText = el.getAttribute('data-tag-helper') + const newTagHelperText = el.getAttribute('data-tag-helper-new') + const existingTagHelperText = el.getAttribute('data-tag-helper-existing') + + $('#tag-name').on('keyup', function(e) { + const value = e.target.value + if (existingTags.includes(value)) { + // If the tag already exists, hide the target branch selector. + $('#tag-target-selector').hide() + $('#tag-helper').text(existingTagHelperText) + } else { + $('#tag-target-selector').show() + if (typeof value == 'string' && value.length > 0) { + $('#tag-helper').text(newTagHelperText) + } else { + $('#tag-helper').text(defaultTagHelperText) + } + } + }) +} diff --git a/web_src/js/index.js b/web_src/js/index.js index 611c09d2b8c16..f30972b7687ff 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -90,6 +90,7 @@ import {initFormattingReplacements} from './features/formatting.js'; import {initCopyContent} from './features/copycontent.js'; import {initCaptcha} from './features/captcha.js'; import {initRepositoryActionView} from './components/RepoActionView.vue'; +import {initTagNameEditor} from './features/tag-editor.js'; // Run time-critical code as soon as possible. This is safe to do because this // script appears at the end of and rendered HTML is accessible at that point. @@ -198,4 +199,6 @@ $(document).ready(() => { initUserAuthWebAuthnRegister(); initUserSettings(); initViewedCheckboxListenerFor(); + + initTagNameEditor(); }); From bda5bb25619333589d50308a639c0e8a836dd207 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Mon, 27 Feb 2023 14:29:04 +0800 Subject: [PATCH 2/9] rename --- web_src/js/features/{tag-editor.js => tag-name-editor.js} | 0 web_src/js/index.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename web_src/js/features/{tag-editor.js => tag-name-editor.js} (100%) diff --git a/web_src/js/features/tag-editor.js b/web_src/js/features/tag-name-editor.js similarity index 100% rename from web_src/js/features/tag-editor.js rename to web_src/js/features/tag-name-editor.js diff --git a/web_src/js/index.js b/web_src/js/index.js index f30972b7687ff..52b88064762c3 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -90,7 +90,7 @@ import {initFormattingReplacements} from './features/formatting.js'; import {initCopyContent} from './features/copycontent.js'; import {initCaptcha} from './features/captcha.js'; import {initRepositoryActionView} from './components/RepoActionView.vue'; -import {initTagNameEditor} from './features/tag-editor.js'; +import {initTagNameEditor} from './features/tag-name-editor.js'; // Run time-critical code as soon as possible. This is safe to do because this // script appears at the end of and rendered HTML is accessible at that point. From 1d9a9079371ac94953f3b06c602d78e08c82a361 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Mon, 27 Feb 2023 14:38:51 +0800 Subject: [PATCH 3/9] lint code --- web_src/js/features/tag-name-editor.js | 45 +++++++++++++------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/web_src/js/features/tag-name-editor.js b/web_src/js/features/tag-name-editor.js index 80a3fc86db753..6a3ddc63f1b94 100644 --- a/web_src/js/features/tag-name-editor.js +++ b/web_src/js/features/tag-name-editor.js @@ -1,29 +1,30 @@ import $ from 'jquery'; +import {hideElem, showElem} from '../utils/dom.js'; export function initTagNameEditor() { - const el = document.getElementById('tag-name-editor'); - if (!el) return; + const el = document.getElementById('tag-name-editor'); + if (!el) return; - const existingTags = JSON.parse(el.getAttribute('data-existing-tags')) - if (!Array.isArray(existingTags)) return + const existingTags = JSON.parse(el.getAttribute('data-existing-tags')); + if (!Array.isArray(existingTags)) return; - const defaultTagHelperText = el.getAttribute('data-tag-helper') - const newTagHelperText = el.getAttribute('data-tag-helper-new') - const existingTagHelperText = el.getAttribute('data-tag-helper-existing') + const defaultTagHelperText = el.getAttribute('data-tag-helper'); + const newTagHelperText = el.getAttribute('data-tag-helper-new'); + const existingTagHelperText = el.getAttribute('data-tag-helper-existing'); - $('#tag-name').on('keyup', function(e) { - const value = e.target.value - if (existingTags.includes(value)) { - // If the tag already exists, hide the target branch selector. - $('#tag-target-selector').hide() - $('#tag-helper').text(existingTagHelperText) - } else { - $('#tag-target-selector').show() - if (typeof value == 'string' && value.length > 0) { - $('#tag-helper').text(newTagHelperText) - } else { - $('#tag-helper').text(defaultTagHelperText) - } - } - }) + $('#tag-name').on('keyup', (e) => { + const value = e.target.value; + if (existingTags.includes(value)) { + // If the tag already exists, hide the target branch selector. + hideElem($('#tag-target-selector')); + $('#tag-helper').text(existingTagHelperText); + } else { + showElem($('#tag-target-selector')); + if (typeof value === 'string' && value.length > 0) { + $('#tag-helper').text(newTagHelperText); + } else { + $('#tag-helper').text(defaultTagHelperText); + } + } + }); } From e72b39ca771a1017ab9ac4b2b839659447345d43 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Mon, 27 Feb 2023 14:44:20 +0800 Subject: [PATCH 4/9] format --- templates/repo/release/new.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/release/new.tmpl b/templates/repo/release/new.tmpl index 8d8b86a55f437..59ef38e12668e 100644 --- a/templates/repo/release/new.tmpl +++ b/templates/repo/release/new.tmpl @@ -20,7 +20,7 @@ {{.tag_name}}@{{.tag_target}} {{else}} - + @
{{.locale.Tr "repo.release.tag_helper"}}
From f9c6c8ec0ec9cb037d8ec7084310fe36fc6c5e0c Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Fri, 3 Mar 2023 21:48:27 +0800 Subject: [PATCH 7/9] add initRepoReleaseNew --- web_src/js/features/repo-release.js | 39 ++++++++++++++++++++++++-- web_src/js/features/tag-name-editor.js | 29 ------------------- web_src/js/index.js | 7 ++--- 3 files changed, 39 insertions(+), 36 deletions(-) delete mode 100644 web_src/js/features/tag-name-editor.js diff --git a/web_src/js/features/repo-release.js b/web_src/js/features/repo-release.js index a061c6b23f832..51684ae07c55f 100644 --- a/web_src/js/features/repo-release.js +++ b/web_src/js/features/repo-release.js @@ -3,7 +3,7 @@ import {attachTribute} from './tribute.js'; import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js'; import {initEasyMDEImagePaste} from './comp/ImagePaste.js'; import {createCommentEasyMDE} from './comp/EasyMDE.js'; -import {hideElem} from '../utils/dom.js'; +import {hideElem,showElem} from '../utils/dom.js'; export function initRepoRelease() { $(document).on('click', '.remove-rel-attach', function() { @@ -14,8 +14,43 @@ export function initRepoRelease() { }); } +export function initRepoReleaseNew() { + const $repoReleaseNew = $('.repository.new.release'); + if (!$repoReleaseNew.length) return; -export function initRepoReleaseEditor() { + initTagNameEditor() + initRepoReleaseEditor() +} + +function initTagNameEditor() { + const el = document.getElementById('tag-name-editor'); + if (!el) return; + + const existingTags = JSON.parse(el.getAttribute('data-existing-tags')); + if (!Array.isArray(existingTags)) return; + + const defaultTagHelperText = el.getAttribute('data-tag-helper'); + const newTagHelperText = el.getAttribute('data-tag-helper-new'); + const existingTagHelperText = el.getAttribute('data-tag-helper-existing'); + + document.getElementById('tag-name').addEventListener('keyup', (e) => { + const value = e.target.value; + if (existingTags.includes(value)) { + // If the tag already exists, hide the target branch selector. + hideElem('#tag-target-selector'); + document.getElementById('tag-helper').innerText = existingTagHelperText; + } else { + showElem('#tag-target-selector'); + if (value) { + document.getElementById('tag-helper').innerText = newTagHelperText; + } else { + document.getElementById('tag-helper').innerText = defaultTagHelperText; + } + } + }); +} + +function initRepoReleaseEditor() { const $editor = $('.repository.new.release .content-editor'); if ($editor.length === 0) { return; diff --git a/web_src/js/features/tag-name-editor.js b/web_src/js/features/tag-name-editor.js deleted file mode 100644 index 9b0a2cbd9f9a6..0000000000000 --- a/web_src/js/features/tag-name-editor.js +++ /dev/null @@ -1,29 +0,0 @@ -import {hideElem, showElem} from '../utils/dom.js'; - -export function initTagNameEditor() { - const el = document.getElementById('tag-name-editor'); - if (!el) return; - - const existingTags = JSON.parse(el.getAttribute('data-existing-tags')); - if (!Array.isArray(existingTags)) return; - - const defaultTagHelperText = el.getAttribute('data-tag-helper'); - const newTagHelperText = el.getAttribute('data-tag-helper-new'); - const existingTagHelperText = el.getAttribute('data-tag-helper-existing'); - - document.getElementById('tag-name').addEventListener('keyup', (e) => { - const value = e.target.value; - if (existingTags.includes(value)) { - // If the tag already exists, hide the target branch selector. - hideElem('#tag-target-selector'); - document.getElementById('tag-helper').innerText = existingTagHelperText; - } else { - showElem('#tag-target-selector'); - if (value) { - document.getElementById('tag-helper').innerText = newTagHelperText; - } else { - document.getElementById('tag-helper').innerText = defaultTagHelperText; - } - } - }); -} diff --git a/web_src/js/index.js b/web_src/js/index.js index 52b88064762c3..6b4f4ef3ebe12 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -76,7 +76,7 @@ import { import {initViewedCheckboxListenerFor} from './features/pull-view-file.js'; import {initOrgTeamSearchRepoBox, initOrgTeamSettings} from './features/org-team.js'; import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/user-auth-webauthn.js'; -import {initRepoRelease, initRepoReleaseEditor} from './features/repo-release.js'; +import {initRepoRelease, initRepoReleaseNew} from './features/repo-release.js'; import {initRepoEditor} from './features/repo-editor.js'; import {initCompSearchUserBox} from './features/comp/SearchUserBox.js'; import {initInstall} from './features/install.js'; @@ -90,7 +90,6 @@ import {initFormattingReplacements} from './features/formatting.js'; import {initCopyContent} from './features/copycontent.js'; import {initCaptcha} from './features/captcha.js'; import {initRepositoryActionView} from './components/RepoActionView.vue'; -import {initTagNameEditor} from './features/tag-name-editor.js'; // Run time-critical code as soon as possible. This is safe to do because this // script appears at the end of and rendered HTML is accessible at that point. @@ -180,7 +179,7 @@ $(document).ready(() => { initRepoPullRequestAllowMaintainerEdit(); initRepoPullRequestReview(); initRepoRelease(); - initRepoReleaseEditor(); + initRepoReleaseNew(); initRepoSettingGitHook(); initRepoSettingSearchTeamBox(); initRepoSettingsCollaboration(); @@ -199,6 +198,4 @@ $(document).ready(() => { initUserAuthWebAuthnRegister(); initUserSettings(); initViewedCheckboxListenerFor(); - - initTagNameEditor(); }); From e6adfce54484dd7d740e785cb3cd31b5215fbaa2 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Fri, 3 Mar 2023 21:56:38 +0800 Subject: [PATCH 8/9] lint code --- web_src/js/features/repo-release.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web_src/js/features/repo-release.js b/web_src/js/features/repo-release.js index 51684ae07c55f..a230d7765e223 100644 --- a/web_src/js/features/repo-release.js +++ b/web_src/js/features/repo-release.js @@ -3,7 +3,7 @@ import {attachTribute} from './tribute.js'; import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js'; import {initEasyMDEImagePaste} from './comp/ImagePaste.js'; import {createCommentEasyMDE} from './comp/EasyMDE.js'; -import {hideElem,showElem} from '../utils/dom.js'; +import {hideElem, showElem} from '../utils/dom.js'; export function initRepoRelease() { $(document).on('click', '.remove-rel-attach', function() { @@ -18,8 +18,8 @@ export function initRepoReleaseNew() { const $repoReleaseNew = $('.repository.new.release'); if (!$repoReleaseNew.length) return; - initTagNameEditor() - initRepoReleaseEditor() + initTagNameEditor(); + initRepoReleaseEditor(); } function initTagNameEditor() { From c56daa5bd9ff4dcdd3fb30ed84f665928b623b6c Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Sun, 5 Mar 2023 09:33:36 +0800 Subject: [PATCH 9/9] add margin --- templates/repo/release/new.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/release/new.tmpl b/templates/repo/release/new.tmpl index 7a524cd85a8c9..d7c580fed9693 100644 --- a/templates/repo/release/new.tmpl +++ b/templates/repo/release/new.tmpl @@ -39,7 +39,7 @@
- {{.locale.Tr "repo.release.tag_helper"}} + {{.locale.Tr "repo.release.tag_helper"}}
{{end}}