1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-12-27 07:52:28 -05:00

Add pagination for transactions, 'New Transaction' button

This commit is contained in:
Aaron Lindsay 2015-08-11 07:00:58 -04:00
parent 684e8defb7
commit 8ca68da816
2 changed files with 96 additions and 25 deletions

View File

@ -1,6 +1,7 @@
// Import all the objects we want to use from ReactBootstrap // Import all the objects we want to use from ReactBootstrap
var Modal = ReactBootstrap.Modal; var Modal = ReactBootstrap.Modal;
var Pagination = ReactBootstrap.Pagination;
var Label = ReactBootstrap.Label; var Label = ReactBootstrap.Label;
var Table = ReactBootstrap.Table; var Table = ReactBootstrap.Table;
@ -8,6 +9,9 @@ var Grid = ReactBootstrap.Grid;
var Row = ReactBootstrap.Row; var Row = ReactBootstrap.Row;
var Col = ReactBootstrap.Col; var Col = ReactBootstrap.Col;
var Button = ReactBootstrap.Button;
var ButtonToolbar = ReactBootstrap.ButtonToolbar;
var DateTimePicker = ReactWidgets.DateTimePicker; var DateTimePicker = ReactWidgets.DateTimePicker;
const TransactionRow = React.createClass({ const TransactionRow = React.createClass({
@ -273,7 +277,7 @@ const AddEditTransactionModal = React.createClass({
</form> </form>
</Modal.Body> </Modal.Body>
<Modal.Footer> <Modal.Footer>
<ButtonGroup className="pull-right"> <ButtonGroup>
<Button onClick={this.handleCancel} bsStyle="warning">Cancel</Button> <Button onClick={this.handleCancel} bsStyle="warning">Cancel</Button>
{deleteButton} {deleteButton}
<Button onClick={this.handleSubmit} bsStyle="success">{buttonText}</Button> <Button onClick={this.handleSubmit} bsStyle="success">{buttonText}</Button>
@ -289,11 +293,23 @@ const AccountRegister = React.createClass({
return { return {
editingTransaction: false, editingTransaction: false,
selectedTransaction: new Transaction(), selectedTransaction: new Transaction(),
transactions: [] transactions: [],
pageSize: 20,
numPages: 0,
currentPage: 0,
height: 0
}; };
}, },
handleEditTransaction: function(transaction, fieldName) { resize: function() {
//TODO select fieldName first when editing var div = React.findDOMNode(this);
this.setState({height: div.parentElement.clientHeight - 30});
},
componentDidMount: function() {
this.resize();
var self = this;
$(window).resize(function() {self.resize();});
},
handleEditTransaction: function(transaction) {
this.setState({ this.setState({
selectedTransaction: transaction, selectedTransaction: transaction,
editingTransaction: true editingTransaction: true
@ -304,6 +320,19 @@ const AccountRegister = React.createClass({
editingTransaction: false editingTransaction: false
}); });
}, },
handleNewTransactionClicked: function() {
var newTransaction = new Transaction();
newTransaction.Status = TransactionStatus.Entered;
newTransaction.Date = new Date();
newTransaction.Splits.push(new Split());
newTransaction.Splits.push(new Split());
newTransaction.Splits[0].AccountId = this.props.selectedAccount.AccountId;
this.setState({
editingTransaction: true,
selectedTransaction: newTransaction
});
},
ajaxError: function(jqXHR, status, error) { ajaxError: function(jqXHR, status, error) {
var e = new Error(); var e = new Error();
e.ErrorId = 5; e.ErrorId = 5;
@ -314,7 +343,7 @@ const AccountRegister = React.createClass({
$.ajax({ $.ajax({
type: "GET", type: "GET",
dataType: "json", dataType: "json",
url: "account/"+account.AccountId+"/transactions?sort=date-desc&limit=50&page="+page, url: "account/"+account.AccountId+"/transactions?sort=date-desc&limit="+this.state.pageSize+"&page="+page,
success: function(data, status, jqXHR) { success: function(data, status, jqXHR) {
var e = new Error(); var e = new Error();
var transactions = []; var transactions = [];
@ -331,19 +360,38 @@ const AccountRegister = React.createClass({
var a = new Account(); var a = new Account();
a.fromJSON(data.account); a.fromJSON(data.account);
this.setState({transactions: transactions}); var pages = Math.ceil(data.totaltransactions / this.state.pageSize);
this.setState({
transactions: transactions,
numPages: pages
});
}.bind(this), }.bind(this),
error: this.ajaxError error: this.ajaxError
}); });
}, },
handleSelectPage: function(event, selectedEvent) {
var newpage = selectedEvent.eventKey - 1;
// Don't do pages that don't make sense
if (newpage < 0)
newpage = 0;
if (newpage >= this.state.numPages)
newpage = this.state.numPages-1;
if (newpage != this.state.currentPage) {
if (this.props.selectedAccount != null) {
this.getTransactionPage(this.props.selectedAccount, newpage);
}
this.setState({currentPage: newpage});
}
},
onNewTransaction: function() { onNewTransaction: function() {
this.getTransactionPage(this.props.selectedAccount, 0); this.getTransactionPage(this.props.selectedAccount, this.state.currentPage);
}, },
onUpdatedTransaction: function() { onUpdatedTransaction: function() {
this.getTransactionPage(this.props.selectedAccount, 0); this.getTransactionPage(this.props.selectedAccount, this.state.currentPage);
}, },
onDeletedTransaction: function() { onDeletedTransaction: function() {
this.getTransactionPage(this.props.selectedAccount, 0); this.getTransactionPage(this.props.selectedAccount, this.state.currentPage);
}, },
createNewTransaction: function(transaction) { createNewTransaction: function(transaction) {
$.ajax({ $.ajax({
@ -419,10 +467,10 @@ const AccountRegister = React.createClass({
if (nextProps.selectedAccount != this.props.selectedAccount) { if (nextProps.selectedAccount != this.props.selectedAccount) {
this.setState({ this.setState({
selectedTransaction: new Transaction(), selectedTransaction: new Transaction(),
transactions: [] transactions: [],
currentPage: 0
}); });
this.getTransactionPage(nextProps.selectedAccount, 0); this.getTransactionPage(nextProps.selectedAccount, 0);
console.log("TODO begin fetching transactions for new account");
} }
}, },
render: function() { render: function() {
@ -432,18 +480,9 @@ const AccountRegister = React.createClass({
if (this.props.selectedAccount != null) { if (this.props.selectedAccount != null) {
name = this.props.selectedAccount.Name; name = this.props.selectedAccount.Name;
var newTransaction = new Transaction();
newTransaction.Description = "Create New Transaction...";
newTransaction.Status = TransactionStatus.Entered;
newTransaction.Date = new Date();
newTransaction.Splits.push(new Split());
newTransaction.Splits.push(new Split());
newTransaction.Splits[0].AccountId = this.props.selectedAccount.AccountId;
var transactionRows = []; var transactionRows = [];
var allTransactions = [newTransaction].concat(this.state.transactions); for (var i = 0; i < this.state.transactions.length; i++) {
for (var i = 0; i < allTransactions.length; i++) { var t = this.state.transactions[i];
var t = allTransactions[i];
transactionRows.push(( transactionRows.push((
<TransactionRow <TransactionRow
transaction={t} transaction={t}
@ -474,8 +513,11 @@ const AccountRegister = React.createClass({
); );
} }
var style = {height: this.state.height + "px"};
var disabled = (this.props.selectedAccount == null) ? "disabled" : "";
return ( return (
<div> <div className="transactions-container" style={style}>
<AddEditTransactionModal <AddEditTransactionModal
show={this.state.editingTransaction} show={this.state.editingTransaction}
transaction={this.state.selectedTransaction} transaction={this.state.selectedTransaction}
@ -485,7 +527,26 @@ const AccountRegister = React.createClass({
onSubmit={this.handleUpdateTransaction} onSubmit={this.handleUpdateTransaction}
onDelete={this.handleDeleteTransaction} onDelete={this.handleDeleteTransaction}
securities={this.props.securities}/> securities={this.props.securities}/>
{name} Transactions for '{name}'
<ButtonToolbar className="pull-right">
<ButtonGroup>
<Pagination
className="skinny-pagination"
prev next first last ellipses
items={this.state.numPages}
maxButtons={Math.min(5, this.state.numPages)}
activePage={this.state.currentPage+1}
onSelect={this.handleSelectPage} />
</ButtonGroup>
<ButtonGroup>
<Button
onClick={this.handleNewTransactionClicked}
bsStyle="success"
disabled={disabled}>
<Glyphicon glyph='plus-sign' /> New Transaction
</Button>
</ButtonGroup>
</ButtonToolbar>
{register} {register}
</div> </div>
); );

View File

@ -71,6 +71,12 @@ div.accounttree-root div {
right: 15px; right: 15px;
bottom: 15px; bottom: 15px;
} }
.transactions-container {
display: block;
width: 100%;
height: 100%;
overflow: auto;
}
.transactions-column { .transactions-column {
padding: 15px; padding: 15px;
border-right: 1px solid #DDD; border-right: 1px solid #DDD;
@ -96,3 +102,7 @@ div.accounttree-root div {
font-weight: 700; font-weight: 700;
text-align: center; text-align: center;
} }
.skinny-pagination {
margin: 0px;
}