From b81e5c3ddf4df6230dafd9303c9deecac715f5eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Caux?= <git@jscaux.org> Date: Sat, 5 Feb 2022 17:00:33 +0100 Subject: [PATCH] Ensure proper working of (re)setting session acad_field and spec --- scipost_django/ontology/views.py | 3 +- .../static/scipost/assets/css/_general.scss | 13 --- .../static/scipost/assets/css/_grid.scss | 2 + .../static/scipost/assets/css/_homepage.scss | 83 +------------- .../templates/scipost/_hx_sponsors.html | 1 + .../scipost/templates/scipost/header.html | 10 +- .../scipost/templates/scipost/index.html | 1 - .../scipost/templates/scipost/navbar.html | 104 ++++++++++++------ .../templates/scipost/portal/_hx_home.html | 2 + .../templates/scipost/portal/portal.html | 43 +++++--- scipost_django/scipost/views.py | 5 +- 11 files changed, 120 insertions(+), 147 deletions(-) diff --git a/scipost_django/ontology/views.py b/scipost_django/ontology/views.py index 2d981cd3a..4a7f34221 100644 --- a/scipost_django/ontology/views.py +++ b/scipost_django/ontology/views.py @@ -30,8 +30,9 @@ def set_session_acad_field(request): """Set the Academic Field to be viewed in the current user session.""" form = SessionAcademicFieldForm(request.GET or None) if form.is_valid(): + if form.cleaned_data['acad_field_slug'] != request.session['session_acad_field_slug']: + request.session['session_specialty_slug'] = '' request.session['session_acad_field_slug'] = form.cleaned_data['acad_field_slug'] - request.session['session_specialty_slug'] = '' try: initial = { 'acad_field_slug': AcademicField.objects.get( diff --git a/scipost_django/scipost/static/scipost/assets/css/_general.scss b/scipost_django/scipost/static/scipost/assets/css/_general.scss index 0a515cf10..bf2df13c5 100644 --- a/scipost_django/scipost/static/scipost/assets/css/_general.scss +++ b/scipost_django/scipost/static/scipost/assets/css/_general.scss @@ -229,19 +229,6 @@ header { display: flex; flex-wrap: nowrap; - .logobox { - align-self: center; - - a { - display: block; - } - } - - .blurbbox { - align-self: center; - margin-left: auto; - text-align: right; - } } .navbar-nav { diff --git a/scipost_django/scipost/static/scipost/assets/css/_grid.scss b/scipost_django/scipost/static/scipost/assets/css/_grid.scss index 01832e519..759b3d407 100644 --- a/scipost_django/scipost/static/scipost/assets/css/_grid.scss +++ b/scipost_django/scipost/static/scipost/assets/css/_grid.scss @@ -14,6 +14,8 @@ main { margin-top: -1px; padding-top: $grid-gutter-width; padding-bottom: $grid-gutter-width; + padding-left: 2*$grid-gutter-width; + padding-right: 2*$grid-gutter-width; border-left: 1px solid; border-right: 1px solid; border-top: 1px solid; diff --git a/scipost_django/scipost/static/scipost/assets/css/_homepage.scss b/scipost_django/scipost/static/scipost/assets/css/_homepage.scss index 937f9a57b..7dc486849 100644 --- a/scipost_django/scipost/static/scipost/assets/css/_homepage.scss +++ b/scipost_django/scipost/static/scipost/assets/css/_homepage.scss @@ -65,7 +65,11 @@ } //.main-nav .nav-item .dropdown-toggle::after { content: none; } - .container { max-width: 1440px; } + .container { + box-shadow: none; + border: 0; + max-width: 1440px; + } h2, .h2 { font-size: 1.1rem; } @@ -84,90 +88,13 @@ } } - .domains:hover + .subdomains, - .subdomains:hover { - max-height: 300px; - margin-bottom: 0; - } - - .domains { - list-style: none; - padding: 0 0 20px 0; - margin: 0; - - li { - font-size: 1.0rem; - display: inline-block; - background-color: #d3e3f6; - padding: 5px 15px; - margin-right: 15px; - border-radius: 99px; - cursor: pointer; - transition: 100ms; - } - - li.active { - background-color: #496bb6; - color: #fff; - text-decoration: underline; - } - - li:hover { - background-color: #b8c8db; - text-decoration: underline; - } - - li.active:hover { - background-color: #3e5c9d; - } - } - - .subdomains { - - list-style: none; - padding: 0; - margin-bottom: 0; - transition: 100ms; - max-height: 0; - overflow: hidden; - - li { - font-size: 0.825rem; - display: inline-block; - background-color: #eee; - padding: 2px 10px; - margin: 0 5px 10px 0; - border-radius: 99px; - cursor: pointer; - transition: 100ms; - border: 1px solid #dedede; - transition: 200ms; - } - - li:hover, - li.active { - background-color: #ccc; - // text-decoration: underline; - } - - } - .container { - box-shadow: none; - border: 0; } .navbar .nav-link { font-weight: normal; } - header .logobox img { - max-height: 45px; - width: auto; - margin: 15px 10px; - } - - .publication-list ul { list-style: none; padding: 0; diff --git a/scipost_django/scipost/templates/scipost/_hx_sponsors.html b/scipost_django/scipost/templates/scipost/_hx_sponsors.html index acb4851cc..e3be1bf9e 100644 --- a/scipost_django/scipost/templates/scipost/_hx_sponsors.html +++ b/scipost_django/scipost/templates/scipost/_hx_sponsors.html @@ -3,6 +3,7 @@ <div id="sponsor-logos" class="sp-swap" hx-get="{% url 'scipost:_hx_sponsors' %}?dt={{ request.GET.dt|increment_dt }}" + hx-push-url="false" hx-trigger="every {{ request.GET.dt|increment_dt }}s" hx-swap="outerHTML swap:1s" > diff --git a/scipost_django/scipost/templates/scipost/header.html b/scipost_django/scipost/templates/scipost/header.html index 19967d75b..bf4a9749c 100644 --- a/scipost_django/scipost/templates/scipost/header.html +++ b/scipost_django/scipost/templates/scipost/header.html @@ -11,20 +11,20 @@ <div class="mx-2 my-4 my-lg-auto"> <form id="session_acad_field_form" style="display: none;" - hx-get="{% url 'ontology:set_session_acad_field' %}" - hx-trigger="change" - hx-swap="outerHTML" + hx-get="{% url 'ontology:set_session_acad_field' %}" + hx-trigger="{% if not request.get_full_path == '/' %}load, {% endif %}change" + hx-swap="outerHTML" > {% crispy session_acad_field_form %} </form> </div> <div class="mx-2 my-4 my-lg-auto" hx-get="{% url 'ontology:_hx_session_specialty_form' %}" - hx-trigger="hide.bs.tab from:#home-tab, session-acad-field-set from:body" + hx-trigger="{% if not request.get_full_path == '/' %}load, {% endif %}hide.bs.tab from:#home-tab, session-acad-field-set from:body" > </div> - <div class="ms-2 mt-4 my-lg-auto"> + <div class="mt-4 my-lg-auto ms-2"> <form id="header-search-form" method="get" action="{% url 'scipost:search' %}"> <div class="form-floating"> <input type="text" id="headerSearchInput" class="form-control" name="q" placeholder="Search" value="{{ request.GET.q }}"> diff --git a/scipost_django/scipost/templates/scipost/index.html b/scipost_django/scipost/templates/scipost/index.html index c660c10fb..245335c8d 100644 --- a/scipost_django/scipost/templates/scipost/index.html +++ b/scipost_django/scipost/templates/scipost/index.html @@ -1,6 +1,5 @@ {% extends 'scipost/base.html' %} -{% load render_bundle from webpack_loader %} {% load static %} {% block body_class %}{{ block.super }} homepage{% endblock %} diff --git a/scipost_django/scipost/templates/scipost/navbar.html b/scipost_django/scipost/templates/scipost/navbar.html index 31d1b0748..915bd29fc 100644 --- a/scipost_django/scipost/templates/scipost/navbar.html +++ b/scipost_django/scipost/templates/scipost/navbar.html @@ -14,6 +14,7 @@ </button> <div class="collapse navbar-collapse mt-3" id="main-navbar"> --> + <nav class="navbar main-nav p-2"> <div class="container"> <div class="flex-fill" id="main-navbar"> @@ -22,66 +23,105 @@ role="tablist"> <li class="nav-item" role="presentation"> - <button class="nav-link active" id="home-tab" - data-bs-toggle="tab" data-bs-target="#home" - type="button" role="tab" - aria-controls="home" aria-selected="true"> - Home - </button> + {% if request.path == '/' %} + <button class="nav-link{% if not request.GET.tab %} active{% endif %}" + id="home-tab" + data-bs-toggle="tab" data-bs-target="#home" + type="button" role="tab" + aria-controls="home" aria-selected="true"> + Home + </button> + {% else %} + <a href="{% url 'scipost:index' %}">Home</a> + {% endif %} </li> <li class="nav-item" role="presentation"> - <button class="nav-link" id="journals-tab" - data-bs-toggle="tab" data-bs-target="#journals" - type="button" role="tab" - aria-controls="journals" aria-selected="true"> - Journals - </button> + {% if request.path == '/' %} + <button class="nav-link{% if request.GET.tab == 'journals' %} active{% endif %}" + id="journals-tab" + data-bs-toggle="tab" data-bs-target="#journals" + type="button" role="tab" + aria-controls="journals" aria-selected="true"> + Journals + </button> + {% else %} + <a href="{% url 'scipost:index' %}?tab=journals">Journals</a> + {% endif %} </li> <li class="nav-item" role="presentation"> - <button class="nav-link" id="publications-tab" - data-bs-toggle="tab" data-bs-target="#publications" - type="button" role="tab" - aria-controls="publications" aria-selected="true"> - Publications - </button> + {% if request.path == '/' %} + <button class="nav-link{% if request.GET.tab == 'publications' %} active{% endif %}" + id="publications-tab" + data-bs-toggle="tab" data-bs-target="#publications" + type="button" role="tab" + aria-controls="publications" aria-selected="true"> + Publications + </button> + {% else %} + <a href="{% url 'scipost:index' %}?tab=publications">Publications</a> + {% endif %} </li> <li class="nav-item" role="presentation"> - <button class="nav-link" id="submissions-tab" - data-bs-toggle="tab" data-bs-target="#submissions" - type="button" role="tab" - aria-controls="submissions" aria-selected="true"> - Submissions - </button> + {% if request.path == '/' %} + <button class="nav-link{% if request.GET.tab == 'submissions' %} active{% endif %}" + id="submissions-tab" + data-bs-toggle="tab" data-bs-target="#submissions" + type="button" role="tab" + aria-controls="submissions" aria-selected="true"> + Submissions + </button> + {% else %} + <a href="{% url 'scipost:index' %}?tab=submissions">Submissions</a> + {% endif %} </li> <li class="nav-item" role="presentation"> - <button class="nav-link border border-2 border-warning" id="reports-needed-tab" - data-bs-toggle="tab" data-bs-target="#reports-needed" - type="button" role="tab" - aria-controls="reports-needed" aria-selected="true"> - Reports needed <span class="text-warning">{% include 'bi/exclamation-square-fill.html' %}</span> - </button> + {% if request.path == '/' %} + <button class="nav-link border border-2 border-warning{% if request.GET.tab == 'reportsneeded' %} active{% endif %}" + id="reports-needed-tab" + data-bs-toggle="tab" data-bs-target="#reports-needed" + type="button" role="tab" + aria-controls="reports-needed" aria-selected="true"> + Reports needed <span class="text-warning">{% include 'bi/exclamation-square-fill.html' %}</span> + </button> + {% else %} + <a href="{% url 'scipost:index' %}?tab=reportsneeded" + class="border border-2 border-warning"> + Reports needed + <span class="text-warning">{% include 'bi/exclamation-square-fill.html' %}</span> + </a> + {% endif %} </li> <!-- <li class="nav-item" role="presentation"> - <button class="nav-link" id="reports-tab" + {% if request.path == '/' %} + <button class="nav-link{% if request.GET.tab == 'reports' %} active{% endif %}" + id="reports-tab" data-bs-toggle="tab" data-bs-target="#reports" type="button" role="tab" aria-controls="reports" aria-selected="true"> Reports </button> + {% else %} + <a href="{% url 'scipost:index' %}?tab=reports">Reports</a> + {% endif %} </li> <li class="nav-item" role="presentation"> - <button class="nav-link" id="comments-tab" + {% if request.path == '/' %} + <button class="nav-link{% if request.GET.tab == 'comments' %} active{% endif %}" + id="comments-tab" data-bs-toggle="tab" data-bs-target="#comments" type="button" role="tab" aria-controls="comments" aria-selected="true"> Comments </button> + {% else %} + <a href="{% url 'scipost:index' %}?tab=comments">Comments</a> + {% endif %} </li> --> <li class="nav-item" role="presentation"> diff --git a/scipost_django/scipost/templates/scipost/portal/_hx_home.html b/scipost_django/scipost/templates/scipost/portal/_hx_home.html index a7142e12b..2949f733e 100644 --- a/scipost_django/scipost/templates/scipost/portal/_hx_home.html +++ b/scipost_django/scipost/templates/scipost/portal/_hx_home.html @@ -107,6 +107,7 @@ <br> <div id="sponsor-logos" class="sp-swap" hx-get="{% url 'scipost:_hx_sponsors' %}" + hx-push-url="false" hx-trigger="load" hx-swap="outerHTML swap:1s" > @@ -149,6 +150,7 @@ <div class="col-md-8" hx-get="{% url 'scipost:_hx_participates_in' %}" + hx-push-url="false" hx-trigger="load" > </div> diff --git a/scipost_django/scipost/templates/scipost/portal/portal.html b/scipost_django/scipost/templates/scipost/portal/portal.html index b2201e255..829a5c6a4 100644 --- a/scipost_django/scipost/templates/scipost/portal/portal.html +++ b/scipost_django/scipost/templates/scipost/portal/portal.html @@ -7,7 +7,6 @@ <link href="https://fonts.googleapis.com/css2?family=Merriweather+Sans:wght@300;400;500;600&display=swap" rel="stylesheet"> {% endblock headsup %} -{% load render_bundle from webpack_loader %} {% load static %} {% block body_class %}{{ block.super }} homepage home-alt{% endblock %} @@ -20,58 +19,72 @@ <div class="tab-content mt-4" id="portalTabContent"> - <div class="tab-pane portal-tab fade show active" id="home" + <div class="tab-pane portal-tab fade{% if not request.GET.tab %} show active{% endif %}" + id="home" role="tabpanel" aria-labelledby="home-tab"> <div hx-get="{% url 'scipost:portal_hx_home' %}" - hx-trigger="load, click delay:200ms from:#home-tab" + hx-trigger="{% if not request.GET.tab %}load, {% endif %}click delay:200ms from:#home-tab" + hx-push-url="{% url 'scipost:index' %}" > </div> </div> - <div class="tab-pane portal-tab fade" id="journals" + <div class="tab-pane portal-tab fade{% if request.GET.tab == 'journals' %} show active{% endif %}" + id="journals" role="tabpanel" aria-labelledby="journals-tab"> <div hx-get="{% url 'scipost:portal_hx_journals' %}" - hx-trigger="click delay:200ms from:#journals-tab, session-acad-field-set from:body" + hx-trigger="{% if request.GET.tab == 'journals' %}load, {% endif %}click delay:200ms from:#journals-tab, session-acad-field-set from:body" + hx-push-url="{% url 'scipost:index' %}?tab=journals" > </div> </div> - <div class="tab-pane portal-tab fade" id="publications" + <div class="tab-pane portal-tab fade{% if request.GET.tab == 'publications' %} show active{% endif %}" + id="publications" role="tabpanel" aria-labelledby="publications-tab"> <div hx-get="{% url 'scipost:portal_hx_publications' %}" - hx-trigger="load, click delay:200ms from:#publications-tab, session-acad-field-set from:body, session-specialty-set from:body" + hx-trigger="{% if request.GET.tab == 'publications' %}load, {% endif %}click delay:200ms from:#publications-tab, session-acad-field-set from:body, session-specialty-set from:body" + hx-push-url="{% url 'scipost:index' %}?tab=publications" > </div> </div> - <div class="tab-pane portal-tab fade" id="submissions" + <div class="tab-pane portal-tab fade{% if request.GET.tab == 'submissions' %} show active{% endif %}" + id="submissions" role="tabpanel" aria-labelledby="submissions-tab"> <div hx-get="{% url 'scipost:portal_hx_submissions' %}" - hx-trigger="click delay:200ms from:#submissions-tab, session-acad-field-set from:body, session-specialty-set from:body" + hx-trigger="{% if request.GET.tab == 'submissions' %}load, {% endif %}click delay:200ms from:#submissions-tab, session-acad-field-set from:body, session-specialty-set from:body" + hx-push-url="{% url 'scipost:index' %}?tab=submissions" > </div> </div> - <div class="tab-pane portal-tab fade" id="reports-needed" + <div class="tab-pane portal-tab fade{% if request.GET.tab == 'reportsneeded' %} show active{% endif %}" + id="reports-needed" role="tabpanel" aria-labelledby="reports-needed-tab"> <div hx-get="{% url 'scipost:portal_hx_submissions' %}?reports_needed=1" - hx-trigger="click delay:200ms from:#reports-needed-tab, session-acad-field-set from:body, session-specialty-set from:body" + hx-trigger="{% if request.GET.tab == 'reportsneeded' %}load, {% endif %}click delay:200ms from:#reports-needed-tab, session-acad-field-set from:body, session-specialty-set from:body" + hx-push-url="{% url 'scipost:index' %}?tab=reportsneeded" > </div> </div> - <div class="tab-pane portal-tab fade" id="reports" + <div class="tab-pane portal-tab fade{% if request.GET.tab == 'reports' %} show active{% endif %}" + id="reports" role="tabpanel" aria-labelledby="reports-tab"> <div hx-get="{% url 'scipost:portal_hx_reports' %}" - hx-trigger="click delay:200ms from:#reports-tab, session-acad-field-set from:body, session-specialty-set from:body" + hx-trigger="{% if request.GET.tab == 'reports' %}load, {% endif %}click delay:200ms from:#reports-tab, session-acad-field-set from:body, session-specialty-set from:body" + hx-push-url="{% url 'scipost:index' %}?tab=reports" > </div> </div> - <div class="tab-pane portal-tab fade" id="comments" + <div class="tab-pane portal-tab fade{% if request.GET.tab == 'comments' %} show active{% endif %}" + id="comments" role="tabpanel" aria-labelledby="comments-tab"> <div hx-get="{% url 'scipost:portal_hx_comments' %}" - hx-trigger="click delay:200ms from:#comments-tab, session-acad-field-set from:body, session-specialty-set from:body" + hx-trigger="{% if request.GET.tab == 'comments' %}load, {% endif %}click delay:200ms from:#comments-tab, session-acad-field-set from:body, session-specialty-set from:body" + hx-push-url="{% url 'scipost:index' %}?tab=comments" > </div> </div> diff --git a/scipost_django/scipost/views.py b/scipost_django/scipost/views.py index 0fc4c69bc..e0beb6c32 100644 --- a/scipost_django/scipost/views.py +++ b/scipost_django/scipost/views.py @@ -164,8 +164,9 @@ def index_pre202202(request): def index(request): if request.GET.get('field', None): - request.session['session_acad_field_slug'] = request.GET.get('field', None) - request.session['session_specialty_slug'] = '' + if request.GET['field'] != request.session['session_acad_field_slug']: + request.session['session_specialty_slug'] = '' + request.session['session_acad_field_slug'] = request.GET['field'] context = { 'news_items': NewsItem.objects.homepage().order_by('-date')[:3], 'publications': Publication.objects.published().order_by('-publication_date', -- GitLab