summaryrefslogtreecommitdiffstats
path: root/web_src/js/components
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-02-09 20:28:55 +0000
committerGitHub <noreply@github.com>2022-02-09 20:28:55 +0000
commiteb748f5f3c93e8e347309fc75ea8273c06a5489b (patch)
treefceec474a21fa35437bcf3e90bd549c11976b72e /web_src/js/components
parent439ad34c71b8777a9dac369c643560b18bc41bab (diff)
downloadgitea-eb748f5f3c93e8e347309fc75ea8273c06a5489b.tar.gz
gitea-eb748f5f3c93e8e347309fc75ea8273c06a5489b.zip
Add apply-patch, basic revert and cherry-pick functionality (#17902)
This code adds a simple endpoint to apply patches to repositories and branches on gitea. This is then used along with the conflicting checking code in #18004 to provide a basic implementation of cherry-pick revert. Now because the buttons necessary for cherry-pick and revert have required us to create a dropdown next to the Browse Source button I've also implemented Create Branch and Create Tag operations. Fix #3880 Fix #17986 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'web_src/js/components')
-rw-r--r--web_src/js/components/RepoBranchTagDropdown.js60
1 files changed, 58 insertions, 2 deletions
diff --git a/web_src/js/components/RepoBranchTagDropdown.js b/web_src/js/components/RepoBranchTagDropdown.js
index e72563ff29..d55fa91b92 100644
--- a/web_src/js/components/RepoBranchTagDropdown.js
+++ b/web_src/js/components/RepoBranchTagDropdown.js
@@ -10,11 +10,22 @@ export function initRepoBranchTagDropdown(selector) {
items: [],
mode: $data.data('mode'),
searchTerm: '',
+ refName: '',
noResults: '',
canCreateBranch: false,
menuVisible: false,
createTag: false,
- active: 0
+ isViewTag: false,
+ isViewBranch: false,
+ isViewTree: false,
+ active: 0,
+ branchForm: '',
+ branchURLPrefix: '',
+ branchURLSuffix: '',
+ tagURLPrefix: '',
+ tagURLSuffix: '',
+ setAction: false,
+ submitForm: false,
};
$data.find('.item').each(function () {
data.items.push({
@@ -64,6 +75,26 @@ export function initRepoBranchTagDropdown(selector) {
beforeMount() {
this.noResults = this.$el.getAttribute('data-no-results');
this.canCreateBranch = this.$el.getAttribute('data-can-create-branch') === 'true';
+ this.branchForm = this.$el.getAttribute('data-branch-form');
+ switch (this.$el.getAttribute('data-view-type')) {
+ case 'tree':
+ this.isViewTree = true;
+ break;
+ case 'tag':
+ this.isViewTag = true;
+ break;
+ default:
+ this.isViewBranch = true;
+ break;
+ }
+ this.refName = this.$el.getAttribute('data-ref-name');
+ this.branchURLPrefix = this.$el.getAttribute('data-branch-url-prefix');
+ this.branchURLSuffix = this.$el.getAttribute('data-branch-url-suffix');
+ this.tagURLPrefix = this.$el.getAttribute('data-tag-url-prefix');
+ this.tagURLSuffix = this.$el.getAttribute('data-tag-url-suffix');
+ this.setAction = this.$el.getAttribute('data-set-action') === 'true';
+ this.submitForm = this.$el.getAttribute('data-submit-form') === 'true';
+
document.body.addEventListener('click', (event) => {
if (this.$el.contains(event.target)) return;
@@ -80,7 +111,32 @@ export function initRepoBranchTagDropdown(selector) {
prev.selected = false;
}
item.selected = true;
- window.location.href = item.url;
+ const url = (item.tag) ? this.tagURLPrefix + item.url + this.tagURLSuffix : this.branchURLPrefix + item.url + this.branchURLSuffix;
+ if (this.branchForm === '') {
+ window.location.href = url;
+ } else {
+ this.isViewTree = false;
+ this.isViewTag = false;
+ this.isViewBranch = false;
+ this.$refs.dropdownRefName.textContent = item.name;
+ if (this.setAction) {
+ $(`#${this.branchForm}`).attr('action', url);
+ } else {
+ $(`#${this.branchForm} input[name="refURL"]`).val(url);
+ }
+ $(`#${this.branchForm} input[name="ref"]`).val(item.name);
+ if (item.tag) {
+ this.isViewTag = true;
+ $(`#${this.branchForm} input[name="refType"]`).val('tag');
+ } else {
+ this.isViewBranch = true;
+ $(`#${this.branchForm} input[name="refType"]`).val('branch');
+ }
+ if (this.submitForm) {
+ $(`#${this.branchForm}`).trigger('submit');
+ }
+ Vue.set(this, 'menuVisible', false);
+ }
},
createNewBranch() {
if (!this.showCreateNewBranch) return;