GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
BillPay/MainWidget.cpp
Go to the documentation of this file.
1#line 2 "src/Gui/BillPay/MainWidget.cpp"
2
3#include <Wt/WVBoxLayout.h>
4#include <Wt/WHBoxLayout.h>
5#include <Wt/WTable.h>
6#include <Wt/WTimer.h>
7#include <Wt/WPushButton.h>
8
9#include "BillPay.h"
10
13{
14 // identify
15 addStyleClass( "BillPay" );
16 addStyleClass( "MainWidget" );
17
19
20} // endMainWidget()
21
22auto
24buildContent()-> void
25{
26 clear();
27
28 // layout
29 m_hlw = setLayout( std::make_unique< Wt::WHBoxLayout >() );
30
31 m_summaryView = m_hlw-> addWidget( std::make_unique< SummaryWidget >() );
32 m_summaryView-> clicked().connect( this, &MainWidget::summaryClicked );
33 m_hlw-> setResizable( 0, true, Wt::WLength( 20, Wt::LengthUnit::Percentage ) );
34
35 auto cw = m_hlw-> addWidget( std::make_unique< Wt::WContainerWidget >() );
36
37 // toolbar
38 {
39 m_toolBar = cw-> addWidget( std::make_unique< ToolBar >() );
40 toolBar()-> yearSelector () -> activated () .connect( this, &MainWidget:: do_yearChanged );
41 toolBar()-> refreshButton () -> clicked () .connect( this, &MainWidget:: do_refreshClicked );
42 toolBar()-> addButton () -> clicked () .connect( this, &MainWidget:: do_addClicked );
43 toolBar()-> editButton () -> clicked () .connect( this, &MainWidget:: do_editClicked );
44 toolBar()-> inactiveButton () -> clicked () .connect( this, &MainWidget:: do_inactiveClicked );
45 toolBar()-> summaryButton () -> clicked () .connect( this, &MainWidget:: do_summaryClicked );
46 toolBar()-> summaryDetailButton () -> clicked () .connect( this, &MainWidget:: do_refreshClicked );
47#ifdef BILL_PAY_IMPORT_EXPORT
48 toolBar()-> importButton () -> clicked () .connect( this, &MainWidget:: importClicked );
49 toolBar()-> exportButton () -> clicked () .connect( this, &MainWidget:: exportClicked );
50#endif
51 toolBar()-> finderInput () -> textInput () .connect( this, &MainWidget:: finderInput );
52
53 } // toolbar
54
55 // recall selected month
56 m_selectedMonth = recallSelectedMonth();
57
58 // unpaid items
59 {
60 m_unpaidView = cw-> addWidget( std::make_unique< TableView >( selectedMonth(), selectedYear(), Status::Unpaid ) );
61 m_unpaidView->
62 clicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
63 {
64 /*
65 ** remember the clicked index
66 */
67 m_selectedIndex = _index;
68 clearSelectionExcept( m_unpaidView );
69 });
70 m_unpaidView->
71 doubleClicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
72 {
73 clearSelectionExcept( m_unpaidView );
74 editClicked( m_unpaidView, _index );
75 });
76
77 /*
78 ** unpaid items has a header, whereas the other two item-tables do not have a
79 ** header and clicking on the header changes the selected month
80 */
81 m_unpaidView->
82 headerClicked().connect( this, &MainWidget::on_headerClicked );
83
84 } // endunpaid items
85
86 // pending items
87 {
88 m_pendingView = cw-> addWidget( std::make_unique< TableView >( selectedMonth(), selectedYear(), Status::Pending ) );
89 m_pendingView->
90 clicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
91 {
92 /*
93 ** remember the clicked index
94 */
95 m_selectedIndex = _index;
96 clearSelectionExcept( m_pendingView );
97 });
98 m_pendingView->
99 doubleClicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
100 {
101 clearSelectionExcept( m_pendingView );
102 editClicked( m_pendingView, _index );
103 });
104
105 } // endpending items
106
107 // paid items
108 {
109 m_paidView = cw-> addWidget( std::make_unique< TableView >( selectedMonth(), selectedYear(), Status::Paid ) );
110 m_paidView->
111 clicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
112 {
113 /*
114 ** remember the clicked index
115 */
116 m_selectedIndex = _index;
117 clearSelectionExcept( m_paidView );
118 });
119 m_paidView->
120 doubleClicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
121 {
122 clearSelectionExcept( m_paidView );
123 editClicked( m_paidView, _index );
124 });
125
126 } // endpaid items
127
128 // inactive items
129 {
130 m_inactiveView = cw-> addWidget( std::make_unique< TableView >( selectedMonth(), selectedYear(), Status::Inactive ) );
131 m_inactiveView->
132 clicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
133 {
134 /*
135 ** remember the clicked index
136 */
137 m_selectedIndex = _index;
138 clearSelectionExcept( m_inactiveView );
139 });
140 m_inactiveView->
141 doubleClicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
142 {
143 clearSelectionExcept( m_inactiveView );
144 editClicked( m_inactiveView, _index );
145 });
146
147 } // endinactive items
148
149 do_summaryClicked();
150
151 refreshViews();
152
153} // endbuildContent()-> void
154
155
156auto
158finderInput()-> void
159{
160 /*
161 ** apply the filter to all the views
162 */
163 if( m_unpaidView ) m_unpaidView -> setFilter( toolBar()-> finderText() );
164 if( m_pendingView ) m_pendingView -> setFilter( toolBar()-> finderText() );
165 if( m_paidView ) m_paidView -> setFilter( toolBar()-> finderText() );
166 if( m_inactiveView ) m_inactiveView -> setFilter( toolBar()-> finderText() );
167
168} // endfinderInput()-> void
169
170auto
172summaryClicked( const std::string & _itemIdent )-> void
173{
174 /*
175 ** select the item based on what was selected in the summary view
176 */
177 m_unpaidView -> selectItem( _itemIdent );
178 m_pendingView -> selectItem( _itemIdent );
179 m_paidView -> selectItem( _itemIdent );
180 m_inactiveView -> selectItem( _itemIdent );
181
182} // endsummaryClicked( const std::string & _txGuid )-> void
183
184
185auto
187clearSelectionExcept( TableView * _view )-> void
188{
189 /*
190 ** clear all selections except the table that's being selected
191 */
192 if( _view != m_unpaidView ) m_unpaidView -> clearSelection();
193 if( _view != m_pendingView ) m_pendingView -> clearSelection();
194 if( _view != m_paidView ) m_paidView -> clearSelection();
195 if( _view != m_inactiveView ) m_inactiveView -> clearSelection();
196
197 wApp-> processEvents();
198
199} // endclearSelectionExcept( TableView * )-> void
200
201
202auto
204openEditor( const std::string & _bpGuid )-> void
205{
206
207 /*
208 ** if the edit widget is open, then we can't do anything.
209 */
210 if( m_editWidget )
211 return;
212
213 /*
214 ** Split the page to open/edit this item
215 **
216 */
217 auto u_ = std::make_unique< GCW::Gui::BillPay::EditWidget >( _bpGuid );
218 m_editWidget = u_.get();
219// m_gridLayout-> addWidget( std::move( u_), 1, 1 );
220// m_gridLayout-> setColumnResizable( 0, true, "30%" );
221
222 m_hlw-> addWidget( std::move( u_ ) );
223 m_hlw-> setResizable( 1, true, Wt::WLength( 20, Wt::LengthUnit::Percentage ) );
224
225 m_editWidget->
226 deleted().connect( [=]()
227 {
228 Wt::WMessageBox::show( TR("gcw.billPay.lbl.billPay"), TR("gcw.not-yet-implemented"), Wt::StandardButton::Ok );
229 });
230
231 m_editWidget->
232 saved().connect( [=]()
233 {
234 refreshViews();
235 m_hlw-> removeWidget( m_editWidget.get() );
236 m_hlw-> setResizable( 1, true, Wt::WLength::Auto );
237 });
238
239 m_editWidget->
240 canceled().connect( [=]()
241 {
242 m_hlw-> removeWidget( m_editWidget.get() );
243 m_hlw-> setResizable( 1, true, Wt::WLength::Auto );
244 });
245
246} // endopenEditor( const std::string & _nickname )-> void
247
248auto
250do_yearChanged()-> void
251{
252 refreshViews();
253
254} // enddo_addClicked()-> void
255
256auto
258do_refreshClicked()-> void
259{
260 refreshClicked();
261
262} // enddo_addClicked()-> void
263
264auto
266do_addClicked()-> void
267{
268 addClicked();
269
270} // enddo_addClicked()-> void
271
272auto
274do_editClicked()-> void
275{
276 if( !m_selectedIndex.isValid() )
277 return;
278
279 auto zcolIndex = m_selectedIndex.model()-> index( m_selectedIndex.row(), 0 );
280 auto bpGuid = Wt::asString( zcolIndex.data( Wt::ItemDataRole::User ) ).toUTF8();
281 openEditor( bpGuid );
282
283} // enddo_editClicked()-> void
284
285auto
287refreshClicked()-> void
288{
289 setMonth( recallSelectedMonth() );
290
291} // endaddClicked()-> void
292
293auto
295addClicked()-> void
296{
297 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
298 openEditor( "" );
299
300} // endaddClicked()-> void
301
302auto
304editClicked( TableView * _table, Wt::WModelIndex _index )-> void
305{
306 /*
307 ** remember the index
308 */
309 m_selectedIndex = _index;
310
311 /*
312 ** Get the 0-col index and use that to get the guid of this
313 ** row, and use that to get the Edit dialog open on that
314 ** guid.
315 */
316 if( _index.isValid() )
317 {
318 auto zcolIndex = _index.model()-> index( _index.row(), 0 );
319 auto bpGuid = Wt::asString( zcolIndex.data( Wt::ItemDataRole::User ) ).toUTF8();
320 openEditor( bpGuid );
321 }
322
323} // endeditClicked( TableView * _table, Wt::WModelIndex _index )-> void
324
325auto
327do_inactiveClicked()-> void
328{
329 if( toolBar()-> showInactive() )
330 inactiveView()-> setHidden( false );
331 else
332 inactiveView()-> setHidden( true );
333
334} // endinactiveClicked()-> void
335
336auto
338do_summaryClicked()-> void
339{
340 if( toolBar()-> showSummary() )
341 summaryView()-> setHidden( false );
342 else
343 summaryView()-> setHidden( true );
344
345} // enddo_summaryClicked()-> void
346
347auto
349recallSelectedMonth() const-> int
350{
351 auto selectedMonth = configItem()-> getVarInt( "selectedMonth" );
352
353 if( selectedMonth < 1
354 || selectedMonth > 12 )
355 selectedMonth = 1;
356
357 return selectedMonth;
358
359} // endrecallSelectedMonth() const-> int
360
361auto
363setMonth( int _month )-> void
364{
365 m_selectedMonth = _month;
366
367 auto _setDate = [&]( auto _view )
368 {
369 if( _view ) _view-> setDate( _month, selectedYear() );
370 };
371
372 m_summaryView-> showSummaryDetail( toolBar()-> showSummaryDetail() );
373
374 _setDate( m_unpaidView );
375 _setDate( m_pendingView );
376 _setDate( m_paidView );
377 _setDate( m_inactiveView );
378 _setDate( m_summaryView );
379
380 if( m_pendingView-> rowCount() > 0 )
381 m_pendingView-> setHidden( false );
382 else
383 m_pendingView-> setHidden( true );
384
385 if( m_paidView-> rowCount() > 0 )
386 m_paidView-> setHidden( false );
387 else
388 m_paidView-> setHidden( true );
389
390 /*
391 ** BUGBUG: not sure why i tested all of this just to make the same call... weird!
392 */
393// if( m_inactiveView-> rowCount() > 0 )
394// do_inactiveClicked();
395// else
396 do_inactiveClicked();
397
398 /*
399 ** in the words of Spock; "remember"
400 */
401 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
402 configItem().modify()-> setVar( "selectedMonth", m_selectedMonth );
403
404} // endsetMonth( int _month )-> void
405
406auto
408selectedYear()-> int
409{
410 return
411 toolBar()-> selectedYear();
412
413} // endselectedYear()-> int
414
415auto
417refreshViews()-> void
418{
419 setMonth( m_selectedMonth );
420
421} // endrefreshViews()-> void
422
423auto
425importClicked()-> void
426{
427 std::cout << __FILE__ << ":" << __LINE__ << " " << std::endl;
428
429} // endimportClicked()-> void
430
431auto
433exportClicked()-> void
434{
435 std::cout << __FILE__ << ":" << __LINE__ << " " << std::endl;
436
437} // endexportClicked()-> void
438
439auto
441on_headerClicked( int _col, const Wt::WMouseEvent _me )-> void
442{
443 if( _col >= 9 )
444 setMonth( _col - 8 );
445
446} // endon_headerClicked( int _col, const Wt::WMouseEvent _me )-> void
447
448
auto summaryClicked(const std::string &_txGuid) -> void
auto openEditor(const std::string &_bpGuid) -> void
auto editClicked(TableView *_table, Wt::WModelIndex _index) -> void
auto clearSelectionExcept(TableView *=nullptr) -> void
auto setMonth(int _month) -> void
auto on_headerClicked(int _col, const Wt::WMouseEvent _me) -> void
Header Clicked.
static constexpr const int User
static WLength Auto
std::string toUTF8() const
virtual void addStyleClass(const WString &styleClass, bool force=false) override
#define TR(X)
Definition define.h:17
WString asString(const cpp17::any &v, const WString &formatString=WString())
@ Pending
Pending Status.
@ Inactive
Disabled Status.
@ Unpaid
Unpaid Status.
auto configItem() -> GCW::Dbo::Vars::Item::Ptr
Config Item.
Definition BillPay.cpp:7
App * app()
Definition App.cpp:75