diff --git a/client/api/design/energy_data.js b/client/api/design/energy_data.js index 8ecffe7..3538032 100644 --- a/client/api/design/energy_data.js +++ b/client/api/design/energy_data.js @@ -3,6 +3,24 @@ import DateRange from './../../../shared/utils/date_range'; class EnergyDataApi { static index(params){ + if (params.houses){ + var promises = [], + data = []; + for (var opts of params.houses){ + var promise = EnergyDataApi.getHouseData(opts) + .then((res)=>{ + data.concat(res); + }); + promises.push(promise); + } + return Promise.all(promises) + .then(()=>{ return data; }); + } else { + return EnergyDataApi.getHouseData(params); + } + } + + static getHouseData(params){ return jQuery.ajax({ url: '/data/energy_data/' + params.house_id + ".json", dataType: 'json' @@ -13,6 +31,7 @@ class EnergyDataApi { }); }); }); + } } diff --git a/client/config/design/component_map.js b/client/config/design/component_map.js index 49e8dc3..b7336ef 100644 --- a/client/config/design/component_map.js +++ b/client/config/design/component_map.js @@ -1 +1 @@ -export const COMPONENT_MAP = {"energy":"dashboard/energy/energy","energy_graph":"dashboard/energy/graph/graph","energy_table":"dashboard/energy/table/table","layout":"dashboard/layout/layout","power_graph":"dashboard/power/graph/graph","power":"dashboard/power/power","power_table":"dashboard/power/table/table"} \ No newline at end of file +export const COMPONENT_MAP = {"energy":"dashboard/energy/energy","energy_graph":"dashboard/energy/graph/graph","energy_table":"dashboard/energy/table/table","irradiance_graph":"dashboard/irradiance/graph/graph","irradiance":"dashboard/irradiance/irradiance","irradiance_table":"dashboard/irradiance/table/table","layout":"dashboard/layout/layout","power_graph":"dashboard/power/graph/graph","power":"dashboard/power/power","power_table":"dashboard/power/table/table"} \ No newline at end of file diff --git a/client/config/design/style.js b/client/config/design/style.js index 5e71106..b8a8daa 100644 --- a/client/config/design/style.js +++ b/client/config/design/style.js @@ -1,4 +1,5 @@ // Vendor Stylesheets require('bootstrap/dist/css/bootstrap.min.css'); +require('c3/c3.min.css') require(__dirname + '/../../d3/chart.scss'); diff --git a/client/config/design/styles.js b/client/config/design/styles.js index 741356b..fdfde2d 100644 --- a/client/config/design/styles.js +++ b/client/config/design/styles.js @@ -13,7 +13,6 @@ class Styles { }); all.push(done); } - var app_styles = all.push(Styles.addAppCss() .then((result)=>{ if(result)css += result; })); return Promise.all(all) @@ -25,7 +24,11 @@ class Styles { static addCss(view, fnResolve){ return jQuery.ajax({ url: COMPONENT_MAP[view] + '.scss' - }).then((scss)=>{ + }) + .fail(()=>{ + fnResolve(''); + }) + .then((scss)=>{ var sass = new Sass(); if (!scss) return fnResolve(""); sass.compile(scss, (result, a)=>{ @@ -38,7 +41,11 @@ class Styles { return new Promise((fnResolve, fnReject)=>{ jQuery.ajax({ url: '/dashboard/app.scss' - }).then((scss)=>{ + }) + .fail(()=>{ + fnResolve(''); + }) + .then((scss)=>{ var sass = new Sass(); sass.compile(scss, (result, a)=>{ fnResolve(result.text); diff --git a/client/models/energy_datum.js b/client/models/energy_datum.js index 603b3e2..afe3ba4 100644 --- a/client/models/energy_datum.js +++ b/client/models/energy_datum.js @@ -65,6 +65,7 @@ class EnergyDatum { // get all data needed for all houses in one call. return new Promise((fnResolve, fnReject)=>{ + console.log(params) EnergyDataApi.index({houses: params}) .then((energy_data)=>{ energy_data = energy_data.reduce((grouped, energy_datum)=>{ diff --git a/client/models/house.js b/client/models/house.js index 83cce86..ad07739 100644 --- a/client/models/house.js +++ b/client/models/house.js @@ -276,7 +276,7 @@ class House { var required_ids = ids ? ArrayUtil.diff(ids, houses_data.map((data)=>{ return data.id; })) : undefined; return HousesApi.index({id: ids}) .then((required_houses)=>{ - required_houses.forEach((house_data)=>{ + (required_houses || []).forEach((house_data)=>{ house_collection.insert(house_data); }); House.db.save(); diff --git a/server/lib/tasks/design_data_generator.js b/server/lib/tasks/design_data_generator.js index 54b4026..eec3164 100644 --- a/server/lib/tasks/design_data_generator.js +++ b/server/lib/tasks/design_data_generator.js @@ -102,8 +102,10 @@ class DesignDataGenerator { } static energyIndex(opts){ - return DB.EnergyDatum.exposeForHouseAtDates(opts.house_id, opts.dates) + return DB.EnergyDatum.exposeForHouseAtDates(opts) .then((energy_data)=>{ + console.log('Energy data length') + console.log(energy_data.length) return JSON.stringify({data: energy_data}); }); }