diff --git a/.gitignore b/.gitignore
index 1a1f39d..072ab26 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ node_modules/
server/bin/
client/build/
shared/data/
+sass/
diff --git a/client/api/design/energy_data.js b/client/api/design/energy_data.js
index 9f597a9..8ecffe7 100644
--- a/client/api/design/energy_data.js
+++ b/client/api/design/energy_data.js
@@ -1,10 +1,18 @@
+import ArrayUtil from './../../../shared/utils/array';
+import DateRange from './../../../shared/utils/date_range';
class EnergyDataApi {
static index(params){
- return Promise.resolve(
-
-
- );
+ return jQuery.ajax({
+ url: '/data/energy_data/' + params.house_id + ".json",
+ dataType: 'json'
+ }).then((res)=>{
+ return res.data.filter((energy_datum)=>{
+ return ArrayUtil.any(params.dates, (range)=>{
+ return DateRange.lte(range[0], energy_datum.day) && DateRange.gte(range[1], energy_datum.day)
+ });
+ });
+ });
}
}
diff --git a/client/api/design/houses.js b/client/api/design/houses.js
index d0e1f6a..155c6d1 100644
--- a/client/api/design/houses.js
+++ b/client/api/design/houses.js
@@ -1,8 +1,12 @@
class HousesApi {
static index(params){
- return Promise.resolve({
-
+ return jQuery.ajax({
+ url: '/data/houses.json',
+ dataType: 'json'
+ })
+ .then((res)=>{
+ return res.data;
});
}
diff --git a/client/api/design/power_data.js b/client/api/design/power_data.js
index 3ed6b42..9fa15ba 100644
--- a/client/api/design/power_data.js
+++ b/client/api/design/power_data.js
@@ -1,8 +1,18 @@
+import ArrayUtil from './../../../shared/utils/array';
+import DateRange from './../../../shared/utils/date_range';
+
class PowerDataApi {
static index(params){
- return Promise.resolve({
-
+ return jQuery.ajax({
+ url: '/data/power_data/' + params.house_id + ".json",
+ dataType: 'json'
+ }).then((res)=>{
+ return res.data.filter((power_datum)=>{
+ return ArrayUtil.any(params.dates, (range)=>{
+ return DateRange.lte(range[0], power_datum.time) && DateRange.gte(range[1], power_datum.time)
+ });
+ });
});
}
diff --git a/client/config/design/app.js b/client/config/design/app.js
index ca5bc53..df46f77 100644
--- a/client/config/design/app.js
+++ b/client/config/design/app.js
@@ -1,6 +1,6 @@
import Styles from 'config/styles';
import Templates from 'config/templates';
-import app from './../app';
+import app from './../../app';
Promise.all([
Templates.sync(),
diff --git a/client/config/design/style.js b/client/config/design/style.js
index 805fb34..5a41f1a 100644
--- a/client/config/design/style.js
+++ b/client/config/design/style.js
@@ -1,5 +1,5 @@
// Vendor Stylesheets
require('bootstrap/dist/css/bootstrap.min.css');
require('font-awesome/css/font-awesome.min.css');
-require(__dirname + '/d3/chart.scss');
+require(__dirname + '/../../d3/chart.scss');
diff --git a/client/config/design/styles.js b/client/config/design/styles.js
index 2b84209..ad8f27d 100644
--- a/client/config/design/styles.js
+++ b/client/config/design/styles.js
@@ -1,9 +1,8 @@
-import sass from 'sass';
-
const STYLE_ROUTES = Object.freeze({
energy: 'dashboard/energy/energy.scss',
- layout: 'dashboard/energy/layout.scss',
- power: 'dashboard/energy/power.scss'
+ layout: 'dashboard/layout/layout.scss',
+ power: 'dashboard/power/power.scss',
+ app: 'dashboard/app.scss'
});
class Styles {
@@ -13,23 +12,31 @@ class Styles {
css = '';
for (var view in STYLE_ROUTES){
var done = new Promise((fnResolve, fnReject)=>{
- jQuery.ajax({
- url: STYLE_ROUTES[view]
- }).done((scss)=>{
- sass.compile(scss, (result)=>{
- css += result;
- fnResolve()
- });
- });
+ Styles.addCss(view, fnResolve)
+ }).then((result)=>{
+ css += result;
});
all.push(done);
}
return Promise.all(all)
.then(()=>{
- document.write(``);
+ jQuery('head').append(``);
});
}
+ static addCss(view, fnResolve){
+ return jQuery.ajax({
+ url: STYLE_ROUTES[view]
+ }).then((scss)=>{
+ var sass = new Sass();
+ if (!scss) return fnResolve("");
+ sass.compile(scss, (result, a)=>{
+ fnResolve(result.text)
+ });
+ });
+ }
+
}
+export default Styles;
diff --git a/client/config/design/templates.js b/client/config/design/templates.js
index 24c043f..745b232 100644
--- a/client/config/design/templates.js
+++ b/client/config/design/templates.js
@@ -1,13 +1,21 @@
import rt from 'react-templates';
+import React from 'react';
+import _ from 'lodash';
+
import Energy from './../../dashboard/energy/energy';
import Power from './../../dashboard/power/power';
const TEMPLATE_ROUTES = Object.freeze({
- energy: 'dashboard/energy/energy.html',
- layout: 'dashboard/energy/layout.html',
- power: 'dashboard/energy/power.html'
+ energy: 'dashboard/energy/energy.rt',
+ layout: 'dashboard/layout/layout.rt',
+ power: 'dashboard/power/power.rt'
});
+const COMPONENTS = {
+ Power: Power,
+ Energy: Energy
+};
+
var TEMPLATES = {};
class Templates {
@@ -16,13 +24,7 @@ class Templates {
var all = [];
for (var view in TEMPLATE_ROUTES){
var done = new Promise((fnResolve, fnReject)=>{
- jQuery.ajax({
- url: TEMPLATE_ROUTES[view]
- }).done((template)=>{
- eval(rt.convertTemplateToReact(template, {modules: 'none'}));
- TEMPLATES[view] = eval(view);
- fnResolve();
- });
+ Templates.evalTemplate(view, fnResolve);
});
all.push(done);
}
@@ -33,4 +35,25 @@ class Templates {
return TEMPLATES[view];
}
+ static evalTemplate(view, fnResolve){
+ jQuery.ajax({
+ url: TEMPLATE_ROUTES[view]
+ }).done((template)=>{
+ var code = rt.convertTemplateToReact(template, {modules: 'none', name: view}),
+ context = {};
+ code = code.replace('var '+view+' = ', 'context.'+view+' = ');
+ new Function('with(this){ ' + code + ' } ').call({
+ Energy: Energy,
+ Power: Power,
+ context: context,
+ '_': _,
+ 'React': React
+ });
+ TEMPLATES[view] = context[view];
+ fnResolve();
+ });
+ }
+
}
+
+export default Templates;
diff --git a/client/config/design/webpack.js b/client/config/design/webpack.js
index e7474d5..2ebdff8 100644
--- a/client/config/design/webpack.js
+++ b/client/config/design/webpack.js
@@ -1,20 +1,20 @@
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import webpack from 'webpack';
-const ROOT = __dirname + '/../../../';
+const CLIENT = __dirname + '/../..';
+const ROOT = CLIENT + '/..';
module.exports = {
entry: {
- app: ROOT + 'client/config/app',
- style: ROOT + 'client/config/style'
+ app: CLIENT + '/config/design/app',
+ style: CLIENT + '/config/design/style'
},
- devtool: 'source-map',
output: {
filename: '[name].js',
- path: ROOT + 'client/build/design/assets'
+ path: CLIENT + '/build/design/assets'
},
module: {
- loaders: [
+ loaders: [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader", "raw-loader!sass-loader")
@@ -22,15 +22,17 @@ module.exports = {
test: /\.css$/,
loader: ExtractTextPlugin.extract("style-loader", "raw-loader")
}, {
- test: /\.js$/,
- loader: 'babel'
- }
- ]
+ test: /\.js$/,
+ loader: 'babel'
+ }, {
+ test: /\.json$/,
+ loader: 'json'
+ }
+ ]
},
sassLoader: {
- includePaths: [ROOT + 'client', ROOT + 'node_modules']
+ includePaths: [CLIENT, ROOT + '/node_modules']
},
- // Use the plugin to specify the resulting filename (and add needed behavior to the compiler)
plugins: [
new ExtractTextPlugin("style.css", {
allChunks: true
@@ -39,6 +41,10 @@ module.exports = {
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
+ }),
+ new webpack.ProvidePlugin({
+ d3: "d3",
+ "window.d3": "d3"
})
],
node: {
@@ -46,8 +52,8 @@ module.exports = {
},
resolve: {
alias: {
- api: ROOT + 'client/api/design',
- config: ROOT + 'client/config/design'
+ api: CLIENT + '/api/' + process.env.NODE_ENV,
+ config: CLIENT + '/config/' + process.env.NODE_ENV
}
}
-};
+}
diff --git a/client/config/development/webpack.js b/client/config/development/webpack.js
index d22ac18..f8aca1f 100644
--- a/client/config/development/webpack.js
+++ b/client/config/development/webpack.js
@@ -10,7 +10,7 @@ module.exports = {
},
output: {
filename: '[name].js',
- path: CLIENT + '/build/development'
+ path: CLIENT + '/build/' + process.env.NODE_ENV
},
module: {
loaders: [
@@ -23,6 +23,9 @@ module.exports = {
}, {
test: /\.js$/,
loader: 'babel'
+ }, {
+ test: /\.json$/,
+ loader: 'json'
}
]
},
@@ -45,8 +48,8 @@ module.exports = {
},
resolve: {
alias: {
- api: CLIENT + '/api/development',
- config: CLIENT + '/config/development'
+ api: CLIENT + '/api/' + process.env.NODE_ENV,
+ config: CLIENT + '/config/' + process.env.NODE_ENV
}
}
}
diff --git a/client/config/production/webpack.js b/client/config/production/webpack.js
deleted file mode 100644
index dae28da..0000000
--- a/client/config/production/webpack.js
+++ /dev/null
@@ -1,58 +0,0 @@
-import ExtractTextPlugin from 'extract-text-webpack-plugin';
-import webpack from 'webpack';
-
-const ROOT = __dirname + '/../../../';
-
-module.exports = {
- entry: {
- app: ROOT + 'client/app',
- style: ROOT + 'client/style'
- },
- devtool: 'source-map',
- output: {
- filename: '[name].min.js',
- path: ROOT + 'client/build/production'
- },
- externals: {
- jquery: "$",
- d3: "d3"
- },
- module: {
- loaders: [
- {
- test: /\.scss$/,
- loader: ExtractTextPlugin.extract("style-loader", "raw-loader!sass-loader")
- }, {
- test: /\.css$/,
- loader: ExtractTextPlugin.extract("style-loader", "raw-loader")
- }, {
- test: /\.js$/,
- loader: 'babel'
- }, {
- test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/,
- loader: "url-loader?limit=10000&minetype=application/font-woff"
- }, {
- test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
- loader: "file-loader"
- }
- ]
- },
- sassLoader: {
- includePaths: [ROOT + 'client', ROOT + 'node_modules']
- },
- // Use the plugin to specify the resulting filename (and add needed behavior to the compiler)
- plugins: [
- new ExtractTextPlugin("style.min.css", {
- allChunks: true
- }),
- new webpack.optimize.UglifyJsPlugin({minimize: true}),
- new webpack.ProvidePlugin({
- $: "jquery",
- jQuery: "jquery",
- "window.jQuery": "jquery"
- })
- ],
- node: {
- fs: "empty"
- }
-};
diff --git a/client/config/webpack.js b/client/config/webpack.js
deleted file mode 100644
index ddd0a04..0000000
--- a/client/config/webpack.js
+++ /dev/null
@@ -1,55 +0,0 @@
-import webpack from 'webpack';
-
-const CLIENT = __dirname + '/..';
-const ROOT = CLIENT + '/..';
-
-module.exports = {
- entry: {
- app: CLIENT + '/config/' + process.env.NODE_ENV + '/app',
- style: CLIENT + '/config/' + process.env.NODE_ENV + '/style'
- },
- output: {
- filename: '[name].js',
- path: CLIENT + '/build/' + process.env.NODE_ENV
- },
- module: {
- loaders: [
- {
- test: /\.scss$/,
- loaders: ['style', 'raw', 'sass']
- }, {
- test: /\.css$/,
- loaders: ['style', 'raw']
- }, {
- test: /\.js$/,
- loader: 'babel'
- }, {
- test: /\.json$/,
- loader: 'json'
- }
- ]
- },
- sassLoader: {
- includePaths: [CLIENT, ROOT + '/node_modules']
- },
- plugins: [
- new webpack.ProvidePlugin({
- $: "jquery",
- jQuery: "jquery",
- "window.jQuery": "jquery"
- }),
- new webpack.ProvidePlugin({
- d3: "d3",
- "window.d3": "d3"
- })
- ],
- node: {
- fs: "empty"
- },
- resolve: {
- alias: {
- api: CLIENT + '/api/' + process.env.NODE_ENV,
- config: CLIENT + '/config/' + process.env.NODE_ENV
- }
- }
-}
diff --git a/client/dashboard/layout/layout.js b/client/dashboard/layout/layout.js
index ea8d8c1..8c459f9 100644
--- a/client/dashboard/layout/layout.js
+++ b/client/dashboard/layout/layout.js
@@ -23,7 +23,9 @@ var Layout = React.createClass({
componentDidMount: function() {
var layout = this;
// window.addEventListener('resize', this.handleResize);
+ console.log('a')
House.ensureHouses().then((houses)=>{
+ console.log('b')
layout.setState({
houses: houses,
house: houses[0],
diff --git a/client/models/house.js b/client/models/house.js
index e65ccfa..d8d6eba 100644
--- a/client/models/house.js
+++ b/client/models/house.js
@@ -129,6 +129,7 @@ class House {
if (pd1.time < pd2.time) return -1;
})
.map((data)=>{ return new PowerDatum(data, house); });
+ debugger
});
});
}
diff --git a/gulpfile.babel.js b/gulpfile.babel.js
index 7d38f85..2105d0e 100644
--- a/gulpfile.babel.js
+++ b/gulpfile.babel.js
@@ -37,20 +37,39 @@ gulp.task('compile_react_templates', function() {
// right now, build only available for design.
gulp.task('build', function(done) {
- var config, env;
+ var config, env,
+ gulpCopy = require('gulp-copy');
if (yargs.argv.design){
process.env.NODE_ENV = process.env.NODE_ENV || 'design';
} else {
throw new gutil.PluginError("webpack", "Must include '--production' or '--design' option.");
}
- config = require(`${__dirname}/client/config/webpack.js`);
+ config = require(`${__dirname}/client/config/${process.env.NODE_ENV}/webpack.js`);
// run webpack
webpack(config, function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({
// output options
}));
+ if (yargs.argv.design){
+ gulp.src([
+ `client/app.scss`
+ ]).pipe(gulpCopy(`client/build/design/dashboard`, {prefix: 1}));
+ gulp.src([
+ `client/dashboard/layout/layout.rt`,
+ `client/dashboard/layout/layout.scss`,
+ ]).pipe(gulpCopy(`client/build/design/dashboard/layout`, {prefix: 3}));
+ gulp.src([
+ `client/dashboard/energy/energy.rt`,
+ `client/dashboard/energy/energy.scss`,
+ ]).pipe(gulpCopy(`client/build/design/dashboard/energy`, {prefix: 3}));
+ gulp.src([
+ `client/dashboard/power/power.rt`,
+ `client/dashboard/power/power.scss`,
+ ]).pipe(gulpCopy(`client/build/design/dashboard/power`, {prefix: 3}));
+ }
+
done();
});
});
diff --git a/npm-debug.log b/npm-debug.log
deleted file mode 100644
index f818a33..0000000
--- a/npm-debug.log
+++ /dev/null
@@ -1,45 +0,0 @@
-0 info it worked if it ends with ok
-1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
-2 info using npm@3.5.3
-3 info using node@v5.4.1
-4 verbose run-script [ 'prestart', 'start', 'poststart' ]
-5 info lifecycle spike_proto@0.0.0~prestart: spike_proto@0.0.0
-6 silly lifecycle spike_proto@0.0.0~prestart: no script for prestart, continuing
-7 info lifecycle spike_proto@0.0.0~start: spike_proto@0.0.0
-8 verbose lifecycle spike_proto@0.0.0~start: unsafe-perm in lifecycle true
-9 verbose lifecycle spike_proto@0.0.0~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/home/eric/Code/spike2/node_modules/.bin:/home/eric/.rvm/gems/ruby-1.9.3-p484@oroeco_dev/bin:/home/eric/.rvm/gems/ruby-1.9.3-p484@global/bin:/home/eric/.rvm/rubies/ruby-1.9.3-p484/bin:/home/eric/.rvm/bin:/home/eric/bin:/usr/local/heroku/bin:/home/eric/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/lampp/bin
-10 verbose lifecycle spike_proto@0.0.0~start: CWD: /home/eric/Code/spike2
-11 silly lifecycle spike_proto@0.0.0~start: Args: [ '-c', 'babel-node ./server/app.express.js' ]
-12 silly lifecycle spike_proto@0.0.0~start: Returned: code: 1 signal: null
-13 info lifecycle spike_proto@0.0.0~start: Failed to exec start script
-14 verbose stack Error: spike_proto@0.0.0 start: `babel-node ./server/app.express.js`
-14 verbose stack Exit status 1
-14 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:232:16)
-14 verbose stack at emitTwo (events.js:87:13)
-14 verbose stack at EventEmitter.emit (events.js:172:7)
-14 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
-14 verbose stack at emitTwo (events.js:87:13)
-14 verbose stack at ChildProcess.emit (events.js:172:7)
-14 verbose stack at maybeClose (internal/child_process.js:821:16)
-14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
-15 verbose pkgid spike_proto@0.0.0
-16 verbose cwd /home/eric/Code/spike2
-17 error Linux 3.19.0-49-generic
-18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
-19 error node v5.4.1
-20 error npm v3.5.3
-21 error code ELIFECYCLE
-22 error spike_proto@0.0.0 start: `babel-node ./server/app.express.js`
-22 error Exit status 1
-23 error Failed at the spike_proto@0.0.0 start script 'babel-node ./server/app.express.js'.
-23 error Make sure you have the latest version of node.js and npm installed.
-23 error If you do, this is most likely a problem with the spike_proto package,
-23 error not with npm itself.
-23 error Tell the author that this fails on your system:
-23 error babel-node ./server/app.express.js
-23 error You can get information on how to open an issue for this project with:
-23 error npm bugs spike_proto
-23 error Or if that isn't available, you can get their info via:
-23 error npm owner ls spike_proto
-23 error There is likely additional logging output above.
-24 verbose exit [ 1, true ]
diff --git a/package.json b/package.json
index 2f6be35..e510fbd 100644
--- a/package.json
+++ b/package.json
@@ -45,6 +45,7 @@
"babel-standalone": "6.4.4",
"gulp": "^3.9.0",
"gulp-util": "3.0.7",
+ "gulp-copy": "0.0.2",
"jasmine-core": "2.4.1",
"karma": "^0.13.19",
"karma-babel-preprocessor": "^6.0.1",
diff --git a/shared/utils/array.js b/shared/utils/array.js
index bc333bf..62b7a84 100644
--- a/shared/utils/array.js
+++ b/shared/utils/array.js
@@ -12,6 +12,17 @@ class ArrayUtil {
return map;
}
+ static any(a, fnCondition){
+ var any = false;
+ for (var elem of a){
+ if (fnCondition(elem)){
+ any = true;
+ break;
+ }
+ }
+ return any;
+ }
+
static all(a, fnCondition){
var all = true;
for (var elem of a){