Commit e6369dc5 by tasawernawaz Committed by Tasawer Nawaz

Remove html tags before comparing course fields

ECOM-7694
parent 99efb6c0
......@@ -15,12 +15,24 @@ $(document).on('click', '.btn-show-changes', function (e) {
}
});
function getComparableText(object) {
if ($(object).find('.dont-compare').length > 0) {
return "";
} else {
return object.text().trim()
}
}
var dmp = new diff_match_patch();
dmp.Diff_EditCost = 8;
function showDiff($object, $historyObject, $outputDiv) {
var d = dmp.diff_main($historyObject.text(), $object.text());
dmp.diff_cleanupEfficiency(d);
$outputDiv.html(dmp.diff_prettyHtml(d));
var currentText = $($.parseHTML($object.text())).text().trim(),
historyText = getComparableText($historyObject),
diff;
diff = dmp.diff_main(historyText, currentText);
dmp.diff_cleanupEfficiency(diff);
$outputDiv.html(dmp.diff_prettyHtml(diff));
$historyObject.hide();
$outputDiv.show();
}
......
......@@ -12,14 +12,18 @@ $(document).on('change', '#id_select_revisions', function (e) {
});
function loadRevisionHistory(revisionUrl) {
var currentObject,
currentObjectText;
$.getJSON({
url: revisionUrl,
success: function (data) {
$.each(data, function(key, value) {
var currentObject = $('.history-field-container').find('.' + key);
currentObject = $('.history-field-container').find('.' + key);
if (currentObject.length && value != null) {
showDiffCourseDetails(value, currentObject.text(), currentObject.siblings('.show-diff'));
currentObjectText = getComparableText(currentObject);
value = $($.parseHTML(value)).text().trim();
showDiffCourseDetails(value, currentObjectText, currentObject.siblings('.show-diff'));
currentObject.hide();
}
});
......
......@@ -3,5 +3,5 @@
{% if field %}
{{ field|safe }}
{% else %}
{% trans "(Optional) Not yet added" %}
<div class="dont-compare">{% trans "(Optional) Not yet added" %}</div>
{% endif %}
......@@ -3,5 +3,5 @@
{% if field %}
{{ field|safe }}
{% else %}
{% trans "(Required) Not yet added" %}
<div class="dont-compare">{% trans "(Required) Not yet added" %}</div>
{% endif %}
......@@ -45,7 +45,11 @@
<div class="field-container">
<div class="field-title">{% trans "Brief Description" %}</div>
<span class="object">{{ object.short_description }}</span>
<span class="history-object">{{ history_object.short_description }}</span>
<span class="history-object">
{% with history_object.short_description as field %}
{% include "publisher/_render_required_field.html" %}
{% endwith %}
</span>
<span class="show-diff"></span>
</div>
......@@ -53,7 +57,11 @@
<div class="field-container">
<div class="field-title">{% trans "Full Description" %}</div>
<span class="object">{{ object.full_description }}</span>
<span class="history-object">{{ history_object.full_description }}</span>
<span class="history-object">
{% with history_object.full_description as field %}
{% include "publisher/_render_required_field.html" %}
{% endwith %}
</span>
<span class="show-diff"></span>
</div>
......@@ -61,56 +69,88 @@
<div class="field-container">
<div class="field-title">{% trans "Expected Learnings" %}</div>
<span class="object">{{ object.expected_learnings }}</span>
<span class="history-object">{{ history_object.expected_learnings }}</span>
<span class="history-object">
{% with history_object.expected_learnings as field %}
{% include "publisher/_render_required_field.html" %}
{% endwith %}
</span>
<span class="show-diff"></span>
</div>
<div class="field-container">
<div class="field-title">{% trans "Primary Subject" %}</div>
<span class="object">{{ object.primary_subject }}</span>
<span class="history-object">{{ history_object.primary_subject }}</span>
<span class="history-object">
{% with history_object.primary_subject as field %}
{% include "publisher/_render_required_field.html" %}
{% endwith %}
</span>
<span class="show-diff"></span>
</div>
<div class="field-container">
<div class="field-title">{% trans "Secondary Subject" %}</div>
<span class="object">{{ object.secondary_subject }}</span>
<span class="history-object">{{ history_object.secondary_subject }}</span>
<span class="history-object">
{% with history_object.secondary_subject as field %}
{% include "publisher/_render_optional_field.html" %}
{% endwith %}
</span>
<span class="show-diff"></span>
</div>
<div class="field-container">
<div class="field-title">{% trans "Tertiary Subject" %}</div>
<span class="object">{{ object.tertiary_subject }}</span>
<span class="history-object">{{ history_object.tertiary_subject }}</span>
<span class="history-object">
{% with history_object.tertiary_subject as field %}
{% include "publisher/_render_optional_field.html" %}
{% endwith %}
</span>
<span class="show-diff"></span>
</div>
<div class="field-container">
<div class="field-title">{% trans "Prerequisites" %}</div>
<span class="object">{{ object.prerequisites }}</span>
<span class="history-object">{{ history_object.prerequisites }}</span>
<span class="history-object">
{% with history_object.prerequisites as field %}
{% include "publisher/_render_required_field.html" %}
{% endwith %}
</span>
<span class="show-diff"></span>
</div>
<div class="field-container">
<div class="field-title">{% trans "Course Level" %}</div>
<span class="object">{{ object.level_type }}</span>
<span class="history-object">{{ history_object.level_type }}</span>
<span class="history-object">
{% with history_object.level_type as field %}
{% include "publisher/_render_required_field.html" %}
{% endwith %}
</span>
<span class="show-diff"></span>
</div>
<div class="field-container">
<div class="field-title">{% trans "Learner Testimonials" %}</div>
<span class="object">{{ object.learner_testimonial }}</span>
<span class="history-object">{{ history_object.learner_testimonial }}</span>
<span class="history-object">
{% with history_object.learner_testimonial as field %}
{% include "publisher/_render_optional_field.html" %}
{% endwith %}
</span>
<span class="show-diff"></span>
</div>
<div class="field-container">
<div class="field-title">{% trans "FAQ" %}</div>
<span class="object">{{ object.faq }}</span>
<span class="history-object">{{ history_object.faq }}</span>
<span class="history-object">
{% with history_object.faq as field %}
{% include "publisher/_render_optional_field.html" %}
{% endwith %}
</span>
<span class="show-diff"></span>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment