Add option controls

This commit is contained in:
Tim Van Baak 2021-02-12 22:45:55 -08:00
parent 2ddb1281c1
commit c3604f38b2
4 changed files with 40 additions and 9 deletions

View File

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

View File

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

View File

@ -104,9 +104,6 @@
table.page-table a {
color: #8af;
}
table.page-table a:visited {
color: #88f;
}
/* Edit page styling */
input.tag-name {

View File

@ -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 () {
<td><div contenteditable>{{ tab.name }}</div></td>
</tr>
<tr><td></td>
<td><i>priority: <a href="/edit/{{ document.get_tag('id').value }}?tab={{ tab.name }}&option=priority">{{ tab.options.priority }}</a> &mdash; hide_names: <a href="/edit/{{ document.get_tag('id').value }}?tab={{ tab.name }}&option=hide_names">{{ tab.options.hide_names|lower }}</a> &mdash; private: <a href="/edit/{{ document.get_tag('id').value }}?tab={{ tab.name }}&option=private">{{ tab.options.private|lower }}</a></td>
</tr>
{% for tag in tab.tags %}
<tr>
{%- if tag.name == 'id' -%}
@ -81,15 +84,16 @@ window.onload = function () {
<td><div contenteditable>{{ tag.value }}</div></td>
</tr>
<tr>
<td>
{%- if tag.name != 'id' -%}
<tr><td>
{%- if tag.subtags -%}
&#9474;
{%- else -%}
<a href="/edit/{{ document.get_tag('id').value }}?add=subtag&tag={{ tag.name }}">&#9492; +</a>
{%- endif -%}</td>
<td></td>
<td><i>hyperlink: <a href="/edit/{{ document.get_tag('id').value }}?tag={{ tag.name }}&option=hyperlink">{{ tag.options.hyperlink|lower }}</a> &mdash; interlink: <a href="/edit/{{ document.get_tag('id').value }}?tag={{ tag.name }}&option=interlink">{{ tag.options.interlink|lower }}</a> &mdash; private: <a href="/edit/{{ document.get_tag('id').value }}?tag={{ tag.name }}&option=private">{{ tag.options.private|lower }}</a></td>
</tr>
{%- endif -%}
{% for subtag in tag.subtags %}
<tr>
@ -112,7 +116,7 @@ window.onload = function () {
{% endfor %}
<tr>
<td><a href="/edit/{{ document.get_tag('id').value }}?add=tag&tab={{ tab.name }}">Add tag</td>
<td><a href="/edit/{{ document.get_tag('id').value }}?add=tag&tab={{ tab.name }}">add tag</td>
<td></td>
</tr>