Supply different versions to browse

pull/1/head
Leigh Morresi 4 years ago
parent 118814912f
commit 3e934e8f8c

@ -187,18 +187,28 @@ def diff_history_page(uuid):
dates = list(watch['history'].keys()) dates = list(watch['history'].keys())
dates = [int(i) for i in dates] dates = [int(i) for i in dates]
dates.sort(reverse=True) dates.sort(reverse=True)
dates = [str(i) for i in dates]
left_file_contents = right_file_contents = "" left_file_contents = right_file_contents = ""
l_file = watch['history'][str(dates[-1])] l_file = watch['history'][str(dates[-1])]
with open(l_file, 'r') as f: with open(l_file, 'r') as f:
left_file_contents = f.read() left_file_contents = f.read()
previous_version = request.args.get('previous_version')
try:
r_file = watch['history'][str(previous_version)]
except KeyError:
# Not present, use a default value
r_file = watch['history'][str(dates[-2])] r_file = watch['history'][str(dates[-2])]
with open(r_file, 'r') as f: with open(r_file, 'r') as f:
right_file_contents = f.read() right_file_contents = f.read()
#print (dates, l_file, r_file)
output = render_template("diff.html", watch_a=watch, messages=messages, left=left_file_contents, output = render_template("diff.html", watch_a=watch, messages=messages, left=left_file_contents,
right=right_file_contents, extra_stylesheets=extra_stylesheets) right=right_file_contents, extra_stylesheets=extra_stylesheets, versions=dates[:-1],
current_previous_version=str(previous_version))
return output return output
@app.route("/favicon.ico", methods=['GET']) @app.route("/favicon.ico", methods=['GET'])

@ -32,12 +32,17 @@ ins {
} }
#settings { #settings {
background: rgba(0,0,0,.05);
padding: 1em;
line-height: 2em; border-radius: 10px;
margin-bottom: 1em;
color: #fff;
font-size: 80%;
} }
#settings label { #settings label {
margin-left: 1em; margin-left: 1em;
display: inline-block;
font-weight: normal;
} }
.source { .source {
@ -53,7 +58,7 @@ ins {
} }
#diff-ui { #diff-ui {
background: #fff; background: #fff;
padding: 2em; padding: 2em;
margin: 1em; margin: 1em;
border-radius: 5px; border-radius: 5px;

@ -2,17 +2,38 @@
{% block content %} {% block content %}
<div id="diff-ui"> <div id="settings">
<h1>Differences</h1>
<form class="pure-form " action="" method="GET">
<fieldset>
<label for="diffWords" class="pure-checkbox">
<input type="radio" name="diff_type" id="diffWords" value="diffWords" checked=""/> Words</label>
<label for="diffLines" class="pure-checkbox">
<input type="radio" name="diff_type" id="diffLines" value="diffLines"/> Lines</label>
<label for="diffChars" class="pure-checkbox">
<input type="radio" name="diff_type" id="diffChars" value="diffChars"/> Chars</label>
{% if versions|length >= 1 %}
<label for="diff-version">Compare newest with</label>
<select id="diff-version" name="previous_version">
{% for version in versions %}
<option value="{{version}}" {% if version== current_previous_version %} selected="" {% endif %}>
{{version}}
</option>
{% endfor %}
</select>
<button type="submit" class="pure-button pure-button-primary">Go</button>
{% endif %}
</fieldset>
</form>
<del>Removed text</del> <del>Removed text</del>
<ins>Inserted Text</ins> <ins>Inserted Text</ins>
<div id="settings">
<h3>Diff</h3>
<label><input type="radio" name="diff_type" value="diffChars"> Chars</label>
<label><input type="radio" name="diff_type" value="diffWords" > Words</label>
<label><input type="radio" name="diff_type" value="diffLines" checked=""> Lines</label>
</div> </div>
<div id="diff-ui">
<table> <table>
<tbody> <tbody>
<tr> <tr>
@ -20,16 +41,19 @@
<td id="a" style="display: none;">{{left}}</td> <td id="a" style="display: none;">{{left}}</td>
<td id="b" style="display: none;">{{right}}</td> <td id="b" style="display: none;">{{right}}</td>
<td> <td>
<pre id="result"></pre> <span id="result"></span>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
Diff algorithm from the amazing <a href="https://github.com/kpdecker/jsdiff" >github.com/kpdecker/jsdiff</a> Diff algorithm from the amazing <a href="https://github.com/kpdecker/jsdiff">github.com/kpdecker/jsdiff</a>
</div> </div>
<script src="/static/js/diff.js"></script> <script src="/static/js/diff.js"></script>
<script defer=""> <script defer="">
var a = document.getElementById('a'); var a = document.getElementById('a');
var b = document.getElementById('b'); var b = document.getElementById('b');
var result = document.getElementById('result'); var result = document.getElementById('result');
@ -63,6 +87,19 @@ function changed() {
} }
window.onload = function() { window.onload = function() {
/* Convert what is options from UTC time.time() to local browser time */
var diffList=document.getElementById("diff-version");
if (typeof(diffList) != 'undefined' && diffList != null) {
for (var option of diffList.options) {
//alert(option.value);
var dateObject = new Date(option.value*1000);
option.label=dateObject.toLocaleString();
}
}
onDiffTypeChange(document.querySelector('#settings [name="diff_type"]:checked')); onDiffTypeChange(document.querySelector('#settings [name="diff_type"]:checked'));
changed(); changed();
}; };
@ -89,10 +126,11 @@ for (var i = 0; i < radio.length; i++) {
} }
} }
</script>
</script>
{% endblock %} {% endblock %}
Loading…
Cancel
Save