Changes.
This commit is contained in:
parent
8d0d709e18
commit
d7b943dc8c
@ -27,6 +27,7 @@ from snek.view.rpc import RPCView
|
||||
from snek.view.status import StatusView
|
||||
from snek.view.web import WebView
|
||||
from snek.view.upload import UploadView
|
||||
from snek.view.search_user import SearchUserView
|
||||
|
||||
SESSION_KEY = b"c79a0c5fda4b424189c427d28c9f7c34"
|
||||
|
||||
@ -83,6 +84,8 @@ class Application(BaseApplication):
|
||||
self.router.add_view("/register.json", RegisterView)
|
||||
self.router.add_view("/drive.bin", UploadView)
|
||||
self.router.add_view("/drive.bin/{uid}", UploadView)
|
||||
self.router.add_view("/search-user.html", SearchUserView)
|
||||
self.router.add_view("/search-user.json", SearchUserView)
|
||||
self.router.add_get("/http-get", self.handle_http_get)
|
||||
self.router.add_get("/http-photo", self.handle_http_photo)
|
||||
self.router.add_get("/rpc.ws", RPCView)
|
||||
|
30
src/snek/static/push.js
Normal file
30
src/snek/static/push.js
Normal file
@ -0,0 +1,30 @@
|
||||
this.onpush = (event) => {
|
||||
console.log(event.data);
|
||||
// From here we can write the data to IndexedDB, send it to any open
|
||||
// windows, display a notification, etc.
|
||||
};
|
||||
|
||||
navigator.serviceWorker
|
||||
.register("service-worker.js")
|
||||
.then((serviceWorkerRegistration) => {
|
||||
serviceWorkerRegistration.pushManager.subscribe().then(
|
||||
(pushSubscription) => {
|
||||
const subscriptionObject = {
|
||||
endpoint: pushSubscription.endpoint,
|
||||
keys: {
|
||||
p256dh: pushSubscription.getKey('p256dh'),
|
||||
auth: pushSubscription.getKey('auth'),
|
||||
},
|
||||
encoding: PushManager.supportedContentEncodings,
|
||||
/* other app-specific data, such as user identity */
|
||||
};
|
||||
console.log(pushSubscription.endpoint, pushSubscription, subscriptionObject);
|
||||
// The push subscription details needed by the application
|
||||
// server are now available, and can be sent to it using,
|
||||
// for example, the fetch() API.
|
||||
},
|
||||
(error) => {
|
||||
console.error(error);
|
||||
},
|
||||
);
|
||||
});
|
30
src/snek/static/service-worker.js
Normal file
30
src/snek/static/service-worker.js
Normal file
@ -0,0 +1,30 @@
|
||||
self.addEventListener("install", (event) => {
|
||||
console.log("Service worker installed");
|
||||
});
|
||||
|
||||
self.addEventListener("push", (event) => {
|
||||
if (!(self.Notification && self.Notification.permission === "granted")) {
|
||||
return;
|
||||
}
|
||||
console.log("Received a push message", event);
|
||||
|
||||
const data = event.data?.json() ?? {};
|
||||
const title = data.title || "Something Has Happened";
|
||||
const message =
|
||||
data.message || "Here's something you might want to check out.";
|
||||
const icon = "images/new-notification.png";
|
||||
|
||||
event.waitUntil(self.registration.showNotification(title, {
|
||||
body: message,
|
||||
tag: "simple-push-demo-notification",
|
||||
icon,
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
self.addEventListener("notificationclick", (event) => {
|
||||
console.log("Notification click Received.", event);
|
||||
event.notification.close();
|
||||
event.waitUntil(clients.openWindow(
|
||||
"https://snek.molodetz.nl",));
|
||||
});
|
@ -24,6 +24,7 @@
|
||||
<div class="logo">Snek</div>
|
||||
<nav>
|
||||
<a href="/web.html">🏠</a>
|
||||
<a href="/search-user.html">🔍</a>
|
||||
<a style="display:none" id="install-button" href="#">📥</a>
|
||||
<a href="/web.html">👥</a>
|
||||
<a href="#">⚙️</a>
|
||||
@ -52,7 +53,7 @@ let installPrompt = null
|
||||
window.addEventListener("beforeinstallprompt", async(event) => {
|
||||
event.preventDefault();
|
||||
installPrompt = event;
|
||||
//document.addEventListener("DOMContentLoaded", () => {
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
alert("Jaaah")
|
||||
const button = document.getElementById("install-button")
|
||||
button.addEventListener("click", async ()=>{
|
||||
@ -61,6 +62,7 @@ let installPrompt = null
|
||||
})
|
||||
button.style.display = 'inline-block'
|
||||
|
||||
})
|
||||
});
|
||||
;
|
||||
</script>
|
||||
|
8
src/snek/templates/search-user.html
Normal file
8
src/snek/templates/search-user.html
Normal file
@ -0,0 +1,8 @@
|
||||
{% extends "app.html" %}
|
||||
|
||||
{% block title %}Search{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<h1>Search user</h1>
|
||||
<generic-form class="center" url="/search_user.json"></generic-form>
|
||||
{% endblock %}
|
21
src/snek/view/search_user.py
Normal file
21
src/snek/view/search_user.py
Normal file
@ -0,0 +1,21 @@
|
||||
from aiohttp import web
|
||||
|
||||
from snek.form.search_user import SearchUserForm
|
||||
from snek.system.view import BaseFormView
|
||||
|
||||
|
||||
class SearchUserView(BaseFormView):
|
||||
form = SearchUserForm
|
||||
|
||||
async def get(self):
|
||||
if self.session.get("logged_in"):
|
||||
return web.HTTPFound("/web.html")
|
||||
if self.request.path.endswith(".json"):
|
||||
return await super().get()
|
||||
return await self.render_template("login.html")
|
||||
|
||||
async def submit(self, form):
|
||||
if await form.is_valid:
|
||||
|
||||
return {"redirect_url": "/search-user.html?query=" + form.query.value}
|
||||
return {"is_valid": False}
|
Loading…
Reference in New Issue
Block a user