46 #include <Wt/WAnchor.h> 47 #include <Wt/WApplication.h> 49 #include <Wt/WStackedWidget.h> 50 #include <Wt/WTable.h> 51 #include <Wt/WTemplate.h> 55 #include "ViewSummary.h" 56 #include "ViewDetail.h" 58 #define BLOG_ENTRY_URL "/blog/entry/" 60 #define ID_ROW_ITEM "Wtx.Web.BlogEntryViewSummary.RowItem" 62 :
public Wt::WContainerWidget
66 RowItem(
const Wt::Dbo::ptr<Wtx::Web::BlogEntry::Item> & item )
67 :
Wt::WContainerWidget()
75 auto tr = Wt::WString::tr(ID_ROW_ITEM);
76 if( tr.toUTF8().find(
"??") != std::string::npos )
82 " <strong><big>${title}</big></strong><br />" 84 " <small>Posted on ${date}</small><br />" 94 auto templt = addNew<Wt::WTemplate>( tr );
95 templt-> setInternalPathEncoding(
true);
97 auto url = item-> keyField.value();
99 auto link = Wt::WLink( Wt::LinkType::InternalPath, BLOG_ENTRY_URL + url );
100 auto anchor = std::make_unique<Wt::WAnchor>( link, item-> keyField.value() );
102 templt-> bindWidget<Wt::WAnchor>(
"title", std::move(anchor) );
103 templt-> bindNew<Wt::WText>(
"shortBody", item-> summary.value() );
105 templt-> setCondition(
"if-date", item-> datePosted.value() !=
"" );
106 templt-> bindNew<Wt::WText>(
"date", item-> datePosted.value() );
108 if( item-> thumbnail.value() ==
"" )
109 templt-> bindEmpty(
"thumbnail");
114 Wt::WString::tr(
"kbw.thumbnail")
115 .arg( item-> thumbnail.value() )
124 :
Wt::WContainerWidget(),
127 m_stack = addNew<Wt::WStackedWidget>();
129 auto table = m_stack-> addNew<Wt::WTable>();
131 Wt::Dbo::Transaction t(*
session());
133 session()-> find<Wtx::Web::BlogEntry::Item>()
134 .where(
"\"isActive\" = 1 AND id > 1" )
135 .orderBy(
"\"datePosted\" DESC" )
139 for(
auto blogEntry : blogEntries )
140 table-> elementAt( table-> rowCount(), 0 )->
143 std::make_unique<RowItem>(blogEntry)
147 wApp-> internalPathChanged().connect(
this, &ViewSummary::on_internalPathChanged );
148 on_internalPathChanged();
152 void Wtx::Web::BlogEntry::ViewSummary::on_internalPathChanged()
154 auto ip = wApp-> internalPath();
163 if( m_stack-> currentIndex() == 0 )
172 m_stack-> removeWidget( m_stack-> currentWidget() );
181 if( ip.find(
"/blog/entry/") != std::string::npos )
183 if( m_stack-> currentIndex() == 1 )
186 auto page = ip.substr( 12 );
188 Wt::Dbo::Transaction t(*
session());
190 session()-> find<Wtx::Web::BlogEntry::Item>()
191 .where(
"\"keyField\" = ?" )
198 m_stack-> addWidget( std::make_unique<Wt::WText>( Wt::WString(
"oh oh, I could not find the article: '{1}'").arg( page ) ) );
202 m_stack-> addWidget( std::make_unique<Wtx::Web::BlogEntry::ViewDetail>( blogEntry ) );
205 m_stack-> setCurrentIndex( 1 );
Wtx::Dbo::Session * session()
Current Session.