From 985697f8eebf021059fd3b9fd67bd3799e74d845 Mon Sep 17 00:00:00 2001 From: Nathan Chapman Date: Sun, 29 Jan 2023 15:31:24 -0700 Subject: [PATCH] Add ability to drag-n-drop sort Products, Variants, and Photos --- dashboard/templates/dashboard/catalog.html | 2 +- .../templates/dashboard/category/list.html | 2 +- .../templates/dashboard/product/_table.html | 6 +-- .../templates/dashboard/product/detail.html | 30 +++++------ .../templates/dashboard/product/list.html | 5 ++ dashboard/urls.py | 6 +++ dashboard/views.py | 26 +++++++++- static/scripts/sorting.js | 51 +++++++++++++++++++ static/styles/dashboard.css | 4 ++ templates/dashboard.html | 5 ++ 10 files changed, 116 insertions(+), 21 deletions(-) create mode 100644 static/scripts/sorting.js diff --git a/dashboard/templates/dashboard/catalog.html b/dashboard/templates/dashboard/catalog.html index 7a6ac93..b4ac5e1 100644 --- a/dashboard/templates/dashboard/catalog.html +++ b/dashboard/templates/dashboard/catalog.html @@ -19,7 +19,7 @@

{{ category }}

View category → - {% include 'dashboard/product/_table.html' with product_list=category.product_set.all %} + {% include 'dashboard/product/_table.html' with product_list=category.product_set.all category=category %} {% endfor %} diff --git a/dashboard/templates/dashboard/category/list.html b/dashboard/templates/dashboard/category/list.html index d36b932..5832376 100644 --- a/dashboard/templates/dashboard/category/list.html +++ b/dashboard/templates/dashboard/category/list.html @@ -20,7 +20,7 @@

{{ category }}

View category → - {% include 'dashboard/product/_table.html' with product_list=category.product_set.all %} + {% include 'dashboard/product/_table.html' with product_list=category.product_set.all category=category %} {% endfor %} diff --git a/dashboard/templates/dashboard/product/_table.html b/dashboard/templates/dashboard/product/_table.html index 841837e..d587362 100644 --- a/dashboard/templates/dashboard/product/_table.html +++ b/dashboard/templates/dashboard/product/_table.html @@ -6,10 +6,10 @@ Visible in listings - + {% for product in product_list %} - - {{ product.sorting }} + + ☰
{{ product.get_first_img.image }} diff --git a/dashboard/templates/dashboard/product/detail.html b/dashboard/templates/dashboard/product/detail.html index 60a982d..05d68ae 100644 --- a/dashboard/templates/dashboard/product/detail.html +++ b/dashboard/templates/dashboard/product/detail.html @@ -80,10 +80,10 @@ Stock - + {% for variant in product.variants.all %} - - {{ variant.sorting }} + + ☰

{{ variant.name }}

@@ -124,18 +124,18 @@

Photos

+ Upload new photo - {% endif %} +{% url 'dashboard:update-sorting' as sorting_url %} +{{ sorting_url|json_script:"sorting-url" }} +