Typica is a free program for professional coffee roasters. https://typica.us
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

batchdetailsnew.xml 30KB

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