change combobox to select time.
All checks were successful
Deploy / Build (push) Successful in 6m18s
All checks were successful
Deploy / Build (push) Successful in 6m18s
This commit is contained in:
parent
d65ca63c13
commit
acf951a07f
@ -11,7 +11,7 @@ using Tasks = Wt::Dbo::collection<Wt::Dbo::ptr<Task>>;
|
||||
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;
|
||||
|
@ -3,15 +3,16 @@
|
||||
#include "BoostLog.h"
|
||||
#include "Database/Session.h"
|
||||
#include <Wt/WCheckBox.h>
|
||||
#include <Wt/WComboBox.h>
|
||||
#include <Wt/WContainerWidget.h>
|
||||
#include <Wt/WDateEdit.h>
|
||||
#include <Wt/WDialog.h>
|
||||
#include <Wt/WLineEdit.h>
|
||||
#include <Wt/WMessageBox.h>
|
||||
#include <Wt/WPushButton.h>
|
||||
#include <Wt/WStandardItemModel.h>
|
||||
#include <Wt/WTemplateFormView.h>
|
||||
#include <Wt/WTextArea.h>
|
||||
#include <Wt/WTimeEdit.h>
|
||||
|
||||
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<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 t;
|
||||
t.content = Wt::asString(value(ContentField)).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;
|
||||
}
|
||||
|
||||
@ -119,6 +145,18 @@ protected:
|
||||
v->setMandatory(true);
|
||||
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 {
|
||||
@ -144,17 +182,19 @@ public:
|
||||
m_model->setValue(AddTaskModel::DeadlineDateField, date);
|
||||
});
|
||||
|
||||
auto timeEdit = std::make_unique<Wt::WTimeEdit>();
|
||||
auto timeEdit = std::make_unique<Wt::WComboBox>();
|
||||
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<Wt::WDate>(m_model->value(AddTaskModel::DeadlineTimeField));
|
||||
// dateEdit_->setDate(date);
|
||||
Wt::WTime time = Wt::cpp17::any_cast<Wt::WTime>(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<Wt::WPushButton>("确定"));
|
||||
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user