From e2316d7ac1db28c2339e5ca6bd607df43e82407e Mon Sep 17 00:00:00 2001 From: vera Date: Wed, 3 Feb 2021 20:14:48 -0800 Subject: [PATCH] snapshot --- app/__init__.py | 2 ++ app/agora.py | 23 +++++++++++++++++++---- app/static/css/screen-dark.css | 3 +++ app/static/css/screen.css | 1 + app/static/js/main.js | 20 ++++++++++++++++++++ app/templates/nodes.html | 2 +- app/templates/settings.html | 30 ++++++++++++++++++++++++++++++ 7 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 app/templates/settings.html diff --git a/app/__init__.py b/app/__init__.py index b567149..a532611 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -18,6 +18,7 @@ from flask import Flask from flaskext.markdown import Markdown from markdown.extensions.wikilinks import WikiLinkExtension from . import util +from flask_cors import CORS def wikilink_to_url(label, base, end): label = util.canonical_wikilink(label) @@ -30,6 +31,7 @@ def create_app(test_config=None): app.config.from_mapping( SECRET_KEY='dev', ) + CORS(app) if test_config is None: # load the instance config, if it exists, when not testing diff --git a/app/agora.py b/app/agora.py index b8bdc1a..ccec9e9 100644 --- a/app/agora.py +++ b/app/agora.py @@ -13,13 +13,15 @@ # limitations under the License. import datetime -from flask import Blueprint, url_for, render_template, current_app, Response, redirect, request +import jsons +from flask import Blueprint, url_for, render_template, current_app, Response, redirect, request, jsonify from markupsafe import escape from slugify import slugify, SLUG_OK from . import config from . import db from . import forms from . import util +from flask_cors import CORS bp = Blueprint('agora', __name__) G = db.G @@ -149,12 +151,17 @@ def jump(): # Entities @bp.route('/wikilink/') @bp.route('/node/') -def node(node): - +@bp.route('/node//uprank/') +def node(node,user_list=""): + default_rank = ['agora', 'flancian'] + rank = user_list.split(",") + if len(rank) == 0: + rank = default_rank n = G.node(node) if n.subnodes: # earlier in the list means more highly ranked. - n.subnodes = util.uprank(n.subnodes, users=['agora', 'flancian']) + print("rank", rank) + n.subnodes = util.uprank(n.subnodes, users=rank) permutations = [] # if it's a 404, include permutations. else: @@ -213,6 +220,10 @@ def garden(garden): def nodes(): return render_template('nodes.html', nodes=G.nodes(include_journals=False)) +@bp.route('/nodes.json') +def nodes_json(): + return jsonify(jsons.dump(G.nodes(include_journals=False))) + @bp.route('/notes') # alias @bp.route('/subnodes') def subnodes(): @@ -243,3 +254,7 @@ def raw(subnode): def backlinks(node): # Currently unused. return render_template('nodes.html', nodes=db.nodes_by_outlink(node)) + +@bp.route('/settings') +def settings(): + return render_template('settings.html', header="Settings") diff --git a/app/static/css/screen-dark.css b/app/static/css/screen-dark.css index 6fc09f3..5af21ce 100644 --- a/app/static/css/screen-dark.css +++ b/app/static/css/screen-dark.css @@ -209,3 +209,6 @@ nav { font-family: sans-serif} This totally doesn't work, at all, and I have no idea why :) */ .annotator-frame { margin-top: 4.5em } + + +.submit {display: block; margin-top: 25px} \ No newline at end of file diff --git a/app/static/css/screen.css b/app/static/css/screen.css index a9f56be..18e46c0 100644 --- a/app/static/css/screen.css +++ b/app/static/css/screen.css @@ -42,3 +42,4 @@ h2 { font-size: 1.2em; } .wikilink:after { content: "]]" } + diff --git a/app/static/js/main.js b/app/static/js/main.js index 308ae6a..a65ae6a 100644 --- a/app/static/js/main.js +++ b/app/static/js/main.js @@ -16,6 +16,8 @@ // Adapted from https://css-tricks.com/a-complete-guide-to-dark-mode-on-the-web/#toggling-themes document.addEventListener("DOMContentLoaded", function() { + // Hack for settings page + try { processSettings({ignore: true}) } catch(e){ console.error(e)} // Select button const btn = document.querySelector(".theme-toggle"); var theme = document.querySelector("#theme-link"); @@ -40,3 +42,21 @@ document.addEventListener("DOMContentLoaded", function() { } }); }); + +function processSettings(args){ + args = args || {} + let ranking // string for ranking nodes by user, comma separated user list + ranking = document.getElementById("settings-ranking").value || "" + if (ranking === ""){ + ranking = localStorage["ranking"] || "" + console.log("ranking", ranking) + if (ranking !== ""){ + document.getElementById("settings-ranking").value = ranking + } + } + + ranking = document.getElementById("settings-ranking").value || "" + localStorage["ranking"] = ranking + console.log("processing", ranking) + if (!args["ignore"]) alert("Settings Saved") +} diff --git a/app/templates/nodes.html b/app/templates/nodes.html index 9bca448..b4a4a8d 100644 --- a/app/templates/nodes.html +++ b/app/templates/nodes.html @@ -23,7 +23,7 @@

Nodes

{% endif %} {% for node in nodes %} -{{node.wikilink}} ({{node.size()}})
+{{node.wikilink}} ({{node.size()}})
{% endfor %} {% endblock %} diff --git a/app/templates/settings.html b/app/templates/settings.html new file mode 100644 index 0000000..add0553 --- /dev/null +++ b/app/templates/settings.html @@ -0,0 +1,30 @@ + + +{% extends "base.html" %} +{% block content %} +
+{% if header %} +

{{header}}

+{% endif %} + +
+ Enter comma separated list of users to rank + + +
+
+{% endblock %}