From c3604f38b21801fb8a3eb7f19e8ea34fb39d4e27 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 12 Feb 2021 22:45:55 -0800 Subject: [PATCH] Add option controls --- redstring/parser.py | 2 +- redstring/server.py | 30 ++++++++++++++++++++++++++++++ redstring/templates/base.jinja | 3 --- redstring/templates/edit.jinja | 14 +++++++++----- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/redstring/parser.py b/redstring/parser.py index 1ccbfed..6891d59 100644 --- a/redstring/parser.py +++ b/redstring/parser.py @@ -80,7 +80,7 @@ class TagOptions: def interlink(self) -> bool: return self.options.get(self._INTERLINK_KEY, False) - @hyperlink.setter + @interlink.setter def interlink(self, value: bool): self.options[self._INTERLINK_KEY] = value diff --git a/redstring/server.py b/redstring/server.py index 116a6de..6258660 100644 --- a/redstring/server.py +++ b/redstring/server.py @@ -91,6 +91,36 @@ def edit(document_id): return redirect(url_for('edit', document_id=document_id)) return abort(400) + elif option := request.args.get('option'): + if tag_name := request.args.get('tag'): + tag = doc.get_tag(tag_name) + if option == 'hyperlink': + tag.options.hyperlink = not tag.options.hyperlink + elif option == 'interlink': + print(tag.options.options) + tag.options.interlink = not tag.options.interlink + elif option == 'private': + tag.options.private = not tag.options.private + else: + return abort(400) + with open(doc_path, 'w') as f: + dump(doc, f) + return redirect(url_for('edit', document_id=document_id)) + elif tab_name := request.args.get('tab'): + tab = doc.get_tab(tab_name) + if option == 'priority': + value = request.args.get('value', 0) + tab.options.priority = value + elif option == 'hide_names': + tab.options.hide_names = not tab.options.hide_names + elif option == 'private': + tab.options.private = not tab.options.private + else: + return abort(400) + with open(doc_path, 'w') as f: + dump(doc, f) + return redirect(url_for('edit', document_id=document_id)) + # Otherwise, return the editor page else: return render_template('edit.jinja', document=doc, index=False) diff --git a/redstring/templates/base.jinja b/redstring/templates/base.jinja index c55243b..66c7e87 100644 --- a/redstring/templates/base.jinja +++ b/redstring/templates/base.jinja @@ -104,9 +104,6 @@ table.page-table a { color: #8af; } - table.page-table a:visited { - color: #88f; - } /* Edit page styling */ input.tag-name { diff --git a/redstring/templates/edit.jinja b/redstring/templates/edit.jinja index 4044693..8d6139b 100644 --- a/redstring/templates/edit.jinja +++ b/redstring/templates/edit.jinja @@ -8,7 +8,6 @@ var newTabCounter = 0; function selectTab(name) { - let tab = document.getElementById("tab-" + name); if (tab) { @@ -71,6 +70,10 @@ window.onload = function () {
{{ tab.name }}
+ +priority: {{ tab.options.priority }} — hide_names: {{ tab.options.hide_names|lower }} — private: {{ tab.options.private|lower }} + + {% for tag in tab.tags %} {%- if tag.name == 'id' -%} @@ -81,15 +84,16 @@ window.onload = function () {
{{ tag.value }}
- - +{%- if tag.name != 'id' -%} + {%- if tag.subtags -%} │ {%- else -%} └ + {%- endif -%} - +hyperlink: {{ tag.options.hyperlink|lower }} — interlink: {{ tag.options.interlink|lower }} — private: {{ tag.options.private|lower }} +{%- endif -%} {% for subtag in tag.subtags %} @@ -112,7 +116,7 @@ window.onload = function () { {% endfor %} -Add tag +add tag