Skip to content

Commit

Permalink
version 14: adding assets details page
Browse files Browse the repository at this point in the history
  • Loading branch information
Kumar authored and Kumar committed Apr 23, 2020
1 parent 3e368d4 commit 4d0160a
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 27 deletions.
22 changes: 11 additions & 11 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ class App extends Component {
}

fetchServiceData() {
const data = JSON.parse(utils.mockAssetzService());
console.log(data)
this.setState({
data: data
});
// const data = JSON.parse(utils.mockAssetzService());
// console.log(data)
// this.setState({
// data: data
// });
//uncomment below in production.
// fetch('http://192.168.0.112:8080/assets?startDate=' + this.state.startDate + "&endDate=" + this.state.endDate)
// .then(res => res.json())
// .then((data) => {
// this.setState({ data: data })
// })
// .catch(console.log)
fetch('http://192.168.0.112:8080/assets?startDate=' + this.state.startDate + "&endDate=" + this.state.endDate)
.then(res => res.json())
.then((data) => {
this.setState({ data: data })
})
.catch(console.log)
}

componentDidMount() {
Expand Down
54 changes: 45 additions & 9 deletions src/component/AppDashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
import React, { Component } from 'react';
import Modal from 'react-bootstrap/Modal';
import Button from 'react-bootstrap/Button';
import * as utils from './Utils'

class AppDashboard extends Component {


constructor(props) {
super(props);
this.state = {
data: null
}
}

fetchServiceData() {
const data = JSON.parse(utils.mockAppStatusService());
console.log(data)
this.setState({
data: data
});
//uncomment below in production.
// fetch('http://192.168.0.112:8080/assets?startDate=' + this.state.startDate + "&endDate=" + this.state.endDate)
// .then(res => res.json())
// .then((data) => {
// this.setState({ data: data })
// })
// .catch(console.log)
}

componentDidMount() {
this.fetchServiceData();
}

render() {
const { show } = this.props;
let stocksNavSyncDt = null;
let mfNavSyncDt = null;
const { data } = this.state;
if (data && data.data) {
stocksNavSyncDt = data.data.stocksNavSyncDt;
mfNavSyncDt = data.data.mfNavSyncDt;
}

debugger
return (
<div>
{/* <Alert show={show} variant="success">
Expand All @@ -28,14 +64,14 @@ class AppDashboard extends Component {
<Modal.Title>Application Status</Modal.Title>
</Modal.Header>
<Modal.Body>
<label>Stocks Latest Nav Date: </label>
<span>
100.5
</span>
<label>Mutual Fund Latest Nav Date: </label>
<span>
100.5
</span>
<p>
<label class="text-primary">Stocks Nav Date:</label>
<label class="text-success"> {stocksNavSyncDt}</label>
</p>
<p>
<label class="text-primary">Mutual Funds Nav Date:</label>
<label class="text-success"> {mfNavSyncDt} </label>
</p>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={() => this.props.closeAppStatus()}>
Expand Down
185 changes: 185 additions & 0 deletions src/component/AssetsDetails.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import React, { Component } from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import * as utils from './Utils'

function lossGainFormatter(cell, row) {
let icon;
const formattedAmount = utils.formatMoney(cell)
if (cell < 0) {
icon = <FontAwesomeIcon icon="arrow-alt-circle-down" color="red" />
} else if (cell > 0) {
icon = <FontAwesomeIcon icon="arrow-alt-circle-up" color="green" />
}
return (
<span>{formattedAmount} {icon}</span>

);
}

function moneyFormatter(cell, row) {
const formattedAmount = utils.formatMoney(cell)
return (
<span>{formattedAmount} </span>
);
}

function percentFormatter(cell, row) {
let icon;
const formattedPer = utils.formatNum(cell)
if (cell < 0) {
icon = <FontAwesomeIcon icon="arrow-alt-circle-down" color="red" />
} else if (cell > 0) {
icon = <FontAwesomeIcon icon="arrow-alt-circle-up" color="green" />
}
return (
<span>{formattedPer} % {icon}</span>
);
}



class AssetsDetails extends Component {
constructor(props) {
super(props);
this.state = {
data: null,
startDate: utils.yesterdayDate(),
endDate: utils.todayDate()
}
}

fetchServiceData() {
// const data = JSON.parse(utils.mockAppStatusService());
// console.log(data)
// this.setState({
// data: data
// });
//uncomment below in production.
console.log("fetch service in assets details called");
const { assetType, portfolioName } = this.props;
if (assetType && assetType != null && portfolioName && portfolioName != null) {
fetch('http://192.168.0.112:8080/assets/types/' + assetType + '/portfolios/' + portfolioName + '?startDate=' + this.state.startDate + "&endDate=" + this.state.endDate)
.then(res => res.json())
.then((data) => {
this.setState({ data: data })
})
.catch(console.log)
}

}

componentDidMount() {
console.log("inside componentDidMount for assets details");
debugger
if (this.props.reloadAssetDetails && this.props.reloadAssetDetails === true) {
this.fetchServiceData();
}
}

render() {
const { data } = this.state;
let details = [];
if (data && data.data) {
details = data.data;
}
const columns = [
{
dataField: 'schemeName',
text: 'Scheme',
sort: true,
align: "left"
}, {
dataField: 'lastNav',
text: 'Last Nav',
formatter: moneyFormatter,
sort: true,
align: "left"
}, {
dataField: 'lastNavDt',
text: 'Last Nav Date',
sort: true,
align: "left"
},
{
dataField: 'navChange',
text: 'Nav Change',
formatter: lossGainFormatter,
sort: true,
align: "left"
}, {
dataField: 'navChangePercent',
text: 'Nav Change %',
formatter: percentFormatter,
sort: true,
align: "left"
},
{
dataField: 'units',
text: 'Units',
sort: true,
align: "left"
},
{
dataField: 'avgCost',
text: 'Avg Cost',
sort: true,
formatter: moneyFormatter,
align: "left"
},
{
dataField: 'investedAmt',
text: 'Amount Invested',
formatter: moneyFormatter,
sort: true,
align: "left"
},
{
dataField: 'currentValuation',
text: 'Current Valuation',
formatter: moneyFormatter,
sort: true,
align: "left"
},

{
dataField: 'gainLoss',
text: 'Gain/Loss',
sort: true,
formatter: lossGainFormatter,
sort: true,
align: "left"
},
{
dataField: 'gainLossPercent',
text: 'Gain/Loss %',
sort: true,
formatter: percentFormatter,
align: "left"
},
{
dataField: 'notionalGainLoss',
text: 'Notional Gain/Loss',
formatter: lossGainFormatter,
sort: true,
align: "left"
},
{
dataField: 'notionalGainLossPercent',
text: 'Notional Gain/Loss %',
formatter: percentFormatter,
sort: true,
align: "left"
}
];

return (
<div>
<h2 className="text-left">Assets Breakdown</h2>
<BootstrapTable wrapperClasses="table-responsive text-nowrap" keyField='assetType' data={details} columns={columns} />
</div>
);
}
}

export default AssetsDetails;
32 changes: 30 additions & 2 deletions src/component/AssetsSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,26 @@ function moneyFormatter(cell, row) {
);
}

function percentFormatter(cell, row) {
let icon;
const formattedPer = utils.formatNum(cell)
if (cell < 0) {
icon = <FontAwesomeIcon icon="arrow-alt-circle-down" color="red" />
} else if (cell > 0) {
icon = <FontAwesomeIcon icon="arrow-alt-circle-up" color="green" />
}
return (
<span>{formattedPer} % {icon}</span>
);
}

class AssetsSummary extends Component {

handleRowSelect(assetType) {
console.log("clicked on:"+assetType)
this.props.selectAssetType(assetType);
};

render() {
let details = [];
if (this.props.assets && this.props.assets.details) {
Expand All @@ -41,11 +59,13 @@ class AssetsSummary extends Component {
dataField: 'currentValuation',
text: 'Current Valuation',
formatter: moneyFormatter,
sort: true,
align: "left"
}, {
dataField: 'amountInvested',
text: 'Amount Invested',
formatter: moneyFormatter,
sort: true,
align: "left"
},
{
Expand All @@ -59,27 +79,35 @@ class AssetsSummary extends Component {
dataField: 'gainLossPercentage',
text: 'Gain/Loss %',
sort: true,
formatter: lossGainFormatter,
formatter: percentFormatter,
align: "left"
},
{
dataField: 'totalNotionalGainLoss',
text: 'Total Notional Gain/Loss',
formatter: lossGainFormatter,
sort: true,
align: "left"
},
{
dataField: 'totalRealizedGainLoss',
text: 'Total Realized Gain/Loss',
formatter: lossGainFormatter,
sort: true,
align: "left"
}
];

const rowEvents = {
onClick: (e, row, rowIndex) => {
this.handleRowSelect(row.assetType);
}
};

return (
<div>
<h2 className="text-left">Assets Summary</h2>
<BootstrapTable wrapperClasses="table-responsive" keyField='assetType' data={details} columns={columns} />
<BootstrapTable keyField="assetType" wrapperClasses="table-responsive text-nowrap" keyField='assetType' data={details} columns={columns} rowEvents={ rowEvents } />
</div>
);
}
Expand Down
Loading

0 comments on commit 4d0160a

Please sign in to comment.