-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from Team-40-IDATT2003/105-create-transaction…
…s-page 105 create transactions page
- Loading branch information
Showing
12 changed files
with
478 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,5 +4,6 @@ public enum TopBarActions { | |
| EXIT, | ||
| STATS, | ||
| MARKET, | ||
| SETTINGS; | ||
| SETTINGS, | ||
| TRANSACTIONS; | ||
| } | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
.../java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/transactions/TransactionsActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions; | ||
|
|
||
| /** | ||
| * Enum representing actions to be done in a {@link TransactionsView} element. | ||
| * */ | ||
| public enum TransactionsActions { | ||
| // Empty, no interactable buttons in transactions page. | ||
| } |
99 changes: 99 additions & 0 deletions
99
...va/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/transactions/TransactionsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions; | ||
|
|
||
| import edu.ntnu.idi.idatt2003.g40.mappe.engine.TransactionArchive; | ||
| import edu.ntnu.idi.idatt2003.g40.mappe.model.Sale; | ||
| import edu.ntnu.idi.idatt2003.g40.mappe.model.Transaction; | ||
| import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager; | ||
| import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Controller for a {@link TransactionsView} element. | ||
| * | ||
| * <p>extends {@link ViewController}</p> | ||
| * */ | ||
| public class TransactionsController extends ViewController<TransactionsView> { | ||
|
|
||
| private final TransactionArchive transactionArchive; | ||
| public TransactionsController(final TransactionsView viewElement, | ||
| final EventManager eventManager, | ||
| final TransactionArchive transactionArchive) { | ||
| this.transactionArchive = transactionArchive; | ||
| super(viewElement, eventManager); | ||
| getViewElement().clearCards(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initInteractions() { | ||
|
|
||
|
|
||
| getViewElement().getWeekSelectBox().setOnAction(event -> { | ||
| try { | ||
| Integer selectedWeek = Integer.parseInt(getViewElement().getWeekSelectBox().getValue()); | ||
| filterData(getViewElement().getSearchField().getText(), selectedWeek); | ||
| } catch (NumberFormatException _) { | ||
| filterData(getViewElement().getSearchField().getText(), 1); | ||
| } | ||
| }); | ||
|
|
||
| getViewElement().getSearchField().textProperty().addListener((observable, oldValue, newValue) -> { | ||
| filterData(newValue, Integer.parseInt(getViewElement().getWeekSelectBox().getValue())); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Method used for updating the list of transactions based on a search and target week. | ||
| * | ||
| * @param searchKeyword the keyword to search for stocks with. | ||
| * @param weekTarget the week used when searching for transactions. | ||
| * */ | ||
| private void filterData(final String searchKeyword, final Integer weekTarget) { | ||
| getViewElement().clearCards(); | ||
| transactionArchive.getTransactions(weekTarget).forEach(t -> { | ||
| if (t.getShare().getStock().getCompany().toLowerCase().contains(searchKeyword.toLowerCase()) | ||
| || t.getShare().getStock().getSymbol().toLowerCase().contains(searchKeyword.toLowerCase())) { | ||
| String transactionType = "Purchase"; | ||
| String sharePrefix = "+ "; | ||
| String moneyPrefix = "- "; | ||
|
|
||
| if(t.getClass().equals(Sale.class)){ | ||
| transactionType = "Sale"; | ||
| sharePrefix = "- "; | ||
| moneyPrefix = "+ "; | ||
| } | ||
|
|
||
| getViewElement().addTransactionCard( | ||
| transactionType, | ||
| t.getShare().getStock().getSymbol(), | ||
| t.getShare().getStock().getCompany(), | ||
| sharePrefix + t.getShare().getQuantity().floatValue() + " shares", | ||
| moneyPrefix + t.getCalculator().calculateTotal().toString() + " NOK", | ||
| weekTarget.toString()); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private List<Integer> getUniqueTransactionWeeks(final List<Transaction> transactionList) { | ||
| return transactionList.stream() | ||
| .map(Transaction::getWeek) | ||
| .distinct() | ||
| .sorted() | ||
| .toList(); | ||
| } | ||
|
|
||
| public void refresh() { | ||
| List<Integer> activeWeeks = getUniqueTransactionWeeks(transactionArchive.getTransactions()); | ||
| getViewElement().setWeekSelectBoxOptions(activeWeeks); | ||
|
|
||
| if (activeWeeks.contains(Integer.parseInt(getViewElement().getWeekSelectBox().getValue()))) { | ||
| getViewElement().getWeekSelectBox().setValue(getViewElement().getWeekSelectBox().getValue()); | ||
| } else if (!activeWeeks.isEmpty()) { | ||
| getViewElement().getWeekSelectBox().setValue(activeWeeks.getFirst().toString()); | ||
| } | ||
|
|
||
| filterData( | ||
| getViewElement().getSearchField().getText(), | ||
| Integer.parseInt(getViewElement().getWeekSelectBox().getValue()) | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.