123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- <window id="batchDetails">
- <layout type="vertical">
- <layout type="horizontal">
- <button type="push" id="target" name="Load profile as target" />
- <button type="push" id="viewprofile" name="View profile" />
- <button type="push" id="compare" name="Compare profile" />
- <button type="push" id="edit" name="Edit" />
- </layout>
- <webview id="view" />
- </layout>
- <program>
- <![CDATA[
- var window = this;
- dataView = findChildObject(this, 'view');
- var fileID;
- var target = findChildObject(this, 'target');
- var compare = findChildObject(this, 'compare');
- var edit = findChildObject(this, 'edit');
- edit.enabled = false;
- if(typeof(navigationwindow.loggingWindow) == "undefined") {
- compare.enabled = false;
- target.enabled = false;
- }
- var tableReference;
- var rowReference;
- var batchTime;
- var machine;
- var approval;
- var annotation;
- edit.clicked.connect(function() {
- var editWindow = createWindow("editBatchDetails");
- editWindow.loadData(window, tableReference, rowReference, batchTime, machine, approval, annotation);
- });
- compare.clicked.connect(function() {
- var query = new QSqlQuery;
- query.prepare("SELECT file, name FROM files WHERE id = :id");
- query.bind(":id", Number(fileID));
- query.exec();
- query.next();
- var buffer = new QBuffer(query.value(0));
- var pname = query.value(1);
- query = query.invalidate();
- var startSeries = Number(QSettings.value('cseries', 3));
- var nextSeries = startSeries + 2;
- QSettings.setValue('cseries', nextSeries);
- var input = new XMLInput(buffer, startSeries);
- var graph = findChildObject(navigationwindow.loggingWindow, 'graph');
- input.measure.connect(graph.newMeasurement);
- input.input();
- query = query.invalidate();
- });
- target.clicked.connect(function() {
- var query = new QSqlQuery;
- query.prepare("SELECT file, name FROM files WHERE id = :id");
- query.bind(":id", Number(fileID));
- query.exec();
- query.next();
- var buffer = new QBuffer(query.value(0));
- var pname = query.value(1);
- query = query.invalidate();
- var input = new XMLInput(buffer, 1);
- var graph = findChildObject(navigationwindow.loggingWindow, 'graph');
- var log = findChildObject(navigationwindow.loggingWindow, 'log');
- log.clear();
- graph.clear();
- input.newTemperatureColumn.connect(log.setHeaderData);
- input.newTemperatureColumn.connect(function(col, text) {
- if(text == navigationwindow.loggingWindow.targetcolumnname)
- {
- targetseries = col;
- }
- });
- input.newAnnotationColumn.connect(log.setHeaderData);
- input.measure.connect(graph.newMeasurement);
- input.measure.connect(log.newMeasurement);
- input.measure.connect(function(data, series) {
- if(series == targetseries)
- {
- targetDetector.newMeasurement(data);
- }
- });
- var lc;
- input.lastColumn.connect(function(c) {
- lc = c;
- QSettings.setValue("liveColumn", c + 1);
- navigationwindow.loggingWindow.postLoadColumnSetup(c);
- });
- input.annotation.connect(log.newAnnotation);
- input.annotation.connect(function(note, tcol, ncol) {
- for(var i = tcol; i < ncol; i++) {
- log.newAnnotation(note, i, ncol);
- }
- });
- navigationwindow.loggingWindow.windowTitle = "Typica - " + pname;
- navigationwindow.loggingWindow.raise();
- navigationwindow.loggingWindow.activateWindow();
- input.input();
- log.newAnnotation("End", 1, lc);
- query = query.invalidate();
- });
- var viewbutton = findChildObject(this, 'viewprofile');
- viewbutton.clicked.connect(function() {
- var query = new QSqlQuery;
- query.prepare("SELECT file, name FROM files WHERE id = :id");
- query.bind(":id", Number(fileID));
- query.exec();
- if(query.next()) {
- var viewer = createWindow('offline');
- var buffer = new QBuffer(query.value(0));
- var pname = query.value(1);
- query = query.invalidate();
- var input = new XMLInput(buffer, 1);
- var graph = findChildObject(viewer, 'graph');
- var log = findChildObject(viewer, 'log');
- input.newTemperatureColumn.connect(log.setHeaderData);
- input.newTemperatureColumn.connect(function(column) {
- viewer.saveTemperatureColumns.push(column);
- });
- input.newAnnotationColumn.connect(log.setHeaderData);
- input.newAnnotationColumn.connect(function(column) {
- viewer.saveAnnotationColumns.push(column);
- });
- input.measure.connect(graph.newMeasurement);
- input.measure.connect(log.newMeasurement);
- input.annotation.connect(log.newAnnotation);
- var lc;
- input.lastColumn.connect(function(c) {
- lc = c;
- if(c < 3)
- {
- log.setHeaderData(3, "");
- }
- });
- input.annotation.connect(function(note, tcol, ncol) {
- for(var i = tcol; i < ncol; i++) {
- log.newAnnotation(note, i, ncol);
- }
- });
- viewer.windowTitle = "Typica - " + pname;
- viewer.raise();
- viewer.activateWindow();
- input.input();
- log.newAnnotation("End", 1, lc);
- }
- else {
- print("Query returned no results");
- }
- query = query.invalidate();
- });
- window.loadData = function(table, row) {
- tableReference = table;
- rowReference = row;
- var buffer = new QBuffer;
- buffer.open(3);
- var output = new XmlWriter(buffer);
- output.writeStartDocument("1.0");
- output.writeDTD('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg.dtd">');
- output.writeStartElement("html");
- output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
- output.writeStartElement("head");
- output.writeTextElement("title", "Batch Details");
- output.writeEndElement();
- output.writeStartElement("body");
- output.writeStartElement("div");
- output.writeAttribute("style", "float: left; padding-right: 10px");
- output.writeStartElement("p");
- output.writeTextElement("strong", "Roasted Coffee: ");
- output.writeTextElement("span", table.data(row, 2));
- output.writeEndElement();
- output.writeEndElement();
- output.writeStartElement("div");
- output.writeAttribute("style", "float: left");
- output.writeStartElement("p");
- output.writeTextElement("strong", "Roasted On: ");
- batchTime = table.data(row, 0);
- output.writeTextElement("span", batchTime);
- output.writeEndElement();
- output.writeStartElement("p");
- output.writeTextElement("strong", "Batch Duration: ");
- output.writeTextElement("span", table.data(row, 6));
- output.writeEndElement();
- output.writeEndElement();
- output.writeStartElement("div");
- output.writeAttribute("style", "clear: both");
- output.writeEndElement();
- output.writeStartElement("table");
- output.writeStartElement("thead");
- output.writeStartElement("tr");
- output.writeTextElement("th", "Green Coffee");
- output.writeTextElement("th", "Weight (lb)");
- output.writeEndElement();
- output.writeEndElement();
- output.writeStartElement("tbody");
- var query = new QSqlQuery();
- query.prepare("SELECT unroasted_id, unroasted_quantity, approval, files, annotation FROM roasting_log WHERE time = :time AND machine = :machine");
- query.bind(":time", batchTime);
- machine = table.data(row, 1);
- query.bind(":machine", machine);
- query.exec();
- query.next();
- approval = query.value(2);
- annotation = query.value(4);
- var items = sqlToArray(query.value(0));
- var quantities = sqlToArray(query.value(1));
- var nameQuery = new QSqlQuery();
- nameQuery.prepare("SELECT name FROM items WHERE id = :id");
- for(var i = 0; i < items.length; i++) {
- output.writeStartElement("tr");
- nameQuery.bind(":id", items[i]);
- nameQuery.exec();
- nameQuery.next();
- output.writeTextElement("td", nameQuery.value(0));
- output.writeStartElement("td");
- output.writeAttribute("align", "center");
- output.writeCharacters(quantities[i]);
- output.writeEndElement();
- output.writeEndElement();
- }
- nameQuery = nameQuery.invalidate();
- output.writeEndElement();
- output.writeStartElement("tfoot");
- output.writeStartElement("tr");
- output.writeStartElement("td");
- output.writeAttribute("align", "right");
- output.writeTextElement("strong", "Green Total:");
- output.writeEndElement();
- output.writeStartElement("td");
- output.writeAttribute("align", "center");
- output.writeCharacters(table.data(row, 3));
- output.writeEndElement();
- output.writeEndElement();
- output.writeStartElement("tr");
- output.writeStartElement("td");
- output.writeAttribute("align", "right");
- output.writeTextElement("strong", "Roasted Weight:");
- output.writeEndElement();
- output.writeStartElement("td");
- output.writeAttribute("align", "center");
- output.writeCharacters(table.data(row, 4));
- output.writeEndElement();
- output.writeEndElement();
- output.writeStartElement("tr");
- output.writeStartElement("td");
- output.writeAttribute("align", "right");
- output.writeTextElement("strong", "Weight Loss:");
- output.writeEndElement();
- output.writeStartElement("td");
- output.writeAttribute("align", "center");
- output.writeCharacters(table.data(row, 5));
- output.writeCharacters("%");
- output.writeEndElement();
- output.writeEndElement();
- output.writeEndElement();
- output.writeEndElement();
- output.writeStartElement("p");
- output.writeTextElement("strong", "Approved: ");
- output.writeCharacters(approval);
- output.writeEndElement();
- output.writeStartElement("p");
- output.writeTextElement("strong", "Files: ");
- output.writeCharacters(query.value(3));
- output.writeEndElement();
- output.writeStartElement("p");
- output.writeTextElement("strong", "Annotations:");
- var files = sqlToArray(query.value(3));
- var annotations = annotationFromRecord(files[0]);
- fileID = files[0];
- var buffer2 = new QBuffer("<points>"+annotations+"</points>");
- buffer2.open(1);
- var colQuery = new XQuery;
- colQuery.bind("profile", buffer2);
- colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
- var result = colQuery.exec();
- buffer2.close();
- var seriesHeaders = new Array();
- seriesHeaders.push("Time");
- var records = result.split(";");
- for(var i = 0; i < records.length - 1; i++) {
- seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
- }
- seriesHeaders.push("Note");
- output.writeStartElement("table");
- output.writeStartElement("thead");
- output.writeStartElement("tr");
- for(var i = 0; i < seriesHeaders.length; i++) {
- output.writeTextElement("th", seriesHeaders[i]);
- }
- output.writeEndElement();
- output.writeEndElement();
- buffer2.open(1);
- var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
- for(var i = 0; i < seriesHeaders.length - 2; i++) {
- rq = rq + 'string($t/temperature[' + Number(i+1) + ']), ";", ';
- }
- rq = rq + 'string($t/annotation), "~")';
- colQuery.setQuery(rq);
- var annotationData = colQuery.exec();
- colQuery = colQuery.invalidate();
- buffer2.close();
- output.writeStartElement("tbody");
- var annotationRecords = annotationData.split("~");
- for(var i = 0; i < annotationRecords.length - 1; i++) {
- output.writeStartElement("tr");
- var annotationRow = annotationRecords[i].split(";");
- for(var j = 0; j < annotationRow.length; j++) {
- output.writeStartElement("td");
- output.writeAttribute("style", "border-left: 1px solid #000000");
- if(j > 0) {
- output.writeAttribute("align", "center");
- }
- if(j > 0 && j < annotationRow.length - 1) {
- output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
- }
- else {
- output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
- }
- output.writeEndElement();
- }
- output.writeEndElement();
- }
- output.writeEndElement();
- output.writeEndElement();
- output.writeCharacters(annotation);
- output.writeEndElement();
- output.writeEndElement();
- output.writeEndElement();
- output.writeEndDocument();
- dataView.setContent(buffer);
- buffer.close();
- query = query.invalidate();
- edit.enabled = true;
- };
- ]]>
- </program>
- </window>
|