From c1175122d0814166a1aa4b9632688b2cb77560d2 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 5 Jul 2017 11:50:42 +0200 Subject: [PATCH] Backup --- .eslintrc.yml | 3 +- forms/ecomerce/orders/ui.xml | 15 +++-- js/hedera/form.js | 5 ++ js/vn/builder.js | 4 +- js/vn/iterator-iface.js | 1 - js/vn/lot-iface.js | 12 ++-- js/vn/lot-query.js | 125 ++++++++++++++--------------------- js/vn/lot.js | 18 ++++- js/vn/spec.js | 45 +++++++++++++ js/vn/vn.js | 1 + package.json | 9 ++- webpack.config.js | 4 +- 12 files changed, 144 insertions(+), 98 deletions(-) create mode 100644 js/vn/spec.js diff --git a/.eslintrc.yml b/.eslintrc.yml index 64de1d5c..0fe49c2b 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -4,4 +4,5 @@ rules: no-redeclare: 0 no-mixed-spaces-and-tabs: 0 no-console: 0 - no-cond-assign: 0 \ No newline at end of file + no-cond-assign: 0 + no-unexpected-multiline: 0 \ No newline at end of file diff --git a/forms/ecomerce/orders/ui.xml b/forms/ecomerce/orders/ui.xml index 1d1b6c22..055bbfaf 100755 --- a/forms/ecomerce/orders/ui.xml +++ b/forms/ecomerce/orders/ui.xml @@ -1,11 +1,12 @@ - - - - SELECT clientGetDebt() debt - - - + + + + + + SELECT clientGetDebt() debt + +

LastOrders

diff --git a/js/hedera/form.js b/js/hedera/form.js index d4098f8b..589f59bd 100644 --- a/js/hedera/form.js +++ b/js/hedera/form.js @@ -42,6 +42,11 @@ module.exports = new Class var res = this.builderResultInit (builder); + var paramsLot = res.$('params'); + + if (paramsLot) + paramsLot.source = this.hash; + var models = res.getByTagName ('db-model'); for (var i = 0; i < models.length; i++) diff --git a/js/vn/builder.js b/js/vn/builder.js index d3a9dfb4..1d0bc026 100644 --- a/js/vn/builder.js +++ b/js/vn/builder.js @@ -81,7 +81,7 @@ module.exports = new Class { var parser = new DOMParser (); var xmlDoc = parser.parseFromString (xmlString, 'text/xml'); - return this.loadFromXmlDoc (xmlDoc); + return this.loadFromXmlDoc (xmlDoc, dstDocument); } ,loadFromXmlDoc: function (xmlDoc, dstDocument) @@ -194,7 +194,7 @@ module.exports = new Class this._doc = dstDocument ? dstDocument : document; } - ,_compileEnd: function (node) + ,_compileEnd: function () { for (var i = this._links.length - 1; i >= 0; i--) { diff --git a/js/vn/iterator-iface.js b/js/vn/iterator-iface.js index a96fd692..4e9d2cae 100644 --- a/js/vn/iterator-iface.js +++ b/js/vn/iterator-iface.js @@ -121,4 +121,3 @@ module.exports = new Class return this._model.setByIndex (this._row, column, value); } }); - diff --git a/js/vn/lot-iface.js b/js/vn/lot-iface.js index ae4a1957..db34d372 100644 --- a/js/vn/lot-iface.js +++ b/js/vn/lot-iface.js @@ -24,7 +24,7 @@ module.exports = new Class } /** - * Gets a value from the set. + * Gets a value from the lot. * * @param {string} field The field name * @return {*} The field value @@ -35,7 +35,7 @@ module.exports = new Class } /** - * Sets a value on the set. + * Sets a value on the lot. * * @param {string} field The field name * @param {*} value The new field value @@ -48,14 +48,14 @@ module.exports = new Class } /** - * Returns an array with the set keys. + * Returns an array with the lot keys. * - * @return {Array} The set keys + * @return {Array} The lot keys */ ,keys: function () {} /** - * Emits the 'change' signal on the set. + * Emits the 'change' signal on the lot. * * @param {Object} changes The changed params and its values */ @@ -65,7 +65,7 @@ module.exports = new Class } /** - * Copies all values from another set. + * Copies all values from another lot. * * @param {Object} object The source object */ diff --git a/js/vn/lot-query.js b/js/vn/lot-query.js index cfbd3b54..b0fe585b 100644 --- a/js/vn/lot-query.js +++ b/js/vn/lot-query.js @@ -1,22 +1,10 @@ var Lot = require ('./lot'); var LotIface = require ('./lot-iface'); +var Spec = require ('./spec'); +var Value = require ('./value'); -var Klass = new Class (); -module.exports = Klass; - -var Type = -{ - INCLUDE: 1, - EXCLUDE: 2 -}; - -Klass.extend -({ - Type: Type -}); - -Klass.implement +module.exports = new Class ({ Extends: Lot ,Tag: 'vn-lot-query' @@ -47,82 +35,69 @@ Klass.implement { return this._source; } - }, - type: - { - enumType: Type - ,set: function (x) - { - this._type = x; - this._onSourceChange (); - } - ,get: function () - { - return this._type; - } } } - ,_fields: null - ,_source: null - ,_type: Type.INCLUDE - ,_sourceFields: null + ,initialize: function (props) + { + Object.assign (this, { + _fields: null, + _source: null, + _specs: {} + }); + this.parent (props); + } + + ,appendChild: function (child) + { + if (!(child instanceof Spec)) + throw new Error ('VnLotQuery: Child must be a Vn.Spec instance'); + + this._specs[child.name] = child; + } ,_onSourceChange: function () { - var changed = false; var params = this._source ? this._source.params : {}; + var myParams = {}; - if (this._fields) - switch (this._type) - { - case Type.EXCLUDE: - changed = this.typeExclude (params); - break; - default: - changed = this.typeInclude (params); - } - else - changed = true; + for (var key in this._specs) + myParams[key] = Value.simpleClone (params[key]); - if (changed) - this.changed (); + this.assign (myParams); } - ,typeInclude: function (params) + ,transformParams: function (params) { - var changed = false; - var fields = this._fields; + var newParams = {}; - for (var i = fields.length; i--;) + for (var key in this._specs) { - var field = fields[i]; - - if (this._params[field] !== params[field]) - { - this._params[field] = params[field]; - changed = true; - } + var spec = this._specs[key]; + if (params[key]) + newParams[key] = cast (params[key], spec.type); } - return changed; - } - - ,typeExclude: function (params) - { - var changed = false; - var sourceFields = []; - - for (var field in params) - if (this._fields.indexOf (field) === -1 - && this._params[field] !== params[field]) - { - this._params[field] = params[field]; - sourceFields.push (field); - changed = true; - } - - return changed; + return Object.assign (params, newParams); } }); +function cast (value, type) +{ + switch (type) + { + case Boolean: + return (/^(true|1)$/i).test (v); + case Number: + return 0 + new Number (v); + case Date: + var date = new Date (v); + date.setHours (0, 0, 0, 0); + return date; + default: + if (type instanceof Object) + return JSON.parse (v); + else + return v; + } +} diff --git a/js/vn/lot.js b/js/vn/lot.js index 57cbe91c..4cbf4a28 100644 --- a/js/vn/lot.js +++ b/js/vn/lot.js @@ -54,6 +54,7 @@ module.exports = new Class ,assign: function (params) { + params = this.transformParams (params); var diff = Value.partialDiff (this._params, params); if (diff) @@ -66,6 +67,7 @@ module.exports = new Class ,setAll: function (params) { + params = this.transformParams (params); var diff = Value.diff (this._params, params); if (diff) @@ -77,10 +79,22 @@ module.exports = new Class } /** - * Called when lot params changes, can be implemented by child classes to - * be notified about changes. + * Called when lot params changes, can be implemented by child classes to be + * notified about changes. * * @param {Object} diff Changed parameters and its new values */ ,_paramsChanged: function () {} + + /** + * Called when lot params changes to apply transformations over them, can be + * implemented by child classes. + * + * @param {Object} params New parameters + * @return {Object} Transformed parameters + */ + ,transformParams: function (params) + { + return params; + } }); diff --git a/js/vn/spec.js b/js/vn/spec.js new file mode 100644 index 00000000..c9b28f3e --- /dev/null +++ b/js/vn/spec.js @@ -0,0 +1,45 @@ + +var VnObject = require ('./object'); +var Type = require ('./type'); + +/** + * Paramter specification. + */ +module.exports = new Class +({ + Extends: VnObject + ,Tag: 'vn-spec' + ,Properties: + { + /** + * The parameter name. + */ + name: + { + type: String + ,set: function (x) + { + this._name = x; + } + ,get: function () + { + return this._name; + } + }, + /** + * The parameter type. + */ + type: + { + type: Type + ,set: function (x) + { + this._type = x; + } + ,get: function () + { + return this._type; + } + } + } +}); diff --git a/js/vn/vn.js b/js/vn/vn.js index 26d52b8f..3a69931f 100644 --- a/js/vn/vn.js +++ b/js/vn/vn.js @@ -18,6 +18,7 @@ Vn = module.exports = { ,Hash : require ('./hash') ,ParamIface : require ('./param-iface') ,Param : require ('./param') + ,Spec : require ('./spec') ,ModelIface : require ('./model-iface') ,ModelProxy : require ('./model-proxy') ,JsonModel : require ('./json-model') diff --git a/package.json b/package.json index 92f339a7..b79f9a3c 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,11 @@ "name": "hedera-web", "version": "2.0.4", "description": "Verdnatura web page", + "license": "GPL-3.0", + "repository": { + "type": "git", + "url": "https://git.verdnatura.es/hedera-web" + }, "devDependencies": { "assets-webpack-plugin": "^3.5.1", "bundle-loader": "^0.5.4", @@ -12,9 +17,9 @@ "raw-loader": "^0.5.1", "style-loader": "^0.13.1", "url-loader": "^0.5.7", - "webpack": "^2.5.1", + "webpack": "^3.0.0", "webpack-chunk-hash": "^0.4.0", - "webpack-dev-server": "^2.4.5", + "webpack-dev-server": "^2.5.0", "webpack-merge": "^3.0.0" }, "dependencies": { diff --git a/webpack.config.js b/webpack.config.js index 41034d10..d4d89d48 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -72,8 +72,8 @@ var devConfig = { port: wpConfig.devServerPort, headers: { "Access-Control-Allow-Origin": "*" }, stats: { chunks: false } - }/*, - devtool: 'eval-source-map'*/ + }, + devtool: 'eval' }; var mrgConfig = devMode ? devConfig : prodConfig;