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