change combobox to select time.
All checks were successful
Deploy / Build (push) Successful in 6m18s

This commit is contained in:
amass 2025-01-18 01:34:05 +08:00
parent d65ca63c13
commit acf951a07f
3 changed files with 57 additions and 7 deletions

View File

@ -11,7 +11,7 @@ using Tasks = Wt::Dbo::collection<Wt::Dbo::ptr<Task>>;
class Task { class Task {
public: public:
bool finished = false; bool finished = false;
std::chrono::system_clock::time_point createTime; std::chrono::system_clock::time_point createTime = std::chrono::system_clock::now();
std::chrono::system_clock::time_point deadline; std::chrono::system_clock::time_point deadline;
std::string content; std::string content;
std::string remark; std::string remark;

View File

@ -3,15 +3,16 @@
#include "BoostLog.h" #include "BoostLog.h"
#include "Database/Session.h" #include "Database/Session.h"
#include <Wt/WCheckBox.h> #include <Wt/WCheckBox.h>
#include <Wt/WComboBox.h>
#include <Wt/WContainerWidget.h> #include <Wt/WContainerWidget.h>
#include <Wt/WDateEdit.h> #include <Wt/WDateEdit.h>
#include <Wt/WDialog.h> #include <Wt/WDialog.h>
#include <Wt/WLineEdit.h> #include <Wt/WLineEdit.h>
#include <Wt/WMessageBox.h> #include <Wt/WMessageBox.h>
#include <Wt/WPushButton.h> #include <Wt/WPushButton.h>
#include <Wt/WStandardItemModel.h>
#include <Wt/WTemplateFormView.h> #include <Wt/WTemplateFormView.h>
#include <Wt/WTextArea.h> #include <Wt/WTextArea.h>
#include <Wt/WTimeEdit.h>
TaskPage::TaskPage() : Wt::WTemplate(tr("Wt.Task.Home")) { TaskPage::TaskPage() : Wt::WTemplate(tr("Wt.Task.Home")) {
using namespace Wt; using namespace Wt;
@ -93,6 +94,7 @@ public:
static constexpr Field DeadlineTimeField = "task-deadlinetime"; static constexpr Field DeadlineTimeField = "task-deadlinetime";
static constexpr Field RemarkField = "task-remark"; static constexpr Field RemarkField = "task-remark";
AddTaskModel() : Wt::WFormModel() { AddTaskModel() : Wt::WFormModel() {
initializeModels();
addField(ContentField); addField(ContentField);
addField(DeadlineDateField); addField(DeadlineDateField);
addField(DeadlineTimeField); addField(DeadlineTimeField);
@ -101,11 +103,35 @@ public:
setValidator(DeadlineDateField, createDeadlineValidator()); setValidator(DeadlineDateField, createDeadlineValidator());
setValue(DeadlineDateField, Wt::WDate{}); setValue(DeadlineDateField, Wt::WDate{});
setValue(DeadlineTimeField, Wt::WTime{});
} }
std::shared_ptr<Wt::WAbstractItemModel> timeModel() {
return m_timeModel;
}
Wt::WTime timefRow(int row) {
return Wt::cpp17::any_cast<Wt::WTime>(m_timeModel->data(row, 0, Wt::ItemDataRole::User));
}
int rowOfTime(const Wt::WTime &time) {
int ret = -1;
for (int i = 0; i < m_timeModel->rowCount(); ++i) {
if (timefRow(i) == time) {
ret = i;
break;
}
}
return -1;
}
Task task() { Task task() {
Task t; Task t;
t.content = Wt::asString(value(ContentField)).toUTF8(); t.content = Wt::asString(value(ContentField)).toUTF8();
t.remark = Wt::asString(value(RemarkField)).toUTF8(); t.remark = Wt::asString(value(RemarkField)).toUTF8();
auto date = Wt::cpp17::any_cast<Wt::WDate>(value(AddTaskModel::DeadlineDateField));
auto time = Wt::cpp17::any_cast<Wt::WTime>(value(AddTaskModel::DeadlineTimeField));
t.deadline = Wt::WDateTime(date, time).toTimePoint();
return t; return t;
} }
@ -119,6 +145,18 @@ protected:
v->setMandatory(true); v->setMandatory(true);
return v; return v;
} }
void initializeModels() {
m_timeModel = std::make_shared<Wt::WStandardItemModel>(48, 1);
for (int i = 0; i < 48; i++) {
Wt::WTime time(i / 2, (i % 2) * 30);
m_timeModel->setData(i, 0, time.toString("HH:mm"), Wt::ItemDataRole::Display);
m_timeModel->setData(i, 0, time, Wt::ItemDataRole::User);
}
}
private:
std::shared_ptr<Wt::WStandardItemModel> m_timeModel;
}; };
class AddTaskView : public Wt::WTemplateFormView { class AddTaskView : public Wt::WTemplateFormView {
@ -144,17 +182,19 @@ public:
m_model->setValue(AddTaskModel::DeadlineDateField, date); m_model->setValue(AddTaskModel::DeadlineDateField, date);
}); });
auto timeEdit = std::make_unique<Wt::WTimeEdit>(); auto timeEdit = std::make_unique<Wt::WComboBox>();
auto timeEdit_ = timeEdit.get(); auto timeEdit_ = timeEdit.get();
timeEdit_->setModel(m_model->timeModel());
setFormWidget( setFormWidget(
AddTaskModel::DeadlineTimeField, std::move(timeEdit), AddTaskModel::DeadlineTimeField, std::move(timeEdit),
[this, timeEdit_] { // updateViewValue() [this, timeEdit_] { // updateViewValue()
// Wt::WDate date = Wt::cpp17::any_cast<Wt::WDate>(m_model->value(AddTaskModel::DeadlineTimeField)); Wt::WTime time = Wt::cpp17::any_cast<Wt::WTime>(m_model->value(AddTaskModel::DeadlineTimeField));
// dateEdit_->setDate(date); int row = m_model->rowOfTime(time);
timeEdit_->setCurrentIndex(row);
}, },
[this, timeEdit_] { // updateModelValue() [this, timeEdit_] { // updateModelValue()
// Wt::WDate date = dateEdit_->date(); Wt::WTime time = m_model->timefRow(timeEdit_->currentIndex());
// m_model->setValue(AddTaskModel::DeadlineTimeField, date); m_model->setValue(AddTaskModel::DeadlineTimeField, time);
}); });
auto button = bindWidget("submit-button", std::make_unique<Wt::WPushButton>("确定")); auto button = bindWidget("submit-button", std::make_unique<Wt::WPushButton>("确定"));

View File

@ -198,6 +198,16 @@ ul li ul li {
padding: 0 .2em !important padding: 0 .2em !important
} }
.Wt-calendar {
background-color: var(--bulma-background);
}
.Wt-calendar table td,
.Wt-calendar table th {
padding: 0;
width: 42.5px;
}
.Wt-calendar .form-control { .Wt-calendar .form-control {
display: initial; display: initial;
} }