diff --git a/Server/SystemUsage.cpp b/Server/SystemUsage.cpp index a2bd5ef..0143460 100644 --- a/Server/SystemUsage.cpp +++ b/Server/SystemUsage.cpp @@ -47,7 +47,7 @@ void SystemUsage::start() { auto receiveGigabyte = static_cast(back.receiveBytes - front.receiveBytes) / gigabyte; auto transmitGigabyte = static_cast(back.transmitBytes - front.transmitBytes) / gigabyte; auto speed = (receiveGigabyte + transmitGigabyte) / duration.count() * SpeedInterval.count(); - LOG(info) << "network speed: " << std::fixed << std::setprecision(2) << speed << "GB/h"; + // LOG(info) << "network speed: " << std::fixed << std::setprecision(2) << speed << "GB/h"; static system_clock::time_point lastNotify; auto now = system_clock::now(); if ((speed >= 1.5f) && (duration_cast(now - lastNotify) > minutes(10))) { // 一个小时1.5GB的流量 diff --git a/WebApplication/Application.cpp b/WebApplication/Application.cpp index 105c073..2cc1c3e 100644 --- a/WebApplication/Application.cpp +++ b/WebApplication/Application.cpp @@ -2,7 +2,7 @@ #include "BoostLog.h" #include "BulmaTheme.h" #include "Database/Session.h" -#include "Dialog.h" +#include "HomePage.h" #include "LoginPage.h" #include "Restful.h" #include "VisitorRecordsPage.h" @@ -17,8 +17,6 @@ #include #include #include -#include -#include #include #include @@ -33,7 +31,6 @@ Application::Application(const Wt::WEnvironment &env, bool embedded) : Wt::WAppl m_session->login().changed().connect(this, &Application::authEvent); setTheme(std::make_shared("bulma", !embedded)); if (!embedded) { - // setTheme(std::make_shared()); m_root = root(); } else { std::unique_ptr topPtr = std::make_unique(); @@ -55,34 +52,11 @@ Application::Application(const Wt::WEnvironment &env, bool embedded) : Wt::WAppl LOG(info) << p.first; } } - LOG(info) << "url: " << url(); - LOG(info) << "relative resources url: " << relativeResourcesUrl(); - LOG(info) << "resources url: " << resourcesUrl(); - } - - if (!embedded) { - root()->addWidget(std::make_unique( - "Note: you can also run this application from within a web page.")); } + LOG(info) << "url: " << url(); + LOG(info) << "relative resources url: " << relativeResourcesUrl(); + LOG(info) << "resources url: " << resourcesUrl(); LOG(info) << "internal path: " << internalPath(); - - m_root->addWidget(std::make_unique("Your name, please ? ")); - m_nameEdit = m_root->addWidget(std::make_unique()); - m_nameEdit->setFocus(); - - auto b = m_root->addWidget(std::make_unique("点击我!")); - b->setMargin(5, Wt::Side::Left); - - m_root->addWidget(std::make_unique()); - - m_greeting = m_root->addWidget(std::make_unique()); - - b->clicked().connect(this, &Application::greet); - m_nameEdit->enterPressed().connect(this, &Application::greet); - - auto app = Amass::Singleton::instance(); - - m_root->addWidget(std::make_unique()); internalPathChanged().connect(this, &Application::handlePathChange); handlePathChange(m_externalPath.empty() ? internalPath() : m_externalPath); } @@ -90,11 +64,6 @@ Application::Application(const Wt::WEnvironment &env, bool embedded) : Wt::WAppl Application::~Application() { } -void Application::greet() { - m_greeting->setText("Hello there, " + m_nameEdit->text()); - setInternalPath(m_externalPath); -} - void Application::authEvent() { if (m_session->login().loggedIn()) { const Wt::Auth::User &u = m_session->login().user(); @@ -114,6 +83,9 @@ void Application::handlePathChange(const std::string &path) { } else if (path.starts_with("/wt/visitor/analysis")) { m_root->clear(); m_root->addNew(*m_session); + } else { + m_root->clear(); + m_root->addNew(); } } diff --git a/WebApplication/Application.h b/WebApplication/Application.h index a9a8c6f..5f30793 100644 --- a/WebApplication/Application.h +++ b/WebApplication/Application.h @@ -27,13 +27,10 @@ public: ~Application(); protected: - void greet(); void authEvent(); void handlePathChange(const std::string &path); private: - Wt::WLineEdit *m_nameEdit = nullptr; - Wt::WText *m_greeting = nullptr; std::unique_ptr m_session; std::string m_externalPath; diff --git a/WebApplication/BulmaTheme.cpp b/WebApplication/BulmaTheme.cpp index 4c26411..03dff5b 100644 --- a/WebApplication/BulmaTheme.cpp +++ b/WebApplication/BulmaTheme.cpp @@ -1,6 +1,7 @@ #include "BulmaTheme.h" #include "BoostLog.h" #include +#include #include #include #include @@ -11,6 +12,19 @@ namespace std { std::ostream &operator<<(std::ostream &os, Wt::DomElementType type); } +void BulmaTheme::init(Wt::WApplication *app) const { + Wt::WString v = app->metaHeader(Wt::MetaHeaderType::Meta, "viewport"); + if (v.empty()) { + // app->addMetaHeader("viewport", "width=device-width, initial-scale=1"); + app->doJavaScript(R"( + var meta = document.createElement('meta'); + meta.name = 'viewport'; + meta.content = 'width=device-width, initial-scale=1'; + document.getElementsByTagName('head')[0].appendChild(meta); + )"); + } +} + std::string BulmaTheme::disabledClass() const { return ""; } @@ -38,6 +52,40 @@ bool BulmaTheme::canStyleAnchorAsButton() const { } void BulmaTheme::apply(Wt::WWidget *widget, Wt::WWidget *child, int widgetRole) const { + using namespace Wt; + if (!widget->isThemeStyleEnabled()) return; + switch (widgetRole) { + case DialogContent: { + child->addStyleClass("bulma-modal-content"); + break; + } + case DialogCoverWidget: { + child->addStyleClass("bulma-modal-backdrop"); + break; + } + case DialogTitleBar: { + child->addStyleClass("bulma-modal-card-head"); + child->setAttributeValue("style", "justify-content: space-between"); + break; + } + case DialogBody: { + child->addStyleClass("bulma-modal-card-body"); + break; + } + case DialogFooter: { + child->addStyleClass("bulma-modal-card-foot bulma-buttons"); + break; + } + case DialogCloseIcon: { + auto parent = dynamic_cast(child->parent()); + auto self = parent->removeWidget(child); + parent->addWidget(std::move(self)); + child->addStyleClass("bulma-delete"); + break; + } + default: + break; + } } void BulmaTheme::apply(Wt::WWidget *widget, Wt::DomElement &element, int elementRole) const { @@ -55,9 +103,11 @@ void BulmaTheme::apply(Wt::WWidget *widget, Wt::DomElement &element, int element break; } case Wt::DomElementType::DIV: { - Wt::WDialog *dialog = dynamic_cast(widget); - if (dialog) { - element.addPropertyWord(Wt::Property::Class, "modal-content"); + if (Wt::WDialog *dialog = dynamic_cast(widget); dialog != nullptr) { + element.addPropertyWord(Wt::Property::Class, "bulma-modal bulma-is-active"); + return; + } else if (auto text = dynamic_cast(widget); text != nullptr) { + element.addPropertyWord(Wt::Property::Class, "is-size-6"); return; } break; diff --git a/WebApplication/BulmaTheme.h b/WebApplication/BulmaTheme.h index 6cf1ebc..3aa4b30 100644 --- a/WebApplication/BulmaTheme.h +++ b/WebApplication/BulmaTheme.h @@ -12,6 +12,7 @@ class BulmaTheme : public Wt::WTheme { public: BulmaTheme(const std::string &name, bool global = true); std::string name() const final; + void init(Wt::WApplication *app) const final; std::string disabledClass() const final; std::string activeClass() const final; std::string utilityCssClass(int utilityCssClassRole) const final; diff --git a/WebApplication/CMakeLists.txt b/WebApplication/CMakeLists.txt index 86ceb49..a98a8ec 100644 --- a/WebApplication/CMakeLists.txt +++ b/WebApplication/CMakeLists.txt @@ -2,8 +2,9 @@ find_package(Wt REQUIRED Wt) add_library(WebApplication Application.h Application.cpp - LoginPage.h LoginPage.cpp BulmaTheme.h BulmaTheme.cpp + HomePage.h HomePage.cpp + LoginPage.h LoginPage.cpp VisitorRecordsPage.h VisitorRecordsPage.cpp VisitorRecordTableModel.h VisitorRecordTableModel.cpp Restful.h Restful.cpp diff --git a/WebApplication/Dialog.cpp b/WebApplication/Dialog.cpp index 32d7bca..5a7e109 100644 --- a/WebApplication/Dialog.cpp +++ b/WebApplication/Dialog.cpp @@ -9,7 +9,7 @@ Dialog::Dialog() { textdiv->setStyleClass("text"); Wt::WContainerWidget *buttons = addWidget(std::make_unique()); - buttons->setStyleClass("buttons"); + buttons->setStyleClass("bulma-buttons"); Wt::WPushButton *button = buttons->addWidget(std::make_unique("One liner")); button->clicked().connect(this, &Dialog::messageBox1); @@ -42,8 +42,7 @@ void Dialog::messageBox1() { void Dialog::messageBox2() { m_messageBox = std::make_unique("Question", "Are you getting comfortable?", Wt::Icon::Question, - Wt::StandardButton::Yes | Wt::StandardButton::No | - Wt::StandardButton::Cancel); + Wt::StandardButton::Yes | Wt::StandardButton::No | Wt::StandardButton::Cancel); m_messageBox->buttonClicked().connect(this, &Dialog::messageBoxDone); @@ -68,14 +67,13 @@ void Dialog::messageBox4() { Wt::Icon::None, Wt::StandardButton::None); m_messageBox->addButton("Discard Modifications", Wt::StandardButton::Ok); + m_messageBox->setMovable(false); + m_messageBox->setClosable(true); Wt::WPushButton *continueButton = m_messageBox->addButton("Cancel", Wt::StandardButton::Cancel); m_messageBox->setDefaultButton(continueButton); m_messageBox->buttonClicked().connect(this, &Dialog::messageBoxDone); - - m_messageBox->setOffsets(0, Wt::Side::Bottom); - m_messageBox->animateShow(Wt::WAnimation(Wt::AnimationEffect::SlideInFromBottom | Wt::AnimationEffect::Fade, - Wt::TimingFunction::Linear, 250)); + m_messageBox->animateShow(Wt::WAnimation(Wt::AnimationEffect::SlideInFromBottom | Wt::AnimationEffect::Fade, Wt::TimingFunction::Linear, 250)); } void Dialog::custom() { diff --git a/WebApplication/HomePage.cpp b/WebApplication/HomePage.cpp new file mode 100644 index 0000000..b26fd99 --- /dev/null +++ b/WebApplication/HomePage.cpp @@ -0,0 +1,39 @@ +#include "HomePage.h" +#include "Dialog.h" +#include +#include +#include + +HomePage::HomePage() { + addStyleClass("bulma-content"); + auto p = addWidget(std::make_unique("这是一个结合 C++ Web Toolkit 和 CSS Bulma 框架的前后端一体应用程序。")); + p->setInline(false); + + auto ul = addWidget(std::make_unique()); + ul->setList(true); + auto li = ul->addWidget(std::make_unique(R"(登录页面)")); + li->setHtmlTagName("li"); + li = ul->addWidget(std::make_unique(R"(访客数据)")); + li->setHtmlTagName("li"); + + addWidget(std::make_unique("Your name, please ? ")); + m_nameEdit = addWidget(std::make_unique()); + m_nameEdit->setFocus(); + + auto b = addWidget(std::make_unique("点击我!")); + b->setMargin(5, Wt::Side::Left); + + addWidget(std::make_unique()); + + m_greeting = addWidget(std::make_unique()); + + b->clicked().connect(this, &HomePage::greet); + m_nameEdit->enterPressed().connect(this, &HomePage::greet); + + addWidget(std::make_unique()); +} + +void HomePage::greet() { + m_greeting->setText("Hello there, " + m_nameEdit->text()); + Wt::WApplication::instance()->setInternalPath("/hello"); +} diff --git a/WebApplication/HomePage.h b/WebApplication/HomePage.h new file mode 100644 index 0000000..db8cc85 --- /dev/null +++ b/WebApplication/HomePage.h @@ -0,0 +1,18 @@ +#ifndef __HOMEPAGE_H__ +#define __HOMEPAGE_H__ + +#include + +class HomePage : public Wt::WContainerWidget { +public: + HomePage(); + + protected: + void greet(); + +private: + Wt::WLineEdit *m_nameEdit = nullptr; + Wt::WText *m_greeting = nullptr; +}; + +#endif // __HOMEPAGE_H__ \ No newline at end of file diff --git a/resources/wt_zh.xml b/resources/wt_zh.xml index db14d22..49e3fe1 100644 --- a/resources/wt_zh.xml +++ b/resources/wt_zh.xml @@ -273,6 +273,6 @@ -

${title}

+

${title}