var self = this;
var model = self.ractive;
model.observe('points.*.view points.*.query', function(nVal,oVal,kPath){
var pathToPoint = kPath.substring(0, kPath.lastIndexOf('.'));
var point = model.get(pathToPoint);
if (point) {
if (kPath.indexOf('query') != -1) {
var nQuery = model.get('getUpdatedQueryStringForItem').call(model, point);
if (!nQuery || !nQuery.length)
return;
finstack.eval(nQuery).then(function(data) {
if (data && data.result && !data.result.isErrorGrid) {
point.chartConfig.dataProvider = data.result.toObj();
model.get('updateChartForElementIdWithConfig').call(model, point.amId, point.chartConfig);
} else {
console.log(data);
}
}, function(err) {
console.error(err);
});
} else if (point && point.view == 'amChart') {
model.get('updateChartForElementIdWithConfig').call(model, point.amId, point.chartConfig);
}
}
});
model.on('unrender', function() {
model.get('updatePoll').call(model, true);
});
model.on('foldUpdate', function(event) {
var point = model.get(event.resolve());
var fVal = event.node.value;
model.set(event.resolve()+ '.fold', fVal);
model.get('updatePoll').call(model);
if (fVal != 'live') {
var q = 'readById(' +point.pointId+ ').hisRead(' +point.range+ ').foldCol("v0",'+point.fold+')';
console.log("Setting out...", q);
finstack.eval(q).then(function(data) {
model.set(event.resolve()+ '.mainValue', fin.Data.PointUtil.GetPrettyValue(point.original,data.result.toObj(false,false,true)));
}, function(err) {
console.log(err);
});
}
});
this.ractive.on("calendar", function(event){
var point = self.ractive.get(event.resolve());
var model = self.ractive;
top.app.ShowCalendar(true,function(calEvent){
var date = top.app.Utils.DateRangeToAxonDate(calEvent.range, calEvent.mode);
model.set(event.resolve()+ '.range', date);//.then(function() {
if (point.fold != 'live') {
var q = 'readById(' +point.pointId+ ').hisRead(' +point.range+ ').foldCol("v0",'+point.fold+')';
console.log("Setting out...", q);
finstack.eval(q).then(function(data) {
model.set(event.resolve()+ '.mainValue', fin.Data.PointUtil.GetPrettyValue(point.original,data.result.toObj(false,false,true)));
}, function(err) {
console.log(err);
});
}
}, {periods:true});
});
// Init Data
self.ractive.set({points: [{
mainIcon: "sm-oil",
iconColor: "#3488b2",
mainText: "Main Water",
mainValue: "150L",
btIcon: "icon-calendar",
btIconText: "Today",
view: 'icon',
range:"Date",
options: "hideButtons"
},{
mainIcon: "icon-location",
iconColor: "red",
mainText: "Rain Water",
mainValue: "50L",
btIcon: "icon-calendar",
btIconText: "Today",
view: 'waterdrop',
fillColor:"lightblue",
svgBackColor:"#d2d2d2",
fillValue:50,
myStart:"Select",
myEnd:"Date",
options: "hideButtons"
},{
mainIcon: "icon-graph-line",
iconColor: "#b083e0",
mainText: "Errors",
mainValue: "23",
btIcon: "icon-graph-line",
btIconText: "Data",
view: 'amChart',
options: "hideButtons",
amId: top.app.Utils.GetPseudoId(),
range:"today()",
fold:"avg",
chartConfig: {
"type": "pie",
"theme": "light",
dataProvider: [{
"country": "IT",
"value": 31.32
}, {
"country": "Heating",
"value": 27.47
}, {
"country": "Cooling",
"value": 25.55
}, {
"country": "Lighting",
"value": 15.66
} ],
"valueField": "value",
"titleField": "country",
"outlineAlpha": 0.4,
"depth3D": 15,
"balloonText": "[[title]]<br><span style='font-size:14px'><b>[[value]]:</b> ([[percents]]%)</span>",
"angle": 30,
"export": {
"enabled": true
}
}
}]}); |