aboutsummaryrefslogtreecommitdiffstats
path: root/web_src
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2022-05-12 21:39:02 +0800
committerGitHub <noreply@github.com>2022-05-12 21:39:02 +0800
commit368baf9e77606e5de8bbcda8b0348f1a6fba6d73 (patch)
treee6358627708f2d695fc48b4967b9c1fe803450b8 /web_src
parentd985dcc922892ffd2cc1af427d330f98e9dc2f80 (diff)
downloadgitea-368baf9e77606e5de8bbcda8b0348f1a6fba6d73.tar.gz
gitea-368baf9e77606e5de8bbcda8b0348f1a6fba6d73.zip
Use Vue to refactor pull merge UI (#19650)
* Use Vue to refactor pull merge UI * add comments * fix comments * small fine tune * fix tests * adopt new pull default messages * clean up Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'web_src')
-rw-r--r--web_src/js/components/PullRequestMergeForm.vue127
-rw-r--r--web_src/js/features/repo-issue-pr-form.js12
-rw-r--r--web_src/js/features/repo-issue.js26
-rw-r--r--web_src/js/features/repo-legacy.js6
4 files changed, 143 insertions, 28 deletions
diff --git a/web_src/js/components/PullRequestMergeForm.vue b/web_src/js/components/PullRequestMergeForm.vue
new file mode 100644
index 0000000000..40398a65cb
--- /dev/null
+++ b/web_src/js/components/PullRequestMergeForm.vue
@@ -0,0 +1,127 @@
+<template>
+ <div>
+ <div class="ui form" v-if="showActionForm">
+ <form :action="mergeForm.baseLink+'/merge'" method="post">
+ <input type="hidden" name="_csrf" :value="csrfToken">
+ <input type="hidden" name="head_commit_id" v-model="mergeForm.pullHeadCommitID">
+
+ <template v-if="!mergeStyleDetail.hideMergeMessageTexts">
+ <div class="field">
+ <input type="text" name="merge_title_field" v-model="mergeTitleFieldValue">
+ </div>
+ <div class="field">
+ <textarea name="merge_message_field" rows="5" :placeholder="mergeForm.mergeMessageFieldPlaceHolder" v-model="mergeMessageFieldValue"/>
+ </div>
+ </template>
+
+ <button class="ui button" :class="[mergeForm.allOverridableChecksOk?'green':'red']" type="submit" name="do" :value="mergeStyle">
+ {{ mergeStyleDetail.textDoMerge }}
+ </button>
+
+ <button class="ui button merge-cancel" @click="toggleActionForm(false)">
+ {{ mergeForm.textCancel }}
+ </button>
+
+ <div class="ui checkbox ml-2" v-if="mergeForm.isPullBranchDeletable">
+ <input name="delete_branch_after_merge" type="checkbox" v-model="deleteBranchAfterMerge" id="delete-branch-after-merge">
+ <label for="delete-branch-after-merge">{{ mergeForm.textDeleteBranch }}</label>
+ </div>
+ </form>
+ </div>
+
+ <template v-if="!showActionForm">
+ <div class="ui buttons merge-button" :class="[mergeForm.allOverridableChecksOk?'green':'red']" @click="toggleActionForm(true)">
+ <button class="ui button">
+ <svg-icon name="octicon-git-merge"/>
+ <span class="button-text">{{ mergeStyleDetail.textDoMerge }}</span>
+ </button>
+ <div class="ui dropdown icon button no-text" @click.stop="showMergeStyleMenu = !showMergeStyleMenu" v-if="mergeStyleAllowedCount>1">
+ <svg-icon name="octicon-triangle-down" :size="14"/>
+ <div class="menu" :class="{'show':showMergeStyleMenu}">
+ <template v-for="msd in mergeForm.mergeStyles">
+ <div class="item" v-if="msd.allowed" :key="msd.name" @click.stop="mergeStyle=msd.name">
+ {{ msd.textDoMerge }}
+ </div>
+ </template>
+ </div>
+ </div>
+ </div>
+ </template>
+ </div>
+</template>
+
+<script>
+import {SvgIcon} from '../svg.js';
+
+const {csrfToken, pageData} = window.config;
+
+export default {
+ name: 'PullRequestMergeForm',
+ components: {
+ SvgIcon,
+ },
+
+ data: () => ({
+ csrfToken,
+ mergeForm: pageData.pullRequestMergeForm,
+
+ mergeTitleFieldValue: '',
+ mergeMessageFieldValue: '',
+ deleteBranchAfterMerge: false,
+
+ mergeStyle: '',
+ mergeStyleDetail: { // dummy only, these values will come from one of the mergeForm.mergeStyles
+ hideMergeMessageTexts: false,
+ textDoMerge: '',
+ mergeTitleFieldText: '',
+ mergeMessageFieldText: '',
+ },
+ mergeStyleAllowedCount: 0,
+
+ showMergeStyleMenu: false,
+ showActionForm: false,
+ }),
+
+ watch: {
+ mergeStyle(val) {
+ this.mergeStyleDetail = this.mergeForm.mergeStyles.find((e) => e.name === val);
+ }
+ },
+
+ created() {
+ this.mergeStyleAllowedCount = this.mergeForm.mergeStyles.reduce((v, msd) => v + (msd.allowed ? 1 : 0), 0);
+ this.mergeStyle = this.mergeForm.mergeStyles.find((e) => e.allowed)?.name;
+ },
+
+ mounted() {
+ document.addEventListener('mouseup', this.hideMergeStyleMenu);
+ },
+
+ unmounted() {
+ document.removeEventListener('mouseup', this.hideMergeStyleMenu);
+ },
+
+ methods: {
+ hideMergeStyleMenu() {
+ this.showMergeStyleMenu = false;
+ },
+ toggleActionForm(show) {
+ this.showActionForm = show;
+ if (!show) return;
+ this.deleteBranchAfterMerge = this.mergeForm.defaultDeleteBranchAfterMerge;
+ this.mergeTitleFieldValue = this.mergeStyleDetail.mergeTitleFieldText;
+ this.mergeMessageFieldValue = this.mergeStyleDetail.mergeMessageFieldText;
+ }
+ },
+};
+</script>
+
+<style scoped>
+/* to keep UI the same, at the moment we are still using some Fomantic UI styles, but we do not use their scripts, so we need to fine tune some styles */
+.ui.dropdown .menu.show {
+ display: block;
+}
+.ui.checkbox label {
+ cursor: pointer;
+}
+</style>
diff --git a/web_src/js/features/repo-issue-pr-form.js b/web_src/js/features/repo-issue-pr-form.js
new file mode 100644
index 0000000000..747e4f467e
--- /dev/null
+++ b/web_src/js/features/repo-issue-pr-form.js
@@ -0,0 +1,12 @@
+import Vue from 'vue';
+import PullRequestMergeForm from '../components/PullRequestMergeForm.vue';
+
+export default function initPullRequestMergeForm() {
+ const el = document.getElementById('pull-request-merge-form');
+ if (!el) return;
+
+ const View = Vue.extend({
+ render: (createElement) => createElement(PullRequestMergeForm),
+ });
+ new View().$mount(el);
+}
diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js
index 4e077c14e2..bdd616f071 100644
--- a/web_src/js/features/repo-issue.js
+++ b/web_src/js/features/repo-issue.js
@@ -234,32 +234,6 @@ export function initRepoIssueStatusButton() {
});
}
-export function initRepoPullRequestMerge() {
- // Pull Request merge button
- const $mergeButton = $('.merge-button > button');
- $mergeButton.on('click', function (e) {
- e.preventDefault();
- $(`.${$(this).data('do')}-fields`).show();
- $(this).parent().hide();
- $('.instruct-toggle').hide();
- $('.instruct-content').hide();
- });
- $('.merge-button > .dropdown').dropdown({
- onChange(_text, _value, $choice) {
- if ($choice.data('do')) {
- $mergeButton.find('.button-text').text($choice.text());
- $mergeButton.data('do', $choice.data('do'));
- }
- }
- });
- $('.merge-cancel').on('click', function (e) {
- e.preventDefault();
- $(this).closest('.form').hide();
- $mergeButton.parent().show();
- $('.instruct-toggle').show();
- });
-}
-
export function initRepoPullRequestUpdate() {
// Pull Request update button
const $pullUpdateButton = $('.update-button > button');
diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js
index b7e6206e53..a24d1b974a 100644
--- a/web_src/js/features/repo-legacy.js
+++ b/web_src/js/features/repo-legacy.js
@@ -8,7 +8,7 @@ import {
initRepoIssueComments, initRepoIssueDependencyDelete,
initRepoIssueReferenceIssue, initRepoIssueStatusButton,
initRepoIssueTitleEdit,
- initRepoIssueWipToggle, initRepoPullRequestMerge, initRepoPullRequestUpdate,
+ initRepoIssueWipToggle, initRepoPullRequestUpdate,
updateIssuesMeta,
} from './repo-issue.js';
import {initUnicodeEscapeButton} from './repo-unicode-escape.js';
@@ -28,6 +28,7 @@ import createDropzone from './dropzone.js';
import {initCommentContent, initMarkupContent} from '../markup/content.js';
import {initCompReactionSelector} from './comp/ReactionSelector.js';
import {initRepoSettingBranches} from './repo-settings.js';
+import initRepoPullRequestMergeForm from './repo-issue-pr-form.js';
const {csrfToken} = window.config;
@@ -507,9 +508,10 @@ export function initRepository() {
initRepoIssueDependencyDelete();
initRepoIssueCodeCommentCancel();
initRepoIssueStatusButton();
- initRepoPullRequestMerge();
initRepoPullRequestUpdate();
initCompReactionSelector();
+
+ initRepoPullRequestMergeForm();
}
// Pull request