Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

batchdetailsnew.xml 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <window id="batchDetails">
  2. <layout type="vertical">
  3. <layout type="horizontal">
  4. <button type="push" id="target" name="Load profile as target" />
  5. <button type="push" id="compare" name="Compare profile" />
  6. <stretch />
  7. <label>Search:</label>
  8. <line id="search" />
  9. </layout>
  10. <tabbar id="tabs" />
  11. <layout type="stack" id="pages">
  12. <page>
  13. <layout type="vertical">
  14. <webview id="view" />
  15. </layout>
  16. </page>
  17. <page>
  18. <layout type="vertical">
  19. <splitter type="horizontal" id="logsplit">
  20. <measurementtable id="log">
  21. <column>Time</column>
  22. <column>Bean</column>
  23. <column>Air</column>
  24. <column>Note</column>
  25. </measurementtable>
  26. <graph id="graph" />
  27. </splitter>
  28. </layout>
  29. </page>
  30. <page>
  31. <layout type="vertical">
  32. <layout type="horizontal">
  33. <label>Roasted Weight: </label>
  34. <line id="roasted" validator="numeric" />
  35. <line id="roastunit" writable="false" />
  36. <stretch />
  37. </layout>
  38. <label>Degree of Roast</label>
  39. <layout type="horizontal">
  40. <label>Whole Bean:</label>
  41. <roastcoloredit id="wholecolor" />
  42. <stretch />
  43. </layout>
  44. <label id="wholespec">-</label>
  45. <layout type="horizontal">
  46. <label>Ground:</label>
  47. <roastcoloredit id="groundcolor" />
  48. <stretch />
  49. </layout>
  50. <label id="groundspec">-</label>
  51. <button type="check" name="Approved" id="approval" />
  52. <layout type="horizontal">
  53. <label>Annotation</label>
  54. <textarea id="annotation" />
  55. </layout>
  56. <button type="push" id="submit" name="Save" />
  57. <stretch />
  58. </layout>
  59. </page>
  60. <page>
  61. <layout type="vertical">
  62. <webview id="batchTag" />
  63. <layout type="horizontal">
  64. <printerselector id="printerlist" />
  65. <button name="Print" id="printbutton" type="push" />
  66. </layout>
  67. </layout>
  68. </page>
  69. </layout>
  70. </layout>
  71. <menu name="File">
  72. <item id="save" shortcut="Ctrl+S">Save Profile...</item>
  73. <item id="print" shortcut="Ctrl+P">Print Report...</item>
  74. </menu>
  75. <menu name="Log">
  76. <item id="showC">Display Celsius</item>
  77. <item id="showF">Display Fahrenheit</item>
  78. <separator />
  79. <item id="ms">Millisecond View</item>
  80. <item id="1s">1 Second View</item>
  81. <item id="5s">5 Second View</item>
  82. <item id="10s">10 Second View</item>
  83. <item id="15s">15 Second View</item>
  84. <item id="30s">30 Second View</item>
  85. <item id="1m">1 Minute View</item>
  86. </menu>
  87. <program>
  88. <![CDATA[
  89. var window = this;
  90. var tabs = findChildObject(this, 'tabs');
  91. tabs.addTab("Report");
  92. tabs.addTab("Profile");
  93. tabs.addTab("Edit");
  94. tabs.addTab("Batch Tag");
  95. var pages = findChildObject(this, 'pages');
  96. tabs.currentChanged.connect(function(index) {
  97. pages.setCurrentIndex(index);
  98. });
  99. var log = findChildObject(this, 'log');
  100. var graph = findChildObject(this, 'graph');
  101. var showC = findChildObject(this, 'showC');
  102. showC.triggered.connect(function() {
  103. log.setDisplayUnits(Units.Celsius);
  104. graph.showC();
  105. });
  106. var showF = findChildObject(this, 'showF');
  107. showF.triggered.connect(function() {
  108. log.setDisplayUnits(Units.Fahrenheit);
  109. graph.showF();
  110. });
  111. var v1 = findChildObject(this, 'ms');
  112. v1.triggered.connect(log.LOD_ms);
  113. var v2 = findChildObject(this, '1s');
  114. v2.triggered.connect(log.LOD_1s);
  115. var v3 = findChildObject(this, '5s');
  116. v3.triggered.connect(log.LOD_5s);
  117. var v4 = findChildObject(this, '10s');
  118. v4.triggered.connect(log.LOD_10s);
  119. var v5 = findChildObject(this, '15s');
  120. v5.triggered.connect(log.LOD_15s);
  121. var v6 = findChildObject(this, '30s');
  122. v6.triggered.connect(log.LOD_30s);
  123. var v7 = findChildObject(this, '1m');
  124. v7.triggered.connect(log.LOD_1m);
  125. var splitter = findChildObject(this, 'logsplit');
  126. splitter.restoreState("script/offlineViewSplitter");
  127. window.saveTemperatureColumns = new Array();
  128. window.saveAnnotationColumns = new Array();
  129. this.aboutToClose.connect(function() {
  130. splitter.saveState("script/batchdetails/profileSplitter");
  131. });
  132. var unit = QSettings.value("script/history_unit", 1);
  133. var conversion = 1;
  134. if(unit == 0)
  135. {
  136. conversion = 2.2;
  137. }
  138. var unitText = (unit == 0 ? TTR("batchDetails", "Kg") :
  139. TTR("batchDetails", "Lb"));
  140. dataView = findChildObject(this, 'view');
  141. var printMenu = findChildObject(this, 'print');
  142. printMenu.triggered.connect(function() {
  143. dataView.print();
  144. });
  145. var fileID;
  146. var target = findChildObject(this, 'target');
  147. var compare = findChildObject(this, 'compare');
  148. if(typeof(Windows.loggingWindow) == "undefined") {
  149. compare.enabled = false;
  150. target.enabled = false;
  151. }
  152. var tableReference;
  153. var rowReference;
  154. var batchTime;
  155. var machine;
  156. var approval;
  157. var annotation;
  158. var roastWeight;
  159. compare.clicked.connect(function() {
  160. var query = new QSqlQuery;
  161. query.prepare("SELECT file, name FROM files WHERE id = :id");
  162. query.bind(":id", Number(fileID));
  163. query.exec();
  164. query.next();
  165. var buffer = new QBuffer(query.value(0));
  166. var pname = query.value(1);
  167. query = query.invalidate();
  168. var startSeries = Number(QSettings.value('cseries', 3));
  169. var nextSeries = startSeries + 2;
  170. QSettings.setValue('cseries', nextSeries);
  171. var input = new XMLInput(buffer, startSeries);
  172. var graph = findChildObject(Windows.loggingWindow, 'graph');
  173. input.measure.connect(graph.newMeasurement);
  174. input.input();
  175. query = query.invalidate();
  176. });
  177. target.clicked.connect(function() {
  178. var query = new QSqlQuery;
  179. query.prepare("SELECT file, name FROM files WHERE id = :id");
  180. query.bind(":id", Number(fileID));
  181. query.exec();
  182. query.next();
  183. var buffer = new QBuffer(query.value(0));
  184. var pname = query.value(1);
  185. query = query.invalidate();
  186. var input = new XMLInput(buffer, 1);
  187. var graph = findChildObject(Windows.loggingWindow, 'graph');
  188. var log = findChildObject(Windows.loggingWindow, 'log');
  189. log.clear();
  190. graph.clear();
  191. input.newTemperatureColumn.connect(log.setHeaderData);
  192. input.newTemperatureColumn.connect(function(col, text) {
  193. if(text == Windows.loggingWindow.targetcolumnname) {
  194. targetseries = col;
  195. }
  196. });
  197. input.newAnnotationColumn.connect(log.setHeaderData);
  198. input.measure.connect(graph.newMeasurement);
  199. input.measure.connect(log.newMeasurement);
  200. input.measure.connect(function(data, series) {
  201. if(series == targetseries) {
  202. targetDetector.newMeasurement(data);
  203. }
  204. });
  205. var lc;
  206. input.lastColumn.connect(function(c) {
  207. lc = c;
  208. QSettings.setValue("liveColumn", c + 1);
  209. Windows.loggingWindow.postLoadColumnSetup(c);
  210. });
  211. input.annotation.connect(log.newAnnotation);
  212. input.annotation.connect(function(note, tcol, ncol) {
  213. for(var i = tcol; i < ncol; i++) {
  214. log.newAnnotation(note, i, ncol);
  215. }
  216. });
  217. Windows.loggingWindow.windowTitle = "Typica - " + pname;
  218. Windows.loggingWindow.raise();
  219. Windows.loggingWindow.activateWindow();
  220. input.input();
  221. log.newAnnotation(TTR("batchDetails", "End"), 1, lc);
  222. query = query.invalidate();
  223. });
  224. var approvalButton = findChildObject(this, 'approval');
  225. var annotationField = findChildObject(this, 'annotation');
  226. var roastedEdit = findChildObject(this, 'roasted');
  227. var unitEdit = findChildObject(this, 'roastunit');
  228. var wholecolor = findChildObject(this, 'wholecolor');
  229. var groundcolor = findChildObject(this, 'groundcolor');
  230. window.loadBatch = function(mref, tref) {
  231. machine = mref;
  232. batchTime = tref;
  233. var query = new QSqlQuery();
  234. var q = "WITH names AS ( WITH greens AS ( SELECT unnest(unroasted_id) AS gitem, machine, time FROM roasting_log WHERE machine = :machine AND time = :time) SELECT array_agg((SELECT name FROM items WHERE id = greens.gitem) || ' (' || gitem || ')') AS names, max(greens.machine) AS machine, max(greens.time) AS time FROM greens LIMIT 1) SELECT (SELECT name FROM items WHERE id = roasted_id), duration, names, unroasted_quantity, (unroasted_total_quantity/:c1)::numeric(12,3), (roasted_quantity/:c2)::numeric(12,3), approval, files, annotation, (SELECT file FROM files WHERE id = files[1]) AS file, additional_data, roasted_id FROM names, roasting_log WHERE roasting_log.machine = names.machine AND roasting_log.time = names.time";
  235. query.prepare(q);
  236. query.bind(":machine", mref);
  237. query.bind(":time", tref);
  238. query.bind(":c1", conversion);
  239. query.bind(":c2", conversion);
  240. query.exec();
  241. query.next();
  242. var buffer = new QBuffer;
  243. buffer.open(3);
  244. var output = new XmlWriter(buffer);
  245. output.writeStartDocument("1.0");
  246. 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">');
  247. output.writeStartElement("html");
  248. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  249. output.writeStartElement("head");
  250. output.writeTextElement("title", "Batch Details");
  251. output.writeEndElement();
  252. output.writeStartElement("body");
  253. output.writeStartElement("div");
  254. output.writeAttribute("style", "float: left; padding-right: 10px");
  255. output.writeStartElement("p");
  256. output.writeTextElement("strong", TTR("batchDetails", "Roasted Coffee: "));
  257. output.writeTextElement("span", query.value(0));
  258. output.writeEndElement();
  259. output.writeEndElement();
  260. output.writeStartElement("div");
  261. output.writeAttribute("style", "float: left");
  262. output.writeStartElement("p");
  263. output.writeTextElement("strong", TTR("batchDetails", "Roasted At: "));
  264. output.writeTextElement("span", batchTime);
  265. output.writeEndElement();
  266. output.writeStartElement("p");
  267. output.writeTextElement("strong", TTR("batchDetails", "Batch Duration: "));
  268. output.writeTextElement("span", query.value(1));
  269. output.writeEndElement();
  270. output.writeEndElement();
  271. output.writeStartElement("div");
  272. output.writeAttribute("style", "clear: both");
  273. output.writeEndElement();
  274. output.writeStartElement("table");
  275. output.writeStartElement("thead");
  276. output.writeStartElement("tr");
  277. output.writeTextElement("th", TTR("batchDetails", "Green Coffee"));
  278. output.writeTextElement("th", TTR("batchDetails", "Weight") + "(" + unitText + ")");
  279. output.writeEndElement();
  280. output.writeEndElement();
  281. output.writeStartElement("tbody");
  282. var items = sqlToArray(query.value(2));
  283. var quantities = sqlToArray(query.value(3));
  284. for(var i = 0; i < items.length; i++) {
  285. output.writeStartElement("tr");
  286. output.writeTextElement("td", items[i]);
  287. output.writeStartElement("td");
  288. output.writeAttribute("align", "center");
  289. output.writeCharacters(Number(quantities[i]/conversion).toFixed(3));
  290. output.writeEndElement();
  291. output.writeEndElement();
  292. }
  293. output.writeEndElement();
  294. output.writeStartElement("tfoot");
  295. output.writeStartElement("tr");
  296. output.writeStartElement("td");
  297. output.writeAttribute("align", "right");
  298. output.writeTextElement("strong", TTR("batchDetails", "Green Total:"));
  299. output.writeEndElement();
  300. output.writeStartElement("td");
  301. output.writeAttribute("align", "center");
  302. output.writeCharacters(query.value(4));
  303. output.writeEndElement();
  304. output.writeEndElement();
  305. output.writeStartElement("tr");
  306. output.writeStartElement("td");
  307. output.writeAttribute("align", "right");
  308. output.writeTextElement("strong", TTR("batchDetails", "Roasted Weight:"));
  309. output.writeEndElement();
  310. output.writeStartElement("td");
  311. output.writeAttribute("align", "center");
  312. output.writeCharacters(query.value(5));
  313. output.writeEndElement();
  314. output.writeEndElement();
  315. output.writeStartElement("tr");
  316. output.writeStartElement("td");
  317. output.writeAttribute("align", "right");
  318. output.writeTextElement("strong", TTR("batchDetails", "Weight Loss:"));
  319. output.writeEndElement();
  320. output.writeStartElement("td");
  321. output.writeAttribute("align", "center");
  322. if(Number(query.value(4)) > 0) {
  323. output.writeCharacters(Number(((Number(query.value(4)) - Number(query.value(5)))/Number(query.value(4))) * 100).toFixed(2));
  324. output.writeCharacters("%");
  325. } else {
  326. output.writeCharacters("unknown");
  327. }
  328. output.writeEndElement();
  329. output.writeEndElement();
  330. output.writeEndElement();
  331. output.writeEndElement();
  332. if(query.value(10).length > 0) {
  333. var extradata = JSON.parse(query.value(10));
  334. if(extradata.color) {
  335. output.writeStartElement("p");
  336. output.writeTextElement("strong", TTR("batchDetails", "Degree of Roast"));
  337. output.writeEndElement();
  338. if(extradata.color.whole) {
  339. wholecolor.value = extradata.color.whole;
  340. output.writeStartElement("p");
  341. output.writeTextElement("strong", TTR("batchDetails", "Whole Bean: "));
  342. output.writeTextElement("span", extradata.color.whole);
  343. output.writeEndElement();
  344. } else {
  345. wholecolor.value = "";
  346. }
  347. if(extradata.color.ground) {
  348. groundcolor.value = extradata.color.ground;
  349. output.writeStartElement("p");
  350. output.writeTextElement("strong", TTR("batchDetails", "Ground: "));
  351. output.writeTextElement("span", extradata.color.ground);
  352. output.writeEndElement();
  353. } else {
  354. groundcolor.value = "";
  355. }
  356. } else {
  357. wholecolor.value = "";
  358. groundcolor.value = "";
  359. }
  360. } else {
  361. wholecolor.value = "";
  362. groundcolor.value = "";
  363. }
  364. output.writeStartElement("p");
  365. output.writeTextElement("strong", TTR("batchDetails", "Approved: "));
  366. output.writeCharacters(query.value(6));
  367. output.writeEndElement();
  368. output.writeStartElement("p");
  369. output.writeTextElement("strong", TTR("batchDetails", "Files: "));
  370. output.writeCharacters(query.value(7));
  371. output.writeEndElement();
  372. output.writeStartElement("p");
  373. output.writeTextElement("strong", TTR("batchDetails", "Annotations:"));
  374. var files = sqlToArray(query.value(7));
  375. var annotations = annotationFromRecord(files[0]);
  376. fileID = files[0];
  377. var buffer2 = new QBuffer("<points>"+annotations+"</points>");
  378. buffer2.open(1);
  379. var colQuery = new XQuery;
  380. colQuery.bind("profile", buffer2);
  381. colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
  382. var result = colQuery.exec();
  383. buffer2.close();
  384. var seriesHeaders = new Array();
  385. seriesHeaders.push(TTR("batchDetails", "Time"));
  386. var records = result.split(";");
  387. for(var i = 0; i < records.length - 1; i++) {
  388. seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
  389. }
  390. seriesHeaders.push(TTR("batchDetails", "Note"));
  391. output.writeStartElement("table");
  392. output.writeStartElement("thead");
  393. output.writeStartElement("tr");
  394. for(var i = 0; i < seriesHeaders.length; i++) {
  395. output.writeTextElement("th", seriesHeaders[i]);
  396. }
  397. output.writeEndElement();
  398. output.writeEndElement();
  399. buffer2.open(1);
  400. var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
  401. for(var i = 0; i < seriesHeaders.length - 2; i++) {
  402. rq += 'string($t/temperature[' + Number(i+1) + ']), ";", ';
  403. }
  404. rq += 'string($t/annotation), "~")';
  405. colQuery.setQuery(rq);
  406. var annotationData = colQuery.exec();
  407. colQuery = colQuery.invalidate();
  408. buffer2.close();
  409. output.writeStartElement("tbody");
  410. var annotationRecords = annotationData.split("~");
  411. for(var i = 0; i < annotationRecords.length - 1; i++) {
  412. output.writeStartElement("tr");
  413. var annotationRow = annotationRecords[i].split(";");
  414. for(var j = 0; j < annotationRow.length; j++) {
  415. output.writeStartElement("td");
  416. output.writeAttribute("style", "border-left: 1px solid #000000");
  417. if(j > 0) {
  418. output.writeAttribute("align", "center");
  419. }
  420. if(j > 0 && j < annotationRow.length - 1) {
  421. output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
  422. } else {
  423. output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
  424. }
  425. output.writeEndElement();
  426. }
  427. output.writeEndElement();
  428. }
  429. output.writeEndElement();
  430. output.writeEndElement();
  431. output.writeCharacters(query.value(8));
  432. output.writeEndElement();
  433. output.writeEndElement();
  434. output.writeEndElement();
  435. output.writeEndDocument();
  436. dataView.setContent(buffer);
  437. buffer.close();
  438. log.clear();
  439. graph.clear();
  440. var buffer3 = new QBuffer(query.value(9));
  441. var input = new XMLInput(buffer3, 1);
  442. input.newTemperatureColumn.connect(log.setHeaderData);
  443. input.newAnnotationColumn.connect(log.setHeaderData);
  444. var lc;
  445. input.lastColumn.connect(function(c) {
  446. lc = c;
  447. if(c < 3) {
  448. log.setHeaderData(3, "");
  449. }
  450. });
  451. input.measure.connect(graph.newMeasurement);
  452. input.measure.connect(log.newMeasurement);
  453. input.annotation.connect(function(note,tcol,ncol) {
  454. for(var i = tcol; i < ncol; i++) {
  455. log.newAnnotation(note, i, ncol);
  456. }
  457. });
  458. graph.updatesEnabled = false;
  459. log.updatesEnabled = false;
  460. input.input();
  461. log.updatesEnabled = true;
  462. graph.updatesEnabled = true;
  463. log.newAnnotation("End", 1, lc);
  464. if(query.value(6) == "true") {
  465. approvalButton.checked = true;
  466. }
  467. annotationField.plainText = query.value(8);
  468. unitEdit.text = unitText;
  469. roastedEdit.text = query.value(5);
  470. drawTag(query.value(11), query.value(0));
  471. query = query.invalidate();
  472. }
  473. var saveMenu = findChildObject(this, 'save');
  474. saveMenu.triggered.connect(function() {
  475. var filename = QFileDialog.getSaveFileName(window, TTR("batchDetails", "Save Log As..."), QSettings.value("script/lastDir", "") + "/");
  476. if(filename != "") {
  477. saveFileFromDatabase(fileID, filename);
  478. }
  479. });
  480. var submit = findChildObject(this, 'submit');
  481. submit.clicked.connect(function() {
  482. var query = new QSqlQuery;
  483. query.prepare("UPDATE roasting_log SET roasted_quantity = :roasted, approval = :approval, annotation = :annotation, additional_data = :extradata WHERE time = :time AND machine = :machine");
  484. query.bind(":approval", approvalButton.checked);
  485. query.bind(":annotation", annotationField.plainText);
  486. query.bind(":roasted", Number(Number(roastedEdit.text)*conversion));
  487. var extradata = new Object;
  488. var colordata = new Object;
  489. if(wholecolor.value.length > 0) {
  490. colordata.whole = wholecolor.value;
  491. }
  492. if(groundcolor.value.length > 0) {
  493. colordata.ground = groundcolor.value;
  494. }
  495. if(colordata.whole || colordata.ground) {
  496. extradata.color = colordata;
  497. }
  498. query.bind(":extradata", JSON.stringify(extradata));
  499. query.bind(":time", batchTime);
  500. query.bind(":machine", Number(machine));
  501. query.exec();
  502. query = query.invalidate();
  503. window.loadBatch(machine, batchTime);
  504. displayInfo(TTR("batchDetails", "Batch Data Saved"),
  505. TTR("roastspec", "New batch details saved"));
  506. });
  507. var batchTag = findChildObject(this, 'batchTag');
  508. var printers = findChildObject(this, 'printerlist');
  509. printers.currentIndex = printers.findText(QSettings.value("script/batchtagprinter"));
  510. printers['currentIndexChanged(int)'].connect(function() {
  511. QSettings.setValue("script/batchtagprinter", printers.currentText);
  512. });
  513. var printbutton = findChildObject(this, 'printbutton');
  514. printbutton.clicked.connect(function() {
  515. batchTag.print(printers.currentText);
  516. });
  517. function drawTag(item, name) {
  518. var buffer = new QBuffer;
  519. buffer.open(3);
  520. var output = new XmlWriter(buffer);
  521. output.writeStartDocument("1.0");
  522. 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">');
  523. output.writeStartElement("html");
  524. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  525. output.writeStartElement("head");
  526. var styleFile = new QFile(QSettings.value("config") + "/Scripts/batchtag.css");
  527. styleFile.open(1);
  528. output.writeTextElement("style", styleFile.readToString());
  529. styleFile.close();
  530. styleFile = new QFile(QSettings.value("config") + "/Scripts/barcode.css");
  531. styleFile.open(1);
  532. output.writeTextElement("style", styleFile.readToString());
  533. styleFile.close();
  534. output.writeStartElement("script");
  535. scriptFile = new QFile(QSettings.value("config") + "/Scripts/qrcode.js");
  536. scriptFile.open(1);
  537. output.writeCDATA(scriptFile.readToString());
  538. scriptFile.close();
  539. output.writeEndElement();
  540. output.writeStartElement("script");
  541. scriptFile = new QFile(QSettings.value("config") + "/Scripts/barcode.js");
  542. scriptFile.open(1);
  543. output.writeCDATA(scriptFile.readToString());
  544. scriptFile.close();
  545. output.writeEndElement();
  546. output.writeEndElement();
  547. output.writeStartElement("body");
  548. output.writeStartElement("h1");
  549. output.writeCharacters(name + " (" + item + ")");
  550. output.writeEndElement();
  551. output.writeTextElement("span", "Roasted at: " + batchTime);
  552. output.writeTextElement("span", "On machine: " + machine);
  553. output.writeTextElement("span", "Batch file: " + fileID);
  554. output.writeStartElement("div");
  555. output.writeAttribute("id", "barcode");
  556. output.writeAttribute("class", "barcode128h");
  557. output.writeAttribute("align", "center");
  558. output.writeEndElement();
  559. output.writeStartElement("script");
  560. var c128data = 'var strBarcodeHTML = code128("';
  561. c128data += fileID;
  562. c128data += '", "C");'
  563. c128data += 'document.getElementById("barcode").innerHTML = strBarcodeHTML;';
  564. output.writeCDATA(c128data);
  565. output.writeEndElement();
  566. output.writeStartElement("div");
  567. output.writeAttribute("id", "container");
  568. output.writeEndElement();
  569. output.writeStartElement("script");
  570. var tag = {g: "Typica", m: Number(machine), v: 1};
  571. tag.t = batchTime;
  572. tag.f = Number(fileID);
  573. var scriptData = 'var width = document.getElementById("container").offsetWidth;';
  574. scriptData += 'var qrcode = new QRCode({content: \'';
  575. scriptData += JSON.stringify(tag);
  576. scriptData += '\', width: width, height: width});';
  577. scriptData += 'var svg = qrcode.svg();';
  578. scriptData += 'document.getElementById("container").innerHTML = svg;';
  579. output.writeCDATA(scriptData);
  580. output.writeEndElement();
  581. output.writeEndElement();
  582. output.writeEndElement();
  583. output.writeEndDocument();
  584. batchTag.setContent(buffer);
  585. buffer.close();
  586. };
  587. var search = findChildObject(this, 'search');
  588. search.returnPressed.connect(function() {
  589. if(search.text.length == 0) {
  590. return;
  591. }
  592. if(Number(search.text)) {
  593. var query = new QSqlQuery();
  594. query.prepare("SELECT machine, time FROM roasting_log WHERE files[1] = :file");
  595. query.bind(":file", Number(search.text));
  596. query.exec();
  597. if(query.next()) {
  598. window.loadBatch(query.value(0), query.value(1));
  599. }
  600. query = query.invalidate();
  601. } else {
  602. var tag = JSON.parse(search.text);
  603. if(tag.m != undefined && tag.t != undefined) {
  604. window.loadBatch(tag.m, tag.t);
  605. }
  606. }
  607. search.text = "";
  608. });
  609. ]]>
  610. </program>
  611. </window>