finalize design package

This commit is contained in:
Eric Hulburd
2016-02-23 00:52:24 -06:00
parent a0cda06672
commit ce9cd68470
18 changed files with 149 additions and 211 deletions

View File

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

View File

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

View File

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

View File

@@ -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(),

View File

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

View File

@@ -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(`<style>${css}</style>`);
jQuery('head').append(`<style>${css}</style>`);
});
}
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;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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],

View File

@@ -129,6 +129,7 @@ class House {
if (pd1.time < pd2.time) return -1;
})
.map((data)=>{ return new PowerDatum(data, house); });
debugger
});
});
}