Skip to content

Commit

Permalink
update transactions view when reports are updated (#137)
Browse files Browse the repository at this point in the history
remember the filter when showing list of transactions, and use it to
show fresh list of transactions when report is updated
  • Loading branch information
hrj authored Feb 15, 2017
1 parent fbcf267 commit a2716cd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 21 deletions.
75 changes: 56 additions & 19 deletions gui/src/main/scala/co/uproot/abandon/RegReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,49 @@ object RegUIReport extends UIReport {
item.getValue.txns ++ item.children.flatMap(getNestedTxns(_))
}

def mkRegisterReport(appState: AppState, reportSettings: RegisterReportSettings) = {
case class SelectionFilter(itemName: String, parentNameOpt: Option[String]) {
def heading = parentNameOpt.map(_ + " / ").getOrElse("") + itemName

def isMatching(entry: TreeItem[RegisterReportEntry]): Boolean = {
parentNameOpt match {
case Some(pn) =>
itemName == entry.getValue.accountName && pn == entry.getParent.getValue.render
case None =>
itemName == entry.getValue.render
}
}

}

private var transactionViewRegTitle: String = _
private var selectedFilterOpt: Option[SelectionFilter] = None

private val txnRootSP: ScrollPane = new ScrollPane { }
private val txStage = new Stage() {
scene = new Scene(800, 600) {
root = txnRootSP
stylesheets += "default_theme.css"
}
initModality(Modality.ApplicationModal)
onCloseRequest = () => selectedFilterOpt = None
}

private def showTransactions(selectedItemOpt: Option[javafx.scene.control.TreeItem[RegisterReportEntry]]):Unit = {
val txns = selectedItemOpt.map(si => getNestedTxns(si)).getOrElse(Nil)
txnRootSP.content = TxnUIReport.mkTxnView(txns)
txStage.title = "Transactions for " + selectedFilterOpt.get.heading
txStage.show
}

private def findMatchingEntry(entry: TreeItem[RegisterReportEntry], filter: SelectionFilter):Option[javafx.scene.control.TreeItem[RegisterReportEntry]] = {
if(filter.isMatching(entry)) {
Some(entry.delegate)
} else {
entry.children.map(c => findMatchingEntry(c, filter)).find(_.isDefined).getOrElse(None)
}
}

def mkRegisterReport(title: String, appState: AppState, reportSettings: RegisterReportSettings) = {
val registers = Reports.registerReport(appState, reportSettings)
val registerItems = registers.map { rg =>
new TreeItem(RegisterReportEntry(null, Nil, rg.groupTitle)) {
Expand All @@ -27,31 +69,26 @@ object RegUIReport extends UIReport {
children = registerItems
expanded = true
}

if (title == transactionViewRegTitle) {
// update transactions view
selectedFilterOpt foreach {sf => showTransactions(findMatchingEntry(reportRoot, sf))}
}

new TreeView(reportRoot) {
styleClass += styleClassName
onKeyTyped = { e: KeyEvent =>
if (e.character equals "\r") {
val selectedItemOpt = selectionModel().getSelectedItems().headOption
selectedItemOpt foreach { selectedItem =>
val heading =
if (selectedItem.getValue.accountName == null) {
selectedItem.getValue.render
} else {
selectedItem.getParent.getValue.render + " / " + selectedItem.getValue.accountName
}

val txStage = new Stage() {
scene = new Scene(800, 600) {
root = new ScrollPane {
content = TxnUIReport.mkTxnView(getNestedTxns(selectedItem))
}
stylesheets += "default_theme.css"
}
initModality(Modality.ApplicationModal)
title = "Transactions for " + heading
selectedFilterOpt = selectedItemOpt map {selectedItem =>
if (selectedItem.getValue.accountName == null) {
SelectionFilter(selectedItem.getValue.render, None)
} else {
SelectionFilter(selectedItem.getValue.accountName, Option(selectedItem.getParent.getValue.render))
}
txStage.show
}
transactionViewRegTitle = title
showTransactions(selectedItemOpt)
}
}
cellFactory = { v =>
Expand Down
4 changes: 2 additions & 2 deletions gui/src/main/scala/co/uproot/abandon/UI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ object CurrReports {
def showReport(appState: AppState, settings: Settings, rs: ReportSettings, canClose: Boolean) = {
val reportRender = rs match {
case regSettings: RegisterReportSettings =>
RegUIReport.mkRegisterReport(appState, regSettings)
RegUIReport.mkRegisterReport(rs.title, appState, regSettings)
case balSettings: BalanceReportSettings =>
BalanceUIReport.mkBalanceReport(appState, settings, balSettings)
case bookSettings: BookReportSettings =>
// TODO
RegUIReport.mkRegisterReport(appState, RegisterReportSettings(bookSettings.title, bookSettings.accountMatch, Nil, GroupByMonth()))
RegUIReport.mkRegisterReport(rs.title, appState, RegisterReportSettings(bookSettings.title, bookSettings.accountMatch, Nil, GroupByMonth()))
}
AbandonUI.tabPane.addOrSetTab(rs.title, reportRender, canClose)
}
Expand Down

0 comments on commit a2716cd

Please sign in to comment.