8#include <Wt/WApplication.h>
9#include <Wt/WComboBox.h>
10#include <Wt/WContainerWidget.h>
11#include <Wt/WDatePicker.h>
12#include <Wt/WDateValidator.h>
13#include <Wt/WDialog.h>
14#include <Wt/WEnvironment.h>
15#include <Wt/WIntValidator.h>
16#include <Wt/WItemDelegate.h>
18#include <Wt/WLineEdit.h>
19#include <Wt/WMessageBox.h>
20#include <Wt/WPushButton.h>
21#include <Wt/WRegExpValidator.h>
22#include <Wt/WGridLayout.h>
23#include <Wt/WPopupMenu.h>
24#include <Wt/WSortFilterProxyModel.h>
25#include <Wt/WStandardItem.h>
26#include <Wt/WStandardItemModel.h>
27#include <Wt/WTableView.h>
28#include <Wt/WTreeView.h>
30#include <Wt/WVBoxLayout.h>
32#include <Wt/Chart/WPieChart.h>
95 auto nameEdit = std::make_unique<WLineEdit>(
asString(
model_->data(modelRow, 1)));
99 auto typeEdit = std::make_unique<WComboBox>();
108 auto sizeEdit = std::make_unique<WLineEdit>(
asString(
model_->data(modelRow, 3)));
111 (std::make_shared<WIntValidator>(0, std::numeric_limits<int>::max()));
115 auto createdPicker = std::make_unique<WDatePicker>();
122 auto modifiedPicker = std::make_unique<WDatePicker>();
131 auto layout = std::make_unique<WGridLayout>();
133 std::unique_ptr<WLabel> label;
136 label = std::make_unique<WLabel>(
"Name:");
138 layout->addWidget(std::move(label), row, 0);
139 layout->addWidget(std::move(nameEdit), row, 1);
142 label = std::make_unique<WLabel>(
"Type:");
144 layout->addWidget(std::move(label), row, 0);
145 layout->addWidget(std::move(typeEdit), row, 1);
148 label = std::make_unique<WLabel>(
"Size");
150 layout->addWidget(std::move(label), row, 0);
151 layout->addWidget(std::move(sizeEdit), row, 1);
154 label = std::make_unique<WLabel>(
"Created:");
156 layout->addWidget(std::move(label), row, 0);
157 layout->addWidget(std::move(createdPicker), row, 2);
160 label = std::make_unique<WLabel>(
"Modified:");
162 layout->addWidget(std::move(label), row, 0);
163 layout->addWidget(std::move(modifiedPicker), row, 2);
166 std::unique_ptr<WPushButton>button;
167 auto buttons = std::make_unique<WContainerWidget>();
169 button = std::make_unique<WPushButton>(
"Save");
171 buttons->addWidget(std::move(button));
173 button = std::make_unique<WPushButton>(
"Cancel");
176 buttons->addWidget(std::move(button));
196 layout->addWidget(std::move(buttons), row, 0, 0, 3, AlignmentFlag::Center);
197 layout->setColumnStretch(1, 1);
207 std::shared_ptr<WAbstractItemModel>
model_;
216 if (
result == DialogCode::Accepted) {
227 std::shared_ptr<WAbstractItemModel> m =
model_;
230 std::shared_ptr<WAbstractProxyModel> proxyModel =
231 std::dynamic_pointer_cast<WAbstractProxyModel>(m);
233 m = proxyModel->sourceModel();
234 modelRow = proxyModel->mapToSource(
item_).row();
239 m->setData(modelRow, 3, cpp17::any(
asNumber
269 std::make_shared<WStandardItemModel>(0, 1);
274 std::make_shared<FileModel>();
340 std::unique_ptr<WGridLayout> layout =
341 std::make_unique<WGridLayout>();
345 layout->setColumnResizable(0);
350 std::unique_ptr<WVBoxLayout> vbox =
351 std::make_unique<WVBoxLayout>();
354 vbox->setResizable(0);
356 layout->addLayout(std::move(vbox), 1, 1);
363 layout->setRowStretch(1, 1);
364 layout->setColumnStretch(1, 1);
372 auto result = std::make_unique<WText>(
title);
373 result->setInline(
false);
374 result->setStyleClass(
"title");
382 auto treeView = std::make_unique<FolderView>();
393 contextJS << WT_CLASS <<
".$('" << treeView->id() <<
"').oncontextmenu = "
394 <<
"function() { event.cancelBubble = true; event.returnValue = false; return false; };";
398 treeView->setSelectionMode(SelectionMode::Single);
399 treeView->setEnabledDropLocations(DropLocation::OnItem);
400 treeView->expandToDepth(1);
401 treeView->selectionChanged()
408 return std::move(treeView);
415 = std::make_unique<WTableView>();
417 tableView->setAlternatingRowColors(
true);
420 tableView->setSelectionMode(SelectionMode::Extended);
421 tableView->setDragEnabled(
true);
423 tableView->setColumnWidth(0, 100);
424 tableView->setColumnWidth(1, 150);
425 tableView->setColumnWidth(2, 100);
426 tableView->setColumnWidth(3, 60);
427 tableView->setColumnWidth(4, 100);
428 tableView->setColumnWidth(5, 100);
430 auto delegate = std::make_shared<WItemDelegate>();
432 tableView->setItemDelegateForColumn(4, delegate);
433 tableView->setItemDelegateForColumn(5, delegate);
435 tableView->setColumnAlignment(3, AlignmentFlag::Right);
436 tableView->setColumnAlignment(4, AlignmentFlag::Right);
437 tableView->setColumnAlignment(5, AlignmentFlag::Right);
439 tableView->sortByColumn(1, SortOrder::Ascending);
442 this, std::placeholders::_1));
458 using namespace Chart;
460 auto chart = std::make_unique<WPieChart>();
463 chart->setTitle(
"File sizes");
465 chart->setLabelsColumn(1);
466 chart->setDataColumn(3);
468 chart->setPerspectiveEnabled(
true, 0.2);
469 chart->setDisplayLabels(LabelOption::Outside | LabelOption::TextLabel);
471 if (!WApplication::instance()->
environment().ajax()) {
472 chart->resize(500, 200);
475 auto w = std::make_unique<WContainerWidget>();
476 w->addWidget(std::move(chart));
477 w->setStyleClass(
"about");
480 chart->setStyleClass(
"about");
481 return std::move(chart);
488 std::unique_ptr<WText> result
489 = std::make_unique<WText>(
WString::tr(
"about-text"));
490 result->setStyleClass(
"about");
491 return std::move(result);
503 if (cpp17::any_has_value(d)) {
504 std::string folder = cpp17::any_cast<std::string>(d);
510 fileFilterModel_->setFilterRegExp(std::unique_ptr<std::regex>(
new std::regex(folder)));
517 if (event.
button() == MouseButton::Right) {
523 popup_ = std::make_unique<WPopupMenu>();
524 popup_->addItem(
"icons/folder_new.gif",
"Create a New Folder");
525 popup_->addItem(
"Rename this Folder")->setCheckable(
true);
526 popup_->addItem(
"Delete this Folder");
528 popup_->addItem(
"Folder Details");
530 popup_->addItem(
"Application Inventory");
531 popup_->addItem(
"Hardware Inventory");
534 std::unique_ptr<WPopupMenu> subMenu = std::make_unique<WPopupMenu>();
535 subMenu->addItem(
"Sub Item 1");
536 subMenu->addItem(
"Sub Item 2");
537 popup_->addMenu(
"File Deployments", std::move(subMenu));
568 + text +
"' is not implemented.",
593 fileModel_->invisibleRootItem()->setRowCount(0);
595 std::ifstream f((
appRoot() +
"data/files.csv").c_str());
598 throw std::runtime_error(
"Could not read: data/files.csv");
602 for (
int i = 0; i <
fileModel_->rowCount(); ++i) {
605 item->
setIcon(
"icons/file.gif");
635 std::unique_ptr<WStandardItem> level1;
660 cpp17::any(std::string(
"SandBox")));
668 const std::string& folderId = std::string())
671 = std::make_unique<WStandardItem>(location);
673 if (!folderId.empty()) {
674 result->setData(cpp17::any(folderId));
675 result->setFlags(result->flags() | ItemFlag::DropEnabled);
678 result->setFlags(result->flags().clear(ItemFlag::Selectable));
680 result->setIcon(
"icons/folder.gif");
688 auto app = std::make_unique<TreeViewDragDrop>(env);
689 app->setTwoPhaseRenderingThreshold(0);
690 app->setTitle(
"WTreeView Drag & Drop");
691 app->useStyleSheet(
"styles.css");
692 app->messageResourceBundle().use(WApplication::appRoot() +
"about");
695 return std::move(app);
int main(int argc, char **argv)
std::unique_ptr< WApplication > createApplication(const WEnvironment &env)
A dialog for editing a 'file'.
void handleFinish(DialogCode result)
std::shared_ptr< WAbstractItemModel > model_
WDatePicker * createdPicker_
WDatePicker * modifiedPicker_
FileEditDialog(std::shared_ptr< WAbstractItemModel > model, const WModelIndex &item)
A specialized standard item model which report a specific drag and drop mime type.
static WString dateEditFormat
Date edit format.
virtual std::string mimeType() const
Return the mime type.
static WString dateDisplayFormat
Date display format.
static const char * FileSelectionMimeType
Constant that indicates the mime type for a selection of files.
void folderChanged()
Change the filter on the file view when the selected folder changes.
std::unique_ptr< WWidget > aboutDisplay()
Creates the hints text.
std::shared_ptr< WStandardItemModel > fileModel_
The file model (used by fileView_)
std::map< std::string, WString > folderNameMap_
Maps folder id's to folder descriptions.
void editFile(const WModelIndex &item)
Edit a particular row.
std::shared_ptr< WSortFilterProxyModel > fileFilterModel_
The sort filter proxy model that adapts fileModel_.
std::unique_ptr< WTreeView > folderView()
Creates the folder WTreeView.
std::unique_ptr< WText > createTitle(const WString &title)
Creates a title widget.
void createUI()
Setup the user interface.
virtual ~TreeViewDragDrop()
std::shared_ptr< WStandardItemModel > folderModel_
The folder model (used by folderView_)
std::unique_ptr< WMessageBox > popupActionBox_
Message box to confirm the poup menu action.
std::unique_ptr< WTableView > fileView()
Creates the file table view (a WTableView)
std::unique_ptr< WPopupMenu > popup_
Popup menu on the folder view.
WTableView * fileView_
The file view.
void convertToDate(WStandardItem *item)
Convert a string to a date.
std::unique_ptr< WWidget > pieChart()
Creates the chart.
void showPopup(const WModelIndex &item, const WMouseEvent &event)
Show a popup for a folder item.
std::unique_ptr< WStandardItem > createFolderItem(const WString &location, const std::string &folderId=std::string())
Create a folder item.
TreeViewDragDrop(const WEnvironment &env)
Constructor.
void popupAction()
Process the result of the popup menu.
void populateFiles()
Populate the files model.
void convertToNumber(WStandardItem *item)
Convert a string to a number.
void dialogDone()
Process the result of the message box.
WTreeView * folderView_
The folder view.
std::unique_ptr< FileEditDialog > dialog_
void populateFolders()
Populate the folders model.
Wt::Signals::connection connect(F function)
static constexpr const int User
static constexpr const int Edit
static constexpr const int Display
WModelIndexSet selectedIndexes() const
bool isSelected(const WModelIndex &index) const
void select(const WModelIndex &index, SelectionFlag option=SelectionFlag::Select)
std::shared_ptr< WAbstractItemModel > model() const
void setCssTheme(const std::string &name)
void doJavaScript(const std::string &javascript, bool afterLoaded=true)
static WApplication * instance()
WContainerWidget * root() const
static std::string appRoot()
const WEnvironment & environment() const
const WString & title() const
int findText(const WString &text, WFlags< MatchFlag > flags=MatchFlag::Exactly|MatchFlag::CaseSensitive) const
const WString currentText() const
void setCurrentIndex(int index)
void addItem(const WString &text)
void setFormat(const WString &format)
void setDate(const WDate &date)
WLineEdit * lineEdit() const
static WDate fromString(const WString &s)
Signal< DialogCode > & finished()
WContainerWidget * contents() const
DialogCode result() const
const WString & text() const
cpp17::any data(ItemDataRole role=ItemDataRole::Display) const
MouseButton button() const
virtual void setData(const cpp17::any &data, ItemDataRole role=ItemDataRole::User)
void setIcon(const std::string &uri)
void setText(const WString &text)
WFlags< ItemFlag > flags() const
void setFlags(WFlags< ItemFlag > flags)
static WString tr(const char *key)
std::string toUTF8() const
WString asString(const cpp17::any &v, const WString &formatString=WString())
double asNumber(const cpp17::any &v)
void readFromCsv(std::istream &f, std::shared_ptr< WAbstractItemModel > model, int numRows, bool firstLineIsHeaders)