Loading app/assets/javascripts/lib/utils/flash_queue.jsdeleted 100644 → 0 +0 −46 Original line number Diff line number Diff line import _ from 'underscore'; import createFlash from '~/flash'; import AccessorUtilities from '~/lib/utils/accessor'; const FLASH_QUEUE_KEY = 'flash-key'; export function popFlashMessage() { const page = $('body').attr('data-page'); let savedFlashMessages; let returnVal = false; if (!page) { return returnVal; } if (AccessorUtilities.isLocalStorageAccessSafe()) { savedFlashMessages = JSON.parse(window.localStorage.getItem(FLASH_QUEUE_KEY)); const queuedMessage = _.findWhere(savedFlashMessages, { bodyData: page }); if (queuedMessage) { const queuedMessageIndex = _.findIndex(savedFlashMessages, { bodyData: page }); createFlash(queuedMessage.message, queuedMessage.type); savedFlashMessages.splice(queuedMessageIndex, 1); window.localStorage.setItem(FLASH_QUEUE_KEY, JSON.stringify(savedFlashMessages)); } returnVal = true; } return returnVal; } export function saveFlashMessage(bodyData, message, type) { let savedFlashMessages; if (AccessorUtilities.isLocalStorageAccessSafe()) { savedFlashMessages = JSON.parse(window.localStorage.getItem(FLASH_QUEUE_KEY)); if (!savedFlashMessages) { savedFlashMessages = []; } savedFlashMessages.push({ bodyData, message, type, }); window.localStorage.setItem(FLASH_QUEUE_KEY, JSON.stringify(savedFlashMessages)); } } app/assets/javascripts/main.js +0 −2 Original line number Diff line number Diff line Loading @@ -33,7 +33,6 @@ import './milestone_select'; import './projects_dropdown'; import './render_gfm'; import initBreadcrumbs from './breadcrumb'; import { popFlashMessage } from './lib/utils/flash_queue'; import initDispatcher from './dispatcher'; Loading Loading @@ -263,5 +262,4 @@ document.addEventListener('DOMContentLoaded', () => { } initDispatcher(); popFlashMessage(); }); app/assets/javascripts/pages/milestones/shared/components/promote_milestone_modal.vue +4 −8 Original line number Diff line number Diff line <script> import axios from '~/lib/utils/axios_utils'; import createFlash from '~/flash'; import { saveFlashMessage } from '~/lib/utils/flash_queue'; import GlModal from '~/vue_shared/components/gl_modal.vue'; import { redirectTo } from '~/lib/utils/url_utility'; import { s__, sprintf } from '~/locale'; import { visitUrl } from '~/lib/utils/url_utility'; import eventHub from '../event_hub'; export default { Loading @@ -27,20 +26,17 @@ }, text() { return s__(`Milestones|Promoting this milestone will make it available for all projects inside the group. Existing project milestones with the same name will be merged. Existing project milestones with the same title will be merged. This action cannot be reversed.`); }, }, methods: { onSubmit() { eventHub.$emit('promoteMilestoneModal.requestStarted', this.url); return axios.post(this.url) return axios.post(this.url, { params: { format: 'json' } }) .then((response) => { eventHub.$emit('promoteMilestoneModal.requestFinished', { milestoneUrl: this.url, successful: true }); const responseURL = new URL(response.request.responseURL); const bodyData = responseURL.searchParams.get('body_data'); saveFlashMessage(bodyData, `${this.milestoneTitle} promoted to group milestone`, 'notice'); redirectTo(`${responseURL.protocol}//${responseURL.host}${responseURL.pathname}`); visitUrl(response.data.url); }) .catch((error) => { eventHub.$emit('promoteMilestoneModal.requestFinished', { milestoneUrl: this.url, successful: false }); Loading app/assets/javascripts/pages/projects/labels/components/promote_label_modal.vue +4 −8 Original line number Diff line number Diff line <script> import axios from '~/lib/utils/axios_utils'; import { saveFlashMessage } from '~/lib/utils/flash_queue'; import createFlash from '~/flash'; import GlModal from '~/vue_shared/components/gl_modal.vue'; import { redirectTo } from '~/lib/utils/url_utility'; import { s__, sprintf } from '~/locale'; import { visitUrl } from '~/lib/utils/url_utility'; import eventHub from '../event_hub'; export default { Loading Loading @@ -32,7 +31,7 @@ computed: { text() { return s__(`Milestones|Promoting this label will make it available for all projects inside the group. Existing project labels with the same name will be merged. This action cannot be reversed.`); Existing project labels with the same title will be merged. This action cannot be reversed.`); }, title() { const label = `<span Loading @@ -48,13 +47,10 @@ methods: { onSubmit() { eventHub.$emit('promoteLabelModal.requestStarted', this.url); return axios.post(this.url) return axios.post(this.url, { params: { format: 'json' } }) .then((response) => { eventHub.$emit('promoteLabelModal.requestFinished', { labelUrl: this.url, successful: true }); const responseURL = new URL(response.request.responseURL); const bodyData = responseURL.searchParams.get('body_data'); saveFlashMessage(bodyData, `${this.labelTitle} promoted to group label`, 'notice'); redirectTo(`${responseURL.protocol}//${responseURL.host}${responseURL.pathname}`); visitUrl(response.data.url); }) .catch((error) => { eventHub.$emit('promoteLabelModal.requestFinished', { labelUrl: this.url, successful: false }); Loading app/controllers/projects/labels_controller.rb +5 −3 Original line number Diff line number Diff line class Projects::LabelsController < Projects::ApplicationController include ToggleSubscriptionAction include FlashHelper before_action :check_issuables_available! before_action :label, only: [:edit, :update, :destroy, :promote] Loading Loading @@ -113,11 +112,14 @@ def promote begin return render_404 unless promote_service.execute(@label) flash[:notice] = "#{@label.title} promoted to group label." respond_to do |format| format.html do redirect_to(project_labels_path(@project, body_data: get_body_data_page(project_labels_path(@project))), status: 303) redirect_to(project_labels_path(@project), status: 303) end format.json do render json: { url: project_labels_path(@project) } end format.js end rescue ActiveRecord::RecordInvalid => e Gitlab::AppLogger.error "Failed to promote label \"#{@label.title}\" to group label" Loading Loading
app/assets/javascripts/lib/utils/flash_queue.jsdeleted 100644 → 0 +0 −46 Original line number Diff line number Diff line import _ from 'underscore'; import createFlash from '~/flash'; import AccessorUtilities from '~/lib/utils/accessor'; const FLASH_QUEUE_KEY = 'flash-key'; export function popFlashMessage() { const page = $('body').attr('data-page'); let savedFlashMessages; let returnVal = false; if (!page) { return returnVal; } if (AccessorUtilities.isLocalStorageAccessSafe()) { savedFlashMessages = JSON.parse(window.localStorage.getItem(FLASH_QUEUE_KEY)); const queuedMessage = _.findWhere(savedFlashMessages, { bodyData: page }); if (queuedMessage) { const queuedMessageIndex = _.findIndex(savedFlashMessages, { bodyData: page }); createFlash(queuedMessage.message, queuedMessage.type); savedFlashMessages.splice(queuedMessageIndex, 1); window.localStorage.setItem(FLASH_QUEUE_KEY, JSON.stringify(savedFlashMessages)); } returnVal = true; } return returnVal; } export function saveFlashMessage(bodyData, message, type) { let savedFlashMessages; if (AccessorUtilities.isLocalStorageAccessSafe()) { savedFlashMessages = JSON.parse(window.localStorage.getItem(FLASH_QUEUE_KEY)); if (!savedFlashMessages) { savedFlashMessages = []; } savedFlashMessages.push({ bodyData, message, type, }); window.localStorage.setItem(FLASH_QUEUE_KEY, JSON.stringify(savedFlashMessages)); } }
app/assets/javascripts/main.js +0 −2 Original line number Diff line number Diff line Loading @@ -33,7 +33,6 @@ import './milestone_select'; import './projects_dropdown'; import './render_gfm'; import initBreadcrumbs from './breadcrumb'; import { popFlashMessage } from './lib/utils/flash_queue'; import initDispatcher from './dispatcher'; Loading Loading @@ -263,5 +262,4 @@ document.addEventListener('DOMContentLoaded', () => { } initDispatcher(); popFlashMessage(); });
app/assets/javascripts/pages/milestones/shared/components/promote_milestone_modal.vue +4 −8 Original line number Diff line number Diff line <script> import axios from '~/lib/utils/axios_utils'; import createFlash from '~/flash'; import { saveFlashMessage } from '~/lib/utils/flash_queue'; import GlModal from '~/vue_shared/components/gl_modal.vue'; import { redirectTo } from '~/lib/utils/url_utility'; import { s__, sprintf } from '~/locale'; import { visitUrl } from '~/lib/utils/url_utility'; import eventHub from '../event_hub'; export default { Loading @@ -27,20 +26,17 @@ }, text() { return s__(`Milestones|Promoting this milestone will make it available for all projects inside the group. Existing project milestones with the same name will be merged. Existing project milestones with the same title will be merged. This action cannot be reversed.`); }, }, methods: { onSubmit() { eventHub.$emit('promoteMilestoneModal.requestStarted', this.url); return axios.post(this.url) return axios.post(this.url, { params: { format: 'json' } }) .then((response) => { eventHub.$emit('promoteMilestoneModal.requestFinished', { milestoneUrl: this.url, successful: true }); const responseURL = new URL(response.request.responseURL); const bodyData = responseURL.searchParams.get('body_data'); saveFlashMessage(bodyData, `${this.milestoneTitle} promoted to group milestone`, 'notice'); redirectTo(`${responseURL.protocol}//${responseURL.host}${responseURL.pathname}`); visitUrl(response.data.url); }) .catch((error) => { eventHub.$emit('promoteMilestoneModal.requestFinished', { milestoneUrl: this.url, successful: false }); Loading
app/assets/javascripts/pages/projects/labels/components/promote_label_modal.vue +4 −8 Original line number Diff line number Diff line <script> import axios from '~/lib/utils/axios_utils'; import { saveFlashMessage } from '~/lib/utils/flash_queue'; import createFlash from '~/flash'; import GlModal from '~/vue_shared/components/gl_modal.vue'; import { redirectTo } from '~/lib/utils/url_utility'; import { s__, sprintf } from '~/locale'; import { visitUrl } from '~/lib/utils/url_utility'; import eventHub from '../event_hub'; export default { Loading Loading @@ -32,7 +31,7 @@ computed: { text() { return s__(`Milestones|Promoting this label will make it available for all projects inside the group. Existing project labels with the same name will be merged. This action cannot be reversed.`); Existing project labels with the same title will be merged. This action cannot be reversed.`); }, title() { const label = `<span Loading @@ -48,13 +47,10 @@ methods: { onSubmit() { eventHub.$emit('promoteLabelModal.requestStarted', this.url); return axios.post(this.url) return axios.post(this.url, { params: { format: 'json' } }) .then((response) => { eventHub.$emit('promoteLabelModal.requestFinished', { labelUrl: this.url, successful: true }); const responseURL = new URL(response.request.responseURL); const bodyData = responseURL.searchParams.get('body_data'); saveFlashMessage(bodyData, `${this.labelTitle} promoted to group label`, 'notice'); redirectTo(`${responseURL.protocol}//${responseURL.host}${responseURL.pathname}`); visitUrl(response.data.url); }) .catch((error) => { eventHub.$emit('promoteLabelModal.requestFinished', { labelUrl: this.url, successful: false }); Loading
app/controllers/projects/labels_controller.rb +5 −3 Original line number Diff line number Diff line class Projects::LabelsController < Projects::ApplicationController include ToggleSubscriptionAction include FlashHelper before_action :check_issuables_available! before_action :label, only: [:edit, :update, :destroy, :promote] Loading Loading @@ -113,11 +112,14 @@ def promote begin return render_404 unless promote_service.execute(@label) flash[:notice] = "#{@label.title} promoted to group label." respond_to do |format| format.html do redirect_to(project_labels_path(@project, body_data: get_body_data_page(project_labels_path(@project))), status: 303) redirect_to(project_labels_path(@project), status: 303) end format.json do render json: { url: project_labels_path(@project) } end format.js end rescue ActiveRecord::RecordInvalid => e Gitlab::AppLogger.error "Failed to promote label \"#{@label.title}\" to group label" Loading