123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <window id="roastspec">
- <layout type="horizontal">
- <layout type="vertical">
- <layout type="horizontal">
- <label>Coffee:</label>
- <sqldrop data="0" display="1" showdata="false" id="currentitems">
- <query>SELECT id, name FROM items WHERE id IN (SELECT item FROM current_items) ORDER BY name</query>
- </sqldrop>
- </layout>
- <layout type="horizontal">
- <label>Expected % weight loss:</label>
- <line validator="numeric" id="expectedloss" />
- </layout>
- <layout type="horizontal">
- <label>Tolerance</label>
- <line validator="numeric" id="tolerance" />
- </layout>
- <label>Specification Notes:</label>
- <textarea id="notes" />
- <layout type="horizontal">
- <stretch />
- <button id="save" type="push" name="Save" />
- </layout>
- </layout>
- <svgwidget id="boxplot" />
- </layout>
- <program>
- <![CDATA[
- var window = this;
- this.windowTitle = TTR("roastspec", "Typica - Edit Roasting Specification");
- var selector = findChildObject(this, 'currentitems');
- var expected = findChildObject(this, 'expectedloss');
- var tolerance = findChildObject(this, 'tolerance');
- var notes = findChildObject(this, 'notes');
- var savebutton = findChildObject(this, 'save');
- var boxplot = findChildObject(this, 'boxplot');
- var updateDisplay = function() {
- var query = new QSqlQuery();
- query.prepare("SELECT loss, tolerance, notes FROM roasting_specification WHERE item = :id1 AND time = (SELECT max(time) FROM roasting_specification WHERE item = :id2)");
- query.bind(":id1", selector.currentData());
- query.bind(":id2", selector.currentData());
- query.exec();
- if(query.next()) {
- if(query.value(0).length > 0) {
- expected.text = Number(query.value(0)) * 100;
- } else {
- expected.text = "";
- }
- if(query.value(1).length > 0) {
- tolerance.text = Number(query.value(1)) * 100;
- } else {
- tolerance.text = "";
- }
- notes.plainText = query.value(2);
- } else {
- expected.text = "";
- tolerance.text = "";
- notes.plainText = "";
- }
- query.prepare("SELECT (unroasted_total_quantity - roasted_quantity)/unroasted_total_quantity AS loss FROM roasting_log WHERE roasted_id = :id1 AND unroasted_id = (SELECT unroasted_id FROM roasting_log WHERE time = (SELECT max(time) FROM roasting_log WHERE roasted_id = :id2) AND roasted_id = :id3) AND approval = true ORDER BY loss ASC");
- query.bind(":id1", selector.currentData());
- query.bind(":id2", selector.currentData());
- query.bind(":id3", selector.currentData());
- query.exec();
- var buffer = new QBuffer;
- buffer.open(3);
- var output = new XmlWriter(buffer);
- output.writeStartDocument("1.0");
- output.writeDTD('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">');
- output.writeStartElement("svg");
- output.writeAttribute("width", "40");
- output.writeAttribute("height", "320");
- output.writeStartElement("g");
- output.writeAttribute("stroke", "black");
- output.writeAttribute("stroke-width", "2");
- output.writeStartElement("line");
- output.writeAttribute("x1", "15");
- output.writeAttribute("x2", "25");
- output.writeAttribute("y1", "278.25");
- output.writeAttribute("y2", "278.26");
- output.writeTextElement("title", "17.71");
- output.writeEndElement();
- output.writeStartElement("line");
- output.writeAttribute("x1", "20");
- output.writeAttribute("x2", "20");
- output.writeAttribute("y1", "278.25");
- output.writeAttribute("y2", "247.5");
- output.writeEndElement();
- output.writeStartElement("line");
- output.writeAttribute("x1", "10");
- output.writeAttribute("x2", "30");
- output.writeAttribute("y1", "247.5");
- output.writeAttribute("y2", "247.5");
- output.writeEndElement();
-
- output.writeEndElement();
- output.writeEndElement();
- output.writeEndDocument();
- boxplot.loadDevice(buffer);
- buffer.close();
- query = query.invalidate();
- };
- updateDisplay();
- selector['currentIndexChanged(int)'].connect(function() {
- updateDisplay();
- });
- savebutton.clicked.connect(function() {
- var query = new QSqlQuery();
- var columnspec = "time, item, ";
- var valuespec = "'now', :id, ";
- if(expected.text.length > 0) {
- columnspec += "loss, ";
- valuespec += ":loss, ";
- }
- if(tolerance.text.length > 0) {
- columnspec += "tolerance, ";
- valuespec += ":tolerance, ";
- }
- columnspec += "notes";
- valuespec += ":notes";
- query.prepare("INSERT INTO roasting_specification (" + columnspec + ") VALUES (" + valuespec + ")");
- query.bind(":id", selector.currentData());
- if(expected.text.length > 0) {
- query.bind(":loss", Number(expected.text) / 100);
- }
- if(tolerance.text.length > 0) {
- query.bind(":tolerance", Number(tolerance.text) / 100);
- }
- query.bind(":notes", notes.plainText);
- query.exec();
- window.close();
- });
- ]]>
- </program>
- </window>
|