Skip to content

Commit

Permalink
Improved search function for printing, improved printing layout and a…
Browse files Browse the repository at this point in the history
…dded printing options
  • Loading branch information
hgrf committed Dec 6, 2016
1 parent f42783b commit 9d803ba
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 36 deletions.
9 changes: 4 additions & 5 deletions app/printdata/forms.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from flask.ext.wtf import Form
from wtforms import SubmitField
from wtforms.fields.html5 import DateField

from wtforms import SubmitField, StringField

class RequestActionsForm(Form):
datefrom = DateField('From:')
dateto = DateField('To:')
datefrom = StringField('From:')
dateto = StringField('To:')
sample = StringField('Sample:')
submit = SubmitField('Submit')
13 changes: 12 additions & 1 deletion app/printdata/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,16 @@ def overview():
form = RequestActionsForm()
actions = []
if form.validate_on_submit():
actions = Action.query.join(Action.sample).filter(Action.timestamp >= form.datefrom.data, Action.timestamp <= form.dateto.data, Sample.owner == current_user).order_by(Action.sample_id)
try: datefrom = datetime.strptime(form.datefrom.data, "%Y-%m-%d")
except ValueError: datefrom = None
try: dateto = datetime.strptime(form.dateto.data, "%Y-%m-%d")
except ValueError: dateto = None
query = Action.query.join(Action.sample).filter(Sample.owner == current_user)
if datefrom:
query = query.filter(Action.timestamp >= datefrom)
if dateto:
query = query.filter(Action.timestamp <= dateto)
if form.sample.data:
query = query.filter(Sample.name == form.sample.data)
actions = query.order_by(Action.sample_id, Action.ordnum)
return render_template('print.html', form=form, actions=actions)
Binary file added app/static/images/ui-icons_444444_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/images/ui-icons_555555_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/images/ui-icons_777620_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/images/ui-icons_777777_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/images/ui-icons_cc0000_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/images/ui-icons_ffffff_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions app/static/print.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.samplename {
font-size:x-large;
font-weight:bold;
border-bottom:3px solid #000;
}

.actionheader {
font-size:large;
border-bottom:2px solid #000;
}

.actionheader .date {
font-weight:bold;
}

.actionheader .username, .actiontype {
font-style:italic;
}

.actiondesc {
}

#printDestination {
visibility: hidden;
}

@media print {
body * {
visibility: hidden;
}
#printDestination, #printDestination * {
visibility: visible;
}
#printDestination {
position: absolute;
left: 0;
top: 0;
}
}
120 changes: 90 additions & 30 deletions app/templates/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,39 @@

{% block styles %}
{{super()}}
<link rel="stylesheet" href="{{url_for('static', filename='editor.css')}}">
<link rel="stylesheet" href="{{url_for('static', filename='print.css')}}">
{% endblock %}

{% block sidebarnav %}
<div class="col-sm-3 col-md-2 sidebar">
{{ wtf.quick_form(form) }}
<button type="button" class="btn btn-default" onclick="printActionList()">Print</button>
{{ wtf.quick_form(form, id="selectdataform") }}
<div class="checkbox"><label><input type="checkbox" id="chkreduce" onchange="onChkReduce()">Reduce image size</label></div>
<div class="checkbox"><label><input type="checkbox" id="chkshowuser" onchange="onChkShowUser()">Hide user names</label></div>
<div class="checkbox"><label><input type="checkbox" id="chkshowtype" onchange="onChkShowType()">Hide action types</label></div>
<button type="button" class="btn btn-default" id="btnprint">Print</button>
</div>
{% endblock %}

{% block page_content %}
<div id="printArea">
<div class="container-fluid">
<div class="row list-header">
<div class="col-md-2 col-xs-2">Date</div>
<div class="col-md-10 col-xs-10">Description</div>
</div>
{% for action in actions %}
{% if previous_sample != action.sample.id %}
<div class="row list-entry">
<div class="col-md-12 col-xs-12"><strong>Sample {{ action.sample.name }}</strong></div>
</div>
{% endif %}
{% set previous_sample = action.sample.id %}
<div class="row list-entry" id="{{ action.id }}">
<div class="col-md-2 col-xs-2">
<div>{{ action.timestamp }}</div>
<div style="font-style: italic">{{ action.owner.username }}</div>
<div style="display: inline">{{ action.actiontype.name }}</div>
</div>
<div class="col-md-10 col-xs-10">{{ action.description|safe }}</div>
{% for action in actions %}
{% if previous_sample != action.sample.id %}
<div class="samplename">
Sample {{ action.sample.name }}
</div>
{% endif %}
{% set previous_sample = action.sample.id %}
<div>
<div class="actionheader">
<span>
<span class="date">{{ action.timestamp }}</span>
<span class="username">{{ action.owner.username }}</span>
<span class="actiontype">{{ action.actiontype.name }}</span>
</span>
</div>
{% endfor %}
<div class="actiondesc">{{ action.description|safe }}</div>
</div>
{% endfor %}
</div>
{% endblock %}

Expand All @@ -52,15 +51,76 @@
<script async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script>window.MathJax || document.write('<script async src="{{ url_for('static', filename='mathjax/MathJax.js') }}?config=TeX-MML-AM_CHTML">\x3C/script>')</script>
<script>
function printActionList() {
var printContents = document.getElementById("printArea").innerHTML;
var originalContents = document.body.innerHTML;

document.body.innerHTML = printContents;
function onChkReduce() {
var images = document.getElementsByTagName('img');
if(document.getElementById('chkreduce').checked) {
for(var i=0; i < images.length; i++) {
images[i].orgwidth = images[i].style.width;
images[i].orgheight = images[i].style.height;
images[i].style.width = "20%";
images[i].style.height = "auto";
}
} else {
for(var i=0; i < images.length; i++) {
images[i].style.width = images[i].orgwidth;
images[i].style.height = images[i].orgheight;
}
}
}

window.print();
function onChkShowUser() {
var spans = document.getElementsByClassName("username");
if(document.getElementById('chkshowuser').checked) {
for (var i = 0; i < spans.length; i++)
spans[i].style.display = "none";
} else {
for (var i = 0; i < spans.length; i++)
spans[i].style.display = "initial";
}
}

document.body.innerHTML = originalContents;
function onChkShowType() {
var spans = document.getElementsByClassName("actiontype");
if(document.getElementById('chkshowtype').checked) {
for (var i = 0; i < spans.length; i++)
spans[i].style.display = "none";
} else {
for (var i = 0; i < spans.length; i++)
spans[i].style.display = "initial";
}
}
</script>
<script>
(function($) {
$("#sample").autocomplete({
source: function (request, response) {
$.getJSON("/search", {
term: request.term, // in flask, "term" will be the argument to look for using request.args
}, function (data) {
response(data.results); // results from jsonify
});
},
select: function (event, ui) {
event.preventDefault();
$(this).val(ui.item.label);
},
focus: function (event, ui) {
event.preventDefault();
$(this).val(ui.item.label);
}
});

$("#datefrom").attr("autocomplete", "off");
$("#datefrom").datepicker({dateFormat: "yy-mm-dd"});
$("#dateto").attr("autocomplete", "off");
$("#dateto").datepicker({dateFormat: "yy-mm-dd"});


$("#btnprint").click(function(){
$("body").append('<div id="printDestination">'+document.getElementById("printArea").innerHTML+'</div>');
window.print();
$("#printDestination").remove();
});
})(jQuery);
</script>
{% endblock %}
Empty file modified database/.gitignore
100644 → 100755
Empty file.
Empty file modified uploads/.gitignore
100644 → 100755
Empty file.

0 comments on commit 9d803ba

Please sign in to comment.