Implement a hooks page

Mark Veidemanis 2 years ago
parent 5c67a3a707
commit 83808dfa52
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

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

@ -74,6 +74,12 @@ class Session(models.Model):
plan = models.ForeignKey(Plan, null=True, blank=True, on_delete=models.CASCADE) 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 Perms(models.Model):
# class Meta: # class Meta:
# permissions = ( # permissions = (

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

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

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

@ -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 %}

@ -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>

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

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

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

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

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

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

@ -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)

@ -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)
Loading…
Cancel
Save