This commit is contained in:
parent
69220431d3
commit
f3d211a109
@ -32,6 +32,7 @@ Application::Application(const Wt::WEnvironment &env, bool embedded)
|
|||||||
messageResourceBundle().use(appRoot() + "wt");
|
messageResourceBundle().use(appRoot() + "wt");
|
||||||
messageResourceBundle().use(appRoot() + "auth_strings");
|
messageResourceBundle().use(appRoot() + "auth_strings");
|
||||||
messageResourceBundle().use(appRoot() + "auth_css_theme");
|
messageResourceBundle().use(appRoot() + "auth_css_theme");
|
||||||
|
messageResourceBundle().use(appRoot() + "webrtc");
|
||||||
useStyleSheet("/resources/app.css");
|
useStyleSheet("/resources/app.css");
|
||||||
LOG(info) << "app root: " << appRoot();
|
LOG(info) << "app root: " << appRoot();
|
||||||
m_session = Database::session();
|
m_session = Database::session();
|
||||||
|
@ -13,11 +13,9 @@
|
|||||||
|
|
||||||
TaskPage::TaskPage() : Wt::WTemplate(tr("Wt.Task.Home")) {
|
TaskPage::TaskPage() : Wt::WTemplate(tr("Wt.Task.Home")) {
|
||||||
using namespace Wt;
|
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");
|
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); });
|
addButton->clicked().connect(this, [this]() { showAddTaskDialog(-1); });
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,23 @@
|
|||||||
#include <Wt/WBreak.h>
|
#include <Wt/WBreak.h>
|
||||||
#include <Wt/WItemDelegate.h>
|
#include <Wt/WItemDelegate.h>
|
||||||
#include <Wt/WLabel.h>
|
#include <Wt/WLabel.h>
|
||||||
|
#include <Wt/WLineEdit.h>
|
||||||
#include <Wt/WMessageBox.h>
|
#include <Wt/WMessageBox.h>
|
||||||
#include <Wt/WPushButton.h>
|
#include <Wt/WPushButton.h>
|
||||||
#include <Wt/WTableView.h>
|
#include <Wt/WTableView.h>
|
||||||
|
|
||||||
VisitorRecordsPage::VisitorRecordsPage(Session &session) : m_model{std::make_shared<VisitorRecordTableModel>(session)} {
|
VisitorRecordsPage::VisitorRecordsPage(Session &session)
|
||||||
addNew<Wt::WLabel>("访客数据统计");
|
: Wt::WTemplate(tr("Wt.VisitorRecords.Home")), m_model{std::make_shared<VisitorRecordTableModel>(session)} {
|
||||||
addNew<Wt::WBreak>();
|
|
||||||
auto button = addNew<Wt::WPushButton>("删除");
|
auto button = bindNew<Wt::WPushButton>("remove-button", "删除");
|
||||||
button->clicked().connect(this, &VisitorRecordsPage::onDeleteButtonClicked);
|
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(0, Wt::WLength::Auto);
|
||||||
view->setColumnWidth(1, Wt::WLength::Auto);
|
view->setColumnWidth(1, Wt::WLength::Auto);
|
||||||
view->setHeaderHeight(30); // 设置表头的高度
|
view->setHeaderHeight(30); // 设置表头的高度
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
#ifndef __VISITORRECORDSPAGE_H__
|
#ifndef __VISITORRECORDSPAGE_H__
|
||||||
#define __VISITORRECORDSPAGE_H__
|
#define __VISITORRECORDSPAGE_H__
|
||||||
|
|
||||||
#include <Wt/WContainerWidget.h>
|
#include <Wt/WTemplate.h>
|
||||||
|
|
||||||
class Session;
|
class Session;
|
||||||
class VisitorRecordTableModel;
|
class VisitorRecordTableModel;
|
||||||
|
|
||||||
// https://infima.dev/
|
// https://infima.dev/
|
||||||
|
|
||||||
class VisitorRecordsPage : public Wt::WContainerWidget {
|
class VisitorRecordsPage : public Wt::WTemplate {
|
||||||
public:
|
public:
|
||||||
VisitorRecordsPage(Session &session);
|
VisitorRecordsPage(Session &session);
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
WebRTCClientPage::WebRTCClientPage() : Wt::WTemplate(tr("Wt.WebRTC.Home")) {
|
WebRTCClientPage::WebRTCClientPage() : Wt::WTemplate(tr("Wt.WebRTC.Home")) {
|
||||||
using namespace Wt;
|
using namespace Wt;
|
||||||
WApplication *app = WApplication::instance();
|
WApplication *app = WApplication::instance();
|
||||||
app->messageResourceBundle().use(app->appRoot() + "webrtc");
|
|
||||||
LOAD_JAVASCRIPT(app, "js/WebRTCClient.js", "WebRTCClient", wtjs1);
|
LOAD_JAVASCRIPT(app, "js/WebRTCClient.js", "WebRTCClient", wtjs1);
|
||||||
|
|
||||||
addStyleClass("bulma-is-flex-grow-1 bulma-is-flex bulma-is-flex-direction-column");
|
addStyleClass("bulma-is-flex-grow-1 bulma-is-flex bulma-is-flex-direction-column");
|
||||||
|
@ -4,20 +4,7 @@
|
|||||||
#include "DateTime.h"
|
#include "DateTime.h"
|
||||||
|
|
||||||
VisitorRecordTableModel::VisitorRecordTableModel(Session &session) : m_session(session) {
|
VisitorRecordTableModel::VisitorRecordTableModel(Session &session) : m_session(session) {
|
||||||
Wt::Dbo::Transaction transaction(session);
|
filter("");
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int VisitorRecordTableModel::columnCount(const Wt::WModelIndex &parent) const {
|
int VisitorRecordTableModel::columnCount(const Wt::WModelIndex &parent) const {
|
||||||
@ -154,6 +141,26 @@ Wt::WModelIndexSet VisitorRecordTableModel::selectedIndexes() const {
|
|||||||
return ret;
|
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) {
|
bool VisitorRecordTableModel::removeSelectedRows(const Wt::WModelIndexSet &indexes) {
|
||||||
Wt::Dbo::Transaction transaction(m_session);
|
Wt::Dbo::Transaction transaction(m_session);
|
||||||
layoutAboutToBeChanged().emit();
|
layoutAboutToBeChanged().emit();
|
||||||
|
@ -21,6 +21,7 @@ public:
|
|||||||
Wt::ItemDataRole role = Wt::ItemDataRole::Edit) final;
|
Wt::ItemDataRole role = Wt::ItemDataRole::Edit) final;
|
||||||
void sort(int column, Wt::SortOrder order = Wt::SortOrder::Ascending) final;
|
void sort(int column, Wt::SortOrder order = Wt::SortOrder::Ascending) final;
|
||||||
Wt::WModelIndexSet selectedIndexes() const;
|
Wt::WModelIndexSet selectedIndexes() const;
|
||||||
|
void filter(const std::string &search);
|
||||||
|
|
||||||
bool removeRows(int row, int count, const Wt::WModelIndex &parent = Wt::WModelIndex()) final;
|
bool removeRows(int row, int count, const Wt::WModelIndex &parent = Wt::WModelIndex()) final;
|
||||||
bool removeSelectedRows(const Wt::WModelIndexSet &indexes);
|
bool removeSelectedRows(const Wt::WModelIndexSet &indexes);
|
||||||
|
@ -97,4 +97,21 @@
|
|||||||
</message>
|
</message>
|
||||||
<message id="task-content">内容</message>
|
<message id="task-content">内容</message>
|
||||||
<message id="task-remark">备注</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>
|
</messages>
|
Loading…
Reference in New Issue
Block a user