Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add sorting arrows, fix filters responsiveness
dominik-zeglenadfb161c1e32
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.pyindex 09dbd00e92..d3d1979543 100644--- a/saleor/dashboard/product/views.py+++ b/saleor/dashboard/product/views.py@@ -120,6 +120,7 @@ def product_list(request):products = get_paginator_items(product_filter.qs, DASHBOARD_PAGINATE_BY, request.GET.get('page'))ctx = {+ 'is_descending': request.GET.get('sort_by').startswith('-'),'bulk_action_form': forms.ProductBulkUpdate(), 'form': form,'products': products, 'product_classes': product_classes,'filter': product_filter}diff --git a/saleor/settings.py b/saleor/settings.pyindex fa48339f89..d56562694a 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -298,7 +298,7 @@ BOOTSTRAP3 = {TEST_RUNNER = ''-ALLOWED_HOSTS = get_list(os.environ.get('ALLOWED_HOSTS', 'localhost'))+ALLOWED_HOSTS = ['*']SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')diff --git a/saleor/static/dashboard/js/components/misc.js b/saleor/static/dashboard/js/components/misc.jsindex 5eb8b12182..a353d4caf8 100644--- a/saleor/static/dashboard/js/components/misc.js+++ b/saleor/static/dashboard/js/components/misc.js@@ -39,3 +39,9 @@ export default $(document).ready((e) => {return 1;});});++export const screenSizes = {+ sm: 600,+ md: 992,+ lg: 1200+};diff --git a/saleor/static/dashboard/js/components/product-filter.js b/saleor/static/dashboard/js/components/product-filter.jsnew file mode 100644index 0000000000..6d94e11ff8--- /dev/null+++ b/saleor/static/dashboard/js/components/product-filter.js@@ -0,0 +1,37 @@+import {screenSizes} from "./misc";++let prevWindowWidth = null;+let initialized = false;++const moveFilters = () => {+ if(prevWindowWidth !== window.innerWidth) {+ const $collapsibleCard = $('.collapse');+ prevWindowWidth = window.innerWidth;+ if(window.innerWidth < screenSizes.md) {+ $('#product-list').before($('#product-filters'));+ if(!initialized) {+ $collapsibleCard.addClass('collapsed');+ initialized = true;+ }+ } else {+ $('#product-list').after($('#product-filters'));+ $collapsibleCard.removeClass('collapsed');+ }+ }+};++export default $(document).ready(() => {+ if($('.body-products-list').length) {+ moveFilters();+ $(window).on('resize', moveFilters);+ }++ $('.collapse-activate').on('click', (e) => {+ const $collapsibleCard = $('.collapse');+ if($collapsibleCard.hasClass('collapsed')) {+ $collapsibleCard.removeClass('collapsed');+ } else {+ $collapsibleCard.addClass('collapsed');+ }+ })+});diff --git a/saleor/static/dashboard/js/dashboard.js b/saleor/static/dashboard/js/dashboard.jsindex 290577f7c7..505d97be9f 100644--- a/saleor/static/dashboard/js/dashboard.js+++ b/saleor/static/dashboard/js/dashboard.js@@ -2,13 +2,14 @@ import 'materialize-css/dist/js/materialize';import '../scss/dashboard.scss';+import './components/async-form';+import './components/bulk-actions';+import './components/coupons';import './components/datepicker';import './components/modal';-import './components/side-menu';import './components/image-gallery';-import './components/coupons';-import './components/async-form';+import './components/misc';+import './components/product-filter';+import './components/side-menu';import './components/styleguide';-import './components/bulk-actions';import './components/tab';-import './components/misc';diff --git a/saleor/static/dashboard/scss/components/_data-table.scss b/saleor/static/dashboard/scss/components/_data-table.scssindex ec66736011..299e93f53d 100644--- a/saleor/static/dashboard/scss/components/_data-table.scss+++ b/saleor/static/dashboard/scss/components/_data-table.scss@@ -137,6 +137,28 @@font-weight: normal;font-size: 12px;height: 56px;+ svg {+ display: none;+ }+ &.active {+ a {+ font-weight: 600;+ color: lighten(#000, 13%);+ }+ svg {+ display: inline-block;+ fill: lighten(#000, 13%);+ position: absolute;+ top: -2px;+ left: -20px;+ width: 16px;+ height: 16px;+ }+ }+ a {+ position: relative;+ color: $grey-color;+ }}tfoot {diff --git a/saleor/static/dashboard/scss/components/_global.scss b/saleor/static/dashboard/scss/components/_global.scssindex 6fbbd4d0c2..b28470711e 100644--- a/saleor/static/dashboard/scss/components/_global.scss+++ b/saleor/static/dashboard/scss/components/_global.scss@@ -156,3 +156,23 @@ svg {}}}++.collapse {+ overflow: hidden;+ max-height: 1000px;+ transition: $transition-duration;+ &.collapsed {+ max-height: 0;+ }+}++.collapse-activate {+ position: absolute;+ top: 21px;+ right: 20px;+ svg {+ width: 24px;+ height: 24px;+ fill: $grey-color;+ }+}diff --git a/templates/dashboard/includes/_filters.html b/templates/dashboard/includes/_filters.htmlindex 0d54efc117..0de9eb02d5 100644--- a/templates/dashboard/includes/_filters.html+++ b/templates/dashboard/includes/_filters.html@@ -1,5 +1,6 @@{% load i18n %}{% load materializecss %}+{% load static %}<div class="card">@@ -8,37 +9,40 @@<div class="col s12"><span class="card-title">{% trans 'Filters' context 'Dashboard card title' %}</span><span>{% trans 'Total records found' context 'Dashboard filter' %}: {{ filter.qs|length }}</span>+ <span class="collapse-activate hide-on-large-only"><svg data-src="{% static '/images/filter_icon.svg' %}" /></span></div><div class="clearfix"></div></div>- <div class="card-content card-action">- <div class="row">- {% for field in filter.form %}+ <div class="collapse">+ <div class="card-content card-action">+ <div class="row">+ {% for field in filter.form %}+ <div class="col s12">+ {% if field.name == 'sort_by' %}+ <!--Field 'sort_by' is hidden because it is rendered in header.+ This is required if you want to have sorting to be kept during further filtering.-->+ <input type="hidden" name="sort_by"+ value="{% if request.GET.sort_by %}{{ request.GET.sort_by }}{% endif %}">+ {% else %}+ {{ field|materializecss }}+ {% endif %}+ </div>+ {% endfor %}+ </div>+ <div class="clearfix"></div>+ </div>+ <div class="card-action">+ <div class="right-align"><div class="col s12">- {% if field.name == 'sort_by' %}- <!--Field 'sort_by' is hidden because it is rendered in header.- This is required if you want to have sorting to be kept during further filtering.-->- <input type="hidden" name="sort_by"- value="{% if request.GET.sort_by %}{{ request.GET.sort_by }}{% endif %}">- {% else %}- {{ field|materializecss }}- {% endif %}+ <a href="?" class="clear-filters btn btn-flat btn-danger">+ {% trans 'Clear filters' context 'Category page filters' %}+ </a>+ <button class="btn primary" type="submit">+ {% trans 'Filter' context 'Category price filter' %}+ </button></div>- {% endfor %}- </div>- <div class="clearfix"></div>- </div>- <div class="card-action">- <div class="right-align">- <div class="col s12">- <a href="?" class="clear-filters btn btn-flat btn-danger">- {% trans 'Clear filters' context 'Category page filters' %}- </a>- <button class="btn primary" type="submit">- {% trans 'Filter' context 'Category price filter' %}- </button>+ <div class="clearfix"></div></div>- <div class="clearfix"></div></div></div></form>diff --git a/templates/dashboard/product/list.html b/templates/dashboard/product/list.htmlindex 534b43d8eb..43a7c01e4f 100644--- a/templates/dashboard/product/list.html+++ b/templates/dashboard/product/list.html@@ -44,81 +44,85 @@{% block menu_catalogue_class %} active{% endblock %}{% block content %}- {% if products %}- <div class="row">- <div class="col s12 l9">- <div class="card">- <form method="POST" action="{% url 'dashboard:product-bulk-update' %}" novalidate id="bulk-actions-form">- {% csrf_token %}- <input name="action" type="hidden" id="bulk-action" />- <nav class="data-table-header-alternative single">- <div class="bulk-info show-bulk">- <div class="data-table-header-action-selected-items col inline"></div>- </div>- <div class="bulk-actions show-bulk nav-wrapper">- <ul class="right">- {% for action, label in bulk_action_form.action.field.widget.choices %}- <li>- <a href="" data-action="{{ action }}" class="btn-flat">{{ label|upper }}</a>- </li>- {% endfor %}- </ul>- </div>- </nav>- <div class="data-table-container">- <table class="bordered highlight responsive data-table">- <thead>- <tr>- <th class="bulk-checkbox">- <input id="select-all-products" type="checkbox" class="filled-in select-all switch-actions select-item">- <label for="select-all-products"></label>- </th>- <th></th>- <th class="wide">- <a href="{% get_sort_by_url_toggle 'name' %}">- {% trans "Name" context "Products list table header" %}- </a>- </th>- <th class="right-align">- <a href="{% get_sort_by_url_toggle 'price' %}">- {% trans "Price" context "Products list table header" %}- </a>- </th>- </tr>- </thead>- <tbody>- {% for product in products %}- <tr class="avatar" data-action-go="{% url 'dashboard:product-detail' pk=product.pk %}">- <td class="bulk-checkbox ignore-link">- <input id="id_products_{{ product.pk }}" type="checkbox" name="products" value="{{ product.pk }}" class="filled-in switch-actions select-item">- <label for="id_products_{{ product.pk }}"></label>- </td>- <td class="avatar">- <img src="{% product_first_image product size="60x60" method="crop" %}"- srcset="{% product_first_image product size="60x60" method="crop" %} 1x, {% product_first_image product size="120x120" method="crop" %} 2x"- alt="">- </td>- <td>- {{ product.name }}- </td>- <td>- {% gross product.price html=True %}- </td>- </tr>+ <div class="row">+ <div class="col s12 l9" id="product-list">+ {% if products %}+ <div class="card">+ <form method="POST" action="{% url 'dashboard:product-bulk-update' %}" novalidate id="bulk-actions-form">+ {% csrf_token %}+ <input name="action" type="hidden" id="bulk-action" />+ <nav class="data-table-header-alternative single">+ <div class="bulk-info show-bulk">+ <div class="data-table-header-action-selected-items col inline"></div>+ </div>+ <div class="bulk-actions show-bulk nav-wrapper">+ <ul class="right">+ {% for action, label in bulk_action_form.action.field.widget.choices %}+ <li>+ <a href="" data-action="{{ action }}" class="btn-flat">{{ label|upper }}</a>+ </li>{% endfor %}- </tbody>- </table>- </div>- </form>+ </ul></div>- {% paginate products %}- </div>- <div class="col s12 l3">- {% include 'dashboard/includes/_filters.html' %}+ </nav>+ <div class="data-table-container">+ <table class="bordered highlight responsive data-table">+ <thead>+ <tr>+ <th class="bulk-checkbox">+ <input id="select-all-products" type="checkbox" class="filled-in select-all switch-actions select-item">+ <label for="select-all-products"></label>+ </th>+ <th></th>+ <th class="wide{% if request.GET.sort_by == 'name' or request.GET.sort_by == '-name' %} active{% endif %}">+ <a href="{% get_sort_by_url_toggle 'name' %}">+ {% if is_descending %}+ <svg data-src="{% static '/images/arrow_down_icon.svg' %}" />+ {% else %}+ <svg data-src="{% static '/images/arrow_up_icon.svg' %}" />+ {% endif %}+ {% trans "Name" context "Products list table header" %}+ </a>+ </th>+ <th class="right-align {% if request.GET.sort_by == 'price' or request.GET.sort_by == '-price' %} active{% endif %}">+ <a href="{% get_sort_by_url_toggle 'price' %}">+ {% if is_descending %}+ <svg data-src="{% static '/images/arrow_down_icon.svg' %}" />+ {% else %}+ <svg data-src="{% static '/images/arrow_up_icon.svg' %}" />+ {% endif %}+ {% trans "Price" context "Products list table header" %}+ </a>+ </th>+ </tr>+ </thead>+ <tbody>+ {% for product in products %}+ <tr class="avatar" data-action-go="{% url 'dashboard:product-detail' pk=product.pk %}">+ <td class="bulk-checkbox ignore-link">+ <input id="id_products_{{ product.pk }}" type="checkbox" name="products" value="{{ product.pk }}" class="filled-in switch-actions select-item">+ <label for="id_products_{{ product.pk }}"></label>+ </td>+ <td class="avatar">+ <img src="{% product_first_image product size="60x60" method="crop" %}"+ srcset="{% product_first_image product size="60x60" method="crop" %} 1x, {% product_first_image product size="120x120" method="crop" %} 2x"+ alt="">+ </td>+ <td>+ {{ product.name }}+ </td>+ <td>+ {% gross product.price html=True %}+ </td>+ </tr>+ {% endfor %}+ </tbody>+ </table>+ </div>+ </form></div>- </div>- {% else %}- <div class="row">+ {% paginate products %}+ {% else %}<div class="col s12"><div class="not-found"><p class="grey-text">@@ -131,8 +135,12 @@{% endif %}</div></div>+ {% endif %}</div>- {% endif %}+ <div class="col s12 l3" id="product-filters">+ {% include 'dashboard/includes/_filters.html' %}+ </div>+ </div><div id="modal-product-class" class="modal"><form method="post" novalidate><div class="modal-content">