Added timestamp logging for client logins, enhanced admin login display with date and time columns, and updated CSS for improved user interaction. Adjusted CMake configuration for better project management.

This commit is contained in:
Torsten Schulz (local)
2025-11-16 12:42:14 +01:00
parent 0964f584d2
commit e869abde5d
5 changed files with 703 additions and 137 deletions

View File

@@ -605,6 +605,8 @@ void App::showAdminLogins() {
table->elementAt(0, 1)->addNew<Wt::WText>("Country");
table->elementAt(0, 2)->addNew<Wt::WText>("Gender");
table->elementAt(0, 3)->addNew<Wt::WText>("Age");
table->elementAt(0, 4)->addNew<Wt::WText>("Datum");
table->elementAt(0, 5)->addNew<Wt::WText>("Uhrzeit");
int row = 1;
for (const auto& item : jsonArray) {
Wt::Json::Object jsonData = item;
@@ -612,13 +614,45 @@ void App::showAdminLogins() {
std::string country = jsonData.get("country").orIfNull("");
std::string gender = jsonData.get("gender").orIfNull("");
int age = jsonData.get("age").orIfNull(0);
std::string timestamp = jsonData.get("timestamp").orIfNull("");
auto nameCell = table->elementAt(row, 0)->addNew<Wt::WText>(name);
nameCell->setStyleClass("padding-right");
auto countryCell = table->elementAt(row, 1)->addNew<Wt::WText>(country);
countryCell->setStyleClass("padding-right");
auto genderCell = table->elementAt(row, 2)->addNew<Wt::WText>(gender);
genderCell->setStyleClass("padding-right");
table->elementAt(row, 3)->addNew<Wt::WText>(std::to_string(age));
auto ageCell = table->elementAt(row, 3)->addNew<Wt::WText>(std::to_string(age));
ageCell->setStyleClass("padding-right");
// Zeitstempel in deutsches Format umwandeln (falls vorhanden und gültig)
if (!timestamp.empty()) {
std::istringstream ss(timestamp);
std::tm tm{};
ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S");
if (!ss.fail()) {
std::ostringstream dateStream;
std::ostringstream timeStream;
dateStream.imbue(std::locale("de_DE.utf8"));
timeStream.imbue(std::locale("de_DE.utf8"));
dateStream << std::put_time(&tm, "%d.%m.%Y");
timeStream << std::put_time(&tm, "%H:%M:%S");
auto dateCell = table->elementAt(row, 4)->addNew<Wt::WText>(dateStream.str());
dateCell->setStyleClass("padding-right");
table->elementAt(row, 5)->addNew<Wt::WText>(timeStream.str());
} else {
// Fallback bei ungültigem Zeitstempel
auto dateCell = table->elementAt(row, 4)->addNew<Wt::WText>("-");
dateCell->setStyleClass("padding-right");
table->elementAt(row, 5)->addNew<Wt::WText>("-");
}
} else {
// Fallback für alte Einträge ohne Zeitstempel
auto dateCell = table->elementAt(row, 4)->addNew<Wt::WText>("-");
dateCell->setStyleClass("padding-right");
table->elementAt(row, 5)->addNew<Wt::WText>("-");
}
row++;
}
}
@@ -1182,14 +1216,21 @@ void App::showHistory(Wt::Json::Object broadcast) {
auto headerWidget = contentContainer_->addNew<Wt::WText>("<h2>Conversations with already logged in users</h2>");
headerWidget->setInline(false);
auto listWidget = contentContainer_->addNew<Wt::WTable>();
for (Wt::Json::Object user: (Wt::Json::Array)broadcast["data"]) {
auto userName = std::make_shared<std::string>((std::string)user["name"]);
auto tableCell = listWidget->elementAt(listWidget->rowCount(), 0);
tableCell->addNew<Wt::WText>(Wt::WString("{1} ({2})").arg(*userName).arg((int)user["age"]));
tableCell->setStyleClass(Wt::WString("user-conversation-info userlist-item userlist-gender-{1}").arg((std::string)user["gender"]));
tableCell->clicked().connect([=, this]() {
requestConversation(*userName);
});
auto dataArray = (Wt::Json::Array)broadcast["data"];
if (dataArray.empty()) {
// Keine bisherigen Unterhaltungen vorhanden
contentContainer_->addNew<Wt::WText>("No previous conversations available.");
} else {
for (Wt::Json::Object user: dataArray) {
auto userName = std::make_shared<std::string>((std::string)user["name"]);
auto tableCell = listWidget->elementAt(listWidget->rowCount(), 0);
tableCell->addNew<Wt::WText>(Wt::WString("{1} ({2})").arg(*userName).arg((int)user["age"]));
tableCell->setStyleClass(Wt::WString("user-conversation-info userlist-item userlist-gender-{1}").arg((std::string)user["gender"]));
tableCell->clicked().connect([=, this]() {
requestConversation(*userName);
});
}
}
} catch(std::exception &e) {
std::cout << e.what() << std::endl;

View File

@@ -75,7 +75,14 @@ void Broadcast::logClientLogin(const Wt::Json::Object &clientJson) {
Wt::Json::parse(fileContent, logArray);
}
}
logArray.push_back(clientJson);
// Zeitstempel hinzufügen
Wt::Json::Object logEntry = clientJson;
Wt::WDateTime now = Wt::WDateTime::currentDateTime();
std::string timestamp = now.toString("yyyy-MM-dd HH:mm:ss").toUTF8();
logEntry["timestamp"] = Wt::Json::Value(timestamp);
logArray.push_back(logEntry);
std::ofstream outfile(logFilePath);
if (outfile.is_open()) {
outfile << Wt::Json::serialize(logArray) << std::endl;