From 163cccc14ca089cb5b8a0b0ac0f770411ee66f8d Mon Sep 17 00:00:00 2001 From: anonymous <anonymous> Date: Wed, 26 Sep 2018 16:07:27 +0200 Subject: [PATCH] ODPSH-67: Modifies templates --- ckanext/odsh/plugin.py | 14 ++- ckanext/odsh/templates/footer.html | 1 - ckanext/odsh/templates/header.html | 96 +++++++++++++++---- ckanext/odsh/templates/package/search.html | 24 +++++ .../odsh/templates/snippets/package_item.html | 82 ++++++++++++++++ .../odsh/templates/snippets/package_list.html | 27 ++++++ .../odsh/templates/snippets/search_form.html | 81 ++++++++++++++++ 7 files changed, 305 insertions(+), 20 deletions(-) create mode 100644 ckanext/odsh/templates/package/search.html create mode 100644 ckanext/odsh/templates/snippets/package_item.html create mode 100644 ckanext/odsh/templates/snippets/package_list.html create mode 100644 ckanext/odsh/templates/snippets/search_form.html diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index d9d679ea..8d3644f2 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -1,5 +1,9 @@ import ckan.plugins as plugins import ckan.plugins.toolkit as toolkit +from ckan.lib.plugins import DefaultTranslation +from ckan.common import OrderedDict + +_ = toolkit._ def odsh_main_groups(): '''Return a list of the groups to be shown on the start page.''' @@ -11,10 +15,12 @@ def odsh_main_groups(): return groups -class OdshPlugin(plugins.SingletonPlugin): +class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation): plugins.implements(plugins.IConfigurer) plugins.implements(plugins.ITemplateHelpers) plugins.implements(plugins.IRoutes, inherit=True) + plugins.implements(plugins.ITranslation) + plugins.implements(plugins.IFacets) # IConfigurer @@ -32,3 +38,9 @@ class OdshPlugin(plugins.SingletonPlugin): def before_map(self, map): map.connect('info_page', '/info_page', controller='ckanext.odsh.controller:OdshRouteController', action='info_page') return map + + def dataset_facets(self, facets_dict, package_type): + return OrderedDict({'groups': _('Groups')}) + + def group_facets(self, facets_dict, group_type, package_type): + return facets_dict \ No newline at end of file diff --git a/ckanext/odsh/templates/footer.html b/ckanext/odsh/templates/footer.html index 464315c6..e69de29b 100644 --- a/ckanext/odsh/templates/footer.html +++ b/ckanext/odsh/templates/footer.html @@ -1 +0,0 @@ -hier ist der footer \ No newline at end of file diff --git a/ckanext/odsh/templates/header.html b/ckanext/odsh/templates/header.html index fdac883c..bf03f3c2 100644 --- a/ckanext/odsh/templates/header.html +++ b/ckanext/odsh/templates/header.html @@ -1,19 +1,79 @@ -{% ckan_extends %} -{% block header_account_container_content %} -hier war der login -{% endblock %} -{% block header_site_navigation %} -<nav class="section navigation"> - <ul class="nav nav-pills"> - {% block header_site_navigation_tabs %} - {{ h.build_nav_main( - ('search', _('Datasets')), - ('organizations_index', _('Organizations')), - ('group_index', _('Groups')), - ('about', _('About')), - ('info_page', _('Info')) - ) }} - {% endblock %} - </ul> -</nav> +{% block header_wrapper %} +{% block header_account %} +<header class="account-masthead"> + <div class="container"> + </div> +</header> +<header class="navbar navbar-static-top masthead"> + {% block header_debug %} + {% if g.debug and not g.debug_supress_header %} + <div class="debug">Controller : {{ c.controller }}<br />Action : {{ c.action }}</div> + {% endif %} + {% endblock %} + <div class="container"> + <button data-target=".nav-collapse" data-toggle="collapse" class="btn btn-navbar" type="button"> + <span class="fa fa-bars"></span> + </button> + {# The .header-image class hides the main text and uses image replacement for the title #} + <div class='row'> + + <div class='span4'> + <hgroup class="{{ g.header_class }} pull-left"> + + {% block header_logo %} + {% if g.site_logo %} + <a class="logo" href="{{ h.url_for('home') }}"><img src="{{ h.url_for_static_or_external(g.site_logo) }}" + alt="{{ g.site_title }}" title="{{ g.site_title }}" /></a> + {% else %} + <h1> + <a href="{{ h.url_for('home') }}">{{ g.site_title }}</a> + </h1> + {% if g.site_description %}<h2>{{ g.site_description }}</h2>{% endif %} + {% endif %} + {% endblock %} + </hgroup> + </div> + + + {% block header_site_search %} + <div class="span4"> + <form class="section site-search simple-input" action="{% url_for controller='package', action='search' %}" + method="get"> + <div class="field"> + <label for="field-sitewide-search">{% block header_site_search_label %}{{ _('Search Datasets') + }}{% + endblock %}</label> + <input id="field-sitewide-search" type="text" name="q" placeholder="{{ _('Search') }}" /> + <button class="btn-search" type="submit"><i class="fa fa-search"></i></button> + </div> + </form> + </div> + {% endblock %} + + <div class='span4'> + {% snippet "snippets/language_selector.html" %} + </div> + + </div> + + <div class="nav-collapse collapse"> + + <nav class="section navigation"> + <ul class="nav nav-pills"> + {% block header_site_navigation_tabs %} + {{ h.build_nav_main( + ('home', _('Start')), + ('search', _('Datasets')), + ('organizations_index', _('Organizations')), + ('info_page', _('Info')) + ) }} + {% endblock %} + </ul> + </nav> + {% endblock %} + + + </div> + </div> +</header> {% endblock %} \ No newline at end of file diff --git a/ckanext/odsh/templates/package/search.html b/ckanext/odsh/templates/package/search.html new file mode 100644 index 00000000..5c0e5bb0 --- /dev/null +++ b/ckanext/odsh/templates/package/search.html @@ -0,0 +1,24 @@ +{% ckan_extends %} + +{% block page_primary_action %} +{% endblock %} + +{% block package_search_results_list %} +{{ h.snippet('snippets/package_list.html', packages=c.page.items) }} +{% endblock %} + + +## +## tools on left side, ie filter +{% block secondary_content %} +<div class="filters"> + <div> + {% for facet in c.facet_titles %} + {{ h.snippet('snippets/facet_list.html', title=c.facet_titles[facet], name=facet) }} + {% endfor %} + </div> + <a class="close no-text hide-filters"><i class="fa fa-times-circle"></i><span class="text">close</span></a> +</div> +{% endblock %} +{% block package_search_results_api %} +{% endblock %} \ No newline at end of file diff --git a/ckanext/odsh/templates/snippets/package_item.html b/ckanext/odsh/templates/snippets/package_item.html new file mode 100644 index 00000000..2fca1ce4 --- /dev/null +++ b/ckanext/odsh/templates/snippets/package_item.html @@ -0,0 +1,82 @@ +{# +Displays a single of dataset. + +package - A package to display. +item_class - The class name to use on the list item. +hide_resources - If true hides the resources (default: false). +banner - If true displays a popular banner (default: false). +truncate - The length to trucate the description to (default: 180) +truncate_title - The length to truncate the title to (default: 80). + +Example: + + {% snippet 'snippets/package_item.html', package=c.datasets[0] %} + +#} +{% set truncate = truncate or 180 %} +{% set truncate_title = truncate_title or 80 %} +{% set title = package.title or package.name %} +{% set notes = h.markdown_extract(package.notes, extract_length=truncate) %} + +{% block package_item %} + <li class="{{ item_class or "dataset-item" }}"> + {% block content %} + <div class="dataset-content"> + {% block heading %} + <h3 class="dataset-heading"> + {% block heading_private %} + {% if package.private %} + <span class="dataset-private label label-inverse"> + <i class="fa fa-lock"></i> + {{ _('Private') }} + </span> + {% endif %} + {% endblock %} + {% block heading_title %} + {{ h.link_to(h.truncate(title, truncate_title), h.url_for(controller='package', action='read', id=package.name)) }} + {% endblock %} + {% block heading_meta %} + {% if package.get('state', '').startswith('draft') %} + <span class="label label-info">{{ _('Draft') }}</span> + {% elif package.get('state', '').startswith('deleted') %} + <span class="label label-important">{{ _('Deleted') }}</span> + {% endif %} + {{ h.popular('recent views', package.tracking_summary.recent, min=10) if package.tracking_summary }} + {% endblock %} + </h3> + {% endblock %} + {% block banner %} + {% if banner %} + <span class="banner">{{ _('Popular') }}</span> + {% endif %} + {% endblock %} + {% block notes %} + {% if notes %} + <div>{{ notes|urlize }}</div> + {% else %} + <p class="empty">{{ _("This dataset has no description") }}</p> + {% endif %} + {% endblock %} + </div> + {% block resources %} + {% if package.resources and not hide_resources %} + {% block resources_outer %} + <ul class="dataset-resources unstyled"> + {% block resources_inner %} + {% for resource in h.dict_list_reduce(package.resources, 'format') %} + <li> + <a href="{{ h.url_for(controller='package', action='read', id=package.name) }}" class="label" data-format="{{ resource.lower() }}">{{ resource }}</a> + </li> + {% endfor %} + {% endblock %} + </ul> + {% endblock %} + {% endif %} + {% endblock %} + {% block package_openness %} + <div class="module module-narrow module-shallow context-info"> + </div> + {% endblock %} + {% endblock %} + </li> +{% endblock %} diff --git a/ckanext/odsh/templates/snippets/package_list.html b/ckanext/odsh/templates/snippets/package_list.html new file mode 100644 index 00000000..3cb0d852 --- /dev/null +++ b/ckanext/odsh/templates/snippets/package_list.html @@ -0,0 +1,27 @@ +{# +Displays a list of datasets. + +packages - A list of packages to display. +list_class - The class name for the list item. +item_class - The class name to use on each item. +hide_resources - If true hides the resources (default: false). +banner - If true displays a popular banner (default: false). +truncate - The length to trucate the description to (default: 180) +truncatle_title - The length to truncate the title to (default: 80). + +Example: + + {% snippet 'snippets/package_list.html', packages=c.datasets %} + +#} +{% block package_list %} + {% if packages %} + <ul class="{{ list_class or 'dataset-list unstyled' }}"> + {% block package_list_inner %} + {% for package in packages %} + {% snippet 'snippets/package_item.html', package=package, item_class=item_class, hide_resources=hide_resources, banner=banner, truncate=truncate, truncate_title=truncate_title %} + {% endfor %} + {% endblock %} + </ul> + {% endif %} +{% endblock %} diff --git a/ckanext/odsh/templates/snippets/search_form.html b/ckanext/odsh/templates/snippets/search_form.html new file mode 100644 index 00000000..f7e712cc --- /dev/null +++ b/ckanext/odsh/templates/snippets/search_form.html @@ -0,0 +1,81 @@ +{% import 'macros/form.html' as form %} + +{% set placeholder = placeholder if placeholder else _('Search datasets...') %} +{% set sorting = sorting if sorting else [(_('Name Ascending'), 'name asc'), (_('Name Descending'), 'name desc')] %} +{% set search_class = search_class if search_class else 'search-giant' %} +{% set no_bottom_border = no_bottom_border if no_bottom_border else false %} +{% set form_id = form_id if form_id else false %} + +<form {% if form_id %}id="{{ form_id }}" {% endif %}class="search-form{% if no_bottom_border %} no-bottom-border{% endif %}" + method="get" data-module="select-switch"> + + {% block search_input %} + {% endblock %} + + {% block search_search_fields %} + {% if fields -%} + <span>{{ form.hidden_from_list(fields=fields) }}</span> + {%- endif %} + {% endblock %} + + {% block search_sortby %} + {% if sorting %} + <div class="form-select control-group control-order-by"> + <label for="field-order-by">{{ _('Order by') }}</label> + <select id="field-order-by" name="sort"> + {% for label, value in sorting %} + {% if label and value %} + <option value="{{ value }}" {% if sorting_selected==value %} selected="selected" {% endif %}>{{ label }}</option> + {% endif %} + {% endfor %} + </select> + {% block search_sortby_button %} + <button class="btn js-hide" type="submit">{{ _('Go') }}</button> + {% endblock %} + </div> + {% endif %} + {% endblock %} + + {% block search_title %} + {% if not error %} + <h2>{% snippet 'snippets/search_result_text.html', query=query, count=count, type=type %}</h2> + {% else %} + <h2>Error</h2> + {% endif %} + {% endblock %} + + {% block search_facets %} + {% if facets %} + <p class="filter-list"> + {% for field in facets.fields %} + {% set search_facets_items = facets.search.get(field)['items'] %} + <span class="facet">{{ facets.titles.get(field) }}:</span> + {% for value in facets.fields[field] %} + <span class="filtered pill"> + {%- if facets.translated_fields and facets.translated_fields.has_key((field,value)) -%} + {{ facets.translated_fields[(field,value)] }} + {%- else -%} + {{ h.list_dict_filter(search_facets_items, 'name', 'display_name', value) }} + {%- endif %} + <a href="{{ facets.remove_field(field, value) }}" class="remove" title="{{ _('Remove') }}"><i class="fa fa-times"></i></a> + </span> + {% endfor %} + {% endfor %} + </p> + <a class="show-filters btn">{{ _('Filter Results') }}</a> + {% endif %} + {% endblock %} + +</form> + +{% if show_empty and count == 0 and not error %} +{% trans %} +<p class="extra">Please try another search.</p> +{% endtrans %} +{% endif %} + +{% if error %} +{% trans %} +<p id="search-error"><strong>There was an error while searching.</strong> Please try again.</p> +{% endtrans %} +{% endif %} \ No newline at end of file -- GitLab