diff --git a/Database/Task.h b/Database/Task.h index 7938acd..348e155 100644 --- a/Database/Task.h +++ b/Database/Task.h @@ -11,7 +11,7 @@ using Tasks = Wt::Dbo::collection>; class Task { public: 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::string content; std::string remark; diff --git a/WebApplication/TaskPage.cpp b/WebApplication/TaskPage.cpp index 79263f0..a842b5f 100644 --- a/WebApplication/TaskPage.cpp +++ b/WebApplication/TaskPage.cpp @@ -3,15 +3,16 @@ #include "BoostLog.h" #include "Database/Session.h" #include +#include #include #include #include #include #include #include +#include #include #include -#include TaskPage::TaskPage() : Wt::WTemplate(tr("Wt.Task.Home")) { using namespace Wt; @@ -93,6 +94,7 @@ public: static constexpr Field DeadlineTimeField = "task-deadlinetime"; static constexpr Field RemarkField = "task-remark"; AddTaskModel() : Wt::WFormModel() { + initializeModels(); addField(ContentField); addField(DeadlineDateField); addField(DeadlineTimeField); @@ -101,11 +103,35 @@ public: setValidator(DeadlineDateField, createDeadlineValidator()); setValue(DeadlineDateField, Wt::WDate{}); + setValue(DeadlineTimeField, Wt::WTime{}); } + + std::shared_ptr timeModel() { + return m_timeModel; + } + + Wt::WTime timefRow(int row) { + return Wt::cpp17::any_cast(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 t; t.content = Wt::asString(value(ContentField)).toUTF8(); t.remark = Wt::asString(value(RemarkField)).toUTF8(); + auto date = Wt::cpp17::any_cast(value(AddTaskModel::DeadlineDateField)); + auto time = Wt::cpp17::any_cast(value(AddTaskModel::DeadlineTimeField)); + t.deadline = Wt::WDateTime(date, time).toTimePoint(); return t; } @@ -119,6 +145,18 @@ protected: v->setMandatory(true); return v; } + + void initializeModels() { + m_timeModel = std::make_shared(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 m_timeModel; }; class AddTaskView : public Wt::WTemplateFormView { @@ -144,17 +182,19 @@ public: m_model->setValue(AddTaskModel::DeadlineDateField, date); }); - auto timeEdit = std::make_unique(); + auto timeEdit = std::make_unique(); auto timeEdit_ = timeEdit.get(); + timeEdit_->setModel(m_model->timeModel()); setFormWidget( AddTaskModel::DeadlineTimeField, std::move(timeEdit), [this, timeEdit_] { // updateViewValue() - // Wt::WDate date = Wt::cpp17::any_cast(m_model->value(AddTaskModel::DeadlineTimeField)); - // dateEdit_->setDate(date); + Wt::WTime time = Wt::cpp17::any_cast(m_model->value(AddTaskModel::DeadlineTimeField)); + int row = m_model->rowOfTime(time); + timeEdit_->setCurrentIndex(row); }, [this, timeEdit_] { // updateModelValue() - // Wt::WDate date = dateEdit_->date(); - // m_model->setValue(AddTaskModel::DeadlineTimeField, date); + Wt::WTime time = m_model->timefRow(timeEdit_->currentIndex()); + m_model->setValue(AddTaskModel::DeadlineTimeField, time); }); auto button = bindWidget("submit-button", std::make_unique("确定")); diff --git a/resources/app.css b/resources/app.css index 03cfde8..f141d3a 100644 --- a/resources/app.css +++ b/resources/app.css @@ -198,6 +198,16 @@ ul li ul li { 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 { display: initial; } \ No newline at end of file