Skip to content

Commit

Permalink
added rest-api get_htmldiff
Browse files Browse the repository at this point in the history
  • Loading branch information
drfho committed Nov 16, 2024
1 parent 6c6ca87 commit f31ffe8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
9 changes: 8 additions & 1 deletion Products/zms/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def __call__(self, REQUEST=None, **kw):
decoration, data = self.get_tag(self.context, content_type=True)
elif self.ids == ['body_content']:
decoration, data = self.body_content(self.context, content_type=True)
elif self.ids == ['get_htmldiff']:
decoration, data = self.get_htmldiff(self.context, content_type=True)
elif self.ids == [] or self.ids == ['get']:
decoration, data = self.get(self.context, content_type=True)
else:
Expand Down Expand Up @@ -330,4 +332,9 @@ def body_content(self, context):
html = []
html.append('<div class="%s"><h1>%s<small>%s</small></h1></div>'%(version_container.meta_id,version_container.getTitle(request),version_container.getDCDescription(request)))
html.append(version_container.getBodyContent(request))
return '\n'.join(html)
return '\n'.join(html)

@api(tag="version", pattern="/{path}/get_htmldiff", method="POST", content_type="text/html")
def get_htmldiff(self, context, original='<pre>original</pre>', changed='<pre>changed</pre>'):
request = _get_request(context)
return standard.htmldiff(original, changed)
17 changes: 17 additions & 0 deletions Products/zms/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2234,6 +2234,23 @@ def processData(context, processId, data, trans=None):
return _filtermanager.processData(context, processId, data, trans)


security.declarePublic('htmldiff')
def htmldiff(original, changed):
"""
Wrapper for htmldiff2.render_html_diff.
@param original: html-file-0
@type context: C{str}
@param changed: html-file-1
@type changed: C{str}
"""
try:
from htmldiff2 import render_html_diff
diff = render_html_diff(original,changed)
except:
diff = '<pre>ERROR: Cannot load or work with htmldiff2</pre>'
return diff


############################################################################
#
#{ Executable
Expand Down
25 changes: 22 additions & 3 deletions Products/zms/zpt/versionmanager/manage_undoversionform.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
level python:here.getLevel();
obj_versions python:here.getObjVersions();">

<div class="container diff-container">
<div class="diff-container container">
<div class="row">
<div class="col-sm-6">
<div class="col-sm-6 col-original">
<div class="input-group mb-3" title="original">
<div class="input-group-prepend">
<span class="form-control input-group-text alert-danger">Version</span>
Expand All @@ -23,7 +23,7 @@
<div class="original preview"></div>
<pre class="original json d-none"></pre>
</div>
<div class="col-sm-6">
<div class="col-sm-6 col-changed">
<div class="input-group mb-3" title="changed">
<div class="input-group-prepend">
<span class="form-control input-group-text alert-success">Version</span>
Expand Down Expand Up @@ -92,6 +92,25 @@ function toggle_view(btn,btn_func) {
}
}

function get_htmldiff() {
let href = $ZMI.getPhysicalPath();
let original = $('.diff-container .original.preview').html();
let changed = $('.diff-container .changed.preview').html();
let data = {
'original':original,
'changed':changed
};
$.ajax({
type: "POST",
url: $ZMI.get_rest_api_url(href)+'/get_htmldiff',
data: data,
dataType: 'html',
success: function(html) {
$('.diff.preview').html(html);
}
});
}

function diff(container, qualifier) {
var diffContainer = qualifier+".diff";
$(container).prettyTextDiff({
Expand Down

0 comments on commit f31ffe8

Please sign in to comment.