diff --git a/setup.py b/setup.py index d9032243a..8380c159e 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/sonar/config.py b/sonar/config.py index af23fdeee..8ac48bfad 100644 --- a/sonar/config.py +++ b/sonar/config.py @@ -229,7 +229,8 @@ def _(x): 'https://code.jquery.com', 'https://cdnjs.cloudflare.com', 'https://stackpath.bootstrapcdn.com', 'https://www.googletagmanager.com', - 'https://www.google-analytics.com' + 'https://www.google-analytics.com', + 'https://cdn.jsdelivr.net' ], 'style-src': [ "'self'", "'unsafe-inline'", 'https://cdnjs.cloudflare.com', diff --git a/sonar/dedicated/__init__.py b/sonar/dedicated/__init__.py new file mode 100644 index 000000000..b5b31cf5a --- /dev/null +++ b/sonar/dedicated/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# +# Swiss Open Access Repository +# Copyright (C) 2022 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 . + + +"""Dedicated module.""" diff --git a/sonar/help/__init__.py b/sonar/help/__init__.py new file mode 100644 index 000000000..e356d7180 --- /dev/null +++ b/sonar/help/__init__.py @@ -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 . + + +"""Help module.""" diff --git a/sonar/help/templates/help/page_wiki.html b/sonar/help/templates/help/page_wiki.html new file mode 100644 index 000000000..5cde74092 --- /dev/null +++ b/sonar/help/templates/help/page_wiki.html @@ -0,0 +1,62 @@ +{# -*- coding: utf-8 -*- + Swiss Open Access Repository + Copyright (C) 2022 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 . +#} + +{% extends 'sonar/page_wiki.html' %} +{% set active_page = "page" %} + +{% block navigation %} +{%- include "help/page_wiki_search_navigation.html" %} +{%- endblock navigation %} + +{% block content %} +
+
+
+
+

{{ page.title }}

+
+
+ {% if page.tags %} +
    + {% for tag in page.tags.split(',') %} +
  • {{ tag }}
  • + {% endfor %} +
+ {% endif %} +
+ {{ _('Created:')}} {{ page.creation_datetime | date_format }} - {{ _('Last updated:')}} {{ page.modification_datetime | date_format }} +
+
+
+
+ {{ page.body.replace('](/help', '](/{view}/help'.format(view=view))|markdown_filter|safe }} +
+
+ +
+{% endblock %} + +{%- block javascript %} +{{ super() }} +{%- endblock javascript %} diff --git a/sonar/help/templates/help/page_wiki_search.html b/sonar/help/templates/help/page_wiki_search.html new file mode 100644 index 000000000..1ccda6831 --- /dev/null +++ b/sonar/help/templates/help/page_wiki_search.html @@ -0,0 +1,69 @@ +{# -*- coding: utf-8 -*- + Swiss Open Access Repository + Copyright (C) 2022 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 . +#} + +{% from 'bootstrap/form.html' import render_form_row %} + +{% extends 'sonar/page_wiki.html' %} +{% set active_page = "search" %} + +{% block navigation %} +{%- include "help/page_wiki_search_navigation.html" %} +{%- endblock navigation %} + +{% block content %} +
+
+
+
+ {{ results | length }} {{ ngettext('result', 'results', results | length) }} + {{ _("All languages") }} +
+
+
+
    + {%- for result in results -%} +
  • +
    +
    +
    + + {{ result.title }} + +
    +
      +
    • + {{ result.language | upper }} +
    • + {% if result.tags %} + {% for tag in result.tags.split(',') %} +
    • {{ tag }}
    • + {% endfor %} + {% endif %} +
    +
    +
    +
  • + {%- endfor -%} +
+
+
+
+{% endblock %} + +{%- block javascript %} +{{ super() }} +{%- endblock javascript %} diff --git a/sonar/help/templates/help/page_wiki_search_navigation.html b/sonar/help/templates/help/page_wiki_search_navigation.html new file mode 100644 index 000000000..b0c0878b7 --- /dev/null +++ b/sonar/help/templates/help/page_wiki_search_navigation.html @@ -0,0 +1,44 @@ +{# -*- coding: utf-8 -*- + Swiss Open Access Repository + Copyright (C) 2022 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 . +#} + +
+ +
diff --git a/sonar/help/views.py b/sonar/help/views.py new file mode 100644 index 000000000..e85820bec --- /dev/null +++ b/sonar/help/views.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# +# Swiss Open Access Repository +# Copyright (C) 2022 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 . + +"""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('//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('//help//', methods=['GET']) +def page(view, url): + """Help page.""" + page =current_wiki.get_or_404(url) + return render_template( + 'help/page_wiki.html', + view=view, + page=page) + + +@blueprint.route('//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 + ) diff --git a/sonar/theme/templates/sonar/page_wiki.html b/sonar/theme/templates/sonar/page_wiki.html index 1ce936010..89d7c68a6 100644 --- a/sonar/theme/templates/sonar/page_wiki.html +++ b/sonar/theme/templates/sonar/page_wiki.html @@ -37,8 +37,6 @@ {%- block javascript %} {{ super() }} +{{ bootstrap.load_js() }} {%- endblock javascript %} - - -