13 #include <boost/filesystem.hpp>
22 #include <Wt/WDateTime>
23 #include <Wt/WStandardItemModel>
25 #include <gdcore/gdCore.h>
27 #include <gdwtcore/gdWTextDelegate.h>
33 #include <WsModule/WsModule.h>
38 #define WSMODLATESTNEWS "wsmodlatestnews"
39 #define NB_NEWS "nb_news"
46 : WContainerWidget(parent), m_pTableView(0)
48 addStyleClass(
"WsLatestNews2");
56 WContainerWidget::load();
58 WText* pTitle =
new WText(asString(
option(
"title")).toUTF8());
59 pTitle->addStyleClass(
"WsTitle");
63 if ( asString(
option(
"useReadAll")) ==
"true" ) {
64 std::string link = asString(
option(
"link")).toUTF8();
65 boost::replace_all(link,
"&",
"&");
66 std::string text = asString(
option(
"text")).toUTF8();
67 WAnchor* pAnchor =
new WAnchor(WLink(WLink::InternalPath, link), text);
68 pAnchor->addStyleClass(
"WsReadAll");
77 std::string sWithoutPrefix =
WsApp->WsModules().pathWithoutPrefix(path);
78 std::string rootPath = asString(
option(
"rootPath")).narrow();
79 boost::algorithm::replace_all(rootPath,
"&",
"&");
82 if (rootPath.size() == 0)
87 root = root.get()->eatPath(rootPath);
89 if (root.get() == 0) {
90 LOG(
DEBUG) <<
"WsLatestNews2::setTable cannot get root ! root = " << root <<
" rootPath " << rootPath;
96 int rowsCount = asNumber(
option(
"rowsCount"));
97 if ( rowsCount > 0 ) nbl = rowsCount;
99 WStandardItemModel* m_pModelView =
new WStandardItemModel(0, 4,
this);
101 m_pModelView->setHeaderData(0, WString::tr(
"WsModLatestNews2-Name"));
102 m_pModelView->setHeaderData(1, WString::tr(
"WsModLatestNews2-Desc"));
103 m_pModelView->setHeaderData(2, WString::tr(
"WsModLatestNews2-Size"));
104 m_pModelView->setHeaderData(3, WString::tr(
"WsModLatestNews2-Date"));
105 m_pModelView->setSortRole(UserRole);
106 for (
int i = 0; i < news.size(); ++i) {
108 news[i].
get()->getPath().extension().
string() ==
".fhtml" ||
109 news[i].
get()->getPath().extension().
string() ==
".pdf" ||
110 news[i].
get()->getPath().extension().
string() ==
".rpg" ||
111 news[i].
get()->getPath().extension().
string() ==
".zip"
114 if ( news[i].
get()->getProperties().get()->get(
"global",
"in_view",
"true") ==
"false" )
continue;
115 boost::filesystem::path wsRes = news[i].get()->getPath();
117 while (wsRes.string() !=
"/") {
118 wsRes = wsRes.parent_path();
119 if ( wsRes.filename().string() ==
"ws.res" ) {
123 if ( wsRes.filename().string() ==
"ws" ) {
129 if ( bRes )
continue;
130 std::vector<WStandardItem*> pRow;
132 dateTime.setTime_t(boost::lexical_cast<time_t>(dynamic_cast<WsFileNode*>(news[i].
get())->getPublishDate()));
133 std::string sName = news[i].get()->getName();
134 std::string sPath = news[i].get()->getPath().string();
135 WStandardItem* nameItem =
new WStandardItem(sName);
136 nameItem->setData(sPath, UserRole);
137 pRow.push_back(nameItem);
139 sDesc +=
"<p class='ls2Date'>";
140 sDesc += dateTime.toString(
"yyyy-MM-dd").toUTF8();
142 if ( asString(
option(
"useDisplayName")) ==
"true" ) {
143 std::string dispName = news[i].get()->getDisplayName(
true);
144 boost::algorithm::replace_all(dispName,
"&",
"&");
145 sDesc +=
"<p>" + dispName +
"</p>";
147 sDesc += news[i].get()->getProperties().get()->get(
"global",
"short_description",
"");
148 WStandardItem* descItem =
new WStandardItem(sDesc);
152 descItem->setData(sDesc, UserRole);
153 pRow.push_back(descItem);
154 std::stringstream sstr;
155 sstr << news[i].get()->getSize();
156 std::string sSize(sstr.str());
158 WStandardItem* sizeItem =
new WStandardItem(sSize);
159 long lSize = news[i].get()->getSize();
160 sizeItem->setData(sSize, UserRole);
161 pRow.push_back(sizeItem);
162 WStandardItem* dateItem =
new WStandardItem(dateTime.toString(
"yyyy-MM-dd : hh-mm-ss"));
163 dateItem->setData(dateTime, UserRole);
164 pRow.push_back(dateItem);
165 m_pModelView->invisibleRootItem()->appendRow(pRow);
167 m_pModelView->sort(3, Wt::DescendingOrder);
176 long rowHeight = asNumber(
option(
"rowHeight"));
181 std::string hideHeader = asString(
option(
"hideHeader")).narrow();
182 if ( hideHeader ==
"true" )
184 std::string columnsWidth = asString(
option(
"columnsWidth")).narrow();
185 if ( columnsWidth.size() < 1 ) {
189 std::vector<std::string> sVectColumnsWidth;
190 gd_core_string2vector(sVectColumnsWidth, columnsWidth.c_str(),
",");
191 for (
int iCol = 0; iCol < sVectColumnsWidth.size(); ++iCol) {
192 double width = asNumber(sVectColumnsWidth[iCol]);
197 std::string columnsToHide = asString(
option(
"hideColumns")).narrow();
198 std::vector<std::string> sVectColumns;
199 gd_core_string2vector(sVectColumns, columnsToHide.c_str(),
",");
200 for (
int iCol = 0; iCol < sVectColumns.size(); ++iCol) {
201 int col = asNumber(sVectColumns[iCol]);
204 gdWTextDelegate* delegate2 =
new gdWTextDelegate(
this);
205 delegate2->setRowHeight(
m_pTableView->rowHeight().value());
213 WModelIndexSet::iterator it = pSet.begin();
214 if ( pSet.empty() )
return;
215 WModelIndex idx = *it;
216 std::string str = asString(idx.data(UserRole)).toUTF8();
217 wApp->setInternalPath(str,
true);
boost::shared_ptr< WsAbstractNode > NodePtr
std::string getProperty(const std::string &path, const std::string §ion, const string &attr, const std::string &def)
returns one property of a node If the property does not exist, a empty string is returned.
vector< NodePtr > getLatestNews(int nb)
static WsApplication * wsInstance()
Facility function to access the application object.
Interface that provides differents methods for accessing the FsTree as well as other features...
void onViewSelectionChanged()
WsLatestNews2(Wt::WContainerWidget *parent=0)
const boost::any & option(const std::string &attribute) const
Get an options value.
std::string get(const std::string §ion, const std::string &id, const std::string &def)
Wt::WTableView * m_pTableView
#define WsApp
Define a shortcut to the application instance.
static WsGlobalProperties * instance()
NodePtr getAccessRoot()
return the root node of the access tree starting from the root