From 7d1feca66fe521a82ffa6faa776662d27b712c22 Mon Sep 17 00:00:00 2001 From: Andreas <andreasv@fsmpi.rwth-aachen.de> Date: Mon, 29 Jan 2018 21:01:47 +0100 Subject: [PATCH] add changelog to edit tooltip, closes #350 --- edit.py | 8 ++++++++ templates/macros.html | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/edit.py b/edit.py index 33df20b..6a676cd 100644 --- a/edit.py +++ b/edit.py @@ -131,6 +131,14 @@ def getfielddescription(path): desc = '<br>'+desc return desc +@app.template_filter(name='getfieldchangelog') +def getfieldchangelog(path): + p = parseeditpath(path) + changelog = query('SELECT * FROM changelog LEFT JOIN users ON (changelog.who = users.id) WHERE `table` = ? AND `id_value` = ? and `field` = ? ORDER BY `when` DESC LIMIT 5', p['table'], p['id'], p['column']) + for entry in changelog: + entry['path'] = '.'.join([entry['table'], entry['id_value'], entry['field']]) + return changelog + @app.route('/internal/edit', methods=['GET', 'POST']) @mod_required @csrf_protect diff --git a/templates/macros.html b/templates/macros.html index 70fed19..cc0232d 100644 --- a/templates/macros.html +++ b/templates/macros.html @@ -298,7 +298,7 @@ $('#embedcodebtn').popover( {% macro moderator_editor (path,value,reload=false) %} {% if ismod() %} <span class="moderator_editor" data-path="{{path|join('.')}}" data-reload="{{ reload|int }}" > - <a class="moderator_editor_sign btn btn-default" title="{{path|join('.')}}{{ path|join('.')|getfielddescription }}" data-toggle="tooltip" tabindex="0" style="padding: 3px; margin-right: 5px;"> + <a class="moderator_editor_sign btn btn-default" title="{{path|join('.')}}{{ path|join('.')|getfielddescription }}{% for l in path|join('.')|getfieldchangelog %}<br>{% if (l.who != l.who|string) %}{{ l.name }} ({{ l.who }}){% else %}{{ l.who }}{%endif%} <{{ l.when }}>: {{ l.value_new }}{% endfor %}" data-toggle="tooltip" tabindex="0" style="padding: 3px; margin-right: 5px;"> <span class="glyphicon glyphicon-pencil"></span> </a> <span class="moderator_editor_value">{{ value|fixnl|safe }}</span> @@ -310,7 +310,7 @@ $('#embedcodebtn').popover( {% macro moderator_checkbox (path,value) %} {% if ismod() %} - <input title="{{path|join('.')}}{{ path|join('.')|getfielddescription }}" data-toggle="tooltip" type="checkbox" data-path="{{path|join('.')}}" {% if value %} checked {% endif %} onchange="moderator.editor.changeboxclick(this)"/> + <input title="{{path|join('.')}}{{ path|join('.')|getfielddescription }}{% for l in path|join('.')|getfieldchangelog %}<br>{% if (l.who != l.who|string) %}{{ l.name }} ({{ l.who }}){% else %}{{ l.who }}{%endif%} <{{ l.when }}>: {{ l.value_new }}{% endfor %}" data-toggle="tooltip" type="checkbox" data-path="{{path|join('.')}}" {% if value %} checked {% endif %} onchange="moderator.editor.changeboxclick(this)"/> {% endif %} {% endmacro %} -- GitLab