Add UserOperationLog.
This commit is contained in:
@@ -34,12 +34,25 @@ UserOperationLogForm::UserOperationLogForm(QWidget* parent) {
|
||||
btn = new QPushButton(header);
|
||||
headerLayout->addWidget(btn, 0, Qt::AlignLeft);
|
||||
headerLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
|
||||
table = new SlideTableView(this);
|
||||
layout->addWidget(header);
|
||||
layout->addWidget(table);
|
||||
|
||||
model = new LogFileTableModel(this);
|
||||
model->setHeader(QStringList()<< "Operation Date" << "Operation Time" << "User" << "Operation");
|
||||
loadUserOperationLog();
|
||||
table = new SlideTableView(this);
|
||||
layout->addWidget(header);
|
||||
layout->addWidget(table);
|
||||
table->setModel(model);
|
||||
table->setAlternatingRowColors(true);
|
||||
table->setSelectionMode(QAbstractItemView::NoSelection);
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
table->verticalHeader()->setDefaultSectionSize(38);
|
||||
table->horizontalHeader()->setStretchLastSection(true);
|
||||
table->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
||||
table->setColumnWidth(0, 250);
|
||||
table->setColumnWidth(1, 250);
|
||||
table->setColumnWidth(2, 200);
|
||||
//暂时先放构造函数,之后需要移除,等需要时再调用
|
||||
loadUserOperationLog();
|
||||
|
||||
connect(btn, &QPushButton::clicked, [=]() {
|
||||
auto files = UserOperationLog::getHistoryLogFiles();
|
||||
QStringList dates;
|
||||
@@ -75,7 +88,6 @@ UserOperationLogForm::~UserOperationLogForm() {
|
||||
void UserOperationLogForm::loadUserOperationLog() {
|
||||
|
||||
QString filePath = UserOperationLog::Default()->currentLogFile();
|
||||
model->setFileName(filePath);
|
||||
btn->setText(fileNameToDate(filePath));
|
||||
loadUserOperationLog(filePath, fileNameToDate(filePath));
|
||||
selectedDateStr = fileNameToDate(filePath);
|
||||
@@ -83,22 +95,12 @@ void UserOperationLogForm::loadUserOperationLog() {
|
||||
|
||||
void UserOperationLogForm::loadUserOperationLog(const QString& fileName, const QString& date) {
|
||||
selectedDateStr = date;
|
||||
model->setFileName(dateToFileName(date));
|
||||
model->setFileName(dateToFileName(date));
|
||||
btn->setText(date);
|
||||
QStringList header;
|
||||
header << "Operation Date" << "Operation Time" << "User" << "Operation";
|
||||
model->setHeader(header);
|
||||
// UserOperationLog::getHistoryLogFiles();
|
||||
delete table;
|
||||
table = new SlideTableView(this);
|
||||
layout->addWidget(table);
|
||||
table->setModel(model);
|
||||
|
||||
table->setAlternatingRowColors(true);
|
||||
table->setSelectionMode(QAbstractItemView::NoSelection);
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
table->verticalHeader()->setDefaultSectionSize(38);
|
||||
table->horizontalHeader()->setStretchLastSection(true);
|
||||
table->setColumnWidth(0, 250);
|
||||
table->setColumnWidth(1, 250);
|
||||
}
|
||||
|
||||
void UserOperationLogForm::showEvent(QShowEvent *aEvent)
|
||||
{
|
||||
loadUserOperationLog("", selectedDateStr);
|
||||
QWidget::showEvent(aEvent);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//
|
||||
// Created by Krad on 2021/11/23.
|
||||
//
|
||||
|
||||
#ifndef GUI_USEROPERATIONLOGFORM_H
|
||||
#define GUI_USEROPERATIONLOGFORM_H
|
||||
|
||||
@@ -19,6 +15,9 @@ public:
|
||||
void loadUserOperationLog();
|
||||
void loadUserOperationLog(const QString& fileName, const QString& date);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *aEvent) override;
|
||||
|
||||
private:
|
||||
QTableView* table = nullptr;
|
||||
QPushButton* btn = nullptr;
|
||||
|
||||
@@ -100,6 +100,6 @@ bool ChangePasswordFormDialog::updateReferenceData()
|
||||
User::Current()->restorePassword(encryptPwd);
|
||||
return false;
|
||||
}
|
||||
LOG_USER_OPERATION(ChangePassword);
|
||||
LOG_USER_OPERATION("Change Password");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ void GUIMessageDialog::startLoading() {
|
||||
}
|
||||
accept();
|
||||
EventCenter::Default()->triggerEvent(GUIEvents::RequestFullScanStop, nullptr, nullptr);
|
||||
LOG_USER_OPERATION(Stop);
|
||||
LOG_USER_OPERATION("Stop Scan");
|
||||
});
|
||||
mTimerID = startTimer(100);
|
||||
mBtnMain->setVisible(true);
|
||||
@@ -117,7 +117,7 @@ void GUIMessageDialog::showExitButton() {
|
||||
mTimerID = -1;
|
||||
}
|
||||
accept();
|
||||
LOG_USER_OPERATION(ConfirmError);
|
||||
LOG_USER_OPERATION("Confirm Error");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "components/ULineEdit.h"
|
||||
#include "action/GetWorkListAction.h"
|
||||
#include "action/ActionCreator.h"
|
||||
#include "log/UserOperationLog.h"
|
||||
|
||||
GetWorkListDialog::GetWorkListDialog(QSqlTableModel* aSqlModel, QTableView* aTableView, QWidget* aParent, Qt::WindowFlags aFlags)
|
||||
: AsyncActionDialog(ActionCreator::getAsyncAction<GetWorkListAction>("GetWorkListAction"),"Work List", aParent, aFlags)
|
||||
@@ -254,4 +255,5 @@ void GetWorkListDialog::insertPatient(PatientInformationPointer aPatient)
|
||||
mErrorLabel->show();
|
||||
}
|
||||
mTableView->selectRow(0);
|
||||
LOG_USER_OPERATION(QString("Add Patient, ID:%1").arg(aPatient->ID));
|
||||
}
|
||||
|
||||
@@ -51,7 +51,11 @@ ReconFormWidget::ReconFormWidget(QWidget *parent)
|
||||
contentLayout->setContentsMargins(0, 0, 0, 0);
|
||||
initTableView(contentLayout);
|
||||
|
||||
connect(mBtnRefresh, &QToolButton::clicked, DeviceManager::Default(), &DeviceManager::updateReconState);
|
||||
connect(mBtnRefresh, &QToolButton::clicked, []()
|
||||
{
|
||||
LOG_USER_OPERATION("Update Recon State")
|
||||
DeviceManager::Default()->updateReconState();
|
||||
});
|
||||
connect(DeviceManager::Default(), &DeviceManager::updateReconStateFinished, mModel, &QSqlTableModel::select);
|
||||
connect(DeviceManager::Default(), &DeviceManager::transferStatusUpdated, mModel, &QSqlTableModel::select);
|
||||
connect(mSearchWidget, &ScanSearchCriteriaForm::searchFilterUpdated, this, &ReconFormWidget::updateSearchFilter);
|
||||
@@ -157,7 +161,7 @@ void ReconFormWidget::deleteReconRecord()
|
||||
{
|
||||
mScanTable->selectRow(0);
|
||||
mModel->selectRow(0);
|
||||
LOG_USER_OPERATION(DeletePatient)
|
||||
LOG_USER_OPERATION(QString("Delete Recon, ID: %1").arg(mModel->index(currentRowIndex, getTableColumnIndex("PatientID")).data().toString()))
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -47,6 +47,11 @@ void PatientInformationForm::setProtocol(int type) {
|
||||
}
|
||||
}
|
||||
|
||||
QString PatientInformationForm::getPatientID()
|
||||
{
|
||||
return mUI->lbl_ID->text();
|
||||
}
|
||||
|
||||
const char* PatientInformationForm::getCurrentPatientJsonString(bool empty)
|
||||
{
|
||||
cJSON* patientInfoObject = cJSON_CreateObject();
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
void setPatientInformation(PatientInformation* information);
|
||||
void setProtocol(int type);
|
||||
const char * getCurrentPatientJsonString(bool emptyScan);
|
||||
QString getPatientID();
|
||||
private:
|
||||
Ui::PatientInformationForm *mUI;
|
||||
PatientInformation* mInfo = nullptr;
|
||||
|
||||
@@ -122,12 +122,13 @@ void SelectFormWidget::editPatient() {
|
||||
if (addFlag){
|
||||
mPatTable->selectRow(0);
|
||||
mModel->selectRow(0);
|
||||
LOG_USER_OPERATION(QString("Add Patient, ID: %1").arg(patientDetailForm->getPatientInformation()->ID))
|
||||
}
|
||||
else{
|
||||
mPatTable->clicked(mPatTable->currentIndex());
|
||||
setPatientDetail(mPatTable, mModel, patientDetailForm);
|
||||
LOG_USER_OPERATION(QString("Edit Patient, ID: %1").arg(patientDetailForm->getPatientInformation()->ID))
|
||||
}
|
||||
LOG_USER_OPERATION(AddPatient)
|
||||
mBtnSelect->setEnabled(true);
|
||||
}
|
||||
}
|
||||
@@ -154,7 +155,7 @@ void SelectFormWidget::delPatient() {
|
||||
mPatTable->selectRow(0);
|
||||
mModel->selectRow(0);
|
||||
setPatientDetail(mPatTable, mModel, patientDetailForm);
|
||||
LOG_USER_OPERATION(DeletePatient)
|
||||
LOG_USER_OPERATION(QString("Delete Patient, ID: %1").arg(patientDetailForm->getPatientInformation()->ID))
|
||||
}
|
||||
} else {
|
||||
//TODO:error handle
|
||||
@@ -166,7 +167,7 @@ void SelectFormWidget::delPatient() {
|
||||
void SelectFormWidget::selectPatient() {
|
||||
EventCenter::Default()->triggerEvent(PatientSelected, nullptr, patientDetailForm->getPatientInformation()->Copy());
|
||||
selectedPatientUID = patientDetailForm->getPatientInformation()->PatientUID;
|
||||
LOG_USER_OPERATION(SelectPatient)
|
||||
LOG_USER_OPERATION(QString("Select Patient, ID: %1").arg(patientDetailForm->getPatientInformation()->ID))
|
||||
}
|
||||
|
||||
void SelectFormWidget::initDetailPanel(QHBoxLayout *contentLayout) {// prepare edit panel
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "utilities/LanguageSwitcher.h"
|
||||
#include "components/ULineEdit.h"
|
||||
#include "components/ListBox.h"
|
||||
#include "log/UserOperationLog.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -101,6 +102,7 @@ GeneralForm::GeneralForm(QWidget* aParent)
|
||||
{
|
||||
if(DialogManager::Default()->requestAlertMessage(QString(tr("Shut down now ?")), DialogButtonMode::OkAndCancel,tr("Shut Down")) == QDialog::Accepted)
|
||||
{
|
||||
LOG_USER_OPERATION("Shut Down")
|
||||
EventCenter::Default()->triggerEvent(GUIEvents::RequestShutdown, nullptr, nullptr);
|
||||
}
|
||||
});
|
||||
@@ -134,6 +136,7 @@ GeneralForm::GeneralForm(QWidget* aParent)
|
||||
return;
|
||||
}
|
||||
second = result.ResultData.toInt();
|
||||
LOG_USER_OPERATION(QString("Set Screen Lock Time to %1 seconds").arg(second))
|
||||
if(second == 0)
|
||||
{
|
||||
JsonObject::Instance()->setLockScreenTimeout(QString::number(second));
|
||||
@@ -163,6 +166,7 @@ GeneralForm::GeneralForm(QWidget* aParent)
|
||||
JsonObject::Instance()->setDefaultLanguage(language);
|
||||
LanguageSwitcher::getInstance()->setDefaultLanguage(language);
|
||||
btnLan->setText(JsonObject::Instance()->defaultLanguage());
|
||||
LOG_USER_OPERATION(QString("Change Language to %1").arg(language))
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "AccountTableForm.h"
|
||||
#include "event/EventCenter.h"
|
||||
#include "AboutForm.h"
|
||||
#include "UserOperationLogForm.h"
|
||||
|
||||
SettingFormWidget::SettingFormWidget(QWidget* aParent, Qt::WindowFlags f)
|
||||
: TabFormWidget(aParent)
|
||||
@@ -27,7 +28,7 @@ SettingFormWidget::SettingFormWidget(QWidget* aParent, Qt::WindowFlags f)
|
||||
QListWidget* widget = new QListWidget(ui->contentWidget);
|
||||
widget->setFixedWidth(250);
|
||||
QStringList menus;
|
||||
menus << tr("General") << tr("Account") << tr("System") << tr("About");
|
||||
menus << tr("General") << tr("Account") << tr("System") << tr("About") << tr("Operation Log");
|
||||
widget->addItems(menus);
|
||||
widget->setSpacing(3);
|
||||
for (int i = 0; i < menus.count(); ++i)
|
||||
@@ -55,13 +56,16 @@ SettingFormWidget::SettingFormWidget(QWidget* aParent, Qt::WindowFlags f)
|
||||
AboutForm* about = new AboutForm(ui->commandWidget);
|
||||
stackedWidget->addWidget(about);
|
||||
|
||||
UserOperationLogForm* operationLog = new UserOperationLogForm(ui->commandWidget);
|
||||
stackedWidget->addWidget(operationLog);
|
||||
|
||||
widget->setCurrentRow(0);
|
||||
connect(widget, &QListWidget::currentRowChanged, [=](int rowindex) {
|
||||
stackedWidget->setCurrentIndex(rowindex);
|
||||
});
|
||||
connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() {
|
||||
QStringList menus;
|
||||
menus << tr("General") << tr("Account") << tr("System") << tr("About");
|
||||
menus << tr("General") << tr("Account") << tr("System") << tr("About") << tr("Operation Log");
|
||||
widget->clear();
|
||||
widget->addItems(menus);
|
||||
for (int i = 0; i < menus.count(); ++i)
|
||||
|
||||
@@ -549,3 +549,8 @@ bool JsonObject::isDmsSimulator()
|
||||
{
|
||||
return getBool("dms","simulator");
|
||||
}
|
||||
|
||||
int JsonObject::getOperationLogExpireDays()
|
||||
{
|
||||
return QString(getJsonString("operatorlog", "expire")).toInt();
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@ public:
|
||||
void setIpRouteList(const QList<QStringList>& list);
|
||||
|
||||
QStringList getScreenSaverInfomation();
|
||||
int getOperationLogExpireDays();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -12,6 +12,7 @@ LogFileTableModel::LogFileTableModel(QObject *parent) : QAbstractTableModel(pare
|
||||
}
|
||||
|
||||
void LogFileTableModel::setFileName(QString fileName) {
|
||||
beginResetModel();
|
||||
if (!logdata.isEmpty())logdata.clear();
|
||||
qDebug()<<fileName;
|
||||
QFile f;
|
||||
@@ -25,6 +26,7 @@ void LogFileTableModel::setFileName(QString fileName) {
|
||||
logdata.push_back(in.readLine().split("\t"));
|
||||
}
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QVariant LogFileTableModel::data(const QModelIndex &index, int role) const {
|
||||
|
||||
@@ -3,15 +3,18 @@
|
||||
//
|
||||
|
||||
#include "UserOperationLog.h"
|
||||
#include <QDate>
|
||||
#include <QDir>
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
#include "models/User.h"
|
||||
#include <json/jsonobject.h>
|
||||
|
||||
#include <QDirIterator>
|
||||
#include <qdebug.h>
|
||||
#include <QDate>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
const char * logDir = "./log";
|
||||
namespace
|
||||
{
|
||||
const QString logDir = "./log";
|
||||
}
|
||||
|
||||
void UserOperationLog::init() {
|
||||
QDir log_dir("./");
|
||||
@@ -58,15 +61,13 @@ QString getOperationName(UserOperation operation)
|
||||
|
||||
}
|
||||
|
||||
void UserOperationLog::log(UserOperation operation, bool processing) {
|
||||
void UserOperationLog::log(const QString& aOperationText)
|
||||
{
|
||||
reloadFile();
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
AppGlobalValues::setLastOperationTime(now);
|
||||
AppGlobalValues::setLastOperation(operation);
|
||||
QString operationName = getOperationName(operation);
|
||||
AppGlobalValues::setInProcessing(processing);
|
||||
QString UserName = (!User::Current() || User::Current()->getUserCode().isEmpty())?"anonymous":User::Current()->getUserCode();
|
||||
out << now.toString(Qt::DateFormat::ISODateWithMs).replace("T","\t")<<"\t"<<UserName<<"\t"<<operationName<<endl;
|
||||
out << now.toString(Qt::DateFormat::ISODateWithMs).replace("T","\t")<<"\t"<<UserName<<"\t"<<aOperationText<<endl;
|
||||
}
|
||||
|
||||
void UserOperationLog::reloadFile() {
|
||||
@@ -91,7 +92,6 @@ QStringList UserOperationLog::getHistoryLogFiles() {
|
||||
{
|
||||
iter.next();
|
||||
list << iter.fileInfo().absoluteFilePath();
|
||||
qDebug()<<iter.fileInfo().absoluteFilePath();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -109,3 +109,23 @@ void UserOperationLog::loadLogFromFile(QString path, QStringList& result) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UserOperationLog::cleanHistoryLog()
|
||||
{
|
||||
int expireDays = JsonObject::Instance()->getOperationLogExpireDays();
|
||||
QDateTime currentDate = QDateTime::currentDateTime();
|
||||
QDateTime deleteDate = currentDate.addDays(-expireDays);
|
||||
|
||||
QDir dir(logDir);
|
||||
QStringList logFiles = dir.entryList(QStringList() << "*.log", QDir::Files);
|
||||
for(const QString &logFile : logFiles)
|
||||
{
|
||||
QString filePath = logDir + "/" + logFile;
|
||||
QFileInfo fileInfo(filePath);
|
||||
QDateTime fileDate = fileInfo.created();
|
||||
if (fileDate <= deleteDate)
|
||||
{
|
||||
QFile::remove(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ ADD_OPERATION(ChangePatientInfo)\
|
||||
ADD_OPERATION(DeletePatient)\
|
||||
ADD_OPERATION(SelectPatient)\
|
||||
ADD_OPERATION(StartRefresh)\
|
||||
ADD_OPERATION(Stop)\
|
||||
ADD_OPERATION(StopScan)\
|
||||
ADD_OPERATION(StopPreview)\
|
||||
ADD_OPERATION(StartPreview)\
|
||||
ADD_OPERATION(StartScan)\
|
||||
ADD_OPERATION(ConfirmError)\
|
||||
@@ -55,7 +56,7 @@ public:
|
||||
|
||||
static QStringList getHistoryLogFiles();
|
||||
|
||||
void log(UserOperation operation, bool processing = false);
|
||||
void log(const QString& aOperationText);
|
||||
void reloadFile();
|
||||
QString currentLogFile(){
|
||||
return currentFileName;
|
||||
|
||||
@@ -96,6 +96,7 @@ int main(int argc, char* argv[])
|
||||
QStringList app_args = a.arguments();
|
||||
int ret = 0;
|
||||
KeyboardManager::getInstance();
|
||||
UserOperationLog::cleanHistoryLog();
|
||||
|
||||
if (app_args.contains("-d"))
|
||||
//if (true)
|
||||
|
||||
@@ -124,12 +124,13 @@ void LoginDialog::doLogin()
|
||||
{
|
||||
mErrorMessage->setVisible(false);
|
||||
accept();
|
||||
LOG_USER_OPERATION(Login);
|
||||
LOG_USER_OPERATION("Login Sucessful");
|
||||
JsonObject::Instance()->setDefaultUser(strUserCode);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_USER_OPERATION(QString("Login Failed, User Name: %1").arg(strUserCode));
|
||||
mErrorMessage->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user