Commit af530485 authored by Martin Straka's avatar Martin Straka

Added records management message upload page

parent 42495254
......@@ -84,6 +84,7 @@ ApplicationWindow {
property Component pageSettingsPin: PageSettingsPin {}
property Component pageSettingsStorage: PageSettingsStorage {}
property Component pageSettingsSync: PageSettingsSync {}
property Component pageUploadMessageToRm: PageUploadMessageToRm {}
// header background color
property string mainHeaderBgColor: "#00539b"
......
......@@ -43,13 +43,20 @@ Component {
property var attachmentModel: null /* The QVariant holds actually a pointer to the model. */
Component.onCompleted: {
var index
if (msgType == MessageType.TYPE_SENT) {
// Hide some menu items for sent messages
// Note: remove argument is ListModel item index
var index = messageDetailMenuList.get_model_index(messageDetailMenuListModel, "funcName", "reply");
index = messageDetailMenuList.get_model_index(messageDetailMenuListModel, "funcName", "reply");
if (index >= 0) {
messageDetailMenuListModel.setProperty(index, "showEntry", false)
}
}
if (!recordsManagement.isValidRecordsManagement()) {
// Note: remove argument is ListModel item index
index = messageDetailMenuList.get_model_index(messageDetailMenuListModel, "funcName", "uploadRM");
if (index >= 0) {
messageDetailMenuListModel.setProperty(index, "showEntry", false)
//messageDetailMenuListModel.remove(index)
}
}
}
......@@ -101,6 +108,16 @@ Component {
"action": "template"
}, StackView.Immediate)
},
"uploadRM": function calluploadRM() {
pageView.replace(pageUploadMessageToRm, {
"pageView": pageView,
"statusBar": statusBar,
"acntName" : acntName,
"userName": userName,
"msgId": msgId,
"msgType": msgType
}, StackView.Immediate)
},
"sendEmail": function callSendEmail() {
files.sendAttachmentsWithEmail(userName, msgId)
pageView.pop(StackView.Immediate)
......@@ -149,6 +166,13 @@ Component {
name: qsTr("Use as template")
funcName: "useTemplate"
}
ListElement {
image: "qrc:/ui/briefcase.svg"
showEntry: true
showNext: true
name: qsTr("Upload to Records Management")
funcName: "uploadRM"
}
ListElement {
image: "qrc:/ui/attach-to-mail.svg"
showEntry: true
......
......@@ -244,7 +244,7 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Update list of uploaded files")
onClicked: {
recordsManagement.getStoredMsgInfoFromRecordsManagement(urlTextField.text, tokenTextField.text)
recordsManagement.getStoredMsgInfoFromRecordsManagement()
}
}
} // // Column
......
/*
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
import QtQuick 2.7
import QtQuick.Controls 1.4
import QtQuick.Controls 2.1
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka 1.0
import cz.nic.mobileDatovka.models 1.0
Component {
id: uploadRm
Item {
id: mainLayout
/* These properties must be set by caller. */
property var pageView
property var statusBar
property string acntName
property string userName
property int msgType
property string msgId
/* Holsd selected folder ids */
property var uploadIds: []
Component.onCompleted: {
}
Component.onDestruction: {
statusBar.visible = false
}
ListModel {
/* TODO */
id: uploadHierarchyModel
Component.onCompleted: {
}
}
PageHeader {
id: headerBar
title: qsTr("Upload message %1").arg(msgId)
onBackClicked: {
pageView.pop(StackView.Immediate)
}
}
Flickable {
id: flickable
z: 0
anchors.top: headerBar.bottom
anchors.right: parent.right
anchors.left: parent.left
anchors.bottom: parent.bottom
contentHeight: flickContent.implicitHeight
Pane {
id: flickContent
anchors.fill: parent
Column {
anchors.right: parent.right
anchors.left: parent.left
spacing: formItemVerticalSpacing
AccessibleText {
color: datovkaPalette.mid
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
width: parent.width
text: qsTr("Here you can upload message into chosen folder in the records management. Update folder hierarchy and select target folder.")
}
AccessibleButton {
id: hierarchyButton
anchors.horizontalCenter: parent.horizontalCenter
height: inputItemHeight
font.pointSize: defaultTextFont.font.pointSize
text: qsTr("Update upload hierarchy")
onClicked: {
recordsManagement.callUploadHierarchy()
}
}
TreeView {
/* TODO */
width: parent.width
TableViewColumn {
title: "Records management hierarchy"
role: "folderName"
width: parent.width
}
model: uploadHierarchyModel
}
AccessibleButton {
id: uplaodButton
anchors.horizontalCenter: parent.horizontalCenter
height: inputItemHeight
font.pointSize: defaultTextFont.font.pointSize
text: qsTr("Upload message")
onClicked: {
recordsManagement.uploadMessage(userName, msgId, msgType, uploadIds)
}
}
} // Column layout
} // Pane
ScrollIndicator.vertical: ScrollIndicator {}
} // Flickable
}
}
......@@ -148,6 +148,7 @@
<file>../qml/pages/PageSettingsPin.qml</file>
<file>../qml/pages/PageSettingsStorage.qml</file>
<file>../qml/pages/PageSettingsSync.qml</file>
<file>../qml/pages/PageUploadMessageToRm.qml</file>
<file>../qml/main.qml</file>
</qresource>
</RCC>
......@@ -118,6 +118,7 @@ const struct QmlTypeEntry qmlPages[] = {
{ "PageSettingsPin", 1, 0 },
{ "PageSettingsStorage", 1, 0 },
{ "PageSettingsSync", 1, 0 },
{ "PageUploadMessageToRm", 1, 0 },
{ NULL, 0, 0 }
};
......
......@@ -34,6 +34,7 @@
#include "src/worker/emitter.h"
#include "src/worker/pool.h"
#include "src/worker/task_records_management_stored_messages.h"
#include "src/sqlite/zfo_db.h"
/*!
* @brief Process upload file service response.
......@@ -144,8 +145,7 @@ fail:
QMessageBox::critical(Q_NULLPTR, errTitle, errDesctiption);
}
void RecordsManagement::callUploadHierarchy(const QString &urlStr,
const QString &tokenStr)
void RecordsManagement::callUploadHierarchy(void)
{
QByteArray response;
QString errTitle = tr("Communication error");
......@@ -156,7 +156,8 @@ void RecordsManagement::callUploadHierarchy(const QString &urlStr,
/* Clear model. */
m_uploadModel.setHierarchy(UploadHierarchyResp());
m_rmc.setConnection(urlStr.trimmed(), tokenStr.trimmed());
m_rmc.setConnection(globRecordsManagementSet.url(),
globRecordsManagementSet.token());
if (m_rmc.communicate(RecordsManagementConnection::SRVC_UPLOAD_HIERARCHY,
QByteArray(), response)) {
......@@ -181,14 +182,14 @@ fail:
QMessageBox::critical(Q_NULLPTR, errTitle, errDesctiption);
}
void RecordsManagement::getStoredMsgInfoFromRecordsManagement(
const QString &urlStr, const QString &tokenStr)
void RecordsManagement::getStoredMsgInfoFromRecordsManagement(void)
{
emit statusBarTextChanged(tr("Sync service"), true, true);
TaskRecordsManagementStoredMessages *task =
new (::std::nothrow) TaskRecordsManagementStoredMessages(
urlStr, tokenStr,
globRecordsManagementSet.url(),
globRecordsManagementSet.token(),
TaskRecordsManagementStoredMessages::RM_UPDATE_STORED,
Q_NULLPTR, QString(), 0, 0);
if (Q_NULLPTR == task) {
......@@ -216,7 +217,8 @@ void RecordsManagement::getStoredMsgInfoFromRecordsManagement(
TaskRecordsManagementStoredMessages *task =
new (::std::nothrow) TaskRecordsManagementStoredMessages(
urlStr, tokenStr,
globRecordsManagementSet.url(),
globRecordsManagementSet.token(),
TaskRecordsManagementStoredMessages::RM_DOWNLOAD_ALL,
msgDb, userName, accNumber, accTotal);
if (Q_NULLPTR == task) {
......@@ -231,6 +233,14 @@ void RecordsManagement::getStoredMsgInfoFromRecordsManagement(
}
}
bool RecordsManagement::isValidRecordsManagement(void)
{
RecordsManagementDb::ServiceInfoEntry entry(
globRecordsManagementDbPtr->serviceInfo());
return (entry.isValid() && !globRecordsManagementSet.url().isEmpty()
&& !globRecordsManagementSet.token().isEmpty());
}
void RecordsManagement::loadStoredServiceInfo(void)
{
if (Q_NULLPTR == globRecordsManagementDbPtr) {
......@@ -248,53 +258,43 @@ void RecordsManagement::loadStoredServiceInfo(void)
emit serviceInfo(entry.name, entry.tokenName);
}
bool RecordsManagement::uploadMessage(const QString &urlStr,
const QString &tokenStr, qint64 dmId, const QString &msgFileName,
const QByteArray &msgData)
bool RecordsManagement::uploadMessage(const QString &userName,
const QString &dmId, enum Messages::MessageType messageType,
const QStringList &uploadIds)
{
if (msgFileName.isEmpty() || msgData.isEmpty()) {
Q_ASSERT(0);
bool ok = false;
qint64 msgId = dmId.toLongLong(&ok);
if (!ok || (msgId < 0)) {
return false;
}
QStringList uploadIds;
QByteArray msgData =
QByteArray::fromBase64(globZfoDbPtr->getZfoContentFromDb(msgId,
AccountListModel::globAccounts[userName].isTestAccount()));
UploadFileReq ufReq(uploadIds, msgFileName, msgData);
if (!ufReq.isValid()) {
Q_ASSERT(0);
if (msgData.isEmpty()) {
return false;
}
QByteArray response;
QString errTitle = tr("Communication error");
QString errDesctiption = tr("Received invalid response.");
QString msgType;
switch (messageType) {
case Messages::TYPE_RECEIVED:
msgType = QLatin1String("DDZ");
break;
case Messages::TYPE_SENT:
msgType = QLatin1String("ODZ");
break;
default:
msgType = QLatin1String("DZ");
break;
}
emit statusBarTextChanged(tr("Upload message"), true, true);
QString msgFileName = QString("%1_%2.zfo").arg(msgType).arg(dmId);
m_rmc.setConnection(urlStr.trimmed(), tokenStr.trimmed());
if (m_rmc.communicate(RecordsManagementConnection::SRVC_UPLOAD_FILE,
ufReq.toJson(), response)) {
if (!response.isEmpty()) {
bool ok = false;
UploadFileResp ufRes(
UploadFileResp::fromJson(response, &ok));
if (!ok || !ufRes.isValid()) {
goto fail;
}
emit statusBarTextChanged(tr("Done"), false, true);
return processUploadFileResponse(ufRes, dmId);
} else {
errDesctiption = tr("Received empty response.");
goto fail;
}
}
/* TODO - removed this return */
return true;
emit statusBarTextChanged(tr("Done"), false, true);
return false;
fail:
emit statusBarTextChanged(errTitle, false, true);
QMessageBox::critical(Q_NULLPTR, errTitle, errDesctiption);
return false;
return uploadFile(msgId, msgFileName, msgData, uploadIds);
}
bool RecordsManagement::updateServiceInfo(const QString &urlStr,
......@@ -357,6 +357,53 @@ void RecordsManagement::loadRecordsManagementPixmap(const QByteArray &logoSvg)
QPixmap pixmap(Graphics::pixmapFromSvg(logo, LOGO_EDGE));
if (!pixmap.isNull()) {
/* TODO - set Pixmap into QML */
//m_ui->pixmapLabel->setPixmap(pixmap);
}
}
bool RecordsManagement::uploadFile(qint64 dmId, const QString &msgFileName,
const QByteArray &msgData, const QStringList &uploadIds)
{
if (msgFileName.isEmpty() || msgData.isEmpty()) {
Q_ASSERT(0);
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(),
globRecordsManagementSet.token());
if (m_rmc.communicate(RecordsManagementConnection::SRVC_UPLOAD_FILE,
ufReq.toJson(), response)) {
if (!response.isEmpty()) {
bool ok = false;
UploadFileResp ufRes(
UploadFileResp::fromJson(response, &ok));
if (!ok || !ufRes.isValid()) {
goto fail;
}
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);
return false;
}
......@@ -58,23 +58,23 @@ public:
/*!
* @brief Download upload hierarchy and set model.
*
* @param[in] urlStr Records management url string.
* @param[in] tokenStr Records management token string.
*/
Q_INVOKABLE
void callUploadHierarchy(const QString &urlStr, const QString &tokenStr);
void callUploadHierarchy(void);
/*!
* @brief Obtain information about stored messages from records
* management.
* @brief Obtain information about stored messages from records managnt.
*/
Q_INVOKABLE
void getStoredMsgInfoFromRecordsManagement(void);
/*!
* @brief Test if records management is set, active and valid.
*
* @param[in] urlStr Records management url string.
* @param[in] tokenStr Records management token string.
* @return True if records management is set, active and valid.
*/
Q_INVOKABLE
void getStoredMsgInfoFromRecordsManagement(const QString &urlStr,
const QString &tokenStr);
bool isValidRecordsManagement(void);
/*!
* @brief Loads service information from storage.
......@@ -85,17 +85,15 @@ public:
/*!
* @brief Upload message into records management service.
*
* @param[in] urlStr Records management url string.
* @param[in] tokenStr Records management token string.
* @param[in] userName Account user name identifier.
* @param[in] dmId Message identifier.
* @param[in] msgFileName Message file name.
* @param[in] msgData Message data.
* @param[in] messageType Message orientation.
* @param[in] uploadIds List of records management location ids.
* @return True when data have been updated, false else.
*/
Q_INVOKABLE
bool uploadMessage(const QString &urlStr,
const QString &tokenStr, qint64 dmId, const QString &msgFileName,
const QByteArray &msgData);
bool uploadMessage(const QString &userName, const QString &dmId,
enum Messages::MessageType messageType, const QStringList &uploadIds);
/*!
* @brief Update record management settings.
......@@ -152,6 +150,19 @@ private:
*/
void loadRecordsManagementPixmap(const QByteArray &logoSvg);
/*!
* @brief Upload file into records management service.
*
* @param[in] dmId Message identifier.
* @param[in] msgFileName Message file name.
* @param[in] msgData Message data.
* @param[in] uploadIds List of records management location ids.
* @return True when data have been updated, false else.
*/
Q_INVOKABLE
bool uploadFile(qint64 dmId, const QString &msgFileName,
const QByteArray &msgData, const QStringList &uploadIds);
UploadHierarchyModel m_uploadModel; /*!< Upload hierarchy model. */
UploadHierarchyProxyModel m_uploadProxyModel; /*!< Used for filtering. */
RecordsManagementConnection m_rmc; /*!< Connection to records management service. */
......
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