Project

General

Profile

Bug #13933 » 0002-Log-estimate-of-browser-wait-time-in-ChartsExample.patch

Bruce Toll, 08/15/2025 12:02 AM

View differences:

examples/charts/ChartsApplication.C
*/
#include <Wt/WApplication.h>
#include <Wt/WDefaultLoadingIndicator.h>
#include <Wt/WStringStream.h>
#include "ChartsExample.h"
using namespace Wt;
class customLoadingIndicator: public WDefaultLoadingIndicator
{
public:
customLoadingIndicator() : WDefaultLoadingIndicator(),
handleShow_(this, "handleShow"),
handleHide_(this, "handleHide")
{
WStringStream js1;
js1 << "Wt.emit(" << jsRef() << ", 'handleShow', Date.now());";
implementJavaScript(&WWidget::show, js1.str());
WStringStream js2;
js2 << "Wt.emit(" << jsRef() << ", 'handleHide', Date.now());";
implementJavaScript(&WWidget::hide, js2.str());
handleShow_.connect(std::bind(&customLoadingIndicator::handleShow, this, std::placeholders::_1));
handleHide_.connect(std::bind(&customLoadingIndicator::handleHide, this, std::placeholders::_1));
}
void handleShow(std::string show_time_s) {
log("info") << "handleShow: " << show_time_s;
last_shown = stol(show_time_s);
}
void handleHide(std::string hide_time_s) {
log("info") << "handleHide: " << hide_time_s;
long hide_time = stol(hide_time_s);
if (last_shown) {
long elapsed = hide_time - last_shown + 500;
log("info") << "wait indicator was shown for " << elapsed << "ms";
}
}
void setHidden(bool hidden, const WAnimation &animation=WAnimation() ) override {
Wt::WCompositeWidget::setHidden(hidden, animation);
Wt::log("info") << "setHidden called";
}
private:
long last_shown = 0;
JSignal<std::string> handleShow_;
JSignal<std::string> handleHide_;
};
class ChartsApplication: public WApplication
{
public:
......
* Set our style sheet last, so that it loaded after the ext stylesheets.
*/
useStyleSheet("charts.css");
auto loadingIndicator = std::make_unique<customLoadingIndicator>();
setLoadingIndicator(std::move(loadingIndicator));
}
};
(2-2/3)