-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7763 from mutantsan/7710-fix-datastore-and-datapu…
…sher-templates-init [#7710] add datastore and datapusher templates-bs3
- Loading branch information
Showing
16 changed files
with
625 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
ckanext/datapusher/templates-bs3/datapusher/resource_data.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{% extends "package/resource_edit_base.html" %} | ||
|
||
{% block subtitle %}{{ h.dataset_display_name(pkg) }} - {{ h.resource_display_name(res) }}{% endblock %} | ||
|
||
{% block primary_content_inner %} | ||
|
||
{% set action = h.url_for('datapusher.resource_data', id=pkg.name, resource_id=res.id) %} | ||
{% set show_table = true %} | ||
|
||
<form method="post" action="{{ action }}" class="datapusher-form"> | ||
<button class="btn btn-primary" name="save" type="submit"> | ||
<i class="fa fa-cloud-upload"></i> {{ _('Upload to DataStore') }} | ||
</button> | ||
</form> | ||
|
||
{% if status.error and status.error.message %} | ||
{% set show_table = false %} | ||
<div class="alert alert-error"> | ||
<strong>{{ _('Upload error:') }}</strong> {{ status.error.message }} | ||
</div> | ||
{% elif status.task_info and status.task_info.error %} | ||
<div class="alert alert-error"> | ||
{% if status.task_info.error is string %} | ||
{# DataPusher < 0.0.3 #} | ||
<strong>{{ _('Error:') }}</strong> {{ status.task_info.error }} | ||
{% elif status.task_info.error is mapping %} | ||
<strong>{{ _('Error:') }}</strong> {{ status.task_info.error.message }} | ||
{% for error_key, error_value in status.task_info.error.items() %} | ||
{% if error_key != "message" and error_value %} | ||
<br> | ||
<strong>{{ error_key }}</strong>: | ||
{{ error_value }} | ||
{% endif %} | ||
{% endfor %} | ||
{% elif status.task_info.error is iterable %} | ||
<strong>{{ _('Error traceback:') }}</strong> | ||
<pre>{{ ''.join(status.task_info.error) }}</pre> | ||
{% endif %} | ||
</div> | ||
{% endif %} | ||
|
||
<table class="table table-bordered"> | ||
<colgroup> | ||
<col width="150"> | ||
<col> | ||
</colgroup> | ||
<tr> | ||
<th>{{ _('Status') }}</th> | ||
<td>{{ h.datapusher_status_description(status) }}</td> | ||
</tr> | ||
<tr> | ||
<th>{{ _('Last updated') }}</th> | ||
{% if status.status %} | ||
<td><span class="date" title="{{ h.render_datetime(status.last_updated, with_hours=True) }}">{{ h.time_ago_from_timestamp(status.last_updated) }}</span></td> | ||
{% else %} | ||
<td>{{ _('Never') }}</td> | ||
{% endif %} | ||
</tr> | ||
</table> | ||
|
||
{% if status.status and status.task_info and show_table %} | ||
<h3>{{ _('Upload Log') }}</h3> | ||
<ul class="activity"> | ||
{% for item in status.task_info.logs|sort(attribute='timestamp') %} | ||
{% set icon = 'ok' if item.level == 'INFO' else 'exclamation' %} | ||
{% set class = ' failure' if icon == 'exclamation' else ' success' %} | ||
{% set popover_content = 'test' %} | ||
<li class="item no-avatar{{ class }}"> | ||
<i class="fa icon fa-{{ icon }}"></i> | ||
<p> | ||
{% for line in item.message.strip().split('\n') %} | ||
{{ line | urlize }}<br> | ||
{% endfor %} | ||
<span class="date" title="{{ h.render_datetime(item.timestamp, with_hours=True) }}"> | ||
{{ h.time_ago_from_timestamp(item.timestamp) }} | ||
<a href="#" data-target="popover" data-content="<dl>{% for key, value in item.items() %}<dt>{{ key }}</dt><dd>{{ h.clean_html(value|string) }}</dd>{% endfor %}</dl>" data-html="true">{{ _('Details') }}</a> | ||
</span> | ||
</p> | ||
</li> | ||
{% endfor %} | ||
<li class="item no-avatar"> | ||
<i class="fa icon fa-info"></i> | ||
<p class="muted">{{ _('End of log') }}</p> | ||
</li> | ||
</ul> | ||
{% endif %} | ||
|
||
{% endblock %} |
16 changes: 16 additions & 0 deletions
16
ckanext/datapusher/templates-bs3/package/resource_edit_base.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% ckan_extends %} | ||
|
||
{% block scripts %} | ||
{{ super() }} | ||
{% asset 'ckanext-datapusher/datapusher' %} | ||
{% endblock scripts %} | ||
|
||
{% block styles %} | ||
{{ super() }} | ||
{% asset 'ckanext-datapusher/datapusher-css' %} | ||
{% endblock %} | ||
|
||
{% block inner_primary_nav %} | ||
{{ super() }} | ||
{{ h.build_nav_icon('datapusher.resource_data', _('DataStore'), id=pkg.name, resource_id=res.id) }} | ||
{% endblock %} |
137 changes: 137 additions & 0 deletions
137
ckanext/datastore/templates-bs3/ajax_snippets/api_info.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
{# | ||
Displays information about accessing a resource via the API. | ||
|
||
resource_id - The resource id | ||
embedded - If true will not include the "modal" classes on the snippet. | ||
|
||
Example | ||
|
||
{% snippet 'ajax_snippets/api_info.html', resource_id=resource_id, embedded=true %} | ||
|
||
#} | ||
|
||
{% set resource_id = h.sanitize_id(resource_id) %} | ||
{% set sql_example_url = h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search_sql', qualified=True) + '?sql=SELECT * from "' + resource_id + '" WHERE title LIKE \'jones\'' %} | ||
{# not urlencoding the sql because its clearer #} | ||
<div{% if not embedded %} class="modal fade"{% endif %}> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h3> | ||
{{ _('CKAN Data API') }} | ||
</h3> | ||
</div> | ||
<div{% if not embedded %} class="modal-body"{% endif %}> | ||
<p><strong>{{ _('Access resource data via a web API with powerful query support') }}</strong>. | ||
{% trans %} | ||
Further information in the <a | ||
href="http://docs.ckan.org/en/latest/maintaining/datastore.html" target="_blank">main | ||
CKAN Data API and DataStore documentation</a>.</p> | ||
{% endtrans %} | ||
<div class="panel-group" id="accordion2"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
|
||
<a class="accordion-toggle" data-toggle="collapse" data-parent="accordion2" href="#collapse-endpoints">{{ _('Endpoints') }} »</a> | ||
</div> | ||
<div id="collapse-endpoints" class="in panel-collapse collapse"> | ||
<div class="panel-body"> | ||
<p>{{ _('The Data API can be accessed via the following actions of the CKAN action API.') }}</p> | ||
<table class="table-condensed table-striped table-bordered"> | ||
<thead></thead> | ||
<tbody> | ||
<tr> | ||
<th scope="row">{{ _('Create') }}</th> | ||
<td><code>{{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_create', qualified=True) }}</code></td> | ||
</tr> | ||
<tr> | ||
<th scope="row">{{ _('Update / Insert') }}</th> | ||
<td><code>{{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_upsert', qualified=True) }}</code></td> | ||
</tr> | ||
<tr> | ||
<th scope="row">{{ _('Query') }}</th> | ||
<td><code>{{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search', qualified=True) }}</code></td> | ||
</tr> | ||
<tr> | ||
<th scope="row">{{ _('Query (via SQL)') }}</th> | ||
<td><code>{{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search_sql', qualified=True) }}</code></td> | ||
</tr> | ||
|
||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<a class="accordion-toggle" data-toggle="collapse" data-parent="accordion2" href="#collapse-querying">{{ _('Querying') }} »</a> | ||
</div> | ||
<div id="collapse-querying" class="collapse panel-collapse in"> | ||
<div class="panel-body"> | ||
<strong>{{ _('Query example (first 5 results)') }}</strong> | ||
<p> | ||
<code><a href="{{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search', resource_id=resource_id, limit=5, qualified=True) }}" target="_blank" rel="nofollow">{{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search', resource_id=resource_id, limit=5, qualified=True) }}</a></code> | ||
</p> | ||
|
||
<strong>{{ _('Query example (results containing \'jones\')') }}</strong> | ||
<p> | ||
<code><a href="{{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search', resource_id=resource_id, q='jones', qualified=True) }}" target="_blank" rel="nofollow">{{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search', resource_id=resource_id, q='jones', qualified=True) }}</a></code> | ||
</p> | ||
|
||
<strong>{{ _('Query example (via SQL statement)') }}</strong> | ||
<p> | ||
<code><a href="{{sql_example_url}}" target="_blank" rel="nofollow">{{ sql_example_url }}</a></code> | ||
</p> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<a class="accordion-toggle" data-toggle="collapse" data-parent="accordion2" href="#collapse-javascript">{{ _('Example: Javascript') }} »</a> | ||
</div> | ||
<div id="collapse-javascript" class="panel-collapse collapse"> | ||
<div class="panel-body"> | ||
<p>{{ _('A simple ajax (JSONP) request to the data API using jQuery.') }}</p> | ||
<pre> | ||
var data = { | ||
resource_id: '{{resource_id}}', // the resource id | ||
limit: 5, // get 5 results | ||
q: 'jones' // query for 'jones' | ||
}; | ||
$.ajax({ | ||
url: '{{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search', qualified=True) }}', | ||
data: data, | ||
dataType: 'jsonp', | ||
success: function(data) { | ||
alert('Total results found: ' + data.result.total) | ||
} | ||
});</pre> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<a class="accordion-toggle" data-toggle="collapse" data-parent="accordion2" href="#collapse-python">{{ _('Example: Python') }} »</a> | ||
</div> | ||
<div id="collapse-python" class="panel-collapse collapse"> | ||
<div class="panel-body"> | ||
<pre> | ||
import urllib | ||
url = '{{ h.url_for(qualified=True, controller='api', action='action', ver=3, logic_function='datastore_search', resource_id=resource_id, limit=5) + '&q=title:jones' }}' {# not urlencoding the ":" because its clearer #} | ||
fileobj = urllib.urlopen(url) | ||
print fileobj.read() | ||
</pre> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> |
40 changes: 40 additions & 0 deletions
40
ckanext/datastore/templates-bs3/datastore/api_examples/curl.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{% call register_example('curl', 'button_label') %} | ||
curl | ||
{% endcall %} | ||
|
||
|
||
{% call register_example('curl', 'request_limit') %} | ||
<pre class="example-curl"><code class="language-bash" | ||
>curl {{ h.url_for('api.action', logic_function='datastore_search', qualified=True) }} \ | ||
-H"Authorization:$API_TOKEN" -d ' | ||
{ | ||
"resource_id": "{{ resource_id }}", | ||
"limit": 5, | ||
"q": "jones" | ||
}'</code></pre> | ||
{% endcall %} | ||
|
||
|
||
{% call register_example('curl', 'request_filter') %} | ||
<pre class="example-curl"><code class="language-bash" | ||
>curl {{ h.url_for('api.action', logic_function='datastore_search', qualified=True) }} \ | ||
-H"Authorization:$API_TOKEN" -d ' | ||
{ | ||
"resource_id": "{{ resource_id }}", | ||
"filters": { | ||
"subject": ["watershed", "survey"], | ||
"stage": "active" | ||
} | ||
}'</code></pre> | ||
{% endcall %} | ||
|
||
|
||
{% call register_example('curl', 'request_sql') %} | ||
<pre class="example-curl"><code class="language-bash" | ||
>curl {{ h.url_for('api.action', logic_function='datastore_search_sql', qualified=True) }} \ | ||
-H"Authorization:$API_TOKEN" -d @- <<END | ||
{ | ||
"sql": "SELECT * FROM \"{{ resource_id }}\" WHERE title LIKE 'jones'" | ||
} | ||
END</code></pre> | ||
{% endcall %} |
55 changes: 55 additions & 0 deletions
55
ckanext/datastore/templates-bs3/datastore/api_examples/javascript.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{% call register_example('javascript', 'button_label') %} | ||
JavaScript | ||
{% endcall %} | ||
|
||
{% call register_example('javascript', 'request_limit') %} | ||
<pre class="example-javascript"><code class="language-javascript" | ||
>const resp = await fetch(`{{ | ||
h.url_for('api.action', logic_function='datastore_search', qualified=True) }}`, { | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/json', | ||
authorization: API_TOKEN | ||
}, | ||
body: JSON.stringify({ | ||
resource_id: '{{ resource_id }}', | ||
limit: 5, | ||
q: 'jones' | ||
}) | ||
}) | ||
await resp.json()</code></pre> | ||
{% endcall %} | ||
|
||
|
||
{% call register_example('javascript', 'request_filter') %} | ||
<pre class="example-javascript"><code class="language-javascript" | ||
>const resp = await fetch(`{{ | ||
h.url_for('api.action', logic_function='datastore_search', qualified=True) }}`, { | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/json', | ||
authorization: API_TOKEN | ||
}, | ||
body: JSON.stringify({resource_id: '{{ resource_id }}', filters: { | ||
subject: ['watershed', 'survey'], | ||
stage: 'active' | ||
}})}) | ||
await resp.json()</code></pre> | ||
{% endcall %} | ||
|
||
|
||
{% call register_example('javascript', 'request_sql') %} | ||
<pre class="example-javascript"><code class="language-javascript" | ||
>const resp = await fetch(`{{ | ||
h.url_for('api.action', logic_function='datastore_search_sql', qualified=True) }}`, { | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/json', | ||
authorization: API_TOKEN | ||
}, | ||
body: JSON.stringify({ | ||
sql: `SELECT * FROM "{{ resource_id }}" WHERE title LIKE 'jones'` | ||
}) | ||
}) | ||
await resp.json()</code></pre> | ||
{% endcall %} |
48 changes: 48 additions & 0 deletions
48
ckanext/datastore/templates-bs3/datastore/api_examples/powershell.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{% call register_example('powershell', 'button_label') %} | ||
PowerShell | ||
{% endcall %} | ||
|
||
|
||
{% call register_example('powershell', 'request_limit') %} | ||
<pre class="example-powershell"><code class="language-powershell" | ||
>$json = @' | ||
{ | ||
"resource_id": "{{resource_id}}", | ||
"limit": 5, | ||
"q": "jones" | ||
} | ||
'@ | ||
$response = Invoke-RestMethod {{ h.url_for('api.action', logic_function='datastore_search', qualified=True) }}` | ||
-Method Post -Body $json -Headers @{"Authorization"="$API_TOKEN"} | ||
$response.result.records</code></pre> | ||
{% endcall %} | ||
|
||
|
||
{% call register_example('powershell', 'request_filter') %} | ||
<pre class="example-powershell"><code class="language-powershell" | ||
>$json = @' | ||
{ | ||
"resource_id": "{{resource_id}}", | ||
"filters": { | ||
"subject": ["watershed", "survey"], | ||
"stage": "active" | ||
} | ||
} | ||
'@ | ||
$response = Invoke-RestMethod {{ h.url_for('api.action', logic_function='datastore_search', qualified=True) }}` | ||
-Method Post -Body $json -Headers @{"Authorization"="$API_TOKEN"} | ||
$response.result.records</code></pre> | ||
{% endcall %} | ||
|
||
|
||
{% call register_example('powershell', 'request_sql') %} | ||
<pre class="example-powershell"><code class="language-powershell" | ||
>$json = @' | ||
{ | ||
"sql": "SELECT * from \"{{resource_id}}\" WHERE title LIKE 'jones'" | ||
} | ||
'@ | ||
$response = Invoke-RestMethod {{ h.url_for('api.action', logic_function='datastore_search_sql', qualified=True) }}` | ||
-Method Post -Body $json -Headers @{"Authorization"="$API_TOKEN"} | ||
$response.result.records</code></pre> | ||
{% endcall %} |
Oops, something went wrong.