use react templates loader
This commit is contained in:
@@ -3,15 +3,15 @@
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
import aboutRt from './../../dashboard/about/about.rt.js';
|
||||
import houseRt from './../../dashboard/house/house.rt.js';
|
||||
import layoutRt from './../../dashboard/layout/layout.rt.js';
|
||||
import energyRt from './../../dashboard/energy/energy.rt.js';
|
||||
import energyGraphRt from './../../dashboard/energy/graph/graph.rt.js';
|
||||
import energyTableRt from './../../dashboard/energy/table/table.rt.js';
|
||||
import powerRt from './../../dashboard/power/power.rt.js';
|
||||
import powerGraphRt from './../../dashboard/power/graph/graph.rt.js';
|
||||
import powerTableRt from './../../dashboard/power/table/table.rt.js';
|
||||
import aboutRt from './../../dashboard/about/about.rt';
|
||||
import houseRt from './../../dashboard/house/house.rt';
|
||||
import layoutRt from './../../dashboard/layout/layout.rt';
|
||||
import energyRt from './../../dashboard/energy/energy.rt';
|
||||
import energyGraphRt from './../../dashboard/energy/graph/graph.rt';
|
||||
import energyTableRt from './../../dashboard/energy/table/table.rt';
|
||||
import powerRt from './../../dashboard/power/power.rt';
|
||||
import powerGraphRt from './../../dashboard/power/graph/graph.rt';
|
||||
import powerTableRt from './../../dashboard/power/table/table.rt';
|
||||
|
||||
const TEMPLATES = {
|
||||
about: aboutRt,
|
||||
|
||||
@@ -23,6 +23,9 @@ module.exports = {
|
||||
}, {
|
||||
test: /\.json$/,
|
||||
loader: 'json'
|
||||
}, {
|
||||
test: /\.rt/,
|
||||
loader: "react-templates-loader"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
export default function () {
|
||||
return React.createElement('div', { 'id': 'about' }, React.createElement('div', { 'className': 'panel panel-default' }, React.createElement('div', { 'className': 'panel-heading' }, 'About'), React.createElement('div', { 'className': 'panel-body' }, React.createElement('p', {}, 'This is a Spike bundle prototype using the following lirbaries:'), React.createElement('ul', {}, React.createElement('li', {}, 'React'), React.createElement('li', {}, 'React Templates'), React.createElement('li', {}, 'React Router'), React.createElement('li', {}, 'LokiJs - persisting API calls to indexedDb'), React.createElement('li', {}, 'Webpack - hot mode developing and app bundling'), React.createElement('li', {}, 'Babel - ES6 transpiler')), React.createElement('p', {}, 'The demo app consists of a dataset of 10 houses and 10 years of randomly generated power consumption and production at 15 minute intervals. You can toggle between different houses and time periods to compare and contrast the dataset.'), React.createElement('p', {}, 'Select a house below to get started.'))));
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
export default function () {
|
||||
return React.createElement('div', { 'id': 'energy_view' }, this.state.loading_energy_data ? React.createElement('div', { 'className': 'alert alert-warning' }, '\n Retrieving energy data...\n ') : null, this.props.view === 'graph' ? React.createElement('div', {}, React.createElement('h4', {}, 'Select Data'), React.createElement('div', {
|
||||
'className': 'btn-group',
|
||||
'role': 'group'
|
||||
}, React.createElement('button', {
|
||||
'data-param': 'graph_attr',
|
||||
'data-value': 'consumption',
|
||||
'className': _.keys(_.pick({ active: this.state.graph_attr === 'consumption' }, _.identity)).join(' ') + ' ' + 'btn btn-primary',
|
||||
'onClick': this.setAttr,
|
||||
'type': 'button'
|
||||
}, 'Consumption'), React.createElement('button', {
|
||||
'data-param': 'graph_attr',
|
||||
'data-value': 'production',
|
||||
'className': _.keys(_.pick({ active: this.state.graph_attr === 'production' }, _.identity)).join(' ') + ' ' + 'btn btn-primary',
|
||||
'onClick': this.setGraphAttr,
|
||||
'type': 'button'
|
||||
}, 'Production'))) : null, '\n ', this.props.children, '\n');
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
export default function () {
|
||||
return React.createElement('div', { 'id': 'energy_graph' });
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
function repeatEnergy_datum1(energy_datum, energy_datumIndex) {
|
||||
return React.createElement('tr', { 'key': energy_datum.scoped_id }, React.createElement('td', {}), React.createElement('td', {}, energy_datum.day_to_s), React.createElement('td', {}, energy_datum.consumption_to_s), React.createElement('td', {}, energy_datum.production_to_s));
|
||||
}
|
||||
export default function () {
|
||||
return this.context.house ? React.createElement('table', { 'className': 'table' }, React.createElement('thead', {}, React.createElement('tr', {}, React.createElement('th', {}), React.createElement('th', {}, 'Day'), React.createElement('th', {}, 'Consumption (kWh)'), React.createElement('th', {}, 'Production (kWh)'))), React.createElement.apply(this, [
|
||||
'tbody',
|
||||
{},
|
||||
_.map(this.context.house.energy_data, repeatEnergy_datum1.bind(this))
|
||||
])) : null;
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
function repeatYear1(year, yearIndex) {
|
||||
return React.createElement('button', {
|
||||
'data-param': 'year',
|
||||
'data-value': year,
|
||||
'key': 'data-year-' + year,
|
||||
'className': 'btn-info btn btn-sm' + ' ' + _.keys(_.pick({ active: year == this.context.house.state.year }, _.identity)).join(' '),
|
||||
'onClick': this.setParam.bind(this)
|
||||
}, year);
|
||||
}
|
||||
export default function () {
|
||||
return React.createElement('div', { 'id': 'house' }, React.createElement('h4', {}, 'Select dataset:'), React.createElement('div', {
|
||||
'className': 'btn-group',
|
||||
'role': 'group'
|
||||
}, React.createElement('button', {
|
||||
'data-param': 'dataset',
|
||||
'data-value': 'energy',
|
||||
'className': _.keys(_.pick({ active: this.energySelected() }, _.identity)).join(' ') + ' ' + 'btn btn-primary',
|
||||
'onClick': this.setParam.bind(this),
|
||||
'type': 'button'
|
||||
}, 'Daily Energy Statistics'), React.createElement('button', {
|
||||
'data-param': 'dataset',
|
||||
'data-value': 'power',
|
||||
'className': _.keys(_.pick({ active: this.powerSelected() }, _.identity)).join(' ') + ' ' + 'btn btn-primary',
|
||||
'onClick': this.setParam.bind(this),
|
||||
'type': 'button'
|
||||
}, '15-minute Power Statistics')), React.createElement('h4', {}, 'View as:'), React.createElement('div', {
|
||||
'className': 'btn-group',
|
||||
'role': 'group'
|
||||
}, React.createElement('button', {
|
||||
'data-param': 'view',
|
||||
'data-value': 'graph',
|
||||
'className': _.keys(_.pick({ active: this.graphSelected() }, _.identity)).join(' ') + ' ' + 'btn btn-primary',
|
||||
'onClick': this.setParam.bind(this),
|
||||
'type': 'button'
|
||||
}, 'Graph'), React.createElement('button', {
|
||||
'data-param': 'view',
|
||||
'data-value': 'table',
|
||||
'className': _.keys(_.pick({ active: this.tableSelected() }, _.identity)).join(' ') + ' ' + 'btn btn-primary',
|
||||
'onClick': this.setParam.bind(this),
|
||||
'type': 'button'
|
||||
}, 'Table')), this.context.house ? React.createElement('div', {}, React.createElement('h4', {}, 'Select dates:'), React.createElement.apply(this, [
|
||||
'div',
|
||||
{ 'className': 'btn-group' },
|
||||
_.map(this.context.house.years, repeatYear1.bind(this))
|
||||
])) : null, React.createElement('br', {}), '\n\n ', this.props.children, '\n');
|
||||
};
|
||||
@@ -1,23 +0,0 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
function repeatHouse1(house, houseIndex) {
|
||||
return React.createElement('option', {
|
||||
'value': house.data.id,
|
||||
'key': house.scoped_id
|
||||
}, house.data.name);
|
||||
}
|
||||
export default function () {
|
||||
return React.createElement('div', { 'id': 'layout' }, this.state.requesting_data ? React.createElement('div', { 'className': 'alert alert-warning' }, 'Retrieving houses...') : null, React.createElement('h4', {}, 'Select household:'), this.state.houses ? React.createElement.apply(this, [
|
||||
'select',
|
||||
{
|
||||
'id': 'houses_select',
|
||||
'className': 'form-control',
|
||||
'onChange': this.setHouse.bind(this),
|
||||
'value': this.props.params.house_id
|
||||
},
|
||||
_.map(this.state.houses, repeatHouse1.bind(this))
|
||||
]) : null, this.state.house ? React.createElement('button', {
|
||||
'onClick': this.refreshData.bind(this),
|
||||
'className': 'btn btn-xs btn-default'
|
||||
}, 'Refresh House Data') : null, '\n\n ', this.props.children, '\n');
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
export default function () {
|
||||
return React.createElement('div', { 'id': 'power_graph' });
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
function repeatMonth1(month, monthIndex) {
|
||||
return React.createElement('button', {
|
||||
'data-param': 'month',
|
||||
'data-value': month,
|
||||
'key': 'data-month-' + month,
|
||||
'className': 'btn-warning btn btn-sm' + ' ' + _.keys(_.pick({ active: month === this.context.house.state.month }, _.identity)).join(' '),
|
||||
'onClick': this.setParam.bind(this)
|
||||
}, month);
|
||||
}
|
||||
export default function () {
|
||||
return React.createElement('div', { 'id': 'power_view' }, React.createElement.apply(this, [
|
||||
'div',
|
||||
{ 'className': 'btn-group' },
|
||||
this.context.house ? _.map(this.context.house.availableMonths(), repeatMonth1.bind(this)) : null
|
||||
]), this.state.loading_power_data ? React.createElement('div', { 'className': 'alert alert-warning' }, '\n Retrieving power data...\n ') : null, React.createElement('div', { 'id': 'power_date_setter' }), '\n ', this.props.children, '\n');
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
function repeatPower_datum1(power_datum, power_datumIndex) {
|
||||
return React.createElement('tr', { 'key': power_datum.scoped_id }, React.createElement('td', {}), React.createElement('td', {}, power_datum.time_to_s), React.createElement('td', {}, power_datum.consumption_to_s), React.createElement('td', {}, power_datum.production_to_s));
|
||||
}
|
||||
export default function () {
|
||||
return this.context.house ? React.createElement('table', { 'className': 'table' }, React.createElement('thead', {}, React.createElement('tr', {}, React.createElement('th', {}), React.createElement('th', {}, 'Time'), React.createElement('th', {}, 'Consumption (W)'), React.createElement('th', {}, 'Production (W)'))), React.createElement.apply(this, [
|
||||
'tbody',
|
||||
{},
|
||||
_.map(this.context.house.power_data, repeatPower_datum1.bind(this))
|
||||
])) : null;
|
||||
};
|
||||
Reference in New Issue
Block a user