1 #line 2 "src/Gui/AccountsTreeView.cpp"
4 #define EDIT_FORM_AS_SPLIT_PAGE
9 #include <Wt/Json/Array.h>
10 #include <Wt/Json/Parser.h>
11 #include <Wt/Json/Serializer.h>
13 #include <Wt/WTreeTableNode.h>
14 #include <Wt/WMessageBox.h>
16 #include "../define.h"
21 AccountsTreeView(
const std::string & _selectedAccountGuid,
int _columnCount )
22 : m_columnCount( _columnCount )
32 : m_columnCount( _columnCount )
42 addStyleClass(
"AccountsTreeView" );
44 m_gridLayout = setLayout( std::make_unique< Wt::WGridLayout >() );
47 auto w = std::make_unique< Wt::WTreeView >();
49 m_gridLayout-> addWidget( std::move( w ), 0, 0 );
51 view()-> setSelectionBehavior( Wt::SelectionBehavior::Rows );
52 view()-> setSelectionMode( Wt::SelectionMode::Single );
53 view()-> setAlternatingRowColors(
true );
55 view()-> setAttributeValue(
"oncontextmenu",
"event.cancelBubble=true;event.returnValue=false;return false;" );
58 std::vector< std::string > cols =
90 for(
int i=0; i< m_columnCount; i++ )
91 m_columns.push_back(
TR8(
"gcw.AccountsTreeView.column." + cols.at(i) ) );
107 if( _event.button() == Wt::MouseButton::Right )
109 std::cout << __FILE__ <<
":" << __LINE__ <<
" right-click pop-up menu" << std::endl;
116 while( m_popup.count() )
117 m_popup.removeItem( m_popup.itemAt(0) );
119 m_popup.addItem(
"icons/folder_new.gif",
"Create a New Folder",
this, &WEB::FolderTableView::on_pbAddFolder_triggered );
120 m_popup.addItem(
"Rename",
this, &WEB::FolderTableView::on_pbRenameItem_triggered );
122 std::string fileName =
Wt::asString(m_tableView.model()-> data( index.row(), 0 )).toUTF8();
125 if( isFolder(fileName) )
126 m_popup.addItem(
"Delete this Folder",
this, &WEB::FolderTableView::on_pbDeleteItem_triggered );
128 m_popup.addItem(
"Delete this File",
this, &WEB::FolderTableView::on_pbDeleteItem_triggered );
130 m_popup.addSeparator();
131 m_popup.addItem(
"Upload a file",
this, &WEB::FolderTableView::on_pbUploadFile_triggered );
132 m_popup.addItem(
"Refresh",
this, &WEB::FolderTableView::refresh );
133 m_popup.addSeparator();
134 m_popup.addItem(
"Properties",
this, &WEB::FolderTableView::on_pbProperties_triggered );
137 if( !m_tableView.isSelected(index) )
139 m_tableView.clearSelection();
140 m_tableView.select(index);
143 if( m_popup.isHidden() )
145 m_popup.popup(event);
174 auto selected = view()-> selectedIndexes();
175 if( selected.size() == 1 )
179 model()-> data( *selected.begin(),
180 Wt::ItemDataRole::User
192 if( _accountGuid ==
"" )
195 #ifdef EDIT_FORM_AS_POPUP_DIALOG
200 #ifdef EDIT_FORM_AS_SPLIT_PAGE
206 if( m_editAccountWidget )
210 Wt::WMessageBox::show(
"AccountsTree",
"Please close the account you are editing", Wt::StandardButton::Ok );
218 auto u_ = std::make_unique< GCW::Gui::AccountEditor >( _accountGuid );
219 m_editAccountWidget = u_.get();
220 m_gridLayout-> addWidget( std::move( u_), 0, 1 );
221 m_gridLayout-> setColumnResizable( 0,
true,
"25%" );
223 m_editAccountWidget->
224 save().connect( [=]()
227 m_gridLayout-> removeWidget( m_editAccountWidget );
228 m_editAccountWidget =
nullptr;
231 m_editAccountWidget->
232 cancel().connect( [=]()
235 m_gridLayout-> removeWidget( m_editAccountWidget );
236 m_editAccountWidget =
nullptr;
248 editAccount( selectedAccount() );
257 m_model = std::make_shared< Model >();
259 m_model->
load( m_columnCount );
261 view()-> setModel( m_model );
263 view()-> sortByColumn( 0, Wt::SortOrder::Ascending );
273 if(
GCW::app()-> gnucashew_session().hasGnuCashewExtensions() )
275 Wt::Dbo::Transaction t(
GCW::app()-> gnucashew_session() );
289 if( !
GCW::app()-> gnucashew_session().hasGnuCashewExtensions() )
292 Wt::Dbo::Transaction t(
GCW::app()-> gnucashew_session() );
301 if( !
GCW::app()-> gnucashew_session().hasGnuCashewExtensions() )
304 Wt::Json::Object jobj;
308 catch( std::exception & e )
325 iterate( Wt::Json::Array & _jary, Wt::WModelIndex _parent )
const
331 if( !view()-> isExpanded( _parent ) )
339 bool expanded =
false;
340 for(
int row=0; row< view()-> model()-> rowCount( _parent ); row++ )
341 expanded |=
iterate( _jary, view()-> model()-> index( row, 0, _parent ) );
357 auto accountGuid =
Wt::asString( _parent.data( Wt::ItemDataRole::User ) );
358 if( accountGuid !=
"" )
359 _jary.push_back( accountGuid );
378 Wt::Json::Object jobj;
380 jobj[
"selected"] = Wt::WString( selectedAccount() );
382 for(
int col=0; col< 7; col++ )
383 jobj[ Wt::WString(
"cw{1}").arg( col ).toUTF8() ] = Wt::WString( view()-> columnWidth( col ).cssText() );
385 Wt::Json::Array jary;
387 jobj[
"expanded"] = jary;
395 expandNode(
const std::string & _accountGuid, Wt::WModelIndex _parent )
404 for(
int row=0; row< view()-> model()-> rowCount( _parent ); row++ )
409 auto child = view()-> model()-> index( row, 0, _parent );
414 auto nodeGuid =
Wt::asString( child.data( Wt::ItemDataRole::User ) ).toUTF8();
421 if( nodeGuid == _accountGuid )
423 view()-> expand( child );
431 retVal |= expandNode( _accountGuid, child );
442 view()-> expand( _parent );
456 auto jary = _jobj.get(
"expanded").orIfNull( Wt::Json::Array() );
458 for(
auto value : jary )
459 expandNode( value.orIfNull(
"" ) );
474 findIndex(
const std::string & _accountGuid, Wt::WModelIndex _parentIndex )
480 if(
Wt::asString( _parentIndex.data( Wt::ItemDataRole::User ) ) == _accountGuid )
488 for(
int row=0; row< view()-> model()-> rowCount( _parentIndex ); row++ )
490 auto childIndex = findIndex( _accountGuid, view()-> model()-> index( row, 0, _parentIndex ) );
497 if( childIndex.isValid() )
506 return Wt::WModelIndex();
514 auto index = findIndex( _accountGuid );
516 view()-> select ( index );
517 view()-> scrollTo ( index, Wt::ScrollHint::PositionAtCenter );
525 fromJson( Wt::Json::Object & _jobj )
527 expandTreeNodes( _jobj );
529 setSelected( _jobj.get(
"selected").orIfNull( std::string() ) );
539 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << std::endl;
541 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << Wt::Json::serialize(
toJson() ) << std::endl;
548 on_doubleClicked(
const Wt::WModelIndex & index,
const Wt::WMouseEvent & event )
551 std::cout << std::endl << std::endl << __FILE__ <<
":" << __LINE__
552 <<
" " <<
"on_doubleClicked:"
553 <<
" " << index.row()
554 <<
" " <<
Wt::asString( m_model-> data( index, Wt::ItemDataRole::User ) )
555 << std::endl << std::endl
563 m_doubleClicked.emit(
Wt::asString( m_model-> data( index, Wt::ItemDataRole::User ) ).toUTF8() );
static bool iterate(Wt::Json::Array &_jary, Wt::WModelIndex _parent)
AccountsTreeView(int _columnCount)
auto toJson() const -> Wt::Json::Object
auto on_doubleClicked(const Wt::WModelIndex &index, const Wt::WMouseEvent &event) -> void
auto expandNode(const std::string &_accountGuid, Wt::WModelIndex _parent=Wt::WModelIndex()) -> bool
auto configItem() -> GCW::Dbo::Vars::Item::Ptr
Config Item.
auto expandTreeNodes(Wt::Json::Object &_jobj) -> bool
auto findIndex(const std::string &_accountGuid, Wt::WModelIndex _parentIndex=Wt::WModelIndex()) -> Wt::WModelIndex
Find Index by AccountGuid.
auto loadConfig() -> void
auto on_showPopup_triggered(const Wt::WModelIndex &_index, const Wt::WMouseEvent &_event) -> void
auto iterate(Wt::Json::Array &_jary, Wt::WModelIndex _parent=Wt::WModelIndex()) const -> bool
auto fromJson(Wt::Json::Object &_jobj) -> bool
auto setSelected(const std::string &_accountGuid) -> bool
auto selectedAccount() const -> std::string
auto editSelectedAccount() -> void
auto saveConfig() -> void
auto editAccount(const std::string &_accountGuid) -> void
Wt::Json::Object toJson(Wt::WTreeView *_view)
auto load(const std::string &_guid) -> Item::Ptr
Load Account by GUID.
Wt::WFormModel::Field varField
GCW::Dbo::Vars::Item::Ptr get(const std::string &_keyValue, const std::string &_cfyValue="*", bool _add=true)
std::string asString(Status _status)
Get Status as String.
auto configItem() -> GCW::Dbo::Vars::Item::Ptr
Config Item.