From ff212d6e1518f6bdb55a13fee2209bb83419a3d1 Mon Sep 17 00:00:00 2001
From: Daoud Clarke
Date: Sun, 29 Oct 2023 14:22:25 +0000
Subject: [PATCH 1/4] Add template for results; remove some unused code
---
mwmbl/templates/results.html | 16 ++++++++++++++++
mwmbl/urls.py | 8 +-------
mwmbl/views.py | 19 +------------------
3 files changed, 18 insertions(+), 25 deletions(-)
create mode 100644 mwmbl/templates/results.html
diff --git a/mwmbl/templates/results.html b/mwmbl/templates/results.html
new file mode 100644
index 0000000..ddaac9f
--- /dev/null
+++ b/mwmbl/templates/results.html
@@ -0,0 +1,16 @@
+{% for result in results %}
+
+{% end for %}
diff --git a/mwmbl/urls.py b/mwmbl/urls.py
index b416085..0666890 100644
--- a/mwmbl/urls.py
+++ b/mwmbl/urls.py
@@ -15,12 +15,10 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
-from django.contrib.auth import login, logout
-from django.template.defaulttags import url
from django.urls import path, include
from mwmbl.api import api_original as api, api_v1
-from mwmbl.views import signup, profile
+from mwmbl.views import profile
urlpatterns = [
path('admin/', admin.site.urls),
@@ -28,9 +26,5 @@ urlpatterns = [
path('api/v1/', api_v1.urls),
path('accounts/', include('allauth.urls')),
- # path("accounts/", include("django.contrib.auth.urls")),
- # path('accounts/new/', signup, name='signup'),
path('accounts/profile/', profile, name='profile'),
- # path('login/', login, {'template_name': 'login.html'}, name='login'),
- # path('logout/', logout, {'next_page': 'login'}, name='logout'),
]
diff --git a/mwmbl/views.py b/mwmbl/views.py
index 0ae3ba8..2eac576 100644
--- a/mwmbl/views.py
+++ b/mwmbl/views.py
@@ -1,22 +1,5 @@
-from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
-from django.contrib.auth.forms import UserCreationForm
-from django.shortcuts import redirect, render
-
-
-def signup(request):
- if request.method == 'POST':
- form = UserCreationForm(request.POST)
- if form.is_valid():
- form.save()
- username = form.cleaned_data.get('username')
- raw_password = form.cleaned_data.get('password1')
- user = authenticate(username=username, password=raw_password)
- login(request, user)
- return redirect('/')
- else:
- form = UserCreationForm()
- return render(request, 'signup.html', {'form': form})
+from django.shortcuts import render
@login_required
From fb270532953b10649653b84db1b071cf9c0efb4e Mon Sep 17 00:00:00 2001
From: Daoud Clarke
Date: Mon, 30 Oct 2023 08:53:25 +0000
Subject: [PATCH 2/4] WIP: implement search using htmx
---
front-end/src/components/molecules/result.js | 42 +++++------
front-end/src/components/organisms/results.js | 72 +++++++------------
front-end/src/index.html | 40 +++++++++++
front-end/src/index.js | 2 +-
mwmbl/api.py | 20 +-----
mwmbl/apps.py | 2 +-
mwmbl/search_setup.py | 19 +++++
mwmbl/templates/results.html | 31 ++++----
mwmbl/templatetags/__init__.py | 0
mwmbl/templatetags/result_filters.py | 18 +++++
mwmbl/urls.py | 4 +-
mwmbl/views.py | 8 +++
12 files changed, 153 insertions(+), 105 deletions(-)
create mode 100644 mwmbl/search_setup.py
create mode 100644 mwmbl/templatetags/__init__.py
create mode 100644 mwmbl/templatetags/result_filters.py
diff --git a/front-end/src/components/molecules/result.js b/front-end/src/components/molecules/result.js
index 2a2859e..a5ff9b1 100644
--- a/front-end/src/components/molecules/result.js
+++ b/front-end/src/components/molecules/result.js
@@ -5,22 +5,22 @@ import deleteButton from "./delete-button.js";
import validateButton from "./validate-button.js";
import addButton from "./add-button.js";
-const template = ({ data }) => /*html*/`
-
-`;
+// const template = ({ data }) => /*html*/`
+//
+//
+//
+//
+//
+//
+//
+//
+// `;
export default define('result', class extends HTMLLIElement {
constructor() {
@@ -30,11 +30,11 @@ export default define('result', class extends HTMLLIElement {
}
__setup() {
- this.innerHTML = template({ data: {
- url: this.dataset.url,
- title: this.__handleBold(JSON.parse(this.dataset.title)),
- extract: this.__handleBold(JSON.parse(this.dataset.extract))
- }});
+ // this.innerHTML = template({ data: {
+ // url: this.dataset.url,
+ // title: this.__handleBold(JSON.parse(this.dataset.title)),
+ // extract: this.__handleBold(JSON.parse(this.dataset.extract))
+ // }});
this.__events();
}
diff --git a/front-end/src/components/organisms/results.js b/front-end/src/components/organisms/results.js
index 9cd9993..d466c49 100644
--- a/front-end/src/components/organisms/results.js
+++ b/front-end/src/components/organisms/results.js
@@ -7,15 +7,22 @@ import emptyResult from '../molecules/empty-result.js';
import home from './home.js';
import escapeString from '../../utils/escapeString.js';
-const template = () => /*html*/`
-
-`;
+// const template = () => /*html*/`
+//
+// `;
-export default define('results', class extends HTMLElement {
+
+document.body.addEventListener('htmx:load', function(evt) {
+
+});
+
+
+// export default define('results', class extends HTMLElement {
+
+class ResultsHandler {
constructor() {
- super();
this.results = null;
this.oldIndex = null;
this.curating = false;
@@ -23,50 +30,16 @@ export default define('results', class extends HTMLElement {
}
__setup() {
- this.innerHTML = template();
- this.results = this.querySelector('.results');
+ // this.innerHTML = template();
this.__events();
}
__events() {
- globalBus.on('search', (e) => {
- this.results.innerHTML = '';
- let resultsHTML = '';
- if (!e.detail.error) {
- // If there is no details the input is empty
- if (!e.detail.results) {
- resultsHTML = /*html*/`
-
- `;
- }
- // If the details array has results display them
- else if (e.detail.results.length > 0) {
- for(const resultData of e.detail.results) {
- resultsHTML += /*html*/`
-
- `;
- }
- }
- // If the details array is empty there is no result
- else {
- resultsHTML = /*html*/`
-
- `;
- }
- }
- else {
- // If there is an error display an empty result
- resultsHTML = /*html*/`
-
- `;
- }
- // Bind HTML to the DOM
- this.results.innerHTML = resultsHTML;
+ document.body.addEventListener('htmx:load', e => {
+ // });
+ //
+ // globalBus.on('search', (e) => {
+ this.results = document.querySelector('.results');
// Allow the user to re-order search results
$(".results").sortable({
@@ -236,4 +209,7 @@ export default define('results', class extends HTMLElement {
});
globalBus.dispatch(curationMoveEvent);
}
-});
\ No newline at end of file
+}
+
+const resultsHandler = new ResultsHandler();
+
diff --git a/front-end/src/index.html b/front-end/src/index.html
index 65bacda..74e9a21 100644
--- a/front-end/src/index.html
+++ b/front-end/src/index.html
@@ -48,6 +48,8 @@
+
+
+
+
+
+
+
+
+
+
+
+
+