diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /app/assets/javascripts/jira_connect | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'app/assets/javascripts/jira_connect')
-rw-r--r-- | app/assets/javascripts/jira_connect/components/app.vue | 13 | ||||
-rw-r--r-- | app/assets/javascripts/jira_connect/index.js | 74 |
2 files changed, 85 insertions, 2 deletions
diff --git a/app/assets/javascripts/jira_connect/components/app.vue b/app/assets/javascripts/jira_connect/components/app.vue index 6d32ba41eae..490bf2fdd66 100644 --- a/app/assets/javascripts/jira_connect/components/app.vue +++ b/app/assets/javascripts/jira_connect/components/app.vue @@ -1,7 +1,16 @@ <script> -export default {}; +export default { + name: 'JiraConnectApp', + computed: { + state() { + return this.$root.$data.state || {}; + }, + error() { + return this.state.error; + }, + }, +}; </script> - <template> <div></div> </template> diff --git a/app/assets/javascripts/jira_connect/index.js b/app/assets/javascripts/jira_connect/index.js index 37f00d56a05..e7aa4c437bb 100644 --- a/app/assets/javascripts/jira_connect/index.js +++ b/app/assets/javascripts/jira_connect/index.js @@ -1,11 +1,85 @@ import Vue from 'vue'; +import $ from 'jquery'; import App from './components/app.vue'; +const store = { + state: { + error: '', + }, + setErrorMessage(errorMessage) { + this.state.error = errorMessage; + }, +}; + +/** + * Initialize necessary form handlers for the Jira Connect app + */ +const initJiraFormHandlers = () => { + const reqComplete = () => { + AP.navigator.reload(); + }; + + const reqFailed = (res, fallbackErrorMessage) => { + const { responseJSON: { error = fallbackErrorMessage } = {} } = res || {}; + + store.setErrorMessage(error); + // eslint-disable-next-line no-alert + alert(error); + }; + + AP.getLocation(location => { + $('.js-jira-connect-sign-in').each(function updateSignInLink() { + const updatedLink = `${$(this).attr('href')}?return_to=${location}`; + $(this).attr('href', updatedLink); + }); + }); + + $('#add-subscription-form').on('submit', function onAddSubscriptionForm(e) { + const actionUrl = $(this).attr('action'); + e.preventDefault(); + + AP.context.getToken(token => { + // eslint-disable-next-line no-jquery/no-ajax + $.post(actionUrl, { + jwt: token, + namespace_path: $('#namespace-input').val(), + format: 'json', + }) + .done(reqComplete) + .fail(err => reqFailed(err, 'Failed to add namespace. Please try again.')); + }); + }); + + $('.remove-subscription').on('click', function onRemoveSubscriptionClick(e) { + const href = $(this).attr('href'); + e.preventDefault(); + + AP.context.getToken(token => { + // eslint-disable-next-line no-jquery/no-ajax + $.ajax({ + url: href, + method: 'DELETE', + data: { + jwt: token, + format: 'json', + }, + }) + .done(reqComplete) + .fail(err => reqFailed(err, 'Failed to remove namespace. Please try again.')); + }); + }); +}; + function initJiraConnect() { const el = document.querySelector('.js-jira-connect-app'); + initJiraFormHandlers(); + return new Vue({ el, + data: { + state: store.state, + }, render(createElement) { return createElement(App, {}); }, |