Skip to content

Commit

Permalink
Move scripts and CSS out of HTML, only show metadata diffs for most r…
Browse files Browse the repository at this point in the history
…ecent displayed change
  • Loading branch information
hayley-leblanc committed Aug 8, 2019
1 parent 4a990c6 commit 0fb1373
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 51 deletions.
12 changes: 6 additions & 6 deletions ckan/lib/changes.py
Expand Up @@ -119,7 +119,7 @@ def _check_resource_changes(change_list, original, new, new_pkg,

# if a format was not originally set and the user set one
if not original_metadata['format'] and new_metadata['format']:
change_list.append({u'type': 'resource_format',
change_list.append({u'type': u'resource_format',
u'method': u'add',
u'pkg_id': new_pkg['pkg_id'],
u'title': new_pkg['title'],
Expand Down Expand Up @@ -308,7 +308,7 @@ def _maintainer_change(change_list, original, new, new_pkg):
u'method': u'remove'})
# if there wasn't one there before
else:
change_list.append({u'type': 'maintainer', u'pkg_id':
change_list.append({u'type': u'maintainer', u'pkg_id':
new_pkg['pkg_id'], u'title': new_pkg['title'],
u'new_maintainer': new['maintainer'],
u'method': u'add'})
Expand Down Expand Up @@ -336,7 +336,7 @@ def _maintainer_email_change(change_list, original, new, new_pkg):
else:
change_list.append({u'type': u'maintainer_email', u'pkg_id':
new_pkg['pkg_id'], u'title': new_pkg['title'],
'new_maintainer_email': new['maintainer_email'],
u'new_maintainer_email': new['maintainer_email'],
u'method': u'add'})


Expand Down Expand Up @@ -441,8 +441,8 @@ def _license_change(change_list, original, new, new_pkg):
Appends a summary of a change to a dataset's license between two versions
(original and new) to change_list.
'''
original_license_url = ""
new_license_url = ""
original_license_url = u""
new_license_url = u""
# if the license has a URL
if u'license_url' in original and original['license_url']:
original_license_url = original['license_url']
Expand Down Expand Up @@ -501,7 +501,7 @@ def _version_change(change_list, original, new, new_pkg):
'''
# if both old and new versions have version numbers
if original['version'] and new['version']:
change_list.append({u'type': 'version', u'method': u'change',
change_list.append({u'type': u'version', u'method': u'change',
u'pkg_id': new_pkg['pkg_id'], u'title':
new_pkg['title'], u'old_version':
original['version'], u'new_version':
Expand Down
7 changes: 5 additions & 2 deletions ckan/lib/helpers.py
Expand Up @@ -2709,8 +2709,11 @@ def compare_pkg_dicts(original, new, old_activity_id):
from changes import _check_metadata_changes, _check_resource_changes
change_list = []

new_pkg = {u'pkg_id': new['id'], u'name': new['name'],
u'title': new['title']}
new_pkg = {
u'pkg_id': new['id'],
u'name': new['name'],
u'title': new['title']
}

_check_metadata_changes(change_list, original, new, new_pkg)

Expand Down
15 changes: 15 additions & 0 deletions ckan/public/base/css/main.css
Expand Up @@ -10760,3 +10760,18 @@ iframe {
.reduced-padding {
padding: 3px 5px;
}

.select-time {
width: 250px;
display: inline;
}

br.line-height2 {
line-height: 2;
}

.select-div {
width:250px;
position:absolute;
right:30px;
}
38 changes: 38 additions & 0 deletions ckan/public/base/javascript/modules/metadata-button.js
@@ -0,0 +1,38 @@
/* Watches the "Show metadata diff" button on the Changes summary page.
* When the button is pressed, toggles the display of the metadata diff
* for the chronologically most recent revision on and off.
*
* target - a button to watch for changes (default: button)
*
*/

ckan.module('metadata-button', function(jQuery) {
return {
options: {
target: 'button'
},

initialize: function () {
// Watch for our button to be clicked.
this.el.on('click', jQuery.proxy(this._onClick, this));
},

_onClick: function(event) {
console.log("PRESSED THE BUTTON");
var div = document.getElementById("metadata_diff");
if (div.style.display === "none") {
div.style.display = "block";
}
else {
div.style.display = "none";
}
var btn = document.getElementById("metadata_button");
if (btn.value === "Show metadata diff") {
btn.value = "Hide metadata diff";
}
else {
btn.value = "Show metadata diff";
}
}
}
});
1 change: 1 addition & 0 deletions ckan/public/base/javascript/webassets.yml
Expand Up @@ -57,6 +57,7 @@ ckan:
- modules/media-grid.js
- modules/image-upload.js
- modules/followers-counter.js
- modules/metadata-button.js

tracking:
output: base/%(version)s_tracking.js
Expand Down
25 changes: 18 additions & 7 deletions ckan/templates/package/changes.html
Expand Up @@ -13,29 +13,28 @@
{% block primary %}
<article class="module">
<div class="module-content">
<div style="width:250px;position:absolute;right:30px;">
<div class="select-div">
</div>
{% block package_changes_header %}
<h1 class="page-heading">{{ _('Changes') }}</h1>
{% endblock %}

{% set select_list1 = h.activity_list_select(pkg_activity_list, activity_diffs[-1].activities[0].id) %}
{% set select_list2 = h.activity_list_select(pkg_activity_list, activity_diffs[0].activities[1].id) %}
<form id="range_form" action="{{ h.url_for('dataset.change_range') }}" >
<form id="range_form" action="{{ h.url_for('dataset.change_range') }}" data-module="select-switch" data-module-target="">
<input type="hidden" name="current_old_id" value="{{ activity_diffs[-1].activities[0].id }}">
<input type="hidden" name="current_new_id" value="{{ activity_diffs[0].activities[1].id }}">
View changes from
<select class="form-control" style="width:235px;display:inline;" form="range_form" name="oldest_id">
<select class="form-control select-time" form="range_form" name="oldest_id">
<pre>
{{ select_list1[1:]|safe }}
</pre>
</select> to
<select class="form-control" style="width:235px;display:inline;" form="range_form" name="newest_id">
<select class="form-control select-time" form="range_form" name="newest_id">
<pre>
{{ select_list2|safe }}
</pre>
</select>
<input class="btn" style="display:inline;" type="submit" value="Submit">
</form>

<br>
Expand All @@ -44,10 +43,22 @@ <h1 class="page-heading">{{ _('Changes') }}</h1>
<hr>
{% for i in range(activity_diffs|length) %}
{% snippet "package/snippets/change_item.html", activity_diff=activity_diffs[i], pkg_dict=pkg_dict %}
<br style="line-height:2;">

{# TODO: display metadata for more than most recent change #}
{% if i == 0 %}
{# button to show JSON metadata diff for the most recent change - not shown by default #}
<input type="button" data-module="metadata-button" data-module-target="" class="btn" value="Show metadata diff" id="metadata_button"></input>
<div id="metadata_diff" style="display:none;">
{% block package_changes_diff %}
<pre>
{{ activity_diffs[0]['diff']|safe }}
</pre>
{% endblock %}
</div>
{% endif %}

<hr>
{% endfor %}

</div>
</article>
{% endblock %}
Expand Down
30 changes: 0 additions & 30 deletions ckan/templates/package/snippets/change_item.html
Expand Up @@ -8,33 +8,3 @@
<br>
{% endfor %}
</ul>

{# button to show JSON metadata diff - not shown by default #}
<input type="button" onClick="show_metadata()" class="btn" value="Show metadata diff" id="metadata_button"></input>

<div id="metadata_diff" style="display:none;">
{% block package_changes_diff %}
<pre>
{{ activity_diff['diff']|safe }}
</pre>
{% endblock %}
</div>

<script>
function show_metadata() {
var div = document.getElementById("metadata_diff");
if (div.style.display === "none") {
div.style.display = "block";
}
else {
div.style.display = "none";
}
var btn = document.getElementById("metadata_button");
if (btn.value === "Show metadata diff") {
btn.value = "Hide metadata diff";
}
else {
btn.value = "Show metadata diff";
}
}
</script>
6 changes: 3 additions & 3 deletions ckan/templates/snippets/changes/description.html
Expand Up @@ -2,8 +2,8 @@
<p>
{% if ah.method == "change" %}
{{ _('Updated description of <a href="{pkg_url}">{dataset}</a> from
<br style="line-height:2;"><blockquote>{old_desc}</blockquote>
to <br style="line-height:2;"><blockquote>{new_desc}
<br class="line-height2"><blockquote>{old_desc}</blockquote>
to <br class="line-height2"><blockquote>{new_desc}
</blockquote>').format(
pkg_url = h.url_for(controller='dataset', action='read', id=ah.pkg_id),
dataset = ah.title,
Expand All @@ -12,7 +12,7 @@
)|safe }}
{% elif ah.method == "add" %}
{{ _('Updated description of <a href="{pkg_url}">{dataset}</a>
to <br style="line-height:2;"><blockquote>{new_desc}
to <br class="line-height2"><blockquote>{new_desc}
</blockquote>').format(
pkg_url = h.url_for(controller='dataset', action='read', id=ah.pkg_id),
dataset = ah.title,
Expand Down
6 changes: 3 additions & 3 deletions ckan/templates/snippets/changes/resource_desc.html
Expand Up @@ -3,7 +3,7 @@
{% if ah.method == "add" %}
{{ _('Updated description of resource <a href="{resource_url}">
{resource_name}</a> in <a href="{pkg_url}">{dataset}</a>
to <br style="line-height:2;"><blockquote>{new_desc}</blockquote>'
to <br class="line-height2"><blockquote>{new_desc}</blockquote>'
).format(
pkg_url = h.url_for(controller='dataset', action='read', id=ah.pkg_id),
dataset = ah.title,
Expand All @@ -24,8 +24,8 @@
{% elif ah.method == "change" %}
{{ _('Updated description of resource <a href="{resource_url}">
{resource_name}</a> in <a href="{pkg_url}">{dataset}</a>
from <br style="line-height:2;"><blockquote>{old_desc}</blockquote>
to <br style="line-height:2;"><blockquote>{new_desc}</blockquote>'
from <br class="line-height2"><blockquote>{old_desc}</blockquote>
to <br class="line-height2"><blockquote>{new_desc}</blockquote>'
).format(
pkg_url = h.url_for(controller='dataset', action='read', id=ah.pkg_id),
dataset = ah.title,
Expand Down

0 comments on commit 0fb1373

Please sign in to comment.