Skip to content

Commit

Permalink
help: display with the organization's code
Browse files Browse the repository at this point in the history
The help is displayed with the organization's code
and is no longer directed to the global help.

* Closes rero#709.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Jan 18, 2022
1 parent 2422b85 commit aac67b2
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 4 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
sonar.modules.pdf_extractor.views.client:blueprint',
'validation = sonar.modules.validation.views:blueprint',
'collections = sonar.modules.collections.views:blueprint',
'dedicated = sonar.dedicated.views:blueprint'
'dedicated = sonar.dedicated.views:blueprint',
'help = sonar.help.views:blueprint'
],
'invenio_base.api_blueprints': [
'pdf_extractor = sonar.modules.pdf_extractor.views.api:blueprint',
Expand Down
19 changes: 19 additions & 0 deletions sonar/dedicated/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
#
# Swiss Open Access Repository
# Copyright (C) 2021 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


"""Dedicated module."""
19 changes: 19 additions & 0 deletions sonar/help/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
#
# Swiss Open Access Repository
# Copyright (C) 2021 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


"""Help module."""
36 changes: 36 additions & 0 deletions sonar/help/templates/help/page_wiki_base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{# -*- coding: utf-8 -*-
Swiss Open Access Repository
Copyright (C) 2021 RERO

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#}

{% extends 'sonar/page.html' %}

{% block base_href %}
<base href="{{ request.path }}">
{% endblock base_href %}

{%- block css %}
{{ super() }}
<link href="{{ url_for('wiki.static', filename='css/wiki.css') }}" rel="stylesheet" />
{%- endblock %}

{%- block body %}

{% block navigation %}
{%- include "help/page_wiki_search_navigation.html" %}
{%- endblock navigation %}

{% block content %} {% endblock %}
{%- endblock body %}
53 changes: 53 additions & 0 deletions sonar/help/templates/help/page_wiki_org.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{# -*- coding: utf-8 -*-
Swiss Open Access Repository
Copyright (C) 2021 RERO

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#}

{% extends 'help/page_wiki_base.html' %}
{% set active_page = "page" %}

{% block content %}
<main class="row mt-4 wiki-page">
<article class="col-md-8 offset-md-1">
<header class="d-flex flex-column justify-content-lg-between mb-4 pb-2 border-bottom">
<header class="wiki-page-header d-flex flex-column flex-lg-row justify-content-lg-between mb-2 mb-lg-0">
<h1 class="wiki-page-title mb-0">{{ page.title }}</h1>
</header>
<footer class="wiki-page-info d-flex flex-column flex-lg-row justify-content-lg-between">
{% if page.tags %}
<ul class="wiki-page-tags m-0 p-0">
{% for tag in page.tags.split(',') %}
<li class="badge badge-primary">{{ tag }}</li>
{% endfor %}
</ul>
{% endif %}
<div class="text-muted small">
<span>{{ _('Created:')}} {{ page.creation_datetime | date_format }} - {{ _('Last updated:')}} {{ page.modification_datetime | date_format }}</span>
</div>
</footer>
</header>
<article>
{{ page.body.replace('](/', '](/{view}/'.format(view=view))|markdown_filter|safe }}
</article>
</article>
<aside class="col-md-3">
<div class="sticky-top pt-3">
{% if page.toc %}
<h5>{{ _('Table of contents') }}</h5>
{{ page.toc }}
{% endif %}
</aside>
</main>
{% endblock %}
61 changes: 61 additions & 0 deletions sonar/help/templates/help/page_wiki_search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{# -*- coding: utf-8 -*-
Swiss Open Access Repository
Copyright (C) 2021 RERO

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#}

{% from 'bootstrap/form.html' import render_form_row %}

{% extends 'help/page_wiki_base.html' %}
{% set active_page = "search" %}

{% block content %}
<main class="row mt-4 wiki-page">
<article class="col-md-10 offset-md-1">
<header>
<div class="pb-3">
{{ results | length }} {{ ngettext('result', 'results', results | length) }}
<a href="{{ url_for('help.search', view=view, q='*') }}" class="btn btn-sm btn-outline-primary ml-2">{{ _("All languages") }}</a>
</div>
</header>
<article>
<ul class="list-group list-group-flush">
{%- for result in results -%}
<li class="list-group-item">
<article class="d-lg-flex justify-content-lg-between">
<article class="mb-2">
<h5 class="m-0">
<a class="mr-2" href="{{ url_for('help.page', view=view, url=result.url) }}">
{{ result.title }}
</a>
</h5>
<ul class="m-0 p-0">
<li class="badge badge-secondary">
{{ result.language | upper }}
</li>
{% if result.tags %}
{% for tag in result.tags.split(',') %}
<li class="badge badge-primary">{{ tag }}</li>
{% endfor %}
{% endif %}
</ul>
</article>
</article>
</li>
{%- endfor -%}
</ul>
</article>
</article>
</main>
{% endblock %}
44 changes: 44 additions & 0 deletions sonar/help/templates/help/page_wiki_search_navigation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{# -*- coding: utf-8 -*-
Swiss Open Access Repository
Copyright (C) 2021 RERO

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#}

<header class="row">
<nav class="navbar navbar-expand-lg navbar-light bg-light col-lg-10 offset-lg-1 justify-content-end">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{{ url_for('help.index', view=view) }}">{{ _('Home') }}</a>
</li>
</ul>
<form class="form-inline" action="{{ url_for('help.search', view=view) }}">
<div class="input-group">
<input class="form-control"
type="search" value="{{ query }}"
name="q" placeholder="{{ _('Search') }}"
aria-label="{{ _('Search') }}" />
<div class="input-group-append">
<button class="btn btn-outline-primary" type="submit">
{{ _('Search') }}
</button>
</div>
</div>
</form>
</div>
</nav>
</header>
57 changes: 57 additions & 0 deletions sonar/help/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
#
# Swiss Open Access Repository
# Copyright (C) 2021 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""help organisation views."""

from flask import Blueprint, current_app, redirect, render_template, request, \
url_for
from flask_wiki.api import current_wiki

blueprint = Blueprint('help',
__name__,
template_folder='templates',
static_folder='static')


@blueprint.route('/<org_code:view>/help/', methods=['GET'])
def index(view):
"""Help index redirect to home."""
return redirect(url_for(
'help.page', view=view, url=current_app.config.get('WIKI_HOME')))


@blueprint.route('/<org_code:view>/help/<path:url>/', methods=['GET'])
def page(view, url):
"""Help page."""
page =current_wiki.get_or_404(url)
return render_template(
'help/page_wiki_org.html',
view=view,
page=page)


@blueprint.route('/<org_code:view>/help/search', methods=['GET'])
def search(view):
"""Help search."""
query = request.args.get('q', '')
results = current_wiki.search(query)
return render_template(
'help/page_wiki_search.html',
results=results,
query=query,
view=view
)
3 changes: 0 additions & 3 deletions sonar/theme/templates/sonar/page_wiki.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,3 @@
{{ super() }}
<script type="text/javascript" src="{{ url_for('wiki.static', filename='js/wiki.js') }}"></script>
{%- endblock javascript %}
</body>

</html>

0 comments on commit aac67b2

Please sign in to comment.