From 4d8bd4ad9506bace9c3976ebc4038a334503f978 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sun, 22 Oct 2017 02:25:57 +0200 Subject: [PATCH] Interpolate v2 --- forms/admin/connections/connections.js | 8 -- forms/admin/connections/ui.xml | 12 +- forms/admin/links/ui.xml | 3 +- forms/admin/users/ui.xml | 3 +- forms/admin/visits/ui.xml | 6 +- forms/agencies/packages/packages.js | 4 +- forms/cms/home/ui.xml | 5 +- forms/ecomerce/basket/ui.xml | 14 +- forms/ecomerce/orders/orders.js | 8 -- forms/ecomerce/orders/ui.xml | 6 +- forms/ecomerce/ticket/ticket.js | 7 +- forms/ecomerce/ticket/ui.xml | 27 ++-- js/db/db.js | 1 + js/db/lot.js | 84 ++++++++++++ js/db/query.js | 4 +- js/hedera/app.js | 14 +- js/hedera/form.js | 28 ++-- js/hedera/gui.js | 51 ++++---- js/hedera/gui.xml | 22 +++- js/htk/repeater.js | 4 +- js/vn/builder.js | 24 +++- js/vn/compiler-element.js | 30 +++-- js/vn/compiler-interpolable.js | 144 +++++++++++++++++++++ js/vn/compiler-object.js | 27 +++- js/vn/compiler-text.js | 16 ++- js/vn/compiler.js | 3 + js/vn/iterator.js | 5 +- js/vn/json-connection.js | 24 ++-- js/vn/{json-exception.js => json-error.js} | 6 +- js/vn/object.js | 34 ++--- js/vn/scope.js | 56 ++------ js/vn/vn.js | 2 +- 32 files changed, 466 insertions(+), 216 deletions(-) create mode 100644 js/db/lot.js create mode 100644 js/vn/compiler-interpolable.js rename js/vn/{json-exception.js => json-error.js} (79%) diff --git a/forms/admin/connections/connections.js b/forms/admin/connections/connections.js index 92e41dab..b9f9d939 100644 --- a/forms/admin/connections/connections.js +++ b/forms/admin/connections/connections.js @@ -26,14 +26,6 @@ Hedera.Connections = new Class this.$.sessions.refresh (); } - ,repeaterFunc: function (res, form) - { - res.$.link.href = this.hash.make ({ - form: 'admin/access-log', - user: form.$.userId - }); - } - ,onChangeUserClick: function (button, form) { this.gui.supplantUser (form.get ('user'), diff --git a/forms/admin/connections/ui.xml b/forms/admin/connections/ui.xml index 69d33272..a6f69387 100755 --- a/forms/admin/connections/ui.xml +++ b/forms/admin/connections/ui.xml @@ -19,7 +19,7 @@
- + SELECT vu.user userId, vu.stamp, c.Cliente, s.lastUpdate, a.platform, a.browser, a.version, u.name user @@ -33,7 +33,9 @@ ORDER BY lastUpdate DESC - +

- + {{Cliente}}

-

- - - - + {{platform}} - {{browser}} {{version}}

diff --git a/forms/admin/links/ui.xml b/forms/admin/links/ui.xml index 6d97810f..d55b8212 100755 --- a/forms/admin/links/ui.xml +++ b/forms/admin/links/ui.xml @@ -12,8 +12,7 @@

diff --git a/forms/admin/users/ui.xml b/forms/admin/users/ui.xml index 3fe27365..b765d4a7 100755 --- a/forms/admin/users/ui.xml +++ b/forms/admin/users/ui.xml @@ -24,8 +24,7 @@ title="_AccessLog">

diff --git a/forms/admin/visits/ui.xml b/forms/admin/visits/ui.xml index eefd52b4..ebbfc644 100755 --- a/forms/admin/visits/ui.xml +++ b/forms/admin/visits/ui.xml @@ -42,7 +42,7 @@

- + SELECT browser ,MIN(CAST(version AS DECIMAL(4,1))) minVersion @@ -61,9 +61,7 @@

- - - - + {{browser}} {{minVersion}} - {{maxVersion}}

diff --git a/forms/agencies/packages/packages.js b/forms/agencies/packages/packages.js index 6eba7324..9bf85770 100644 --- a/forms/agencies/packages/packages.js +++ b/forms/agencies/packages/packages.js @@ -6,8 +6,8 @@ Hedera.Packages = new Class ,onShowClick: function (column, agencyId) { this.hash.setAll ({ - 'form': 'agencies/provinces', - 'agency': agencyId + form: 'agencies/provinces', + agency: agencyId }); } }); diff --git a/forms/cms/home/ui.xml b/forms/cms/home/ui.xml index ad4c725a..b1724c30 100755 --- a/forms/cms/home/ui.xml +++ b/forms/cms/home/ui.xml @@ -23,14 +23,13 @@

{{title}}

- +
diff --git a/forms/ecomerce/basket/ui.xml b/forms/ecomerce/basket/ui.xml index 26add649..5517b5b6 100755 --- a/forms/ecomerce/basket/ui.xml +++ b/forms/ecomerce/basket/ui.xml @@ -26,7 +26,7 @@

- + SELECT i.id, i.amount, i.price, a.Article, a.Categoria, a.Medida, a.Tallos, a.Color, o.Abreviatura, a.Foto @@ -37,26 +37,22 @@

- - - + {{Article}} {{Medida}} {{Categoria}}

- x + {{amount}} x diff --git a/forms/ecomerce/orders/orders.js b/forms/ecomerce/orders/orders.js index 2e11ab4e..9c88b647 100644 --- a/forms/ecomerce/orders/orders.js +++ b/forms/ecomerce/orders/orders.js @@ -32,14 +32,6 @@ Hedera.Orders = new Class { this.hash.setAll ({form: 'ecomerce/basket'}); } - - ,repeaterFunc: function (res, form) - { - res.$.link.href = this.hash.make ({ - form: 'ecomerce/ticket', - ticket: form.get ('ticket_id') - }); - } // TPV diff --git a/forms/ecomerce/orders/ui.xml b/forms/ecomerce/orders/ui.xml index b7b282f7..818f2ba4 100755 --- a/forms/ecomerce/orders/ui.xml +++ b/forms/ecomerce/orders/ui.xml @@ -48,12 +48,14 @@

- + CALL clientTicketList (#from, NULL) - +

diff --git a/forms/ecomerce/ticket/ticket.js b/forms/ecomerce/ticket/ticket.js index f91cafd5..f2c12e7b 100644 --- a/forms/ecomerce/ticket/ticket.js +++ b/forms/ecomerce/ticket/ticket.js @@ -31,11 +31,10 @@ Hedera.Ticket = new Class ,subtotal: function (form) { - var price = form.get ('price'); - var discount = form.get ('discount'); + var row = form.$; - if (price && form.get ('fixed')) - return form.get ('amount') * price * ((100 - discount) / 100); + if (row.price && row.fixed) + return row.amount * row.price * ((100 - row.discount) / 100); else return null; } diff --git a/forms/ecomerce/ticket/ui.xml b/forms/ecomerce/ticket/ui.xml index 0108c155..c3d0f9b9 100755 --- a/forms/ecomerce/ticket/ui.xml +++ b/forms/ecomerce/ticket/ui.xml @@ -2,11 +2,9 @@ - - - CALL clientTicketGet(#ticket) - - + + CALL clientTicketGet(#ticket) +

_OrderDetail

@@ -21,7 +19,7 @@

- @ + @{{ticket.id}}

@@ -29,18 +27,16 @@

- _Delivery + Delivery {{ticket.Agencia}}

- + {{ticket.consignee}}

- + {{ticket.name}}

- - - () + {{ticket.consignee}} {{ticket.city}} ({{ticket.province}})

@@ -54,15 +50,14 @@

- + CALL clientTicketRowGet(#ticket)

- {{amount}} x + {{amount}} x diff --git a/js/db/db.js b/js/db/db.js index 975fe107..12125233 100644 --- a/js/db/db.js +++ b/js/db/db.js @@ -6,6 +6,7 @@ Db = module.exports = { ,Result : require ('./result') ,ResultSet : require ('./result-set') ,Model : require ('./model') + ,Lot : require ('./lot') ,Query : require ('./query') ,Calc : require ('./calc') ,CalcSum : require ('./calc-sum') diff --git a/js/db/lot.js b/js/db/lot.js new file mode 100644 index 00000000..0be4d385 --- /dev/null +++ b/js/db/lot.js @@ -0,0 +1,84 @@ + +var Connection = require ('./connection'); +var Model = require ('./model'); + +module.exports = new Class +({ + Extends: Vn.Form + ,Tag: 'db-lot' + ,Properties: + { + /** + * The connection used to execute the statement. + */ + conn: + { + type: Connection + ,set: function (x) + { + this.model.conn = x; + } + ,get: function () + { + return this.model.conn; + } + }, + /** + * The model query. + */ + query: + { + type: String + ,set: function (x) + { + this.model.query = x; + } + ,get: function () + { + return this.model.query; + } + }, + /** + * The model select statement. + */ + stmt: + { + type: Sql.Stmt + ,set: function (x) + { + this.model.stmt = x; + } + ,get: function () + { + return this.model.stmt; + } + }, + /** + * The lot used to execute the statement. + */ + lot: + { + type: Vn.Lot + ,set: function (x) + { + this.model.lot = x; + } + ,get: function () + { + return this.model.lot; + } + } + } + + ,initialize: function (props) + { + this.model = new Model (); + this.parent (props); + } + + ,appendChild: function (child) + { + if (child.nodeType === Node.TEXT_NODE) + this.query = child.textContent; + } +}); diff --git a/js/db/query.js b/js/db/query.js index c9c7e7c3..b23f30d3 100644 --- a/js/db/query.js +++ b/js/db/query.js @@ -90,7 +90,7 @@ module.exports = new Class ,execute: function () { this._conn.execStmt (this._stmt, - this.onQueryDone.bind (this), this._batch); + this.onQueryDone.bind (this), this._lot ? this._lot.$ : null); } ,onQueryDone: function (resultSet) @@ -100,7 +100,7 @@ module.exports = new Class ,onChange: function () { - if (this.autoLoad && this._conn && this._stmt && this._batch) + if (this.autoLoad && this._conn && this._stmt && this._lot) this.execute (); } }); diff --git a/js/hedera/app.js b/js/hedera/app.js index 92db4264..78469ccb 100644 --- a/js/hedera/app.js +++ b/js/hedera/app.js @@ -118,8 +118,12 @@ module.exports = new Class case 'OutdatedVersion': this._newVersion (); break; - default: + case 'User': Htk.Toast.showError (error.message); + break; + default: + Htk.Toast.showError (_('Something went wrong')); + console.error (error.message); } else { @@ -160,10 +164,10 @@ module.exports = new Class Htk.Toast.showError (_('Something went wrong')); var params = { - 'file': error.fileName - ,'line': error.lineNumber - ,'message': error.message - ,'stack': error.stack + file: error.fileName + ,line: error.lineNumber + ,message: error.message + ,stack: error.stack }; this._conn.send ('core/log', params); } diff --git a/js/hedera/form.js b/js/hedera/form.js index 1c3d276a..02af45b7 100644 --- a/js/hedera/form.js +++ b/js/hedera/form.js @@ -37,11 +37,14 @@ module.exports = new Class var builder = new Vn.Builder (); builder.compileFile ('forms/'+ this.formInfo.path +'/ui.xml'); + var conn = this.conn; + var hash = this.hash; + var extraObjects = { - conn: this.conn, - hash: this.hash + conn: conn, + hash: hash }; - var scope = builder.load (this.doc, this, null, extraObjects, this.hash); + var scope = builder.load (this.doc, this, null, extraObjects, hash); this.scope = scope; this.$ = scope.$; this._node = this.$.main; @@ -50,21 +53,22 @@ module.exports = new Class if (paramsLot) { - paramsLot.source = this.hash; + paramsLot.source = hash; this.params = paramsLot; } scope.link (); - var models = scope.getByTagName ('db-model'); + function setConnection (tagName) + { + var objects = scope.getByTagName (tagName); + for (var i = 0; i < objects.length; i++) + objects[i].conn = conn; + } - for (var i = 0; i < models.length; i++) - models[i].conn = this.conn; - - var queries = scope.getByTagName ('db-query'); - - for (var i = 0; i < queries.length; i++) - queries[i].conn = this.conn; + var tags = ['db-model', 'db-query', 'db-lot']; + for (var i = 0; i < tags.length; i++) + setConnection (tags[i]); if (this.node) { diff --git a/js/hedera/gui.js b/js/hedera/gui.js index a29fce9a..ee5f6a2f 100644 --- a/js/hedera/gui.js +++ b/js/hedera/gui.js @@ -57,31 +57,16 @@ module.exports = new Class this.loadTemplateFromString (Tpl); this.loadingCount = 0; - this.$.background.onclick = function () {}; - - this.$.menuButton.addEventListener ('click', function (event) - { - event.stopPropagation (); - this.showMenu (); - }.bind (this)); - - this.$.leftPanel.addEventListener ('click', function (event) - { - event.stopPropagation (); - }); - this.parent (props); this.$.socialBar.conn = this._conn; - - var sql = 'SELECT name FROM customer_user;' - +'SELECT default_form, image_dir, image_host FROM config;' - +'SELECT production_domain, test_domain FROM config;'; - this._conn.execQuery (sql, this.onMainQueryDone.bind (this)); + this.$.user.conn = this._conn; + this.$.configQuery.conn = this._conn; + this.$.configQuery.execute (); this.loadMenu (); } - + ,show: function () { if (this._shown) @@ -150,13 +135,8 @@ module.exports = new Class this.loaderPop (); } - ,onMainQueryDone: function (resultSet) + ,onConfigQueryReady: function (query, resultSet) { - // Retrieving the user name - - var userName = resultSet.fetchValue (); - Vn.Node.setText (this.$.userName, userName); - // Retrieving configuration parameters Object.assign (Vn.Config, resultSet.fetchObject ()); @@ -178,8 +158,10 @@ module.exports = new Class var linkField = 'test_domain'; } - Vn.Node.setText (this.$.testLink, _(linkText)); - this.$.testLink.href = '//'+ row[linkField]; + this.$.newVersion.assign ({ + text: _(linkText), + link: '//'+ row[linkField] + }); } else Vn.Node.hide (this.$.testLink); @@ -298,6 +280,17 @@ module.exports = new Class } } + ,onMenuButtonClick: function (event) + { + event.stopPropagation (); + this.showMenu (); + } + + ,onLeftPanelClick: function (event) + { + event.stopPropagation (); + } + ,showMenu: function () { this.showBackground (); @@ -335,7 +328,7 @@ module.exports = new Class if (!this._shown) return; - var navbar = this.$.topBar; + var navbar = this.$.navbar; var yOffset = window.pageYOffset; var showNavbar = this._lastYOffset > yOffset || yOffset < navbar.offsetHeight; @@ -357,6 +350,8 @@ module.exports = new Class //++++++++++++++++++++++++++++++++++++++++++++++++++++++ Background + ,onBackgroundClick: function () {} + ,showBackground: function () { Vn.Node.addClass (this.$.background, 'show'); diff --git a/js/hedera/gui.xml b/js/hedera/gui.xml index ab26d747..82ee799b 100755 --- a/js/hedera/gui.xml +++ b/js/hedera/gui.xml @@ -1,14 +1,22 @@ + + + SELECT name FROM customer_user + + + SELECT default_form, image_dir, image_host FROM config; + SELECT production_domain, test_domain FROM config; +

-