Typica is a free program for professional coffee roasters. https://typica.us
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

batchdetailsnew.xml 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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. graph.updatesEnabled = false;
  222. log.updatesEnabled = false;
  223. input.input();
  224. log.updatesEnabled = true;
  225. graph.updatesEnabled = true;
  226. log.newAnnotation(TTR("batchDetails", "End"), 1, lc);
  227. query = query.invalidate();
  228. });
  229. var approvalButton = findChildObject(this, 'approval');
  230. var annotationField = findChildObject(this, 'annotation');
  231. var roastedEdit = findChildObject(this, 'roasted');
  232. var unitEdit = findChildObject(this, 'roastunit');
  233. var wholecolor = findChildObject(this, 'wholecolor');
  234. var groundcolor = findChildObject(this, 'groundcolor');
  235. window.loadBatch = function(mref, tref) {
  236. machine = mref;
  237. batchTime = tref;
  238. var query = new QSqlQuery();
  239. 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";
  240. query.prepare(q);
  241. query.bind(":machine", mref);
  242. query.bind(":time", tref);
  243. query.bind(":c1", conversion);
  244. query.bind(":c2", conversion);
  245. query.exec();
  246. query.next();
  247. var buffer = new QBuffer;
  248. buffer.open(3);
  249. var output = new XmlWriter(buffer);
  250. output.writeStartDocument("1.0");
  251. 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">');
  252. output.writeStartElement("html");
  253. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  254. output.writeStartElement("head");
  255. output.writeTextElement("title", "Batch Details");
  256. output.writeEndElement();
  257. output.writeStartElement("body");
  258. output.writeStartElement("div");
  259. output.writeAttribute("style", "float: left; padding-right: 10px");
  260. output.writeStartElement("p");
  261. output.writeTextElement("strong", TTR("batchDetails", "Roasted Coffee: "));
  262. output.writeTextElement("span", query.value(0));
  263. output.writeEndElement();
  264. output.writeEndElement();
  265. output.writeStartElement("div");
  266. output.writeAttribute("style", "float: left");
  267. output.writeStartElement("p");
  268. output.writeTextElement("strong", TTR("batchDetails", "Roasted At: "));
  269. output.writeTextElement("span", batchTime);
  270. output.writeEndElement();
  271. output.writeStartElement("p");
  272. output.writeTextElement("strong", TTR("batchDetails", "Batch Duration: "));
  273. output.writeTextElement("span", query.value(1));
  274. output.writeEndElement();
  275. output.writeEndElement();
  276. output.writeStartElement("div");
  277. output.writeAttribute("style", "clear: both");
  278. output.writeEndElement();
  279. output.writeStartElement("table");
  280. output.writeStartElement("thead");
  281. output.writeStartElement("tr");
  282. output.writeTextElement("th", TTR("batchDetails", "Green Coffee"));
  283. output.writeTextElement("th", TTR("batchDetails", "Weight") + "(" + unitText + ")");
  284. output.writeEndElement();
  285. output.writeEndElement();
  286. output.writeStartElement("tbody");
  287. var items = sqlToArray(query.value(2));
  288. var quantities = sqlToArray(query.value(3));
  289. for(var i = 0; i < items.length; i++) {
  290. output.writeStartElement("tr");
  291. output.writeTextElement("td", items[i]);
  292. output.writeStartElement("td");
  293. output.writeAttribute("align", "center");
  294. output.writeCharacters(Number(quantities[i]/conversion).toFixed(3));
  295. output.writeEndElement();
  296. output.writeEndElement();
  297. }
  298. output.writeEndElement();
  299. output.writeStartElement("tfoot");
  300. output.writeStartElement("tr");
  301. output.writeStartElement("td");
  302. output.writeAttribute("align", "right");
  303. output.writeTextElement("strong", TTR("batchDetails", "Green Total:"));
  304. output.writeEndElement();
  305. output.writeStartElement("td");
  306. output.writeAttribute("align", "center");
  307. output.writeCharacters(query.value(4));
  308. output.writeEndElement();
  309. output.writeEndElement();
  310. output.writeStartElement("tr");
  311. output.writeStartElement("td");
  312. output.writeAttribute("align", "right");
  313. output.writeTextElement("strong", TTR("batchDetails", "Roasted Weight:"));
  314. output.writeEndElement();
  315. output.writeStartElement("td");
  316. output.writeAttribute("align", "center");
  317. output.writeCharacters(query.value(5));
  318. output.writeEndElement();
  319. output.writeEndElement();
  320. output.writeStartElement("tr");
  321. output.writeStartElement("td");
  322. output.writeAttribute("align", "right");
  323. output.writeTextElement("strong", TTR("batchDetails", "Weight Loss:"));
  324. output.writeEndElement();
  325. output.writeStartElement("td");
  326. output.writeAttribute("align", "center");
  327. if(Number(query.value(4)) > 0) {
  328. output.writeCharacters(Number(((Number(query.value(4)) - Number(query.value(5)))/Number(query.value(4))) * 100).toFixed(2));
  329. output.writeCharacters("%");
  330. } else {
  331. output.writeCharacters("unknown");
  332. }
  333. output.writeEndElement();
  334. output.writeEndElement();
  335. output.writeEndElement();
  336. output.writeEndElement();
  337. if(query.value(10).length > 0) {
  338. var extradata = JSON.parse(query.value(10));
  339. if(extradata.color) {
  340. output.writeStartElement("p");
  341. output.writeTextElement("strong", TTR("batchDetails", "Degree of Roast"));
  342. output.writeEndElement();
  343. if(extradata.color.whole) {
  344. wholecolor.value = extradata.color.whole;
  345. output.writeStartElement("p");
  346. output.writeTextElement("strong", TTR("batchDetails", "Whole Bean: "));
  347. output.writeTextElement("span", extradata.color.whole);
  348. output.writeEndElement();
  349. } else {
  350. wholecolor.value = "";
  351. }
  352. if(extradata.color.ground) {
  353. groundcolor.value = extradata.color.ground;
  354. output.writeStartElement("p");
  355. output.writeTextElement("strong", TTR("batchDetails", "Ground: "));
  356. output.writeTextElement("span", extradata.color.ground);
  357. output.writeEndElement();
  358. } else {
  359. groundcolor.value = "";
  360. }
  361. } else {
  362. wholecolor.value = "";
  363. groundcolor.value = "";
  364. }
  365. } else {
  366. wholecolor.value = "";
  367. groundcolor.value = "";
  368. }
  369. output.writeStartElement("p");
  370. output.writeTextElement("strong", TTR("batchDetails", "Approved: "));
  371. output.writeCharacters(query.value(6));
  372. output.writeEndElement();
  373. output.writeStartElement("p");
  374. output.writeTextElement("strong", TTR("batchDetails", "Files: "));
  375. output.writeCharacters(query.value(7));
  376. output.writeEndElement();
  377. output.writeStartElement("p");
  378. output.writeTextElement("strong", TTR("batchDetails", "Annotations:"));
  379. var files = sqlToArray(query.value(7));
  380. var annotations = annotationFromRecord(files[0]);
  381. fileID = files[0];
  382. var buffer2 = new QBuffer("<points>"+annotations+"</points>");
  383. buffer2.open(1);
  384. var colQuery = new XQuery;
  385. colQuery.bind("profile", buffer2);
  386. colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
  387. var result = colQuery.exec();
  388. buffer2.close();
  389. var seriesHeaders = new Array();
  390. seriesHeaders.push(TTR("batchDetails", "Time"));
  391. var records = result.split(";");
  392. for(var i = 0; i < records.length - 1; i++) {
  393. seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
  394. }
  395. seriesHeaders.push(TTR("batchDetails", "Note"));
  396. output.writeStartElement("table");
  397. output.writeStartElement("thead");
  398. output.writeStartElement("tr");
  399. for(var i = 0; i < seriesHeaders.length; i++) {
  400. output.writeTextElement("th", seriesHeaders[i]);
  401. }
  402. output.writeEndElement();
  403. output.writeEndElement();
  404. buffer2.open(1);
  405. var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
  406. for(var i = 0; i < seriesHeaders.length - 2; i++) {
  407. rq += 'string($t/temperature[' + Number(i+1) + ']), ";", ';
  408. }
  409. rq += 'string($t/annotation), "~")';
  410. colQuery.setQuery(rq);
  411. var annotationData = colQuery.exec();
  412. colQuery = colQuery.invalidate();
  413. buffer2.close();
  414. output.writeStartElement("tbody");
  415. var annotationRecords = annotationData.split("~");
  416. for(var i = 0; i < annotationRecords.length - 1; i++) {
  417. output.writeStartElement("tr");
  418. var annotationRow = annotationRecords[i].split(";");
  419. for(var j = 0; j < annotationRow.length; j++) {
  420. output.writeStartElement("td");
  421. output.writeAttribute("style", "border-left: 1px solid #000000");
  422. if(j > 0) {
  423. output.writeAttribute("align", "center");
  424. }
  425. if(j > 0 && j < annotationRow.length - 1) {
  426. output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
  427. } else {
  428. output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
  429. }
  430. output.writeEndElement();
  431. }
  432. output.writeEndElement();
  433. }
  434. output.writeEndElement();
  435. output.writeEndElement();
  436. output.writeCharacters(query.value(8));
  437. output.writeEndElement();
  438. output.writeEndElement();
  439. output.writeEndElement();
  440. output.writeEndDocument();
  441. dataView.setContent(buffer);
  442. buffer.close();
  443. log.clear();
  444. graph.clear();
  445. var buffer3 = new QBuffer(query.value(9));
  446. var input = new XMLInput(buffer3, 1);
  447. input.newTemperatureColumn.connect(log.setHeaderData);
  448. input.newAnnotationColumn.connect(log.setHeaderData);
  449. var lc;
  450. input.lastColumn.connect(function(c) {
  451. lc = c;
  452. if(c < 3) {
  453. log.setHeaderData(3, "");
  454. }
  455. });
  456. input.measure.connect(graph.newMeasurement);
  457. input.measure.connect(log.newMeasurement);
  458. input.annotation.connect(function(note,tcol,ncol) {
  459. for(var i = tcol; i < ncol; i++) {
  460. log.newAnnotation(note, i, ncol);
  461. }
  462. });
  463. graph.updatesEnabled = false;
  464. log.updatesEnabled = false;
  465. input.input();
  466. log.updatesEnabled = true;
  467. graph.updatesEnabled = true;
  468. log.newAnnotation("End", 1, lc);
  469. if(query.value(6) == "true") {
  470. approvalButton.checked = true;
  471. }
  472. annotationField.plainText = query.value(8);
  473. unitEdit.text = unitText;
  474. roastedEdit.text = query.value(5);
  475. drawTag(query.value(11), query.value(0));
  476. query = query.invalidate();
  477. }
  478. var saveMenu = findChildObject(this, 'save');
  479. saveMenu.triggered.connect(function() {
  480. var filename = QFileDialog.getSaveFileName(window, TTR("batchDetails", "Save Log As..."), QSettings.value("script/lastDir", "") + "/");
  481. if(filename != "") {
  482. saveFileFromDatabase(fileID, filename);
  483. }
  484. });
  485. var submit = findChildObject(this, 'submit');
  486. submit.clicked.connect(function() {
  487. var query = new QSqlQuery;
  488. query.prepare("UPDATE roasting_log SET roasted_quantity = :roasted, approval = :approval, annotation = :annotation, additional_data = :extradata WHERE time = :time AND machine = :machine");
  489. query.bind(":approval", approvalButton.checked);
  490. query.bind(":annotation", annotationField.plainText);
  491. query.bind(":roasted", Number(Number(roastedEdit.text)*conversion));
  492. var extradata = new Object;
  493. var colordata = new Object;
  494. if(wholecolor.value.length > 0) {
  495. colordata.whole = wholecolor.value;
  496. }
  497. if(groundcolor.value.length > 0) {
  498. colordata.ground = groundcolor.value;
  499. }
  500. if(colordata.whole || colordata.ground) {
  501. extradata.color = colordata;
  502. }
  503. query.bind(":extradata", JSON.stringify(extradata));
  504. query.bind(":time", batchTime);
  505. query.bind(":machine", Number(machine));
  506. query.exec();
  507. query = query.invalidate();
  508. window.loadBatch(machine, batchTime);
  509. displayInfo(TTR("batchDetails", "Batch Data Saved"),
  510. TTR("roastspec", "New batch details saved"));
  511. });
  512. var batchTag = findChildObject(this, 'batchTag');
  513. var printers = findChildObject(this, 'printerlist');
  514. printers.currentIndex = printers.findText(QSettings.value("script/batchtagprinter"));
  515. printers['currentIndexChanged(int)'].connect(function() {
  516. QSettings.setValue("script/batchtagprinter", printers.currentText);
  517. });
  518. var printbutton = findChildObject(this, 'printbutton');
  519. printbutton.clicked.connect(function() {
  520. batchTag.print(printers.currentText);
  521. });
  522. function drawTag(item, name) {
  523. var buffer = new QBuffer;
  524. buffer.open(3);
  525. var output = new XmlWriter(buffer);
  526. output.writeStartDocument("1.0");
  527. 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">');
  528. output.writeStartElement("html");
  529. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  530. output.writeStartElement("head");
  531. var styleFile = new QFile(QSettings.value("config") + "/Scripts/batchtag.css");
  532. styleFile.open(1);
  533. output.writeTextElement("style", styleFile.readToString());
  534. styleFile.close();
  535. styleFile = new QFile(QSettings.value("config") + "/Scripts/barcode.css");
  536. styleFile.open(1);
  537. output.writeTextElement("style", styleFile.readToString());
  538. styleFile.close();
  539. output.writeStartElement("script");
  540. scriptFile = new QFile(QSettings.value("config") + "/Scripts/qrcode.js");
  541. scriptFile.open(1);
  542. output.writeCDATA(scriptFile.readToString());
  543. scriptFile.close();
  544. output.writeEndElement();
  545. output.writeStartElement("script");
  546. scriptFile = new QFile(QSettings.value("config") + "/Scripts/barcode.js");
  547. scriptFile.open(1);
  548. output.writeCDATA(scriptFile.readToString());
  549. scriptFile.close();
  550. output.writeEndElement();
  551. output.writeEndElement();
  552. output.writeStartElement("body");
  553. output.writeStartElement("h1");
  554. output.writeCharacters(name + " (" + item + ")");
  555. output.writeEndElement();
  556. output.writeTextElement("span", "Roasted at: " + batchTime);
  557. output.writeTextElement("span", "On machine: " + machine);
  558. output.writeTextElement("span", "Batch file: " + fileID);
  559. output.writeStartElement("div");
  560. output.writeAttribute("id", "barcode");
  561. output.writeAttribute("class", "barcode128h");
  562. output.writeAttribute("align", "center");
  563. output.writeEndElement();
  564. output.writeStartElement("script");
  565. var c128data = 'var strBarcodeHTML = code128("';
  566. c128data += fileID;
  567. c128data += '", "C");'
  568. c128data += 'document.getElementById("barcode").innerHTML = strBarcodeHTML;';
  569. output.writeCDATA(c128data);
  570. output.writeEndElement();
  571. output.writeStartElement("div");
  572. output.writeAttribute("id", "container");
  573. output.writeEndElement();
  574. output.writeStartElement("script");
  575. var tag = {g: "Typica", m: Number(machine), v: 1};
  576. tag.t = batchTime;
  577. tag.f = Number(fileID);
  578. var scriptData = 'var width = document.getElementById("container").offsetWidth;';
  579. scriptData += 'var qrcode = new QRCode({content: \'';
  580. scriptData += JSON.stringify(tag);
  581. scriptData += '\', width: width, height: width});';
  582. scriptData += 'var svg = qrcode.svg();';
  583. scriptData += 'document.getElementById("container").innerHTML = svg;';
  584. output.writeCDATA(scriptData);
  585. output.writeEndElement();
  586. output.writeEndElement();
  587. output.writeEndElement();
  588. output.writeEndDocument();
  589. batchTag.setContent(buffer);
  590. buffer.close();
  591. };
  592. var search = findChildObject(this, 'search');
  593. search.returnPressed.connect(function() {
  594. if(search.text.length == 0) {
  595. return;
  596. }
  597. if(Number(search.text)) {
  598. var query = new QSqlQuery();
  599. query.prepare("SELECT machine, time FROM roasting_log WHERE files[1] = :file");
  600. query.bind(":file", Number(search.text));
  601. query.exec();
  602. if(query.next()) {
  603. window.loadBatch(query.value(0), query.value(1));
  604. }
  605. query = query.invalidate();
  606. } else {
  607. var tag = JSON.parse(search.text);
  608. if(tag.m != undefined && tag.t != undefined) {
  609. window.loadBatch(tag.m, tag.t);
  610. }
  611. }
  612. search.text = "";
  613. });
  614. ]]>
  615. </program>
  616. </window>