Skip to content

Commit

Permalink
[2375] Start work on the package search results page
Browse files Browse the repository at this point in the history
Still very much a work in progress but the base templates are in there
and facets have been moved into snippets.
  • Loading branch information
aron committed May 14, 2012
1 parent 423396b commit f0782fb
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 20 deletions.
68 changes: 58 additions & 10 deletions ckan/templates/package/search.html
Expand Up @@ -7,20 +7,68 @@
<!--! Include matchers nearest first -->
<xi:include href="../page.html" />
<xi:include href="sidebar.html" />

<!--! Now include the current page -->
<head>
<title>Search for a Dataset</title>
</head>
<body>
<main>
<content id="content" data-wah="">
<p>This is search content</p>
<p>Hmm</p>
</content>
<sidebar id="sidebar" data-test="">
<p>This is search sidebar</p>
</sidebar>
</main>
<content>
<section class="module">
<div class="content">
<form id="dataset-search" class="dataset-search clearfix" method="GET">
<input type="search" class="search" name="q" value="${c.q}" autocomplete="off" results="0" placeholder="${_('Search...')}" />
<input type="submit" hidden="hidden" value="${_('Search')}" class="btn btn-large button" />
<span py:if="c.fields">
<py:for each="(k, v) in c.fields">
<input type="hidden" name="${k}" value="${v}" />
</py:for>
</span>
<div id="dataset-search-ext"></div>
</form>
<div class="filter-list" py:if="c.fields">
<div class="filter-entry" py:for="(field, value) in c.fields">
<span class="name">${h.facet_title(field)}</span>

This comment has been minimized.

Copy link
@aron

aron May 14, 2012

Author Contributor

@tobes I need this span with the facet group to only display once for each group.

At the moment c.fields is a tuple of fields and keys eg.

(['field', 'value'], ['field', 'value'])

Perhaps this should be reformatted to be.

{'field1': ['value1', 'value2', 'value3'], 'field2': ['value1', 'value2', 'value3']}
<span class="value" py:choose="">
<py:when test="c.translated_fields and c.translated_fields.has_key((field,value))">
${c.translated_fields[(field,value)]}
</py:when>
<py:otherwise>
${value}
</py:otherwise>
</span>
<a href="${c.remove_field(field, value)}">
${h.icon('unfilter')}
</a>
</div>
</div>
<py:if test="c.query_error">
<p i18n:msg="item_count"><strong>There was an error while searching.</strong>
Please try again.</p>
</py:if>
<py:if test="request.params">
<h4 i18n:msg="item_count"><strong>${c.page.item_count}</strong> datasets found</h4>
</py:if>
<py:if test="c.page.item_count == 0 and request.params">
<p i18n:msg="">Would you like to <a href="${h.url_for(action='new', id=None)}">create a new dataset?</a></p>
</py:if>
${h.snippet('snippets/package_list.html', packages=c.page.items)}
</div>
${c.page.pager(q=c.q)}
</section>

<section class="module">
<p class="content">
You can also access this registry using the ${h.link_to(_('API'), h.url_for(controller='api', action='get_api', id=None, ver=1))}
(see ${h.link_to(_('API Docs'), 'http://docs.ckan.org/en/latest/api.html')})
<py:if test="c.dumps_url">or download a <a href="${c.dumps_url}">full ${dumps_format} dump</a></py:if>.
</p>
</section>
</content>
<sidebar>
${h.snippet('snippets/facet_list.html', title='Tags', name='tags', limit=10)}
${h.snippet('snippets/facet_list.html', title='Formats', name='res_format', limit=10)}
${h.snippet('snippets/facet_list.html', title='Groups', name='groups', limit=10)}
</sidebar>
</body>
</html>
26 changes: 16 additions & 10 deletions ckan/templates/page.html
Expand Up @@ -5,23 +5,29 @@
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip="">
<xi:include href="base.html" />
<div py:match="main">
<body py:match="body">
<!--! Import the header -->
<xi:include href="header.html" />

<!--! Wrap <content> and <sidebar> tags -->
<div class="content" py:attrs="select('content/@*')">
${select('content')}
</div>
<!--! Need an py:if here to exclude if empty. -->
<div class="sidebar" py:attrs="select('sidebar/@*')">
${select('sidebar')}
<div role="main" class="container">
<div class="row">
<!--! Need an py:if here to exclude if empty. -->
<div class="sidebar span3" py:attrs="select('sidebar/@*')">
${select('sidebar')}
</div>

<div class="content span9" py:attrs="select('content/@*')">
${select('content')}
</div>
</div>
</div>

<!--! Import the footer -->
<xi:include href="footer.html" />
</div>
</body>

<!--! Ensure the content tags are never included in the page. -->
<div py:match="content" py:strip="" py:content="select('*|text()')" />
<div py:match="sidebar" py:strip="" py:content="select('*|text()')" />
</html>
25 changes: 25 additions & 0 deletions ckan/templates/snippets/facet_item.html
@@ -0,0 +1,25 @@
<!--!
Generate <li>s for facet items. The generated tags are not wrapped by any
other tag, ie - it's up to the caller to wrap them in something suitable.
item
The facet item itself.
label_function
Renders the human-readable label for each facet value.
If defined, this should be a callable that accepts a `facet_item`.
eg. lambda facet_item: facet_item.display_name.upper()
By default it displays the facet item's display name, which should
usually be good enough.
count_label
A callable which accepts an integer, and returns a string. This controls
how a facet-item's count is displayed.
-->
<li>
<a href="${c.drill_down_url(**{name: item.name})}">
${label_function(item) if vars().has_key('label_function') else item.display_name}
${count_label(item['count']) if vars().has_key('count_label') else ('(%d)' % item['count'])}
</a>
</li>
36 changes: 36 additions & 0 deletions ckan/templates/snippets/facet_list.html
@@ -0,0 +1,36 @@
<!--!
Construct a facet module populated with links to filtered results.
name
The field name identifying the facet field, eg. "tags"
title
The title of the facet, eg. "Tags", or "Tag Cloud"
label_function
Renders the human-readable label for each facet value.
If defined, this should be a callable that accepts a `facet_item`.
eg. lambda facet_item: facet_item.display_name.upper()
By default it displays the facet item's display name, which should
usually be good enough
if_empty
A string, which if defined, and the list of possible facet items is empty,
is displayed in lieu of an empty list.
count_label
A callable which accepts an integer, and returns a string. This controls
how a facet-item's count is displayed.
-->
<section class="module" xmlns:py="http://genshi.edgewall.org/">
<h2 class="heading">${h.facet_title(title)}</h2>
<nav>
<ul class="unstyled nav nav-simple">
<py:for each="item in h.unselected_facet_items(name, 10)">
${h.snippet('snippets/facet_item.html', name=name, item=item)}
</py:for>
</ul>
</nav>
<p class="footer">View all</p>
</section>
19 changes: 19 additions & 0 deletions ckan/templates/snippets/package_list.html
@@ -0,0 +1,19 @@
<ul class="dataset-list unstyled" xmlns:py="http://genshi.edgewall.org/">
<li py:for="package in packages" class="dataset-item">
<h3 class="heading">
${h.link_to(package.get('title') or package.get('name'), h.url_for(controller='package', action='read', id=package.get('name')))}
</h3>
<py:if test="package.resources">
<ul class="dataset-resources unstyled">
<py:for each="resource in package.resources">
<li py:if="resource.get('format')">
<a href="${resource.get('url')}" class="label resource-url-analytics" title="${resource.get('description')}">${resource.get('format')}</a>
</li>
</py:for>
</ul>
</py:if>
<div class="content">
${h.markdown_extract(package.notes)}
</div>
</li>
</ul>

0 comments on commit f0782fb

Please sign in to comment.