123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <window id="roastspec">
- <layout type="horizontal">
- <layout type="vertical">
- <layout type="horizontal">
- <label>Coffee:</label>
- <sqldrop data="0" display="1" showdata="false" id="currentitems">
- <query>SELECT id, name FROM items WHERE id IN (SELECT item FROM current_items) ORDER BY name</query>
- </sqldrop>
- </layout>
- <tabbar id="tabs" />
- <layout type="stack" id="pages">
- <page>
- <layout type="vertical">
- <layout type="horizontal">
- <label>Expected % weight loss:</label>
- <line validator="numeric" id="expectedloss" />
- </layout>
- <layout type="horizontal">
- <label>Tolerance</label>
- <line validator="numeric" id="tolerance" />
- </layout>
- <stretch />
- </layout>
- </page>
- <page>
- <layout type="vertical">
- <layout type="horizontal">
- <label>Whole color:</label>
- <line validator="numeric" id="expectedwhole" />
- </layout>
- <layout type="horizontal">
- <label>Tolerance:</label>
- <line validator="numeric" id="wholetolerance" />
- </layout>
- <layout type="horizontal">
- <label>Ground color:</label>
- <line validator="numeric" id="expectedground" />
- </layout>
- <layout type="horizontal">
- <label>Tolerance:</label>
- <line validator="numeric" id="groundtolerance" />
- </layout>
- <stretch />
- </layout>
- </page>
- <page>
- <layout type="vertical">
- <label>Specification Notes:</label>
- <textarea id="notes" />
- <stretch />
- </layout>
- </page>
- </layout>
- <layout type="horizontal">
- <stretch />
- <button id="save" type="push" name="Save" />
- </layout>
- </layout>
- </layout>
- <program>
- <![CDATA[
- var window = this;
- this.windowTitle = TTR("roastspec", "Typica - Edit Roasting Specification");
- var tabs = findChildObject(this, 'tabs');
- tabs.addTab("Weight Loss");
- tabs.addTab("Color");
- tabs.addTab("Notes");
- var pages = findChildObject(this, 'pages');
- tabs.currentChanged.connect(function(index) {
- pages.setCurrentIndex(index);
- });
- var selector = findChildObject(this, 'currentitems');
- var expected = findChildObject(this, 'expectedloss');
- var tolerance = findChildObject(this, 'tolerance');
- var notes = findChildObject(this, 'notes');
- var savebutton = findChildObject(this, 'save');
- var wholecolor = findChildObject(this, 'expectedwhole');
- var groundcolor = findChildObject(this, 'expectedground');
- var wholetolerance = findChildObject(this, 'wholetolerance');
- var groundtolerance = findChildObject(this, 'groundtolerance');
- var updateDisplay = function() {
- var query = new QSqlQuery();
- query.prepare("SELECT loss, tolerance, notes, spec FROM roasting_specification WHERE item = :id1 AND time = (SELECT max(time) FROM roasting_specification WHERE item = :id2)");
- query.bind(":id1", selector.currentData());
- query.bind(":id2", selector.currentData());
- query.exec();
- if(query.next()) {
- if(query.value(0).length > 0) {
- expected.text = Number(query.value(0)) * 100;
- } else {
- expected.text = "";
- }
- if(query.value(1).length > 0) {
- tolerance.text = Number(query.value(1)) * 100;
- } else {
- tolerance.text = "";
- }
- notes.plainText = query.value(2);
- if(query.value(3).length > 0) {
- var spec = JSON.parse(query.value(3));
- if(spec.color === undefined) {
- wholecolor.text = "";
- wholetolerance.text = "";
- groundcolor.text = "";
- groundtolerance.text = "";
- } else {
- if(spec.color.whole === undefined) {
- wholecolor.text = "";
- wholetolerance.text = "";
- } else {
- if(spec.color.whole.expected === undefined) {
- wholecolor.text = "";
- } else {
- wholecolor.text = spec.color.whole.expected;
- }
- if(spec.color.whole.tolerance === undefined) {
- wholetolerance.text = "";
- } else {
- wholetolerance.text = spec.color.whole.tolerance;
- }
- }
- if(spec.color.ground === undefined) {
- groundcolor.text = "";
- groundtolerance.text = "";
- } else {
- if(spec.color.ground.expected === undefined) {
- groundcolor.text = "";
- } else {
- groundcolor.text = spec.color.ground.expected;
- }
- if(spec.color.ground.tolerance === undefined) {
- groundtolerance.text = "";
- } else {
- groundtolerance.text = spec.color.ground.tolerance;
- }
- }
- }
- }
- } else {
- expected.text = "";
- tolerance.text = "";
- notes.plainText = "";
- wholecolor.text = "";
- wholetolerance.text = "";
- groundcolor.text = "";
- groundtolerance.text = "";
- }
- query = query.invalidate();
- };
- updateDisplay();
- selector['currentIndexChanged(int)'].connect(function() {
- updateDisplay();
- });
- savebutton.clicked.connect(function() {
- var specobject = new Object;
- var query = new QSqlQuery();
- var columnspec = "time, item, ";
- var valuespec = "'now', :id, ";
- if(expected.text.length > 0) {
- columnspec += "loss, ";
- valuespec += ":loss, ";
- var lossspec = new Object;
- lossspec.expected = expected.text;
- if(tolerance.text.length > 0) {
- columnspec += "tolerance, ";
- valuespec += ":tolerance, ";
- lossspec.tolerance = tolerance.text;
- }
- specobject.loss = lossspec;
- }
- colorspec = new Object;
- if(wholecolor.text.length > 0) {
- wholespec = new Object;
- wholespec.expected = wholecolor.text;
- if(wholetolerance.text.length > 0) {
- wholespec.tolerance = wholetolerance.text;
- }
- colorspec.whole = wholespec;
- }
- if(groundcolor.text.length > 0) {
- groundspec = new Object;
- groundspec.expected = groundcolor.text;
- if(groundtolerance.text.length > 0) {
- groundspec.tolerance = groundtolerance.text;
- }
- colorspec.ground = groundspec;
- }
- if(colorspec.whole || colorspec.ground) {
- specobject.color = colorspec;
- }
- if(notes.plainText.length > 0) {
- specobject.notes = notes.plainText;
- }
- columnspec += "notes, spec";
- valuespec += ":notes, :spec";
- query.prepare("INSERT INTO roasting_specification (" + columnspec + ") VALUES (" + valuespec + ")");
- query.bind(":id", selector.currentData());
- if(expected.text.length > 0) {
- query.bind(":loss", Number(expected.text) / 100);
- }
- if(tolerance.text.length > 0) {
- query.bind(":tolerance", Number(tolerance.text) / 100);
- }
- query.bind(":notes", notes.plainText);
- query.bind(":spec", JSON.stringify(specobject));
- query.exec();
- displayInfo(TTR("roastspec", "New Specification Saved"),
- TTR("roastspec", "New roasting specification saved"));
- });
- ]]>
- </program>
- </window>
|