From e0bac3a19b5b5f6feab368dc11342fbc0b966c00 Mon Sep 17 00:00:00 2001 From: amass Date: Fri, 17 Jan 2025 17:56:03 +0800 Subject: [PATCH] add task deadline. --- Database/Task.h | 2 + WebApplication/TaskPage.cpp | 55 +++++++++++++++++++-- resources/app.css | 95 ++++++++++++++++++++++++++++++++++--- resources/webrtc.xml | 46 +++++++++++++++--- resources/wt_zh.xml | 62 ++++++++++++------------ 5 files changed, 212 insertions(+), 48 deletions(-) diff --git a/Database/Task.h b/Database/Task.h index 1951f55..7938acd 100644 --- a/Database/Task.h +++ b/Database/Task.h @@ -12,6 +12,7 @@ class Task { public: bool finished = false; std::chrono::system_clock::time_point createTime; + std::chrono::system_clock::time_point deadline; std::string content; std::string remark; @@ -21,6 +22,7 @@ public: template void persist(Action &a) { Wt::Dbo::field(a, content, "content"); + Wt::Dbo::field(a, deadline, "deadline"); Wt::Dbo::field(a, remark, "remark"); Wt::Dbo::field(a, finished, "finished"); Wt::Dbo::field(a, createTime, "create_time"); diff --git a/WebApplication/TaskPage.cpp b/WebApplication/TaskPage.cpp index 21f4a75..79263f0 100644 --- a/WebApplication/TaskPage.cpp +++ b/WebApplication/TaskPage.cpp @@ -4,12 +4,14 @@ #include "Database/Session.h" #include #include +#include #include #include #include #include #include #include +#include TaskPage::TaskPage() : Wt::WTemplate(tr("Wt.Task.Home")) { using namespace Wt; @@ -23,9 +25,6 @@ TaskPage::TaskPage() : Wt::WTemplate(tr("Wt.Task.Home")) { std::unique_ptr TaskPage::createTask(const Wt::Dbo::ptr &task) { auto ret = std::make_unique(tr("Wt.Task.Item")); auto app = dynamic_cast(Wt::WApplication::instance()); - if (app->inDocusaurus()) { - ret->addStyleClass("li-none-style"); - } ret->bindString("content", task->content); ret->bindString("remark", task->remark); ret->setHtmlTagName("li"); @@ -90,10 +89,18 @@ std::unique_ptr TaskPage::createTask(const Wt::Dbo::ptr &ta class AddTaskModel : public Wt::WFormModel { public: static constexpr Field ContentField = "task-content"; + static constexpr Field DeadlineDateField = "task-deadlinedate"; + static constexpr Field DeadlineTimeField = "task-deadlinetime"; static constexpr Field RemarkField = "task-remark"; AddTaskModel() : Wt::WFormModel() { addField(ContentField); + addField(DeadlineDateField); + addField(DeadlineTimeField); addField(RemarkField); + + setValidator(DeadlineDateField, createDeadlineValidator()); + + setValue(DeadlineDateField, Wt::WDate{}); } Task task() { Task t; @@ -101,6 +108,17 @@ public: t.remark = Wt::asString(value(RemarkField)).toUTF8(); return t; } + +protected: + std::shared_ptr createDeadlineValidator() { + auto v = std::make_shared(); + auto current = Wt::WDate::currentDate(); + v->setBottom(current); + v->setTop(current.addYears(1)); + v->setFormat("yyyy/MM/dd"); + v->setMandatory(true); + return v; + } }; class AddTaskView : public Wt::WTemplateFormView { @@ -113,6 +131,32 @@ public: remark->setRows(5); setFormWidget(AddTaskModel::RemarkField, std::move(remark)); + auto dateEdit = std::make_unique(); + auto dateEdit_ = dateEdit.get(); + setFormWidget( + AddTaskModel::DeadlineDateField, std::move(dateEdit), + [this, dateEdit_] { // updateViewValue() + Wt::WDate date = Wt::cpp17::any_cast(m_model->value(AddTaskModel::DeadlineDateField)); + dateEdit_->setDate(date); + }, + [this, dateEdit_] { // updateModelValue() + Wt::WDate date = dateEdit_->date(); + m_model->setValue(AddTaskModel::DeadlineDateField, date); + }); + + auto timeEdit = std::make_unique(); + auto timeEdit_ = timeEdit.get(); + setFormWidget( + AddTaskModel::DeadlineTimeField, std::move(timeEdit), + [this, timeEdit_] { // updateViewValue() + // Wt::WDate date = Wt::cpp17::any_cast(m_model->value(AddTaskModel::DeadlineTimeField)); + // dateEdit_->setDate(date); + }, + [this, timeEdit_] { // updateModelValue() + // Wt::WDate date = dateEdit_->date(); + // m_model->setValue(AddTaskModel::DeadlineTimeField, date); + }); + auto button = bindWidget("submit-button", std::make_unique("确定")); button->clicked().connect(this, &AddTaskView::process); @@ -180,7 +224,10 @@ void TaskPage::update() { } else { auto list = bindNew("tasks"); list->setList(true); - + auto app = dynamic_cast(Wt::WApplication::instance()); + if (app->inDocusaurus()) { + list->addStyleClass("bulma-is-list-style-none"); + } for (auto &task : tasks) { list->addWidget(createTask(task)); } diff --git a/resources/app.css b/resources/app.css index 8c6fa5e..03cfde8 100644 --- a/resources/app.css +++ b/resources/app.css @@ -7,12 +7,6 @@ ul li ul li { margin-left: 2.5rem } -.li-none-style { - list-style: none; - margin: 0; - padding: 0; -} - .Wt-itemview .Wt-headerdiv { overflow: hidden; -webkit-user-select: none; @@ -117,4 +111,93 @@ ul li ul li { .is-pointer-cursor { cursor: pointer !important; +} + +.Wt-cal table.d1 { + width: 170px +} + +.Wt-cal table.d3 { + width: 300px +} + +.Wt-cal table.dlong { + width: 560px +} + +.Wt-cal .Wt-cal-navbutton { + display: block +} + +.Wt-cal .Wt-cal-now { + background-color: #d3d3d3 +} + +.Wt-cal .days.d1 td { + width: 20px +} + +.Wt-cal .days.d3 td { + width: 35px +} + +.Wt-cal .days.dlong td { + width: 80px +} + +.Wt-cal td, +.Wt-cal td>div, +.Wt-cal th { + border-radius: 4px; + height: 28px; + text-align: center +} + +.Wt-cal tr:first-child th { + cursor: pointer +} + +.Wt-cal tr:first-child th:hover { + background: #eee +} + +.Wt-cal tr:first-child th select { + margin: 0; + width: 125px +} + +.Wt-cal tr:first-child th input { + margin: 0; + width: 60px +} + +.Wt-cal .days td:hover { + background: #eee; + cursor: pointer +} + +.Wt-cal .days td .Wt-cal-oom, +.Wt-cal .days td .Wt-cal-oor { + color: #999 +} + +.Wt-cal .days td .Wt-cal-sel, +.Wt-cal .days td .Wt-cal-sel:hover { + background-color: #0d6efd; + background-image: linear-gradient(180deg, hsla(0, 0%, 100%, .15), hsla(0, 0%, 100%, 0)); + color: #fff; + text-shadow: 0 -1px 0 rgba(0, 0, 0, .25) +} + +.Wt-cal .form-select { + display: inline-block !important +} + +.Wt-cal-year .form-control { + min-height: 1.5em !important; + padding: 0 .2em !important +} + +.Wt-calendar .form-control { + display: initial; } \ No newline at end of file diff --git a/resources/webrtc.xml b/resources/webrtc.xml index 33b1626..b581e0a 100644 --- a/resources/webrtc.xml +++ b/resources/webrtc.xml @@ -34,12 +34,12 @@ ${tasks} -
+
${finished-checkbox} -
-
${content}
-
${remark}
+
+ ${content}
+
${remove-button class="bulma-button bulma-is-danger"} ${add-child class="bulma-button bulma-is-success"} @@ -61,6 +61,32 @@
${task-content-info class="Wt-info bulma-help"}
+
+
+ +
+ ${task-deadlinedate class="bulma-input" type="text"} + + + +
+ ${task-deadlinedate-info class="Wt-info bulma-help"} +
+
+ +
+ ${task-deadlinetime class="bulma-input" type="text"} + + + +
+ ${task-deadlinetime-info class="Wt-info bulma-help"} +
+
${task-remark-info class="Wt-info bulma-help"}
-
- ${submit-button class="bulma-button"} - ${cancel-button class="bulma-button"} +
+
+ ${submit-button class="bulma-button bulma-is-link"} +
+
+ ${cancel-button class="bulma-button bulma-is-link bulma-is-light"} +
@@ -97,6 +127,8 @@ 内容 备注 + 完成日期 +

访客数据统计

diff --git a/resources/wt_zh.xml b/resources/wt_zh.xml index a9f02b1..926e5c5 100644 --- a/resources/wt_zh.xml +++ b/resources/wt_zh.xml @@ -22,37 +22,37 @@ Friday Saturday Sunday - Mon - Tue - Wed - Thu - Fri - Sat - Sun - January - February - March - April - May - June - July - August - September - October - November - December - Jan - Feb - Mar - Apr - May - Jun - Jul - Aug - Sep - Oct - Nov - Dec + + + + + + + + 一月 + 二月 + 三月 + 四月 + 五月 + 六月 + 七月 + 八月 + 九月 + 十月 + 十一月 + 十二月 + + + + + + + + + + + 十一 + 十二 Close