Skip to content

Commit

Permalink
Add list view for metadata standard attribute mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-saeon committed Nov 27, 2018
1 parent 3d0c150 commit aad6f70
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
19 changes: 19 additions & 0 deletions ckanext/metadata/controllers/metadata_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,25 @@ def activity(self, id):
return tk.render('metadata_standard/activity_stream.html')

def attr_maps(self, id):
context = {'model': model, 'session': model.Session, 'user': tk.c.user}
try:
data_dict = {'metadata_standard_id': id, 'all_fields': True}
tk.c.attr_maps = tk.get_action('metadata_json_attr_map_list')(context, data_dict)
tk.c.metadata_standard = tk.get_action('metadata_standard_show')(context, {'id': id})
except tk.ObjectNotFound:
tk.abort(404, tk._('Metadata standard not found'))
except tk.NotAuthorized:
tk.abort(403, tk._('Not authorized to see this page'))

return tk.render('metadata_standard/attr_maps.html')

def attr_map_new(self, id):
pass

def attr_map_edit(self, id, attr_map_id):
pass

def attr_map_delete(self, id, attr_map_id):
pass

@staticmethod
Expand Down
3 changes: 3 additions & 0 deletions ckanext/metadata/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def before_map(self, map):
map.connect('metadata_standard_about', '/metadata_standard/about/{id}', controller=controller, action='about', ckan_icon='info-circle')
map.connect('metadata_standard_activity', '/metadata_standard/activity/{id}', controller=controller, action='activity', ckan_icon='clock-o')
map.connect('metadata_standard_attr_maps', '/metadata_standard/attr_maps/{id}', controller=controller, action='attr_maps', ckan_icon='random')
map.connect('/metadata_standard/attr_map_new/{id}', controller=controller, action='attr_map_new')
map.connect('/metadata_standard/attr_map_edit/{id}/{attr_map_id}', controller=controller, action='attr_map_edit')
map.connect('/metadata_standard/attr_map_delete/{id}/{attr_map_id}', controller=controller, action='attr_map_delete')

controller = 'ckanext.metadata.controllers.workflow_state:WorkflowStateController'
map.connect('workflow_state_index', '/workflow_state', controller=controller, action='index')
Expand Down
41 changes: 41 additions & 0 deletions ckanext/metadata/templates/metadata_standard/attr_maps.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% extends "metadata_standard/edit_base.html" %}

{% block subtitle %}{{ _('Attribute Mappings') }} - {{ c.metadata_standard.display_name }} - {{ _('Metadata Standards') }}{% endblock %}

{% block page_primary_action %}
{% link_for _('Create Attribute Mapping'), controller='ckanext.metadata.controllers.metadata_standard:MetadataStandardController',
action='attr_map_new', id=c.metadata_standard.name, class_='btn btn-primary', icon='plus-square' %}
{% endblock %}

{% block primary_content_inner %}
<h3 class="page-heading">{{ _('{0} attribute mapping(s)'.format(c.attr_maps|length)) }}</h3>
<table class="table table-header table-hover table-bordered" id="member-table">
<thead>
<tr>
<th>{{ _('Attribute') }}</th>
<th>{{ _('JSON Path') }}</th>
<th></th>
</tr>
</thead>
<tbody>
{% for attr_map in c.attr_maps %}
<tr>
<td>{{ attr_map.record_attr }} {% if attr_map.is_key %}<i class="fa fa-key fa-rotate-90"></i>{% endif %}</td>
<td>{{ attr_map.json_path }}</td>
<td>
<div class="btn-group pull-right">
<a class="btn btn-small" href="{% url_for controller='ckanext.metadata.controllers.metadata_standard:MetadataStandardController',
action='attr_map_edit', id=c.metadata_standard.name, attr_map_id=attr_map.id %}"
title="{{ _('Edit') }}"><i class="fa fa-wrench"></i>
</a>
<a class="btn btn-danger btn-small" href="{% url_for controller='ckanext.metadata.controllers.metadata_standard:MetadataStandardController',
action='attr_map_delete', id=c.metadata_standard.name, attr_map_id=attr_map.id %}"
data-module="confirm-action" data-module-content="{{ _('Are you sure you want to delete this attribute mapping?') }}"
title="{{ _('Delete') }}">{% block delete_button_text %}<i class="fa fa-times"></i>{% endblock %}</a>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
10 changes: 0 additions & 10 deletions ckanext/metadata/templates/metadata_standard/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,3 @@
{% block subtitle %}
{{ _('Manage') }} - {{ c.metadata_standard.display_name }} - {{ _('Metadata Standards') }}
{% endblock %}

{% block breadcrumb_content %}
{% snippet "metadata_standard/snippets/breadcrumb_content_outer.html" %}
{% snippet "metadata_standard/snippets/breadcrumb_content_item.html" %}
{% snippet "metadata_standard/snippets/breadcrumb_content_manage.html" %}
{% endblock %}

{% block secondary_content %}
{% snippet "metadata_standard/snippets/info.html", metadata_standard=c.metadata_standard %}
{% endblock %}
10 changes: 10 additions & 0 deletions ckanext/metadata/templates/metadata_standard/edit_base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{% extends "page.html" %}

{% block breadcrumb_content %}
{% snippet "metadata_standard/snippets/breadcrumb_content_outer.html" %}
{% snippet "metadata_standard/snippets/breadcrumb_content_item.html" %}
{% snippet "metadata_standard/snippets/breadcrumb_content_manage.html" %}
{% endblock %}

{% block page_primary_action %}{% endblock %}

{% block primary_content_inner %}
Expand All @@ -18,3 +24,7 @@ <h1 class="{% block page_heading_class %}page-heading{% endblock %}">{% block pa
{{ h.build_nav_icon('metadata_standard_edit', _('Edit'), id=c.metadata_standard.name) }}
{{ h.build_nav_icon('metadata_standard_attr_maps', _('Attribute Mappings'), id=c.metadata_standard.name) }}
{% endblock %}

{% block secondary_content %}
{% snippet "metadata_standard/snippets/info.html", metadata_standard=c.metadata_standard %}
{% endblock %}

0 comments on commit aad6f70

Please sign in to comment.