Typica is a free program for professional coffee roasters. https://typica.us
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

batchdetailsnew.xml 31KB

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