Compare commits
112 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
809e7ce6d7 | ||
|
|
576e65dca6 | ||
|
|
e0505755da | ||
|
|
4fe86d33b6 | ||
|
|
3cd93ac7da | ||
|
|
7c4ed1d2b2 | ||
|
|
67395c9ebf | ||
|
|
3ef834e103 | ||
|
|
cf9da4c6a0 | ||
|
|
58f2a53539 | ||
|
|
46e891d429 | ||
|
|
01d9377238 | ||
|
|
7819b461b8 | ||
|
|
f0e2c9ca94 | ||
|
|
ad94658aef | ||
|
|
1b52eaac46 | ||
|
|
e03b58057e | ||
|
|
1ffd08082b | ||
|
|
942ee3805d | ||
|
|
75034e0602 | ||
|
|
5bd335dbd6 | ||
|
|
ffce155154 | ||
|
|
245de43c78 | ||
|
|
bb9ee26bd2 | ||
|
|
158d49d221 | ||
|
|
fcd2f16401 | ||
|
|
f1331157fd | ||
|
|
f021209531 | ||
|
|
d5867c4f0d | ||
|
|
b8c3603cbb | ||
|
|
dbde003fc2 | ||
|
|
239c73fb8e | ||
|
|
9589a21f96 | ||
|
|
c1c6804a63 | ||
|
|
08166dda95 | ||
|
|
2e3af63c72 | ||
|
|
d438bc4b14 | ||
|
|
00f74d4228 | ||
|
|
2d06680bab | ||
|
|
39d8a2034f | ||
|
|
8d63c8fd4e | ||
|
|
63e37061de | ||
|
|
319828b8b1 | ||
|
|
952917d415 | ||
|
|
c85fbe915f | ||
|
|
4091f6c8f5 | ||
|
|
e9c21409cd | ||
|
|
7068ae402e | ||
|
|
a9bebd789e | ||
|
|
fa94a99567 | ||
|
|
180a26344a | ||
|
|
f7686371c5 | ||
|
|
51735f79dc | ||
|
|
53854b23cd | ||
|
|
fa91d5f670 | ||
|
|
ad23d05000 | ||
|
|
154d496208 | ||
|
|
36d373cdc3 | ||
|
|
f266f3579c | ||
|
|
6fd7726ae0 | ||
|
|
bee5b04441 | ||
|
|
cdefc2e993 | ||
|
|
7abdbe605b | ||
|
|
2d193969f7 | ||
|
|
22396d1a00 | ||
|
|
031a4e5259 | ||
|
|
03b1695d9a | ||
|
|
03e75ffe2a | ||
|
|
93f9979259 | ||
|
|
02d5aa0263 | ||
|
|
4125b433e5 | ||
|
|
bbd6f6635d | ||
|
|
1612e7d241 | ||
|
|
81f0aadd39 | ||
|
|
d66b9272b7 | ||
|
|
07e014cd8f | ||
|
|
aa65cead2e | ||
|
|
7a5ba150f7 | ||
|
|
057bcdcf02 | ||
|
|
2eeda6fc5c | ||
|
|
b49a4c3ddf | ||
|
|
70590fbdc9 | ||
|
|
fe005863a8 | ||
|
|
982f845cfc | ||
|
|
b1b081fe30 | ||
|
|
7d4d74b01a | ||
|
|
0dea7b77d7 | ||
|
|
626a3474f8 | ||
|
|
7abd354625 | ||
|
|
562829a23b | ||
|
|
c5799921d1 | ||
|
|
d03c46fa5f | ||
|
|
fea54cc943 | ||
|
|
05735972ae | ||
|
|
cf6ba862d6 | ||
|
|
6da2807b0a | ||
|
|
fe1d24a23e | ||
|
|
5453691016 | ||
|
|
5d86ca29fb | ||
|
|
435ae846c1 | ||
|
|
7f2e30c587 | ||
|
|
5bffe1cefd | ||
|
|
91cc589617 | ||
|
|
cc44bbaa4e | ||
|
|
834f1284fe | ||
|
|
1c1d758ab1 | ||
|
|
15ed4bd993 | ||
|
|
92bf70831e | ||
|
|
5fda34fef9 | ||
|
|
18b2d01c23 | ||
|
|
3786a803a6 | ||
|
|
0a168ea8b4 |
19
README.md
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# 🚀 Getting started with PomeloNote
|
||||||
|
### **THIS REPOSITORY HAS DEPENDENCIES WITH SECURITY VULNERABILITIES. YOU MIGHT WANT TO UPDATE PACKAGES BEFORE USE.**
|
||||||
|
## Setup
|
||||||
|
- run `npm i`
|
||||||
|
- get the .env file and save it to the root directory of the project
|
||||||
|
- set up Strapi
|
||||||
|
- go to `localhost:1337/admin`
|
||||||
|
- register an admin user
|
||||||
|
- go to Settings => Users&Permissions Plugin => Roles => Authenticated => Note => Select all
|
||||||
|
- Save
|
||||||
|
|
||||||
|
### Starting the container with svelte and strapi:
|
||||||
|
``docker-compose up --build -d``
|
||||||
|
|
||||||
|
### Restart and rebuild Svelte:
|
||||||
|
``docker-compose up --detach --build svelte``
|
||||||
|
|
||||||
|
### Restart and rebuild Strapi:
|
||||||
|
``docker-compose up --detach --build strapi``
|
||||||
|
|
@ -4,7 +4,8 @@
|
||||||
"info": {
|
"info": {
|
||||||
"singularName": "note",
|
"singularName": "note",
|
||||||
"pluralName": "notes",
|
"pluralName": "notes",
|
||||||
"displayName": "note"
|
"displayName": "note",
|
||||||
|
"description": ""
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"draftAndPublish": true
|
"draftAndPublish": true
|
||||||
|
|
@ -20,8 +21,9 @@
|
||||||
},
|
},
|
||||||
"owners": {
|
"owners": {
|
||||||
"type": "relation",
|
"type": "relation",
|
||||||
"relation": "oneToMany",
|
"relation": "manyToMany",
|
||||||
"target": "admin::user"
|
"target": "plugin::users-permissions.user",
|
||||||
|
"mappedBy": "notes"
|
||||||
},
|
},
|
||||||
"lastViewed": {
|
"lastViewed": {
|
||||||
"type": "datetime",
|
"type": "datetime",
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,138 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
//move to utils!
|
||||||
|
|
||||||
|
function getNoteIdFromUrl(url) {
|
||||||
|
return Number(url.split("/").at(-1));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* note controller
|
* note controller
|
||||||
*/
|
*/
|
||||||
|
const noteUid = 'api::note.note';
|
||||||
|
const {createCoreController} = require('@strapi/strapi').factories;
|
||||||
|
|
||||||
const { createCoreController } = require('@strapi/strapi').factories;
|
module.exports = createCoreController(noteUid, ({strapi}) => ({
|
||||||
|
/**
|
||||||
module.exports = createCoreController('api::note.note');
|
* Gives all, to the user related, notes.
|
||||||
|
* @param ctx
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
async find(ctx) {
|
||||||
|
const userId = ctx.state.user.id;
|
||||||
|
const entries = await strapi.entityService.findMany(noteUid, {
|
||||||
|
populate: ['owners'],
|
||||||
|
filters: {
|
||||||
|
owners: {
|
||||||
|
id: userId
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sort: {
|
||||||
|
lastViewed: 'desc'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return JSON.stringify(entries);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Finds the note by id and updates lastViewed. Exits 403 if the note does not belong to the user making the request.
|
||||||
|
* @param ctx
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
async findOne(ctx) {
|
||||||
|
const noteId = getNoteIdFromUrl(ctx.request.url);
|
||||||
|
const userId = ctx.state.user.id;
|
||||||
|
let entry = await strapi.entityService.findOne(noteUid, noteId, {
|
||||||
|
populate: ['owners'],
|
||||||
|
});
|
||||||
|
const authorized = entry.owners.some(owner => owner.id === userId)
|
||||||
|
if (authorized) {
|
||||||
|
entry = await strapi.entityService.update(noteUid, noteId, {
|
||||||
|
data: {
|
||||||
|
lastViewed: Date.now()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
entry = await strapi.entityService.findOne(noteUid, noteId, {
|
||||||
|
populate: ['owners'],
|
||||||
|
});
|
||||||
|
return JSON.stringify(entry);
|
||||||
|
} else {
|
||||||
|
ctx.response.status = 403;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Updates note. Removing owners is an illegal operation (400)
|
||||||
|
* @param ctx
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
async update(ctx) {
|
||||||
|
const noteId = getNoteIdFromUrl(ctx.request.url)
|
||||||
|
const userId = ctx.state.user.id;
|
||||||
|
const requestBody = JSON.parse(ctx.request.body);
|
||||||
|
console.log(JSON.stringify(requestBody, null, 2))
|
||||||
|
const entry = await strapi.entityService.findOne(noteUid, noteId, {
|
||||||
|
populate: ['owners'],
|
||||||
|
});
|
||||||
|
const authorized = entry.owners.some(owner => owner.id === userId)
|
||||||
|
let allPreviousOwnersKept = true;
|
||||||
|
if (requestBody.data.hasOwnProperty("owners")) {
|
||||||
|
allPreviousOwnersKept = entry.owners.every(owner => requestBody.data.owners.includes(owner));
|
||||||
|
}
|
||||||
|
console.log({
|
||||||
|
"auth": authorized,
|
||||||
|
"allprev": allPreviousOwnersKept,
|
||||||
|
})
|
||||||
|
if (!authorized) {
|
||||||
|
ctx.response.status = 403;
|
||||||
|
} else if (!allPreviousOwnersKept) {
|
||||||
|
ctx.response.status = 400;
|
||||||
|
}
|
||||||
|
return await strapi.entityService.update(noteUid, noteId, requestBody);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Creates a new note, automatically sets owners to the user making the request and lastViewed
|
||||||
|
* @param ctx
|
||||||
|
* @returns {Promise<ctx>}
|
||||||
|
*/
|
||||||
|
async create(ctx) {
|
||||||
|
const userId = ctx.state.user.id;
|
||||||
|
const requestBody = JSON.parse(ctx.request.body);
|
||||||
|
console.log(requestBody);
|
||||||
|
const response = await strapi.entityService.create(noteUid, {
|
||||||
|
data: {
|
||||||
|
title: requestBody.data.title,
|
||||||
|
content: requestBody.data.content,
|
||||||
|
lastViewed: Date.now(),
|
||||||
|
owners: [userId],
|
||||||
|
publishedAt: Date.now()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Deletes user from note owners. If note has no owners anymore, deletes note.
|
||||||
|
* @param ctx
|
||||||
|
* @returns nothing
|
||||||
|
*/
|
||||||
|
async delete(ctx) {
|
||||||
|
const noteId = getNoteIdFromUrl(ctx.request.url)
|
||||||
|
const userId = ctx.state.user.id;
|
||||||
|
const entry = await strapi.entityService.findOne(noteUid, noteId, {
|
||||||
|
populate: ['owners'],
|
||||||
|
});
|
||||||
|
const ownersCount = entry.owners.length;
|
||||||
|
const authorized = entry.owners.some(owner => owner.id === userId)
|
||||||
|
if (!authorized) {
|
||||||
|
ctx.response.status = 403;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ownersCount === 1) {
|
||||||
|
super.delete(ctx);
|
||||||
|
} else {
|
||||||
|
strapi.entityService.update(noteUid, noteId, {
|
||||||
|
data: {
|
||||||
|
owners: entry.owners.filter(owner => owner.id !== userId)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
ctx.response.status = 200;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
|
||||||
3
backend/strapi/src/api/note/utils.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
function getNoteIdFromUrl(url) {
|
||||||
|
return Number(url.split("/").at(-1));
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
{
|
||||||
|
"kind": "collectionType",
|
||||||
|
"collectionName": "up_users",
|
||||||
|
"info": {
|
||||||
|
"name": "user",
|
||||||
|
"description": "",
|
||||||
|
"singularName": "user",
|
||||||
|
"pluralName": "users",
|
||||||
|
"displayName": "User"
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"draftAndPublish": false,
|
||||||
|
"timestamps": true
|
||||||
|
},
|
||||||
|
"attributes": {
|
||||||
|
"username": {
|
||||||
|
"type": "string",
|
||||||
|
"minLength": 3,
|
||||||
|
"unique": true,
|
||||||
|
"configurable": false,
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"email": {
|
||||||
|
"type": "email",
|
||||||
|
"minLength": 6,
|
||||||
|
"configurable": false,
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"provider": {
|
||||||
|
"type": "string",
|
||||||
|
"configurable": false
|
||||||
|
},
|
||||||
|
"password": {
|
||||||
|
"type": "password",
|
||||||
|
"minLength": 6,
|
||||||
|
"configurable": false,
|
||||||
|
"private": true
|
||||||
|
},
|
||||||
|
"resetPasswordToken": {
|
||||||
|
"type": "string",
|
||||||
|
"configurable": false,
|
||||||
|
"private": true
|
||||||
|
},
|
||||||
|
"confirmationToken": {
|
||||||
|
"type": "string",
|
||||||
|
"configurable": false,
|
||||||
|
"private": true
|
||||||
|
},
|
||||||
|
"confirmed": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"configurable": false
|
||||||
|
},
|
||||||
|
"blocked": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"configurable": false
|
||||||
|
},
|
||||||
|
"role": {
|
||||||
|
"type": "relation",
|
||||||
|
"relation": "manyToOne",
|
||||||
|
"target": "plugin::users-permissions.role",
|
||||||
|
"inversedBy": "users",
|
||||||
|
"configurable": false
|
||||||
|
},
|
||||||
|
"notes": {
|
||||||
|
"type": "relation",
|
||||||
|
"relation": "manyToMany",
|
||||||
|
"target": "api::note.note",
|
||||||
|
"inversedBy": "owners"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ version: "3"
|
||||||
services:
|
services:
|
||||||
strapi:
|
strapi:
|
||||||
container_name: strapi
|
container_name: strapi
|
||||||
build: .
|
build: ./backend/strapi
|
||||||
image: mystrapi:latest
|
image: mystrapi:latest
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
|
@ -17,11 +17,11 @@ services:
|
||||||
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
|
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
|
||||||
NODE_ENV: ${NODE_ENV}
|
NODE_ENV: ${NODE_ENV}
|
||||||
volumes:
|
volumes:
|
||||||
- ./config:/opt/app/config
|
- ./backend/strapi/config:/opt/app/config
|
||||||
- ./src:/opt/app/src
|
- ./backend/strapi/src:/opt/app/src
|
||||||
- ./package.json:/opt/package.json
|
- ./backend/strapi/package.json:/opt/package.json
|
||||||
- ./yarn.lock:/opt/yarn.lock # Replace with package-lock.json if using npm
|
- ./backend/strapi/yarn.lock:/opt/yarn.lock # Replace with package-lock.json if using npm
|
||||||
- ./.env:/opt/app/.env
|
- ./backend/strapi/.env:/opt/app/.env
|
||||||
ports:
|
ports:
|
||||||
- "1337:1337"
|
- "1337:1337"
|
||||||
networks:
|
networks:
|
||||||
|
|
@ -47,10 +47,21 @@ services:
|
||||||
networks:
|
networks:
|
||||||
- strapi
|
- strapi
|
||||||
|
|
||||||
|
svelte:
|
||||||
|
container_name: svelte
|
||||||
|
build: ./frontend/svelte
|
||||||
|
image: svelte:latest
|
||||||
|
|
||||||
|
ports:
|
||||||
|
- "80:5173"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
strapi-data:
|
strapi-data:
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
strapi:
|
strapi:
|
||||||
name: Strapi
|
name: Strapi
|
||||||
driver: bridge
|
driver: bridge
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
3
docs/_config.yml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
remote_theme: pages-themes/leap-day@v0.2.0
|
||||||
|
plugins:
|
||||||
|
- jekyll-remote-theme
|
||||||
4
docs/_data/devs.csv
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
name,github,image
|
||||||
|
Jonas Weissengruber,j-weissen,jowei
|
||||||
|
Stefan Prechtler,s-prechtl,stef
|
||||||
|
David Hain,d-hain,dave
|
||||||
|
BIN
docs/images/dave.jpg
Normal file
|
After Width: | Height: | Size: 151 KiB |
BIN
docs/images/delete.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
docs/images/editor.png
Normal file
|
After Width: | Height: | Size: 57 KiB |
BIN
docs/images/jowei.jpg
Normal file
|
After Width: | Height: | Size: 182 KiB |
BIN
docs/images/listing.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
docs/images/login.png
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
docs/images/register.png
Normal file
|
After Width: | Height: | Size: 58 KiB |
BIN
docs/images/stef.jpg
Normal file
|
After Width: | Height: | Size: 134 KiB |
31
docs/index.md
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
# Pomelo Note
|
||||||
|
|
||||||
|
This is the best open source note app you will ever find.
|
||||||
|
|
||||||
|
## Login
|
||||||
|
When first entering the app, you will need to login. If you haven't got an account you may consider [registering](#register), or just not using the app at all.
|
||||||
|
<br /><img src="images/login.png" width="50%" style="margin: auto; display: block;" />
|
||||||
|
|
||||||
|
## Register
|
||||||
|
A username, an email and a password that's all you need. If you are missing one of those, just don't use the app at all.
|
||||||
|
<br /><img src="images/register.png" width="50%" style="margin: auto; display: block;" />
|
||||||
|
|
||||||
|
## Editor
|
||||||
|
You can edit your notes with our minimalistic editor interface.
|
||||||
|
<br /><img src="images/editor.png" width="50%" style="margin: auto; display: block;" />
|
||||||
|
|
||||||
|
## Listing
|
||||||
|
Here you can see all your notes. Click on them to open the editor or hover and press the red "X" to delete them.
|
||||||
|
<br /><img src="images/listing.png" width="50%" style="margin: auto; display: block;" />
|
||||||
|
|
||||||
|
## Delete
|
||||||
|
Confirm the deletion.
|
||||||
|
<br /><img src="images/delete.png" width="50%" style="margin: auto; display: block;" />
|
||||||
|
|
||||||
|
# The Team
|
||||||
|
{% for dev in site.data.devs %}
|
||||||
|
{{ dev.name }}
|
||||||
|
[GitHub](https://github.com/{{ dev.github }})
|
||||||
|

|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
@ -1,13 +1,7 @@
|
||||||
# Creating the svelte project
|
# 🚀 Getting started with Svelte
|
||||||
|
|
||||||
## Create the docker image
|
### Starting the container:
|
||||||
|
``docker-compose up --build -d``
|
||||||
|
|
||||||
``docker build -t svelte .``
|
### Restart and rebuild Svelte:
|
||||||
|
``docker-compose up --detach --build svelte``
|
||||||
## Run the docker container
|
|
||||||
|
|
||||||
``docker run --name svelte -dp 5173:5173 svelte``
|
|
||||||
|
|
||||||
## Mastercommand for rebuild run etc.
|
|
||||||
|
|
||||||
``docker build -t svelte .;docker stop svelte;docker rm svelte; docker run --name svelte -dp 5173:5173 svelte``
|
|
||||||
|
|
|
||||||
9
frontend/svelte/docker-compose.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
svelte:
|
||||||
|
container_name: svelte
|
||||||
|
build: .
|
||||||
|
image: svelte:latest
|
||||||
|
|
||||||
|
ports:
|
||||||
|
- "80:5173"
|
||||||
31
frontend/svelte/package-lock.json
generated
|
|
@ -8,10 +8,10 @@
|
||||||
"name": "svelte_pages",
|
"name": "svelte_pages",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bootstrap-icons": "^1.9.1"
|
"bootstrap-icons": "^1.9.1",
|
||||||
},
|
"nookies": "^2.5.2",
|
||||||
"dependencies": {
|
"sv-popup": "^0.2.5",
|
||||||
"nookies": "^2.5.2"
|
"webworker": "^0.8.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "next",
|
"@sveltejs/adapter-auto": "next",
|
||||||
|
|
@ -2085,6 +2085,11 @@
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/sv-popup": {
|
||||||
|
"version": "0.2.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/sv-popup/-/sv-popup-0.2.5.tgz",
|
||||||
|
"integrity": "sha512-JhBu4piXaauamT4vMEcFCydvxJ8e72G7c9F3caZVAPsiFqWPTYT3JDz99FlR+YCnbOp1emsZqqOPVvCwHgURog=="
|
||||||
|
},
|
||||||
"node_modules/svelte": {
|
"node_modules/svelte": {
|
||||||
"version": "3.50.1",
|
"version": "3.50.1",
|
||||||
"resolved": "https://registry.npmjs.org/svelte/-/svelte-3.50.1.tgz",
|
"resolved": "https://registry.npmjs.org/svelte/-/svelte-3.50.1.tgz",
|
||||||
|
|
@ -2360,6 +2365,14 @@
|
||||||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/webworker": {
|
||||||
|
"version": "0.8.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/webworker/-/webworker-0.8.4.tgz",
|
||||||
|
"integrity": "sha512-zzsVxtHf+mCn0WuYLarSWfRGmX7JiYKkKvso5FYC7rJ9G8svwGQA5a51Sjq9D2c/rKVU6U/kyBcaI7gUTVlsJg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/whatwg-url": {
|
"node_modules/whatwg-url": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
||||||
|
|
@ -3826,6 +3839,11 @@
|
||||||
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
|
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"sv-popup": {
|
||||||
|
"version": "0.2.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/sv-popup/-/sv-popup-0.2.5.tgz",
|
||||||
|
"integrity": "sha512-JhBu4piXaauamT4vMEcFCydvxJ8e72G7c9F3caZVAPsiFqWPTYT3JDz99FlR+YCnbOp1emsZqqOPVvCwHgURog=="
|
||||||
|
},
|
||||||
"svelte": {
|
"svelte": {
|
||||||
"version": "3.50.1",
|
"version": "3.50.1",
|
||||||
"resolved": "https://registry.npmjs.org/svelte/-/svelte-3.50.1.tgz",
|
"resolved": "https://registry.npmjs.org/svelte/-/svelte-3.50.1.tgz",
|
||||||
|
|
@ -3983,6 +4001,11 @@
|
||||||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"webworker": {
|
||||||
|
"version": "0.8.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/webworker/-/webworker-0.8.4.tgz",
|
||||||
|
"integrity": "sha512-zzsVxtHf+mCn0WuYLarSWfRGmX7JiYKkKvso5FYC7rJ9G8svwGQA5a51Sjq9D2c/rKVU6U/kyBcaI7gUTVlsJg=="
|
||||||
|
},
|
||||||
"whatwg-url": {
|
"whatwg-url": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nookies": "^2.5.2"
|
"bootstrap-icons": "^1.9.1",
|
||||||
|
"nookies": "^2.5.2",
|
||||||
|
"sv-popup": "^0.2.5",
|
||||||
|
"webworker": "^0.8.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en" data-theme="emerald">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" href="../src/resources/images/logo2.svg" />
|
<link rel="icon" href="../src/resources/images/logo2.svg" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<link rel="manifest" href="../static/manifest.json">
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>%sveltekit.body%</div>
|
<div>%sveltekit.body%</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
29
frontend/svelte/src/customBootstrap.css
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
|
||||||
|
html,
|
||||||
|
:root {
|
||||||
|
--main-txt-color: black;
|
||||||
|
--cross-txt-color: red;
|
||||||
|
|
||||||
|
--color-primary: #fff494;
|
||||||
|
--color-primary-600: #fff17a;
|
||||||
|
--color-primary-700: #ffec47;
|
||||||
|
--color-primary-800: #ffe714;
|
||||||
|
--color-primary-900: #e0c900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
background-color: var(--color-primary-800) !important;
|
||||||
|
border: var(--color-primary-800) !important;
|
||||||
|
color: var(--main-txt-color) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
background-color: var(--color-primary-900) !important;
|
||||||
|
border: var(--color-primary-900) !important;
|
||||||
|
color: var(--main-txt-color) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:disabled {
|
||||||
|
background-color: var(--color-primary-700) !important;
|
||||||
|
border: var(--color-primary-700) !important;
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
import type {Authentication} from "./authentication";
|
||||||
|
import {createErrorToast} from "./customToasts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capitalises first letter of string.
|
* Capitalises first letter of string.
|
||||||
* @param str
|
* @param str
|
||||||
|
|
@ -18,4 +21,16 @@ export async function bearerFetch(endpoint: string, jwt: string, baseUrl: string
|
||||||
Authorization: `Bearer ${jwt}`
|
Authorization: `Bearer ${jwt}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function handleErrorsFromResponseWithToast(response: Authentication) {
|
||||||
|
if (response.error != null) {
|
||||||
|
if (response.error.details.errors) {
|
||||||
|
for (const error of response.error.details.errors) {
|
||||||
|
createErrorToast(error.message);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
createErrorToast(response.error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type {User} from "../../../models/user";
|
import type {User} from "./user";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User Login Auth.
|
* User Login Auth.
|
||||||
10
frontend/svelte/src/models/repos/note/NoteRepository.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
import type {Note} from "../../types";
|
||||||
|
|
||||||
|
export interface NoteRepository {
|
||||||
|
getNotes(): Promise<Note[]>;
|
||||||
|
getNote(id: number): Promise<Note>;
|
||||||
|
getCurrentNote(): Promise<Note | void>;
|
||||||
|
updateNote(id: number, note: Partial<Note>): Promise<Note>;
|
||||||
|
deleteNote(id: number): void;
|
||||||
|
createNote(note: Partial<Note> & Pick<Note, 'title'>): Promise<Note>;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
import type {Note} from "../../types";
|
||||||
|
import {parseCookies} from "nookies";
|
||||||
|
import type {NoteRepository} from "./NoteRepository";
|
||||||
|
import {currentNoteId} from "../../../stores";
|
||||||
|
|
||||||
|
|
||||||
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE'
|
||||||
|
|
||||||
|
export class StrapiNoteRepository implements NoteRepository {
|
||||||
|
private static instance: StrapiNoteRepository;
|
||||||
|
public static getInstance(): StrapiNoteRepository {
|
||||||
|
if (this.instance === undefined || this.instance === null) {
|
||||||
|
this.instance = new StrapiNoteRepository();
|
||||||
|
}
|
||||||
|
return this.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
currentNoteId.subscribe((value) => (this._currentNoteId = value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private _currentNoteId: unknown;
|
||||||
|
private static apiNoteEndpoint: string = "http://localhost:1337/api/notes"
|
||||||
|
|
||||||
|
public set currentNoteId(value: number | undefined) {
|
||||||
|
currentNoteId.set(value || -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get currentNoteId(): number {
|
||||||
|
return <number>this._currentNoteId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getNotes(): Promise<Note[]>{
|
||||||
|
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/", 'GET');
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getNote(id: number): Promise<Note>{
|
||||||
|
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/" + id, 'GET');
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getCurrentNote(): Promise<Note | void> {
|
||||||
|
if (this._currentNoteId === null || this._currentNoteId === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return await this.getNote(this.currentNoteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateNote(id: number, note: Partial<Note>): Promise<Note> {
|
||||||
|
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/" + id, 'PUT', note);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async createNote(note: Partial<Note> & Pick<Note, 'title'>): Promise<Note> {
|
||||||
|
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/", 'POST', note);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteNote(id: number): Promise<void> {
|
||||||
|
await StrapiNoteRepository.fetchStrapiNoteEndpoint("/" + id, 'DELETE');
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async fetchStrapiNoteEndpoint(path: string, method: HttpMethod, body: Partial<Note> | null = null): Promise<Response> {
|
||||||
|
let requestInit: RequestInit = {
|
||||||
|
method: method,
|
||||||
|
headers: {
|
||||||
|
authorization: StrapiNoteRepository.getAuthorizationHeader()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (body) {
|
||||||
|
requestInit["body"] = JSON.stringify({data: body});
|
||||||
|
}
|
||||||
|
return await fetch(StrapiNoteRepository.apiNoteEndpoint + path, requestInit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static mockedGetAuthorizationHeader() {
|
||||||
|
return "bearer TOKEN"
|
||||||
|
}
|
||||||
|
|
||||||
|
static getAuthorizationHeader() {
|
||||||
|
// @ts-ignore
|
||||||
|
const jwt = parseCookies('/').jwt;
|
||||||
|
return `bearer ${jwt}`
|
||||||
|
}
|
||||||
|
}
|
||||||
93
frontend/svelte/src/models/repos/user/StrapiUserRepo.ts
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
import type {UserRepository} from "./UserRepository";
|
||||||
|
import type {Authentication} from "../../authentication";
|
||||||
|
import type {HttpMethod} from "@sveltejs/kit/types/private";
|
||||||
|
import {StrapiNoteRepository} from "../note/StrapiNoteRepository";
|
||||||
|
import {error} from "@sveltejs/kit";
|
||||||
|
import {User} from "../../user";
|
||||||
|
|
||||||
|
export class StrapiUserRepo implements UserRepository {
|
||||||
|
private static instance: StrapiUserRepo;
|
||||||
|
|
||||||
|
public static getInstance(verification: boolean = true): StrapiUserRepo {
|
||||||
|
if (this.instance === undefined || this.instance === null) {
|
||||||
|
this.instance = new StrapiUserRepo();
|
||||||
|
this.instance.verify().then(() => {
|
||||||
|
if (verification && !this.instance.verified) {
|
||||||
|
window.location.href = "/login";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return this.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private verified: boolean = false;
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static api: string = "http://localhost:1337/api"
|
||||||
|
|
||||||
|
private static apiUserEndpoint: string = StrapiUserRepo.api + "/auth/local"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies the current users jwt.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private async verify() {
|
||||||
|
this.verified = false;
|
||||||
|
let result = await this.getMe();
|
||||||
|
if (!result.error) {
|
||||||
|
this.verified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getMe(): Promise<Authentication> {
|
||||||
|
const response = await StrapiUserRepo.fetchStrapi("/me", "GET", null, true, "/users")
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async registerUser(email: string, username: string, password: string): Promise<Authentication> {
|
||||||
|
const payload = {
|
||||||
|
email: email,
|
||||||
|
password: password,
|
||||||
|
username: username
|
||||||
|
};
|
||||||
|
const response = await StrapiUserRepo.fetchStrapi("/register", "POST", payload, false);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async loginUser(identifier: string, password: string): Promise<Authentication> {
|
||||||
|
const payload = {
|
||||||
|
identifier: identifier,
|
||||||
|
password: password
|
||||||
|
};
|
||||||
|
const response = await StrapiUserRepo.fetchStrapi("/", "POST", payload, false);
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async fetchStrapi(path: string, method: HttpMethod, body: any | null = null, authorization: boolean = true, customPath: any = null): Promise<Response> {
|
||||||
|
let requestInit: RequestInit = {
|
||||||
|
method: method,
|
||||||
|
};
|
||||||
|
if (authorization && body) {
|
||||||
|
requestInit["headers"] = {
|
||||||
|
authorization: StrapiNoteRepository.getAuthorizationHeader() ?? '',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
} else if (authorization) {
|
||||||
|
requestInit["headers"] = {
|
||||||
|
authorization: StrapiNoteRepository.getAuthorizationHeader() ?? '',
|
||||||
|
}
|
||||||
|
} else if (body) {
|
||||||
|
requestInit["headers"] = {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (body) {
|
||||||
|
requestInit["body"] = JSON.stringify(body)
|
||||||
|
}
|
||||||
|
return await fetch((customPath) ? (this.api + customPath + path) : StrapiUserRepo.apiUserEndpoint + path, requestInit);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
frontend/svelte/src/models/repos/user/UserRepository.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import type {Authentication} from "../../authentication";
|
||||||
|
|
||||||
|
export interface UserRepository {
|
||||||
|
/**
|
||||||
|
* Registers a new user.
|
||||||
|
* @param email
|
||||||
|
* @param username
|
||||||
|
* @param password
|
||||||
|
*/
|
||||||
|
registerUser(email: string, username: string, password: string): Promise<Authentication>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current user.
|
||||||
|
* @param jwt
|
||||||
|
*/
|
||||||
|
getMe(jwt: string): Promise<Authentication>;
|
||||||
|
|
||||||
|
loginUser(identifier: string, password: string): Promise<Authentication>;
|
||||||
|
}
|
||||||
|
|
@ -2,5 +2,5 @@ export interface Note {
|
||||||
id: number;
|
id: number;
|
||||||
title: string;
|
title: string;
|
||||||
content: string;
|
content: string;
|
||||||
lastOpened: string;
|
lastViewed: Date;
|
||||||
}
|
}
|
||||||
BIN
frontend/svelte/src/resources/icons/android-icon-144x144.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
frontend/svelte/src/resources/icons/android-icon-192x192.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
frontend/svelte/src/resources/icons/android-icon-36x36.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
frontend/svelte/src/resources/icons/android-icon-48x48.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
frontend/svelte/src/resources/icons/android-icon-72x72.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
frontend/svelte/src/resources/icons/android-icon-96x96.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
|
|
@ -1 +0,0 @@
|
||||||
export const ssr = false;
|
|
||||||
|
|
@ -1,118 +1,48 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {Note} from "../types";
|
import type {Note} from "../models/types";
|
||||||
import {onMount} from "svelte";
|
import {onMount} from "svelte";
|
||||||
import {parseCookies} from "nookies";
|
import {StrapiNoteRepository} from "../models/repos/note/StrapiNoteRepository";
|
||||||
import {bearerFetch} from "../models/PomeloUtils";
|
import {StrapiUserRepo} from "../models/repos/user/StrapiUserRepo";
|
||||||
import {User} from "../models/user";
|
import {Content, Modal, Trigger} from "sv-popup";
|
||||||
|
|
||||||
let user: User;
|
|
||||||
|
|
||||||
|
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
||||||
|
const noteRepo: StrapiNoteRepository = StrapiNoteRepository.getInstance();
|
||||||
|
let notes: Note[];
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const jwt = parseCookies("/").jwt;
|
StrapiUserRepo.getInstance();
|
||||||
let invalid = !jwt;
|
notes = await noteRepo.getNotes();
|
||||||
|
notes.forEach(note => {
|
||||||
if (!invalid) {
|
note.lastViewed = new Date(note.lastViewed);
|
||||||
const request = await bearerFetch("/users/me", jwt);
|
});
|
||||||
const response = await request.json();
|
|
||||||
|
|
||||||
if ('error' in response){
|
|
||||||
invalid = true;
|
|
||||||
} else {
|
|
||||||
user = new User(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (invalid) {
|
|
||||||
window.location = "/login";
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: TEMP!!!
|
|
||||||
const tempJson = "[{\"id\":0,\"title\":\"samc\",\"content\":\"SAAAAAAAAAAMC\",\"lastOpened\":\"2022-09-25T10:45:49.903Z\"},{\"id\":1,\"title\":\"Push\",\"content\":\"Kollege Pusch\",\"lastOpened\":\"2022-09-25T10:50:49.903Z\"},{\"id\":2,\"title\":\"Mike\",\"content\":\"C Meister\",\"lastOpened\":\"2022-09-25T10:09:13.903Z\"},{\"id\":3,\"title\":\"kekw\",\"content\":\"OMEGALUL\",\"lastOpened\":\"2022-09-25T12:03:49.903Z\"}]";
|
|
||||||
//TODO: TEMP!!!
|
|
||||||
|
|
||||||
let notes: Note[] = JSON.parse(tempJson);
|
|
||||||
sortNotesByDate();
|
|
||||||
window.localStorage.setItem("notes", JSON.stringify(notes));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reloads the Notes Listing
|
* Adds a Note with the title "New Note" and redirects to editor
|
||||||
* (by doing something very intelligent)
|
|
||||||
*/
|
*/
|
||||||
function reloadNotesListing() {
|
async function addNoteHandler() {
|
||||||
notes = notes.filter(i => i === i);
|
const newTitle = "New Note";
|
||||||
|
const newNote = await addNote(newTitle);
|
||||||
|
noteRepo.currentNoteId = newNote.id;
|
||||||
|
window.location = "/editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the "notes" Array by the lastOpened Property of a Note
|
* Adds a new note to the Database
|
||||||
*/
|
|
||||||
function sortNotesByDate() {
|
|
||||||
notes.sort(function (x, y) {
|
|
||||||
if (x.lastOpened > y.lastOpened) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x.lastOpened < y.lastOpened) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gives the user a prompt to input the new title of the note and creates it if the title is valid
|
|
||||||
*/
|
|
||||||
function addNotePrompt() {
|
|
||||||
let newTitle = prompt('Name of the new Note');
|
|
||||||
console.log(notes)
|
|
||||||
if (newTitle != null && newTitle != '') {
|
|
||||||
addNote(newTitle);
|
|
||||||
console.log(notes)
|
|
||||||
sortNotesByDate();
|
|
||||||
reloadNotesListing();
|
|
||||||
window.localStorage.setItem("notes", JSON.stringify(notes));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a new note to the "notes" Array with:
|
|
||||||
* * the latest id + 1 (or 0 if no notes exist)
|
|
||||||
* * no content
|
|
||||||
* @param title The title of the new Note
|
* @param title The title of the new Note
|
||||||
|
* @return The created Note Object
|
||||||
*/
|
*/
|
||||||
function addNote(title: string) {
|
async function addNote(title: string): Promise<Note> {
|
||||||
let date = new Date();
|
return await noteRepo.createNote({title: title,});
|
||||||
let newNoteId = (notes.length == 0) ? 0 : notes[notes.length - 1].id + 1
|
|
||||||
let note: Note = {
|
|
||||||
id: newNoteId,
|
|
||||||
title: title,
|
|
||||||
content: "",
|
|
||||||
lastOpened: date.toISOString()
|
|
||||||
};
|
|
||||||
notes.push(note);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives the user a prompt if they are sure to delete this note and deletes it if they confirm
|
* Deletes the note from the "notes" Array and the database
|
||||||
* @param note The note to be removed
|
* @param note The note to be deleted
|
||||||
*/
|
*/
|
||||||
function removeNotePrompt(note) {
|
function deleteNote(note) {
|
||||||
const reallyDelete = confirm("Do you really want to delete this Note?");
|
|
||||||
if (reallyDelete) {
|
|
||||||
removeNote(note);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the note from the "notes" Array
|
|
||||||
* @param note The note to be removed
|
|
||||||
*/
|
|
||||||
function removeNote(note) {
|
|
||||||
notes = notes.filter(i => i !== note);
|
notes = notes.filter(i => i !== note);
|
||||||
|
noteRepo.deleteNote(note.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -132,72 +62,112 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a click on a note list element
|
* Sets the currentNoteId and redirects to the editor
|
||||||
* @param note The note the user clicked on
|
* @param note The note the user clicked on
|
||||||
*/
|
*/
|
||||||
function onNoteLiClick(note) {
|
function onNoteLiClick(note) {
|
||||||
window.localStorage.setItem("clickedNoteId", note.id);
|
noteRepo.currentNoteId = note.id;
|
||||||
window.location = "/editor";
|
window.location = "/editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the modal (popup for deletion)
|
||||||
|
*/
|
||||||
|
async function closeModal() {
|
||||||
|
closeModalBool = true;
|
||||||
|
await sleep(1);
|
||||||
|
closeModalBool = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let closeModalBool = false;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta content="width=device-width, initial-scale=1" name="viewport">
|
||||||
<title>PomeloNote | Home</title>
|
<title>PomeloNote | Home</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css" rel="stylesheet">
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet"
|
<link crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css"
|
||||||
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="row">
|
<div class="container">
|
||||||
<!-- Add Note Button -->
|
|
||||||
<div class="offset-md-7 col-md-1">
|
<div class="row">
|
||||||
<button class="btn btn-primary" on:click={() => addNotePrompt()}>Add Note</button>
|
<!-- Add Note Button -->
|
||||||
|
<div class="offset-md-7 col-md-1">
|
||||||
|
<button class="btn btn-primary" on:click={() => addNoteHandler()}>Add Note</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="offset-md-4 col-md-4">
|
<div class="row">
|
||||||
<!-- Notes listing -->
|
<div class="offset-md-4 col-md-4">
|
||||||
<ul>
|
{#if notes}
|
||||||
{#each notes as note}
|
<!-- Notes listing -->
|
||||||
<li on:mouseover={() => handleMouseOverLi(note.id)}
|
<ul>
|
||||||
on:mouseout={() => handleMouseOutLi(note.id)}>
|
{#each notes as note}
|
||||||
<div class="row">
|
<li on:mouseover={() => handleMouseOverLi(note.id)}
|
||||||
<div class="col-md-10" on:click={() => onNoteLiClick(note)}>
|
on:mouseout={() => handleMouseOutLi(note.id)}>
|
||||||
<span>
|
<div class="row">
|
||||||
{note.title} <br/>
|
<div class="col-10" on:click={() => onNoteLiClick(note)}>
|
||||||
{note.lastOpened}
|
<div>
|
||||||
</span>
|
{note.title}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-1">
|
<div class="list-date-text">
|
||||||
<button style="display: none" id={"noteButton" + note.id}
|
{note.lastViewed.toLocaleDateString()}
|
||||||
on:click={() => removeNotePrompt(note)}>
|
</div>
|
||||||
<i class="bi bi-x"></i>
|
</div>
|
||||||
</button>
|
|
||||||
</div>
|
<div class="col-1">
|
||||||
</div>
|
<!-- Delete Note Popup -->
|
||||||
</li>
|
<Modal basic small={true} button={false} close={closeModalBool}>
|
||||||
{/each}
|
<Content>
|
||||||
</ul>
|
<div class="row" style="margin-bottom: 10px;">
|
||||||
|
<h5>Do you really want to delete the "{note.title}" note?</h5>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4 offset-2">
|
||||||
|
<button class="btn btn-primary"
|
||||||
|
on:click={() => deleteNote(note)}
|
||||||
|
on:click={() => closeModal()}>
|
||||||
|
<b>Yes</b>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="col-4 offset-2">
|
||||||
|
<button class="btn btn-primary" autofocus
|
||||||
|
on:click={() => closeModal()}>
|
||||||
|
<b>No</b>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Content>
|
||||||
|
<Trigger>
|
||||||
|
<button style="display: none" id={"noteButton" + note.id}>
|
||||||
|
<i class="bi bi-x"></i>
|
||||||
|
</button>
|
||||||
|
</Trigger>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@import "../customBootstrap.css";
|
||||||
|
|
||||||
html,
|
html,
|
||||||
:root {
|
:root {
|
||||||
--main-txt-color: black;
|
--sub-txt-color: gray;
|
||||||
--cross-txt-color: red;
|
|
||||||
|
|
||||||
--color-primary: #fff494;
|
|
||||||
--color-primary-600: #fff17a;
|
|
||||||
--color-primary-700: #ffec47;
|
|
||||||
--color-primary-800: #ffe714;
|
|
||||||
--color-primary-900: #e0c900;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
|
@ -207,19 +177,23 @@
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
|
||||||
color: var(--main-txt-color);
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
li {
|
li {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
padding: 6px 10px;
|
padding: 6px 10px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
margin-top: 5px;
|
||||||
border-bottom: 1px solid #ddd;
|
border-bottom: 1px solid #ddd;
|
||||||
|
border-top: 1px solid #ddd;
|
||||||
|
border-radius: 10px;
|
||||||
border-bottom-color: var(--color-primary-900);
|
border-bottom-color: var(--color-primary-900);
|
||||||
|
border-top-color: var(--color-primary-900);
|
||||||
background-color: var(--color-primary-600);
|
background-color: var(--color-primary-600);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
li:hover {
|
||||||
|
background-color: var(--color-primary-700);
|
||||||
|
}
|
||||||
|
|
||||||
li button {
|
li button {
|
||||||
float: right;
|
float: right;
|
||||||
border: none;
|
border: none;
|
||||||
|
|
@ -228,10 +202,11 @@
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
transform: scale(1.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
li button:hover {
|
li button:hover {
|
||||||
transform: scale(1.7);
|
transform: scale(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
li:last-child {
|
li:last-child {
|
||||||
|
|
@ -246,15 +221,8 @@
|
||||||
color: var(--cross-txt-color);
|
color: var(--cross-txt-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-primary {
|
.list-date-text {
|
||||||
background-color: var(--color-primary-800);
|
color: var(--sub-txt-color);
|
||||||
border: var(--color-primary-800);
|
font-size: 0.8314159265358979323846264338rem;
|
||||||
color: var(--main-txt-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-primary:hover {
|
|
||||||
background-color: var(--color-primary-900);
|
|
||||||
border: var(--color-primary-900);
|
|
||||||
color: var(--main-txt-color);
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
6
frontend/svelte/src/routes/+page.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
import {StrapiUserRepo} from "../models/repos/user/StrapiUserRepo";
|
||||||
|
|
||||||
|
/** @type {import('./$types').PageLoad} */
|
||||||
|
export async function load() {
|
||||||
|
// StrapiUserRepo.getInstance();
|
||||||
|
}
|
||||||
|
|
@ -1,24 +1,81 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {Note} from "../../types";
|
import type {Note} from "../../models/types";
|
||||||
|
import {StrapiNoteRepository} from "../../models/repos/note/StrapiNoteRepository";
|
||||||
|
import {onMount} from "svelte";
|
||||||
|
|
||||||
let notes: Note[] = JSON.parse(window.localStorage.getItem("notes"));
|
let noteRepo: StrapiNoteRepository;
|
||||||
const clickedNoteId = window.localStorage.getItem("clickedNoteId");
|
let currentNote: Note;
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
noteRepo = StrapiNoteRepository.getInstance();
|
||||||
|
try {
|
||||||
|
currentNote = await noteRepo.getNote(noteRepo.currentNoteId);
|
||||||
|
} catch {
|
||||||
|
returnToListing();
|
||||||
|
}
|
||||||
|
title = (<Note>currentNote).title;
|
||||||
|
content = (<Note>currentNote).content;
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saves the currently opened Note and returns to listing
|
||||||
|
*/
|
||||||
|
function saveAndQuit() {
|
||||||
|
noteRepo.updateNote(currentNote.id, {
|
||||||
|
"title": title,
|
||||||
|
"content": content,
|
||||||
|
})
|
||||||
|
returnToListing();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redirects to listing
|
||||||
|
*/
|
||||||
|
function returnToListing() {
|
||||||
|
window.location = "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
export let title: string, content: string;
|
||||||
|
|
||||||
const currNote = notes.find((note)=>{
|
|
||||||
return note.id === parseInt(clickedNoteId);
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>{"Pomelonote | Edit " + currNote.title}</title>
|
<title>Editor</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet"
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||||
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<div class="offset-3 col-6">
|
<div class="offset-3 col-6 wrapper">
|
||||||
{currNote.content}
|
<h1 class="">{title === "" ? "" : title}</h1>
|
||||||
|
<input bind:value={title} class="input"> <br/>
|
||||||
|
<textarea bind:value={content} class="input textarea"></textarea>
|
||||||
|
<div class="button-container">
|
||||||
|
<button on:click={() => saveAndQuit()} class="btn btn-primary">Save</button>
|
||||||
|
<button on:click={() => returnToListing()} class="btn btn-outline-danger">Cancel</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
@import "../../customBootstrap.css";
|
||||||
|
|
||||||
|
.wrapper {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-container {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.textarea {
|
||||||
|
height: 300px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {setCookie} from "nookies";
|
import {setCookie} from "nookies";
|
||||||
import type {Authentication} from "./models/authentication";
|
import {SvelteToast} from '@zerodevx/svelte-toast'
|
||||||
import { SvelteToast } from '@zerodevx/svelte-toast'
|
|
||||||
import {createErrorToast} from "../../models/customToasts";
|
|
||||||
import logo from "../../resources/images/logo2.svg";
|
import logo from "../../resources/images/logo2.svg";
|
||||||
|
import {handleErrorsFromResponseWithToast} from "../../models/PomeloUtils";
|
||||||
|
import {StrapiUserRepo} from "../../models/repos/user/StrapiUserRepo";
|
||||||
|
|
||||||
let user: string;
|
let user: string;
|
||||||
let password: string;
|
let password: string;
|
||||||
|
|
@ -14,39 +14,20 @@
|
||||||
* Handles the button click.
|
* Handles the button click.
|
||||||
*/
|
*/
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
const endpoint = "http://localhost:1337/api/auth/local";
|
const userRepo: StrapiUserRepo = StrapiUserRepo.getInstance(false);
|
||||||
const payload = {
|
|
||||||
identifier: user,
|
|
||||||
password: password
|
|
||||||
};
|
|
||||||
|
|
||||||
const login = await fetch(endpoint, {
|
const response = await userRepo.loginUser(user, password);
|
||||||
method: 'post',
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json',
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(payload)
|
|
||||||
})
|
|
||||||
|
|
||||||
const response: Authentication = await login.json();
|
if (response.error != null) {
|
||||||
|
handleErrorsFromResponseWithToast(response);
|
||||||
if (response.error != null){
|
|
||||||
if (response.error.details.errors){
|
|
||||||
for (const error of response.error.details.errors) {
|
|
||||||
createErrorToast(error.message);
|
|
||||||
}
|
|
||||||
} else{
|
|
||||||
createErrorToast(response.error.message);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (rememberMe) {
|
if (rememberMe) {
|
||||||
setCookie(null, 'jwt', response.jwt, {
|
setCookie(null, 'jwt', response.jwt, {
|
||||||
maxAge: 30 * 24 * 60 * 60,
|
maxAge: 30 * 24 * 60 * 60,
|
||||||
path: '/'
|
path: '/'
|
||||||
})
|
})
|
||||||
window.location = "/";
|
|
||||||
}
|
}
|
||||||
|
window.location = "/";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,33 +37,34 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta content="width=device-width, initial-scale=1" name="viewport">
|
||||||
<title>PomeloNote | Login</title>
|
<title>PomeloNote | Login</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet"
|
<link crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css"
|
||||||
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<main class="form-signin w-100 m-auto">
|
<main class="form-signin w-100 m-auto">
|
||||||
|
|
||||||
<img class="img-fluid" src="{logo}" alt="Logo">
|
<img alt="Logo" class="img-fluid" src="{logo}">
|
||||||
<h1 class="h3 mb-3 fw-normal">Please sign in</h1>
|
<h1 class="h3 mb-3 fw-normal">Please sign in</h1>
|
||||||
|
|
||||||
<div class="form-floating">
|
<div class="form-floating">
|
||||||
<input type="email" class="form-control" id="floatingInput" placeholder="name@example.com" bind:value={user}>
|
<input bind:value={user} class="form-control" id="floatingInput" placeholder="name@example.com" type="text">
|
||||||
<label for="floatingInput">Email address</label>
|
<label for="floatingInput">Email address or username</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-floating">
|
<div class="form-floating">
|
||||||
<input type="password" class="form-control" id="floatingPassword" placeholder="Password" bind:value={password}>
|
<input bind:value={password} class="form-control" id="floatingPassword" placeholder="Password" type="password">
|
||||||
<label for="floatingPassword">Password</label>
|
<label for="floatingPassword">Password</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="checkbox mb-3">
|
<div class="checkbox mb-3">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" value="rememberMe" bind:checked={rememberMe}> Remember me
|
<input bind:checked={rememberMe} type="checkbox" value="rememberMe"> Remember me
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<button class="w-100 btn btn-lg btn-primary" on:click={handleSubmit}>Sign in</button>
|
<button class="w-100 btn btn-lg btn-primary" on:click={handleSubmit}>Sign in</button>
|
||||||
|
<a class="opacity-75 d-flex justify-content-center text-center fs-6" href="/register">No user yet? Register.</a>
|
||||||
<p class="mt-5 mb-3 text-muted">©2022</p>
|
<p class="mt-5 mb-3 text-muted">©2022</p>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
|
@ -90,42 +72,7 @@
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
html,
|
@import "../../userInput.css";
|
||||||
body {
|
@import "../../customBootstrap.css";
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
align-items: center;
|
|
||||||
padding-top: 40px;
|
|
||||||
padding-bottom: 40px;
|
|
||||||
background-color: #f5f5f5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-signin {
|
|
||||||
max-width: 330px;
|
|
||||||
padding: 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-signin .form-floating:focus-within {
|
|
||||||
z-index: 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-signin input[type="email"] {
|
|
||||||
margin-bottom: -1px;
|
|
||||||
border-bottom-right-radius: 0;
|
|
||||||
border-bottom-left-radius: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-signin input[type="password"] {
|
|
||||||
margin-bottom: 10px;
|
|
||||||
border-top-left-radius: 0;
|
|
||||||
border-top-right-radius: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.img-fluid{
|
|
||||||
margin-bottom: 15px;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
73
frontend/svelte/src/routes/register/+page.svelte
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import logo from "../../resources/images/logo2.svg";
|
||||||
|
import {SvelteToast} from "@zerodevx/svelte-toast";
|
||||||
|
import {StrapiUserRepo} from "../../models/repos/user/StrapiUserRepo";
|
||||||
|
import {handleErrorsFromResponseWithToast} from "../../models/PomeloUtils";
|
||||||
|
|
||||||
|
let user: string;
|
||||||
|
let password: string;
|
||||||
|
let email: string;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the button click.
|
||||||
|
*/
|
||||||
|
async function handleSubmit() {
|
||||||
|
const userRepo: StrapiUserRepo = StrapiUserRepo.getInstance(false);
|
||||||
|
|
||||||
|
const response = await userRepo.registerUser(email, user, password);
|
||||||
|
|
||||||
|
if (response.error != null) {
|
||||||
|
handleErrorsFromResponseWithToast(response);
|
||||||
|
} else {
|
||||||
|
window.location = "/login";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<html
|
||||||
|
lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta content="width=device-width, initial-scale=1" name="viewport">
|
||||||
|
<title>PomeloNote | Register</title>
|
||||||
|
<link crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css"
|
||||||
|
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<main class="form-signin w-100 m-auto">
|
||||||
|
|
||||||
|
<img alt="Logo" class="img-fluid" src="{logo}">
|
||||||
|
<h1 class="h3 mb-3 fw-normal">Register a new user</h1>
|
||||||
|
|
||||||
|
<div class="form-floating">
|
||||||
|
<input bind:value={user} class="form-control" id="floatingUsr" placeholder="exampleUsername" type="text">
|
||||||
|
<label for="floatingUsr">Username</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-floating">
|
||||||
|
<input bind:value={email} class="form-control" id="floatingInput" placeholder="name@example.com" type="email">
|
||||||
|
<label for="floatingInput">Email address</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-floating">
|
||||||
|
<input bind:value={password} class="form-control" id="floatingPassword" placeholder="Password" type="password">
|
||||||
|
<label for="floatingPassword">Password</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="w-100 btn btn-lg btn-primary" disabled="{(!user || !email || !password)}" on:click={handleSubmit}>
|
||||||
|
Register user
|
||||||
|
{#if user}: {user} {/if}
|
||||||
|
</button>
|
||||||
|
<a class="opacity-75 d-flex justify-content-center text-center fs-6" href="/login">Already registered? Login.</a>
|
||||||
|
<p class="mt-5 mb-3 text-muted">©2022</p>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
<SvelteToast></SvelteToast>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
@import "../../userInput.css";
|
||||||
|
@import "../../customBootstrap.css";
|
||||||
|
</style>
|
||||||
78
frontend/svelte/src/service-worker.js
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
/// <reference lib="webworker" />
|
||||||
|
|
||||||
|
import { build, files, version } from '$service-worker';
|
||||||
|
|
||||||
|
const worker = ServiceWorkerGlobalScope;
|
||||||
|
// const FILES = cache + version;
|
||||||
|
|
||||||
|
const to_cache = build.concat(files);
|
||||||
|
const staticAssets = new Set(to_cache);
|
||||||
|
|
||||||
|
worker.addEventListener('install', (event) => {
|
||||||
|
event.waitUntil(
|
||||||
|
caches
|
||||||
|
.open(FILES)
|
||||||
|
.then((cache) => cache.addAll(to_cache))
|
||||||
|
.then(() => {
|
||||||
|
worker.skipWaiting();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
worker.addEventListener('activate', (event) => {
|
||||||
|
event.waitUntil(
|
||||||
|
caches.keys().then(async (keys) => {
|
||||||
|
// delete old caches
|
||||||
|
for (const key of keys) {
|
||||||
|
if (key !== FILES) await caches.delete(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
worker.clients.claim();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the asset from the network and store it in the cache.
|
||||||
|
* Fall back to the cache if the user is offline.
|
||||||
|
*/
|
||||||
|
async function fetchAndCache(request) {
|
||||||
|
const cache = await caches.open(offline + version);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(request);
|
||||||
|
cache.put(request, response.clone());
|
||||||
|
return response;
|
||||||
|
} catch (err) {
|
||||||
|
const response = await cache.match(request);
|
||||||
|
if (response) return response;
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
worker.addEventListener('fetch', (event) => {
|
||||||
|
if (event.request.method !== 'GET' || event.request.headers.has('range')) return;
|
||||||
|
|
||||||
|
const url = new URL(event.request.url);
|
||||||
|
|
||||||
|
// don't try to handle e.g. data: URIs
|
||||||
|
const isHttp = url.protocol.startsWith('http');
|
||||||
|
const isDevServerRequest =
|
||||||
|
url.hostname === self.location.hostname && url.port !== self.location.port;
|
||||||
|
const isStaticAsset = url.host === self.location.host && staticAssets.has(url.pathname);
|
||||||
|
const skipBecauseUncached = event.request.cache === 'only-if-cached' && !isStaticAsset;
|
||||||
|
|
||||||
|
if (isHttp && !isDevServerRequest && !skipBecauseUncached) {
|
||||||
|
event.respondWith(
|
||||||
|
(async () => {
|
||||||
|
// always serve static files and bundler-generated assets from cache.
|
||||||
|
// if your application has other URLs with data that will never change,
|
||||||
|
// set this variable to true for them and they will only be fetched once.
|
||||||
|
const cachedAsset = isStaticAsset && (await caches.match(event.request));
|
||||||
|
|
||||||
|
return cachedAsset || fetchAndCache(event.request);
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
7
frontend/svelte/src/stores.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import {writable} from "svelte/store";
|
||||||
|
import {browser} from "$app/environment"
|
||||||
|
export const currentNoteId = writable<number>();
|
||||||
|
if (browser) {
|
||||||
|
currentNoteId.set(Number(localStorage.getItem("currentNoteId") || ""))
|
||||||
|
currentNoteId.subscribe(val => localStorage.setItem("currentNoteId", String(val)));
|
||||||
|
}
|
||||||
41
frontend/svelte/src/userInput.css
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
align-items: center;
|
||||||
|
padding-top: 40px;
|
||||||
|
padding-bottom: 40px;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-signin {
|
||||||
|
max-width: 330px;
|
||||||
|
padding: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-signin .form-floating:focus-within {
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-signin input[type="text"] {
|
||||||
|
margin-bottom: -1px;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-signin input[type="email"] {
|
||||||
|
margin-bottom: -1px;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-signin input[type="password"] {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
border-top-left-radius: 0;
|
||||||
|
border-top-right-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.img-fluid {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
41
frontend/svelte/static/manifest.json
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
"lang": "en",
|
||||||
|
"dir": "/",
|
||||||
|
"name": "Pomelo Note",
|
||||||
|
"short_name": "Pomelo",
|
||||||
|
"description": "Best Note App",
|
||||||
|
"theme_color": "#000",
|
||||||
|
"background_color": "#000",
|
||||||
|
"display": "standalone",
|
||||||
|
"orientation": "portrait",
|
||||||
|
"prefer_related_applications": false,
|
||||||
|
"scope": "/",
|
||||||
|
"start_url": "/",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "../resources/icons/android-icon-36x36.png",
|
||||||
|
"sizes": "36x36",
|
||||||
|
"type": "image\/png",
|
||||||
|
"density": "0.75"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "../resources/icons/android-icon-48x48.png",
|
||||||
|
"sizes": "48x48",
|
||||||
|
"type": "image\/png",
|
||||||
|
"density": "1.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "../resources/icons/android-icon-72x72.png",
|
||||||
|
"sizes": "72x72",
|
||||||
|
"type": "image\/png",
|
||||||
|
"density": "1.5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "../resources/icons/android-icon-96x96.png",
|
||||||
|
"sizes": "96x96",
|
||||||
|
"type": "image\/png",
|
||||||
|
"density": "2.0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"splash_pages": null
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,14 @@ import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
import type { UserConfig } from 'vite';
|
import type { UserConfig } from 'vite';
|
||||||
|
|
||||||
const config: UserConfig = {
|
const config: UserConfig = {
|
||||||
plugins: [sveltekit()]
|
plugins: [sveltekit()],
|
||||||
|
|
||||||
|
server: {
|
||||||
|
fs: {
|
||||||
|
// Allow serving files from one level up to the project root
|
||||||
|
allow: ['..'],
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
|
|
||||||