From 22eb51f5802f9e655a0fa68ea37c3e378a171dd5 Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 2 May 2019 15:08:46 -0400 Subject: [PATCH 01/54] Add MV route and container files --- src/components/SideBarDetail/index.js | 6 +++ src/containers/Performance/actions.js | 10 ++++ src/containers/Performance/constants.js | 3 ++ src/containers/Performance/index.js | 69 +++++++++++++++++++++++++ src/routes.js | 4 ++ 5 files changed, 92 insertions(+) create mode 100644 src/containers/Performance/actions.js create mode 100644 src/containers/Performance/constants.js create mode 100644 src/containers/Performance/index.js diff --git a/src/components/SideBarDetail/index.js b/src/components/SideBarDetail/index.js index bf06ec46..0b181771 100644 --- a/src/components/SideBarDetail/index.js +++ b/src/components/SideBarDetail/index.js @@ -210,6 +210,12 @@ export default function SideBarDetail({ building, children, contacts, user }) { Reports +
  • + + {blocnoteSVG} + Performance + +
  • + + +
    + {/* Map, Construction table & run-sim btn */} +
    +
    + {' '} +
    +
    + {' '} +
    +
    +
    {/* Container */} + + ); + } +} + +Performance.propTypes = { + building: buildingDetailPropTypes, + loadPerformance: PropTypes.func, +}; + +const mapDispatchToProps = dispatch => ( + bindActionCreators({ + loadPerformance, + }, dispatch) +); + +const mapStateToProps = state => ({ + performance: state.performance, + eng: state.eng, +}); + +export default connect(mapStateToProps, mapDispatchToProps)(Performance); diff --git a/src/routes.js b/src/routes.js index 381b8699..9ea75214 100644 --- a/src/routes.js +++ b/src/routes.js @@ -23,6 +23,7 @@ import Sensors from './containers/Sensors/Sensors'; import SensorInstall from './containers/Sensors/SensorInstall'; import GatewayList from './components/SensorInstall/GatewayList'; import BuildingReports from './containers/BuildingReports'; +import Performance from './containers/Performance'; import Wrapper from './containers/Wrapper'; import { BGroupOverview, BGroup } from './containers/BGroup'; import NavOnly from './screens/NavOnly/NavOnly'; @@ -57,6 +58,9 @@ export default ( + + + -- GitLab From e79f8ee5e97ae8850e561bbaf3aaaf1f416ec712 Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 3 May 2019 12:11:41 -0400 Subject: [PATCH 02/54] Add actions, constants, index file --- src/containers/Performance/actions.js | 18 +++++++++++------ src/containers/Performance/constants.js | 9 ++++++--- src/containers/Performance/index.js | 27 ++++++++++++++++++------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 4e889fc7..13e51833 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -1,10 +1,16 @@ import { - LOAD_PERFORMANCE, - PERFORMANCE_SUCCESS, - PERFORMANCE_ERROR, + LOAD_OCCUPANTS, + OCCUPANTS_SUCCESS, + OCCUPANTS_ERROR, + LOAD_THERMAL_COMFORT, + THERMAL_COMFORT_SUCCESS, + THERMAL_COMFORT_ERROR, } from './constants'; import { makeActionCreator } from '../../utils/reduxHelpers'; -export const loadPerformance = makeActionCreator(LOAD_PERFORMANCE, 'buildingId'); -export const performanceLoaded = makeActionCreator(PERFORMANCE_SUCCESS, 'payload'); -export const performanceLoadingError = makeActionCreator(PERFORMANCE_ERROR, 'error'); +export const loadOccupants = makeActionCreator(LOAD_OCCUPANTS, 'buildingId'); +export const occupantsLoaded = makeActionCreator(OCCUPANTS_SUCCESS, 'payload'); +export const occupantsLoadingError = makeActionCreator(OCCUPANTS_ERROR, 'error'); +export const loadThermalComfort = makeActionCreator(LOAD_THERMAL_COMFORT, 'buildingId'); +export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCESS, 'payload'); +export const thermalComfortLoadingError = makeActionCreator(THERMAL_COMFORT_ERROR, 'error'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index b3b8ea32..059b46d5 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -1,3 +1,6 @@ -export const LOAD_PERFORMANCE = 'LOAD_PERFORMANCE'; -export const PERFORMANCE_SUCCESS = 'PERFORMANCE_SUCCESS'; -export const PERFORMANCE_ERROR = 'PERFORMANCE_ERROR'; +export const LOAD_OCCUPANTS = 'LOAD_OCCUPANTS'; +export const OCCUPANTS_SUCCESS = 'OCCUPANTS_SUCCESS'; +export const OCCUPANTS_ERROR = 'OCCUPANTS_ERROR'; +export const LOAD_THERMAL_COMFORT = 'LOAD_THERMAL_COMFORT'; +export const THERMAL_COMFORT_SUCCESS = 'THERMAL_COMFORT_SUCCESS'; +export const THERMAL_COMFORT_ERROR = 'THERMAL_COMFORT_ERROR'; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 5bf07cbf..8e921c03 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -3,10 +3,13 @@ import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { - loadPerformance, + loadOccupants, + loadThermalComfort, } from './actions'; import buildingDetailPropTypes from '../../containers/Building/propTypes'; import LinkBarDetail from '../../components/LinkBarDetail'; +import Occupants from '../../components/Performance/Occupants'; +import ThermalComfort from '../../components/Performance/ThermalComfort'; class Performance extends Component { @@ -14,12 +17,15 @@ class Performance extends Component { super(props); this.state = { weather: 'jfk', + occupants: null, + thermalComfort: null, }; } componentDidMount() { const buildingId = this.props.building.building_id; - this.props.loadPerformance(buildingId); + this.props.loadOccupants(buildingId); + this.props.loadThermalComfort(buildingId); } render() { @@ -38,10 +44,14 @@ class Performance extends Component { {/* Map, Construction table & run-sim btn */}
    - {' '} +
    - {' '} +
    {/* Container */} @@ -52,17 +62,20 @@ class Performance extends Component { Performance.propTypes = { building: buildingDetailPropTypes, - loadPerformance: PropTypes.func, + loadOccupants: PropTypes.func, + loadThermalComfort: PropTypes.func, }; const mapDispatchToProps = dispatch => ( bindActionCreators({ - loadPerformance, + loadOccupants, + loadThermalComfort, }, dispatch) ); const mapStateToProps = state => ({ - performance: state.performance, + occupants: state.occupants, + thermalComfort: state.thermalComfort, eng: state.eng, }); -- GitLab From 9d58266674e1ff899aa8c2b4d47da3ae38d9b4ec Mon Sep 17 00:00:00 2001 From: akkking Date: Tue, 7 May 2019 10:18:38 -0400 Subject: [PATCH 03/54] Add Occupants, ThermalComfort components and index container --- src/components/Performance/Occupants.js | 96 ++++++++++++ src/components/Performance/ThermalComfort.js | 145 +++++++++++++++++++ src/components/Performance/styles.css | 13 ++ src/containers/Performance/index.js | 7 +- 4 files changed, 257 insertions(+), 4 deletions(-) create mode 100644 src/components/Performance/Occupants.js create mode 100644 src/components/Performance/ThermalComfort.js create mode 100644 src/components/Performance/styles.css diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js new file mode 100644 index 00000000..5c2f1a43 --- /dev/null +++ b/src/components/Performance/Occupants.js @@ -0,0 +1,96 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { + Table, + Input, + Button, +} from 'reactstrap'; +import './styles.css'; + + +class Occupants extends Component { + constructor(props) { + super(props); + this.state = { + totalUnits: props.totalUnits, + preVacantUnits: props.preVacantUnits, + postVacantUnits: props.postVacantUnits, + }; + } + + handleOnChange = () => { + this.setState({ displayChart: !this.state.displayChart }); + } + + render() { + return ( +
    +
    +
    +

    + Occupants +

    +
    +
    + + {' '} +
    +
    + + + + + + + + + + + + + +
    + Number of Units + + +
    + Vacant Units (Pre-retrofit) + + +
    + Vacant Units (Post-retrofit) + + +
    +
    + ); + } +} + +Occupants.propTypes = { + totalUnits: PropTypes.number, + preVacantUnits: PropTypes.number, + postVacantUnits: PropTypes.number, +}; + +Occupants.defaultProps = { + totalUnits: 0, + preVacantUnits: 0, + postVacantUnits: 0, +}; + +export default Occupants; diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js new file mode 100644 index 00000000..fcaa11f5 --- /dev/null +++ b/src/components/Performance/ThermalComfort.js @@ -0,0 +1,145 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { + Table, + Input, + InputGroup, + InputGroupAddon, + Button, +} from 'reactstrap'; +import './styles.css'; + + +class ThermalComfort extends Component { + constructor(props) { + super(props); + this.state = { + preHeatingSetPoint: props.preHeatingSetPoint, + postHeatingSetPoint: props.postHeatingSetPoint, + preCoolingSetPoint: props.preCoolingSetPoint, + postCoolingSetPoint: props.postCoolingSetPoint, + }; + } + + toggleDisplayChart = () => { + this.setState({ displayChart: !this.state.displayChart }); + } + + render() { + return ( +
    +
    +
    +

    + Thermal Comfort +

    +
    +
    + + {' '} +
    +
    + + + + + + + + + + + + + + + + + +
    + Heating Set Point (Pre-retrofit) + + + + + F + + +
    + Heating Set point (Post-retrofit) + + + + + F + + +
    + Cooling Set Point (Pre-retrofit) + + + + + F + + +
    + Cooling Set Point (Post-retrofit) + + + + + F + + +
    +
    + ); + } +} + +ThermalComfort.propTypes = { + preHeatingSetPoint: PropTypes.number, + postHeatingSetPoint: PropTypes.number, + preCoolingSetPoint: PropTypes.number, + postCoolingSetPoint: PropTypes.number, +}; + +export default ThermalComfort; diff --git a/src/components/Performance/styles.css b/src/components/Performance/styles.css new file mode 100644 index 00000000..97b24ba8 --- /dev/null +++ b/src/components/Performance/styles.css @@ -0,0 +1,13 @@ +.test { + display: block !important; +} + +.header { + margin-bottom: 25px; + padding-left: 10px; +} + +.rightAlign { + text-align: right; + padding-right: 28px !important; +} diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 8e921c03..f4ec518d 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -40,15 +40,14 @@ class Performance extends Component { links={[]} /> -
    - {/* Map, Construction table & run-sim btn */} +
    -
    +
    -
    +
    -- GitLab From db898ea5acc2f31a918724f48e26f801d8243f6a Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 9 May 2019 12:25:50 -0400 Subject: [PATCH 04/54] Update Occupants and Thermal Comfort with modals --- src/components/Performance/Occupants.js | 6 ++ src/components/Performance/ThermalComfort.js | 91 +++++++++++++++++++- src/containers/Performance/index.js | 22 ++++- 3 files changed, 113 insertions(+), 6 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index 5c2f1a43..854dcd9a 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -32,6 +32,12 @@ class Occupants extends Component {
    + {' '}
    + {' '} @@ -130,6 +152,16 @@ class ThermalComfort extends Component { + + Modal title + + This is Modal body! + + + {' '} + + +
    ); } @@ -142,4 +174,59 @@ ThermalComfort.propTypes = { postCoolingSetPoint: PropTypes.number, }; +Modal.propTypes = { + // boolean to control the state of the popover + isOpen: PropTypes.bool, + autoFocus: PropTypes.bool, + // if modal should be centered vertically in viewport + centered: PropTypes.bool, + // corresponds to bootstrap's modal sizes, ie. 'lg' or 'sm' + size: PropTypes.string, + // callback for toggling isOpen in the controlling component + toggle: PropTypes.func, + role: PropTypes.string, // defaults to "dialog" + // used to reference the ID of the title element in the modal + labelledBy: PropTypes.string, + keyboard: PropTypes.bool, + // control backdrop, see http://v4-alpha.getbootstrap.com/components/modal/#options + backdrop: PropTypes.oneOfType([ + PropTypes.bool, + PropTypes.oneOf(['static']), + ]), + // if body of modal should be scrollable when content is long + scrollable: PropTypes.bool, + // external: PropTypes.node, + // called on componentDidMount + onEnter: PropTypes.func, + // called on componentWillUnmount + onExit: PropTypes.func, + // called when done transitioning in + onOpened: PropTypes.func, + // called when done transitioning out + onClosed: PropTypes.func, + className: PropTypes.string, + wrapClassName: PropTypes.string, + modalClassName: PropTypes.string, + backdropClassName: PropTypes.string, + contentClassName: PropTypes.string, + // boolean to control whether the fade transition occurs (default: true) + fade: PropTypes.bool, + cssModule: PropTypes.objectOf, + // zIndex defaults to 1000. + zIndex: PropTypes.oneOfType([ + PropTypes.number, + PropTypes.string, + ]), + // backdropTransition - controls backdrop transition + // timeout is 150ms by default to match bootstrap + // see Fade for more details + backdropTransition: PropTypes.shape, + // modalTransition - controls modal transition + // timeout is 300ms by default to match bootstrap + // see Fade for more details + innerRef: PropTypes.objectOf, + // if modal should be destructed/removed from DOM after closing + unmountOnClose: PropTypes.bool, // defaults to true +}; + export default ThermalComfort; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index f4ec518d..a483bafe 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -17,8 +17,6 @@ class Performance extends Component { super(props); this.state = { weather: 'jfk', - occupants: null, - thermalComfort: null, }; } @@ -29,6 +27,17 @@ class Performance extends Component { } render() { + const occupants = { + totalUnits: null, + preVacantUnits: null, + postVacantUnits: null, + }; + const thermalComfort = { + preHeatingSetPoint: null, + postHeatingSetPoint: null, + preCoolingSetPoint: null, + postCoolingSetPoint: null, + }; return (
    -- GitLab From 8e093e3a41c6882d3fe1dbe4b74576944c3dcbb3 Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 10 May 2019 14:27:03 -0400 Subject: [PATCH 05/54] Updates to occupants and index --- src/components/Performance/Occupants.js | 50 ++++++++++++++++++++++++- src/containers/Performance/index.js | 2 +- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index 854dcd9a..fa3be3f9 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -1,4 +1,5 @@ import React, { Component } from 'react'; +import Modal from 'react-modal'; import PropTypes from 'prop-types'; import { Table, @@ -8,6 +9,19 @@ import { import './styles.css'; +const customStyles = { + content: { + top: '50%', + left: '50%', + right: 'auto', + bottom: 'auto', + marginRight: '-50%', + transform: 'translate(-50%, -50%)', + }, +}; +// Make sure to bind modal to your appElement (http://reactcommunity.org/react-modal/accessibility/) +Modal.setAppElement('body'); + class Occupants extends Component { constructor(props) { super(props); @@ -15,9 +29,23 @@ class Occupants extends Component { totalUnits: props.totalUnits, preVacantUnits: props.preVacantUnits, postVacantUnits: props.postVacantUnits, + modalIsOpen: false, }; - } + this.openModal = this.openModal.bind(this); + this.afterOpenModal = this.afterOpenModal.bind(this); + this.closeModal = this.closeModal.bind(this); + } + openModal() { + this.setState({ modalIsOpen: true }); + } + afterOpenModal() { + // references are now sync'd and can be accessed. + this.subtitle.style.color = '#f00'; + } + closeModal() { + this.setState({ modalIsOpen: false }); + } handleOnChange = () => { this.setState({ displayChart: !this.state.displayChart }); } @@ -34,7 +62,7 @@ class Occupants extends Component {
    {' '} @@ -47,6 +75,24 @@ class Occupants extends Component { {' '}
    + +

    Hello

    + +
    I am a modal
    +
    + + + + + +
    +
    ); diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index 04a58767..5a356dd3 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -24,8 +24,8 @@ class IncomeStatements extends Component { const obj = { GRDropdownOpen: false, - GRDropdownValue: 'Select Growth Rate', - selectedDropdownId: 0, + GRDropdownId: props.data.growth_rate !== null ? props.data.growth_rate : 0, + GRDropdownValue: props.data.growth_rate !== null ? `${String(props.data.growth_rate * 100)}%` : 'Select Growth Rate', growthRateOptions: [ { id: '-2', key: '-2', name: 'CAGR=1.58%' }, { id: '-1', key: '-1', name: 'Average' }, @@ -127,8 +127,8 @@ class IncomeStatements extends Component { } changeGrowthRate(e) { + this.setState({ GRDropdownId: e.currentTarget.id }); this.setState({ GRDropdownValue: e.currentTarget.textContent }); - this.setState({ selectedDropdownId: e.currentTarget.id }); } buildHeader = () => { @@ -222,7 +222,7 @@ class IncomeStatements extends Component { hist.push(obj); }); const growthRate = {}; - growthRate['growth-rate'] = String(this.state.selectedDropdownId); + growthRate['growth-rate'] = String(this.state.GRDropdownId); hist.push(growthRate); this.props.updateIncomeStatements( this.props.buildingId, diff --git a/src/containers/Blocnote/sagas.js b/src/containers/Blocnote/sagas.js index 59a9aacb..53768134 100644 --- a/src/containers/Blocnote/sagas.js +++ b/src/containers/Blocnote/sagas.js @@ -132,7 +132,7 @@ function* updateBillsSummary(action) { request, SagaRequests.generateURL(url, action), { - method: 'PUT', + method: 'POST', headers: getHeaders(), body: JSON.stringify(action.payload), } -- GitLab From 625338f5406337284f886f61a6719db9af302614 Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 10 May 2019 22:51:21 -0400 Subject: [PATCH 07/54] Update Cost estimation and Saving estimation format --- .../Blocnote/BudgetSimulator/BugetTable.js | 5 +- .../PreliminaryFinance/CostEstimation.js | 57 ++++++++++--------- .../PreliminaryFinance/SavingEstimation.js | 15 ++--- .../PreliminaryFinance/SavingEstimationRow.js | 8 ++- .../PreliminaryFinance/SelectScenario.js | 1 - .../Blocnote/FinancialInputs/index.js | 6 +- 6 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/components/Blocnote/BudgetSimulator/BugetTable.js b/src/components/Blocnote/BudgetSimulator/BugetTable.js index 85f575ee..c44e3a75 100644 --- a/src/components/Blocnote/BudgetSimulator/BugetTable.js +++ b/src/components/Blocnote/BudgetSimulator/BugetTable.js @@ -22,6 +22,7 @@ class BudgetTable extends Component { backgroundColor: '#EEEEEE', color: '#000000', fontWeight: 'bold', + padding: '15px', }; const header = [...['Savings'], ...this.props.savingPotentialList] .map((columnName) => { @@ -67,9 +68,9 @@ class BudgetTable extends Component {
    diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index a483bafe..bae57c91 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -39,7 +39,7 @@ class Performance extends Component { postCoolingSetPoint: null, }; return ( -
    +
    Date: Fri, 10 May 2019 17:16:03 -0400 Subject: [PATCH 06/54] Fix bills summary update issue and show all bill sections --- src/components/Blocnote/FinancialInputs/BillsOverview.js | 7 +++++-- .../Blocnote/FinancialInputs/BillsSummaryTable.js | 4 ++-- .../Blocnote/FinancialInputs/IncomeStatements.js | 8 ++++---- src/containers/Blocnote/sagas.js | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/BillsOverview.js b/src/components/Blocnote/FinancialInputs/BillsOverview.js index 1fa5a241..0c7b04f4 100644 --- a/src/components/Blocnote/FinancialInputs/BillsOverview.js +++ b/src/components/Blocnote/FinancialInputs/BillsOverview.js @@ -17,7 +17,9 @@ class BillsOverview extends Component { this.toggleEstimation = this.toggleEstimation.bind(this); this.changeEstimation = this.changeEstimation.bind(this); const data = {}; + let estimationDropDownValue = 'Select Estimation'; if (Object.keys(this.props.data).length !== 0) { + estimationDropDownValue = this.props.data.estimation_algorithm; ['electric', 'water', 'gas', 'oil'].forEach((billName) => { Object.entries(this.props.data[billName]).forEach((bill) => { const keyName = `${billName}-value-${bill[0]}`; @@ -28,10 +30,10 @@ class BillsOverview extends Component { this.state = { estimationDropdownOpen: false, - estimationDropDownValue: 'Select Estimation', + estimationDropDownValue, estimationOptions: [ { id: 'RoughEstimation', key: 'RoughEstimation', name: 'Rough Estimation' }, - { id: 'Fancy Estimation', key: 'FancyEstimation', name: 'Fancy Estimation' }, + { id: 'FancyEstimation', key: 'FancyEstimation', name: 'Fancy Estimation' }, ], action: null, postBills: data, @@ -243,6 +245,7 @@ class BillsOverview extends Component { BillsOverview.propTypes = { data: PropTypes.shape({ + estimation_algorithm: PropTypes.string, electric: PropTypes.objectOf, electric_user: PropTypes.string, gas: PropTypes.objectOf, diff --git a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js index a165391d..3e4f0730 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js @@ -51,7 +51,7 @@ class BillsSummaryTable extends Component { updateBillsSummary = (billData) => { this.props.updateBillsSummary( this.props.buildingId, - billData, + Object.assign(billData, { utility_type: this.props.billName }), ); this.setState({ action: 'updated' }); } @@ -121,7 +121,7 @@ class BillsSummaryTable extends Component { color: '#999999', }} > - Currently no bill. + Currently no annual charge.
    - {header} diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index 6f561c36..9354b137 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -94,7 +94,7 @@ class CostEstimation extends Component { fontSize: '13px', }; - if (this.state.costEstimation !== null) { + if (this.state.costEstimation.length !== 0) { rows = this.state.costEstimation.map((costItem, id) => { return ( ); }); + } else { + rows = ( + + + + ); } return (
    + {this.props.tableName} - +
    + There is no cost estimation. +
    - - + {rows} - - - - -
    Cost Estimation + + +
    Item Estimated CostOptionOption
    - -
    ); diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js index eaa72e31..b7798b43 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js @@ -52,23 +52,24 @@ class SavingEstimation extends Component { return (
    - +
    - + - + diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js index ca392f04..2602bf5f 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js @@ -33,8 +33,12 @@ class SavingEstimationRow extends Component { console.log(this.state); // eslint-disable-line return ( - ); @@ -131,9 +131,7 @@ class CostEstimation extends Component { borderRight: '1px solid #EEEEEE', }} > -
    - Cost Estimation -
    + Cost Estimation diff --git a/src/components/Blocnote/PreliminaryFinance/DownPayment.js b/src/components/Blocnote/PreliminaryFinance/DownPayment.js index 83180ca6..31081c8e 100644 --- a/src/components/Blocnote/PreliminaryFinance/DownPayment.js +++ b/src/components/Blocnote/PreliminaryFinance/DownPayment.js @@ -13,13 +13,18 @@ class DownPayment extends Component { } render() { + let paymentAmount = 'No data'; + if (this.props.paymentAmount !== null) { + paymentAmount = this.props.paymentAmount; // eslint-disable-line + } + return (

    Downpayment

    - {this.props.paymentAmount} + {paymentAmount}
    ); diff --git a/src/components/Blocnote/PreliminaryFinance/LoanSummary.js b/src/components/Blocnote/PreliminaryFinance/LoanSummary.js index 349923ec..a1337037 100644 --- a/src/components/Blocnote/PreliminaryFinance/LoanSummary.js +++ b/src/components/Blocnote/PreliminaryFinance/LoanSummary.js @@ -9,8 +9,9 @@ import LoanSummaryRow from './LoanSummaryRow'; const LoanSummary = (props) => { let header = []; let rows = []; + let displayData = 'No data'; - if (props.data !== null && props.data !== undefined) { + if (props.data !== undefined && props.data !== null && props.data.length !== 0) { header = props.data[0].map((item, index) => { return ( + + + ); } return ( diff --git a/src/components/Blocnote/PreliminaryFinance/SavingsScheduleChart.js b/src/components/Blocnote/PreliminaryFinance/SavingsScheduleChart.js index 60b1e24d..2b113902 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingsScheduleChart.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingsScheduleChart.js @@ -34,11 +34,9 @@ class SavingsScheduleChart extends Component { }); }); - const renderBarChart = ( -
    -

    - Energy Expense Savings Projection -

    + let displayData = 'No data'; + if (data.length !== 0) { + displayData = ( + ); + } + + + const renderBarChart = ( +
    +

    + Energy Expense Savings Projection +

    + {displayData}
    ); diff --git a/src/components/Blocnote/PreliminaryFinance/TableContent.js b/src/components/Blocnote/PreliminaryFinance/TableContent.js index 48c3b985..690d73ec 100644 --- a/src/components/Blocnote/PreliminaryFinance/TableContent.js +++ b/src/components/Blocnote/PreliminaryFinance/TableContent.js @@ -5,7 +5,7 @@ import PropTypes from 'prop-types'; const TableContent = (props) => { let rows = []; - if (props.rows !== null) { + if (props.rows !== null && Object.keys(props.rows).length !== 0) { rows = props.rows.map((items, index1) => { const cells = items.map((item, index2) => { let cellValue = item; -- GitLab From a5e30daf82c429ac9150bf23f68e17c8e18502cb Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 21 Jun 2019 12:20:15 -0400 Subject: [PATCH 45/54] Fix loan options issues --- .../Blocnote/FinancialInputs/LoanOptions.js | 43 ++++++++----------- .../FinancialInputs/LoanOptionsRow.js | 40 +++++++++++++---- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/LoanOptions.js b/src/components/Blocnote/FinancialInputs/LoanOptions.js index a01e9c54..e535e22c 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptions.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptions.js @@ -19,15 +19,12 @@ class LoanOptions extends Component { this.updateRow = this.updateRow.bind(this); this.handleUpdateLoanOptions = this.handleUpdateLoanOptions.bind(this); this.state = { - loanOptions: props.data, + present: props.present, + loanOptions: props.present ? props.data : props.data.slice(0, 1), + defaultLoanOptions: props.present ? [] : props.data, lenders: props.lenders, noi: props.noi, cash: props.cash, - id: 99, - lender: null, - interest_rate: null, - duration: null, - max_loan_amount: null, loading: props.loading, action: null, messageContent: null, @@ -39,19 +36,19 @@ class LoanOptions extends Component { const emptyFields = []; if (this.state.loanOptions.length > 0) { Object.values(this.state.loanOptions).forEach(loanOption => { - if (loanOption.lender === null && + if ((loanOption.lender === null || loanOption.lender === '') && !emptyFields.includes('Lender')) { emptyFields.push('Lender'); } - if (loanOption.interest_rate === null && + if ((loanOption.interest_rate === null || loanOption.interest_rate === '') && !emptyFields.includes('Interest Rate')) { emptyFields.push('Interest Rate'); } - if (loanOption.duration === null && + if ((loanOption.duration === null || loanOption.duration === '') && !emptyFields.includes('Duration')) { emptyFields.push('Duration'); } - if (loanOption.max_loan_amount === null && + if ((loanOption.max_loan_amount === null || loanOption.max_loan_amount === '') && !emptyFields.includes('Max Loan Amount')) { emptyFields.push('Max Loan Amount'); } @@ -81,24 +78,16 @@ class LoanOptions extends Component { addRow = () => { if (this.validateInputs() === true) { if (this.props.financeOverviewExist === true) { - const loanOption = { - id: this.state.id, - lender: this.state.lender, - interest_rate: this.state.interest_rate, - duration: this.state.duration, - max_loan_amount: this.state.max_loan_amount, - }; const loanOptions = this.state.loanOptions; - loanOptions.push(loanOption); + loanOptions.push({ + id: 0, + lender: this.state.loanOptions[0].lender, + interest_rate: '', + duration: '', + max_loan_amount: '', + }); this.setState({ loanOptions }, () => { console.log(this.state.loanOptions, 'New loan option added!'); // eslint-disable-line - this.setState({ - id: this.state.id + 1, - lender: null, - interest_rate: null, - duration: null, - max_loan_amount: null, - }); }); } else { alert('Please fill in Financial Overview first'); @@ -160,7 +149,7 @@ class LoanOptions extends Component { render() { const header = [ - 'Loan Options', + 'Options', 'Lender', 'Interest Rate', 'Duration', @@ -187,6 +176,7 @@ class LoanOptions extends Component { interestRate={parseFloat(loanOption.interest_rate).toFixed(2)} duration={loanOption.duration} maxLoanAmount={parseFloat(loanOption.max_loan_amount).toFixed(2)} + defaultLoanOptions={this.state.defaultLoanOptions} onDelEvent={this.deleteRow} onChangeEvent={this.updateRow} /> @@ -312,6 +302,7 @@ LoanOptions.propTypes = { textAlign: PropTypes.string, marginBottom: PropTypes.string, }), + present: PropTypes.bool, cash: PropTypes.string, noi: PropTypes.string, lenders: PropTypes.arrayOf, diff --git a/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js b/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js index f4eb6c8d..3cd35054 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js @@ -23,9 +23,13 @@ class LoanOptionsRow extends Component { id: props.id, lender: props.lender, lenders: props.lenders, - interest_rate: props.interestRate, - duration: props.duration, - max_loan_amount: props.maxLoanAmount, + defaultLoanOptions: props.defaultLoanOptions, + interest_rate: props.defaultLoanOptions.length > 0 ? '' : props.interestRate, + interest_rate_placeholder: this.setPlaceholder(props.lender, 'interest_rate'), + duration: props.defaultLoanOptions.length > 0 ? '' : props.duration, + duration_placeholder: this.setPlaceholder(props.lender, 'duration'), + max_loan_amount: props.defaultLoanOptions.length > 0 ? '' : props.maxLoanAmount, + max_loan_amount_placeholder: this.setPlaceholder(props.lender, 'max_loan_amount'), lenderDropdownOpen: false, lenderDropDownValue: props.lender, lenderOptions: props.lenders !== undefined ? props.lenders.map((lender, id) => { @@ -38,10 +42,19 @@ class LoanOptionsRow extends Component { this.props.onDelEvent(this.props.id); } + setPlaceholder = (lender, fieldName) => { + let placeholder = ''; + if (this.props.defaultLoanOptions.length > 0) { + const loanOption = this.props.defaultLoanOptions + .filter(defaultLoanOption => defaultLoanOption.lender === lender); + placeholder = loanOption[0][fieldName]; + } + return placeholder; + } + handleOnChange = (event) => { this.setState({ [event.target.name]: event.target.value }, () => { - console.log(this.state); // eslint-disable-line this.props.onChangeEvent(this.state); }); } @@ -53,11 +66,15 @@ class LoanOptionsRow extends Component { } changeLender(e) { - this.setState({ lenderDropDownValue: e.currentTarget.textContent }, - () => { - console.log(this.state); // eslint-disable-line - this.props.onChangeEvent(this.state); - }); + this.setState({ + lenderDropDownValue: e.currentTarget.textContent, + interest_rate_placeholder: this.setPlaceholder(e.currentTarget.textContent, 'interest_rate'), + duration_placeholder: this.setPlaceholder(e.currentTarget.textContent, 'duration'), + max_loan_amount_placeholder: this.setPlaceholder(e.currentTarget.textContent, 'max_loan_amount'), + }, + () => { + this.props.onChangeEvent(this.state); + }); } render() { @@ -83,6 +100,7 @@ class LoanOptionsRow extends Component { isOpen={this.state.lenderDropdownOpen} toggle={this.toggleLender} className="btn-block" + style={{ marginLeft: '-20px' }} > {this.state.lenderDropDownValue} @@ -98,6 +116,7 @@ class LoanOptionsRow extends Component { type="number" step="any" name="interest_rate" + placeholder={this.state.interest_rate_placeholder} value={parseFloat(this.state.interest_rate)} onChange={this.handleOnChange} style={{ width: '50%', textAlign: 'right' }} @@ -113,6 +132,7 @@ class LoanOptionsRow extends Component { type="number" step="any" name="duration" + placeholder={this.state.duration_placeholder} value={this.state.duration} onChange={this.handleOnChange} style={{ width: '50%', textAlign: 'right' }} @@ -131,6 +151,7 @@ class LoanOptionsRow extends Component { type="number" step="any" name="max_loan_amount" + placeholder={this.state.max_loan_amount_placeholder} value={this.state.max_loan_amount} onChange={this.handleOnChange} style={{ width: '50%', textAlign: 'left' }} @@ -156,6 +177,7 @@ LoanOptionsRow.propTypes = { interestRate: PropTypes.string, duration: PropTypes.string, maxLoanAmount: PropTypes.string, + defaultLoanOptions: PropTypes.arrayOf, onDelEvent: PropTypes.func, lenders: PropTypes.arrayOf, onChangeEvent: PropTypes.func, -- GitLab From 15f3546e09dcc2477f91feb28cebee10553a96b0 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 21 Jun 2019 15:12:31 -0400 Subject: [PATCH 46/54] Fix save infeasible scenario issue --- .../PreliminaryFinance/InputScenario.js | 5 +++-- .../Blocnote/FinancialInputs/index.js | 8 ++++++++ .../Blocnote/PreliminaryFinance/index.js | 5 +++-- src/containers/Blocnote/reducer.js | 17 +++++++++++++---- src/containers/Performance/reducer.js | 1 - 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/InputScenario.js b/src/components/Blocnote/PreliminaryFinance/InputScenario.js index 396a746e..e7494681 100644 --- a/src/components/Blocnote/PreliminaryFinance/InputScenario.js +++ b/src/components/Blocnote/PreliminaryFinance/InputScenario.js @@ -66,8 +66,8 @@ class InputScenario extends Component { this.state.messageStyle = 'default'; } - if (this.props.error && typeof this.props.error === 'object') { - this.state.messageContent = this.props.error.response.statusText; + if (this.props.error && this.props.message !== undefined) { + this.state.messageContent = this.props.message; this.state.messageStyle = 'error'; } @@ -150,6 +150,7 @@ InputScenario.propTypes = { updateScenario: PropTypes.func, error: PropTypes.bool, loading: PropTypes.bool, + message: PropTypes.string, }; export default InputScenario; diff --git a/src/containers/Blocnote/FinancialInputs/index.js b/src/containers/Blocnote/FinancialInputs/index.js index 2d3005e6..229c02b6 100644 --- a/src/containers/Blocnote/FinancialInputs/index.js +++ b/src/containers/Blocnote/FinancialInputs/index.js @@ -113,6 +113,7 @@ class FinancialInputs extends Component { fianceOverview.data.instance.financing_overview_data !== undefined; let cashBalanceData = []; let loanOptionsData = []; + let loanOptionsPresent = false; const billsSummaryData = { gas: [], oil: [], @@ -125,6 +126,10 @@ class FinancialInputs extends Component { } if (loanOptions.data.load === true) { loanOptionsData = loanOptions.data.status; + + if (loanOptions.data.present !== undefined && loanOptions.data.present === true) { + loanOptionsPresent = true; + } } if (Object.keys(billsSummary.data.result.user_bill).length === 0) { Object.entries(billsSummary.data.result).forEach((billSummary, id) => { @@ -198,6 +203,7 @@ class FinancialInputs extends Component { blockStyle={blockStyle} headerStyle={headerStyle} data={cashBalanceData} + error={cashBalance.error} buildingId={this.props.building.building_id} loading={cashBalance.loading} updateCashBalance={this.props.updateCashBalance} @@ -206,6 +212,7 @@ class FinancialInputs extends Component { blockStyle={blockStyle} headerStyle={headerStyle} data={liabilities.data.instance} + error={liabilities.error} buildingId={this.props.building.building_id} loading={liabilities.loading} updateLiabilities={this.props.updateLiabilities} @@ -214,6 +221,7 @@ class FinancialInputs extends Component { blockStyle={blockStyle} headerStyle={headerStyle} data={loanOptionsData} + present={loanOptionsPresent} lenders={loanOptions.data.lenders} noi={parseFloat(loanOptions.data.noi).toFixed(2)} cash={parseFloat(loanOptions.data.cash).toFixed(2)} diff --git a/src/containers/Blocnote/PreliminaryFinance/index.js b/src/containers/Blocnote/PreliminaryFinance/index.js index 5a99d081..4ebe07cf 100644 --- a/src/containers/Blocnote/PreliminaryFinance/index.js +++ b/src/containers/Blocnote/PreliminaryFinance/index.js @@ -32,8 +32,6 @@ class PreliminaryFinance extends Component { const baseURL = `${blocnoteURL}buildings/${this.props.buildingId}/financial-inputs`; const blockStyle = { marginBottom: '40px' }; const headerStyle = { textAlign: 'left', marginBottom: '25px' }; - - console.log(this.props); // eslint-disable-line const { blocnote } = this.props; const { scenario } = blocnote; @@ -62,6 +60,9 @@ class PreliminaryFinance extends Component { scenarioName={scenario.data.instance.name} costs={scenario.data.instance.costs} savings={scenario.data.instance.savings} + error={scenario.error} + loading={scenario.loading} + message={scenario.data.instance.message} baseURL={baseURL} updateScenario={this.props.updateScenario} /> diff --git a/src/containers/Blocnote/reducer.js b/src/containers/Blocnote/reducer.js index c95a1bf7..67c02228 100644 --- a/src/containers/Blocnote/reducer.js +++ b/src/containers/Blocnote/reducer.js @@ -730,16 +730,25 @@ export default function (state = blocnoteInitialState, action) { }, }; - case PreliminaryFinance.UPDATE_SCENARIO_SUCCEEDED: + case PreliminaryFinance.UPDATE_SCENARIO_SUCCEEDED: { + let error = false; + if (action.instance.success !== undefined && action.instance.success === false) { + error = true; + } return { ...state, scenario: { - data: { instance: action.instance }, + data: { + instance: Object.assign( + state.scenario.data.instance, + action.instance + ), + }, loading: false, - error: false, + error, }, }; - + } case PreliminaryFinance.UPDATE_SCENARIO_FAILED: return { ...state, scenario: { diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index eca58f89..f1a64cea 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -64,7 +64,6 @@ const PerformanceInitialState = { }; export default function (state = PerformanceInitialState, action) { - console.log(action); // eslint-disable-line switch (action.type) { case OCCUPANTS_REQUESTED: return { -- GitLab From 9102a9a0b1f96e86316d2e4bdbd11ce92695b9e2 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Tue, 25 Jun 2019 12:24:27 -0400 Subject: [PATCH 47/54] Fix empty Saving estimation issue, and cost estimation key error issue --- .../PreliminaryFinance/CostEstimation.js | 5 +-- .../PreliminaryFinance/InputScenario.js | 5 +-- .../PreliminaryFinance/SavingEstimation.js | 2 -- .../Blocnote/PreliminaryFinance/index.js | 35 ++++++++++++++++++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index 0021b639..9c16e70d 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -12,9 +12,7 @@ class CostEstimation extends Component { super(props); this.addRow = this.addRow.bind(); this.state = { - costEstimation: props.data.map((estimation) => { - return { item: estimation.cost_item, cost: String(estimation.cost) }; - }), + costEstimation: props.data, id: props.data.length, cost_item: null, cost: null, @@ -81,7 +79,6 @@ class CostEstimation extends Component { }); this.setState({ costEstimation }, () => { this.props.updateCostEstimation(this.state.costEstimation); - console.log(costEstimation); // eslint-disable-line }); } diff --git a/src/components/Blocnote/PreliminaryFinance/InputScenario.js b/src/components/Blocnote/PreliminaryFinance/InputScenario.js index e7494681..7d9d63ed 100644 --- a/src/components/Blocnote/PreliminaryFinance/InputScenario.js +++ b/src/components/Blocnote/PreliminaryFinance/InputScenario.js @@ -14,7 +14,9 @@ class InputScenario extends Component { this.handleOnChange = this.handleOnChange.bind(); this.state = { scenarioName: props.scenarioName, - costs: props.costs, + costs: props.costs.map(costItem => { + return Object.assign({}, { item: costItem.cost_item, cost: String(costItem.cost) }); + }), savings: props.savings, loading: false, action: null, @@ -36,7 +38,6 @@ class InputScenario extends Component { return Object.assign({}, saving, { estimated_savings: String(saving.estimated_savings) }); }), }; - console.log(data); // eslint-disable-line this.props.updateScenario( this.props.buildingId, data, diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js index 236ed870..2cc4fb88 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js @@ -21,7 +21,6 @@ class SavingEstimation extends Component { savingEstimation[row.utility_type] = newRow; this.setState({ savingEstimation }, () => { this.props.updateSavingEstimation(this.state.savingEstimation); - console.log(this.state.savingEstimation); // eslint-disable-line }); } @@ -94,7 +93,6 @@ class SavingEstimation extends Component { SavingEstimation.propTypes = { blockStyle: PropTypes.objectOf, - // headerStyle: PropTypes.string, data: PropTypes.objectOf, updateSavingEstimation: PropTypes.func, }; diff --git a/src/containers/Blocnote/PreliminaryFinance/index.js b/src/containers/Blocnote/PreliminaryFinance/index.js index 4ebe07cf..d8ae7557 100644 --- a/src/containers/Blocnote/PreliminaryFinance/index.js +++ b/src/containers/Blocnote/PreliminaryFinance/index.js @@ -48,6 +48,39 @@ class PreliminaryFinance extends Component { temp.push(scenario.data.instance.economics_overview[key]); projectEconomicsContent.push(temp); }); + const savings = { + gas: { + estimated_savings: 0, + used_before_retrofit: false, + used_after_retrofit: false, + utility_type: 'gas', + }, + electric: { + estimated_savings: 0, + used_before_retrofit: false, + used_after_retrofit: false, + utility_type: 'electric', + }, + oil: { + estimated_savings: 0, + used_before_retrofit: false, + used_after_retrofit: false, + utility_type: 'oil', + }, + water: { + estimated_savings: 0, + used_before_retrofit: false, + used_after_retrofit: false, + utility_type: 'water', + }, + }; + + Object.keys(scenario.data.instance.savings).forEach(utilityType => { + if (Object.keys(savings).includes(utilityType)) { + savings[utilityType] = scenario.data.instance.savings[utilityType]; + } + }); + mainContent = (
    Date: Tue, 25 Jun 2019 12:46:33 -0400 Subject: [PATCH 48/54] Fix budget simulator wrong table order issue, fix empty scenario not allowed issue --- .../PreliminaryFinance/InputScenario.js | 36 ++++++++++--------- .../Blocnote/BudgetSimulator/index.js | 8 ++--- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/InputScenario.js b/src/components/Blocnote/PreliminaryFinance/InputScenario.js index 7d9d63ed..474f3898 100644 --- a/src/components/Blocnote/PreliminaryFinance/InputScenario.js +++ b/src/components/Blocnote/PreliminaryFinance/InputScenario.js @@ -26,23 +26,27 @@ class InputScenario extends Component { } handleUpdateScenario = () => { - const data = { - scenario: this.state.scenarioName, - cost: this.state.costs - .filter(costItem => - costItem.item !== '' && costItem.item !== null && costItem.cost !== null && costItem.cost !== 'null') - .map(costItem => { - return Object.assign({}, costItem, { cost: String(costItem.cost) }); + if (this.state.scenarioName === null || this.state.scenarioName === '') { + alert('Please input scenario name!'); + } else { + const data = { + scenario: this.state.scenarioName, + cost: this.state.costs + .filter(costItem => + costItem.item !== '' && costItem.item !== null && costItem.cost !== null && costItem.cost !== 'null') + .map(costItem => { + return Object.assign({}, costItem, { cost: String(costItem.cost) }); + }), + savings: Object.values(this.state.savings).map(saving => { + return Object.assign({}, saving, { estimated_savings: String(saving.estimated_savings) }); }), - savings: Object.values(this.state.savings).map(saving => { - return Object.assign({}, saving, { estimated_savings: String(saving.estimated_savings) }); - }), - }; - this.props.updateScenario( - this.props.buildingId, - data, - ); - this.setState({ action: 'updated' }); + }; + this.props.updateScenario( + this.props.buildingId, + data, + ); + this.setState({ action: 'updated' }); + } } handleOnChange = (event) => { diff --git a/src/containers/Blocnote/BudgetSimulator/index.js b/src/containers/Blocnote/BudgetSimulator/index.js index b23f93a3..68237c1c 100644 --- a/src/containers/Blocnote/BudgetSimulator/index.js +++ b/src/containers/Blocnote/BudgetSimulator/index.js @@ -40,10 +40,10 @@ class BudgetSimulator extends Component { 'budgetSfMax', ]; const tableNames = { - budgetLoanFirst: 'Budget with Loan only', - budgetLoanOnly: 'Budget with Loan first', - budgetSfFirst: 'Budget with SF first', - budgetSfMax: 'Budget with SF maximum', + budgetLoanFirst: 'Budget with Loan First', + budgetLoanOnly: 'Budget with Loan Only', + budgetSfFirst: 'Budget with SF First', + budgetSfMax: 'Budget with SF Maximum', }; const { blocnote } = this.props; -- GitLab From e750d5f31b6b998979d6d612a5b97a3424ac74f3 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Tue, 25 Jun 2019 12:50:53 -0400 Subject: [PATCH 49/54] Fix loan first and loan only wrong order in chart issue --- src/components/Blocnote/BudgetSimulator/BudgetChart.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Blocnote/BudgetSimulator/BudgetChart.js b/src/components/Blocnote/BudgetSimulator/BudgetChart.js index 516b8e71..dad8243b 100644 --- a/src/components/Blocnote/BudgetSimulator/BudgetChart.js +++ b/src/components/Blocnote/BudgetSimulator/BudgetChart.js @@ -28,8 +28,8 @@ class BudgetChart extends Component { this.props.savingPotentialList.forEach((saving, index) => { data.push({ x_name: `${saving * 100}%`, - loan_only: this.props.budgets[0][index], - loan_first: this.props.budgets[1][index], + loan_first: this.props.budgets[0][index], + loan_only: this.props.budgets[1][index], sf_first: this.props.budgets[2][index], sf_max: this.props.budgets[3][index], }); -- GitLab From b784264013f7a241d2bb09c7320ca4d3075a6521 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Tue, 2 Jul 2019 16:14:42 -0400 Subject: [PATCH 50/54] Add scenario dot to Preliminary Finance Chart, Add Xais and Yaxis labels --- package.json | 3 +- .../PreliminaryFinance/BudgetChart.js | 73 +++++++++++++++++-- .../Blocnote/PreliminaryFinance/index.js | 1 + 3 files changed, 71 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 67f057fc..3ef7fc97 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "dom-to-image": "^2.5.2", "highcharts": "^5.0.9", "highcharts-3d": "^0.1.2", + "install": "^0.12.2", "leaflet": "^1.1.0", "lodash.debounce": "^4.0.8", "moment": "^2.20.0", @@ -99,7 +100,7 @@ "react-tooltip": "^3.3.0", "react-transition-group": "^2.2.1", "reactstrap": "^4.8.0", - "recharts": "^0.21.2", + "recharts": "^1.6.2", "redux": "^3.6.0", "redux-saga": "^0.14.2", "whatwg-fetch": "^2.0.3" diff --git a/src/components/Blocnote/PreliminaryFinance/BudgetChart.js b/src/components/Blocnote/PreliminaryFinance/BudgetChart.js index c3346d21..704bc6d4 100644 --- a/src/components/Blocnote/PreliminaryFinance/BudgetChart.js +++ b/src/components/Blocnote/PreliminaryFinance/BudgetChart.js @@ -3,12 +3,14 @@ import PropTypes from 'prop-types'; import { LineChart, Line, + Label, CartesianGrid, XAxis, YAxis, Tooltip, Legend, ResponsiveContainer, + ReferenceDot, } from 'recharts'; @@ -24,13 +26,15 @@ class BudgetChart extends Component { render() { const data = []; + const scenarioSavings = this.props.budgetPlot[0].x * 100; this.props.savingPotentialList.forEach((saving, index) => { data.push({ - x_name: `${saving * 100}%`, + x_name: saving * 100, loan_only: this.props.budgets[0][index], loan_first: this.props.budgets[1][index], sf_first: this.props.budgets[2][index], sf_max: this.props.budgets[3][index], + scenario: null, }); }); @@ -45,26 +49,84 @@ class BudgetChart extends Component { }, }); + const values = { + x: scenarioSavings, + y: this.props.budgetPlot[0].y, + isFront: true, + r: 10, + }; + + const scenarioLabelContent = `Scenario: ${scenarioSavings}%, $${this.props.budgetPlot[0].y}`; const renderLineChart = ( - + } /> + + - - + + + @@ -83,6 +145,7 @@ BudgetChart.propTypes = { value: PropTypes.number, savingPotentialList: PropTypes.arrayOf, budgets: PropTypes.arrayOf, + budgetPlot: PropTypes.arrayOf, }; export default BudgetChart; diff --git a/src/containers/Blocnote/PreliminaryFinance/index.js b/src/containers/Blocnote/PreliminaryFinance/index.js index d8ae7557..dfd32a36 100644 --- a/src/containers/Blocnote/PreliminaryFinance/index.js +++ b/src/containers/Blocnote/PreliminaryFinance/index.js @@ -84,6 +84,7 @@ class PreliminaryFinance extends Component { mainContent = (
    -- GitLab From fbcec37f3f974a0ca2792dde4a69413c20e1e614 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Tue, 2 Jul 2019 16:36:20 -0400 Subject: [PATCH 51/54] Update Budget Simulator chart --- .../Blocnote/BudgetSimulator/BudgetChart.js | 42 ++++++++++++++++--- .../PreliminaryFinance/BudgetChart.js | 8 ---- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/components/Blocnote/BudgetSimulator/BudgetChart.js b/src/components/Blocnote/BudgetSimulator/BudgetChart.js index dad8243b..e56dec04 100644 --- a/src/components/Blocnote/BudgetSimulator/BudgetChart.js +++ b/src/components/Blocnote/BudgetSimulator/BudgetChart.js @@ -8,6 +8,7 @@ import { YAxis, Tooltip, Legend, + Label, ResponsiveContainer, } from 'recharts'; @@ -27,7 +28,7 @@ class BudgetChart extends Component { const data = []; this.props.savingPotentialList.forEach((saving, index) => { data.push({ - x_name: `${saving * 100}%`, + x_name: saving * 100, loan_first: this.props.budgets[0][index], loan_only: this.props.budgets[1][index], sf_first: this.props.budgets[2][index], @@ -38,7 +39,6 @@ class BudgetChart extends Component { const CustomizedLabel = React.createClass({ render() { const { x, y, stroke, value } = this.props; - return ( {value} @@ -49,16 +49,22 @@ class BudgetChart extends Component { const renderLineChart = (
    - + @@ -66,8 +72,32 @@ class BudgetChart extends Component { } /> - - + + + diff --git a/src/components/Blocnote/PreliminaryFinance/BudgetChart.js b/src/components/Blocnote/PreliminaryFinance/BudgetChart.js index 704bc6d4..686724de 100644 --- a/src/components/Blocnote/PreliminaryFinance/BudgetChart.js +++ b/src/components/Blocnote/PreliminaryFinance/BudgetChart.js @@ -118,14 +118,6 @@ class BudgetChart extends Component { bottom: 30, }, }} - margin={{ - right: 30, - bottom: 30, - }} - wrapperStyle={{ - paddingRight: 25, - marginRight: 25, - }} /> -- GitLab From b16eb32bf893464ec9dcd6abd329e7bf2cb908a1 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Wed, 3 Jul 2019 16:37:22 -0400 Subject: [PATCH 52/54] Fix preliminary finance loan first and loan only data issue --- src/components/Blocnote/PreliminaryFinance/BudgetChart.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/BudgetChart.js b/src/components/Blocnote/PreliminaryFinance/BudgetChart.js index 686724de..1ea9de88 100644 --- a/src/components/Blocnote/PreliminaryFinance/BudgetChart.js +++ b/src/components/Blocnote/PreliminaryFinance/BudgetChart.js @@ -30,8 +30,8 @@ class BudgetChart extends Component { this.props.savingPotentialList.forEach((saving, index) => { data.push({ x_name: saving * 100, - loan_only: this.props.budgets[0][index], - loan_first: this.props.budgets[1][index], + loan_first: this.props.budgets[0][index], + loan_only: this.props.budgets[1][index], sf_first: this.props.budgets[2][index], sf_max: this.props.budgets[3][index], scenario: null, -- GitLab From d7b5a27852767b944500d2f9a6119256cb79cd73 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Tue, 9 Jul 2019 11:48:07 -0400 Subject: [PATCH 53/54] Fix loan options problem --- .../Blocnote/FinancialInputs/LoanOptions.js | 26 +++++++++++++++---- .../FinancialInputs/LoanOptionsRow.js | 26 ++++++++++++++++--- .../Blocnote/FinancialInputs/index.js | 6 +++++ 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/LoanOptions.js b/src/components/Blocnote/FinancialInputs/LoanOptions.js index e535e22c..82411f9d 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptions.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptions.js @@ -21,7 +21,7 @@ class LoanOptions extends Component { this.state = { present: props.present, loanOptions: props.present ? props.data : props.data.slice(0, 1), - defaultLoanOptions: props.present ? [] : props.data, + defaultLoanOptions: props.present ? props.defaultLoanOptions : props.data, lenders: props.lenders, noi: props.noi, cash: props.cash, @@ -79,12 +79,26 @@ class LoanOptions extends Component { if (this.validateInputs() === true) { if (this.props.financeOverviewExist === true) { const loanOptions = this.state.loanOptions; + const data = { + interestRate: '', + duration: '', + maxLoanAmount: '', + }; + const newLender = this.state.loanOptions[0].lender; + loanOptions.forEach(loanOption => { + if (loanOption.lender === newLender) { + data.interestRate = loanOption.interest_rate; + data.duration = loanOption.duration; + data.maxLoanAmount = loanOption.max_loan_amount; + } + }); + loanOptions.push({ id: 0, - lender: this.state.loanOptions[0].lender, - interest_rate: '', - duration: '', - max_loan_amount: '', + lender: newLender, + interest_rate: data.interestRate, + duration: data.duration, + max_loan_amount: data.maxLoanAmount, }); this.setState({ loanOptions }, () => { console.log(this.state.loanOptions, 'New loan option added!'); // eslint-disable-line @@ -176,6 +190,7 @@ class LoanOptions extends Component { interestRate={parseFloat(loanOption.interest_rate).toFixed(2)} duration={loanOption.duration} maxLoanAmount={parseFloat(loanOption.max_loan_amount).toFixed(2)} + loanOptions={this.state.loanOptions} defaultLoanOptions={this.state.defaultLoanOptions} onDelEvent={this.deleteRow} onChangeEvent={this.updateRow} @@ -306,6 +321,7 @@ LoanOptions.propTypes = { cash: PropTypes.string, noi: PropTypes.string, lenders: PropTypes.arrayOf, + defaultLoanOptions: PropTypes.arrayOf, data: PropTypes.arrayOf( PropTypes.shape({ duration: PropTypes.string, diff --git a/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js b/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js index 3cd35054..5455a0a7 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js @@ -24,11 +24,11 @@ class LoanOptionsRow extends Component { lender: props.lender, lenders: props.lenders, defaultLoanOptions: props.defaultLoanOptions, - interest_rate: props.defaultLoanOptions.length > 0 ? '' : props.interestRate, + interest_rate: props.interestRate, interest_rate_placeholder: this.setPlaceholder(props.lender, 'interest_rate'), - duration: props.defaultLoanOptions.length > 0 ? '' : props.duration, + duration: props.duration, duration_placeholder: this.setPlaceholder(props.lender, 'duration'), - max_loan_amount: props.defaultLoanOptions.length > 0 ? '' : props.maxLoanAmount, + max_loan_amount: props.maxLoanAmount, max_loan_amount_placeholder: this.setPlaceholder(props.lender, 'max_loan_amount'), lenderDropdownOpen: false, lenderDropDownValue: props.lender, @@ -36,6 +36,10 @@ class LoanOptionsRow extends Component { return { id, key: id, name: lender }; }) : [], }; + this.lender = props.lender; + this.interest_rate = props.interestRate; + this.duration = props.duration; + this.max_loan_amount = props.maxLoanAmount; } onDelEvent() { @@ -66,11 +70,26 @@ class LoanOptionsRow extends Component { } changeLender(e) { + const data = { + interestRate: '', + duration: '', + maxLoanAmount: '', + }; + + if (this.lender === e.currentTarget.textContent) { + data.interestRate = this.interest_rate; + data.duration = this.duration; + data.maxLoanAmount = this.max_loan_amount; + } + this.setState({ lenderDropDownValue: e.currentTarget.textContent, interest_rate_placeholder: this.setPlaceholder(e.currentTarget.textContent, 'interest_rate'), duration_placeholder: this.setPlaceholder(e.currentTarget.textContent, 'duration'), max_loan_amount_placeholder: this.setPlaceholder(e.currentTarget.textContent, 'max_loan_amount'), + interest_rate: data.interestRate, + duration: data.duration, + max_loan_amount: data.maxLoanAmount, }, () => { this.props.onChangeEvent(this.state); @@ -177,6 +196,7 @@ LoanOptionsRow.propTypes = { interestRate: PropTypes.string, duration: PropTypes.string, maxLoanAmount: PropTypes.string, + // loanOptions: PropTypes.arrayOf, defaultLoanOptions: PropTypes.arrayOf, onDelEvent: PropTypes.func, lenders: PropTypes.arrayOf, diff --git a/src/containers/Blocnote/FinancialInputs/index.js b/src/containers/Blocnote/FinancialInputs/index.js index 229c02b6..c35c4734 100644 --- a/src/containers/Blocnote/FinancialInputs/index.js +++ b/src/containers/Blocnote/FinancialInputs/index.js @@ -114,6 +114,7 @@ class FinancialInputs extends Component { let cashBalanceData = []; let loanOptionsData = []; let loanOptionsPresent = false; + let defaultLoanOptions = []; const billsSummaryData = { gas: [], oil: [], @@ -130,6 +131,10 @@ class FinancialInputs extends Component { if (loanOptions.data.present !== undefined && loanOptions.data.present === true) { loanOptionsPresent = true; } + + if (loanOptions.data.default_loan_options !== undefined) { + defaultLoanOptions = loanOptions.data.default_loan_options; + } } if (Object.keys(billsSummary.data.result.user_bill).length === 0) { Object.entries(billsSummary.data.result).forEach((billSummary, id) => { @@ -221,6 +226,7 @@ class FinancialInputs extends Component { blockStyle={blockStyle} headerStyle={headerStyle} data={loanOptionsData} + defaultLoanOptions={defaultLoanOptions} present={loanOptionsPresent} lenders={loanOptions.data.lenders} noi={parseFloat(loanOptions.data.noi).toFixed(2)} -- GitLab From a87b1ed25e54ad3a5149ef9e2474a9bcdf9370a7 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Tue, 9 Jul 2019 12:02:11 -0400 Subject: [PATCH 54/54] Fix Saving Schedule Bar Chart issue --- .../PreliminaryFinance/SavingsScheduleChart.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/SavingsScheduleChart.js b/src/components/Blocnote/PreliminaryFinance/SavingsScheduleChart.js index 2b113902..bf37a171 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingsScheduleChart.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingsScheduleChart.js @@ -44,18 +44,18 @@ class SavingsScheduleChart extends Component { top: 20, bottom: 20, }} > + + + + - - - - - - + + ); -- GitLab
    Saving Estimation -
    UtilityUtility Estimated Savings Used Before Retrofit Used After Retrofit
    - {this.props.utilityName} + + {this.props.utilityName.charAt(0).toUpperCase() + this.props.utilityName.slice(1)}
    diff --git a/src/components/Blocnote/PreliminaryFinance/SelectScenario.js b/src/components/Blocnote/PreliminaryFinance/SelectScenario.js index 44ac0af7..fed9fb54 100644 --- a/src/components/Blocnote/PreliminaryFinance/SelectScenario.js +++ b/src/components/Blocnote/PreliminaryFinance/SelectScenario.js @@ -20,7 +20,6 @@ class SelectScenario extends Component { scenarioDropDownValue: 'Select Scenario', scenarioOptions: [ { id: 'Scenario1', key: 'Scenario1', name: 'Scenario 1' }, - { id: 'Scenario2', key: 'Scenario2', name: 'Scenario 2' }, ], }; } diff --git a/src/containers/Blocnote/FinancialInputs/index.js b/src/containers/Blocnote/FinancialInputs/index.js index 398817c2..73b1596c 100644 --- a/src/containers/Blocnote/FinancialInputs/index.js +++ b/src/containers/Blocnote/FinancialInputs/index.js @@ -129,7 +129,7 @@ class FinancialInputs extends Component { fianceOverview.data.instance.financing_overview_data !== undefined; let cashBalanceData = []; let loanOptionsData = []; - let billsSummaryData = { + const billsSummaryData = { gas: [], oil: [], water: [], @@ -153,7 +153,9 @@ class FinancialInputs extends Component { } }); } else { - billsSummaryData = billsSummary.data.result.user_bill; + Object.keys(billsSummary.data.result.user_bill).forEach((billName) => { + billsSummaryData[billName] = billsSummary.data.result.user_bill[billName]; + }); } if (Object.keys(customerPreference.data).length !== 0) { customerPreferenceData = customerPreference.data.instance; -- GitLab From f4831efc7f78fd162bf6ae45bcecc4b16c449a6a Mon Sep 17 00:00:00 2001 From: akkking Date: Sat, 11 May 2019 00:06:46 -0400 Subject: [PATCH 08/54] Fix scenario saving issue --- src/components/Blocnote/PreliminaryFinance/InputScenario.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Blocnote/PreliminaryFinance/InputScenario.js b/src/components/Blocnote/PreliminaryFinance/InputScenario.js index a31f7c5a..a68406d2 100644 --- a/src/components/Blocnote/PreliminaryFinance/InputScenario.js +++ b/src/components/Blocnote/PreliminaryFinance/InputScenario.js @@ -25,7 +25,9 @@ class InputScenario extends Component { const data = { scenario: this.state.scenarioName, cost: this.state.costs, - savings: Object.values(this.state.savings), + savings: Object.values(this.state.savings).map(saving => { + return Object.assign({}, saving, { estimated_savings: String(saving.estimated_savings) }); + }), }; console.log(data); // eslint-disable-line this.props.updateScenario( -- GitLab From aba14435f3ff2f3da4fbac304d868b7633a584dd Mon Sep 17 00:00:00 2001 From: akkking Date: Wed, 15 May 2019 10:45:24 -0400 Subject: [PATCH 09/54] Move css to separate file --- .../PreliminaryFinance/CostEstimation.js | 17 +++------- .../PreliminaryFinance/InputScenario.js | 31 ++++++++++++++----- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index 9354b137..455cfbeb 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -4,6 +4,7 @@ import { Table, Button, } from 'reactstrap'; +import '../styles.css'; import CostEstimationRow from './CostEstimationRow'; @@ -121,18 +122,10 @@ class CostEstimation extends Component {
    -
    - Cost Estimation + +
    + Cost Estimation +
    { const data = { scenario: this.state.scenarioName, - cost: this.state.costs, + cost: this.state.costs + .filter(costItem => + costItem.item !== '' && costItem.item !== null && costItem.cost !== null && costItem.cost !== 'null') + .map(costItem => { + return Object.assign({}, costItem, { cost: String(costItem.cost) }); + }), savings: Object.values(this.state.savings).map(saving => { return Object.assign({}, saving, { estimated_savings: String(saving.estimated_savings) }); }), @@ -70,8 +75,18 @@ class InputScenario extends Component { if (!this.props.error && !this.props.loading && this.props.data !== null && this.state.action !== null) { - messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); - messageStyle = this.props.successMessageStyle; + // messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); + // messageStyle = this.props.successMessageStyle; + messageContent = ( + + ✔  {'Saved and reloaded.'} + + ); + messageStyle = { + paddingRight: '25px', + color: '#336633', + fontWeight: 'bold', + }; } return ( @@ -141,11 +156,11 @@ InputScenario.propTypes = { textAlign: PropTypes.string, marginBottom: PropTypes.string, }), - successMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), + // successMessageStyle: PropTypes.shape({ + // color: PropTypes.string, + // paddingLeft: PropTypes.string, + // fontWeight: PropTypes.string, + // }), errorMessageStyle: PropTypes.shape({ color: PropTypes.string, paddingLeft: PropTypes.string, -- GitLab From 9a399fab7455ced870ba938d4239376b84fb06ef Mon Sep 17 00:00:00 2001 From: akkking Date: Wed, 15 May 2019 17:57:45 -0400 Subject: [PATCH 10/54] Add BlocLink reducers, sagas, contants, actions --- src/components/Performance/Occupants.js | 2 +- src/components/Performance/ThermalComfort.js | 2 +- src/containers/Performance/actions.js | 36 +++-- src/containers/Performance/constants.js | 18 ++- src/containers/Performance/reducer.js | 150 +++++++++++++++++++ src/containers/Performance/sagas.js | 128 ++++++++++++++++ src/reducers.js | 2 + 7 files changed, 318 insertions(+), 20 deletions(-) create mode 100644 src/containers/Performance/reducer.js create mode 100644 src/containers/Performance/sagas.js diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index fa3be3f9..9f04f771 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -93,7 +93,7 @@ class Occupants extends Component { - +
    + + + + + + + + + ); + } +} + +RetrofitRow.propTypes = { + id: PropTypes.number, + retrofitName: PropTypes.string, + installStartDate: PropTypes.string, + installEndDate: PropTypes.string, + primaryUtility: PropTypes.string, + secondUtility: PropTypes.string, + notes: PropTypes.string, + utilityNames: PropTypes.arrayOf, + retrofitNames: PropTypes.arrayOf, + onDelEvent: PropTypes.func, + onChangeEvent: PropTypes.func, +}; + +export default RetrofitRow; diff --git a/src/components/Performance/Retrofits.js b/src/components/Performance/Retrofits.js new file mode 100644 index 00000000..89cf5d33 --- /dev/null +++ b/src/components/Performance/Retrofits.js @@ -0,0 +1,292 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { + Button, + Table, +} from 'reactstrap'; +import RetrofitRow from './RetrofitRow'; +import ResultMessage from './ResultMessage'; + + +class Retrofits extends Component { + constructor(props) { + super(props); + this.deleteRow = this.deleteRow.bind(this); + this.addRow = this.addRow.bind(this); + this.updateRow = this.updateRow.bind(this); + this.state = { + retrofitNames: props.retrofitNames, + utilityNames: props.utilityNames, + retrofits: props.retrofits, + retrofit_name: 'Waterstripping', + install_start_date: null, + install_end_date: null, + primary_utility: 'Natural Gas', + second_utility: 'Water', + notes: null, + }; + } + + validateInputs = () => { + const emptyFields = []; + if (this.state.retrofits.length > 0) { + Object.values(this.state.retrofits).forEach(retrofit => { + console.log(retrofit); // eslint-disable-line + if (retrofit.retrofit_name === null && + !emptyFields.includes('Retrofit Name')) { + emptyFields.push('Retrofit Name'); + } + if (retrofit.install_start_date === null && + !emptyFields.includes('Installation Start Date')) { + emptyFields.push('Installation Start Date'); + } + if (retrofit.install_end_date === null && + !emptyFields.includes('Installation End Date')) { + emptyFields.push('Installation End Date'); + } + if (retrofit.primary_utility === null && + !emptyFields.includes('Primary Influenced Utility')) { + emptyFields.push('Primary Influenced Utility'); + } + if (retrofit.second_utility === null && + !emptyFields.includes('Second Influenced Utility')) { + emptyFields.push('Second Influenced Utility'); + } + }); + } + + if (emptyFields.length > 0) { + alert(`Please fill in ${emptyFields.join(', ')} fields`); + return false; + } + return true; + } + + deleteRow = id => { + const retrofitsCopy = this.state.retrofits.filter((retrofit, index) => { + console.log(retrofit); // eslint-disable-line + return index !== id; + }); + this.setState({ retrofits: retrofitsCopy }, () => { + console.log('Retrofit deleted!'); // eslint-disable-line + }); + } + + addRow = () => { + if (this.validateInputs() === true) { + const retrofit = { + id: this.state.id, + retrofit_name: this.state.retrofit_name, + install_start_date: this.state.install_start_date, + install_end_date: this.state.install_end_date, + primary_utility: this.state.primary_utility, + second_utility: this.state.second_utility, + notes: this.state.notes, + }; + console.log(this.state.retrofits); // eslint-disable-line + const retrofits = this.state.retrofits; + retrofits.push(retrofit); + this.setState({ retrofits }, () => { + console.log(this.state.retrofits, 'New retrofit added!'); // eslint-disable-line + this.setState({ + id: this.state.id + 1, + retrofit_name: 'Waterstripping', + install_start_date: null, + install_end_date: null, + primary_utility: 'Natural Gas', + second_utility: 'Water', + notes: null, + }); + }); + } + } + + updateRow = (row) => { + const retrofits = this.state.retrofits.map((retrofit, id) => { + console.log(id); // eslint-disable-line + console.log(row.id); // eslint-disable-line + if (id === row.id) { + const tmp = { id }; + tmp.retrofit_name = row.retrofit_name; + tmp.install_start_date = row.install_start_date; + tmp.install_end_date = row.install_end_date; + tmp.primary_utility = row.primary_utility; + tmp.second_utility = row.second_utility; + tmp.notes = row.notes; + return tmp; + } + return retrofit; + }); + this.setState({ retrofits }, () => { + console.log(retrofits); // eslint-disable-line + }); + } + + handleUpdateRetrofits = () => { + if (this.validateInputs() === true) { + const formData = {}; + formData.instance = this.state.retrofits; + this.props.updateRetrofits( + this.props.buildingId, + formData, + ); + this.setState({ + loading: false, + action: 'updated', + }); + } + } + + render() { + const header = [ + 'Retrofit Name', + 'Installation Start Date', + 'Installation End Date', + 'Primary Influenced Utility', + 'Second Influenced Utility', + 'Notes', + ' ', + ].map((title, key) => { + return ( + + ); + }); + + let retrofits = []; + let saveButton = null; + if (Object.keys(this.state.retrofits).length !== 0) { + retrofits = this.state.retrofits.map((retrofit, index) => { + return ( + + ); + }); + saveButton = ( + + ); + } else { + retrofits = ( + + + + ); + } + + let messageStyle = {}; + let messageContent = null; + + if (this.props.loading) { + messageContent = 'Updating ...'; + messageStyle = this.props.defaultMessageStyle; + } + + if (this.props.error && typeof this.props.error === 'object') { + messageContent = this.props.error.response.statusText; + messageStyle = this.props.errorMessageStyle; + } + + if (!this.props.error && !this.props.loading + && this.props.data !== null + && this.state.updated) { + messageContent = 'Saved!'; + messageStyle = this.props.successMessageStyle; + } + + return ( +
    +

    + My Retrofits +

    +
    +
    +
    Number of Units diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js index 154a2968..118ad184 100644 --- a/src/components/Performance/ThermalComfort.js +++ b/src/components/Performance/ThermalComfort.js @@ -66,7 +66,7 @@ class ThermalComfort extends Component { {' '} - +
    + + + + + + ); + }); + return (
    @@ -81,7 +102,7 @@ class Occupants extends Component { color="secondary" onClick={this.openModal} > - Action log + History {' '} -
    I am a modal
    -
    - - - - - - +
    +
    +

    Change History

    +
    +
    + +
    +
    +
    +
    Heating Set Point (Pre-retrofit) diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 13e51833..8baa0e03 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -1,16 +1,28 @@ import { - LOAD_OCCUPANTS, - OCCUPANTS_SUCCESS, - OCCUPANTS_ERROR, - LOAD_THERMAL_COMFORT, - THERMAL_COMFORT_SUCCESS, - THERMAL_COMFORT_ERROR, + OCCUPANTS_REQUESTED, + OCCUPANTS_SUCCEEDED, + OCCUPANTS_FAILED, + OCCUPANTS_LOG_REQUESTED, + OCCUPANTS_LOG_SUCCEEDED, + OCCUPANTS_LOG_FAILED, + THERMAL_COMFORT_REQUESTED, + THERMAL_COMFORT_SUCCEEDED, + THERMAL_COMFORT_FAILED, + THERMAL_COMFORT_LOG_REQUESTED, + THERMAL_COMFORT_LOG_SUCCEEDED, + THERMAL_COMFORT_LOG_FAILED, } from './constants'; import { makeActionCreator } from '../../utils/reduxHelpers'; -export const loadOccupants = makeActionCreator(LOAD_OCCUPANTS, 'buildingId'); -export const occupantsLoaded = makeActionCreator(OCCUPANTS_SUCCESS, 'payload'); -export const occupantsLoadingError = makeActionCreator(OCCUPANTS_ERROR, 'error'); -export const loadThermalComfort = makeActionCreator(LOAD_THERMAL_COMFORT, 'buildingId'); -export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCESS, 'payload'); -export const thermalComfortLoadingError = makeActionCreator(THERMAL_COMFORT_ERROR, 'error'); +export const loadOccupants = makeActionCreator(OCCUPANTS_REQUESTED, 'buildingId'); +export const occupantsLoaded = makeActionCreator(OCCUPANTS_SUCCEEDED, 'payload'); +export const occupantsLoadingError = makeActionCreator(OCCUPANTS_FAILED, 'error'); +export const loadOccupantsLog = makeActionCreator(OCCUPANTS_LOG_REQUESTED, 'buildingId'); +export const occupantsLogLoaded = makeActionCreator(OCCUPANTS_LOG_SUCCEEDED, 'payload'); +export const occupantsLogLoadingError = makeActionCreator(OCCUPANTS_LOG_FAILED, 'error'); +export const loadThermalComfort = makeActionCreator(THERMAL_COMFORT_REQUESTED, 'buildingId'); +export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCEEDED, 'payload'); +export const thermalComfortLoadingError = makeActionCreator(THERMAL_COMFORT_FAILED, 'error'); +export const loadThermalComfortLog = makeActionCreator(THERMAL_COMFORT_LOG_REQUESTED, 'buildingId'); +export const thermalComfortLogLoaded = makeActionCreator(THERMAL_COMFORT_LOG_SUCCEEDED, 'payload'); +export const thermalComfortLogLoadingError = makeActionCreator(THERMAL_COMFORT_LOG_FAILED, 'error'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index 059b46d5..f7081663 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -1,6 +1,12 @@ -export const LOAD_OCCUPANTS = 'LOAD_OCCUPANTS'; -export const OCCUPANTS_SUCCESS = 'OCCUPANTS_SUCCESS'; -export const OCCUPANTS_ERROR = 'OCCUPANTS_ERROR'; -export const LOAD_THERMAL_COMFORT = 'LOAD_THERMAL_COMFORT'; -export const THERMAL_COMFORT_SUCCESS = 'THERMAL_COMFORT_SUCCESS'; -export const THERMAL_COMFORT_ERROR = 'THERMAL_COMFORT_ERROR'; +export const OCCUPANTS_REQUESTED = 'OCCUPANTS_REQUESTED'; +export const OCCUPANTS_SUCCEEDED = 'OCCUPANTS_SUCCEEDED'; +export const OCCUPANTS_FAILED = 'OCCUPANTS_FAILED'; +export const OCCUPANTS_LOG_REQUESTED = 'OCCUPANTS_LOG_REQUESTED'; +export const OCCUPANTS_LOG_SUCCEEDED = 'OCCUPANTS_LOG_SUCCEEDED'; +export const OCCUPANTS_LOG_FAILED = 'OCCUPANTS_LOG_FAILED'; +export const THERMAL_COMFORT_REQUESTED = 'THERMAL_COMFORT_REQUESTED'; +export const THERMAL_COMFORT_SUCCEEDED = 'THERMAL_COMFORT_SUCCEEDED'; +export const THERMAL_COMFORT_FAILED = 'THERMAL_COMFORT_FAILED'; +export const THERMAL_COMFORT_LOG_REQUESTED = 'THERMAL_COMFORT_LOG_REQUESTED'; +export const THERMAL_COMFORT_LOG_SUCCEEDED = 'THERMAL_COMFORT_LOG_SUCCEEDED'; +export const THERMAL_COMFORT_LOG_FAILED = 'THERMAL_COMFORT_LOG_FAILED'; diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js new file mode 100644 index 00000000..e8e4f4bc --- /dev/null +++ b/src/containers/Performance/reducer.js @@ -0,0 +1,150 @@ +import { + OCCUPANTS_REQUESTED, + OCCUPANTS_SUCCEEDED, + OCCUPANTS_FAILED, + OCCUPANTS_LOG_REQUESTED, + OCCUPANTS_LOG_SUCCEEDED, + OCCUPANTS_LOG_FAILED, + THERMAL_COMFORT_REQUESTED, + THERMAL_COMFORT_SUCCEEDED, + THERMAL_COMFORT_FAILED, + THERMAL_COMFORT_LOG_REQUESTED, + THERMAL_COMFORT_LOG_SUCCEEDED, + THERMAL_COMFORT_LOG_FAILED, +} from './constants'; + +const PerformanceInitialState = { + occupants: { + loading: false, + error: false, + data: null, + }, + thermalComfort: { + loading: false, + error: false, + data: null, + }, +}; + +export default function (state = PerformanceInitialState, action) { + switch (action.type) { + case OCCUPANTS_REQUESTED: + return { + ...state, + occupants: { + ...state.occupants, + loading: true, + error: false, + }, + }; + + case OCCUPANTS_SUCCEEDED: + return { + ...state, + occupants: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case OCCUPANTS_FAILED: + return { + ...state, + occupants: { + loading: false, + error: action.error, + }, + }; + + case OCCUPANTS_LOG_REQUESTED: + return { + ...state, + occupantsLog: { + ...state.occupantsLog, + loading: true, + error: false, + }, + }; + + case OCCUPANTS_LOG_SUCCEEDED: + return { + ...state, + occupantsLog: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case OCCUPANTS_LOG_FAILED: + return { + ...state, + occupantsLog: { + loading: false, + error: action.error, + }, + }; + + case THERMAL_COMFORT_REQUESTED: + return { + ...state, + thermalComfort: { + ...state.thermalComfort, + loading: true, + error: false, + }, + }; + + case THERMAL_COMFORT_SUCCEEDED: + return { + ...state, + thermalComfort: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case THERMAL_COMFORT_FAILED: + return { + ...state, + thermalComfort: { + loading: false, + error: action.error, + }, + }; + + case THERMAL_COMFORT_LOG_REQUESTED: + return { + ...state, + thermalComfortLog: { + ...state.thermalComfortLog, + loading: true, + error: false, + }, + }; + + case THERMAL_COMFORT_LOG_SUCCEEDED: + return { + ...state, + thermalComfortLog: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case THERMAL_COMFORT_LOG_FAILED: + return { + ...state, + thermalComfortLog: { + loading: false, + error: action.error, + }, + }; + + default: + return state; + } +} diff --git a/src/containers/Performance/sagas.js b/src/containers/Performance/sagas.js new file mode 100644 index 00000000..a1126eb4 --- /dev/null +++ b/src/containers/Performance/sagas.js @@ -0,0 +1,128 @@ +import { call, put, takeEvery } from 'redux-saga/effects'; +import SagaRequests from '../../utils/sagaRequests'; +import request from '../../utils/request'; +import { getHeaders } from '../../utils/restServices'; +import { + OCCUPANTS_REQUESTED, + OCCUPANTS_LOG_REQUESTED, + THERMAL_COMFORT_REQUESTED, + THERMAL_COMFORT_LOG_REQUESTED, +} from './constants'; + +import { + occupantsLoaded, occupantsFailed, + occupantsLogLoaded, occupantsLogFailed, + thermalComfortLoaded, thermalComfortFailed, + thermalComfortLogLoaded, thermalComfortLogFailed, + createThermalComfortLogSucceeded, createOccupantsLogFailed, + createThermalComfortLogSucceeded, createOccupantsLogFailed, +} from './actions'; + +function* loadOccupants(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants`; + yield SagaRequests.get(action, url, occupantsLoaded, occupantsFailed); +} + +function* loadOccupantsLog(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants-log`; + yield SagaRequests.get(action, url, occupantsLogLoaded, occupantsLogFailed); +} + +function* loadThermalComfort(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/thermal-comfort/`; + yield SagaRequests.get(action, url, thermalComfortLoaded, thermalComfortFailed); +} + +function* loadThermalComfortLog(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/thermal-comfort-log/`; + yield SagaRequests.get(action, url, thermalComfortLogLoaded, thermalComfortLogFailed); +} + +function* updateOccupants(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants/`; + const res = yield call( + request, + SagaRequests.generateURL(url, action), + { + method: 'PUT', + headers: getHeaders(), + body: JSON.stringify(action.payload), + } + ); + + if (!res.err) { + yield put(updateOccupantsSucceeded(action.payload)); + } else { + yield put(updateOccupantsFailed(res.err)); + } +} + +function* updateThermalComfort(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/thermal-comfort/`; + const res = yield call( + request, + SagaRequests.generateURL(url, action), + { + method: 'PUT', + headers: getHeaders(), + body: JSON.stringify(action.payload), + } + ); + + if (!res.err) { + yield put(updateThermalComfortSucceeded(action.payload)); + } else { + yield put(updateThermalComfortFailed(res.err)); + } +} + +function* createOccupantsLog(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants-log/`; + const res = yield call( + request, + SagaRequests.generateURL(url, action), + { + method: 'POST', + headers: getHeaders(), + body: JSON.stringify(action.payload), + } + ); + + if (!res.err) { + yield put(createOccupantsLogSucceeded(action.payload, res)); + } else { + yield put(createOccupantsLogFailed(res.err)); + } +} + +function* createThermalComfortLog(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/thermal-comfort-log/`; + const res = yield call( + request, + SagaRequests.generateURL(url, action), + { + method: 'POST', + headers: getHeaders(), + body: JSON.stringify(action.payload), + } + ); + + if (!res.err) { + yield put(createThermalComfortLogSucceeded(action.payload, res)); + } else { + yield put(createThermalComfortLogFailed(res.err)); + } +} + +function* bloclinkWatcher() { + yield takeEvery(OCCUPANTS_REQUESTED, loadOccupants); + yield takeEvery(OCCUPANTS_LOG_REQUESTED, loadOccupantsLog); + yield takeEvery(THERMAL_COMFORT_REQUESTED, loadThermalComfort); + yield takeEvery(THERMAL_COMFORT_LOG_REQUESTED, loadThermalComfortLog); + yield takeEvery(UPDATE_OCCUPANTS_REQUESTED, updateOccupants); + yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); + yield takeEvery(UPDATE_THERMAL_COMFORT_REQUESTED, updateThermalComfort); + yield takeEvery(CREATE_THERMAL_COMFORT_LOG_REQUESTED, createThermalComfortLog); +} + +export default bloclinkWatcher; diff --git a/src/reducers.js b/src/reducers.js index 5bf5ae9a..0044eac8 100644 --- a/src/reducers.js +++ b/src/reducers.js @@ -17,6 +17,7 @@ import buildingArea from './containers/BuildingArea/reducer'; import weather from './containers/Weather/reducer'; import events from './containers/Event/reducer'; import blocnote from './containers/Blocnote/reducer'; +import bloclink from './containers/Performance/reducer'; export default combineReducers({ @@ -37,4 +38,5 @@ export default combineReducers({ weather, events, blocnote, + bloclink, }); -- GitLab From b9dc10e95d957743a6179ecb48e0b7b59d36f92b Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 16 May 2019 15:37:20 -0400 Subject: [PATCH 11/54] Add performance sidebar icon --- src/components/SideBarDetail/index.js | 3 ++- src/components/SideBarDetail/sidebarSVGs.js | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/SideBarDetail/index.js b/src/components/SideBarDetail/index.js index b90e6a55..ee470758 100644 --- a/src/components/SideBarDetail/index.js +++ b/src/components/SideBarDetail/index.js @@ -12,6 +12,7 @@ import { envelopeSVG, reportsSVG, blocnoteSVG, + performanceSVG, iotSVG, } from './sidebarSVGs'; import userPropType from '../../containers/User/propTypes'; @@ -212,7 +213,7 @@ export default function SideBarDetail({ building, children, contacts, user }) {
  • - {blocnoteSVG} + {performanceSVG} Performance
  • diff --git a/src/components/SideBarDetail/sidebarSVGs.js b/src/components/SideBarDetail/sidebarSVGs.js index cb06b34a..35a6ce3d 100644 --- a/src/components/SideBarDetail/sidebarSVGs.js +++ b/src/components/SideBarDetail/sidebarSVGs.js @@ -88,3 +88,11 @@ export const iotSVG = ( ); + +export const performanceSVG = ( + + + + + +); -- GitLab From 23e6955484083c1745f9a0341abd2f3ab0d7919a Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 16 May 2019 16:56:44 -0400 Subject: [PATCH 12/54] Add performance sagas --- src/containers/Performance/actions.js | 34 ++++++++++++++++++++++--- src/containers/Performance/constants.js | 14 ++++++++++ src/containers/Performance/index.js | 1 + src/containers/Performance/reducer.js | 1 + src/containers/Performance/sagas.js | 12 ++++++--- src/sagas.js | 2 ++ 6 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 8baa0e03..0d92d0eb 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -11,18 +11,44 @@ import { THERMAL_COMFORT_LOG_REQUESTED, THERMAL_COMFORT_LOG_SUCCEEDED, THERMAL_COMFORT_LOG_FAILED, + UPDATE_OCCUPANTS_REQUESTED, + UPDATE_OCCUPANTS_SUCCEEDED, + UPDATE_OCCUPANTS_FAILED, + UPDATE_THERMAL_COMFORT_REQUESTED, + UPDATE_THERMAL_COMFORT_SUCCEEDED, + UPDATE_THERMAL_COMFORT_FAILED, + CREATE_OCCUPANTS_LOG_REQUESTED, + CREATE_OCCUPANTS_LOG_SUCCEEDED, + CREATE_OCCUPANTS_LOG_FAILED, + CREATE_THERMAL_COMFORT_LOG_REQUESTED, + CREATE_THERMAL_COMFORT_LOG_SUCCEEDED, + CREATE_THERMAL_COMFORT_LOG_FAILED, } from './constants'; import { makeActionCreator } from '../../utils/reduxHelpers'; export const loadOccupants = makeActionCreator(OCCUPANTS_REQUESTED, 'buildingId'); export const occupantsLoaded = makeActionCreator(OCCUPANTS_SUCCEEDED, 'payload'); -export const occupantsLoadingError = makeActionCreator(OCCUPANTS_FAILED, 'error'); +export const occupantsFailed = makeActionCreator(OCCUPANTS_FAILED, 'error'); export const loadOccupantsLog = makeActionCreator(OCCUPANTS_LOG_REQUESTED, 'buildingId'); export const occupantsLogLoaded = makeActionCreator(OCCUPANTS_LOG_SUCCEEDED, 'payload'); -export const occupantsLogLoadingError = makeActionCreator(OCCUPANTS_LOG_FAILED, 'error'); +export const occupantsLogFailed = makeActionCreator(OCCUPANTS_LOG_FAILED, 'error'); export const loadThermalComfort = makeActionCreator(THERMAL_COMFORT_REQUESTED, 'buildingId'); export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCEEDED, 'payload'); -export const thermalComfortLoadingError = makeActionCreator(THERMAL_COMFORT_FAILED, 'error'); +export const thermalComfortFailed = makeActionCreator(THERMAL_COMFORT_FAILED, 'error'); export const loadThermalComfortLog = makeActionCreator(THERMAL_COMFORT_LOG_REQUESTED, 'buildingId'); export const thermalComfortLogLoaded = makeActionCreator(THERMAL_COMFORT_LOG_SUCCEEDED, 'payload'); -export const thermalComfortLogLoadingError = makeActionCreator(THERMAL_COMFORT_LOG_FAILED, 'error'); +export const thermalComfortLogFailed = makeActionCreator(THERMAL_COMFORT_LOG_FAILED, 'error'); + +export const updateOccupants = makeActionCreator(UPDATE_OCCUPANTS_REQUESTED, 'buildingId'); +export const updateOccupantsSucceeded = makeActionCreator(UPDATE_OCCUPANTS_SUCCEEDED, 'payload'); +export const updateOccupantsFailed = makeActionCreator(UPDATE_OCCUPANTS_FAILED, 'error'); +export const updateThermalComfort = makeActionCreator(UPDATE_THERMAL_COMFORT_REQUESTED, 'buildingId'); +export const updateThermalComfortSucceeded = makeActionCreator(UPDATE_THERMAL_COMFORT_SUCCEEDED, 'payload'); +export const updateThermalComfortFailed = makeActionCreator(UPDATE_THERMAL_COMFORT_FAILED, 'error'); + +export const createOccupantsLog = makeActionCreator(CREATE_OCCUPANTS_LOG_REQUESTED, 'buildingId'); +export const createOccupantsLogSucceeded = makeActionCreator(CREATE_OCCUPANTS_LOG_SUCCEEDED, 'payload'); +export const createOccupantsLogFailed = makeActionCreator(CREATE_OCCUPANTS_LOG_FAILED, 'error'); +export const createThermalComfortLog = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_REQUESTED, 'buildingId'); +export const createThermalComfortLogSucceeded = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_SUCCEEDED, 'payload'); +export const createThermalComfortLogFailed = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_FAILED, 'error'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index f7081663..4aa464e5 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -10,3 +10,17 @@ export const THERMAL_COMFORT_FAILED = 'THERMAL_COMFORT_FAILED'; export const THERMAL_COMFORT_LOG_REQUESTED = 'THERMAL_COMFORT_LOG_REQUESTED'; export const THERMAL_COMFORT_LOG_SUCCEEDED = 'THERMAL_COMFORT_LOG_SUCCEEDED'; export const THERMAL_COMFORT_LOG_FAILED = 'THERMAL_COMFORT_LOG_FAILED'; + +export const UPDATE_OCCUPANTS_REQUESTED = 'UPDATE_OCCUPANTS_REQUESTED'; +export const UPDATE_OCCUPANTS_SUCCEEDED = 'UPDATE_OCCUPANTS_SUCCEEDED'; +export const UPDATE_OCCUPANTS_FAILED = 'UPDATE_OCCUPANTS_FAILED'; +export const UPDATE_THERMAL_COMFORT_REQUESTED = 'UPDATE_THERMAL_COMFORT_REQUESTED'; +export const UPDATE_THERMAL_COMFORT_SUCCEEDED = 'UPDATE_THERMAL_COMFORT_SUCCEEDED'; +export const UPDATE_THERMAL_COMFORT_FAILED = 'UPDATE_THERMAL_COMFORT_FAILED'; + +export const CREATE_OCCUPANTS_LOG_REQUESTED = 'CREATE_OCCUPANTS_LOG_REQUESTED'; +export const CREATE_OCCUPANTS_LOG_SUCCEEDED = 'CREATE_OCCUPANTS_LOG_SUCCEEDED'; +export const CREATE_OCCUPANTS_LOG_FAILED = 'CREATE_OCCUPANTS_LOG_FAILED'; +export const CREATE_THERMAL_COMFORT_LOG_REQUESTED = 'CREATE_THERMAL_COMFORT_LOG_REQUESTED'; +export const CREATE_THERMAL_COMFORT_LOG_SUCCEEDED = 'CREATE_THERMAL_COMFORT_LOG_SUCCEEDED'; +export const CREATE_THERMAL_COMFORT_LOG_FAILED = 'CREATE_THERMAL_COMFORT_LOG_FAILED'; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index bae57c91..1009b1c7 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -22,6 +22,7 @@ class Performance extends Component { componentDidMount() { const buildingId = this.props.building.building_id; + console.log(buildingId); // eslint-disable-line this.props.loadOccupants(buildingId); this.props.loadThermalComfort(buildingId); } diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index e8e4f4bc..67373829 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -27,6 +27,7 @@ const PerformanceInitialState = { }; export default function (state = PerformanceInitialState, action) { + console.log(action); // eslint-disable-line switch (action.type) { case OCCUPANTS_REQUESTED: return { diff --git a/src/containers/Performance/sagas.js b/src/containers/Performance/sagas.js index a1126eb4..34d8a268 100644 --- a/src/containers/Performance/sagas.js +++ b/src/containers/Performance/sagas.js @@ -7,6 +7,10 @@ import { OCCUPANTS_LOG_REQUESTED, THERMAL_COMFORT_REQUESTED, THERMAL_COMFORT_LOG_REQUESTED, + UPDATE_OCCUPANTS_REQUESTED, + UPDATE_THERMAL_COMFORT_REQUESTED, + CREATE_OCCUPANTS_LOG_REQUESTED, + CREATE_THERMAL_COMFORT_LOG_REQUESTED, } from './constants'; import { @@ -14,8 +18,10 @@ import { occupantsLogLoaded, occupantsLogFailed, thermalComfortLoaded, thermalComfortFailed, thermalComfortLogLoaded, thermalComfortLogFailed, - createThermalComfortLogSucceeded, createOccupantsLogFailed, - createThermalComfortLogSucceeded, createOccupantsLogFailed, + updateOccupantsSucceeded, updateOccupantsFailed, + updateThermalComfortSucceeded, updateThermalComfortFailed, + createOccupantsLogSucceeded, createOccupantsLogFailed, + createThermalComfortLogSucceeded, createThermalComfortLogFailed, } from './actions'; function* loadOccupants(action) { @@ -120,8 +126,8 @@ function* bloclinkWatcher() { yield takeEvery(THERMAL_COMFORT_REQUESTED, loadThermalComfort); yield takeEvery(THERMAL_COMFORT_LOG_REQUESTED, loadThermalComfortLog); yield takeEvery(UPDATE_OCCUPANTS_REQUESTED, updateOccupants); - yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); yield takeEvery(UPDATE_THERMAL_COMFORT_REQUESTED, updateThermalComfort); + yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); yield takeEvery(CREATE_THERMAL_COMFORT_LOG_REQUESTED, createThermalComfortLog); } diff --git a/src/sagas.js b/src/sagas.js index d880c23e..7d7ea267 100644 --- a/src/sagas.js +++ b/src/sagas.js @@ -14,6 +14,7 @@ import buildingAreaSaga from './containers/BuildingArea/sagas'; import weatherSaga from './containers/Weather/sagas'; import eventsSaga from './containers/Event/sagas'; import blocnoteSaga from './containers/Blocnote/sagas'; +import performanceSaga from './containers/Performance/sagas'; export default function* rootSaga() { @@ -34,5 +35,6 @@ export default function* rootSaga() { weatherSaga(), eventsSaga(), blocnoteSaga(), + performanceSaga(), ]; } -- GitLab From 366952b187da6e2ee0041ce974e61febce098fcd Mon Sep 17 00:00:00 2001 From: akkking Date: Tue, 21 May 2019 11:30:29 -0400 Subject: [PATCH 13/54] Add update events to actions and reducers --- src/components/Performance/Occupants.js | 35 +++++++++++++++++++++++-- src/containers/Performance/actions.js | 16 +++++------ src/containers/Performance/index.js | 10 +++++++ src/containers/Performance/reducer.js | 32 ++++++++++++++++++++++ 4 files changed, 83 insertions(+), 10 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index 9f04f771..b6e747c3 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -25,6 +25,8 @@ Modal.setAppElement('body'); class Occupants extends Component { constructor(props) { super(props); + this.handleOnChange = this.handleOnChange.bind(this); + this.handleUpdateOccupants = this.handleUpdateOccupants.bind(this); this.state = { totalUnits: props.totalUnits, preVacantUnits: props.preVacantUnits, @@ -46,8 +48,22 @@ class Occupants extends Component { closeModal() { this.setState({ modalIsOpen: false }); } - handleOnChange = () => { - this.setState({ displayChart: !this.state.displayChart }); + + handleOnChange = (event) => { + this.setState({ [event.target.name]: event.target.value }); + } + + handleUpdateOccupants = () => { + console.log(this.state); // eslint-disable-line + this.props.updateOccupants( + this.props.buildingId, + { + totalUnits: this.state.totalUnits, + preVacantUnits: this.state.preVacantUnits, + postVacantUnits: this.state.postVacantUnits, + } + ); + this.setState({ action: 'updated' }); } render() { @@ -69,6 +85,7 @@ class Occupants extends Component { @@ -100,6 +117,10 @@ class Occupants extends Component {
    @@ -111,6 +132,10 @@ class Occupants extends Component { @@ -122,6 +147,10 @@ class Occupants extends Component { @@ -137,6 +166,8 @@ Occupants.propTypes = { totalUnits: PropTypes.number, preVacantUnits: PropTypes.number, postVacantUnits: PropTypes.number, + updateOccupants: PropTypes.func, + buildingId: PropTypes.number, }; Occupants.defaultProps = { diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 0d92d0eb..65d6a68d 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -39,16 +39,16 @@ export const loadThermalComfortLog = makeActionCreator(THERMAL_COMFORT_LOG_REQUE export const thermalComfortLogLoaded = makeActionCreator(THERMAL_COMFORT_LOG_SUCCEEDED, 'payload'); export const thermalComfortLogFailed = makeActionCreator(THERMAL_COMFORT_LOG_FAILED, 'error'); -export const updateOccupants = makeActionCreator(UPDATE_OCCUPANTS_REQUESTED, 'buildingId'); -export const updateOccupantsSucceeded = makeActionCreator(UPDATE_OCCUPANTS_SUCCEEDED, 'payload'); +export const updateOccupants = makeActionCreator(UPDATE_OCCUPANTS_REQUESTED, 'buildingId', 'payload'); +export const updateOccupantsSucceeded = makeActionCreator(UPDATE_OCCUPANTS_SUCCEEDED, 'payload', 'instance'); export const updateOccupantsFailed = makeActionCreator(UPDATE_OCCUPANTS_FAILED, 'error'); -export const updateThermalComfort = makeActionCreator(UPDATE_THERMAL_COMFORT_REQUESTED, 'buildingId'); -export const updateThermalComfortSucceeded = makeActionCreator(UPDATE_THERMAL_COMFORT_SUCCEEDED, 'payload'); +export const updateThermalComfort = makeActionCreator(UPDATE_THERMAL_COMFORT_REQUESTED, 'buildingId', 'payload'); +export const updateThermalComfortSucceeded = makeActionCreator(UPDATE_THERMAL_COMFORT_SUCCEEDED, 'instance'); export const updateThermalComfortFailed = makeActionCreator(UPDATE_THERMAL_COMFORT_FAILED, 'error'); -export const createOccupantsLog = makeActionCreator(CREATE_OCCUPANTS_LOG_REQUESTED, 'buildingId'); -export const createOccupantsLogSucceeded = makeActionCreator(CREATE_OCCUPANTS_LOG_SUCCEEDED, 'payload'); +export const createOccupantsLog = makeActionCreator(CREATE_OCCUPANTS_LOG_REQUESTED, 'buildingId', 'payload'); +export const createOccupantsLogSucceeded = makeActionCreator(CREATE_OCCUPANTS_LOG_SUCCEEDED, 'instance'); export const createOccupantsLogFailed = makeActionCreator(CREATE_OCCUPANTS_LOG_FAILED, 'error'); -export const createThermalComfortLog = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_REQUESTED, 'buildingId'); -export const createThermalComfortLogSucceeded = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_SUCCEEDED, 'payload'); +export const createThermalComfortLog = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_REQUESTED, 'buildingId', 'payload'); +export const createThermalComfortLogSucceeded = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_SUCCEEDED, 'instance'); export const createThermalComfortLogFailed = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_FAILED, 'error'); diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 1009b1c7..f6683df1 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -5,6 +5,8 @@ import { bindActionCreators } from 'redux'; import { loadOccupants, loadThermalComfort, + updateOccupants, + updateThermalComfort, } from './actions'; import buildingDetailPropTypes from '../../containers/Building/propTypes'; import LinkBarDetail from '../../components/LinkBarDetail'; @@ -54,17 +56,21 @@ class Performance extends Component {
    @@ -78,12 +84,16 @@ Performance.propTypes = { building: buildingDetailPropTypes, loadOccupants: PropTypes.func, loadThermalComfort: PropTypes.func, + updateOccupants: PropTypes.func, + updateThermalComfort: PropTypes.func, }; const mapDispatchToProps = dispatch => ( bindActionCreators({ loadOccupants, loadThermalComfort, + updateOccupants, + updateThermalComfort, }, dispatch) ); diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index 67373829..f4d12e09 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -11,6 +11,9 @@ import { THERMAL_COMFORT_LOG_REQUESTED, THERMAL_COMFORT_LOG_SUCCEEDED, THERMAL_COMFORT_LOG_FAILED, + UPDATE_OCCUPANTS_REQUESTED, + UPDATE_OCCUPANTS_SUCCEEDED, + UPDATE_OCCUPANTS_FAILED, } from './constants'; const PerformanceInitialState = { @@ -145,6 +148,35 @@ export default function (state = PerformanceInitialState, action) { }, }; + case UPDATE_OCCUPANTS_REQUESTED: + return { + ...state, + occupants: { + ...state.occupants, + loading: true, + error: false, + }, + }; + + case UPDATE_OCCUPANTS_SUCCEEDED: + return { + ...state, + occupants: { + ...state.occupants, + loading: false, + error: false, + }, + }; + + case UPDATE_OCCUPANTS_FAILED: + return { + ...state, + occupants: { + loading: false, + error: action.error, + }, + }; + default: return state; } -- GitLab From aaedac2346537289b7cba7cd0eae7e37c0d21ece Mon Sep 17 00:00:00 2001 From: akkking Date: Tue, 21 May 2019 18:29:08 -0400 Subject: [PATCH 14/54] Update Occupants and Thermal Comfort actions, index --- src/components/Performance/Occupants.js | 7 +- src/components/Performance/ThermalComfort.js | 29 ++++-- src/containers/Performance/actions.js | 8 +- src/containers/Performance/index.js | 98 +++++++++++++------- 4 files changed, 95 insertions(+), 47 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index b6e747c3..ea5a3998 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -58,9 +58,10 @@ class Occupants extends Component { this.props.updateOccupants( this.props.buildingId, { - totalUnits: this.state.totalUnits, - preVacantUnits: this.state.preVacantUnits, - postVacantUnits: this.state.postVacantUnits, + building_id: this.props.buildingId, + total_units: this.state.totalUnits, + pre_vacant_units: this.state.preVacantUnits, + post_vacant_units: this.state.postVacantUnits, } ); this.setState({ action: 'updated' }); diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js index 118ad184..9514809d 100644 --- a/src/components/Performance/ThermalComfort.js +++ b/src/components/Performance/ThermalComfort.js @@ -26,20 +26,31 @@ class ThermalComfort extends Component { }; } - handleUpdateThermalComfort() { - console.log(this.props); // eslint-disable-line - if (confirm('Are you sure to save these updates?') === true) { - this.setState({ preHeatingSetPoint: !this.props.preHeatingSetPoint }); - alert('Confirmed!'); - } - } - toggle() { this.setState(prevState => ({ modal: !prevState.modal, })); } + handleOnChange = (event) => { + this.setState({ [event.target.name]: event.target.value }); + } + + handleUpdateThermalComfort = () => { + console.log(this.state); // eslint-disable-line + this.props.updateThermalComfort( + this.props.buildingId, + { + building_id: this.props.buildingId, + pre_heating_set_point: this.state.preHeatingSetPoint, + post_heating_set_point: this.state.postHeatingSetPoint, + pre_cooling_set_point: this.state.preCoolingSetPoint, + post_cooling_setPoint: this.state.postCoolingSetPoint, + } + ); + this.setState({ action: 'updated' }); + } + render() { return (
    @@ -172,6 +183,8 @@ ThermalComfort.propTypes = { postHeatingSetPoint: PropTypes.number, preCoolingSetPoint: PropTypes.number, postCoolingSetPoint: PropTypes.number, + updateThermalComfort: PropTypes.func, + buildingId: PropTypes.number, }; Modal.propTypes = { diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 65d6a68d..e87ba57b 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -27,16 +27,16 @@ import { import { makeActionCreator } from '../../utils/reduxHelpers'; export const loadOccupants = makeActionCreator(OCCUPANTS_REQUESTED, 'buildingId'); -export const occupantsLoaded = makeActionCreator(OCCUPANTS_SUCCEEDED, 'payload'); +export const occupantsLoaded = makeActionCreator(OCCUPANTS_SUCCEEDED, 'instance'); export const occupantsFailed = makeActionCreator(OCCUPANTS_FAILED, 'error'); export const loadOccupantsLog = makeActionCreator(OCCUPANTS_LOG_REQUESTED, 'buildingId'); -export const occupantsLogLoaded = makeActionCreator(OCCUPANTS_LOG_SUCCEEDED, 'payload'); +export const occupantsLogLoaded = makeActionCreator(OCCUPANTS_LOG_SUCCEEDED, 'instance'); export const occupantsLogFailed = makeActionCreator(OCCUPANTS_LOG_FAILED, 'error'); export const loadThermalComfort = makeActionCreator(THERMAL_COMFORT_REQUESTED, 'buildingId'); -export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCEEDED, 'payload'); +export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCEEDED, 'instance'); export const thermalComfortFailed = makeActionCreator(THERMAL_COMFORT_FAILED, 'error'); export const loadThermalComfortLog = makeActionCreator(THERMAL_COMFORT_LOG_REQUESTED, 'buildingId'); -export const thermalComfortLogLoaded = makeActionCreator(THERMAL_COMFORT_LOG_SUCCEEDED, 'payload'); +export const thermalComfortLogLoaded = makeActionCreator(THERMAL_COMFORT_LOG_SUCCEEDED, 'instance'); export const thermalComfortLogFailed = makeActionCreator(THERMAL_COMFORT_LOG_FAILED, 'error'); export const updateOccupants = makeActionCreator(UPDATE_OCCUPANTS_REQUESTED, 'buildingId', 'payload'); diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index f6683df1..6edacc5b 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; +import Loading from '../../components/Loading'; import { loadOccupants, loadThermalComfort, @@ -30,51 +31,81 @@ class Performance extends Component { } render() { - const occupants = { - totalUnits: null, - preVacantUnits: null, - postVacantUnits: null, - }; - const thermalComfort = { - preHeatingSetPoint: null, - postHeatingSetPoint: null, - preCoolingSetPoint: null, - postCoolingSetPoint: null, - }; - return ( -
    - + let mainContent = null; + console.log(this.props); // eslint-disable-line + + const { + performance, + } = this.props; + let { + occupants, thermalComfort, + } = performance; + + mainContent = ; + if (occupants.data !== undefined && thermalComfort.data !== undefined && + occupants.data !== null && thermalComfort.data !== null && + occupants.data.occupants !== undefined && thermalComfort.data.thermalComfort !== undefined) { + + if (occupants.data.occupants === null) { + occupants = { + total_units: 0, + pre_vacant_units: 0, + updateOccupants: 0, + }; + } else { + occupants = occupants.data.occupants; + } + + if (thermalComfort.data.thermalComfort === null) { + thermalComfort = { + pre_heating_set_point: 0, + post_heating_set_point: 0, + pre_cooling_set_point: 0, + post_cooling_set_point: 0, + }; + } else { + thermalComfort = thermalComfort.data.thermalComfort; + } + + mainContent = (
    -
    {/* Container */} +
    + ); + } + + return ( +
    + + {mainContent}
    ); } @@ -86,6 +117,7 @@ Performance.propTypes = { loadThermalComfort: PropTypes.func, updateOccupants: PropTypes.func, updateThermalComfort: PropTypes.func, + performance: PropTypes.objectOf, }; const mapDispatchToProps = dispatch => ( @@ -98,9 +130,11 @@ const mapDispatchToProps = dispatch => ( ); const mapStateToProps = state => ({ - occupants: state.occupants, - thermalComfort: state.thermalComfort, - eng: state.eng, + performance: state.bloclink, + occupants: state.bloclink.occupants, + thermalComfort: state.bloclink.thermalComfort, + // occupants: state.occupants, + // thermalComfort: state.thermalComfort, }); export default connect(mapStateToProps, mapDispatchToProps)(Performance); -- GitLab From c920500bf2332c82880ff448f6804169f4cc4dca Mon Sep 17 00:00:00 2001 From: akkking Date: Wed, 22 May 2019 17:32:49 -0400 Subject: [PATCH 15/54] Fix history modal --- src/components/Performance/Occupants.js | 104 ++++++---- src/components/Performance/ThermalComfort.js | 191 ++++++++++--------- src/containers/Performance/index.js | 36 +++- src/containers/Performance/reducer.js | 10 + 4 files changed, 209 insertions(+), 132 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index ea5a3998..a164f1e8 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -17,9 +17,10 @@ const customStyles = { bottom: 'auto', marginRight: '-50%', transform: 'translate(-50%, -50%)', + minWidth: '750px', }, }; -// Make sure to bind modal to your appElement (http://reactcommunity.org/react-modal/accessibility/) + Modal.setAppElement('body'); class Occupants extends Component { @@ -32,42 +33,62 @@ class Occupants extends Component { preVacantUnits: props.preVacantUnits, postVacantUnits: props.postVacantUnits, modalIsOpen: false, + action: null, }; - this.openModal = this.openModal.bind(this); - this.afterOpenModal = this.afterOpenModal.bind(this); this.closeModal = this.closeModal.bind(this); } openModal() { this.setState({ modalIsOpen: true }); } - afterOpenModal() { - // references are now sync'd and can be accessed. - this.subtitle.style.color = '#f00'; - } closeModal() { this.setState({ modalIsOpen: false }); } - handleOnChange = (event) => { this.setState({ [event.target.name]: event.target.value }); } - handleUpdateOccupants = () => { - console.log(this.state); // eslint-disable-line - this.props.updateOccupants( - this.props.buildingId, - { - building_id: this.props.buildingId, - total_units: this.state.totalUnits, - pre_vacant_units: this.state.preVacantUnits, - post_vacant_units: this.state.postVacantUnits, - } - ); - this.setState({ action: 'updated' }); + if (confirm('Are you sure to update?') === true) { + this.props.updateOccupants( + this.props.buildingId, + { + building_id: this.props.buildingId, + total_units: this.state.totalUnits, + pre_vacant_units: this.state.preVacantUnits, + post_vacant_units: this.state.postVacantUnits, + user_id: this.props.userId, + } + ); + this.setState({ action: 'updated' }, () => { + alert('Update successful.'); + }); + } } render() { + const rows = this.props.occupantsLog.map((occupant) => { + const delta = Object.entries(occupant.delta) + .filter(entry => entry[0] !== 'id' && entry[0] !== 'building_id') + .map(entry => { + return ( +
    + {entry[0]} : {entry[1]} +
    + ); + }); + let updatedTime = new Date(occupant.updated_time); + updatedTime = `${updatedTime.toLocaleDateString('en-US')} ${updatedTime.toLocaleTimeString('en-US')}`; + + return ( +
    {occupant.id}{delta}{occupant.user_id}{updatedTime}
    + + + + + + + + {rows} + +
    IDChangesUser IDUpdated Time
    + @@ -164,11 +200,13 @@ class Occupants extends Component { } Occupants.propTypes = { + userId: PropTypes.string, totalUnits: PropTypes.number, preVacantUnits: PropTypes.number, postVacantUnits: PropTypes.number, updateOccupants: PropTypes.func, buildingId: PropTypes.number, + occupantsLog: PropTypes.arrayOf, }; Occupants.defaultProps = { diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js index 9514809d..82adbce8 100644 --- a/src/components/Performance/ThermalComfort.js +++ b/src/components/Performance/ThermalComfort.js @@ -1,4 +1,5 @@ import React, { Component } from 'react'; +import Modal from 'react-modal'; import PropTypes from 'prop-types'; import { Table, @@ -6,14 +7,24 @@ import { InputGroup, InputGroupAddon, Button, - Modal, - ModalBody, - ModalHeader, - ModalFooter, } from 'reactstrap'; import './styles.css'; +const customStyles = { + content: { + top: '50%', + left: '50%', + right: 'auto', + bottom: 'auto', + marginRight: '-50%', + transform: 'translate(-50%, -50%)', + minWidth: '750px', + }, +}; + +Modal.setAppElement('body'); + class ThermalComfort extends Component { constructor(props) { super(props); @@ -22,36 +33,64 @@ class ThermalComfort extends Component { postHeatingSetPoint: props.postHeatingSetPoint, preCoolingSetPoint: props.preCoolingSetPoint, postCoolingSetPoint: props.postCoolingSetPoint, - modal: false, + modalIsOpen: false, + action: null, }; + this.openModal = this.openModal.bind(this); + this.closeModal = this.closeModal.bind(this); } - - toggle() { - this.setState(prevState => ({ - modal: !prevState.modal, - })); + openModal() { + this.setState({ modalIsOpen: true }); + } + closeModal() { + this.setState({ modalIsOpen: false }); } - handleOnChange = (event) => { this.setState({ [event.target.name]: event.target.value }); } - handleUpdateThermalComfort = () => { - console.log(this.state); // eslint-disable-line - this.props.updateThermalComfort( - this.props.buildingId, - { - building_id: this.props.buildingId, - pre_heating_set_point: this.state.preHeatingSetPoint, - post_heating_set_point: this.state.postHeatingSetPoint, - pre_cooling_set_point: this.state.preCoolingSetPoint, - post_cooling_setPoint: this.state.postCoolingSetPoint, - } - ); - this.setState({ action: 'updated' }); + if (confirm('Are you sure to update?') === true) { + this.props.updateThermalComfort( + this.props.buildingId, + { + building_id: this.props.buildingId, + pre_heating_set_point: this.state.preHeatingSetPoint, + post_heating_set_point: this.state.postHeatingSetPoint, + pre_cooling_set_point: this.state.preCoolingSetPoint, + post_cooling_set_point: this.state.postCoolingSetPoint, + user_id: this.props.userId, + } + ); + this.setState({ action: 'updated' }, () => { + alert('Update successful.'); + }); + } } render() { + const rows = this.props.thermalComfortLog.map((thermalComfort) => { + const delta = Object.entries(thermalComfort.delta) + .filter(entry => entry[0] !== 'id' && entry[0] !== 'building_id') + .map(entry => { + return ( +
    + {entry[0]} : {entry[1]} +
    + ); + }); + let updatedTime = new Date(thermalComfort.updated_time); + updatedTime = `${updatedTime.toLocaleDateString('en-US')} ${updatedTime.toLocaleTimeString('en-US')}`; + + return ( + + + + + + + ); + }); + return (
    @@ -63,9 +102,9 @@ class ThermalComfort extends Component {
    {' '}
    + +
    +
    +

    Change History

    +
    +
    + +
    +
    +
    +
    {thermalComfort.id}{delta}{thermalComfort.user_id}{updatedTime}
    + + + + + + + + {rows} + +
    IDChangesUser IDUpdated Time
    + +
    @@ -163,83 +235,20 @@ class ThermalComfort extends Component {
    - - Modal title - - This is Modal body! - - - {' '} - - - ); } } ThermalComfort.propTypes = { + userId: PropTypes.string, preHeatingSetPoint: PropTypes.number, postHeatingSetPoint: PropTypes.number, preCoolingSetPoint: PropTypes.number, postCoolingSetPoint: PropTypes.number, updateThermalComfort: PropTypes.func, buildingId: PropTypes.number, -}; - -Modal.propTypes = { - // boolean to control the state of the popover - isOpen: PropTypes.bool, - autoFocus: PropTypes.bool, - // if modal should be centered vertically in viewport - centered: PropTypes.bool, - // corresponds to bootstrap's modal sizes, ie. 'lg' or 'sm' - size: PropTypes.string, - // callback for toggling isOpen in the controlling component - toggle: PropTypes.func, - role: PropTypes.string, // defaults to "dialog" - // used to reference the ID of the title element in the modal - labelledBy: PropTypes.string, - keyboard: PropTypes.bool, - // control backdrop, see http://v4-alpha.getbootstrap.com/components/modal/#options - backdrop: PropTypes.oneOfType([ - PropTypes.bool, - PropTypes.oneOf(['static']), - ]), - // if body of modal should be scrollable when content is long - scrollable: PropTypes.bool, - // external: PropTypes.node, - // called on componentDidMount - onEnter: PropTypes.func, - // called on componentWillUnmount - onExit: PropTypes.func, - // called when done transitioning in - onOpened: PropTypes.func, - // called when done transitioning out - onClosed: PropTypes.func, - className: PropTypes.string, - wrapClassName: PropTypes.string, - modalClassName: PropTypes.string, - backdropClassName: PropTypes.string, - contentClassName: PropTypes.string, - // boolean to control whether the fade transition occurs (default: true) - fade: PropTypes.bool, - cssModule: PropTypes.objectOf, - // zIndex defaults to 1000. - zIndex: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - // backdropTransition - controls backdrop transition - // timeout is 150ms by default to match bootstrap - // see Fade for more details - backdropTransition: PropTypes.shape, - // modalTransition - controls modal transition - // timeout is 300ms by default to match bootstrap - // see Fade for more details - innerRef: PropTypes.objectOf, - // if modal should be destructed/removed from DOM after closing - unmountOnClose: PropTypes.bool, // defaults to true + thermalComfortLog: PropTypes.arrayOf, }; export default ThermalComfort; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 6edacc5b..0674bd82 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -6,6 +6,8 @@ import Loading from '../../components/Loading'; import { loadOccupants, loadThermalComfort, + loadOccupantsLog, + loadThermalComfortLog, updateOccupants, updateThermalComfort, } from './actions'; @@ -27,7 +29,9 @@ class Performance extends Component { const buildingId = this.props.building.building_id; console.log(buildingId); // eslint-disable-line this.props.loadOccupants(buildingId); + this.props.loadOccupantsLog(buildingId); this.props.loadThermalComfort(buildingId); + this.props.loadThermalComfortLog(buildingId); } render() { @@ -35,17 +39,27 @@ class Performance extends Component { console.log(this.props); // eslint-disable-line const { - performance, + user, performance, } = this.props; let { - occupants, thermalComfort, + occupants, + thermalComfort, + } = performance; + const { + occupantsLog, + thermalComfortLog, } = performance; mainContent = ; - if (occupants.data !== undefined && thermalComfort.data !== undefined && + if (user !== undefined && user.user_id !== undefined && + occupants.data !== undefined && thermalComfort.data !== undefined && occupants.data !== null && thermalComfort.data !== null && - occupants.data.occupants !== undefined && thermalComfort.data.thermalComfort !== undefined) { + occupants.data.occupants !== undefined && thermalComfort.data.thermalComfort !== undefined && + occupantsLog.data !== null && thermalComfortLog.data !== null && + occupantsLog.data.data !== undefined && thermalComfortLog.data.data !== undefined) { + + const userId = user.user_id.split('|')[1]; if (occupants.data.occupants === null) { occupants = { @@ -78,6 +92,8 @@ class Performance extends Component { preVacantUnits={occupants.pre_vacant_units} postVacantUnits={occupants.post_vacant_units} updateOccupants={this.props.updateOccupants} + userId={userId} + occupantsLog={occupantsLog.data.data} />
    @@ -88,6 +104,8 @@ class Performance extends Component { preCoolingSetPoint={thermalComfort.pre_cooling_set_point} postCoolingSetPoint={thermalComfort.post_cooling_set_point} updateThermalComfort={this.props.updateThermalComfort} + userId={userId} + thermalComfortLog={thermalComfortLog.data.data} />
    @@ -115,8 +133,11 @@ Performance.propTypes = { building: buildingDetailPropTypes, loadOccupants: PropTypes.func, loadThermalComfort: PropTypes.func, + loadOccupantsLog: PropTypes.func, + loadThermalComfortLog: PropTypes.func, updateOccupants: PropTypes.func, updateThermalComfort: PropTypes.func, + user: PropTypes.objectOf, performance: PropTypes.objectOf, }; @@ -124,6 +145,8 @@ const mapDispatchToProps = dispatch => ( bindActionCreators({ loadOccupants, loadThermalComfort, + loadOccupantsLog, + loadThermalComfortLog, updateOccupants, updateThermalComfort, }, dispatch) @@ -131,10 +154,7 @@ const mapDispatchToProps = dispatch => ( const mapStateToProps = state => ({ performance: state.bloclink, - occupants: state.bloclink.occupants, - thermalComfort: state.bloclink.thermalComfort, - // occupants: state.occupants, - // thermalComfort: state.thermalComfort, + user: state.user, }); export default connect(mapStateToProps, mapDispatchToProps)(Performance); diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index f4d12e09..46da9491 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -27,6 +27,16 @@ const PerformanceInitialState = { error: false, data: null, }, + occupantsLog: { + loading: false, + error: false, + data: null, + }, + thermalComfortLog: { + loading: false, + error: false, + data: null, + }, }; export default function (state = PerformanceInitialState, action) { -- GitLab From afc0522dc71ee81a5397e02118149cf1a09cca9f Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 23 May 2019 12:21:10 -0400 Subject: [PATCH 16/54] Add react-modal library --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 5bf2fb11..67f057fc 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "react-highcharts": "^12.0.0", "react-json-tree": "^0.10.9", "react-leaflet": "^1.4.1", + "react-modal": "^3.8.1", "react-placeholder": "^1.0.6", "react-redux": "^4.4.5", "react-router": "^3.0.0", -- GitLab From 6d9904a8adec1b2defdc8e436b24d5bb7276eb8c Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 24 May 2019 16:17:40 -0400 Subject: [PATCH 17/54] Add Retrofit section --- src/components/Performance/ResultMessage.js | 22 ++ src/components/Performance/RetrofitRow.js | 227 +++++++++++++++ src/components/Performance/Retrofits.js | 292 ++++++++++++++++++++ src/containers/Performance/index.js | 61 ++++ 4 files changed, 602 insertions(+) create mode 100644 src/components/Performance/ResultMessage.js create mode 100644 src/components/Performance/RetrofitRow.js create mode 100644 src/components/Performance/Retrofits.js diff --git a/src/components/Performance/ResultMessage.js b/src/components/Performance/ResultMessage.js new file mode 100644 index 00000000..22e20eea --- /dev/null +++ b/src/components/Performance/ResultMessage.js @@ -0,0 +1,22 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + + +const ResultMessage = (props) => { + return ( + + {props.messageContent} + + ); +}; + +ResultMessage.propTypes = { + messageStyle: PropTypes.shape({ + downpayment: PropTypes.string, + expected_net_noi_dscr: PropTypes.string, + expected_payback: PropTypes.string, + }), + messageContent: PropTypes.string, +}; + +export default ResultMessage; diff --git a/src/components/Performance/RetrofitRow.js b/src/components/Performance/RetrofitRow.js new file mode 100644 index 00000000..20b622dc --- /dev/null +++ b/src/components/Performance/RetrofitRow.js @@ -0,0 +1,227 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { + Input, + Button, + Dropdown, + DropdownToggle, + DropdownMenu, + DropdownItem, +} from 'reactstrap'; + + +class RetrofitRow extends Component { + constructor(props) { + super(props); + this.handleOnChange = this.handleOnChange.bind(this); + this.onDelEvent = this.onDelEvent.bind(this); + this.toggleRetrofit = this.toggleRetrofit.bind(this); + this.togglePrimaryUtility = this.togglePrimaryUtility.bind(this); + this.toggleSecondUtility = this.toggleSecondUtility.bind(this); + this.changeRetrofit = this.changeRetrofit.bind(this); + this.changePrimaryUtility = this.changePrimaryUtility.bind(this); + this.changeSecondUtility = this.changeSecondUtility.bind(this); + this.state = { + id: props.id, + retrofit_name: props.retrofitName, + install_start_date: props.installStartDate, + install_end_date: props.installEndDate, + primary_utility: props.primaryUtility, + second_utility: props.secondUtility, + notes: props.notes, + retrofitDropdownOpen: false, + retrofitDropDownValue: props.retrofitName, + retrofitNames: props.retrofitNames !== undefined ? + props.retrofitNames.map((retrofitName, id) => { + return { id, key: id, name: retrofitName }; + }) : [], + primaryUtilityDropdownOpen: false, + primaryUtilityDropDownValue: props.primaryUtility, + secondUtilityDropdownOpen: false, + secondUtilityDropDownValue: props.secondUtility, + utilityNames: props.utilityNames !== undefined ? props.utilityNames.map((utilityName, id) => { + return { id, key: id, name: utilityName }; + }) : [], + }; + } + + onDelEvent() { + this.props.onDelEvent(this.props.id); + } + + toggleRetrofit() { + this.setState({ + retrofitDropdownOpen: !this.state.retrofitDropdownOpen, + }); + } + + togglePrimaryUtility() { + this.setState({ + primaryUtilityDropdownOpen: !this.state.primaryUtilityDropdownOpen, + }); + } + + toggleSecondUtility() { + this.setState({ + secondUtilityDropdownOpen: !this.state.secondUtilityDropdownOpen, + }); + } + + changeRetrofit(e) { + this.setState({ retrofitDropDownValue: e.currentTarget.textContent }); + } + + changePrimaryUtility(e) { + this.setState({ primaryUtilityDropDownValue: e.currentTarget.textContent }); + } + + changeSecondUtility(e) { + this.setState({ secondUtilityDropDownValue: e.currentTarget.textContent }); + } + + handleOnChange = (event) => { + this.setState({ [event.target.name]: event.target.value }, + () => { + this.props.onChangeEvent(this.state); + }); + } + + render() { + const style = { textAlign: 'left' }; + const retrofitNames = this.state.retrofitNames.map(e => { + return ( + + {e.name} + + ); + }); + const primaryUtilityNames = this.state.utilityNames.map(e => { + return ( + + {e.name} + + ); + }); + const secondUtilityNames = this.state.utilityNames.map(e => { + return ( + + {e.name} + + ); + }); + const dropdownStyle = { + marginLeft: '0px', + }; + return ( +
    + + + {this.state.retrofitDropDownValue} + + + {retrofitNames} + + + + + + + + + + {this.state.primaryUtilityDropDownValue} + + + {primaryUtilityNames} + + + + + + {this.state.secondUtilityDropDownValue} + + + {secondUtilityNames} + + + + + + +
    + {title} +
    + Currently no retrofits. +
    + + {header} + + + {retrofits} + +
    + + +
    +
    +    +   + {saveButton} +
    +
    + + ); + } +} + +Retrofits.propTypes = { + blockStyle: PropTypes.shape({ + marginBottom: PropTypes.string, + }), + headerStyle: PropTypes.shape({ + textAlign: PropTypes.string, + marginBottom: PropTypes.string, + }), + retrofitNames: PropTypes.arrayOf, + utilityNames: PropTypes.arrayOf, + retrofits: PropTypes.arrayOf, + data: PropTypes.arrayOf( + PropTypes.shape({ + duration: PropTypes.string, + interest_rate: PropTypes.string, + lender: PropTypes.string, + max_loan_amount: PropTypes.string, + }), + ), + successMessageStyle: PropTypes.shape({ + color: PropTypes.string, + paddingLeft: PropTypes.string, + fontWeight: PropTypes.string, + }), + errorMessageStyle: PropTypes.shape({ + color: PropTypes.string, + paddingLeft: PropTypes.string, + fontWeight: PropTypes.string, + }), + defaultMessageStyle: PropTypes.shape({ + color: PropTypes.string, + paddingLeft: PropTypes.string, + fontWeight: PropTypes.string, + }), + buildingId: PropTypes.number, + updateRetrofits: PropTypes.func, + error: PropTypes.bool, + loading: PropTypes.bool, +}; + +export default Retrofits; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 0674bd82..00fdc7b9 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -15,6 +15,7 @@ import buildingDetailPropTypes from '../../containers/Building/propTypes'; import LinkBarDetail from '../../components/LinkBarDetail'; import Occupants from '../../components/Performance/Occupants'; import ThermalComfort from '../../components/Performance/ThermalComfort'; +import Retrofits from '../../components/Performance/Retrofits'; class Performance extends Component { @@ -36,6 +37,29 @@ class Performance extends Component { render() { let mainContent = null; + + const blockStyle = { marginBottom: '40px', marginTop: '40px' }; + const headerStyle = { + textAlign: 'left', + marginBottom: '25px', + paddingLeft: '10px', + }; + const successMessageStyle = { + color: 'green', + paddingLeft: '25px', + fontWeight: 'bold', + }; + const errorMessageStyle = { + color: 'red', + paddingLeft: '25px', + fontWeight: 'bold', + }; + const defaultMessageStyle = { + color: 'black', + paddingLeft: '25px', + fontWeight: 'bold', + }; + console.log(this.props); // eslint-disable-line const { @@ -82,6 +106,25 @@ class Performance extends Component { thermalComfort = thermalComfort.data.thermalComfort; } + const retrofits = [ + { + retrofit_name: 'Weatherstripping', + install_start_date: '2019-04-20', + install_end_date: '2019-05-20', + primary_utility: 'Natural Gas', + second_utility: 'Oil', + notes: 'Test notes 1', + }, + { + retrofit_name: 'Toilet Replacement', + install_start_date: '2019-03-20', + install_end_date: '2019-04-12', + primary_utility: 'Water', + second_utility: 'Natural Gas', + notes: 'Test notes 2', + }, + ]; + mainContent = (
    @@ -109,6 +152,23 @@ class Performance extends Component { />
    +
    +
    + +
    +
    ); } @@ -137,6 +197,7 @@ Performance.propTypes = { loadThermalComfortLog: PropTypes.func, updateOccupants: PropTypes.func, updateThermalComfort: PropTypes.func, + updateRetrofits: PropTypes.func, user: PropTypes.objectOf, performance: PropTypes.objectOf, }; -- GitLab From 03a3218819257bf6b766f99ebae29264e07f8659 Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 24 May 2019 17:00:26 -0400 Subject: [PATCH 18/54] Add pagination to occupants --- src/components/Performance/Occupants.js | 78 ++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index a164f1e8..86d8776b 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -25,6 +25,7 @@ Modal.setAppElement('body'); class Occupants extends Component { constructor(props) { + global.expandNum = 5; super(props); this.handleOnChange = this.handleOnChange.bind(this); this.handleUpdateOccupants = this.handleUpdateOccupants.bind(this); @@ -34,10 +35,53 @@ class Occupants extends Component { postVacantUnits: props.postVacantUnits, modalIsOpen: false, action: null, + occupantsLog: (this.props.occupantsLog.length > global.expandNum) ? + this.props.occupantsLog.slice(0, global.expandNum) : this.props.occupantsLog, + showNextButton: (this.props.occupantsLog.length > global.expandNum) === true, + showlastButton: false, }; this.openModal = this.openModal.bind(this); this.closeModal = this.closeModal.bind(this); } + nextRecords = () => { + console.log(this.props.occupantsLog.slice(0, this.state.occupantsLog.length + global.expandNum)); // eslint-disable-line + this.setState({ + occupantsLog: + this.props.occupantsLog.slice(this.state.occupantsLog.length, + this.state.occupantsLog.length + global.expandNum), + }, () => { + console.log('Expanded'); // eslint-disable-line + this.setState({ + showLastButton: true, + }); + console.log(this.state.occupantsLog.length); // eslint-disable-line + console.log(this.props.occupantsLog.length); // eslint-disable-line + if (this.state.occupantsLog.length === this.props.occupantsLog.length) { + console.log(this.props.occupantsLog.length); // eslint-disable-line + this.setState({ + showNextButton: false, + }); + } + }); + } + lastRecords = () => { + const collapeNum = this.state.occupantsLog.length === this.props.occupantsLog.length ? + this.state.occupantsLog.length % global.expandNum : global.expandNum; + this.setState({ + occupantsLog: this.props.occupantsLog.slice(this.state.occupantsLog.length, + this.state.occupantsLog.length - collapeNum), + }, () => { + console.log('Collapsed'); // eslint-disable-line + this.setState({ + showNextButton: true, + }); + if (this.state.occupantsLog.length <= global.expandNum) { + this.setState({ + showLastButton: false, + }); + } + }); + } openModal() { this.setState({ modalIsOpen: true }); } @@ -66,7 +110,7 @@ class Occupants extends Component { } render() { - const rows = this.props.occupantsLog.map((occupant) => { + const rows = this.state.occupantsLog.map((occupant) => { const delta = Object.entries(occupant.delta) .filter(entry => entry[0] !== 'id' && entry[0] !== 'building_id') .map(entry => { @@ -89,6 +133,30 @@ class Occupants extends Component { ); }); + let nextButton = null; + let lastButton = null; + const buttonStyle = { + textAlign: 'center', + marginBottom: '30px', + marginLeft: '0px', + cursor: 'pointer', + }; + + if (this.state.showNextButton) { + nextButton = ( + + ); + } + if (this.state.showLastButton) { + lastButton = ( + + ); + } + return (
    @@ -145,6 +213,14 @@ class Occupants extends Component { {rows}
    +
    +
    + {lastButton} +
    +
    + {nextButton} +
    +
    -- GitLab From bac5bbd4e2158fe50e59478d98e7349f81ead35b Mon Sep 17 00:00:00 2001 From: akkking Date: Tue, 28 May 2019 14:50:40 -0400 Subject: [PATCH 19/54] Apply modal pagination to both occupants and thermal comfort --- src/components/Performance/Occupants.js | 32 ++++----- src/components/Performance/RetrofitRow.js | 1 + src/components/Performance/Retrofits.js | 3 +- src/components/Performance/ThermalComfort.js | 75 +++++++++++++++++++- 4 files changed, 91 insertions(+), 20 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index 86d8776b..414b9011 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -38,26 +38,25 @@ class Occupants extends Component { occupantsLog: (this.props.occupantsLog.length > global.expandNum) ? this.props.occupantsLog.slice(0, global.expandNum) : this.props.occupantsLog, showNextButton: (this.props.occupantsLog.length > global.expandNum) === true, + currentLogPos: 0, showlastButton: false, }; this.openModal = this.openModal.bind(this); this.closeModal = this.closeModal.bind(this); } nextRecords = () => { - console.log(this.props.occupantsLog.slice(0, this.state.occupantsLog.length + global.expandNum)); // eslint-disable-line + // console.log(this.props.occupantsLog.slice(0, global.expandNum)); // eslint-disable-line this.setState({ - occupantsLog: - this.props.occupantsLog.slice(this.state.occupantsLog.length, - this.state.occupantsLog.length + global.expandNum), + currentLogPos: this.state.currentLogPos + global.expandNum, }, () => { - console.log('Expanded'); // eslint-disable-line this.setState({ + occupantsLog: + this.props.occupantsLog.slice(this.state.currentLogPos, + this.state.currentLogPos + global.expandNum), showLastButton: true, }); - console.log(this.state.occupantsLog.length); // eslint-disable-line - console.log(this.props.occupantsLog.length); // eslint-disable-line - if (this.state.occupantsLog.length === this.props.occupantsLog.length) { - console.log(this.props.occupantsLog.length); // eslint-disable-line + console.log(this.state.currentLogPos); // eslint-disable-line + if (this.state.currentLogPos + global.expandNum >= this.props.occupantsLog.length) { this.setState({ showNextButton: false, }); @@ -65,17 +64,14 @@ class Occupants extends Component { }); } lastRecords = () => { - const collapeNum = this.state.occupantsLog.length === this.props.occupantsLog.length ? - this.state.occupantsLog.length % global.expandNum : global.expandNum; this.setState({ - occupantsLog: this.props.occupantsLog.slice(this.state.occupantsLog.length, - this.state.occupantsLog.length - collapeNum), + occupantsLog: this.props.occupantsLog.slice(this.state.currentLogPos - global.expandNum, + this.state.currentLogPos), + currentLogPos: this.state.currentLogPos - global.expandNum, + showNextButton: true, }, () => { - console.log('Collapsed'); // eslint-disable-line - this.setState({ - showNextButton: true, - }); - if (this.state.occupantsLog.length <= global.expandNum) { + console.log(this.state.currentLogPos); // eslint-disable-line + if (this.state.currentLogPos === 0) { this.setState({ showLastButton: false, }); diff --git a/src/components/Performance/RetrofitRow.js b/src/components/Performance/RetrofitRow.js index 20b622dc..1367ab0f 100644 --- a/src/components/Performance/RetrofitRow.js +++ b/src/components/Performance/RetrofitRow.js @@ -190,6 +190,7 @@ class RetrofitRow extends Component { @@ -169,7 +175,12 @@ class RetrofitRow extends Component { {this.state.primaryUtilityDropDownValue} - + {primaryUtilityNames} @@ -183,7 +194,12 @@ class RetrofitRow extends Component { {this.state.secondUtilityDropDownValue} - + {secondUtilityNames} @@ -213,6 +229,7 @@ class RetrofitRow extends Component { RetrofitRow.propTypes = { id: PropTypes.number, + retrofitId: PropTypes.number, retrofitName: PropTypes.string, installStartDate: PropTypes.string, installEndDate: PropTypes.string, @@ -220,7 +237,7 @@ RetrofitRow.propTypes = { secondUtility: PropTypes.string, notes: PropTypes.string, utilityNames: PropTypes.arrayOf, - retrofitNames: PropTypes.arrayOf, + retrofitMeta: PropTypes.arrayOf, onDelEvent: PropTypes.func, onChangeEvent: PropTypes.func, }; diff --git a/src/components/Performance/Retrofits.js b/src/components/Performance/Retrofits.js index c6b96ce3..5d68a676 100644 --- a/src/components/Performance/Retrofits.js +++ b/src/components/Performance/Retrofits.js @@ -15,12 +15,13 @@ class Retrofits extends Component { this.addRow = this.addRow.bind(this); this.updateRow = this.updateRow.bind(this); this.state = { - retrofitNames: props.retrofitNames, utilityNames: props.utilityNames, retrofits: props.retrofits, - retrofit_name: 'Waterstripping', - install_start_date: null, - install_end_date: null, + retrofitsLog: props.retrofitsLog, + retrofit_id: 1, + retrofit_name: 'Water Stripping', + install_start_date: '2019-05-01', + install_end_date: '2019-06-01', primary_utility: 'Natural Gas', second_utility: 'Water', notes: null, @@ -29,7 +30,7 @@ class Retrofits extends Component { validateInputs = () => { const emptyFields = []; - if (this.state.retrofits.length > 0) { + if (this.state.retrofits !== null && this.state.retrofits.length > 0) { Object.values(this.state.retrofits).forEach(retrofit => { console.log(retrofit); // eslint-disable-line if (retrofit.retrofit_name === null && @@ -85,14 +86,16 @@ class Retrofits extends Component { }; console.log(this.state.retrofits); // eslint-disable-line const retrofits = this.state.retrofits; + console.log(retrofits); // eslint-disable-line retrofits.push(retrofit); + console.log(retrofits); // eslint-disable-line this.setState({ retrofits }, () => { console.log(this.state.retrofits, 'New retrofit added!'); // eslint-disable-line this.setState({ id: this.state.id + 1, - retrofit_name: 'Waterstripping', - install_start_date: null, - install_end_date: null, + retrofit_name: 'Water Stripping', + install_start_date: '2019-05-01', + install_end_date: '2019-06-01', primary_utility: 'Natural Gas', second_utility: 'Water', notes: null, @@ -107,6 +110,7 @@ class Retrofits extends Component { console.log(row.id); // eslint-disable-line if (id === row.id) { const tmp = { id }; + // tmp.retrofit_id = row.retrofit_id; tmp.retrofit_name = row.retrofit_name; tmp.install_start_date = row.install_start_date; tmp.install_end_date = row.install_end_date; @@ -155,16 +159,18 @@ class Retrofits extends Component { }); let retrofits = []; + let historyButton = null; let saveButton = null; - if (Object.keys(this.state.retrofits).length !== 0) { + if (this.state.retrofits !== null && Object.keys(this.state.retrofits).length !== 0) { retrofits = this.state.retrofits.map((retrofit, index) => { return ( Save @@ -193,6 +200,18 @@ class Retrofits extends Component { ); } + if (this.state.retrofitsLog !== null && Object.keys(this.state.retrofitsLog).length !== 0) { + historyButton = ( + + ); + } + let messageStyle = {}; let messageContent = null; @@ -231,7 +250,8 @@ class Retrofits extends Component { onClick={this.addRow} > + Retrofit -   +   + {historyButton} {saveButton} @@ -264,9 +284,10 @@ Retrofits.propTypes = { textAlign: PropTypes.string, marginBottom: PropTypes.string, }), - retrofitNames: PropTypes.arrayOf, + retrofitMeta: PropTypes.arrayOf, utilityNames: PropTypes.arrayOf, retrofits: PropTypes.arrayOf, + retrofitsLog: PropTypes.arrayOf, data: PropTypes.arrayOf( PropTypes.shape({ duration: PropTypes.string, -- GitLab From fd0b3deabae8072dc98d7e3c6f9723caacbe08d9 Mon Sep 17 00:00:00 2001 From: akkking Date: Wed, 29 May 2019 18:15:37 -0400 Subject: [PATCH 23/54] update retrofit and log --- src/containers/Performance/actions.js | 7 +++ src/containers/Performance/constants.js | 3 ++ src/containers/Performance/index.js | 63 ++++++++++++++++--------- src/containers/Performance/reducer.js | 2 +- src/containers/Performance/sagas.js | 22 +++++++++ 5 files changed, 74 insertions(+), 23 deletions(-) diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index ca6d52c0..4f90cd91 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -26,6 +26,9 @@ import { UPDATE_THERMAL_COMFORT_REQUESTED, UPDATE_THERMAL_COMFORT_SUCCEEDED, UPDATE_THERMAL_COMFORT_FAILED, + UPDATE_RETROFITS_REQUESTED, + UPDATE_RETROFITS_SUCCEEDED, + UPDATE_RETROFITS_FAILED, CREATE_OCCUPANTS_LOG_REQUESTED, CREATE_OCCUPANTS_LOG_SUCCEEDED, CREATE_OCCUPANTS_LOG_FAILED, @@ -66,6 +69,10 @@ export const updateThermalComfort = makeActionCreator(UPDATE_THERMAL_COMFORT_REQ export const updateThermalComfortSucceeded = makeActionCreator(UPDATE_THERMAL_COMFORT_SUCCEEDED, 'instance'); export const updateThermalComfortFailed = makeActionCreator(UPDATE_THERMAL_COMFORT_FAILED, 'error'); +export const updateRetrofits = makeActionCreator(UPDATE_RETROFITS_REQUESTED, 'buildingId', 'payload'); +export const updateRetrofitsSucceeded = makeActionCreator(UPDATE_RETROFITS_SUCCEEDED, 'payload', 'instance'); +export const updateRetrofitsFailed = makeActionCreator(UPDATE_RETROFITS_FAILED, 'error'); + export const createOccupantsLog = makeActionCreator(CREATE_OCCUPANTS_LOG_REQUESTED, 'buildingId', 'payload'); export const createOccupantsLogSucceeded = makeActionCreator(CREATE_OCCUPANTS_LOG_SUCCEEDED, 'instance'); export const createOccupantsLogFailed = makeActionCreator(CREATE_OCCUPANTS_LOG_FAILED, 'error'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index c1b96178..37c7ccf3 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -28,6 +28,9 @@ export const UPDATE_OCCUPANTS_FAILED = 'UPDATE_OCCUPANTS_FAILED'; export const UPDATE_THERMAL_COMFORT_REQUESTED = 'UPDATE_THERMAL_COMFORT_REQUESTED'; export const UPDATE_THERMAL_COMFORT_SUCCEEDED = 'UPDATE_THERMAL_COMFORT_SUCCEEDED'; export const UPDATE_THERMAL_COMFORT_FAILED = 'UPDATE_THERMAL_COMFORT_FAILED'; +export const UPDATE_RETROFITS_REQUESTED = 'UPDATE_RETROFITS_REQUESTED'; +export const UPDATE_RETROFITS_SUCCEEDED = 'UPDATE_RETROFITS_SUCCEEDED'; +export const UPDATE_RETROFITS_FAILED = 'UPDATE_RETROFITS_FAILED'; export const CREATE_OCCUPANTS_LOG_REQUESTED = 'CREATE_OCCUPANTS_LOG_REQUESTED'; export const CREATE_OCCUPANTS_LOG_SUCCEEDED = 'CREATE_OCCUPANTS_LOG_SUCCEEDED'; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 75c3cf11..aa9f8186 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -13,6 +13,7 @@ import { loadRetrofitMeta, updateOccupants, updateThermalComfort, + updateRetrofits, } from './actions'; import buildingDetailPropTypes from '../../containers/Building/propTypes'; import LinkBarDetail from '../../components/LinkBarDetail'; @@ -69,7 +70,8 @@ class Performance extends Component { console.log(this.props); // eslint-disable-line const { - user, performance, + user, + performance, } = this.props; let { occupants, @@ -79,6 +81,11 @@ class Performance extends Component { occupantsLog, thermalComfortLog, } = performance; + const { + retrofits, + retrofitsLog, + retrofitMeta, + } = performance; mainContent = ; @@ -87,7 +94,9 @@ class Performance extends Component { occupants.data !== null && thermalComfort.data !== null && occupants.data.occupants !== undefined && thermalComfort.data.thermalComfort !== undefined && occupantsLog.data !== null && thermalComfortLog.data !== null && - occupantsLog.data.data !== undefined && thermalComfortLog.data.data !== undefined) { + occupantsLog.data.data !== undefined && thermalComfortLog.data.data !== undefined && + retrofits.data !== null && retrofitsLog.data !== null && retrofitMeta.data !== null + ) { const userId = user.user_id.split('|')[1]; @@ -112,24 +121,32 @@ class Performance extends Component { thermalComfort = thermalComfort.data.thermalComfort; } - const retrofits = [ - { - retrofit_name: 'Weather Stripping', - install_start_date: '2019-04-20', - install_end_date: '2019-05-20', - primary_utility: 'Natural Gas', - second_utility: 'Oil', - notes: 'Test notes 1', - }, - { - retrofit_name: 'Toilet Replacement', - install_start_date: '2019-03-20', - install_end_date: '2019-04-12', - primary_utility: 'Water', - second_utility: 'Natural Gas', - notes: 'Test notes 2', - }, - ]; + const retrofitsData = retrofits.data.retrofits === null ? [] : retrofits.data.retrofits; + // let retrofitNames = []; + // if (retrofitMeta.data.data !== null) { + // retrofitNames = retrofitMeta.data.data.map(item => { + // return item.retrofit_name; + // }); + // } + + // const retrofits = [ + // { + // retrofit_name: 'Weather Stripping', + // install_start_date: '2019-04-20', + // install_end_date: '2019-05-20', + // primary_utility: 'Natural Gas', + // second_utility: 'Oil', + // notes: 'Test notes 1', + // }, + // { + // retrofit_name: 'Toilet Replacement', + // install_start_date: '2019-03-20', + // install_end_date: '2019-04-12', + // primary_utility: 'Water', + // second_utility: 'Natural Gas', + // notes: 'Test notes 2', + // }, + // ]; mainContent = (
    @@ -162,9 +179,10 @@ class Performance extends Component {
    ( loadRetrofitMeta, updateOccupants, updateThermalComfort, + updateRetrofits, }, dispatch) ); diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index 59efcf42..eca58f89 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -49,7 +49,7 @@ const PerformanceInitialState = { retrofits: { loading: false, error: false, - data: null, + data: [], }, retrofitsLog: { loading: false, diff --git a/src/containers/Performance/sagas.js b/src/containers/Performance/sagas.js index b46d3410..adcde2a3 100644 --- a/src/containers/Performance/sagas.js +++ b/src/containers/Performance/sagas.js @@ -12,6 +12,7 @@ import { RETROFIT_META_REQUESTED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_THERMAL_COMFORT_REQUESTED, + UPDATE_RETROFITS_REQUESTED, CREATE_OCCUPANTS_LOG_REQUESTED, CREATE_THERMAL_COMFORT_LOG_REQUESTED, } from './constants'; @@ -26,6 +27,7 @@ import { retrofitMetaLoaded, retrofitMetaFailed, updateOccupantsSucceeded, updateOccupantsFailed, updateThermalComfortSucceeded, updateThermalComfortFailed, + updateRetrofitsSucceeded, updateRetrofitsFailed, createOccupantsLogSucceeded, createOccupantsLogFailed, createThermalComfortLogSucceeded, createThermalComfortLogFailed, } from './actions'; @@ -103,6 +105,25 @@ function* updateThermalComfort(action) { } } +function* updateRetrofits(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/retrofits/`; + const res = yield call( + request, + SagaRequests.generateURL(url, action), + { + method: 'PUT', + headers: getHeaders(), + body: JSON.stringify(action.payload), + } + ); + + if (!res.err) { + yield put(updateRetrofitsSucceeded(action.payload)); + } else { + yield put(updateRetrofitsFailed(res.err)); + } +} + function* createOccupantsLog(action) { const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants-log/`; const res = yield call( @@ -151,6 +172,7 @@ function* bloclinkWatcher() { yield takeEvery(RETROFIT_META_REQUESTED, loadRetrofitMeta); yield takeEvery(UPDATE_OCCUPANTS_REQUESTED, updateOccupants); yield takeEvery(UPDATE_THERMAL_COMFORT_REQUESTED, updateThermalComfort); + yield takeEvery(UPDATE_RETROFITS_REQUESTED, updateRetrofits); yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); yield takeEvery(CREATE_THERMAL_COMFORT_LOG_REQUESTED, createThermalComfortLog); } -- GitLab From f940297ac0f7dfe7483333decb2d405cf4c2c493 Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 30 May 2019 13:40:31 -0400 Subject: [PATCH 24/54] remove unused css file --- src/components/Blocnote/PreliminaryFinance/CostEstimation.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index 455cfbeb..7ac72966 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -4,7 +4,6 @@ import { Table, Button, } from 'reactstrap'; -import '../styles.css'; import CostEstimationRow from './CostEstimationRow'; -- GitLab From e1279deefceed5e9eca731cf8f2e41ba91b389ff Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 30 May 2019 13:48:50 -0400 Subject: [PATCH 25/54] Update Cost Estimation header format --- .../Blocnote/PreliminaryFinance/CostEstimation.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index 7ac72966..ad5fa447 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -121,7 +121,17 @@ class CostEstimation extends Component {
    ); }); @@ -219,7 +220,7 @@ class Retrofits extends Component {
    - +
    {header} diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js index 82adbce8..2856ed2a 100644 --- a/src/components/Performance/ThermalComfort.js +++ b/src/components/Performance/ThermalComfort.js @@ -35,10 +35,51 @@ class ThermalComfort extends Component { postCoolingSetPoint: props.postCoolingSetPoint, modalIsOpen: false, action: null, + thermalComfortLog: (this.props.thermalComfortLog.length > global.expandNum) ? + this.props.thermalComfortLog.slice(0, global.expandNum) : this.props.thermalComfortLog, + showNextButton: (this.props.thermalComfortLog.length > global.expandNum) === true, + currentLogPos: 0, + showlastButton: false, }; this.openModal = this.openModal.bind(this); this.closeModal = this.closeModal.bind(this); } + nextRecords = () => { + // console.log(this.props.occupantsLog.slice(0, global.expandNum)); // eslint-disable-line + this.setState({ + currentLogPos: this.state.currentLogPos + global.expandNum, + }, () => { + this.setState({ + thermalComfortLog: + this.props.thermalComfortLog.slice(this.state.currentLogPos, + this.state.currentLogPos + global.expandNum), + showLastButton: true, + }); + console.log(this.state.currentLogPos); // eslint-disable-line + if (this.state.currentLogPos + global.expandNum >= this.props.thermalComfortLog.length) { + this.setState({ + showNextButton: false, + }); + } + }); + } + lastRecords = () => { + this.setState({ + thermalComfortLog: this.props.thermalComfortLog.slice( + this.state.currentLogPos - global.expandNum, + this.state.currentLogPos + ), + currentLogPos: this.state.currentLogPos - global.expandNum, + showNextButton: true, + }, () => { + console.log(this.state.currentLogPos); // eslint-disable-line + if (this.state.currentLogPos === 0) { + this.setState({ + showLastButton: false, + }); + } + }); + } openModal() { this.setState({ modalIsOpen: true }); } @@ -68,7 +109,7 @@ class ThermalComfort extends Component { } render() { - const rows = this.props.thermalComfortLog.map((thermalComfort) => { + const rows = this.state.thermalComfortLog.map((thermalComfort) => { const delta = Object.entries(thermalComfort.delta) .filter(entry => entry[0] !== 'id' && entry[0] !== 'building_id') .map(entry => { @@ -91,6 +132,30 @@ class ThermalComfort extends Component { ); }); + let nextButton = null; + let lastButton = null; + const buttonStyle = { + textAlign: 'center', + marginBottom: '30px', + marginLeft: '0px', + cursor: 'pointer', + }; + + if (this.state.showNextButton) { + nextButton = ( + + ); + } + if (this.state.showLastButton) { + lastButton = ( + + ); + } + return (
    @@ -147,6 +212,14 @@ class ThermalComfort extends Component { {rows}
    +
    +
    + {lastButton} +
    +
    + {nextButton} +
    +
    -- GitLab From a9754a4b71887bc678dbd78853ed438ddc0ba164 Mon Sep 17 00:00:00 2001 From: akkking Date: Tue, 28 May 2019 17:59:22 -0400 Subject: [PATCH 20/54] Add retrofits component and container --- src/components/Performance/Retrofits.js | 36 +++++++----- src/containers/Performance/actions.js | 14 +++++ src/containers/Performance/constants.js | 8 +++ src/containers/Performance/index.js | 14 ++++- src/containers/Performance/reducer.js | 74 +++++++++++++++++++++++++ src/containers/Performance/sagas.js | 16 ++++++ 6 files changed, 144 insertions(+), 18 deletions(-) diff --git a/src/components/Performance/Retrofits.js b/src/components/Performance/Retrofits.js index 89f69cd9..c6b96ce3 100644 --- a/src/components/Performance/Retrofits.js +++ b/src/components/Performance/Retrofits.js @@ -215,23 +215,13 @@ class Retrofits extends Component { return (
    -

    - My Retrofits -

    -
    -
    - - {header} - - - {retrofits} - -
    +
    +

    + My Retrofits +

    -
    -
    -
    +
    +
    +
    +
    +
    + + + {header} + + + {retrofits} + +
    +
    +
    +
    +
    ); } diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index e87ba57b..66d87cf0 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -11,6 +11,12 @@ import { THERMAL_COMFORT_LOG_REQUESTED, THERMAL_COMFORT_LOG_SUCCEEDED, THERMAL_COMFORT_LOG_FAILED, + RETROFITS_REQUESTED, + RETROFITS_SUCCEEDED, + RETROFITS_FAILED, + RETROFITS_LOG_REQUESTED, + RETROFITS_LOG_SUCCEEDED, + RETROFITS_LOG_FAILED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_OCCUPANTS_SUCCEEDED, UPDATE_OCCUPANTS_FAILED, @@ -32,6 +38,7 @@ export const occupantsFailed = makeActionCreator(OCCUPANTS_FAILED, 'error'); export const loadOccupantsLog = makeActionCreator(OCCUPANTS_LOG_REQUESTED, 'buildingId'); export const occupantsLogLoaded = makeActionCreator(OCCUPANTS_LOG_SUCCEEDED, 'instance'); export const occupantsLogFailed = makeActionCreator(OCCUPANTS_LOG_FAILED, 'error'); + export const loadThermalComfort = makeActionCreator(THERMAL_COMFORT_REQUESTED, 'buildingId'); export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCEEDED, 'instance'); export const thermalComfortFailed = makeActionCreator(THERMAL_COMFORT_FAILED, 'error'); @@ -39,6 +46,13 @@ export const loadThermalComfortLog = makeActionCreator(THERMAL_COMFORT_LOG_REQUE export const thermalComfortLogLoaded = makeActionCreator(THERMAL_COMFORT_LOG_SUCCEEDED, 'instance'); export const thermalComfortLogFailed = makeActionCreator(THERMAL_COMFORT_LOG_FAILED, 'error'); +export const loadRetrofits = makeActionCreator(RETROFITS_REQUESTED, 'buildingId'); +export const retrofitsLoaded = makeActionCreator(RETROFITS_SUCCEEDED, 'instance'); +export const retrofitsFailed = makeActionCreator(RETROFITS_FAILED, 'error'); +export const loadRetrofitsLog = makeActionCreator(RETROFITS_LOG_REQUESTED, 'buildingId'); +export const retrofitsLogLoaded = makeActionCreator(RETROFITS_LOG_SUCCEEDED, 'instance'); +export const retrofitsLogFailed = makeActionCreator(RETROFITS_LOG_FAILED, 'error'); + export const updateOccupants = makeActionCreator(UPDATE_OCCUPANTS_REQUESTED, 'buildingId', 'payload'); export const updateOccupantsSucceeded = makeActionCreator(UPDATE_OCCUPANTS_SUCCEEDED, 'payload', 'instance'); export const updateOccupantsFailed = makeActionCreator(UPDATE_OCCUPANTS_FAILED, 'error'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index 4aa464e5..0275300c 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -4,6 +4,7 @@ export const OCCUPANTS_FAILED = 'OCCUPANTS_FAILED'; export const OCCUPANTS_LOG_REQUESTED = 'OCCUPANTS_LOG_REQUESTED'; export const OCCUPANTS_LOG_SUCCEEDED = 'OCCUPANTS_LOG_SUCCEEDED'; export const OCCUPANTS_LOG_FAILED = 'OCCUPANTS_LOG_FAILED'; + export const THERMAL_COMFORT_REQUESTED = 'THERMAL_COMFORT_REQUESTED'; export const THERMAL_COMFORT_SUCCEEDED = 'THERMAL_COMFORT_SUCCEEDED'; export const THERMAL_COMFORT_FAILED = 'THERMAL_COMFORT_FAILED'; @@ -11,6 +12,13 @@ export const THERMAL_COMFORT_LOG_REQUESTED = 'THERMAL_COMFORT_LOG_REQUESTED'; export const THERMAL_COMFORT_LOG_SUCCEEDED = 'THERMAL_COMFORT_LOG_SUCCEEDED'; export const THERMAL_COMFORT_LOG_FAILED = 'THERMAL_COMFORT_LOG_FAILED'; +export const RETROFITS_REQUESTED = 'RETROFITS_REQUESTED'; +export const RETROFITS_SUCCEEDED = 'RETROFITS_SUCCEEDED'; +export const RETROFITS_FAILED = 'RETROFITS_FAILED'; +export const RETROFITS_LOG_REQUESTED = 'RETROFITS_LOG_REQUESTED'; +export const RETROFITS_LOG_SUCCEEDED = 'RETROFITS_LOG_SUCCEEDED'; +export const RETROFITS_LOG_FAILED = 'RETROFITS_LOG_FAILED'; + export const UPDATE_OCCUPANTS_REQUESTED = 'UPDATE_OCCUPANTS_REQUESTED'; export const UPDATE_OCCUPANTS_SUCCEEDED = 'UPDATE_OCCUPANTS_SUCCEEDED'; export const UPDATE_OCCUPANTS_FAILED = 'UPDATE_OCCUPANTS_FAILED'; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 00fdc7b9..7ccbbedd 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -5,9 +5,11 @@ import { bindActionCreators } from 'redux'; import Loading from '../../components/Loading'; import { loadOccupants, - loadThermalComfort, loadOccupantsLog, + loadThermalComfort, loadThermalComfortLog, + loadRetrofits, + loadRetrofitsLog, updateOccupants, updateThermalComfort, } from './actions'; @@ -33,6 +35,8 @@ class Performance extends Component { this.props.loadOccupantsLog(buildingId); this.props.loadThermalComfort(buildingId); this.props.loadThermalComfortLog(buildingId); + this.props.loadRetrofits(buildingId); + this.props.loadRetrofitsLog(buildingId); } render() { @@ -192,9 +196,11 @@ class Performance extends Component { Performance.propTypes = { building: buildingDetailPropTypes, loadOccupants: PropTypes.func, - loadThermalComfort: PropTypes.func, loadOccupantsLog: PropTypes.func, + loadThermalComfort: PropTypes.func, loadThermalComfortLog: PropTypes.func, + loadRetrofits: PropTypes.func, + loadRetrofitsLog: PropTypes.func, updateOccupants: PropTypes.func, updateThermalComfort: PropTypes.func, updateRetrofits: PropTypes.func, @@ -205,9 +211,11 @@ Performance.propTypes = { const mapDispatchToProps = dispatch => ( bindActionCreators({ loadOccupants, - loadThermalComfort, loadOccupantsLog, + loadThermalComfort, loadThermalComfortLog, + loadRetrofits, + loadRetrofitsLog, updateOccupants, updateThermalComfort, }, dispatch) diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index 46da9491..4b88bc27 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -11,6 +11,12 @@ import { THERMAL_COMFORT_LOG_REQUESTED, THERMAL_COMFORT_LOG_SUCCEEDED, THERMAL_COMFORT_LOG_FAILED, + RETROFITS_REQUESTED, + RETROFITS_SUCCEEDED, + RETROFITS_FAILED, + RETROFITS_LOG_REQUESTED, + RETROFITS_LOG_SUCCEEDED, + RETROFITS_LOG_FAILED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_OCCUPANTS_SUCCEEDED, UPDATE_OCCUPANTS_FAILED, @@ -27,6 +33,11 @@ const PerformanceInitialState = { error: false, data: null, }, + retrofits: { + loading: false, + error: false, + data: null, + }, occupantsLog: { loading: false, error: false, @@ -37,6 +48,11 @@ const PerformanceInitialState = { error: false, data: null, }, + retrofitsLog: { + loading: false, + error: false, + data: null, + }, }; export default function (state = PerformanceInitialState, action) { @@ -158,6 +174,64 @@ export default function (state = PerformanceInitialState, action) { }, }; + case RETROFITS_REQUESTED: + return { + ...state, + retrofits: { + ...state.retrofits, + loading: true, + error: false, + }, + }; + + case RETROFITS_SUCCEEDED: + return { + ...state, + retrofits: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case RETROFITS_FAILED: + return { + ...state, + retrofits: { + loading: false, + error: action.error, + }, + }; + + case RETROFITS_LOG_REQUESTED: + return { + ...state, + retrofitsLog: { + ...state.retrofitsLog, + loading: true, + error: false, + }, + }; + + case RETROFITS_LOG_SUCCEEDED: + return { + ...state, + retrofitsLog: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case RETROFITS_LOG_FAILED: + return { + ...state, + retrofitsLog: { + loading: false, + error: action.error, + }, + }; + case UPDATE_OCCUPANTS_REQUESTED: return { ...state, diff --git a/src/containers/Performance/sagas.js b/src/containers/Performance/sagas.js index 34d8a268..84684e7e 100644 --- a/src/containers/Performance/sagas.js +++ b/src/containers/Performance/sagas.js @@ -7,6 +7,8 @@ import { OCCUPANTS_LOG_REQUESTED, THERMAL_COMFORT_REQUESTED, THERMAL_COMFORT_LOG_REQUESTED, + RETROFITS_REQUESTED, + RETROFITS_LOG_REQUESTED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_THERMAL_COMFORT_REQUESTED, CREATE_OCCUPANTS_LOG_REQUESTED, @@ -18,6 +20,8 @@ import { occupantsLogLoaded, occupantsLogFailed, thermalComfortLoaded, thermalComfortFailed, thermalComfortLogLoaded, thermalComfortLogFailed, + retrofitsLoaded, retrofitsFailed, + retrofitsLogLoaded, retrofitsLogFailed, updateOccupantsSucceeded, updateOccupantsFailed, updateThermalComfortSucceeded, updateThermalComfortFailed, createOccupantsLogSucceeded, createOccupantsLogFailed, @@ -44,6 +48,16 @@ function* loadThermalComfortLog(action) { yield SagaRequests.get(action, url, thermalComfortLogLoaded, thermalComfortLogFailed); } +function* loadRetrofits(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/retrofits/`; + yield SagaRequests.get(action, url, retrofitsLoaded, retrofitsFailed); +} + +function* loadRetrofitsLog(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/retrofits-log/`; + yield SagaRequests.get(action, url, retrofitsLogLoaded, retrofitsLogFailed); +} + function* updateOccupants(action) { const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants/`; const res = yield call( @@ -125,6 +139,8 @@ function* bloclinkWatcher() { yield takeEvery(OCCUPANTS_LOG_REQUESTED, loadOccupantsLog); yield takeEvery(THERMAL_COMFORT_REQUESTED, loadThermalComfort); yield takeEvery(THERMAL_COMFORT_LOG_REQUESTED, loadThermalComfortLog); + yield takeEvery(RETROFITS_REQUESTED, loadRetrofits); + yield takeEvery(RETROFITS_LOG_REQUESTED, loadRetrofitsLog); yield takeEvery(UPDATE_OCCUPANTS_REQUESTED, updateOccupants); yield takeEvery(UPDATE_THERMAL_COMFORT_REQUESTED, updateThermalComfort); yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); -- GitLab From 91f88f70229f61187af4c089ab99682b70c4f95e Mon Sep 17 00:00:00 2001 From: akkking Date: Wed, 29 May 2019 12:00:18 -0400 Subject: [PATCH 21/54] Add retrofit meta --- src/containers/Performance/actions.js | 6 ++++ src/containers/Performance/constants.js | 3 ++ src/containers/Performance/index.js | 8 +++-- src/containers/Performance/reducer.js | 45 ++++++++++++++++++++++--- src/containers/Performance/sagas.js | 8 +++++ 5 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 66d87cf0..ca6d52c0 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -17,6 +17,9 @@ import { RETROFITS_LOG_REQUESTED, RETROFITS_LOG_SUCCEEDED, RETROFITS_LOG_FAILED, + RETROFIT_META_REQUESTED, + RETROFIT_META_SUCCEEDED, + RETROFIT_META_FAILED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_OCCUPANTS_SUCCEEDED, UPDATE_OCCUPANTS_FAILED, @@ -52,6 +55,9 @@ export const retrofitsFailed = makeActionCreator(RETROFITS_FAILED, 'error'); export const loadRetrofitsLog = makeActionCreator(RETROFITS_LOG_REQUESTED, 'buildingId'); export const retrofitsLogLoaded = makeActionCreator(RETROFITS_LOG_SUCCEEDED, 'instance'); export const retrofitsLogFailed = makeActionCreator(RETROFITS_LOG_FAILED, 'error'); +export const loadRetrofitMeta = makeActionCreator(RETROFIT_META_REQUESTED, 'buildingId'); +export const retrofitMetaLoaded = makeActionCreator(RETROFIT_META_SUCCEEDED, 'instance'); +export const retrofitMetaFailed = makeActionCreator(RETROFIT_META_FAILED, 'error'); export const updateOccupants = makeActionCreator(UPDATE_OCCUPANTS_REQUESTED, 'buildingId', 'payload'); export const updateOccupantsSucceeded = makeActionCreator(UPDATE_OCCUPANTS_SUCCEEDED, 'payload', 'instance'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index 0275300c..c1b96178 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -18,6 +18,9 @@ export const RETROFITS_FAILED = 'RETROFITS_FAILED'; export const RETROFITS_LOG_REQUESTED = 'RETROFITS_LOG_REQUESTED'; export const RETROFITS_LOG_SUCCEEDED = 'RETROFITS_LOG_SUCCEEDED'; export const RETROFITS_LOG_FAILED = 'RETROFITS_LOG_FAILED'; +export const RETROFIT_META_REQUESTED = 'RETROFIT_META_REQUESTED'; +export const RETROFIT_META_SUCCEEDED = 'RETROFIT_META_SUCCEEDED'; +export const RETROFIT_META_FAILED = 'RETROFIT_META_FAILED'; export const UPDATE_OCCUPANTS_REQUESTED = 'UPDATE_OCCUPANTS_REQUESTED'; export const UPDATE_OCCUPANTS_SUCCEEDED = 'UPDATE_OCCUPANTS_SUCCEEDED'; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 7ccbbedd..75c3cf11 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -10,6 +10,7 @@ import { loadThermalComfortLog, loadRetrofits, loadRetrofitsLog, + loadRetrofitMeta, updateOccupants, updateThermalComfort, } from './actions'; @@ -37,6 +38,7 @@ class Performance extends Component { this.props.loadThermalComfortLog(buildingId); this.props.loadRetrofits(buildingId); this.props.loadRetrofitsLog(buildingId); + this.props.loadRetrofitMeta(buildingId); } render() { @@ -112,7 +114,7 @@ class Performance extends Component { const retrofits = [ { - retrofit_name: 'Weatherstripping', + retrofit_name: 'Weather Stripping', install_start_date: '2019-04-20', install_end_date: '2019-05-20', primary_utility: 'Natural Gas', @@ -160,7 +162,7 @@ class Performance extends Component {
    ( loadThermalComfortLog, loadRetrofits, loadRetrofitsLog, + loadRetrofitMeta, updateOccupants, updateThermalComfort, }, dispatch) diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index 4b88bc27..59efcf42 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -17,6 +17,9 @@ import { RETROFITS_LOG_REQUESTED, RETROFITS_LOG_SUCCEEDED, RETROFITS_LOG_FAILED, + RETROFIT_META_REQUESTED, + RETROFIT_META_SUCCEEDED, + RETROFIT_META_FAILED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_OCCUPANTS_SUCCEEDED, UPDATE_OCCUPANTS_FAILED, @@ -28,22 +31,22 @@ const PerformanceInitialState = { error: false, data: null, }, - thermalComfort: { + occupantsLog: { loading: false, error: false, data: null, }, - retrofits: { + thermalComfort: { loading: false, error: false, data: null, }, - occupantsLog: { + thermalComfortLog: { loading: false, error: false, data: null, }, - thermalComfortLog: { + retrofits: { loading: false, error: false, data: null, @@ -53,6 +56,11 @@ const PerformanceInitialState = { error: false, data: null, }, + retrofitMeta: { + loading: false, + error: false, + data: null, + }, }; export default function (state = PerformanceInitialState, action) { @@ -232,6 +240,35 @@ export default function (state = PerformanceInitialState, action) { }, }; + case RETROFIT_META_REQUESTED: + return { + ...state, + retrofitMeta: { + ...state.retrofitMeta, + loading: true, + error: false, + }, + }; + + case RETROFIT_META_SUCCEEDED: + return { + ...state, + retrofitMeta: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case RETROFIT_META_FAILED: + return { + ...state, + retrofitMeta: { + loading: false, + error: action.error, + }, + }; + case UPDATE_OCCUPANTS_REQUESTED: return { ...state, diff --git a/src/containers/Performance/sagas.js b/src/containers/Performance/sagas.js index 84684e7e..b46d3410 100644 --- a/src/containers/Performance/sagas.js +++ b/src/containers/Performance/sagas.js @@ -9,6 +9,7 @@ import { THERMAL_COMFORT_LOG_REQUESTED, RETROFITS_REQUESTED, RETROFITS_LOG_REQUESTED, + RETROFIT_META_REQUESTED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_THERMAL_COMFORT_REQUESTED, CREATE_OCCUPANTS_LOG_REQUESTED, @@ -22,6 +23,7 @@ import { thermalComfortLogLoaded, thermalComfortLogFailed, retrofitsLoaded, retrofitsFailed, retrofitsLogLoaded, retrofitsLogFailed, + retrofitMetaLoaded, retrofitMetaFailed, updateOccupantsSucceeded, updateOccupantsFailed, updateThermalComfortSucceeded, updateThermalComfortFailed, createOccupantsLogSucceeded, createOccupantsLogFailed, @@ -58,6 +60,11 @@ function* loadRetrofitsLog(action) { yield SagaRequests.get(action, url, retrofitsLogLoaded, retrofitsLogFailed); } +function* loadRetrofitMeta(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/retrofit-meta/`; + yield SagaRequests.get(action, url, retrofitMetaLoaded, retrofitMetaFailed); +} + function* updateOccupants(action) { const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants/`; const res = yield call( @@ -141,6 +148,7 @@ function* bloclinkWatcher() { yield takeEvery(THERMAL_COMFORT_LOG_REQUESTED, loadThermalComfortLog); yield takeEvery(RETROFITS_REQUESTED, loadRetrofits); yield takeEvery(RETROFITS_LOG_REQUESTED, loadRetrofitsLog); + yield takeEvery(RETROFIT_META_REQUESTED, loadRetrofitMeta); yield takeEvery(UPDATE_OCCUPANTS_REQUESTED, updateOccupants); yield takeEvery(UPDATE_THERMAL_COMFORT_REQUESTED, updateThermalComfort); yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); -- GitLab From 8ced681472762a53c0496b9f9661147952818321 Mon Sep 17 00:00:00 2001 From: akkking Date: Wed, 29 May 2019 18:15:09 -0400 Subject: [PATCH 22/54] add retrofit and log --- src/components/Performance/RetrofitRow.js | 37 +++++++++++++----- src/components/Performance/Retrofits.js | 47 ++++++++++++++++------- 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/src/components/Performance/RetrofitRow.js b/src/components/Performance/RetrofitRow.js index 1367ab0f..c11f3a18 100644 --- a/src/components/Performance/RetrofitRow.js +++ b/src/components/Performance/RetrofitRow.js @@ -23,17 +23,18 @@ class RetrofitRow extends Component { this.changeSecondUtility = this.changeSecondUtility.bind(this); this.state = { id: props.id, - retrofit_name: props.retrofitName, + retrofit_id: props.retrofitId, install_start_date: props.installStartDate, install_end_date: props.installEndDate, primary_utility: props.primaryUtility, second_utility: props.secondUtility, notes: props.notes, + retrofit_name: props.retrofitName, retrofitDropdownOpen: false, retrofitDropDownValue: props.retrofitName, - retrofitNames: props.retrofitNames !== undefined ? - props.retrofitNames.map((retrofitName, id) => { - return { id, key: id, name: retrofitName }; + retrofitMeta: props.retrofitMeta !== undefined ? + props.retrofitMeta.map((retrofit, id) => { + return { id, key: retrofit.id, name: retrofit.retrofit_name }; }) : [], primaryUtilityDropdownOpen: false, primaryUtilityDropDownValue: props.primaryUtility, @@ -88,7 +89,7 @@ class RetrofitRow extends Component { render() { const style = { textAlign: 'left' }; - const retrofitNames = this.state.retrofitNames.map(e => { + const retrofitMeta = this.state.retrofitMeta.map(e => { return ( {this.state.retrofitDropDownValue} - - {retrofitNames} + + {retrofitMeta}
    - {rows} - + + ); }); props.data.shift(); @@ -57,8 +61,8 @@ const LoanSummary = (props) => { }; LoanSummary.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, data: PropTypes.arrayOf, }; diff --git a/src/components/Blocnote/PreliminaryFinance/LoanSummaryRow.js b/src/components/Blocnote/PreliminaryFinance/LoanSummaryRow.js index 2b3da2b2..d70eee41 100644 --- a/src/components/Blocnote/PreliminaryFinance/LoanSummaryRow.js +++ b/src/components/Blocnote/PreliminaryFinance/LoanSummaryRow.js @@ -29,11 +29,11 @@ const LoanSummaryRow = (props) => { LoanSummaryRow.propTypes = { lender: PropTypes.string, - amountBorrowed: PropTypes.number, - amountUpperLimit: PropTypes.number, - annualInterestRate: PropTypes.number, - duration: PropTypes.number, - monthlyDebtService: PropTypes.number, + amountBorrowed: PropTypes.string, + amountUpperLimit: PropTypes.string, + annualInterestRate: PropTypes.string, + duration: PropTypes.string, + monthlyDebtService: PropTypes.string, }; export default LoanSummaryRow; diff --git a/src/components/Blocnote/PreliminaryFinance/PostRetrofitBalanceSheet.js b/src/components/Blocnote/PreliminaryFinance/PostRetrofitBalanceSheet.js index e27c3f5f..f9c78059 100644 --- a/src/components/Blocnote/PreliminaryFinance/PostRetrofitBalanceSheet.js +++ b/src/components/Blocnote/PreliminaryFinance/PostRetrofitBalanceSheet.js @@ -10,9 +10,13 @@ const PostRetrofitBalanceSheet = (props) => { let header = []; if (props.data !== null) { - header = props.data[0].map((item) => { + header = props.data[0].map((item, index) => { return ( - + ); }); props.data.shift(); @@ -36,8 +40,8 @@ const PostRetrofitBalanceSheet = (props) => { }; PostRetrofitBalanceSheet.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, data: PropTypes.arrayOf, }; diff --git a/src/components/Blocnote/PreliminaryFinance/PostRetrofitIncomeStatement.js b/src/components/Blocnote/PreliminaryFinance/PostRetrofitIncomeStatement.js index c949d896..87c82bfc 100644 --- a/src/components/Blocnote/PreliminaryFinance/PostRetrofitIncomeStatement.js +++ b/src/components/Blocnote/PreliminaryFinance/PostRetrofitIncomeStatement.js @@ -10,9 +10,13 @@ const PostRetrofitIncomeStatement = (props) => { let header = []; if (props.data !== null) { - header = props.data[0].map((item) => { + header = props.data[0].map((item, index) => { return ( - + ); }); props.data.shift(); @@ -36,8 +40,8 @@ const PostRetrofitIncomeStatement = (props) => { }; PostRetrofitIncomeStatement.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, data: PropTypes.arrayOf, }; diff --git a/src/components/Blocnote/PreliminaryFinance/PriorRetrofitBalanceSheet.js b/src/components/Blocnote/PreliminaryFinance/PriorRetrofitBalanceSheet.js index cde94856..fbd4ccab 100644 --- a/src/components/Blocnote/PreliminaryFinance/PriorRetrofitBalanceSheet.js +++ b/src/components/Blocnote/PreliminaryFinance/PriorRetrofitBalanceSheet.js @@ -10,9 +10,13 @@ const PriorRetrofitBalanceSheet = (props) => { let header = []; if (props.data !== null) { - header = props.data[0].map((item) => { + header = props.data[0].map((item, index) => { return ( - + ); }); props.data.shift(); @@ -36,8 +40,8 @@ const PriorRetrofitBalanceSheet = (props) => { }; PriorRetrofitBalanceSheet.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, data: PropTypes.arrayOf, }; diff --git a/src/components/Blocnote/PreliminaryFinance/PriorRetrofitIncomeStatement.js b/src/components/Blocnote/PreliminaryFinance/PriorRetrofitIncomeStatement.js index 0a038581..c8087960 100644 --- a/src/components/Blocnote/PreliminaryFinance/PriorRetrofitIncomeStatement.js +++ b/src/components/Blocnote/PreliminaryFinance/PriorRetrofitIncomeStatement.js @@ -10,9 +10,13 @@ const PriorRetrofitIncomeStatement = (props) => { let header = []; if (props.data !== null) { - header = props.data[0].map((item) => { + header = props.data[0].map((item, index) => { return ( - + ); }); props.data.shift(); @@ -36,8 +40,8 @@ const PriorRetrofitIncomeStatement = (props) => { }; PriorRetrofitIncomeStatement.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, data: PropTypes.arrayOf, }; diff --git a/src/components/Blocnote/PreliminaryFinance/ProjectEconomics.js b/src/components/Blocnote/PreliminaryFinance/ProjectEconomics.js index 9332a32d..dd614088 100644 --- a/src/components/Blocnote/PreliminaryFinance/ProjectEconomics.js +++ b/src/components/Blocnote/PreliminaryFinance/ProjectEconomics.js @@ -19,9 +19,10 @@ class ProjectEconomics extends Component { return false; // skip } return true; - }).map((item) => { + }).map((item, index) => { return ( @@ -43,8 +44,8 @@ class ProjectEconomics extends Component { } ProjectEconomics.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, data: PropTypes.arrayOf, }; diff --git a/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js b/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js index 333d5865..9783c65f 100644 --- a/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js +++ b/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js @@ -28,7 +28,7 @@ class ProjectEconomicsRow extends Component { ProjectEconomicsRow.propTypes = { row_name: PropTypes.string, - amount: PropTypes.number, + amount: PropTypes.string, }; export default ProjectEconomicsRow; diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js index 734e0852..0ce65263 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js @@ -34,9 +34,10 @@ class SavingEstimation extends Component { const rows = []; if (this.state.savingEstimation !== null) { - Object.entries(this.state.savingEstimation).forEach(([utilityName, utilityData]) => { + Object.entries(this.state.savingEstimation).forEach(([utilityName, utilityData], index) => { rows.push( {this.state.scenarioDropDownValue} - + {scenarioOptions} diff --git a/src/components/Blocnote/PreliminaryFinance/TableContent.js b/src/components/Blocnote/PreliminaryFinance/TableContent.js index 8d0c0b91..48c3b985 100644 --- a/src/components/Blocnote/PreliminaryFinance/TableContent.js +++ b/src/components/Blocnote/PreliminaryFinance/TableContent.js @@ -6,8 +6,8 @@ const TableContent = (props) => { let rows = []; if (props.rows !== null) { - rows = props.rows.map((items) => { - const cells = items.map((item) => { + rows = props.rows.map((items, index1) => { + const cells = items.map((item, index2) => { let cellValue = item; if (typeof (item) !== 'string') { cellValue = Math.round(item * 100) / 100; @@ -16,7 +16,9 @@ const TableContent = (props) => { } return ( - + {cells} ); }); diff --git a/src/containers/Blocnote/FinancialInputs/index.js b/src/containers/Blocnote/FinancialInputs/index.js index 2e272d4f..1ff67135 100644 --- a/src/containers/Blocnote/FinancialInputs/index.js +++ b/src/containers/Blocnote/FinancialInputs/index.js @@ -90,6 +90,7 @@ class FinancialInputs extends Component { marginBottom: '25px', paddingLeft: '10px', }; + console.log(this.props); // eslint-disable-line const { blocnote } = this.props; const { fianceOverview, bills, billsOverview, billsSummary, cashBalance, @@ -108,7 +109,6 @@ class FinancialInputs extends Component { liabilities.data !== null && customerPreference.data !== null) { const foData = this.processFinanceOverview(fianceOverview.data); - const financeOverviewExist = fianceOverview.data.instance.financing_overview_data !== undefined; let cashBalanceData = []; @@ -145,6 +145,7 @@ class FinancialInputs extends Component { customerPreferenceData = customerPreference.data.instance; } + console.log(incomeStatement.data.instance); // eslint-disable-line mainContent = (
    Date: Wed, 5 Jun 2019 18:14:10 -0400 Subject: [PATCH 35/54] Fix Cash balance, Income Statement, Bills Overview issues --- .../Blocnote/FinancialInputs/BillsOverview.js | 27 ++++-- .../FinancialInputs/BillsSummaryTable.js | 6 +- .../Blocnote/FinancialInputs/CashBalance.js | 6 +- .../FinancialInputs/CustomerPreference.js | 6 +- .../FinancialInputs/IncomeStatements.js | 91 ++++++++++++------- .../Blocnote/FinancialInputs/LoanOptions.js | 6 +- .../FinancialInputs/MortgageLiabilities.js | 6 +- .../Blocnote/FinancialInputs/ResultMessage.js | 4 +- .../Blocnote/FinancialInputs/index.js | 1 - src/containers/Blocnote/reducer.js | 16 +++- src/containers/Blocnote/sagas.js | 2 +- 11 files changed, 110 insertions(+), 61 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/BillsOverview.js b/src/components/Blocnote/FinancialInputs/BillsOverview.js index c01adf04..d2fc2f06 100644 --- a/src/components/Blocnote/FinancialInputs/BillsOverview.js +++ b/src/components/Blocnote/FinancialInputs/BillsOverview.js @@ -50,7 +50,11 @@ class BillsOverview extends Component { } changeEstimation(e) { - this.setState({ estimationDropDownValue: e.currentTarget.textContent }); + this.setState({ + estimationDropDownValue: e.currentTarget.textContent, + messageContent: null, + messageStyle: 'default', + }); } handleCreateBillsOverview = () => { @@ -176,9 +180,11 @@ class BillsOverview extends Component { ); } - if (this.state.loading) { + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Processing ...'; - this.state.messageStyle = 'default'; } if (this.props.error && typeof this.props.error === 'object') { @@ -192,10 +198,17 @@ class BillsOverview extends Component { } if (!this.props.error && !this.props.loading - && this.props.data !== null - && this.state.action !== null) { - this.state.messageContent = 'Saved!'; - this.state.messageStyle = 'success'; + && this.props.data !== null) { + if (this.state.action === 'updated') { + this.state.messageStyle = 'success'; + this.state.messageContent = 'Projected successfully.'; + } else if (this.state.action === 'created') { + this.state.messageStyle = 'success'; + this.state.messageContent = 'Saved.'; + } else { + this.state.messageStyle = 'default'; + this.state.messageContent = null; + } } return ( diff --git a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js index b2a50bb8..941865d3 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js @@ -159,8 +159,10 @@ class BillsSummaryTable extends Component { ); } - if (this.props.loading) { - this.state.messageStyle = 'default'; + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Processing ...'; } diff --git a/src/components/Blocnote/FinancialInputs/CashBalance.js b/src/components/Blocnote/FinancialInputs/CashBalance.js index 5f478ab3..62c02d1a 100644 --- a/src/components/Blocnote/FinancialInputs/CashBalance.js +++ b/src/components/Blocnote/FinancialInputs/CashBalance.js @@ -161,8 +161,10 @@ class CashBalance extends Component { ); } - if (this.state.loading) { - this.state.messageStyle = 'default'; + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Updating ...'; } diff --git a/src/components/Blocnote/FinancialInputs/CustomerPreference.js b/src/components/Blocnote/FinancialInputs/CustomerPreference.js index 0ef52259..8cc17495 100644 --- a/src/components/Blocnote/FinancialInputs/CustomerPreference.js +++ b/src/components/Blocnote/FinancialInputs/CustomerPreference.js @@ -128,8 +128,10 @@ class CustomerPreference extends Component { ); } - if (this.state.loading) { - this.state.messageStyle = 'default'; + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Updating ...'; } diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index cf3f5da8..2b3a8cf8 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -22,30 +22,44 @@ class IncomeStatements extends Component { this.handleOnChange = this.handleOnChange.bind(this); // this.handleOnChangeNew = this.handleOnChangeNew.bind(this); + console.log(props.data.growth_rate); // eslint-disable-line + const GRDropdownId = props.data.growth_rate !== null ? props.data.growth_rate : 0; + let GRDropdownValue = props.data.growth_rate !== null ? `${String(parseInt(parseFloat(props.data.growth_rate).toFixed(2) * 100, 10))}%` : 'Select Growth Rate'; + const growthRateOptions = [ + { id: '-2', key: '-2', name: 'CAGR=221.23%' }, + { id: '-1', key: '-1', name: 'Average' }, + { id: '0', key: '0', name: '0%' }, + { id: '1', key: '1', name: '1%' }, + { id: '2', key: '2', name: '2%' }, + { id: '3', key: '3', name: '3%' }, + { id: '4', key: '4', name: '4%' }, + { id: '5', key: '5', name: '5%' }, + { id: '6', key: '6', name: '6%' }, + { id: '7', key: '7', name: '7%' }, + { id: '8', key: '8', name: '8%' }, + { id: '9', key: '9', name: '9%' }, + { id: '10', key: '10', name: '10%' }, + { id: '11', key: '11', name: '11%' }, + { id: '12', key: '12', name: '12%' }, + { id: '13', key: '13', name: '13%' }, + { id: '14', key: '14', name: '14%' }, + { id: '15', key: '15', name: '15%' }, + ]; + growthRateOptions.forEach(option => { + if (option.id === GRDropdownId) { + GRDropdownValue = option.name; + } + }); + if (GRDropdownValue === null) { + GRDropdownValue = props.data.growth_rate !== null ? props.data.growth_rate : 0; + } + + const obj = { GRDropdownOpen: false, - GRDropdownId: props.data.growth_rate !== null ? props.data.growth_rate : 0, - GRDropdownValue: props.data.growth_rate !== null ? `${String(props.data.growth_rate * 100)}%` : 'Select Growth Rate', - growthRateOptions: [ - { id: '-2', key: '-2', name: 'CAGR=1.58%' }, - { id: '-1', key: '-1', name: 'Average' }, - { id: '0', key: '0', name: '0%' }, - { id: '1', key: '1', name: '1%' }, - { id: '2', key: '2', name: '2%' }, - { id: '3', key: '3', name: '3%' }, - { id: '4', key: '4', name: '4%' }, - { id: '5', key: '5', name: '5%' }, - { id: '6', key: '6', name: '6%' }, - { id: '7', key: '7', name: '7%' }, - { id: '8', key: '8', name: '8%' }, - { id: '9', key: '9', name: '9%' }, - { id: '10', key: '10', name: '10%' }, - { id: '11', key: '11', name: '11%' }, - { id: '12', key: '12', name: '12%' }, - { id: '13', key: '13', name: '13%' }, - { id: '14', key: '14', name: '14%' }, - { id: '15', key: '15', name: '15%' }, - ], + GRDropdownId, + GRDropdownValue, + growthRateOptions, incomeStatements: props.data, incomeStatementsNew: null, error: false, @@ -55,7 +69,6 @@ class IncomeStatements extends Component { messageStyle: 'default', }; - console.log(props.data.hist); // eslint-disable-line const histYears = {}; const incomeStatementsNew = { incomeStatementsNew: [] }; if (props.data.hist !== null) { @@ -226,6 +239,8 @@ class IncomeStatements extends Component { const growthRate = {}; growthRate['growth-rate'] = String(this.state.GRDropdownId); hist.push(growthRate); + console.log(hist); // eslint-disable-line + this.props.updateIncomeStatements( this.props.buildingId, hist, @@ -292,8 +307,6 @@ class IncomeStatements extends Component { let header = []; let rows = []; let calculateSaveButton = null; - console.log(this.props.data.hist); // eslint-disable-line - console.log(this.state.incomeStatements.hist); // eslint-disable-line const columnKeys = [ 'revenue', @@ -340,15 +353,17 @@ class IncomeStatements extends Component { if (this.state.incomeStatements.hist !== null && this.state.incomeStatements.future !== null) { header = this.buildHeader(); - console.log(this.state.incomeStatements.hist); // eslint-disable-line - const histYears = Object.keys(this.state.incomeStatements.hist).sort(); + const incomeStatements = this.state.incomeStatements; + const histYears = Object.keys(incomeStatements.hist).sort(); rows = columnKeys.map((columnKey, id) => { const cells = [ ...[columnNames[columnKey]], ...histYears.map((histYear) => { - let cellValue = this.state.incomeStatements.hist[histYear][columnKey]; - cellValue = Math.round(cellValue * 100) / 100; + // let cellValue = incomeStatements.hist[histYear][columnKey]; + // cellValue = Math.round(cellValue * 100) / 100; if (['utility_expense', 'revenue', 'non_utility_expense'].includes(columnKey)) { + let cellValue = this.state.incomeStatements.hist[histYear][columnKey]; + cellValue = Math.round(cellValue * 100) / 100; return ( @@ -366,18 +381,20 @@ class IncomeStatements extends Component { ); } + let cellValue = this.props.data.hist[histYear][columnKey]; + cellValue = Math.round(cellValue * 100) / 100; cellValue = cellValue.toLocaleString(); cellValue = `$${cellValue}`; return cellValue; }), - ...[this.state.incomeStatements.future[columnKey]].map((amount) => { + ...[incomeStatements.future[columnKey]].map((amount) => { let cellValue = amount; cellValue = Math.round(cellValue * 100) / 100; cellValue = cellValue.toLocaleString(); cellValue = `$${cellValue}`; return cellValue; }), - ...Object.values([this.state.incomeStatements.average[columnKey]]).map((amount) => { + ...Object.values([incomeStatements.average[columnKey]]).map((amount) => { let cellValue = amount; cellValue = Math.round(cellValue * 100) / 100; cellValue = cellValue.toLocaleString(); @@ -477,8 +494,10 @@ class IncomeStatements extends Component { ); } - if (this.state.loading) { - this.state.messageStyle = 'default'; + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Updating ...'; } @@ -491,9 +510,11 @@ class IncomeStatements extends Component { && this.state.incomeStatements !== null && this.state.action === 'updated') { this.state.messageStyle = 'success'; - this.state.messageContent = 'Saved!'; + this.state.messageContent = 'Saved and reloaded.'; } - + console.log(this.state.GRDropdownId); // eslint-disable-line + console.log(this.state.GRDropdownValue); // eslint-disable-line + console.log(this.props.data.growth_rate); // eslint-disable-line return (

    diff --git a/src/components/Blocnote/FinancialInputs/LoanOptions.js b/src/components/Blocnote/FinancialInputs/LoanOptions.js index 35db9d8f..ea9a17b0 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptions.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptions.js @@ -203,9 +203,11 @@ class LoanOptions extends Component { ); } - if (this.state.loading) { + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Updating ...'; - this.state.messageStyle = 'default'; } if (this.props.error && typeof this.props.error === 'object') { diff --git a/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js b/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js index ce931eb7..ed5a8c72 100644 --- a/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js +++ b/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js @@ -178,9 +178,11 @@ class MortgageLiabilities extends Component { ); } - if (this.state.loading) { + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Updating ...'; - this.state.messageStyle = 'default'; } if (this.props.error && typeof this.props.error === 'object') { diff --git a/src/components/Blocnote/FinancialInputs/ResultMessage.js b/src/components/Blocnote/FinancialInputs/ResultMessage.js index d00d8c20..7a784917 100644 --- a/src/components/Blocnote/FinancialInputs/ResultMessage.js +++ b/src/components/Blocnote/FinancialInputs/ResultMessage.js @@ -11,7 +11,6 @@ const errorStyle = { color: 'red', padding: '10px 25px 10px 25px', fontWeight: 'bold', - background: '#EEEEEE', }; const defaultStyle = { color: 'black', @@ -29,7 +28,8 @@ const ResultMessage = (props) => { } else if (props.style === 'error') { return ( - ×  {props.content} + {/* ×  {props.content} */} +   {props.content} ); } diff --git a/src/containers/Blocnote/FinancialInputs/index.js b/src/containers/Blocnote/FinancialInputs/index.js index 1ff67135..2d3005e6 100644 --- a/src/containers/Blocnote/FinancialInputs/index.js +++ b/src/containers/Blocnote/FinancialInputs/index.js @@ -145,7 +145,6 @@ class FinancialInputs extends Component { customerPreferenceData = customerPreference.data.instance; } - console.log(incomeStatement.data.instance); // eslint-disable-line mainContent = (
    Date: Thu, 6 Jun 2019 12:05:28 -0400 Subject: [PATCH 36/54] Fix income statement dropdown issue --- .../FinancialInputs/IncomeStatements.js | 37 ++++++++----------- src/containers/Blocnote/sagas.js | 1 - 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index 2b3a8cf8..93d78c56 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -22,10 +22,8 @@ class IncomeStatements extends Component { this.handleOnChange = this.handleOnChange.bind(this); // this.handleOnChangeNew = this.handleOnChangeNew.bind(this); - console.log(props.data.growth_rate); // eslint-disable-line - const GRDropdownId = props.data.growth_rate !== null ? props.data.growth_rate : 0; - let GRDropdownValue = props.data.growth_rate !== null ? `${String(parseInt(parseFloat(props.data.growth_rate).toFixed(2) * 100, 10))}%` : 'Select Growth Rate'; - const growthRateOptions = [ + const GRDropdownId = props.data.growth_rate !== null ? props.data.growth_rate : -99; + this.growthRateOptions = [ { id: '-2', key: '-2', name: 'CAGR=221.23%' }, { id: '-1', key: '-1', name: 'Average' }, { id: '0', key: '0', name: '0%' }, @@ -45,21 +43,11 @@ class IncomeStatements extends Component { { id: '14', key: '14', name: '14%' }, { id: '15', key: '15', name: '15%' }, ]; - growthRateOptions.forEach(option => { - if (option.id === GRDropdownId) { - GRDropdownValue = option.name; - } - }); - if (GRDropdownValue === null) { - GRDropdownValue = props.data.growth_rate !== null ? props.data.growth_rate : 0; - } - const obj = { GRDropdownOpen: false, GRDropdownId, - GRDropdownValue, - growthRateOptions, + growthRateOptions: this.growthRateOptions, incomeStatements: props.data, incomeStatementsNew: null, error: false, @@ -143,7 +131,6 @@ class IncomeStatements extends Component { changeGrowthRate(e) { this.setState({ GRDropdownId: e.currentTarget.id }); - this.setState({ GRDropdownValue: e.currentTarget.textContent }); } buildHeader = () => { @@ -239,7 +226,6 @@ class IncomeStatements extends Component { const growthRate = {}; growthRate['growth-rate'] = String(this.state.GRDropdownId); hist.push(growthRate); - console.log(hist); // eslint-disable-line this.props.updateIncomeStatements( this.props.buildingId, @@ -280,7 +266,7 @@ class IncomeStatements extends Component { return newStatement; }); - if (this.state.GRDropdownValue === 'Select Growth Rate') { + if (this.state.GRDropdownId === -99) { emptyMessages.push('Growth Rate'); } @@ -512,9 +498,16 @@ class IncomeStatements extends Component { this.state.messageStyle = 'success'; this.state.messageContent = 'Saved and reloaded.'; } - console.log(this.state.GRDropdownId); // eslint-disable-line - console.log(this.state.GRDropdownValue); // eslint-disable-line - console.log(this.props.data.growth_rate); // eslint-disable-line + + let GRDropdownValue = 'Select Growth Rate'; + this.growthRateOptions.forEach(option => { + if (option.id === String(parseInt(parseFloat(this.state.GRDropdownId).toFixed(2) * 100, 10)) + || option.id === this.state.GRDropdownId + || parseInt(option.id, 10) === this.state.GRDropdownId) { + GRDropdownValue = option.name; + } + }); + return (

    @@ -528,7 +521,7 @@ class IncomeStatements extends Component { className="btn-block" > - {this.state.GRDropdownValue} + {GRDropdownValue} {growthRateOptions} diff --git a/src/containers/Blocnote/sagas.js b/src/containers/Blocnote/sagas.js index 49bff678..7cdd5b7d 100644 --- a/src/containers/Blocnote/sagas.js +++ b/src/containers/Blocnote/sagas.js @@ -215,7 +215,6 @@ function* updateIncomeStatements(action) { ); if (!res.err) { - console.log(action.payload.slice(-1)); // eslint-disable-line res.growth_rate = action.payload.slice(-1)[0]['growth-rate']; yield put(updateIncomeStatementsSucceeded(res)); } else { -- GitLab From 58f1714a55ac516ab775a15ac7cf047330c79ef4 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Thu, 6 Jun 2019 12:12:40 -0400 Subject: [PATCH 37/54] Remove console logs --- src/components/Blocnote/FinancialInputs/BillsSummaryRow.js | 1 - src/components/Blocnote/FinancialInputs/BillsSummaryTable.js | 1 - 2 files changed, 2 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js b/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js index 529a7488..5c765e57 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js @@ -60,7 +60,6 @@ class BillsSummaryRow extends Component { this.setState({ [event.target.name]: event.target.value }, () => { this.props.handleOnChange(this.state); - console.log(this.state); // eslint-disable-line }, ); } diff --git a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js index 941865d3..fb2e5a2b 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js @@ -103,7 +103,6 @@ class BillsSummaryTable extends Component { } handleOnChange = (billData) => { - console.log("billData"); // eslint-disable-line const billsSummary = this.state.billData.map(bill => { if (bill.id === billData.id) { return { -- GitLab From 59518029d0cf081d6bff336c355aefc34ae95233 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 7 Jun 2019 13:17:56 -0400 Subject: [PATCH 38/54] Fix Bill overview and income statement issues --- .../Blocnote/FinancialInputs/BillsOverview.js | 32 ++++++++++--------- .../FinancialInputs/IncomeStatements.js | 6 ++-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/BillsOverview.js b/src/components/Blocnote/FinancialInputs/BillsOverview.js index d2fc2f06..7d3fb7a3 100644 --- a/src/components/Blocnote/FinancialInputs/BillsOverview.js +++ b/src/components/Blocnote/FinancialInputs/BillsOverview.js @@ -16,33 +16,35 @@ class BillsOverview extends Component { super(props); this.toggleEstimation = this.toggleEstimation.bind(this); this.changeEstimation = this.changeEstimation.bind(this); - const data = {}; - let estimationDropDownValue = 'Select Estimation'; - if (Object.keys(this.props.data).length !== 0) { - estimationDropDownValue = this.props.data.estimation_algorithm; - ['electric', 'water', 'gas', 'oil'].forEach((billName) => { - Object.entries(this.props.data[billName]).forEach((bill) => { - const keyName = `${billName}-value-${bill[0]}`; - data[keyName] = bill[1]; - }); - }); - } - this.state = { estimationDropdownOpen: false, - estimationDropDownValue, + estimationDropDownValue: Object.keys(this.props.data).length !== 0 ? + this.props.data.estimation_algorithm : 'Select Estimation', estimationOptions: [ { id: 'RoughEstimation', key: 'RoughEstimation', name: 'Rough Estimation' }, { id: 'FancyEstimation', key: 'FancyEstimation', name: 'Fancy Estimation' }, ], loading: props.loading, action: null, - postBills: data, + postBills: this.processBillsData(), messageContent: null, messageStyle: 'default', }; } + processBillsData = () => { + const data = {}; + if (Object.keys(this.props.data).length !== 0) { + ['electric', 'water', 'gas', 'oil'].forEach((billName) => { + Object.entries(this.props.data[billName]).forEach((bill) => { + const keyName = `${billName}-value-${bill[0]}`; + data[keyName] = bill[1]; + }); + }); + } + return data; + } + toggleEstimation() { this.setState({ estimationDropdownOpen: !this.state.estimationDropdownOpen, @@ -60,7 +62,7 @@ class BillsOverview extends Component { handleCreateBillsOverview = () => { this.props.createBillsOverview( this.props.buildingId, - this.state.postBills, + this.processBillsData(), ); this.setState({ action: 'created' }); } diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index 93d78c56..9b3e0c73 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -24,7 +24,7 @@ class IncomeStatements extends Component { const GRDropdownId = props.data.growth_rate !== null ? props.data.growth_rate : -99; this.growthRateOptions = [ - { id: '-2', key: '-2', name: 'CAGR=221.23%' }, + { id: '-2', key: '-2', name: `CAGR=${props.data.cagr}%` }, { id: '-1', key: '-1', name: 'Average' }, { id: '0', key: '0', name: '0%' }, { id: '1', key: '1', name: '1%' }, @@ -373,14 +373,14 @@ class IncomeStatements extends Component { cellValue = `$${cellValue}`; return cellValue; }), - ...[incomeStatements.future[columnKey]].map((amount) => { + ...[this.props.data.future[columnKey]].map((amount) => { let cellValue = amount; cellValue = Math.round(cellValue * 100) / 100; cellValue = cellValue.toLocaleString(); cellValue = `$${cellValue}`; return cellValue; }), - ...Object.values([incomeStatements.average[columnKey]]).map((amount) => { + ...Object.values([this.props.data.average[columnKey]]).map((amount) => { let cellValue = amount; cellValue = Math.round(cellValue * 100) / 100; cellValue = cellValue.toLocaleString(); -- GitLab From 92c98c14aaaedd19f966618f6ae28157f8d26da9 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 7 Jun 2019 14:30:17 -0400 Subject: [PATCH 39/54] Remove not needed js file --- .../FinancialInputs/\bIncomeStatements.js" | 605 ------------------ 1 file changed, 605 deletions(-) delete mode 100644 "src/containers/Blocnote/FinancialInputs/\bIncomeStatements.js" diff --git "a/src/containers/Blocnote/FinancialInputs/\bIncomeStatements.js" "b/src/containers/Blocnote/FinancialInputs/\bIncomeStatements.js" deleted file mode 100644 index e8db5907..00000000 --- "a/src/containers/Blocnote/FinancialInputs/\bIncomeStatements.js" +++ /dev/null @@ -1,605 +0,0 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { - Dropdown, - DropdownToggle, - DropdownMenu, - DropdownItem, - Button, - Input, - InputGroup, - InputGroupAddon, - Table, -} from 'reactstrap'; -import ResultMessage from './../../../components/Blocnote/FinancialInputs/ResultMessage'; - - -class IncomeStatements extends Component { - constructor(props) { - super(props); - this.toggleGrowthRate = this.toggleGrowthRate.bind(this); - this.changeGrowthRate = this.changeGrowthRate.bind(this); - this.handleOnChange = this.handleOnChange.bind(this); - // this.handleOnChangeNew = this.handleOnChangeNew.bind(this); - - const obj = { - GRDropdownOpen: false, - GRDropdownValue: 'Select Growth Rate', - selectedDropdownId: 0, - growthRateOptions: [ - { id: '-2', key: '-2', name: 'CAGR=1.58%' }, - { id: '-1', key: '-1', name: 'Average' }, - { id: '0', key: '0', name: '0%' }, - { id: '1', key: '1', name: '1%' }, - { id: '2', key: '2', name: '2%' }, - { id: '3', key: '3', name: '3%' }, - { id: '4', key: '4', name: '4%' }, - { id: '5', key: '5', name: '5%' }, - { id: '6', key: '6', name: '6%' }, - { id: '7', key: '7', name: '7%' }, - { id: '8', key: '8', name: '8%' }, - { id: '9', key: '9', name: '9%' }, - { id: '10', key: '10', name: '10%' }, - { id: '11', key: '11', name: '11%' }, - { id: '12', key: '12', name: '12%' }, - { id: '13', key: '13', name: '13%' }, - { id: '14', key: '14', name: '14%' }, - { id: '15', key: '15', name: '15%' }, - ], - incomeStatements: props.data, - incomeStatementsNew: null, - error: false, - loading: false, - action: null, - }; - - const histYears = {}; - const incomeStatementsNew = { incomeStatementsNew: [] }; - if (props.data.hist !== null) { - Object.keys(props.data.hist).forEach((year, id) => { - const histYear = `Year-${id + 1}`; - histYears[histYear] = parseInt(year, 10); - }); - } else { - [0, 1, 2].forEach(id => { - const histYear = `Year-${id + 1}`; - histYears[histYear] = null; - }); - - const growthRate = {}; - growthRate['growth-rate'] = props.data.cagr; - incomeStatementsNew.incomeStatementsNew.push(this.initIncomeStatement()); - incomeStatementsNew.incomeStatementsNew.push(this.initIncomeStatement()); - incomeStatementsNew.incomeStatementsNew.push(this.initIncomeStatement()); - incomeStatementsNew.incomeStatementsNew.push(growthRate); - } - - this.state = Object.assign(obj, histYears, incomeStatementsNew); - console.log(this.state); // eslint-disable-line - } - - initIncomeStatement = () => { - const statement = { - year: null, - revenue: null, - }; - statement['utility-expense'] = null; - statement['non-utility-operating-expense'] = null; - return statement; - } - - handleOnChange = (event) => { - const year = event.target.id; - const targetName = event.target.name; - const copyIS = this.state.incomeStatements; - Object.entries(copyIS.hist).forEach((incomeStatement) => { - if (incomeStatement[0] === year) { - copyIS.hist[year][targetName] = parseFloat(event.target.value); - } - }); - - this.setState({ incomeStatements: copyIS }, () => { - console.log(this.state.incomeStatements); // eslint-disable-line - }); - } - - handleOnChangeNew = (event) => { - const id = event.target.id; - const targetName = event.target.name.includes('Year') ? 'year' : event.target.name; - const targetValue = event.target.value; - const copyISNew = this.state.incomeStatementsNew.map((item, key) => { - if (parseInt(key, 10) === parseInt(id, 10)) { - const tmp = item; - tmp[targetName] = targetValue; - return tmp; - } - return item; - }); - this.setState({ incomeStatementsNew: copyISNew }, () => { - console.log(this.state.incomeStatementsNew); // eslint-disable-line - }); - } - - toggleGrowthRate() { - this.setState({ - GRDropdownOpen: !this.state.GRDropdownOpen, - }); - } - - changeGrowthRate(e) { - this.setState({ GRDropdownValue: e.currentTarget.textContent }); - this.setState({ selectedDropdownId: e.currentTarget.id }); - } - - buildHeader = () => { - const headers = []; - const year = 'year'; - headers.push( -

    - ); - - Object.entries(this.state).forEach((entry, key) => { - if (entry[0].includes('Year')) { - headers.push( - - ); - } - }); - const futureYear = this.state.incomeStatements.future.year; - headers.push( - - ); - const average = 'average'; - headers.push( - - ); - return headers; - } - - buildEmptyHeader = () => { - const headers = []; - const year = 'year'; - headers.push( - - ); - let id = 0; - Object.entries(this.state).forEach((entry, key) => { - if (entry[0].includes('Year')) { - headers.push( - - ); - id += 1; - } - }); - headers.push( - - ); - headers.push( - - ); - return headers; - } - - handleUpdateIncomeStatements = () => { - this.setState({ loading: true }); - const hist = []; - Object.entries(this.state.incomeStatements.hist).forEach(incomeStatement => { - const obj = { - year: String(incomeStatement[0]), - revenue: String(incomeStatement[1].revenue), - }; - obj['non-utility-operating-expense'] = String(incomeStatement[1].non_utility_expense); - obj['utility-expense'] = String(incomeStatement[1].utility_expense); - hist.push(obj); - }); - const growthRate = {}; - growthRate['growth-rate'] = String(this.state.selectedDropdownId); - hist.push(growthRate); - this.props.updateIncomeStatements( - this.props.buildingId, - hist, - ); - this.setState({ - loading: false, - action: 'updated', - }); - } - - handleCreateIncomeStatements = () => { - const emptyMessages = []; - const incomeStatementsNew = Object.values(this.state.incomeStatementsNew.slice(0, 3)) - .map(statement => { - if (statement.year === null && - !emptyMessages.includes('Year')) { - emptyMessages.push('Year'); - } - if (statement.revenue === null && - !emptyMessages.includes('Revenue')) { - emptyMessages.push('Revenue'); - } - if (statement['utility-expense'] === null && - !emptyMessages.includes('Utility Expense')) { - emptyMessages.push('Utility Expense'); - } - if (statement['non-utility-operating-expense'] === null && - !emptyMessages.includes('Non-Utility Operating Expense')) { - emptyMessages.push('Non-Utility Operating Expense'); - } - - const newStatement = {}; - newStatement.year = String(statement.year); - newStatement.revenue = String(statement.revenue); - newStatement['utility-expense'] = String(statement['utility-expense']); - newStatement['non-utility-operating-expense'] = String(statement['non-utility-operating-expense']); - return newStatement; - }); - - if (emptyMessages.length !== 0) { - const msg = `Please fill in ${emptyMessages.join(', ')} fields.`; - alert(msg); - } else { - const growthRate = {}; - growthRate['growth-rate'] = String(this.state.incomeStatementsNew[3]['growth-rate']); - incomeStatementsNew.push(growthRate); - this.setState({ loading: true }); - this.props.updateIncomeStatements( - this.props.buildingId, - incomeStatementsNew, - ); - this.setState({ - loading: false, - action: 'updated', - }); - } - } - - render() { - let header = []; - let rows = []; - let calculateSaveButton = null; - - const columnKeys = [ - 'revenue', - 'utility_expense', - 'energy_opex', - 'electric_opex', - 'gas_opex', - 'oil_opex', - 'water_opex', - 'other_utility', - 'non_utility_expense', - 'net_non_energy_opex', - 'total_opex', - 'noi', - ]; - - const columnNames = { - revenue: 'Revenue', - utility_expense: 'Utility Expense', - energy_opex: 'Energy Expense', - electric_opex: 'Electric Bill', - gas_opex: 'Gas Bill', - oil_opex: 'Oil Bill', - water_opex: 'Water Bill', - other_utility: 'Other Utility Expense', - non_utility_expense: 'Non-Utility Operating Expense', - net_non_energy_opex: 'Net Non-Energy Expense', - total_opex: 'Total Expense', - noi: 'Net Operating Income', - }; - - const growthRateOptions = this.state.growthRateOptions.map(e => { - return ( - - {e.name} - - ); - }); - - if (this.state.incomeStatements.hist !== null && - this.state.incomeStatements.future !== null) { - header = this.buildHeader(); - const histYears = Object.keys(this.state.incomeStatements.hist).sort(); - rows = columnKeys.map((columnKey, id) => { - const cells = [ - ...[columnNames[columnKey]], - ...histYears.map((histYear) => { - let cellValue = this.state.incomeStatements.hist[histYear][columnKey]; - cellValue = Math.round(cellValue * 100) / 100; - if (['utility_expense', 'revenue', 'non_utility_expense'].includes(columnKey)) { - return ( - - - $ - - - - ); - } - cellValue = cellValue.toLocaleString(); - cellValue = `$${cellValue}`; - return cellValue; - }), - ...[this.state.incomeStatements.future[columnKey]].map((amount) => { - let cellValue = amount; - cellValue = Math.round(cellValue * 100) / 100; - cellValue = cellValue.toLocaleString(); - cellValue = `$${cellValue}`; - return cellValue; - }), - ...Object.values([this.state.incomeStatements.average[columnKey]]).map((amount) => { - let cellValue = amount; - cellValue = Math.round(cellValue * 100) / 100; - cellValue = cellValue.toLocaleString(); - cellValue = `$${cellValue}`; - return cellValue; - }), - ]; - - const cellsData = Object.values(cells).map((celldata, key) => { - return ( - - ); - }); - - return ( - - {cellsData} - - ); - }); - - calculateSaveButton = ( - - ); - } else { - header = this.buildEmptyHeader(); - const ids = Object.keys(this.state.incomeStatementsNew).slice(0, 3).sort(); - console.log(this.state.incomeStatementsNew); // eslint-disable-line - rows = columnKeys.map((columnKey, id) => { - const cells = [ - ...[columnNames[columnKey]], - ...ids.map((index) => { - const keyMapping = { - revenue: 'revenue', - utility_expense: 'utility-expense', - non_utility_expense: 'non-utility-operating-expense', - }; - - if (['revenue', 'utility_expense', 'non_utility_expense'].includes(columnKey)) { - const newColumnKey = keyMapping[columnKey]; - return ( - - - $ - - - - ); - } - return null; - }), - ...['', ''], - ]; - - const cellsData = Object.values(cells).map((celldata, key) => { - return ( - - ); - }); - - return ( - - {cellsData} - - ); - }); - - calculateSaveButton = ( - - ); - } - - let messageStyle = {}; - let messageContent = null; - - if (this.state.loading) { - messageContent = 'Processing ...'; - messageStyle = this.props.defaultMessageStyle; - } - - if (this.state.error && typeof this.state.error === 'object') { - messageContent = this.state.error.response.statusText; - messageStyle = this.props.errorMessageStyle; - } - - if (!this.state.error && !this.state.loading - && this.state.incomeStatements !== null - && this.state.action !== null) { - messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); - messageStyle = this.props.successMessageStyle; - } - - return ( -
    -

    - Income Statements (in $, End of Year) -

    -
    -
    - - - {this.state.GRDropdownValue} - - - {growthRateOptions} - - -
    -
    -    - {calculateSaveButton} -
    -
    -
    -
    -
    +
    Cost Estimation
    -- GitLab From 9cd0f3dd124f6412585b6b7311b7c7dbc7dbc9a0 Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 30 May 2019 15:03:49 -0400 Subject: [PATCH 26/54] Fix Saving Estimation not updated issue --- .../PreliminaryFinance/SavingEstimation.js | 2 +- .../PreliminaryFinance/SavingEstimationRow.js | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js index b7798b43..fc3ae4b2 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js @@ -18,7 +18,7 @@ class SavingEstimation extends Component { const newRow = row; const savingEstimation = this.state.savingEstimation; newRow.estimated_savings = String(row.estimated_savings); - savingEstimation[row.utilityType] = newRow; + savingEstimation[row.utility_type] = newRow; this.setState({ savingEstimation }, () => { this.props.updateSavingEstimation(this.state.savingEstimation); console.log(this.state.savingEstimation); // eslint-disable-line diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js index 2602bf5f..9b88a914 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js @@ -12,17 +12,17 @@ class SavingEstimationRow extends Component { super(props); this.handleOnChange = this.handleOnChange.bind(); this.state = { - estimatedSavings: props.estimatedSavings, - usedBeforeRetrofit: props.usedBeforeRetrofit, - usedAfterRetrofit: props.usedAfterRetrofit, - utilityType: props.utilityType, + estimated_savings: props.estimatedSavings, + used_before_retrofit: props.usedBeforeRetrofit, + used_after_retrofit: props.usedAfterRetrofit, + utility_type: props.utilityType, }; console.log(props); // eslint-disable-line } handleOnChange = (event) => { this.setState({ [event.target.name]: - ['usedBeforeRetrofit', 'usedAfterRetrofit'].includes(event.target.name) ? + ['used_before_retrofit', 'used_after_retrofit'].includes(event.target.name) ? event.target.checked : event.target.value }, () => { this.props.updateRow(this.state); @@ -45,8 +45,8 @@ class SavingEstimationRow extends Component { @@ -72,9 +72,9 @@ class SavingEstimationRow extends Component { -- GitLab From 1715276add456ef3d56883d5846c6ca8f674faeb Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 30 May 2019 15:10:52 -0400 Subject: [PATCH 27/54] Move Cost estimation button down --- .../PreliminaryFinance/CostEstimation.js | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index ad5fa447..d11fa83b 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -122,7 +122,7 @@ class CostEstimation extends Component { - @@ -159,6 +144,24 @@ class CostEstimation extends Component { {rows} + + +
    - -
    Item
    + +
    -- GitLab From 3464a5fbeba08e4e3ca6a06436b805a9d81aa6af Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 30 May 2019 15:56:01 -0400 Subject: [PATCH 28/54] Remove comments --- src/components/Blocnote/PreliminaryFinance/BudgetChart.js | 2 -- .../Blocnote/PreliminaryFinance/CostEstimation.js | 1 - src/components/Blocnote/PreliminaryFinance/DownPayment.js | 1 - .../Blocnote/PreliminaryFinance/InputScenario.js | 7 ------- .../Blocnote/PreliminaryFinance/ProjectEconomicsRow.js | 1 - .../Blocnote/PreliminaryFinance/SavingEstimation.js | 1 - .../Blocnote/PreliminaryFinance/SavingEstimationRow.js | 2 -- 7 files changed, 15 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/BudgetChart.js b/src/components/Blocnote/PreliminaryFinance/BudgetChart.js index 53c0d600..c3346d21 100644 --- a/src/components/Blocnote/PreliminaryFinance/BudgetChart.js +++ b/src/components/Blocnote/PreliminaryFinance/BudgetChart.js @@ -15,7 +15,6 @@ import { class BudgetChart extends Component { constructor(props) { super(props); - this.state = { successMessages: [], error: false, @@ -38,7 +37,6 @@ class BudgetChart extends Component { const CustomizedLabel = React.createClass({ render() { const { x, y, stroke, value } = this.props; - return ( {value} diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index d11fa83b..fa43452a 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -64,7 +64,6 @@ class CostEstimation extends Component { delRow = id => { if (confirm('Are you sure to delete this estimation?') === true) { const costEstimation = this.state.costEstimation.filter((estimation, index) => { - console.log(estimation); // eslint-disable-line return index !== id; }); this.setState({ costEstimation }, () => { diff --git a/src/components/Blocnote/PreliminaryFinance/DownPayment.js b/src/components/Blocnote/PreliminaryFinance/DownPayment.js index 5443c29f..9d470f06 100644 --- a/src/components/Blocnote/PreliminaryFinance/DownPayment.js +++ b/src/components/Blocnote/PreliminaryFinance/DownPayment.js @@ -5,7 +5,6 @@ import PropTypes from 'prop-types'; class DownPayment extends Component { constructor(props) { super(props); - this.state = { successMessages: [], error: false, diff --git a/src/components/Blocnote/PreliminaryFinance/InputScenario.js b/src/components/Blocnote/PreliminaryFinance/InputScenario.js index db84fba9..658e7624 100644 --- a/src/components/Blocnote/PreliminaryFinance/InputScenario.js +++ b/src/components/Blocnote/PreliminaryFinance/InputScenario.js @@ -75,8 +75,6 @@ class InputScenario extends Component { if (!this.props.error && !this.props.loading && this.props.data !== null && this.state.action !== null) { - // messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); - // messageStyle = this.props.successMessageStyle; messageContent = ( ✔  {'Saved and reloaded.'} @@ -156,11 +154,6 @@ InputScenario.propTypes = { textAlign: PropTypes.string, marginBottom: PropTypes.string, }), - // successMessageStyle: PropTypes.shape({ - // color: PropTypes.string, - // paddingLeft: PropTypes.string, - // fontWeight: PropTypes.string, - // }), errorMessageStyle: PropTypes.shape({ color: PropTypes.string, paddingLeft: PropTypes.string, diff --git a/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js b/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js index 5315d9b9..333d5865 100644 --- a/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js +++ b/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js @@ -5,7 +5,6 @@ import PropTypes from 'prop-types'; class ProjectEconomicsRow extends Component { constructor(props) { super(props); - this.state = { successMessages: [], error: false, diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js index fc3ae4b2..734e0852 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js @@ -32,7 +32,6 @@ class SavingEstimation extends Component { fontSize: '13px', }; const rows = []; - console.log(this.state.savingEstimation); // eslint-disable-line if (this.state.savingEstimation !== null) { Object.entries(this.state.savingEstimation).forEach(([utilityName, utilityData]) => { diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js index 9b88a914..c0c46312 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js @@ -17,7 +17,6 @@ class SavingEstimationRow extends Component { used_after_retrofit: props.usedAfterRetrofit, utility_type: props.utilityType, }; - console.log(props); // eslint-disable-line } handleOnChange = (event) => { @@ -30,7 +29,6 @@ class SavingEstimationRow extends Component { } render() { - console.log(this.state); // eslint-disable-line return (
    Date: Thu, 30 May 2019 16:54:10 -0400 Subject: [PATCH 29/54] Update scenario to refresh project economics data --- src/containers/Blocnote/PreliminaryFinance/index.js | 1 + src/containers/Blocnote/sagas.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/containers/Blocnote/PreliminaryFinance/index.js b/src/containers/Blocnote/PreliminaryFinance/index.js index 6c46344e..106d7daf 100644 --- a/src/containers/Blocnote/PreliminaryFinance/index.js +++ b/src/containers/Blocnote/PreliminaryFinance/index.js @@ -48,6 +48,7 @@ class PreliminaryFinance extends Component { fontWeight: 'bold', }; + console.log(this.props); // eslint-disable-line const { blocnote } = this.props; const { scenario } = blocnote; diff --git a/src/containers/Blocnote/sagas.js b/src/containers/Blocnote/sagas.js index 53768134..0389e0d9 100644 --- a/src/containers/Blocnote/sagas.js +++ b/src/containers/Blocnote/sagas.js @@ -315,7 +315,7 @@ function* updateScenario(action) { ); if (!res.err) { - yield put(updateScenarioSucceeded(action.payload)); + yield put(updateScenarioSucceeded(res)); } else { yield put(updateScenarioFailed(res.err)); } -- GitLab From 9025bfac325af589422cf0a221c75219dc83be60 Mon Sep 17 00:00:00 2001 From: akkking Date: Mon, 3 Jun 2019 11:17:24 -0400 Subject: [PATCH 30/54] Fix Bills Summary section issues --- .../Blocnote/FinancialInputs/Bills.js | 1 - .../FinancialInputs/BillsSummaryRow.js | 67 ++++++++- .../FinancialInputs/BillsSummaryTable.js | 139 +++++++++++------- .../FinancialInputs/MortgageLiabilities.js | 1 - .../Blocnote/FinancialInputs/index.js | 1 + src/containers/Blocnote/reducer.js | 41 ++++-- src/containers/Blocnote/sagas.js | 2 +- 7 files changed, 174 insertions(+), 78 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/Bills.js b/src/components/Blocnote/FinancialInputs/Bills.js index e37b1d6a..bb02de2c 100644 --- a/src/components/Blocnote/FinancialInputs/Bills.js +++ b/src/components/Blocnote/FinancialInputs/Bills.js @@ -16,7 +16,6 @@ const Bills = (props) => { }; if (props.data !== null) { - console.log(props.data); // eslint-disable-line Object.keys(props.data).forEach(billName => { BillsTables.push(
    diff --git a/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js b/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js index b7479d8d..8ecec0c4 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js @@ -12,6 +12,7 @@ class BillsSummaryRow extends Component { constructor(props) { super(props); this.handleOnChange = this.handleOnChange.bind(this); + this.handleCreateBillsSummary = this.handleCreateBillsSummary.bind(this); this.handleUpdateBillsSummary = this.handleUpdateBillsSummary.bind(this); this.handleDeleteBillsSummary = this.handleDeleteBillsSummary.bind(this); this.state = { @@ -21,9 +22,34 @@ class BillsSummaryRow extends Component { }; } + validateInputs() { + const emptyFields = []; + if (this.state.year === null || isNaN(this.state.year) || this.state.year === '') { + emptyFields.push('Year'); + } + if (this.state.charge === null || isNaN(this.state.charge) || this.state.charge === '') { + emptyFields.push('Charge'); + } + if (emptyFields.length > 0) { + alert(`Please fill in ${emptyFields.join(', ')} field(s)`); + return false; + } + return true; + } + + handleCreateBillsSummary() { + if (this.validateInputs() === true) { + this.props.createBillsSummary({ + year: this.state.year, + charge: this.state.charge, + }); + } + } + handleUpdateBillsSummary() { - console.log(this.state); // eslint-disable-line - this.props.updateBillsSummary(this.state); + if (this.validateInputs() === true) { + this.props.updateBillsSummary(this.state); + } } handleDeleteBillsSummary() { @@ -31,10 +57,37 @@ class BillsSummaryRow extends Component { } handleOnChange = (event) => { - this.setState({ [event.target.name]: event.target.value }); + this.setState({ [event.target.name]: event.target.value }, + () => { + this.props.handleOnChange(this.state); + console.log(this.state); // eslint-disable-line + }, + ); } render() { + let actionButton = null; + + if (this.props.id === 0) { + actionButton = ( + + ); + } else { + actionButton = ( + + ); + } + return (
    @@ -70,10 +123,8 @@ class BillsSummaryRow extends Component { - {' '} + {actionButton} + {' '} diff --git a/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js b/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js index 58d2c9b9..bad1c1a7 100644 --- a/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js +++ b/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js @@ -141,7 +141,6 @@ class MortgageLiabilities extends Component { let rows = []; let saveButton = null; if (this.state.liabilities.length !== 0) { - console.log(this.state.liabilities); // eslint-disable-line rows = this.state.liabilities.map((liability, index) => { return ( { + userBill[billName] = billData; + if (billName === action.instance.utility_type) { + const bill = userBill[billName].pop(); + bill.id = action.result.id; + bill.year = action.instance.year; + bill.charge = action.instance.charge; + userBill[billName].push(bill); + } + }); return { ...state, billsSummary: { data: { - result: - [ - ...state.billsSummary.data, - { - id: action.result.id, - utility_type: action.instance.utility_type, - year: action.instance.year, - charge: action.instance.charge, - }, - ], - + result: { + user_bill: userBill, + }, }, loading: false, error: false, }, }; + } case FinancialInputs.CREATE_BILLS_SUMMARY_FAILED: return { @@ -288,15 +292,24 @@ export default function (state = blocnoteInitialState, action) { }, }; - case FinancialInputs.DELETE_BILLS_SUMMARY_SUCCEEDED: + case FinancialInputs.DELETE_BILLS_SUMMARY_SUCCEEDED: { + const userBill = {}; + Object.entries(state.billsSummary.data.result.user_bill).forEach(([billName, billData]) => { + userBill[billName] = billData.filter(bill => bill.id !== action.instance.id); + }); return { ...state, billsSummary: { - ...state.billsSummary, + data: { + result: { + user_bill: userBill, + }, + }, loading: false, error: false, }, }; + } case FinancialInputs.DELETE_BILLS_SUMMARY_FAILED: return { diff --git a/src/containers/Blocnote/sagas.js b/src/containers/Blocnote/sagas.js index 0389e0d9..a44a0dd2 100644 --- a/src/containers/Blocnote/sagas.js +++ b/src/containers/Blocnote/sagas.js @@ -132,7 +132,7 @@ function* updateBillsSummary(action) { request, SagaRequests.generateURL(url, action), { - method: 'POST', + method: 'PUT', headers: getHeaders(), body: JSON.stringify(action.payload), } -- GitLab From a79cdc3cf32619d56ba127e9a5e21f2af9144c68 Mon Sep 17 00:00:00 2001 From: akkking Date: Mon, 3 Jun 2019 17:42:46 -0400 Subject: [PATCH 31/54] Fix Energy Bills Overview Estimation error --- src/components/Blocnote/FinancialInputs/BillsOverview.js | 8 +++++++- src/components/Blocnote/FinancialInputs/BillsSummary.js | 1 - src/containers/Blocnote/FinancialInputs/index.js | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/BillsOverview.js b/src/components/Blocnote/FinancialInputs/BillsOverview.js index 0c7b04f4..5c7a6c78 100644 --- a/src/components/Blocnote/FinancialInputs/BillsOverview.js +++ b/src/components/Blocnote/FinancialInputs/BillsOverview.js @@ -37,6 +37,7 @@ class BillsOverview extends Component { ], action: null, postBills: data, + message: null, }; } @@ -177,7 +178,12 @@ class BillsOverview extends Component { } if (this.props.error && typeof this.props.error === 'object') { - messageContent = this.props.error.response.statusText; + if (this.state.estimationDropDownValue !== 'Rough Estimation') { + messageContent = 'Only Rough Estimation available at this point'; + } + // } else { + // messageContent = this.props.error.response.statusText; + // } messageStyle = this.props.errorMessageStyle; } diff --git a/src/components/Blocnote/FinancialInputs/BillsSummary.js b/src/components/Blocnote/FinancialInputs/BillsSummary.js index 05b6b1ba..9a5c9626 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummary.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummary.js @@ -18,7 +18,6 @@ class BillsSummary extends Component { const BillsSummaryTables = []; if (this.state.billsSummary !== null) { - console.log(this.state.billsSummary); // eslint-disable-line Object.keys(this.state.billsSummary).forEach(billName => { BillsSummaryTables.push(
    diff --git a/src/containers/Blocnote/FinancialInputs/index.js b/src/containers/Blocnote/FinancialInputs/index.js index 026dac08..4569ea05 100644 --- a/src/containers/Blocnote/FinancialInputs/index.js +++ b/src/containers/Blocnote/FinancialInputs/index.js @@ -106,7 +106,6 @@ class FinancialInputs extends Component { fontWeight: 'bold', }; - console.log(this.props); // eslint-disable-line const { blocnote } = this.props; const { fianceOverview, bills, billsOverview, billsSummary, cashBalance, @@ -205,6 +204,7 @@ class FinancialInputs extends Component { errorMessageStyle={errorMessageStyle} defaultMessageStyle={defaultMessageStyle} data={billsOverview.data.instance} + error={billsOverview.error} buildingId={this.props.building.building_id} loading={billsOverview.loading} createBillsOverview={this.props.createBillsOverview} -- GitLab From 7988355953745f680487404bf97fc11ac7fed51d Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Tue, 4 Jun 2019 12:57:18 -0400 Subject: [PATCH 32/54] Code refactoring for result message, fix loan options not saving issue --- .../Blocnote/FinancialInputs/BillsOverview.js | 37 ++++--------- .../Blocnote/FinancialInputs/BillsSummary.js | 18 ------ .../FinancialInputs/BillsSummaryTable.js | 39 ++++--------- .../Blocnote/FinancialInputs/BillsTable.js | 3 +- .../Blocnote/FinancialInputs/CashBalance.js | 40 ++++---------- .../FinancialInputs/CustomerPreference.js | 36 ++++-------- .../FinancialInputs/FinanceOverview.js | 55 ++++++++----------- .../FinancialInputs/IncomeStatements.js | 54 +++++++----------- .../Blocnote/FinancialInputs/LoanOptions.js | 54 +++++++----------- .../FinancialInputs/MortgageLiabilities.js | 43 +++++---------- .../Blocnote/FinancialInputs/ResultMessage.js | 44 ++++++++++++--- 11 files changed, 157 insertions(+), 266 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/BillsOverview.js b/src/components/Blocnote/FinancialInputs/BillsOverview.js index 5c7a6c78..5b915a67 100644 --- a/src/components/Blocnote/FinancialInputs/BillsOverview.js +++ b/src/components/Blocnote/FinancialInputs/BillsOverview.js @@ -37,7 +37,8 @@ class BillsOverview extends Component { ], action: null, postBills: data, - message: null, + messageContent: null, + messageStyle: 'default', }; } @@ -169,29 +170,26 @@ class BillsOverview extends Component { ); } - let messageStyle = {}; - let messageContent = null; - if (this.props.loading) { - messageContent = 'Processing ...'; - messageStyle = this.props.defaultMessageStyle; + this.state.messageContent = 'Processing ...'; + this.state.messageStyle = 'default'; } if (this.props.error && typeof this.props.error === 'object') { if (this.state.estimationDropDownValue !== 'Rough Estimation') { - messageContent = 'Only Rough Estimation available at this point'; + this.state.messageContent = 'Only Rough Estimation available at this point'; } // } else { // messageContent = this.props.error.response.statusText; // } - messageStyle = this.props.errorMessageStyle; + this.state.messageStyle = 'error'; } if (!this.props.error && !this.props.loading && this.props.data !== null && this.state.action !== null) { - messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); - messageStyle = this.props.successMessageStyle; + this.state.messageContent = 'Saved!'; + this.state.messageStyle = 'success'; } return ( @@ -216,8 +214,8 @@ class BillsOverview extends Component {
    @@ -262,21 +260,6 @@ BillsOverview.propTypes = { water_user: PropTypes.string, total_annual_charge: PropTypes.objectOf, }), - successMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - errorMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - defaultMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), headerStyle: PropTypes.shape({ textAlign: PropTypes.string, paddingLeft: PropTypes.string, diff --git a/src/components/Blocnote/FinancialInputs/BillsSummary.js b/src/components/Blocnote/FinancialInputs/BillsSummary.js index 9a5c9626..c409fbf8 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummary.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummary.js @@ -28,9 +28,6 @@ class BillsSummary extends Component { createBillsSummary={this.props.createBillsSummary} updateBillsSummary={this.props.updateBillsSummary} deleteBillsSummary={this.props.deleteBillsSummary} - successMessageStyle={this.props.successMessageStyle} - errorMessageStyle={this.props.errorMessageStyle} - defaultMessageStyle={this.props.defaultMessageStyle} />
    ); @@ -81,21 +78,6 @@ BillsSummary.propTypes = { }) ), }), - successMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - errorMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - defaultMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), headerStyle: PropTypes.shape({ textAlign: PropTypes.string, paddingLeft: PropTypes.string, diff --git a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js index 811139d3..b2a50bb8 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js @@ -15,6 +15,8 @@ class BillsSummaryTable extends Component { billName: props.billName, billData: props.billData, action: null, + messageContent: null, + messageStyle: 'default', }; } @@ -63,7 +65,6 @@ class BillsSummaryTable extends Component { this.props.buildingId, billData, ); - console.log('saga done!'); // eslint-disable-line this.setState({ action: 'updated' }); } @@ -158,24 +159,21 @@ class BillsSummaryTable extends Component { ); } - let messageStyle = {}; - let messageContent = null; - if (this.props.loading) { - messageContent = 'Processing ...'; - messageStyle = this.props.defaultMessageStyle; + this.state.messageStyle = 'default'; + this.state.messageContent = 'Processing ...'; } if (this.props.error && typeof this.props.error === 'object') { - messageContent = this.props.error.response.statusText; - messageStyle = this.props.errorMessageStyle; + this.state.messageStyle = 'error'; + this.state.messageContent = this.props.error.response.statusText; } if (!this.props.error && !this.props.loading && this.props.billData !== null && this.state.action !== null) { - messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); - messageStyle = this.props.successMessageStyle; + this.state.messageStyle = 'success'; + this.state.messageContent = 'Saved!'; } const billName = this.props.billName.charAt(0).toUpperCase() + this.props.billName.slice(1); @@ -204,9 +202,9 @@ class BillsSummaryTable extends Component { }} > {' '}{' '} + style={this.state.messageStyle} + content={this.state.messageContent} + />   - - - +
    +
    + + + +    + + + +
    +
    @@ -373,16 +372,6 @@ FinanceOverview.propTypes = { anticipatedCommissioningDate: PropTypes.string, anticipatedConstructionPeriod: PropTypes.number, baseURL: PropTypes.string, - successMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - errorMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), headerStyle: PropTypes.shape({ textAlign: PropTypes.string, paddingLeft: PropTypes.string, diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index 5a356dd3..0aaf7a4d 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -51,6 +51,8 @@ class IncomeStatements extends Component { error: false, loading: false, action: null, + messageContent: null, + messageStyle: 'default', }; const histYears = {}; @@ -472,24 +474,21 @@ class IncomeStatements extends Component { ); } - let messageStyle = {}; - let messageContent = null; - - if (this.state.loading) { - messageContent = 'Processing ...'; - messageStyle = this.props.defaultMessageStyle; + if (this.props.loading) { + this.state.messageStyle = 'default'; + this.state.messageContent = 'Updating ...'; } - if (this.state.error && typeof this.state.error === 'object') { - messageContent = this.state.error.response.statusText; - messageStyle = this.props.errorMessageStyle; + if (this.props.error && typeof this.props.error === 'object') { + this.state.messageStyle = 'error'; + this.state.messageContent = this.props.error.response.statusText; } - if (!this.state.error && !this.state.loading + if (!this.props.error && !this.props.loading && this.state.incomeStatements !== null - && this.state.action !== null) { - messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); - messageStyle = this.props.successMessageStyle; + && this.state.action === 'updated') { + this.state.messageStyle = 'success'; + this.state.messageContent = 'Saved!'; } return ( @@ -498,7 +497,7 @@ class IncomeStatements extends Component { Income Statements (in $, End of Year)
    -
    +
    -
    +
       + style={this.state.messageStyle} + content={this.state.messageContent} + /> +
    +
    {calculateSaveButton}
    @@ -587,22 +588,9 @@ IncomeStatements.propTypes = { non_utility_operating_expense: PropTypes.string, })), }), - successMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - errorMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - defaultMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), updateIncomeStatements: PropTypes.func, + error: PropTypes.bool, + loading: PropTypes.bool, }; export default IncomeStatements; diff --git a/src/components/Blocnote/FinancialInputs/LoanOptions.js b/src/components/Blocnote/FinancialInputs/LoanOptions.js index 3b40ddb1..c62a1075 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptions.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptions.js @@ -28,6 +28,8 @@ class LoanOptions extends Component { duration: null, max_loan_amount: null, action: null, + messageContent: null, + messageStyle: 'default', }; } @@ -67,7 +69,6 @@ class LoanOptions extends Component { alert('Sorry, you need at least one loan option!'); } else if (confirm('Are you sure to delete this loan option?') === true) { const loanOptionsCopy = this.state.loanOptions.filter((loanOption, index) => { - console.log(loanOption); // eslint-disable-line return index !== id; }); this.setState({ loanOptions: loanOptionsCopy }, () => { @@ -86,7 +87,6 @@ class LoanOptions extends Component { duration: this.state.duration, max_loan_amount: this.state.max_loan_amount, }; - console.log(this.state.loanOptions); // eslint-disable-line const loanOptions = this.state.loanOptions; loanOptions.push(loanOption); this.setState({ loanOptions }, () => { @@ -107,8 +107,6 @@ class LoanOptions extends Component { updateRow = (row) => { const loanOptions = this.state.loanOptions.map((loanOption, id) => { - console.log(id); // eslint-disable-line - console.log(row.id); // eslint-disable-line if (id === row.id) { const tmp = { id }; tmp.lender = row.lender; @@ -125,7 +123,11 @@ class LoanOptions extends Component { } handleUpdateLoanOptions = () => { - if (this.validateInputs() === true) { + if (isNaN(this.state.noi) === true) { + alert('Please fill in NOI DSCR'); + } else if (isNaN(this.state.cash) === true) { + alert('Please fill in Cash DSCR'); + } else if (this.validateInputs() === true) { const formData = {}; formData['noi-dscr'] = parseFloat(this.state.noi).toFixed(2); formData['cash-dscr'] = parseFloat(this.state.cash).toFixed(2); @@ -141,6 +143,10 @@ class LoanOptions extends Component { } } + handleOnChange = (event) => { + this.setState({ [event.target.name]: event.target.value }); + } + render() { const header = [ 'Loan Options', @@ -192,24 +198,21 @@ class LoanOptions extends Component { ); } - let messageStyle = {}; - let messageContent = null; - if (this.props.loading) { - messageContent = 'Updating ...'; - messageStyle = this.props.defaultMessageStyle; + this.state.messageContent = 'Updating ...'; + this.state.messageStyle = 'default'; } if (this.props.error && typeof this.props.error === 'object') { - messageContent = this.props.error.response.statusText; - messageStyle = this.props.errorMessageStyle; + this.state.messageContent = this.props.error.response.statusText; + this.state.messageStyle = 'error'; } if (!this.props.error && !this.props.loading && this.props.data !== null - && this.state.updated) { - messageContent = 'Saved!'; - messageStyle = this.props.successMessageStyle; + && this.state.action === 'updated') { + this.state.messageContent = 'Saved!'; + this.state.messageStyle = 'success'; } return ( @@ -270,9 +273,9 @@ class LoanOptions extends Component {
       + style={this.state.messageStyle} + content={this.state.messageContent} + /> {' '}{' '} ); } if (this.state.showCollapseButton) { collapseButton = ( - ); } diff --git a/src/components/Blocnote/FinancialInputs/CashBalance.js b/src/components/Blocnote/FinancialInputs/CashBalance.js index 64169a00..5f478ab3 100644 --- a/src/components/Blocnote/FinancialInputs/CashBalance.js +++ b/src/components/Blocnote/FinancialInputs/CashBalance.js @@ -19,6 +19,7 @@ class CashBalance extends Component { balance_amount: null, statement_date: null, is_from_balance_sheet: false, + loading: props.loading, action: null, messageContent: null, messageStyle: 'default', @@ -160,7 +161,7 @@ class CashBalance extends Component { ); } - if (this.props.loading) { + if (this.state.loading) { this.state.messageStyle = 'default'; this.state.messageContent = 'Updating ...'; } diff --git a/src/components/Blocnote/FinancialInputs/CashBalanceRow.js b/src/components/Blocnote/FinancialInputs/CashBalanceRow.js index 332bbfc6..c8f1a13e 100644 --- a/src/components/Blocnote/FinancialInputs/CashBalanceRow.js +++ b/src/components/Blocnote/FinancialInputs/CashBalanceRow.js @@ -89,7 +89,7 @@ class CashBalanceRow extends Component { CashBalanceRow.propTypes = { id: PropTypes.number, - balanceAmount: PropTypes.number, + balanceAmount: PropTypes.string, statementDate: PropTypes.string, isFromBalanceSheet: PropTypes.bool, onDelEvent: PropTypes.func, diff --git a/src/components/Blocnote/FinancialInputs/CustomerPreference.js b/src/components/Blocnote/FinancialInputs/CustomerPreference.js index 1478a557..0ef52259 100644 --- a/src/components/Blocnote/FinancialInputs/CustomerPreference.js +++ b/src/components/Blocnote/FinancialInputs/CustomerPreference.js @@ -18,7 +18,8 @@ class CustomerPreference extends Component { downpayment: this.props.data.downpayment, expectedNetNoiDscr: this.props.data.expected_net_noi_dscr, expectedPayback: this.props.data.expected_payback, - updated: false, + loading: props.loading, + action: null, messageContent: null, messageStyle: 'default', }; @@ -29,15 +30,20 @@ class CustomerPreference extends Component { } handleUpdateCustomerPreference = () => { - this.props.updateCustomerPreference( - this.props.buildingId, - { - downpayment: parseFloat(this.state.downpayment).toFixed(2), - expected_net_noi_dscr: parseInt(this.state.expectedNetNoiDscr, 10), - expected_payback: this.state.expectedPayback, - }, - ); - this.setState({ updated: true }); + this.setState({ loading: true }, () => { + this.props.updateCustomerPreference( + this.props.buildingId, + { + downpayment: parseFloat(this.state.downpayment).toFixed(2), + expected_net_noi_dscr: parseInt(this.state.expectedNetNoiDscr, 10), + expected_payback: this.state.expectedPayback, + }, + ); + this.setState({ + loading: false, + action: 'updated', + }); + }); } render() { @@ -122,7 +128,7 @@ class CustomerPreference extends Component { ); } - if (this.props.loading) { + if (this.state.loading) { this.state.messageStyle = 'default'; this.state.messageContent = 'Updating ...'; } @@ -134,7 +140,7 @@ class CustomerPreference extends Component { if (!this.props.error && !this.props.loading && this.props.data !== null - && this.state.updated) { + && this.state.action === 'updated') { this.state.messageStyle = 'success'; this.state.messageContent = 'Saved!'; } diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index 0aaf7a4d..cf3f5da8 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -49,12 +49,13 @@ class IncomeStatements extends Component { incomeStatements: props.data, incomeStatementsNew: null, error: false, - loading: false, + loading: props.loading, action: null, messageContent: null, messageStyle: 'default', }; + console.log(props.data.hist); // eslint-disable-line const histYears = {}; const incomeStatementsNew = { incomeStatementsNew: [] }; if (props.data.hist !== null) { @@ -77,7 +78,6 @@ class IncomeStatements extends Component { } this.state = Object.assign(obj, histYears, incomeStatementsNew); - console.log(this.state); // eslint-disable-line } initIncomeStatement = () => { @@ -292,6 +292,8 @@ class IncomeStatements extends Component { let header = []; let rows = []; let calculateSaveButton = null; + console.log(this.props.data.hist); // eslint-disable-line + console.log(this.state.incomeStatements.hist); // eslint-disable-line const columnKeys = [ 'revenue', @@ -338,6 +340,7 @@ class IncomeStatements extends Component { if (this.state.incomeStatements.hist !== null && this.state.incomeStatements.future !== null) { header = this.buildHeader(); + console.log(this.state.incomeStatements.hist); // eslint-disable-line const histYears = Object.keys(this.state.incomeStatements.hist).sort(); rows = columnKeys.map((columnKey, id) => { const cells = [ @@ -474,7 +477,7 @@ class IncomeStatements extends Component { ); } - if (this.props.loading) { + if (this.state.loading) { this.state.messageStyle = 'default'; this.state.messageContent = 'Updating ...'; } diff --git a/src/components/Blocnote/FinancialInputs/LoanOptions.js b/src/components/Blocnote/FinancialInputs/LoanOptions.js index c62a1075..35db9d8f 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptions.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptions.js @@ -17,6 +17,7 @@ class LoanOptions extends Component { this.deleteRow = this.deleteRow.bind(this); this.addRow = this.addRow.bind(this); this.updateRow = this.updateRow.bind(this); + this.handleUpdateLoanOptions = this.handleUpdateLoanOptions.bind(this); this.state = { loanOptions: props.data, lenders: props.lenders, @@ -27,6 +28,7 @@ class LoanOptions extends Component { interest_rate: null, duration: null, max_loan_amount: null, + loading: props.loading, action: null, messageContent: null, messageStyle: 'default', @@ -37,7 +39,6 @@ class LoanOptions extends Component { const emptyFields = []; if (this.state.loanOptions.length > 0) { Object.values(this.state.loanOptions).forEach(loanOption => { - console.log(loanOption); // eslint-disable-line if (loanOption.lender === null && !emptyFields.includes('Lender')) { emptyFields.push('Lender'); @@ -128,17 +129,20 @@ class LoanOptions extends Component { } else if (isNaN(this.state.cash) === true) { alert('Please fill in Cash DSCR'); } else if (this.validateInputs() === true) { - const formData = {}; - formData['noi-dscr'] = parseFloat(this.state.noi).toFixed(2); - formData['cash-dscr'] = parseFloat(this.state.cash).toFixed(2); - formData.instance = this.state.loanOptions; - this.props.updateLoanOptions( - this.props.buildingId, - formData, - ); - this.setState({ - loading: false, - action: 'updated', + this.setState({ loading: true }, () => { + const formData = {}; + formData['noi-dscr'] = parseFloat(this.state.noi).toFixed(2); + formData['cash-dscr'] = parseFloat(this.state.cash).toFixed(2); + formData.instance = this.state.loanOptions; + formData.lenders = this.state.lenders; + this.props.updateLoanOptions( + this.props.buildingId, + formData, + ); + this.setState({ + loading: false, + action: 'updated', + }); }); } } @@ -177,6 +181,7 @@ class LoanOptions extends Component { duration={loanOption.duration} maxLoanAmount={parseFloat(loanOption.max_loan_amount).toFixed(2)} onDelEvent={this.deleteRow} + onChangeEvent={this.handleOnChange} /> ); }); @@ -198,7 +203,7 @@ class LoanOptions extends Component { ); } - if (this.props.loading) { + if (this.state.loading) { this.state.messageContent = 'Updating ...'; this.state.messageStyle = 'default'; } @@ -298,8 +303,8 @@ LoanOptions.propTypes = { textAlign: PropTypes.string, marginBottom: PropTypes.string, }), - cash: PropTypes.number, - noi: PropTypes.number, + cash: PropTypes.string, + noi: PropTypes.string, lenders: PropTypes.arrayOf, data: PropTypes.arrayOf( PropTypes.shape({ diff --git a/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js b/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js index bf54384b..afc3052c 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js @@ -149,9 +149,9 @@ class LoanOptionsRow extends Component { LoanOptionsRow.propTypes = { id: PropTypes.number, lender: PropTypes.string, - interestRate: PropTypes.number, + interestRate: PropTypes.string, duration: PropTypes.string, - maxLoanAmount: PropTypes.number, + maxLoanAmount: PropTypes.string, onDelEvent: PropTypes.func, lenders: PropTypes.arrayOf, onChangeEvent: PropTypes.func, diff --git a/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js b/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js index ef53a101..ce931eb7 100644 --- a/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js +++ b/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js @@ -20,6 +20,7 @@ class MortgageLiabilities extends Component { input_date: null, monthly_service: null, remaining_term: null, + loading: props.loading, action: null, messageContent: null, messageStyle: 'default', @@ -112,13 +113,15 @@ class MortgageLiabilities extends Component { handleUpdateLiabilities = () => { if (this.validateInputs() === true) { - this.props.updateLiabilities( - this.props.buildingId, - this.state.liabilities, - ); - this.setState({ - loading: false, - action: 'updated', + this.setState({ loading: true }, () => { + this.props.updateLiabilities( + this.props.buildingId, + this.state.liabilities, + ); + this.setState({ + loading: false, + action: 'updated', + }); }); } } @@ -175,7 +178,7 @@ class MortgageLiabilities extends Component { ); } - if (this.props.loading) { + if (this.state.loading) { this.state.messageContent = 'Updating ...'; this.state.messageStyle = 'default'; } diff --git a/src/components/Blocnote/FinancialInputs/ResultMessage.js b/src/components/Blocnote/FinancialInputs/ResultMessage.js index ce744823..d00d8c20 100644 --- a/src/components/Blocnote/FinancialInputs/ResultMessage.js +++ b/src/components/Blocnote/FinancialInputs/ResultMessage.js @@ -4,9 +4,8 @@ import PropTypes from 'prop-types'; const successStyle = { color: '#336633', - padding: '10px 25px 10px 25px', + padding: '8px 25px 8px 25px', fontWeight: 'bold', - background: '#EEEEEE', }; const errorStyle = { color: 'red', @@ -24,13 +23,13 @@ const ResultMessage = (props) => { if (props.style === 'success') { return ( - ✓   {props.content} + ✓  {props.content} ); } else if (props.style === 'error') { return ( - {props.content} + ×  {props.content} ); } diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index fa43452a..755a017e 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -143,19 +143,20 @@ class CostEstimation extends Component {
    @@ -169,7 +170,7 @@ class CostEstimation extends Component { } CostEstimation.propTypes = { - blockStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, // headerStyle: PropTypes.string, data: PropTypes.arrayOf, updateCostEstimation: PropTypes.func, diff --git a/src/components/Blocnote/PreliminaryFinance/DownPayment.js b/src/components/Blocnote/PreliminaryFinance/DownPayment.js index 9d470f06..83180ca6 100644 --- a/src/components/Blocnote/PreliminaryFinance/DownPayment.js +++ b/src/components/Blocnote/PreliminaryFinance/DownPayment.js @@ -27,9 +27,9 @@ class DownPayment extends Component { } DownPayment.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, - paymentAmount: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, + paymentAmount: PropTypes.number, }; export default DownPayment; diff --git a/src/components/Blocnote/PreliminaryFinance/InputScenario.js b/src/components/Blocnote/PreliminaryFinance/InputScenario.js index 658e7624..396a746e 100644 --- a/src/components/Blocnote/PreliminaryFinance/InputScenario.js +++ b/src/components/Blocnote/PreliminaryFinance/InputScenario.js @@ -18,6 +18,8 @@ class InputScenario extends Component { savings: props.savings, loading: false, action: null, + messageContent: null, + messageStyle: 'default', }; } @@ -59,32 +61,21 @@ class InputScenario extends Component { } render() { - let messageStyle = {}; - let messageContent = null; - if (this.props.loading) { - messageContent = 'Processing ...'; - messageStyle = this.props.defaultMessageStyle; + this.state.messageContent = 'Processing ...'; + this.state.messageStyle = 'default'; } if (this.props.error && typeof this.props.error === 'object') { - messageContent = this.props.error.response.statusText; - messageStyle = this.props.errorMessageStyle; + this.state.messageContent = this.props.error.response.statusText; + this.state.messageStyle = 'error'; } if (!this.props.error && !this.props.loading && this.props.data !== null && this.state.action !== null) { - messageContent = ( - - ✔  {'Saved and reloaded.'} - - ); - messageStyle = { - paddingRight: '25px', - color: '#336633', - fontWeight: 'bold', - }; + this.state.messageContent = 'Saved and reloaded'; + this.state.messageStyle = 'success'; } return ( @@ -105,9 +96,9 @@ class InputScenario extends Component {
    {' '}{' '} + style={this.state.messageStyle} + content={this.state.messageContent} + />   
    {item} + {item} + {item} + {item} + {item} + {item} + {item} + {item} + {item} + {item} + + {cellValue} @@ -25,7 +27,9 @@ const TableContent = (props) => { }); return ( -
    - Year - - - - {futureYear} - - Average - - Year - - - - {' '}Next Year{' '} - - {' '}Average{' '} - - - {celldata} - -
    - - {celldata} - -
    - - {header} - - - {rows} - -
    -
    - - - ); - } -} - -IncomeStatements.propTypes = { - blockStyle: PropTypes.shape({ - marginBottom: PropTypes.string, - }), - headerStyle: PropTypes.shape({ - textAlign: PropTypes.string, - marginBottom: PropTypes.string, - }), - buildingId: PropTypes.number, - data: PropTypes.shape({ - average: PropTypes.shape({ - electric_opex: PropTypes.number, - energy_opex: PropTypes.number, - gas_opex: PropTypes.number, - net_non_energy_opex: PropTypes.number, - noi: PropTypes.number, - non_utility_expense: PropTypes.number, - oil_opex: PropTypes.number, - other_utility: PropTypes.number, - revenue: PropTypes.number, - total_opex: PropTypes.number, - utility_expense: PropTypes.number, - water_opex: PropTypes.number, - year: null, - }), - cagr: PropTypes.number, - future: PropTypes.shape({ - electric_opex: PropTypes.number, - energy_opex: PropTypes.number, - gas_opex: PropTypes.number, - net_non_energy_opex: PropTypes.number, - noi: PropTypes.number, - non_utility_expense: PropTypes.number, - oil_opex: PropTypes.number, - other_utility: PropTypes.number, - revenue: PropTypes.number, - total_opex: PropTypes.number, - utility_expense: PropTypes.number, - water_opex: PropTypes.number, - year: null, - }), - growth_rate: PropTypes.number, - hist: PropTypes.objectOf, - result: PropTypes.arrayOf(PropTypes.shape({ - year: PropTypes.string, - revenue: PropTypes.string, - utility_expense: PropTypes.string, - non_utility_operating_expense: PropTypes.string, - })), - }), - successMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - errorMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - defaultMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - updateIncomeStatements: PropTypes.func, -}; - -export default IncomeStatements; -- GitLab From e321beebeead57cd4a544f24cc6b9cba4d8e9357 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 7 Jun 2019 15:04:23 -0400 Subject: [PATCH 40/54] Fix loan options not saving issue --- .../Blocnote/FinancialInputs/LoanOptions.js | 13 ++++++++++--- .../Blocnote/FinancialInputs/LoanOptionsRow.js | 6 +++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/LoanOptions.js b/src/components/Blocnote/FinancialInputs/LoanOptions.js index ea9a17b0..a01e9c54 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptions.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptions.js @@ -110,7 +110,7 @@ class LoanOptions extends Component { const loanOptions = this.state.loanOptions.map((loanOption, id) => { if (id === row.id) { const tmp = { id }; - tmp.lender = row.lender; + tmp.lender = row.lenderDropDownValue; tmp.interest_rate = row.interest_rate; tmp.duration = row.duration; tmp.max_loan_amount = row.max_loan_amount; @@ -133,7 +133,14 @@ class LoanOptions extends Component { const formData = {}; formData['noi-dscr'] = parseFloat(this.state.noi).toFixed(2); formData['cash-dscr'] = parseFloat(this.state.cash).toFixed(2); - formData.instance = this.state.loanOptions; + formData.instance = this.state.loanOptions.map(loanOption => { + return { + lender: loanOption.lender, + interest_rate: loanOption.interest_rate, + duration: loanOption.duration, + max_loan_amount: loanOption.max_loan_amount, + }; + }); formData.lenders = this.state.lenders; this.props.updateLoanOptions( this.props.buildingId, @@ -181,7 +188,7 @@ class LoanOptions extends Component { duration={loanOption.duration} maxLoanAmount={parseFloat(loanOption.max_loan_amount).toFixed(2)} onDelEvent={this.deleteRow} - onChangeEvent={this.handleOnChange} + onChangeEvent={this.updateRow} /> ); }); diff --git a/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js b/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js index afc3052c..f4eb6c8d 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js @@ -53,7 +53,11 @@ class LoanOptionsRow extends Component { } changeLender(e) { - this.setState({ lenderDropDownValue: e.currentTarget.textContent }); + this.setState({ lenderDropDownValue: e.currentTarget.textContent }, + () => { + console.log(this.state); // eslint-disable-line + this.props.onChangeEvent(this.state); + }); } render() { -- GitLab From a5368878aba2ac48bb3f475c65a6ff66eef75448 Mon Sep 17 00:00:00 2001 From: akkking Date: Mon, 10 Jun 2019 16:05:40 -0400 Subject: [PATCH 41/54] Fix growth rate dropdown issue --- .../Blocnote/FinancialInputs/IncomeStatements.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index 9b3e0c73..304c44ce 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -21,8 +21,6 @@ class IncomeStatements extends Component { this.changeGrowthRate = this.changeGrowthRate.bind(this); this.handleOnChange = this.handleOnChange.bind(this); // this.handleOnChangeNew = this.handleOnChangeNew.bind(this); - - const GRDropdownId = props.data.growth_rate !== null ? props.data.growth_rate : -99; this.growthRateOptions = [ { id: '-2', key: '-2', name: `CAGR=${props.data.cagr}%` }, { id: '-1', key: '-1', name: 'Average' }, @@ -44,6 +42,18 @@ class IncomeStatements extends Component { { id: '15', key: '15', name: '15%' }, ]; + // Assume growth rate dropdown not select, has no value + let GRDropdownId = -99; + if (props.data.growth_rate !== null) { + GRDropdownId = props.data.growth_rate; + this.growthRateOptions.forEach(option => { + if (option.id === String(parseInt(parseFloat(props.data.growth_rate).toFixed(2) * 100, + 10))) { + GRDropdownId = option.id; + } + }); + } + const obj = { GRDropdownOpen: false, GRDropdownId, @@ -499,7 +509,9 @@ class IncomeStatements extends Component { this.state.messageContent = 'Saved and reloaded.'; } + console.log(this.state.GRDropdownId); // eslint-disable-line let GRDropdownValue = 'Select Growth Rate'; + this.growthRateOptions[0].name = `CAGR=${this.props.data.cagr}%`; this.growthRateOptions.forEach(option => { if (option.id === String(parseInt(parseFloat(this.state.GRDropdownId).toFixed(2) * 100, 10)) || option.id === this.state.GRDropdownId -- GitLab From cf18a313d7c3e27b12aedea074726768c3f67ce2 Mon Sep 17 00:00:00 2001 From: akkking Date: Mon, 10 Jun 2019 16:08:35 -0400 Subject: [PATCH 42/54] Fix growth rate dropdown issue --- src/components/Blocnote/FinancialInputs/IncomeStatements.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index 304c44ce..3232f323 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -20,7 +20,6 @@ class IncomeStatements extends Component { this.toggleGrowthRate = this.toggleGrowthRate.bind(this); this.changeGrowthRate = this.changeGrowthRate.bind(this); this.handleOnChange = this.handleOnChange.bind(this); - // this.handleOnChangeNew = this.handleOnChangeNew.bind(this); this.growthRateOptions = [ { id: '-2', key: '-2', name: `CAGR=${props.data.cagr}%` }, { id: '-1', key: '-1', name: 'Average' }, @@ -355,8 +354,6 @@ class IncomeStatements extends Component { const cells = [ ...[columnNames[columnKey]], ...histYears.map((histYear) => { - // let cellValue = incomeStatements.hist[histYear][columnKey]; - // cellValue = Math.round(cellValue * 100) / 100; if (['utility_expense', 'revenue', 'non_utility_expense'].includes(columnKey)) { let cellValue = this.state.incomeStatements.hist[histYear][columnKey]; cellValue = Math.round(cellValue * 100) / 100; @@ -509,7 +506,6 @@ class IncomeStatements extends Component { this.state.messageContent = 'Saved and reloaded.'; } - console.log(this.state.GRDropdownId); // eslint-disable-line let GRDropdownValue = 'Select Growth Rate'; this.growthRateOptions[0].name = `CAGR=${this.props.data.cagr}%`; this.growthRateOptions.forEach(option => { -- GitLab From ddb72179c68afeecf00cbd48866e6f83078579f1 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Mon, 17 Jun 2019 17:38:14 -0400 Subject: [PATCH 43/54] Add alert confirm for financial overview --- .../Blocnote/FinancialInputs/FinanceOverview.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/FinanceOverview.js b/src/components/Blocnote/FinancialInputs/FinanceOverview.js index 3a8ad430..1bab6849 100644 --- a/src/components/Blocnote/FinancialInputs/FinanceOverview.js +++ b/src/components/Blocnote/FinancialInputs/FinanceOverview.js @@ -57,13 +57,14 @@ class FinanceOverview extends Component { submitForm = (event) => { event.preventDefault(); + if (this.props.fundDropDownId !== this.state.fundDropDownId && + confirm('Changing the fund will delete current loan options, Yes or No?') !== true) { + return false; + } + const formData = new FormData(event.target); formData.set('fund_id', this.state.fundDropDownId); - // this.setState({ - // csrftoken: formData.get('csrfmiddlewaretoken'), - // }); - if (formData.get('fund_id') === '0') { this.setState({ messageContent: 'Please select a fund type', @@ -92,6 +93,7 @@ class FinanceOverview extends Component { } }); } + return false; } loadFinancialOverview = (result) => { -- GitLab From 293e470e92d3b64f5b6d0970303446ffd19cc6b9 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Thu, 20 Jun 2019 12:04:09 -0400 Subject: [PATCH 44/54] Fix empty data not loading issue --- .../PreliminaryFinance/CostEstimation.js | 6 ++---- .../PreliminaryFinance/DownPayment.js | 7 ++++++- .../PreliminaryFinance/LoanSummary.js | 19 ++++++++++++------ .../PostRetrofitBalanceSheet.js | 20 +++++++++++-------- .../PostRetrofitIncomeStatement.js | 20 +++++++++++-------- .../PriorRetrofitBalanceSheet.js | 20 +++++++++++-------- .../PriorRetrofitIncomeStatement.js | 20 +++++++++++-------- .../PreliminaryFinance/ProjectEconomics.js | 13 +++++++++--- .../PreliminaryFinance/SavingEstimation.js | 13 ++++++++++-- .../SavingsScheduleChart.js | 18 ++++++++++++----- .../PreliminaryFinance/TableContent.js | 2 +- 11 files changed, 104 insertions(+), 54 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index 755a017e..0021b639 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -110,7 +110,7 @@ class CostEstimation extends Component { rows = (
    - There is no cost estimation. + There is no cost estimation
    { }); } - return ( -
    -

    - Loan Summary -

    + if (rows.length !== 0) { + displayData = ( {header} @@ -56,6 +54,15 @@ const LoanSummary = (props) => { {rows}
    + ); + } + + return ( +
    +

    + Loan Summary +

    + {displayData}
    ); }; diff --git a/src/components/Blocnote/PreliminaryFinance/PostRetrofitBalanceSheet.js b/src/components/Blocnote/PreliminaryFinance/PostRetrofitBalanceSheet.js index f9c78059..5a14605a 100644 --- a/src/components/Blocnote/PreliminaryFinance/PostRetrofitBalanceSheet.js +++ b/src/components/Blocnote/PreliminaryFinance/PostRetrofitBalanceSheet.js @@ -8,8 +8,9 @@ import TableContent from './TableContent'; const PostRetrofitBalanceSheet = (props) => { let header = []; + let tableData = 'No data'; - if (props.data !== null) { + if (props.data !== null && Object.keys(props.data).length !== 0) { header = props.data[0].map((item, index) => { return (
    { ); }); props.data.shift(); - } - - return ( -
    -

    - Post Retrofit Balance Sheet -

    + tableData = ( @@ -35,6 +30,15 @@ const PostRetrofitBalanceSheet = (props) => {
    + ); + } + + return ( +
    +

    + Post Retrofit Balance Sheet +

    + {tableData}
    ); }; diff --git a/src/components/Blocnote/PreliminaryFinance/PostRetrofitIncomeStatement.js b/src/components/Blocnote/PreliminaryFinance/PostRetrofitIncomeStatement.js index 87c82bfc..e9215f94 100644 --- a/src/components/Blocnote/PreliminaryFinance/PostRetrofitIncomeStatement.js +++ b/src/components/Blocnote/PreliminaryFinance/PostRetrofitIncomeStatement.js @@ -8,8 +8,9 @@ import TableContent from './TableContent'; const PostRetrofitIncomeStatement = (props) => { let header = []; + let tableData = 'No data'; - if (props.data !== null) { + if (props.data !== null && Object.keys(props.data).length !== 0) { header = props.data[0].map((item, index) => { return (
    { ); }); props.data.shift(); - } - - return ( -
    -

    - Post Retrofit Income Statement -

    + tableData = ( @@ -35,6 +30,15 @@ const PostRetrofitIncomeStatement = (props) => {
    + ); + } + + return ( +
    +

    + Post Retrofit Income Statement +

    + {tableData}
    ); }; diff --git a/src/components/Blocnote/PreliminaryFinance/PriorRetrofitBalanceSheet.js b/src/components/Blocnote/PreliminaryFinance/PriorRetrofitBalanceSheet.js index fbd4ccab..7952fc71 100644 --- a/src/components/Blocnote/PreliminaryFinance/PriorRetrofitBalanceSheet.js +++ b/src/components/Blocnote/PreliminaryFinance/PriorRetrofitBalanceSheet.js @@ -8,8 +8,9 @@ import TableContent from './TableContent'; const PriorRetrofitBalanceSheet = (props) => { let header = []; + let tableData = 'No data'; - if (props.data !== null) { + if (props.data !== null && Object.keys(props.data).length !== 0) { header = props.data[0].map((item, index) => { return (
    { ); }); props.data.shift(); - } - - return ( -
    -

    - Prior Retrofit Balance Sheet -

    + tableData = ( @@ -35,6 +30,15 @@ const PriorRetrofitBalanceSheet = (props) => {
    + ); + } + + return ( +
    +

    + Prior Retrofit Balance Sheet +

    + {tableData}
    ); }; diff --git a/src/components/Blocnote/PreliminaryFinance/PriorRetrofitIncomeStatement.js b/src/components/Blocnote/PreliminaryFinance/PriorRetrofitIncomeStatement.js index c8087960..624f59bf 100644 --- a/src/components/Blocnote/PreliminaryFinance/PriorRetrofitIncomeStatement.js +++ b/src/components/Blocnote/PreliminaryFinance/PriorRetrofitIncomeStatement.js @@ -8,8 +8,9 @@ import TableContent from './TableContent'; const PriorRetrofitIncomeStatement = (props) => { let header = []; + let tableData = 'No data'; - if (props.data !== null) { + if (props.data !== null && Object.keys(props.data).length !== 0) { header = props.data[0].map((item, index) => { return (
    { ); }); props.data.shift(); - } - - return ( -
    -

    - Prior Retrofit Income Statement -

    + tableData = ( @@ -35,6 +30,15 @@ const PriorRetrofitIncomeStatement = (props) => {
    + ); + } + + return ( +
    +

    + Prior Retrofit Income Statement +

    + {tableData}
    ); }; diff --git a/src/components/Blocnote/PreliminaryFinance/ProjectEconomics.js b/src/components/Blocnote/PreliminaryFinance/ProjectEconomics.js index dd614088..ad4d7784 100644 --- a/src/components/Blocnote/PreliminaryFinance/ProjectEconomics.js +++ b/src/components/Blocnote/PreliminaryFinance/ProjectEconomics.js @@ -12,6 +12,7 @@ class ProjectEconomics extends Component { render() { let rows = []; + let displayData = 'No data'; if (this.props.data !== null) { rows = this.props.data.filter((item) => { @@ -30,14 +31,20 @@ class ProjectEconomics extends Component { }); } + if (rows.length !== 0) { + displayData = ( + + {rows} +
    + ); + } + return (

    Project Economics

    - - {rows} -
    + {displayData}
    ); } diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js index 0ce65263..236ed870 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js @@ -31,9 +31,10 @@ class SavingEstimation extends Component { padding: '10px 0 10px', fontSize: '13px', }; - const rows = []; + let rows = []; - if (this.state.savingEstimation !== null) { + if (this.state.savingEstimation !== null && + Object.keys(this.state.savingEstimation).length !== 0) { Object.entries(this.state.savingEstimation).forEach(([utilityName, utilityData], index) => { rows.push( ); }); + } else { + rows = ( +
    + There is no saving estimation +