45 #include <Wt/WLineEdit.h> 46 #include <Wt/WDialog.h> 47 #include <Wt/WTemplate.h> 48 #include <Wt/WItemDelegate.h> 49 #include <Wt/WPushButton.h> 50 #include <Wt/WPopupMenu.h> 51 #include <Wt/Dbo/Json.h> 53 #include <Wtx/Core/Core.h> 68 << std::string(
session()->
template tableName<C>())
71 if( !viewDef().load( std::string(
session()->
template tableName<C>()),
session() ) )
73 viewDef().load( C::TableDef(),
session() );
85 << layoutName(tableDefName)
88 if( !loadLayout( layoutName(tableDefName) ) )
90 viewDef().load( C::TableDef(),
session() );
91 viewDef().save( layoutName(tableDefName),
session() );
102 viewDef().load( vd, s );
114 << layoutName(tableDefName)
117 if( !loadLayout( layoutName(tableDefName) ) )
119 viewDef().load( vd,
session() );
120 viewDef().save( layoutName(tableDefName),
session() );
138 model()-> setSession(
session() );
139 model()-> m_countTable = C::TableDef().tableName();
140 model()-> setViewDef( &viewDef() );
145 viewDef().changed().connect( std::bind( [=]()
158 Wt::WString(
"viewDef.{1}.{2}")
159 .arg( C::TableDef().tableName() )
169 if( event.button() == Wt::MouseButton::Right )
171 Wt::WPopupMenu* pItemPopup =
new Wt::WPopupMenu();
173 pItemPopup-> addItem( Wt::WString(
"Layout..." ) )->
174 triggered().connect( std::bind( [
this](){ viewDef().
editProperties(); } ) );
176 pItemPopup-> addItem( Wt::WString(
"Save Layout" ) )->
177 triggered().connect( std::bind( [
this]()
180 for(
auto columnDef : viewDef().m_def.columnDefs )
182 viewDef().m_def.columnDefs[col].width = columnWidth( col );
186 if( viewDef().m_name ==
"" )
188 auto dialog =
new Wt::WDialog(
"Save View Layout");
189 dialog-> rejectWhenEscapePressed();
191 dialog-> contents()-> addNew<Wt::WTemplate>
194 " Please enter a name for this view" 196 "<div>${lineEdit}</div>" 198 " ${ok class=\"btn-success btn-xs\"}" 199 " ${cancel class=\"btn-danger btn-xs\"}" 204 templt-> bindNew<Wt::WLineEdit>(
"lineEdit");
206 templt-> bindNew<Wt::WPushButton>(
"ok",
"ok")->
207 clicked().connect( dialog, &Wt::WDialog::accept );
209 templt-> bindNew<Wt::WPushButton>(
"cancel",
"cancel")->
210 clicked().connect( dialog, &Wt::WDialog::reject );
212 dialog-> finished().connect( [=]()
214 if( dialog-> result() != Wt::DialogCode::Accepted )
217 if( lineEdit-> text() ==
"" )
220 viewDef().save( lineEdit-> text().toUTF8(),
session() );
227 viewDef().save( viewDef().m_name,
session() );
232 pItemPopup-> popup( event );
240 return viewDef().load( layoutName(name), C::TableDef(),
session() );
247 viewDef().save( layoutName(name),
session() );
253 return m_filterValue;
259 Wt::Dbo::Transaction t(*
session());
261 auto where = m_filterValue;
262 if( m_subFilterValue !=
"" )
269 where += m_subFilterValue;
277 model()-> setCountWhere(
"WHERE " + where );
279 m_queryRowCount = query.resultList().size();
281 for(
auto sortField : viewDef().m_def.sortFields )
283 query = query.orderBy( sortField );
286 model()-> setQuery( query,
true );
297 viewDef().m_def.filter = f;
307 std::cout << __FILE__ <<
":" << __LINE__ <<
" todo setSearch:" << s << std::endl;
314 m_subFilterValue = f;
331 std::string search = s;
333 qry = viewDef().m_def.filter;
352 std::size_t start_pos = 0;
353 while( (start_pos = search.find(
"'",start_pos)) != std::string::npos )
355 search.replace( start_pos,
size_t(1), std::string(
"''") );
379 qry =
"\n (" + qry +
") AND ";
389 int id = std::stoi(search);
392 Wt::WString(
"(id = {1}) OR " )
402 auto searches = Wtx::Core::split( search,
' ' );
406 for(
auto s : searches )
423 Wt::WString(
"\n (UPPER(\"keyField\") LIKE UPPER('%{1}%'))" )
436 Wt::WString(
"\n OR (UPPER(\"cfyField\") LIKE UPPER('%{1}%'))" )
449 Wt::WString(
"\n OR (UPPER(\"tag\") LIKE UPPER('%{1}%'))" )
462 Wt::WString(
"\n OR (\"xid\" LIKE '%{1}%')" )
472 for(
auto searchField : viewDef().m_def.searchFields )
475 Wt::WString(
"\n OR (UPPER(\"{1}\") LIKE UPPER('%{2}%'))" )
490 if( viewDef().m_def.idin.size() > 0 )
492 if( viewDef().m_def.idin.at(0).find(
"id in") != std::string::npos )
495 Wt::WString( viewDef().m_def.idin.at(0) )
501 Wt::WString(
" OR ({1}) ")
508 auto idin = Wtx::Core::split( viewDef().m_def.idin.at(0),
'_' );
510 if( idin.size() == 3 )
513 Wt::WString(
" OR \"{1}\" IN ")
514 .arg( viewDef().m_def.idin.at(0) )
519 Wt::WString(
"(UPPER(\"keyField\") LIKE UPPER('%{1}%'))" )
527 Wt::WString(
"(UPPER(\"cfyField\") LIKE UPPER('%{1}%'))" )
533 Wt::WString(
"(SELECT id FROM \"{1}\" WHERE ({2}))" )
558 qry =
" WHERE (" + qry +
")";
564 if( viewDef().hasFlag(
"show-sql" ) )
565 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << qry << std::endl;
567 Wt::Dbo::Transaction t(*session());
570 session()->
template find<C>(qry)
573 model()-> setCountWhere( qry );
575 m_queryRowCount = query.resultList().size();
577 for(
auto sortField : viewDef().m_def.sortFields )
579 query = query.orderBy( sortField );
582 model()-> setQuery( query,
true );
594 auto row = model()-> indexOf( item );
596 auto index = model()-> index( row, 0 );
606 setRowHeaderCount( viewDef().m_def.rowHeaderCount );
608 if( viewDef().m_def.columnDefs.size() == 0 )
610 model()-> addAllFieldsAsColumns();
618 for(
auto columnDef : viewDef().m_def.columnDefs )
620 model()-> addColumn( columnDef.field );
622 if( columnDef.label !=
"" )
623 model()-> setHeaderData( c, Wt::Orientation::Horizontal, columnDef.label, Wt::ItemDataRole::Display );
625 if( columnDef.toolTip !=
"" )
626 model()-> setHeaderData( c, Wt::Orientation::Horizontal, columnDef.toolTip, Wt::ItemDataRole::ToolTip );
628 if( columnDef.delegate )
629 setItemDelegateForColumn( c, std::shared_ptr<Wt::WItemDelegate>( columnDef.delegate( session() ) ) );
631 setColumnAlignment( c, columnDef.alignment );
644 setAlternatingRowColors( viewDef().m_def.alternatingRowColors );
646 setSelectionMode( viewDef().m_def.selectionMode );
648 if( std::find( viewDef().m_def.flags.begin(), viewDef().m_def.flags.end(),
"nosort" ) != viewDef().m_def.flags.end() )
649 setSortingEnabled(
false );
652 for(
auto columnDef : viewDef().m_def.columnDefs )
653 setColumnWidth( col++, columnDef.width );
668 auto selectedIndex = *(selectedIndexes().begin());
670 auto indexBeg = model()-> index( selectedIndex.row(), 0 );
671 auto indexEnd = model()-> index( selectedIndex.row(), model()-> columnCount()-1 );
673 model()-> dataChanged().emit( indexBeg, indexEnd );
675 select( selectedIndex );
676 scrollTo( selectedIndex );
683 return item( *(selectedIndexes().begin()) );
void setQuery(const std::string &search="")
Wtx::Dbo::Session * session()
Current Session.