Commit 5199cad2 authored by Martin Straka's avatar Martin Straka

Records management settings page refactoring

parent b19aca0e
......@@ -41,12 +41,6 @@ Item {
clearButton.enabled = infoButton.enabled
}
/* Enable data update and anothers labels if service name and token are filled */
function areServiceInfoAvailable() {
serviceInfo.visible = (serviceName.text.toString() !== "" && tokenName.text.toString() !== "")
infoButton.text = (updateRmDataButton.visible) ? qsTr("Update service info") : qsTr("Get service info")
}
/* Clear all data and info */
function clearAll() {
urlTextField.clear()
......@@ -63,6 +57,7 @@ Item {
tokenTextField.text = settings.rmToken()
areUrlandTokenFilled()
recordsManagement.loadStoredServiceInfo()
updateRmDataButton.visible = recordsManagement.isValidRecordsManagement()
}
PageHeader {
......@@ -83,9 +78,9 @@ Item {
source: "qrc:/ui/checkbox-marked-circle.svg"
accessibleName: qsTr("Accept changes")
onClicked: {
recordsManagement.updateServiceInfo(urlTextField.text, lastUrlFromSettings, serviceName.text, tokenName.text)
settings.setRmUrl(urlTextField.text)
settings.setRmToken(tokenTextField.text)
recordsManagement.updateServiceInfo(urlTextField.text, lastUrlFromSettings, serviceName.text, tokenName.text)
pageView.pop(StackView.Immediate)
}
}
......@@ -172,7 +167,8 @@ Item {
font.pointSize: defaultTextFont.font.pointSize
text: qsTr("Get service info")
onClicked: {
recordsManagement.callServiceInfo(urlTextField.text, tokenTextField.text)
serviceInfo.visible = recordsManagement.callServiceInfo(urlTextField.text, tokenTextField.text)
serviceInfoError.visible = !serviceInfo.visible
}
}
AccessibleButton {
......@@ -185,6 +181,14 @@ Item {
}
}
} // Row
AccessibleText {
id: serviceInfoError
visible: false
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
width: parent.width
text: qsTr("Communication error. Cannot obtain records management info from server. Internet connection failed or service url and identification token can be wrong!")
}
Column {
id: serviceInfo
width: parent.width
......@@ -239,12 +243,13 @@ Item {
}
AccessibleButton {
id: updateRmDataButton
visible: false
height: inputItemHeight
font.pointSize: defaultTextFont.font.pointSize
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Update list of uploaded files")
onClicked: {
recordsManagement.getStoredMsgInfoFromRecordsManagement()
recordsManagement.getStoredMsgInfoFromRecordsManagement(urlTextField.text, tokenTextField.text)
}
}
} // // Column
......@@ -255,9 +260,17 @@ Item {
Connections {
target: recordsManagement
onServiceInfo: {
serviceName.text = srName
tokenName.text = srToken
areServiceInfoAvailable()
if (srName !== "" && srToken !== "") {
serviceInfo.visible = true
infoButton.text = (serviceInfo.visible) ? qsTr("Update service info") : qsTr("Get service info")
serviceName.text = srName
tokenName.text = srToken
updateRmDataButton.visible = serviceInfo.visible
serviceInfoError.visible = false
} else {
serviceInfo.visible = false
updateRmDataButton.visible = serviceInfo.visible
}
}
}
} // Item
......@@ -110,12 +110,14 @@ RecordsManagement::~RecordsManagement(void)
globWorkPool.stop();
}
void RecordsManagement::callServiceInfo(const QString &urlStr,
const QString &tokenStr)
bool RecordsManagement::callServiceInfo(const QString &urlStr,
const QString &tokenStr)
{
QByteArray response;
QString errTitle = tr("Communication error");
QString errDesctiption = tr("Received invalid response.");
if (urlStr.trimmed().isEmpty() || tokenStr.trimmed().isEmpty()) {
return false;
}
emit statusBarTextChanged(tr("Get service info"), true, true);
......@@ -127,31 +129,29 @@ void RecordsManagement::callServiceInfo(const QString &urlStr,
bool ok = false;
ServiceInfoResp siRes(
ServiceInfoResp::fromJson(response, &ok));
if (!ok || !siRes.isValid()) {
goto fail;
if (ok && siRes.isValid()) {
m_logoSvg = siRes.logoSvg();
loadRecordsManagementPixmap(m_logoSvg);
emit serviceInfo(siRes.name(), siRes.tokenName());
emit statusBarTextChanged(tr("Done"), false, true);
return true;
}
m_logoSvg = siRes.logoSvg();
loadRecordsManagementPixmap(m_logoSvg);
emit serviceInfo(siRes.name(), siRes.tokenName());
} else {
errDesctiption = tr("Received empty response.");
goto fail;
}
}
emit statusBarTextChanged(tr("Done"), false, true);
return;
fail:
emit statusBarTextChanged(errTitle, false, true);
QMessageBox::critical(Q_NULLPTR, errTitle, errDesctiption);
emit statusBarTextChanged(tr("Communication error"), false, true);
return false;
}
void RecordsManagement::callUploadHierarchy(
const QVariant &hirerachyModelVariant)
{
QByteArray response;
QString errTitle = tr("Communication error");
QString errDesctiption = tr("Received invalid response.");
if (globRecordsManagementSet.url().isEmpty() ||
globRecordsManagementSet.token().isEmpty()) {
return;
}
emit statusBarTextChanged(tr("Upload hierarchy"), true, true);
......@@ -175,33 +175,35 @@ void RecordsManagement::callUploadHierarchy(
bool ok = false;
UploadHierarchyResp uhRes(
UploadHierarchyResp::fromJson(response, &ok));
if (!ok || !uhRes.isValid()) {
goto fail;
if (ok && uhRes.isValid()) {
/* Set model. */
hierarchyModel->setHierarchy(uhRes);
emit statusBarTextChanged(tr("Done"), false, true);
return;
}
hierarchyModel->setHierarchy(uhRes);
} else {
errDesctiption = tr("Received empty response.");
goto fail;
}
}
emit statusBarTextChanged(tr("Done"), false, true);
return;
fail:
emit statusBarTextChanged(errTitle, false, true);
QMessageBox::critical(Q_NULLPTR, errTitle, errDesctiption);
emit statusBarTextChanged(tr("Communication error"), false, true);
}
void RecordsManagement::getStoredMsgInfoFromRecordsManagement(void)
void RecordsManagement::getStoredMsgInfoFromRecordsManagement(
const QString &urlStr, const QString &tokenStr)
{
QString url = urlStr.trimmed();
QString token = tokenStr.trimmed();
if (url.isEmpty() || token.isEmpty()) {
return;
}
emit statusBarTextChanged(tr("Sync service"), true, true);
TaskRecordsManagementStoredMessages *task =
new (::std::nothrow) TaskRecordsManagementStoredMessages(
globRecordsManagementSet.url(),
globRecordsManagementSet.token(),
TaskRecordsManagementStoredMessages::RM_UPDATE_STORED,
Q_NULLPTR, QString(), 0, 0);
url, token,
TaskRecordsManagementStoredMessages::RM_UPDATE_STORED,
Q_NULLPTR, QString(), 0, 0);
if (Q_NULLPTR == task) {
qCritical("%s", "Cannot create stored_files update task.");
emit statusBarTextChanged(tr("Sync failed"), false, true);
......@@ -227,8 +229,7 @@ void RecordsManagement::getStoredMsgInfoFromRecordsManagement(void)
TaskRecordsManagementStoredMessages *task =
new (::std::nothrow) TaskRecordsManagementStoredMessages(
globRecordsManagementSet.url(),
globRecordsManagementSet.token(),
url, token,
TaskRecordsManagementStoredMessages::RM_DOWNLOAD_ALL,
msgDb, userName, accNumber, accTotal);
if (Q_NULLPTR == task) {
......@@ -245,10 +246,7 @@ void RecordsManagement::getStoredMsgInfoFromRecordsManagement(void)
bool RecordsManagement::isValidRecordsManagement(void)
{
RecordsManagementDb::ServiceInfoEntry entry(
globRecordsManagementDbPtr->serviceInfo());
return (entry.isValid() && !globRecordsManagementSet.url().isEmpty()
&& !globRecordsManagementSet.token().isEmpty());
return globRecordsManagementSet.isValid();
}
void RecordsManagement::loadStoredServiceInfo(void)
......@@ -307,28 +305,27 @@ bool RecordsManagement::uploadMessage(const QString &userName,
return uploadFile(msgId, msgFileName, msgData, uploadIds);
}
bool RecordsManagement::updateServiceInfo(const QString &urlStr,
const QString &urlStrSettings, const QString &srName, const QString &srToken)
bool RecordsManagement::updateServiceInfo(const QString &newUrlStr,
const QString &oldUrlStr, const QString &srName, const QString &srToken)
{
if (Q_NULLPTR == globRecordsManagementDbPtr) {
return false;
}
if (!urlStr.trimmed().isEmpty()) {
QString cUrlStr = newUrlStr.trimmed();
Q_ASSERT(!urlStr.trimmed().isEmpty());
if (!cUrlStr.isEmpty()) {
RecordsManagementDb::ServiceInfoEntry entry;
entry.url = urlStr.trimmed();
entry.url = cUrlStr;
entry.name = srName;
entry.tokenName = srToken;
entry.logoSvg = m_logoSvg;
globRecordsManagementDbPtr->updateServiceInfo(entry);
if (urlStrSettings != urlStr) {
globRecordsManagementDbPtr->deleteAllStoredMsg();
if (oldUrlStr != cUrlStr) {
return globRecordsManagementDbPtr->deleteAllStoredMsg();
}
} else {
globRecordsManagementDbPtr->deleteAllEntries();
return globRecordsManagementDbPtr->deleteAllEntries();
}
return true;
......@@ -373,21 +370,24 @@ void RecordsManagement::loadRecordsManagementPixmap(const QByteArray &logoSvg)
bool RecordsManagement::uploadFile(qint64 dmId, const QString &msgFileName,
const QByteArray &msgData, const QStringList &uploadIds)
{
QByteArray response;
if (msgFileName.isEmpty() || msgData.isEmpty()) {
Q_ASSERT(0);
return false;
}
if (globRecordsManagementSet.url().isEmpty() ||
globRecordsManagementSet.token().isEmpty()) {
return false;
}
UploadFileReq ufReq(uploadIds, msgFileName, msgData);
if (!ufReq.isValid()) {
Q_ASSERT(0);
return false;
}
QByteArray response;
QString errTitle = tr("Communication error");
QString errDesctiption = tr("Received invalid response.");
emit statusBarTextChanged(tr("Upload message"), true, true);
m_rmc.setConnection(globRecordsManagementSet.url(),
......@@ -399,21 +399,13 @@ bool RecordsManagement::uploadFile(qint64 dmId, const QString &msgFileName,
bool ok = false;
UploadFileResp ufRes(
UploadFileResp::fromJson(response, &ok));
if (!ok || !ufRes.isValid()) {
goto fail;
if (ok && ufRes.isValid()) {
emit statusBarTextChanged(tr("Done"), false, true);
return processUploadFileResponse(ufRes, dmId);
}
emit statusBarTextChanged(tr("Done"), false, true);
return processUploadFileResponse(ufRes, dmId);
} else {
errDesctiption = tr("Received empty response.");
goto fail;
}
}
emit statusBarTextChanged(tr("Done"), false, true);
return false;
fail:
emit statusBarTextChanged(errTitle, false, true);
QMessageBox::critical(Q_NULLPTR, errTitle, errDesctiption);
emit statusBarTextChanged(tr("Communication error"), false, true);
return false;
}
......@@ -52,9 +52,10 @@ public:
*
* @param[in] urlStr Records management url string.
* @param[in] tokenStr Records management token string.
* @return True if success.
*/
Q_INVOKABLE
void callServiceInfo(const QString &urlStr, const QString &tokenStr);
bool callServiceInfo(const QString &urlStr, const QString &tokenStr);
/*!
* @brief Download upload hierarchy and set model.
......@@ -64,9 +65,13 @@ public:
/*!
* @brief Obtain information about stored messages from records managnt.
*
* @param[in] urlStr Records management url string.
* @param[in] tokenStr Records management token string.
*/
Q_INVOKABLE
void getStoredMsgInfoFromRecordsManagement(void);
void getStoredMsgInfoFromRecordsManagement(const QString &urlStr,
const QString &tokenSt);
/*!
* @brief Test if records management is set, active and valid.
......@@ -98,15 +103,16 @@ public:
/*!
* @brief Update record management settings.
*
* @param[in] urlStr New records management url string.
* @param[in] urlStrSettings Records management url string from settings.
* @param[in] newUrlStr New records management url string.
* @param[in] oldUrlStr Records management url string from settings.
* @param[in] srName Service name.
* @param[in] srToken Service token.
* @return True when data have been updated, false else.
*/
Q_INVOKABLE
bool updateServiceInfo(const QString &urlStr, const QString &urlStrSettings,
const QString &srName, const QString &srToken);
bool updateServiceInfo(const QString &newUrlStr,
const QString &oldUrlStr, const QString &srName,
const QString &srToken);
signals:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment