From 70b66122c8201ef22d1ce2dd549ab151a0472ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Fri, 27 Dec 2019 12:32:44 +0100 Subject: [PATCH] Implement tag auto-completion --- .gitignore | 3 +- README.md | 4 + bookmarks/components/TagAutocomplete.svelte | 155 +++++++++++ bookmarks/components/index.js | 6 + bookmarks/queries.py | 4 + bookmarks/styles/index.scss | 1 + bookmarks/templates/bookmarks/edit.html | 2 +- bookmarks/templates/bookmarks/form.html | 23 +- bookmarks/templates/bookmarks/new.html | 2 +- bookmarks/templatetags/bookmarks.py | 11 +- bookmarks/views/bookmarks.py | 12 +- build-static.sh | 1 + package-lock.json | 294 ++++++++++++++++++++ package.json | 11 +- rollup.config.js | 40 +++ siteroot/settings/base.py | 1 + 16 files changed, 559 insertions(+), 11 deletions(-) create mode 100644 bookmarks/components/TagAutocomplete.svelte create mode 100644 bookmarks/components/index.js create mode 100644 rollup.config.js diff --git a/.gitignore b/.gitignore index dc99747..63907f5 100644 --- a/.gitignore +++ b/.gitignore @@ -222,7 +222,8 @@ typings/ .next ### Custom - +# Rollup compilation output +/build # Collected static files for deployment /static # Build output, etc. diff --git a/README.md b/README.md index fdf5055..c65f4b9 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,10 @@ Create a user for the frontend: ``` python3 manage.py createsuperuser --username=joe --email=joe@example.com ``` +Start the Node.js development server (used for compiling JavaScript components like tag auto-completion) with: +``` +npm run dev +``` Start the Django development server with: ``` python3 manage.py runserver diff --git a/bookmarks/components/TagAutocomplete.svelte b/bookmarks/components/TagAutocomplete.svelte new file mode 100644 index 0000000..a3676cb --- /dev/null +++ b/bookmarks/components/TagAutocomplete.svelte @@ -0,0 +1,155 @@ + + +
+ +
+ + +
+ + + +
+ + \ No newline at end of file diff --git a/bookmarks/components/index.js b/bookmarks/components/index.js new file mode 100644 index 0000000..7a56156 --- /dev/null +++ b/bookmarks/components/index.js @@ -0,0 +1,6 @@ +import TagAutoComplete from './TagAutocomplete.svelte' + +export default { + TagAutoComplete +} + diff --git a/bookmarks/queries.py b/bookmarks/queries.py index 1bb8b03..564f4d8 100644 --- a/bookmarks/queries.py +++ b/bookmarks/queries.py @@ -78,6 +78,10 @@ def query_tags(user: User, query_string: str): return query_set.distinct() +def get_user_tags(user: User): + return Tag.objects.filter(owner=user).all() + + def _parse_query_string(query_string): # Sanitize query params if not query_string: diff --git a/bookmarks/styles/index.scss b/bookmarks/styles/index.scss index 8797384..556c57c 100644 --- a/bookmarks/styles/index.scss +++ b/bookmarks/styles/index.scss @@ -10,6 +10,7 @@ $alternative-color-dark: darken($alternative-color, 5%); // Import Spectre CSS lib @import "../../node_modules/spectre.css/src/spectre"; +@import "../../node_modules/spectre.css/src/autocomplete"; // Import Spectre icons @import "../../node_modules/spectre.css/src/icons/icons-core"; @import "../../node_modules/spectre.css/src/icons/icons-navigation"; diff --git a/bookmarks/templates/bookmarks/edit.html b/bookmarks/templates/bookmarks/edit.html index 7d5c795..d5e6f54 100644 --- a/bookmarks/templates/bookmarks/edit.html +++ b/bookmarks/templates/bookmarks/edit.html @@ -8,7 +8,7 @@

Edit bookmark

- {% bookmark_form form %} + {% bookmark_form form all_tags %}
diff --git a/bookmarks/templates/bookmarks/form.html b/bookmarks/templates/bookmarks/form.html index 5949d64..377c4c6 100644 --- a/bookmarks/templates/bookmarks/form.html +++ b/bookmarks/templates/bookmarks/form.html @@ -1,4 +1,5 @@ {% load widget_tweaks %} +{% load static %}
{% csrf_token %} @@ -13,7 +14,7 @@ {% endif %}
- + {{ form.tag_string|add_class:"form-input" }}
Enter any number of tags separated by space and without the hash (#). If a tag does not @@ -54,6 +55,26 @@ Nevermind
+ {# Replace tag input with auto-complete component #} + +