From 2ae9df63fd6c6b29c428ade5d6a203e4151ec452 Mon Sep 17 00:00:00 2001 From: Frederic Date: Wed, 14 Mar 2018 23:59:03 +0100 Subject: [PATCH] added (optional) comment field --- journalmarks/journalmarks.py | 17 ++++++ journalmarks/static/journalmarks.js | 7 ++- journalmarks/templates/index.html | 85 +++++++++++++++++++++++++--- journalmarks/templates/overview.html | 12 ++++ 4 files changed, 112 insertions(+), 9 deletions(-) diff --git a/journalmarks/journalmarks.py b/journalmarks/journalmarks.py index 5b5b5fa..720cf89 100644 --- a/journalmarks/journalmarks.py +++ b/journalmarks/journalmarks.py @@ -160,6 +160,23 @@ def create(): return json.dumps(tag) +@journalmarks.route('/update', methods=['POST']) +@login_required +def update(): + if request.json.keys() != {'tag', 'content'}: + return ('invalid fields', 400, None) + tag, content = request.json['tag'], request.json['content'] + try: + j = Journalmark.select().where( + (Journalmark.tag == tag) & (Journalmark.user == flask_g.user) + ).get() + except DoesNotExist: + return ('tag not found', 404, None) + j.content = json.dumps(content) + j.save() + return json.dumps('ok') + + @journalmarks.route('/overview', methods=['GET']) @login_required def overview(): diff --git a/journalmarks/static/journalmarks.js b/journalmarks/static/journalmarks.js index 3c42f19..48e1123 100644 --- a/journalmarks/static/journalmarks.js +++ b/journalmarks/static/journalmarks.js @@ -119,9 +119,12 @@ function journalmarks_initkey(username, password) { } -function journalmarks_encrypturl(url) { +function journalmarks_encrypturl(url, comment) { return new Promise(function(resolve, reject) { - var bytes = enc.encode(JSON.stringify({url: url})); + var content = {url: url}; + if(typeof comment === 'string') + content.comment = comment; + var bytes = enc.encode(JSON.stringify(content)); encrypt(bytes, userkey).then(function(encurl) { resolve(encurl); }).catch(function(error) { diff --git a/journalmarks/templates/index.html b/journalmarks/templates/index.html index 6157fb2..a254bd9 100644 --- a/journalmarks/templates/index.html +++ b/journalmarks/templates/index.html @@ -1,6 +1,8 @@ {% extends "base.html" %} {% block script %} + {% endblock %} {% block body %} -

Welcome!

-

You can now create a new Journalmark by simply pasting a URL into the text field. To access an existing Journalmark, enter its tag code. There's also a listing of all your Journalmarks on the overview page. Finally, you can also logout again. -

+
+

Welcome!

+

You can now create a new Journalmark by simply pasting a URL into the text field. To access an existing Journalmark, enter its tag code. There's also a listing of all your Journalmarks on the overview page. Finally, you can also logout again. +

+ +
+
+ +
+
+ +
+
+
-
- - -
+
+

Journalmark created!

+Yay! You can access your new Journalmark at:
+ +
+ +
+
+ + Should you want to add a descriptive text to be displayed on the overview page, you can do so now: + +
+
+ +
+
+ +
+
+ +

+Continue to welcome page +

+
{% endblock %} diff --git a/journalmarks/templates/overview.html b/journalmarks/templates/overview.html index 101e742..4109c2d 100644 --- a/journalmarks/templates/overview.html +++ b/journalmarks/templates/overview.html @@ -26,6 +26,8 @@ function run() { decrs.push(journalmarks_decrypturl(j.content).then(function(url) { n.getElementsByClassName('url')[0].href = url.url; n.getElementsByClassName('url')[0].innerText = url.url; + if(url.hasOwnProperty('comment')) + n.getElementsByClassName('comment')[0].innerText = url.comment; }).catch(function(error) { console.log(error); n.getElementsByClassName('url')[0].innerText = 'unable to decrypt url'; @@ -54,13 +56,23 @@ else document.attachEvent('onreadystatechange', function(){ padding: 1em; border: 1px solid grey; } +#back-to-welcome { + text-align: center; +} {% endblock %} {% block body %} +

Journalmarks Overview

+ +

+Back to welcome page +

+

Tag:
URL:
+Comment:
Created: