This commit is contained in:
vera 2021-02-03 20:14:48 -08:00
parent 1a35406003
commit e2316d7ac1
7 changed files with 76 additions and 5 deletions

View file

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

View file

@ -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/<node>')
@bp.route('/node/<node>')
def node(node):
@bp.route('/node/<node>/uprank/<user_list>')
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")

View file

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

View file

@ -42,3 +42,4 @@ h2 { font-size: 1.2em; }
.wikilink:after {
content: "]]"
}

View file

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

View file

@ -23,7 +23,7 @@
<h1> Nodes </h1>
{% endif %}
{% for node in nodes %}
<a href="{{node.url}}">{{node.wikilink}}</a> ({{node.size()}})<br />
<a href="{{node.url}}/uprank/foo,bar">{{node.wikilink}}</a> ({{node.size()}})<br />
{% endfor %}
</div>
{% endblock %}

View file

@ -0,0 +1,30 @@
<!--
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
{% extends "base.html" %}
{% block content %}
<div >
{% if header %}
<h1> {{header}} </h1>
{% endif %}
<form method="POST">
Enter comma separated list of users to rank
<input type="text" id="settings-ranking" placeholder="e.g. flancian, vera">
<input type="button" value="Save" class="submit" onclick="processSettings()">
</form>
</div>
{% endblock %}