Implement a hooks page

This commit is contained in:
Mark Veidemanis 2022-10-14 07:20:30 +01:00
parent 5c67a3a707
commit 83808dfa52
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
16 changed files with 109 additions and 83 deletions

View File

@ -19,7 +19,7 @@ from django.contrib import admin
from django.urls import include, path
from django.views.generic import TemplateView
from core.views import base, demo
from core.views import base, hooks
from core.views.callbacks import Callback
urlpatterns = [
@ -41,7 +41,8 @@ urlpatterns = [
path("admin/", admin.site.urls),
path("accounts/", include("django.contrib.auth.urls")),
path("accounts/signup/", base.Signup.as_view(), name="signup"),
path("demo/modal/", demo.DemoModal.as_view(), name="modal"),
path("demo/widget/", demo.DemoWidget.as_view(), name="widget"),
path("demo/window/", demo.DemoWindow.as_view(), name="window"),
# path("demo/modal/", demo.DemoModal.as_view(), name="modal"),
# path("demo/widget/", demo.DemoWidget.as_view(), name="widget"),
# path("demo/window/", demo.DemoWindow.as_view(), name="window"),
path("hooks/<str:type>/", hooks.Hooks.as_view(), name="hooks"),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

View File

@ -74,6 +74,12 @@ class Session(models.Model):
plan = models.ForeignKey(Plan, null=True, blank=True, on_delete=models.CASCADE)
class Hook(models.Model):
user = user = models.ForeignKey(User, on_delete=models.CASCADE)
hook = models.CharField(max_length=255, null=True, blank=True)
received = models.IntegerField(default=0)
# class Perms(models.Model):
# class Meta:
# permissions = (

View File

@ -201,6 +201,11 @@
<a class="navbar-item" href="{% url 'home' %}">
Home
</a>
{% if user.is_authenticated %}
<a class="navbar-item" href="{% url 'hooks' type='page' %}">
Hooks
</a>
{% endif %}
{% if settings.STRIPE_ENABLED %}
{% if user.is_authenticated %}
<a class="navbar-item" href="{% url 'billing' %}">
@ -285,6 +290,12 @@
<div class="container">
{% block content %}
{% endblock %}
<div id="modals-here">
</div>
<div id="items-here">
</div>
<div id="widgets-here" style="display: none;">
</div>
</div>
</section>
</body>

View File

@ -81,13 +81,6 @@
}
});
</script>
<div id="modals-here">
</div>
<div id="items-here">
</div>
<div id="widgets-here" style="display: none;">
</div>
<script>
</script>

View File

@ -1,5 +0,0 @@
{% extends 'wm/modal.html' %}
{% block modal_content %}
{% include 'window-content/main.html' %}
{% endblock %}

View File

@ -1,20 +0,0 @@
{% extends 'wm/widget.html' %}
{% load static %}
{% block widget_options %}
gs-w="10" gs-h="1" gs-y="10" gs-x="1"
{% endblock %}
{% block heading %}
Widget
{% endblock %}
{% block close_button %}
<i
class="fa-solid fa-xmark has-text-grey-light float-right"
onclick='grid.removeWidget("widget-{{ unique }}"); //grid.compact();'></i>
{% endblock %}
{% block panel_content %}
{% include 'window-content/main.html' %}
{% endblock %}

View File

@ -0,0 +1,47 @@
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="#"
hx-trigger="click"
hx-target="#modals-here"
class="button is-info">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-plus"></i>
</span>
<span>Hook</span>
</span>
</button>
</div>
{% include 'partials/notify.html' %}
<table class="table is-fullwidth is-hoverable">
<thead>
<th>user</th>
<th>hook</th>
<th>received hooks</th>
<th>actions</th>
</thead>
{% for item in hooks %}
<tr>
<td>{{ item.user }}</td>
<td>{{ item.hook }}</td>
<td>{{ item.received }}</td>
<td>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="#"
hx-trigger="click"
hx-target="#modals-here"
class="button is-info">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-pencil"></i>
</span>
<span>Hook</span>
</span>
</button>
</td>
</tr>
{% endfor %}
</table>

View File

@ -3,7 +3,7 @@
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'modal' %}"
hx-get="{% url 'hooks' type='modal' %}"
hx-trigger="click"
hx-target="#modals-here"
class="button is-info">
@ -16,7 +16,7 @@
</button>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'widget' %}"
hx-get="{% url 'hooks' type='widget' %}"
hx-trigger="click"
hx-target="#widgets-here"
class="button is-info">
@ -29,7 +29,7 @@
</button>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'window' %}"
hx-get="{% url 'hooks' type='window' %}"
hx-trigger="click"
hx-target="#items-here"
hx-swap="afterend"

View File

@ -1,9 +0,0 @@
{% extends 'wm/magnet.html' %}
{% block heading %}
Window
{% endblock %}
{% block panel_content %}
{% include 'window-content/main.html' %}
{% endblock %}

View File

@ -12,6 +12,7 @@
<div class="modal-content">
<div class="box">
{% block modal_content %}
{% include window_content %}
{% endblock %}
<button class="modal-close is-large" aria-label="close"></button>
</div>

View File

@ -0,0 +1,6 @@
{% extends "base.html" %}
{% block content %}
{% include window_content %}
{% endblock %}

View File

@ -1,5 +1,5 @@
<div id="widget">
<div id="widget-{{ unique }}" class="grid-stack-item" {% block widget_options %}{% endblock %}>
<div id="widget-{{ unique }}" class="grid-stack-item" {% block widget_options %}gs-w="10" gs-h="1" gs-y="10" gs-x="1"{% endblock %}>
<div class="grid-stack-item-content">
<nav class="panel">
@ -14,11 +14,13 @@
class="fa-solid fa-arrows-minimize has-text-grey-light float-right"
onclick='grid.compact();'></i>
{% block heading %}
{{ title }}
{% endblock %}
</p>
<article class="panel-block is-active">
<div class="control">
{% block panel_content %}
{% include window_content %}
{% endblock %}
</div>
</article>

View File

@ -1,8 +1,10 @@
<magnet-block attract-distance="10" align-to="outer|center" class="floating-window">
{% extends 'wm/panel.html' %}
{% block heading %}
{{ title }}
{% endblock %}
{% block panel_content %}
{% include window_content %}
{% endblock %}
</magnet-block>

View File

@ -1,34 +0,0 @@
import uuid
from django.shortcuts import render
from django.views import View
from django.http import HttpResponseBadRequest
class OpenSettings(View):
allowed_types = ["modal", "widget", "window"]
async def get(self, request, type):
if type not in self.allowed_types:
return HttpResponseBadRequest
#template_name =
class DemoModal(View):
template_name = "modals/modal.html"
async def get(self, request):
return render(request, self.template_name)
class DemoWidget(View):
template_name = "widgets/widget.html"
async def get(self, request):
unique = str(uuid.uuid4())[:8]
return render(request, self.template_name, {"unique": unique})
class DemoWindow(View):
template_name = "windows/window.html"
async def get(self, request):
return render(request, self.template_name)

25
core/views/hooks.py Normal file
View File

@ -0,0 +1,25 @@
import uuid
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseBadRequest
from django.shortcuts import render
from django.views import View
class Hooks(LoginRequiredMixin, View):
allowed_types = ["modal", "widget", "window", "page"]
window_content = "window-content/hooks.html"
async def get(self, request, type):
if type not in self.allowed_types:
return HttpResponseBadRequest
template_name = f"wm/{type}.html"
unique = str(uuid.uuid4())[:8]
hooks = [{"user": "test", "hook": "/help22", "received": "40"}]
context = {
"title": f"{type} Demo",
"unique": unique,
"window_content": self.window_content,
"hooks": hooks,
}
return render(request, template_name, context)