add search for record.
All checks were successful
Deploy / Build (push) Successful in 6m12s

This commit is contained in:
amass 2025-01-17 02:55:03 +08:00
parent 69220431d3
commit f3d211a109
8 changed files with 54 additions and 25 deletions

View File

@ -32,6 +32,7 @@ Application::Application(const Wt::WEnvironment &env, bool embedded)
messageResourceBundle().use(appRoot() + "wt");
messageResourceBundle().use(appRoot() + "auth_strings");
messageResourceBundle().use(appRoot() + "auth_css_theme");
messageResourceBundle().use(appRoot() + "webrtc");
useStyleSheet("/resources/app.css");
LOG(info) << "app root: " << appRoot();
m_session = Database::session();

View File

@ -13,11 +13,9 @@
TaskPage::TaskPage() : Wt::WTemplate(tr("Wt.Task.Home")) {
using namespace Wt;
WApplication *app = WApplication::instance();
app->messageResourceBundle().use(app->appRoot() + "webrtc");
addStyleClass("bulma-is-flex-grow-1 bulma-is-flex bulma-is-flex-direction-column");
auto addButton = bindNew<Wt::WPushButton>("add-new", "创建");
auto addButton = bindNew<WPushButton>("add-new", "创建");
addButton->clicked().connect(this, [this]() { showAddTaskDialog(-1); });
update();
}

View File

@ -6,17 +6,23 @@
#include <Wt/WBreak.h>
#include <Wt/WItemDelegate.h>
#include <Wt/WLabel.h>
#include <Wt/WLineEdit.h>
#include <Wt/WMessageBox.h>
#include <Wt/WPushButton.h>
#include <Wt/WTableView.h>
VisitorRecordsPage::VisitorRecordsPage(Session &session) : m_model{std::make_shared<VisitorRecordTableModel>(session)} {
addNew<Wt::WLabel>("访客数据统计");
addNew<Wt::WBreak>();
auto button = addNew<Wt::WPushButton>("删除");
VisitorRecordsPage::VisitorRecordsPage(Session &session)
: Wt::WTemplate(tr("Wt.VisitorRecords.Home")), m_model{std::make_shared<VisitorRecordTableModel>(session)} {
auto button = bindNew<Wt::WPushButton>("remove-button", "删除");
button->clicked().connect(this, &VisitorRecordsPage::onDeleteButtonClicked);
auto view = addNew<Wt::WTableView>();
auto searchInput = bindNew<Wt::WLineEdit>("search-input");
searchInput->setPlaceholderText("请输入文章标题");
auto searchButton = bindNew<Wt::WPushButton>("search-button", "搜索");
searchButton->clicked().connect(this, [this, searchInput]() { m_model->filter(searchInput->text().toUTF8()); });
auto view = bindNew<Wt::WTableView>("records");
view->setColumnWidth(0, Wt::WLength::Auto);
view->setColumnWidth(1, Wt::WLength::Auto);
view->setHeaderHeight(30); // 设置表头的高度

View File

@ -1,14 +1,14 @@
#ifndef __VISITORRECORDSPAGE_H__
#define __VISITORRECORDSPAGE_H__
#include <Wt/WContainerWidget.h>
#include <Wt/WTemplate.h>
class Session;
class VisitorRecordTableModel;
// https://infima.dev/
class VisitorRecordsPage : public Wt::WContainerWidget {
class VisitorRecordsPage : public Wt::WTemplate {
public:
VisitorRecordsPage(Session &session);

View File

@ -15,7 +15,6 @@
WebRTCClientPage::WebRTCClientPage() : Wt::WTemplate(tr("Wt.WebRTC.Home")) {
using namespace Wt;
WApplication *app = WApplication::instance();
app->messageResourceBundle().use(app->appRoot() + "webrtc");
LOAD_JAVASCRIPT(app, "js/WebRTCClient.js", "WebRTCClient", wtjs1);
addStyleClass("bulma-is-flex-grow-1 bulma-is-flex bulma-is-flex-direction-column");

View File

@ -4,20 +4,7 @@
#include "DateTime.h"
VisitorRecordTableModel::VisitorRecordTableModel(Session &session) : m_session(session) {
Wt::Dbo::Transaction transaction(session);
Wt::Dbo::collection<Wt::Dbo::ptr<VisitorRecord>> records = session.find<VisitorRecord>();
int index = 1;
std::unordered_map<std::string, std::string> users;
for (auto &record : records) {
if (record->url.size() <= 1) continue;
if (!users.contains(record->visitorUuid)) {
users.insert({record->visitorUuid, std::format("匿名用户{}", index++)});
}
m_records.push_back({*record, false});
std::get<0>(m_records.back()).visitorUuid = users.at(record->visitorUuid);
std::get<0>(m_records.back()).id = record.id();
}
filter("");
}
int VisitorRecordTableModel::columnCount(const Wt::WModelIndex &parent) const {
@ -154,6 +141,26 @@ Wt::WModelIndexSet VisitorRecordTableModel::selectedIndexes() const {
return ret;
}
void VisitorRecordTableModel::filter(const std::string &search) {
layoutAboutToBeChanged().emit();
m_records.clear();
Wt::Dbo::Transaction transaction(m_session);
VisitorRecords records = m_session.find<VisitorRecord>().where(std::format("url LIKE '%{}%'", search));
int index = 1;
std::unordered_map<std::string, std::string> users;
for (auto &record : records) {
if (record->url.size() <= 1) continue;
if (!users.contains(record->visitorUuid)) {
users.insert({record->visitorUuid, std::format("匿名用户{}", index++)});
}
m_records.push_back({*record, false});
std::get<0>(m_records.back()).visitorUuid = users.at(record->visitorUuid);
std::get<0>(m_records.back()).id = record.id();
}
layoutChanged().emit();
}
bool VisitorRecordTableModel::removeSelectedRows(const Wt::WModelIndexSet &indexes) {
Wt::Dbo::Transaction transaction(m_session);
layoutAboutToBeChanged().emit();

View File

@ -21,6 +21,7 @@ public:
Wt::ItemDataRole role = Wt::ItemDataRole::Edit) final;
void sort(int column, Wt::SortOrder order = Wt::SortOrder::Ascending) final;
Wt::WModelIndexSet selectedIndexes() const;
void filter(const std::string &search);
bool removeRows(int row, int count, const Wt::WModelIndex &parent = Wt::WModelIndex()) final;
bool removeSelectedRows(const Wt::WModelIndexSet &indexes);

View File

@ -97,4 +97,21 @@
</message>
<message id="task-content">内容</message>
<message id="task-remark">备注</message>
<message id="Wt.VisitorRecords.Home">
<h2 class="bulma-subtitle bulma-has-text-centered">访客数据统计</h2>
<div class="bulma-is-flex bulma-is-justify-content-space-between">
<div class="bulma-field bulma-has-addons">
<div class="bulma-control" style="min-width: 10rem">
${search-input class="bulma-input"}
</div>
<div class="bulma-control">
${search-button class="bulma-button bulma-is-info"}
</div>
</div>
<div class="bulma-field">
${remove-button class="bulma-button bulma-is-danger "}
</div>
</div>
${records}
</message>
</messages>