Skip to content

Commit 3504c53

Browse files
authored
Starting Dashboard Work (#799)
1 parent 0a2dc57 commit 3504c53

21 files changed

+570
-362
lines changed

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
pkgs: boost-date-time gtest libnick matplotplusplus podofo rapidcsv
3131
triplet: x64-windows
3232
cache-key: windows-latest
33-
revision: 7f9f0e44db287e8e67c0e888141bfa200ab45121
33+
revision: 936588e23157b56507069ad664b020881c119e54
3434
token: ${{ secrets.GITHUB_TOKEN }}
3535
- name: "Build"
3636
working-directory: ${{github.workspace}}/build
@@ -63,7 +63,7 @@ jobs:
6363
pkgs: boost-date-time gtest libnick matplotplusplus podofo rapidcsv
6464
triplet: x64-linux
6565
cache-key: ubuntu-latest
66-
revision: 7f9f0e44db287e8e67c0e888141bfa200ab45121
66+
revision: 936588e23157b56507069ad664b020881c119e54
6767
token: ${{ secrets.GITHUB_TOKEN }}
6868
- name: "Build"
6969
working-directory: ${{github.workspace}}/build

.github/workflows/windows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
pkgs: boost-date-time libnick matplotplusplus podofo rapidcsv
3131
triplet: x64-windows
3232
cache-key: windows-latest
33-
revision: 7f9f0e44db287e8e67c0e888141bfa200ab45121
33+
revision: 936588e23157b56507069ad664b020881c119e54
3434
token: ${{ secrets.GITHUB_TOKEN }}
3535
- name: "Build"
3636
working-directory: ${{github.workspace}}/build

flatpak/org.nickvision.money.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"app-id" : "org.nickvision.money",
33
"runtime" : "org.gnome.Platform",
4-
"runtime-version" : "45",
4+
"runtime-version" : "46",
55
"sdk" : "org.gnome.Sdk",
66
"command" : "org.nickvision.money",
77
"finish-args":[
@@ -89,7 +89,7 @@
8989
{
9090
"type": "git",
9191
"url": "https://gitlab.gnome.org/jwestman/blueprint-compiler",
92-
"tag": "v0.10.0"
92+
"tag": "v0.12.0"
9393
}
9494
]
9595
},

libdenaro/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ add_library(libdenaro
1818
"src/models/currency.cpp"
1919
"src/models/currencyconversion.cpp"
2020
"src/models/currencyconversionservice.cpp"
21+
"src/models/dashboardgroup.cpp"
2122
"src/models/group.cpp"
2223
"src/models/importresult.cpp"
2324
"src/models/receipt.cpp"

libdenaro/include/controllers/dashboardviewcontroller.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifndef DASHBOARDVIEWCONTROLLER_H
22
#define DASHBOARDVIEWCONTROLLER_H
33

4+
#include <memory>
5+
#include <vector>
6+
#include "accountviewcontroller.h"
7+
48
namespace Nickvision::Money::Shared::Controllers
59
{
610
/**
@@ -11,11 +15,12 @@ namespace Nickvision::Money::Shared::Controllers
1115
public:
1216
/**
1317
* @brief Construct a DashboardViewController.
18+
* @param accountViewControllers A vector of the controllers for the accounts to display on the dashboard
1419
*/
15-
DashboardViewController();
20+
DashboardViewController(const std::vector<std::shared_ptr<AccountViewController>>& accountViewControllers);
1621

1722
private:
18-
23+
std::vector<std::shared_ptr<AccountViewController>> m_accountViewControllers;
1924
};
2025
}
2126

libdenaro/include/controllers/mainwindowcontroller.h

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <libnick/taskbar/taskbaritem.h>
1919
#include <libnick/update/updater.h>
2020
#include "controllers/accountviewcontroller.h"
21+
#include "controllers/dashboardviewcontroller.h"
2122
#include "controllers/newaccountdialogcontroller.h"
2223
#include "controllers/preferencesviewcontroller.h"
2324
#include "models/accounttype.h"
@@ -99,6 +100,11 @@ namespace Nickvision::Money::Shared::Controllers
99100
* @return The NewAccountDialogController
100101
*/
101102
std::shared_ptr<NewAccountDialogController> createNewAccountDialogController() const;
103+
/**
104+
* @brief Gets a DashboardViewController.
105+
* @return The DashboardViewController
106+
*/
107+
std::shared_ptr<DashboardViewController> createDashboardViewController() const;
102108
/**
103109
* @brief Gets a AccountViewController.
104110
* @param path The path of the account
@@ -140,6 +146,11 @@ namespace Nickvision::Money::Shared::Controllers
140146
* @param path The path of the account file
141147
*/
142148
bool isAccountPasswordProtected(const std::filesystem::path& path) const;
149+
/**
150+
* @brief Gets whether or not the application has any open accounts.
151+
* @return True if there are open accounts, else false
152+
*/
153+
bool hasOpenAccounts() const;
143154
/**
144155
* @brief Creates a new account.
145156
* @brief This method will invoke the AccountAdded event if the account is successfully created.

libdenaro/include/models/currency.h

+26
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ namespace Nickvision::Money::Shared::Models
100100
* @return True if valid (check() == CurrencyCheckStatus::Valid), else false
101101
*/
102102
operator bool() const;
103+
/**
104+
* @brief Gets whether or not this currency is same as the compare currency.
105+
* @param compare The Currency to compare to
106+
* @return True if this Currency == compare Currency
107+
*/
108+
bool operator==(const Currency& compare) const;
109+
/**
110+
* @brief Gets whether or not this currency is not equal to the compare currency.
111+
* @param compare The Currency to compare to
112+
* @return True if this Currency != compare Currency
113+
*/
114+
bool operator!=(const Currency& compare) const;
103115

104116
private:
105117
std::string m_symbol;
@@ -111,4 +123,18 @@ namespace Nickvision::Money::Shared::Models
111123
};
112124
}
113125

126+
namespace std
127+
{
128+
template <>
129+
struct hash<Nickvision::Money::Shared::Models::Currency>
130+
{
131+
size_t operator()(const Nickvision::Money::Shared::Models::Currency& currency) const
132+
{
133+
size_t h1{ hash<string>()(currency.getSymbol()) };
134+
size_t h2{ hash<string>()(currency.getCode()) };
135+
return h1 ^ (h2 << 1);
136+
}
137+
};
138+
}
139+
114140
#endif //CUSTOMCURRENCY_H
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef DASHBOARDGROUP_H
2+
#define DASHBOARDGROUP_H
3+
4+
#include <string>
5+
#include <unordered_map>
6+
#include <utility>
7+
#include "currency.h"
8+
9+
namespace Nickvision::Money::Shared::Models
10+
{
11+
/**
12+
* @brief A model of a dashboard group.
13+
*/
14+
class DashboardGroup
15+
{
16+
public:
17+
/**
18+
* @brief Constructs a DashboardGroup.
19+
*/
20+
DashboardGroup();
21+
/**
22+
* @brief Gets the data of the dashboard group.
23+
* @return A map of currency and amount, description pairs
24+
*/
25+
const std::unordered_map<Currency, std::pair<double, std::string>>& getData() const;
26+
/**
27+
* @brief Adds an amount to the dashboard group.
28+
* @param amount The amount to add
29+
* @param currency The currency of the amount
30+
* @param accountName The name of the account the amount is from
31+
*/
32+
void addAmount(double amount, const Currency& currency, const std::string& accountName);
33+
34+
private:
35+
std::unordered_map<Currency, std::pair<double, std::string>> m_data;
36+
};
37+
}
38+
#endif //DASHBOARDGROUP_H

libdenaro/src/controllers/dashboardviewcontroller.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Nickvision::Money::Shared::Controllers
44
{
5-
DashboardViewController::DashboardViewController()
5+
DashboardViewController::DashboardViewController(const std::vector<std::shared_ptr<AccountViewController>>& accountViewControllers)
6+
: m_accountViewControllers{ accountViewControllers }
67
{
78

89
}

libdenaro/src/controllers/mainwindowcontroller.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ namespace Nickvision::Money::Shared::Controllers
161161
{
162162
return std::make_shared<NewAccountDialogController>();
163163
}
164+
165+
std::shared_ptr<DashboardViewController> MainWindowController::createDashboardViewController() const
166+
{
167+
std::vector<std::shared_ptr<AccountViewController>> openAccounts;
168+
for(const std::pair<const std::filesystem::path, std::shared_ptr<AccountViewController>>& pair : m_accountViewControllers)
169+
{
170+
openAccounts.push_back(pair.second);
171+
}
172+
return std::make_shared<DashboardViewController>(openAccounts);
173+
}
164174

165175
const std::shared_ptr<AccountViewController>& MainWindowController::getAccountViewController(const std::filesystem::path& path) const
166176
{
@@ -246,6 +256,11 @@ namespace Nickvision::Money::Shared::Controllers
246256
return a.isEncrypted();
247257
}
248258

259+
bool MainWindowController::hasOpenAccounts() const
260+
{
261+
return !m_accountViewControllers.empty();
262+
}
263+
249264
void MainWindowController::newAccount(const std::shared_ptr<NewAccountDialogController>& newAccountDialogController)
250265
{
251266
if(std::filesystem::exists(newAccountDialogController->getFilePath()))

libdenaro/src/models/currency.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,14 @@ namespace Nickvision::Money::Shared::Models
135135
{
136136
return validate() == CurrencyCheckStatus::Valid;
137137
}
138+
139+
bool Currency::operator==(const Currency& compare) const
140+
{
141+
return m_symbol == compare.m_symbol && m_code == compare.m_code;
142+
}
143+
144+
bool Currency::operator!=(const Currency& compare) const
145+
{
146+
return !operator==(compare);
147+
}
138148
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "models/dashboardgroup.h"
2+
#include <format>
3+
#include <libnick/localization/gettext.h>
4+
#include "helpers/currencyhelpers.h"
5+
6+
namespace Nickvision::Money::Shared::Models
7+
{
8+
DashboardGroup::DashboardGroup()
9+
{
10+
11+
}
12+
13+
const std::unordered_map<Currency, std::pair<double, std::string>>& DashboardGroup::getData() const
14+
{
15+
return m_data;
16+
}
17+
18+
void DashboardGroup::addAmount(double amount, const Currency& currency, const std::string& accountName)
19+
{
20+
if(!m_data.contains(currency))
21+
{
22+
m_data.emplace(currency, std::make_pair(amount, std::vformat(_("{} from {}"), std::make_format_args(CurrencyHelpers::toAmountString(amount, currency), accountName))));
23+
return;
24+
}
25+
m_data.at(currency).first += amount;
26+
m_data.at(currency).second += "\n" + std::vformat(_("{} from {}"), std::make_format_args(CurrencyHelpers::toAmountString(amount, currency), accountName));
27+
}
28+
}

org.nickvision.money.gnome/blueprints/main_window.blp

+51-18
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@ Adw.ApplicationWindow root {
4040
}
4141
}
4242

43-
content: Gtk.ListBox listNavItems {
44-
Gtk.ListBoxRow {
45-
child: Gtk.Box {
43+
content: Gtk.ScrolledWindow {
44+
hscrollbar-policy: never;
45+
vscrollbar-policy: automatic;
46+
47+
Gtk.ListBox listNavItems {
48+
Gtk.Box {
49+
margin-start: 6;
50+
margin-top: 12;
51+
margin-end: 6;
52+
margin-bottom: 12;
4653
orientation: horizontal;
47-
spacing: 6;
54+
spacing: 12;
4855

4956
Gtk.Image {
5057
icon-name: "user-home-symbolic";
@@ -53,13 +60,15 @@ Adw.ApplicationWindow root {
5360
Gtk.Label {
5461
label: _("Home");
5562
}
56-
};
57-
}
63+
}
5864

59-
Gtk.ListBoxRow {
60-
child: Gtk.Box {
65+
Gtk.Box {
66+
margin-start: 6;
67+
margin-top: 12;
68+
margin-end: 6;
69+
margin-bottom: 12;
6170
orientation: horizontal;
62-
spacing: 6;
71+
spacing: 12;
6372

6473
Gtk.Image {
6574
icon-name: "bank-symbolic";
@@ -68,13 +77,27 @@ Adw.ApplicationWindow root {
6877
Gtk.Label {
6978
label: _("Currency Converter");
7079
}
71-
};
72-
}
80+
}
81+
82+
Gtk.ListBoxRow {
83+
selectable: false;
84+
activatable: false;
85+
86+
Gtk.Label navAccountsLabel {
87+
halign: start;
88+
label: _("Accounts");
89+
90+
styles ["heading"]
91+
}
92+
}
7393

74-
Gtk.ListBoxRow {
75-
child: Gtk.Box {
94+
Gtk.Box {
95+
margin-start: 6;
96+
margin-top: 12;
97+
margin-end: 6;
98+
margin-bottom: 12;
7699
orientation: horizontal;
77-
spacing: 6;
100+
spacing: 12;
78101

79102
Gtk.Image {
80103
icon-name: "shell-overview-symbolic";
@@ -83,10 +106,10 @@ Adw.ApplicationWindow root {
83106
Gtk.Label {
84107
label: _("Dashboard");
85108
}
86-
};
87-
}
109+
}
88110

89-
styles ["navigation-sidebar"]
111+
styles ["navigation-sidebar"]
112+
}
90113
};
91114
};
92115
};
@@ -98,7 +121,7 @@ Adw.ApplicationWindow root {
98121
[top]
99122
Adw.HeaderBar {}
100123

101-
content: Adw.ToastOverlay ToastOverlay {
124+
content: Adw.ToastOverlay toastOverlay {
102125
child: Adw.ViewStack viewStack {
103126
Adw.ViewStackPage {
104127
name: "home";
@@ -208,6 +231,16 @@ Adw.ApplicationWindow root {
208231
};
209232
}
210233

234+
Adw.ViewStackPage {
235+
name: "noAccounts";
236+
child: Adw.StatusPage {
237+
icon-name: "wallet2-symbolic";
238+
title: _("No Accounts Open");
239+
240+
styles ["compact"]
241+
};
242+
}
243+
211244
Adw.ViewStackPage {
212245
name: "custom";
213246
child: Adw.Bin customBin {

0 commit comments

Comments
 (0)