Skip to content

Commit

Permalink
XWIKI-19180: In case of merge conflict choosing "Reload editors" won'…
Browse files Browse the repository at this point in the history
…t refresh the content
  • Loading branch information
douakli committed Nov 20, 2023
1 parent 61a2b2c commit 8b9f7eb
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,23 @@
#if ("$!{request.convertHTML}" == '1')
#set ($xdom = $services.rendering.parse($currentContent, 'xhtml/1.0'))
#set ($currentContent = $services.rendering.render($xdom, $nextDocument.syntax.toIdString()))
## FIXME: This requires programming rights.
#set ($discard = $xcontext.setDoc($nextDocument.document))
#set ($source = {
'content': $nextDocument.content,
'syntax': $nextDocument.syntax,
'documentReference': $nextDocument.documentReference
})
## FIXME: We shouldn't depend on a particular WYSIWYG editor. The code should work with the configured WYSIWYG
## editor, whatever that may be.
#set ($result.previousVersionContent = $xwiki.getDocument('CKEditor.ContentSheet').getRenderedContent().replaceAll(
"([\t\r\n]|(\s{2,}))", ''))
#else
#set ($result.previousVersionContent = $nextDocument.content)
#end
##
#set ($result.latestVersion = $previousVersion)
#set ($result.currentVersion = $nextDocument.version)
#set ($result.previousVersionContent = $nextDocument.content) ##TODO : convert if needed
##
## We don't need to merge if the content has not been changed outside of the real-time session (previous == next) or
## if the changes done outside of the real-time session are the same as those done within the real-time session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-flamingo-skin-test-pageobjects</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<!-- Realtime synchronization is done through WebSockets. -->
<dependency>
<groupId>javax.websocket</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.xwiki.ckeditor.test.po.AutocompleteDropdown;
import org.xwiki.ckeditor.test.po.image.ImageDialogEditModal;
import org.xwiki.ckeditor.test.po.image.ImageDialogSelectModal;
import org.xwiki.flamingo.skin.test.po.EditConflictModal;
import org.xwiki.flamingo.skin.test.po.EditConflictModal.ConflictChoice;
import org.xwiki.model.reference.AttachmentReference;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.realtime.wysiwyg.test.po.RealtimeCKEditor;
Expand Down Expand Up @@ -641,4 +643,67 @@ void imageWithCaption(TestReference testReference, TestUtils setup) throws Excep
assertEquals("before\n\n[[Smallest **Tree**>>image:image.gif]]\n\n ",
WikiEditPage.gotoPage(testReference).getContent());
}

@Test
@Order(8)
void reloadEditorsMergeConflictManualSave(TestReference testReference, TestUtils setup)
{
//
// First Tab
//

// Start fresh.
setup.deletePage(testReference);

RealtimeWYSIWYGEditPage firstEditPage = RealtimeWYSIWYGEditPage.gotoPage(testReference);
RealtimeCKEditor firstEditor = firstEditPage.getContenEditor();
RealtimeRichTextAreaElement firstTextArea = firstEditor.getRichTextArea();
firstTextArea.sendKeys("First");
firstEditPage.clickSaveAndContinue();

//
// Second Tab
//

String secondTabHandle = setup.getDriver().switchTo().newWindow(WindowType.TAB).getWindowHandle();

RealtimeWYSIWYGEditPage secondEditPage = RealtimeWYSIWYGEditPage.gotoPage(testReference);
RealtimeCKEditor secondEditor = secondEditPage.getContenEditor();
RealtimeRichTextAreaElement secondTextArea = secondEditor.getRichTextArea();

secondTextArea.waitUntilContentContains("First");

//
// Third Tab
//

String thirdTabHandle = setup.getDriver().switchTo().newWindow(WindowType.TAB).getWindowHandle();

RealtimeWYSIWYGEditPage thirdEditPage = RealtimeWYSIWYGEditPage.gotoPage(testReference);
RealtimeCKEditor thirdEditor = thirdEditPage.getContenEditor();
RealtimeRichTextAreaElement thirdTextArea = thirdEditor.getRichTextArea();
thirdTextArea.waitUntilContentContains("First");

thirdEditPage.leaveRealtimeEditing();

thirdTextArea.sendKeys(Keys.END, " Second");
thirdEditPage.clickSaveAndContinue();

// First tab

setup.getDriver().switchTo().window(firstTabHandle);
firstTextArea.sendKeys(Keys.END, " First");
firstTextArea.waitUntilContentContains("First First");
firstEditPage.clickSaveAndContinue(false);

EditConflictModal editConflictModal = new EditConflictModal();
editConflictModal.makeChoiceAndSubmit(ConflictChoice.RELOAD, false);

firstTextArea.waitUntilContentContains("First Second");

// Second tab
setup.getDriver().switchTo().window(secondTabHandle);
secondTextArea.waitUntilContentContains("First Second");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.xwiki.realtime.wysiwyg.test.po;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.xwiki.model.reference.EntityReference;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void leaveRealtimeEditing()
{
if (isRealtimeEditing()) {
this.allowRealtimeCheckbox.click();
// TODO: Handle the confirmation modal.
getDriver().findElement(By.cssSelector(".modal-popup .realtime-buttons .btn-primary")).click();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ define('xwiki-realtime-wysiwygEditor', [
'chainpad',
'xwiki-realtime-crypto',
'deferred!ckeditor',
'xwiki-realtime-wysiwygEditor-patches'
'xwiki-realtime-wysiwygEditor-patches',
'xwiki-realtime-document'
], function (
/* jshint maxparams:false */
$, realtimeConfig, Messages, ErrorBox, Toolbar, ChainPadNetflux, UserData, TypingTest, Interface, Saver,
Chainpad, Crypto, ckeditorPromise, Patches
Chainpad, Crypto, ckeditorPromise, Patches, doc
) {
'use strict';

Expand Down Expand Up @@ -525,6 +526,68 @@ define('xwiki-realtime-wysiwygEditor', [

realtimeOptions.onLocal();
createSaver(info);

// We need to prevent the diff modal from reloading the editor
// because when reloading the realtime editor when editing with
// another user, the content will not be loaded from the saved
// version, but from the existing realtime session.

// Instead of reloading the editor, the content of the realtime
// session should be replaced with the currently saved version.
$(document).on('xwiki:dom:updated', (event, param) => {
// The preview diff modal triggers a xwiki:dom:updated event
// once initialized (opened), after registering the event handlers
if (param?.elements?.first()?.id === "previewDiffModal") {

var submitButton = $('#submitDiffButton');

// We want to keep the existing behavior when reload is
// not the selected option.
// Passing true to the clone method allows to copy event handlers,
// allowing us to call the old event handler even after changing the
// one on the original button.
var oldSubmit = submitButton.clone(true);

// Replace the click event handler of the submit button.
submitButton.off("click");
submitButton.on("click", () => {
if ($('input[name=warningConflictAction]:checked').val() === "reload") {
// Reload is selected so we get the currently saved version from the service.
$.ajax({
url: new XWiki.Document('Ajax', 'RTFrontend').getURL('get', 'xpage=plain&outputSyntax=plain'),
method: 'POST',
dataType: 'json',
data: {
wiki: editor.config.sourceDocument.wiki,
document: XWiki.Model.serialize(doc.documentReference),
// We need to provide a version, but it is used only for the merge functionality.
// It does not affect the previousVersionContent attribute of the answer which
// will still be the currently saved content.
version: doc.version,
convertHTML: 1 // CKEditor expects HTML.
},
success: function(data) {
// We need to replace the content in the editor.
patchedEditor.setHTML(data.previousVersionContent);
// We need to notify the data change in the editor.
// It allows to propagate the new data to coeditors.
editor.fire('change');
// We can now close the modal.
$('#previewDiffModal').modal('hide');
},
error: function(err) {
ErrorBox.show(err);
warn(err);
}
});
} else {
// Keep the old behavior when reload is not selected.
oldSubmit.trigger("click");
}
});

}
});
},

onAbort: function(info, reason, debug) {
Expand Down

0 comments on commit 8b9f7eb

Please sign in to comment.