This commit is contained in:
Juan Ferrer Toribio 2017-07-05 11:50:42 +02:00
parent 942772ec03
commit c1175122d0
12 changed files with 144 additions and 98 deletions

View File

@ -4,4 +4,5 @@ rules:
no-redeclare: 0
no-mixed-spaces-and-tabs: 0
no-console: 0
no-cond-assign: 0
no-cond-assign: 0
no-unexpected-multiline: 0

View File

@ -1,11 +1,12 @@
<vn>
<vn-group>
<db-form id="debt">
<db-model property="model">
SELECT clientGetDebt() debt
</db-model>
</db-form>
</vn-group>
<vn-lot-query id="params">
<vn-spec name="from" type="Date"/>
</vn-lot-query>
<db-form id="debt">
<db-model property="model">
SELECT clientGetDebt() debt
</db-model>
</db-form>
<h1 id="title">
<t>LastOrders</t>
</h1>

View File

@ -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++)

View File

@ -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--)
{

View File

@ -121,4 +121,3 @@ module.exports = new Class
return this._model.setByIndex (this._row, column, value);
}
});

View File

@ -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
*/

View File

@ -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;
}
}

View File

@ -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;
}
});

45
js/vn/spec.js Normal file
View File

@ -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;
}
}
}
});

View File

@ -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')

View File

@ -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": {

View File

@ -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;