Fixes #3831 - Ticket zoom will loose attachments on rerender.

This commit is contained in:
Rolf Schmidt 2021-11-05 08:42:16 +01:00
parent 58898239d4
commit 2b94843bb7
3 changed files with 83 additions and 20 deletions

View file

@ -493,16 +493,22 @@ class App.TicketZoom extends App.Controller
@form_id = @taskGet('article').form_id || App.ControllerForm.formId() @form_id = @taskGet('article').form_id || App.ControllerForm.formId()
@articleNew = new App.TicketZoomArticleNew( @articleNew = new App.TicketZoomArticleNew(
ticket: @ticket ticket: @ticket
ticket_id: @ticket_id ticket_id: @ticket_id
el: elLocal.find('.article-new') el: elLocal.find('.article-new')
formMeta: @formMeta formMeta: @formMeta
form_id: @form_id form_id: @form_id
defaults: @taskGet('article') defaults: @taskGet('article')
taskKey: @taskKey taskKey: @taskKey
ui: @ ui: @
callbackFileUploadStart: @submitDisable richTextUploadStartCallback: @submitDisable
callbackFileUploadStop: @submitEnable richTextUploadRenderCallback: (attachments) =>
@submitEnable()
@taskUpdateAttachments('article', attachments)
@delay(@markForm, 250, 'ticket-zoom-form-update')
richTextUploadDeleteCallback: (attachments) =>
@taskUpdateAttachments('article', attachments)
@delay(@markForm, 250, 'ticket-zoom-form-update')
) )
@highligher = new App.TicketZoomHighlighter( @highligher = new App.TicketZoomHighlighter(
@ -721,7 +727,7 @@ class App.TicketZoom extends App.Controller
# add attachments if exist # add attachments if exist
attachmentCount = @$('.article-add .textBubble .attachments .attachment').length attachmentCount = @$('.article-add .textBubble .attachments .attachment').length
if attachmentCount > 0 if attachmentCount > 0
currentParams.article.attachments = true currentParams.article.attachments = attachmentCount
else else
delete currentParams.article.attachments delete currentParams.article.attachments
@ -1079,6 +1085,13 @@ class App.TicketZoom extends App.Controller
App.TaskManager.update(@taskKey, taskData) App.TaskManager.update(@taskKey, taskData)
taskUpdateAttachments: (area, attachments) =>
taskData = App.TaskManager.get(@taskKey)
return if !taskData
taskData.attachments = attachments
App.TaskManager.update(@taskKey, taskData)
taskUpdateAll: (data) => taskUpdateAll: (data) =>
@localTaskData = data @localTaskData = data
@localTaskData.article['form_id'] = @form_id @localTaskData.article['form_id'] = @form_id
@ -1101,7 +1114,7 @@ class App.TicketZoom extends App.Controller
@localTaskData = @localTaskData =
ticket: {} ticket: {}
article: {} article: {}
App.TaskManager.update(@taskKey, { 'state': @localTaskData }) App.TaskManager.update(@taskKey, { 'state': @localTaskData, attachments: [] })
renderOverviewNavigator: (parentEl) -> renderOverviewNavigator: (parentEl) ->
new App.TicketZoomOverviewNavigator( new App.TicketZoomOverviewNavigator(

View file

@ -198,17 +198,17 @@ class App.TicketZoomArticleNew extends App.Controller
inputField: @$('.article-attachment input') inputField: @$('.article-attachment input')
onFileStartCallback: => onFileStartCallback: =>
@callbackFileUploadStart?() @richTextUploadStartCallback?()
onFileCompletedCallback: (response) => onFileCompletedCallback: (response) =>
@attachments.push response.data @attachments.push response.data
@renderAttachment(response.data) @renderAttachment(response.data)
@$('.article-attachment input').val('') @$('.article-attachment input').val('')
@callbackFileUploadStop?() @richTextUploadRenderCallback?(@attachments)
onFileAbortedCallback: => onFileAbortedCallback: =>
@callbackFileUploadStop?() @richTextUploadRenderCallback?(@attachments)
attachmentPlaceholder: @attachmentPlaceholder attachmentPlaceholder: @attachmentPlaceholder
attachmentUpload: @attachmentUpload attachmentUpload: @attachmentUpload
@ -287,7 +287,6 @@ class App.TicketZoomArticleNew extends App.Controller
params.preferences ||= {} params.preferences ||= {}
params.preferences.security = @paramsSecurity() params.preferences.security = @paramsSecurity()
params.attachments = @attachments
params params
validate: => validate: =>
@ -624,6 +623,8 @@ class App.TicketZoomArticleNew extends App.Controller
$(e.currentTarget).closest('.attachment').remove() $(e.currentTarget).closest('.attachment').remove()
if element.find('.attachment').length == 0 if element.find('.attachment').length == 0
element.empty() element.empty()
@richTextUploadDeleteCallback?(@attachments)
) )
actions: -> actions: ->

View file

@ -2011,13 +2011,13 @@ RSpec.describe 'Ticket zoom', type: :system do
end end
def expect_upload_and_text def expect_upload_and_text
expect(page).to have_text('mail001.box') expect(page.find('.article-new')).to have_text('mail001.box')
expect(page).to have_text("Hello\nThis\nis\nimportant!\nyo\nhoho\ntest test test test") expect(page.find('.article-new')).to have_text("Hello\nThis\nis\nimportant!\nyo\nhoho\ntest test test test")
end end
def expect_no_upload_and_text def expect_no_upload_and_text
expect(page).to have_no_text('mail001.box') expect(page.find('.article-new')).to have_no_text('mail001.box')
expect(page).to have_no_text("Hello\nThis\nis\nimportant!\nyo\nhoho\ntest test test test") expect(page.find('.article-new')).to have_no_text("Hello\nThis\nis\nimportant!\nyo\nhoho\ntest test test test")
end end
it 'does show up the attachments after a reload of the page' do it 'does show up the attachments after a reload of the page' do
@ -2044,6 +2044,55 @@ RSpec.describe 'Ticket zoom', type: :system do
refresh refresh
expect_no_upload_and_text expect_no_upload_and_text
end end
context 'when rerendering (#3831)' do
def rerender
page.evaluate_script("App.Event.trigger('ui:rerender')")
end
it 'does loose attachments after rerender' do
upload_and_set_text
expect_upload_and_text
rerender
expect_upload_and_text
end
it 'does not readd the attachments after reset' do
upload_and_set_text
expect_upload_and_text
page.find('.js-reset').click
wait_for_upload_blank
expect_no_upload_and_text
rerender
expect_no_upload_and_text
end
it 'does not readd the attachments after submit' do
upload_and_set_text
expect_upload_and_text
page.find('.js-submit').click
wait_for_upload_blank
expect_no_upload_and_text
rerender
expect_no_upload_and_text
end
it 'does not show the ticket as changed after the upload removal' do
page.find('input#fileUpload_1', visible: :all).set(Rails.root.join('test/data/mail/mail001.box'))
expect(page.find('.article-new')).to have_text('mail001.box')
wait_for_upload_present
begin
page.evaluate_script("$('div.attachment-delete.js-delete:last').click()") # not interactable
rescue # Lint/SuppressedException
# because its not interactable it also
# returns this weird exception for the jquery
# even tho it worked fine
end
expect(page).to have_no_selector('.js-reset')
end
end
end end
describe 'Unable to close tickets in certran cases if core workflow is used #3710', authenticated_as: :authenticate, db_strategy: :reset do describe 'Unable to close tickets in certran cases if core workflow is used #3710', authenticated_as: :authenticate, db_strategy: :reset do