2016-02-12 20:36:59 -05:00
|
|
|
var React = require('react');
|
2018-11-02 21:15:33 -04:00
|
|
|
var ReactDOM = require('react-dom');
|
2016-02-12 20:36:59 -05:00
|
|
|
|
|
|
|
var ReactBootstrap = require('react-bootstrap');
|
|
|
|
var Jumbotron = ReactBootstrap.Jumbotron;
|
|
|
|
var Tabs = ReactBootstrap.Tabs;
|
|
|
|
var Tab = ReactBootstrap.Tab;
|
2018-11-02 21:15:33 -04:00
|
|
|
var Nav = ReactBootstrap.Nav;
|
|
|
|
var NavDropdown = ReactBootstrap.NavDropdown;
|
|
|
|
var NavItem = ReactBootstrap.NavItem;
|
|
|
|
var Col = ReactBootstrap.Col;
|
|
|
|
var Row = ReactBootstrap.Row;
|
2016-02-12 20:36:59 -05:00
|
|
|
var Modal = ReactBootstrap.Modal;
|
2018-11-02 21:15:33 -04:00
|
|
|
var FormControl = ReactBootstrap.FormControl;
|
|
|
|
var InputGroup = ReactBootstrap.InputGroup;
|
|
|
|
var Button = ReactBootstrap.Button;
|
|
|
|
var Glyphicon = ReactBootstrap.Glyphicon;
|
|
|
|
|
|
|
|
var MenuItem = ReactBootstrap.MenuItem;
|
|
|
|
var SplitButton = ReactBootstrap.SplitButton;
|
2016-02-12 20:36:59 -05:00
|
|
|
|
2016-10-05 13:45:09 -04:00
|
|
|
var TopBarContainer = require('../containers/TopBarContainer');
|
2017-01-08 21:04:01 -05:00
|
|
|
var NewUserModalContainer = require('../containers/NewUserModalContainer');
|
2016-10-05 13:45:09 -04:00
|
|
|
var AccountSettingsModalContainer = require('../containers/AccountSettingsModalContainer');
|
|
|
|
var AccountsTabContainer = require('../containers/AccountsTabContainer');
|
2016-10-26 06:58:14 -04:00
|
|
|
var SecuritiesTabContainer = require('../containers/SecuritiesTabContainer');
|
2017-02-11 20:39:38 -05:00
|
|
|
var ReportsTabContainer = require('../containers/ReportsTabContainer');
|
2018-11-02 21:15:33 -04:00
|
|
|
var AddEditAccountModal = require('./AddEditAccountModal');
|
|
|
|
|
|
|
|
var AccountTree = require('./AccountTree');
|
|
|
|
|
|
|
|
var utils = require('../utils');
|
2016-02-12 20:36:59 -05:00
|
|
|
|
2017-06-07 19:12:53 -04:00
|
|
|
class MoneyGoApp extends React.Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
2018-11-02 21:15:33 -04:00
|
|
|
tab: 1,
|
|
|
|
accountFilter: "",
|
2017-01-08 21:04:01 -05:00
|
|
|
showNewUserModal: false,
|
2018-11-02 21:15:33 -04:00
|
|
|
showSettingsModal: false,
|
|
|
|
creatingNewAccount: false
|
2016-02-12 20:36:59 -05:00
|
|
|
};
|
2017-06-07 19:12:53 -04:00
|
|
|
this.onShowSettings = this.handleShowSettings.bind(this);
|
|
|
|
this.onHideSettings = this.handleHideSettings.bind(this);
|
|
|
|
this.onShowNewUser = this.handleShowNewUser.bind(this);
|
|
|
|
this.onHideNewUser = this.handleHideNewUser.bind(this);
|
2018-11-02 21:15:33 -04:00
|
|
|
this.onSelectTab = this.handleSelectTab.bind(this);
|
|
|
|
this.onAccountSelected = this.handleAccountSelected.bind(this);
|
|
|
|
this.onNewAccount = this.handleNewAccount.bind(this);
|
|
|
|
this.onNewAccountCancel = this.handleNewAccountCancel.bind(this);
|
|
|
|
this.onCreateAccount = this.handleCreateAccount.bind(this);
|
|
|
|
this.onAccountFilterChange = this.handleAccountFilterChange.bind(this);
|
|
|
|
this.onClearAccountFilter = this.handleClearAccountFilter.bind(this);
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
componentDidMount() {
|
2016-10-05 13:36:47 -04:00
|
|
|
this.props.tryResumingSession();
|
2017-06-21 21:25:38 -04:00
|
|
|
this.props.fetchCurrencies();
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleShowSettings() {
|
2018-11-02 21:15:33 -04:00
|
|
|
this.setState({showSettingsModal: true});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleHideSettings(user) {
|
2018-11-02 21:15:33 -04:00
|
|
|
this.setState({showSettingsModal: false});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleShowNewUser() {
|
2017-01-08 21:04:01 -05:00
|
|
|
this.setState({showNewUserModal: true});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleHideNewUser() {
|
2017-01-08 21:04:01 -05:00
|
|
|
this.setState({showNewUserModal: false});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
2018-11-02 21:15:33 -04:00
|
|
|
handleSelectTab(key) {
|
|
|
|
console.log(key);
|
|
|
|
if (key != undefined) {
|
|
|
|
this.setState({tab: key});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handleAccountSelected(account) {
|
|
|
|
this.setState({
|
|
|
|
tab: 1,
|
|
|
|
accountFilter: ""});
|
|
|
|
this.props.onSelectAccount(account.AccountId);
|
|
|
|
this.props.onFetchTransactionPage(account, 20, 0);
|
|
|
|
}
|
|
|
|
handleNewAccount() {
|
|
|
|
this.setState({creatingNewAccount: true});
|
|
|
|
}
|
|
|
|
handleNewAccountCancel() {
|
|
|
|
this.setState({creatingNewAccount: false});
|
|
|
|
}
|
|
|
|
handleCreateAccount(account) {
|
|
|
|
this.props.onCreateAccount(account);
|
|
|
|
this.setState({creatingNewAccount: false});
|
|
|
|
}
|
|
|
|
handleAccountFilterChange() {
|
|
|
|
this.setState({accountFilter: ReactDOM.findDOMNode(this.refs.accountFilter).value});
|
|
|
|
}
|
|
|
|
handleClearAccountFilter() {
|
|
|
|
this.setState({accountFilter: ""});
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
render() {
|
2016-02-12 20:36:59 -05:00
|
|
|
var mainContent;
|
2018-11-02 21:15:33 -04:00
|
|
|
if (this.props.user.isUser()) {
|
|
|
|
var accountElements = [];
|
|
|
|
if (this.state.accountFilter.length > 0) {
|
|
|
|
var filterRegex = new RegExp(this.state.accountFilter, "i")
|
|
|
|
for (var accountId in this.props.accounts) {
|
|
|
|
var account = this.props.accounts[accountId];
|
|
|
|
var fullName = utils.getAccountDisplayName(account, this.props.accounts);
|
|
|
|
if (fullName.match(filterRegex)) {
|
|
|
|
var clojure = function(self, account) {
|
|
|
|
return function() {
|
|
|
|
self.handleAccountSelected(account);
|
|
|
|
};
|
|
|
|
}(this, account);
|
|
|
|
accountElements.push((<MenuItem key={accountId} onSelect={clojure}>{fullName}</MenuItem>));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
accountElements.push((<MenuItem key={1} divider />));
|
|
|
|
accountElements.push((<AccountTree key={2}
|
|
|
|
accounts={this.props.accounts}
|
|
|
|
accountChildren={this.props.accountChildren}
|
|
|
|
selectedAccount={this.props.selectedAccount}
|
|
|
|
onSelectAccount={this.onAccountSelected}
|
|
|
|
onSelectKey={1} />));
|
|
|
|
}
|
|
|
|
|
2017-01-08 21:04:01 -05:00
|
|
|
mainContent = (
|
2018-11-02 21:15:33 -04:00
|
|
|
<Tab.Container id="main-ui-navigation" activeKey={this.state.tab} onSelect={this.onSelectTab}>
|
|
|
|
<Row className="clearfix">
|
|
|
|
<Col sm={12}>
|
|
|
|
<Nav bsStyle="tabs">
|
|
|
|
<NavDropdown eventKey={1} title="Accounts">
|
|
|
|
<MenuItem onSelect={this.onNewAccount}>New Account</MenuItem>
|
|
|
|
<MenuItem divider />
|
|
|
|
<MenuItem disabled className="account-filter-menuitem">
|
|
|
|
<InputGroup>
|
|
|
|
<FormControl
|
|
|
|
onKeyDown={function(e){if (e.key == " ") e.stopPropagation();}}
|
|
|
|
type="text"
|
|
|
|
placeholder="Search..."
|
|
|
|
value={this.state.accountFilter}
|
|
|
|
onChange={this.onAccountFilterChange}
|
|
|
|
ref="accountFilter" />
|
|
|
|
<InputGroup.Button>
|
|
|
|
<Button className="clear-account-filter" onClick={this.onClearAccountFilter}>
|
|
|
|
<Glyphicon glyph="remove"/>
|
|
|
|
</Button>
|
|
|
|
</InputGroup.Button>
|
|
|
|
</InputGroup>
|
|
|
|
</MenuItem>
|
|
|
|
{accountElements}
|
|
|
|
</NavDropdown>
|
|
|
|
<NavItem eventKey={2}>Securities</NavItem>
|
|
|
|
<NavItem eventKey={3}>Scheduled Transactions</NavItem>
|
|
|
|
<NavItem eventKey={4}>Budgets</NavItem>
|
|
|
|
<NavItem eventKey={5}>Reports</NavItem>
|
|
|
|
</Nav>
|
|
|
|
</Col>
|
|
|
|
<Col sm={12}>
|
|
|
|
<Tab.Content>
|
|
|
|
<Tab.Pane eventKey={1}>
|
|
|
|
<AccountsTabContainer/>
|
|
|
|
</Tab.Pane>
|
|
|
|
<Tab.Pane eventKey={2}>
|
|
|
|
<SecuritiesTabContainer/>
|
|
|
|
</Tab.Pane>
|
|
|
|
<Tab.Pane eventKey={3}>
|
|
|
|
Scheduled transactions go here...
|
|
|
|
</Tab.Pane>
|
|
|
|
<Tab.Pane eventKey={4}>
|
|
|
|
Budgets go here...
|
|
|
|
</Tab.Pane>
|
|
|
|
<Tab.Pane eventKey={5}>
|
|
|
|
<ReportsTabContainer/>
|
|
|
|
</Tab.Pane>
|
|
|
|
</Tab.Content>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Tab.Container>);
|
|
|
|
} else {
|
2017-01-08 21:04:01 -05:00
|
|
|
mainContent = (
|
|
|
|
<Jumbotron>
|
|
|
|
<center>
|
|
|
|
<h1>Money<i>Go</i></h1>
|
|
|
|
<p><i>Go</i> manage your money.</p>
|
|
|
|
</center>
|
|
|
|
</Jumbotron>);
|
2018-11-02 21:15:33 -04:00
|
|
|
}
|
2016-02-12 20:36:59 -05:00
|
|
|
|
|
|
|
return (
|
2018-11-02 21:15:33 -04:00
|
|
|
<div className="ui">
|
2016-10-05 13:36:47 -04:00
|
|
|
<TopBarContainer
|
2017-06-07 19:12:53 -04:00
|
|
|
onCreateNewUser={this.onShowNewUser}
|
2018-11-02 21:15:33 -04:00
|
|
|
onSettings={this.onShowSettings} />
|
2016-02-12 20:36:59 -05:00
|
|
|
{mainContent}
|
2017-01-08 21:04:01 -05:00
|
|
|
<NewUserModalContainer
|
|
|
|
show={this.state.showNewUserModal}
|
2017-06-07 19:12:53 -04:00
|
|
|
onSubmit={this.onHideNewUser}
|
|
|
|
onCancel={this.onHideNewUser}/>
|
2016-10-05 13:36:47 -04:00
|
|
|
<AccountSettingsModalContainer
|
2018-11-02 21:15:33 -04:00
|
|
|
show={this.state.showSettingsModal}
|
2017-06-07 19:12:53 -04:00
|
|
|
onSubmit={this.onHideSettings}
|
|
|
|
onCancel={this.onHideSettings}/>
|
2018-11-02 21:15:33 -04:00
|
|
|
<AddEditAccountModal
|
|
|
|
show={this.state.creatingNewAccount}
|
|
|
|
initialParentAccount={this.props.selectedAccount}
|
|
|
|
accounts={this.props.accounts}
|
|
|
|
accountChildren={this.props.accountChildren}
|
|
|
|
onCancel={this.onNewAccountCancel}
|
|
|
|
onSubmit={this.onCreateAccount}
|
|
|
|
security_list={this.props.security_list}/>
|
2016-02-12 20:36:59 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = MoneyGoApp;
|