Commit 9114ff7f authored by Martin Straka's avatar Martin Straka

Added support for search results pagination

parent 49a79e0e
...@@ -40,9 +40,16 @@ Item { ...@@ -40,9 +40,16 @@ Item {
property var statusBar property var statusBar
property string userName property string userName
/* These properties remember choice of ComboBoxes */
property string searchType: "GENERAL" property string searchType: "GENERAL"
property string searchScope: "ALL" property string searchScope: "ALL"
/* These properties remember origin search settings during pagination */
property int page: 0
property string searchTextTmp
property string searchTypeTmp
property string searchScopeTmp
Component.onCompleted: { Component.onCompleted: {
searchPhraseText.forceActiveFocus() searchPhraseText.forceActiveFocus()
} }
...@@ -174,6 +181,43 @@ Item { ...@@ -174,6 +181,43 @@ Item {
} }
} }
} }
Row {
id: searchResults
anchors.horizontalCenter: parent.horizontalCenter
spacing: formItemVerticalSpacing
visible: false
Text {
id: searchResultPrevious
color: headerColor
text: qsTr("Previuos")
MouseArea {
anchors.fill: parent
onClicked: {
if (page > 0) {
page = page-1
}
isds.findDatabox(userName, databoxModel, searchTextTmp, searchTypeTmp, searchScopeTmp, page)
}
}
}
Text {
id: searchResultText
color: datovkaPalette.text
text: ""
}
Text {
id: searchResultNext
color: headerColor
text: qsTr("Next")
MouseArea {
anchors.fill: parent
onClicked: {
page = page+1
isds.findDatabox(userName, databoxModel, searchTextTmp, searchTypeTmp, searchScopeTmp, page)
}
}
}
}
} }
} // Pane } // Pane
Text { Text {
...@@ -206,7 +250,28 @@ Item { ...@@ -206,7 +250,28 @@ Item {
Connections { Connections {
target: isds target: isds
onRunFindDataboxSig: { onRunFindDataboxSig: {
emptyList.visible = (isds.findDatabox(userName, databoxModel, searchPhraseText.text, searchType, searchScope) <= 0) searchResults.visible = false
searchResultPrevious.visible = false
searchResultNext.visible = false
searchResultText.text = ""
page = 0
searchTextTmp = searchPhraseText.text
searchTypeTmp = searchType
searchScopeTmp = searchScope
emptyList.visible = (isds.findDatabox(userName, databoxModel, searchPhraseText.text, searchType, searchScope, page) <= 0)
}
}
Connections {
target: isds
onSendSearchResultsSig: {
searchResults.visible = true
searchResultNext.visible = !lastPage
searchResultPrevious.visible = (position > 0)
if (totalCount > 0) {
searchResultText.text = qsTr("Found") + ": " + totalCount + "; " + qsTr("Shown") + ": " + currentCount + ";"
} else {
searchResultText.text = qsTr("Found") + ": " + totalCount
}
} }
} }
} // Item } // Item
...@@ -77,7 +77,7 @@ Component { ...@@ -77,7 +77,7 @@ Component {
} }
ListElement { ListElement {
index: 5 index: 5
name: qsTr("Search databox") name: qsTr("Find databox")
image: "qrc:/ui/account-search.svg" image: "qrc:/ui/account-search.svg"
} }
ListElement { ListElement {
......
...@@ -132,7 +132,6 @@ public: ...@@ -132,7 +132,6 @@ public:
* @param[in] data Databox model data. * @param[in] data Databox model data.
* @param[in] role Data role. * @param[in] role Data role.
*/ */
virtual
void setData(const DataboxModelEntry &data, int role = Qt::EditRole); void setData(const DataboxModelEntry &data, int role = Qt::EditRole);
/*! /*!
......
...@@ -92,6 +92,9 @@ ...@@ -92,6 +92,9 @@
#define PWD_HOTP "hotp" #define PWD_HOTP "hotp"
#define PWD_TOTP "totp" #define PWD_TOTP "totp"
/* Maximal number of search results on one page: ISDS allows 100 */
#define ISDS_SEARCH2_ITEMS_PER_PAGE 100
/*! /*!
* @brief Maximum length of message list to be downloaded. * @brief Maximum length of message list to be downloaded.
*/ */
......
...@@ -222,6 +222,68 @@ void IsdsWrapper::getAccountInfo(const QString &userName) ...@@ -222,6 +222,68 @@ void IsdsWrapper::getAccountInfo(const QString &userName)
m_workPool.assignHi(task); m_workPool.assignHi(task);
} }
int IsdsWrapper::findDatabox(const QString &userName,
const QVariant &dbModelVariant, const QString &phrase,
const QString &searchType, const QString &searchScope, int page)
{
qDebug("%s()", __func__);
if (userName.isEmpty() || phrase.isEmpty()) {
return 0;
}
/* User must be logged to isds */
if (!isLoggedToIsds(userName)) {
return 0;
}
emit statusBarTextChanged(tr("Finding databoxes"), true, true);
DataboxListModel *databoxModel =
DataboxListModel::fromVariant(dbModelVariant);
if (databoxModel == Q_NULLPTR) {
Q_ASSERT(0);
qCritical("%s", "Cannot access databox model.");
return 0;
}
TaskFindDatabox *task;
task = new (std::nothrow) TaskFindDatabox(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, phrase,
searchType, searchScope, page, ISDS_SEARCH2_ITEMS_PER_PAGE, false);
task->setAutoDelete(false);
m_workPool.runSingle(task);
bool success = TaskFindDatabox::DL_SUCCESS == task->m_result;
QList<DataboxModelEntry> dbList = task->m_dbList;
int totalCount = task->m_totalCount;
int currentCount = task->m_currentCount;
int position = task->m_position;
bool lastPage = task->m_lastPage;
QString lastError = task->m_lastError;
delete task;
if (!success) {
emit statusBarTextChanged(lastError, false, true);
Dialogues::errorMessage(Dialogues::WARNING,
tr("Find databox: %1").arg(userName),
tr("Failed to find databox on word '%1'.").arg(phrase),
lastError);
return 0;
} else {
emit statusBarTextChanged(
m_isdsSession.isdsCtxMap[userName].last_isds_msg, false, true);
}
emit sendSearchResultsSig(totalCount, currentCount, position, lastPage);
databoxModel->clearAll();
foreach (const DataboxModelEntry &db, dbList) {
databoxModel->setData(db);
}
return databoxModel->rowCount();
}
void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId) void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId)
{ {
qDebug("%s()", __func__); qDebug("%s()", __func__);
...@@ -798,57 +860,3 @@ void IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant, ...@@ -798,57 +860,3 @@ void IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
task->setAutoDelete(true); task->setAutoDelete(true);
m_workPool.assignHi(task); m_workPool.assignHi(task);
} }
int IsdsWrapper::findDatabox(const QString &userName,
const QVariant &dbModelVariant, const QString &phrase,
const QString &searchType, const QString &searchScope)
{
qDebug("%s()", __func__);
if (userName.isEmpty() || phrase.isEmpty()) {
return 0;
}
/* User must be logged to isds */
if (!isLoggedToIsds(userName)) {
return 0;
}
emit statusBarTextChanged(tr("Finding databoxes"), true, true);
DataboxListModel *databoxModel =
DataboxListModel::fromVariant(dbModelVariant);
if (databoxModel == Q_NULLPTR) {
Q_ASSERT(0);
qCritical("%s", "Cannot access databox model.");
return 0;
}
TaskFindDatabox *task;
task = new (std::nothrow) TaskFindDatabox(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, phrase,
searchType, searchScope, databoxModel);
task->setAutoDelete(false);
m_workPool.runSingle(task);
bool success = TaskFindDatabox::DL_SUCCESS == task->m_result;
QList<DataboxModelEntry> dbList = task->m_dbList;
delete task;
if (!success) {
Dialogues::errorMessage(Dialogues::WARNING,
tr("Find databox: %1").arg(userName),
tr("Failed to find databox on word '%1'.").arg(phrase),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
} else {
emit statusBarTextChanged(
m_isdsSession.isdsCtxMap[userName].last_isds_msg, false,
true);
}
databoxModel->clearAll();
foreach (const DataboxModelEntry &db, dbList) {
databoxModel->setData(db);
}
return databoxModel->rowCount();
}
...@@ -82,6 +82,22 @@ public: ...@@ -82,6 +82,22 @@ public:
const QString &userName, enum Messages::MessageType messageType, const QString &userName, enum Messages::MessageType messageType,
qint64 msgId); qint64 msgId);
/*!
* @brief Find databoxes based on search criteria.
*
* @param[in] userName Account username string.
* @param[in] dbModelVariant DataboxList model.
* @param[in] phrase World to be found.
* @param[in] searchType Databox field specification for search.
* @param[in] searchScope Databox type search restriction.
* @param[in] page Page number to be shown.
* @return number of results.
*/
Q_INVOKABLE
int findDatabox(const QString &userName, const QVariant &dbModelVariant,
const QString &phrase, const QString &searchType,
const QString &searchScope, int page);
/*! /*!
* @brief Download account info. * @brief Download account info.
* *
...@@ -140,21 +156,6 @@ public: ...@@ -140,21 +156,6 @@ public:
void inputDialogReturnPassword(const QString &isdsAction, void inputDialogReturnPassword(const QString &isdsAction,
const QString &pwdType, const QString &userName, const QString &pwd); const QString &pwdType, const QString &userName, const QString &pwd);
/*!
* @brief Find databoxes based on search criteria.
*
* @param[in] userName Account username string.
* @param[in] dbModelVariant DataboxList model.
* @param[in] phrase World to be found.
* @param[in] searchType Databox field specification for search.
* @param[in] searchScope Databox type search restriction.
* @return number of results.
*/
Q_INVOKABLE
int findDatabox(const QString &userName, const QVariant &dbModelVariant,
const QString &phrase, const QString &searchType,
const QString &searchScope);
/*! /*!
* @brief Sent SMS request. * @brief Sent SMS request.
* *
...@@ -319,6 +320,17 @@ signals: ...@@ -319,6 +320,17 @@ signals:
*/ */
void runSyncSingleAccountSentSig(QString userName); void runSyncSingleAccountSentSig(QString userName);
/*!
* @brief Send search result info to QML.
*
* @param[in] totalCount Total number of databoxes.
* @param[in] currentCount Number o databoxes on the current page.
* @param[in] position Page number.
* @param[in] lastPage True if search result are last page.
*/
void sendSearchResultsSig(int totalCount, int currentCount,
int position, bool lastPage);
/*! /*!
* @brief Signal is emitted when login to isds of new account fails. * @brief Signal is emitted when login to isds of new account fails.
* *
......
...@@ -1099,7 +1099,8 @@ bool XmlLayer::parseGetSignedMsgDeliveryInfoResponse(const QByteArray &xmlData, ...@@ -1099,7 +1099,8 @@ bool XmlLayer::parseGetSignedMsgDeliveryInfoResponse(const QByteArray &xmlData,
} }
bool XmlLayer::parseISDSSearch2SoapResponse(const QByteArray &xmlData, bool XmlLayer::parseISDSSearch2SoapResponse(const QByteArray &xmlData,
QList<DataboxModelEntry> &dbList, QString &txt) QList<DataboxModelEntry> &dbList, int &totalCount, int &currentCount,
int &position, bool &lastPage, QString &txt)
{ {
qDebug("%s()", __func__); qDebug("%s()", __func__);
...@@ -1116,6 +1117,22 @@ bool XmlLayer::parseISDSSearch2SoapResponse(const QByteArray &xmlData, ...@@ -1116,6 +1117,22 @@ bool XmlLayer::parseISDSSearch2SoapResponse(const QByteArray &xmlData,
continue; continue;
} }
if (token == QXmlStreamReader::StartElement) { if (token == QXmlStreamReader::StartElement) {
if (xml.name() == "totalCount") {
xml.readNext();
totalCount = xml.text().toInt();
}
if (xml.name() == "currentCount") {
xml.readNext();
currentCount = xml.text().toInt();
}
if (xml.name() == "position") {
xml.readNext();
position = xml.text().toInt();
}
if (xml.name() == "lastPage") {
xml.readNext();
lastPage = (xml.text().toInt() == 1);
}
if (xml.name() == "dbResult") { if (xml.name() == "dbResult") {
dbList.append(parseDataboxData(xml)); dbList.append(parseDataboxData(xml));
} }
......
...@@ -369,13 +369,17 @@ public: ...@@ -369,13 +369,17 @@ public:
* *
* @param[in] xmlData Xml Data for parsing. * @param[in] xmlData Xml Data for parsing.
* @param[out] dbList List of databoxes. * @param[out] dbList List of databoxes.
* @param[out] totalCount Total number of databoxes.
* @param[out] currentCount Number o databoxes on the current page.
* @param[out] position Number of page.
* @param[out] lastPage True if search result are last page.
* @param[out] txt Error description if something failed. * @param[out] txt Error description if something failed.
* @return true if success. * @return true if success.
*/ */
static static
bool parseISDSSearch2SoapResponse(const QByteArray &xmlData, bool parseISDSSearch2SoapResponse(const QByteArray &xmlData,
QList<DataboxModelEntry> &dbList, QString &txt); QList<DataboxModelEntry> &dbList, int &totalCount, int &currentCount,
int &position, bool &lastPage, QString &txt);
/*! /*!
* @brief Parse message envleope xml data. * @brief Parse message envleope xml data.
* *
......
...@@ -31,15 +31,22 @@ ...@@ -31,15 +31,22 @@
TaskFindDatabox::TaskFindDatabox(IsdsSession::IsdsContext &ctx, TaskFindDatabox::TaskFindDatabox(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, const QString &searchText, NetLayer *netLayer, const QString &searchText,
const QString &searchType, const QString &searchScope, const QString &searchType, const QString &searchScope,
DataboxListModel *databoxModel) int page, int pageSize, bool highlighting)
: m_result(DL_ERR), : m_result(DL_ERR),
m_dbList(), m_dbList(),
m_totalCount(0),
m_currentCount(0),
m_position(0),
m_lastPage(false),
m_lastError(),
m_ctx(ctx), m_ctx(ctx),
m_netLayer(netLayer), m_netLayer(netLayer),
m_searchText(searchText), m_searchText(searchText),
m_searchType(searchType), m_searchType(searchType),
m_searchScope(searchScope), m_searchScope(searchScope),
m_databoxModel(databoxModel) m_page(page),
m_pageSize(pageSize),
m_highlighting(highlighting)
{ {
} }
...@@ -61,7 +68,9 @@ void TaskFindDatabox::run(void) ...@@ -61,7 +68,9 @@ void TaskFindDatabox::run(void)
logDebugLv1NL("%s", "-----------------------------------------------"); logDebugLv1NL("%s", "-----------------------------------------------");
m_result = findDatabox(m_ctx, m_netLayer, m_searchText, m_searchType, m_result = findDatabox(m_ctx, m_netLayer, m_searchText, m_searchType,
m_searchScope, m_databoxModel, m_dbList); m_searchScope, m_page, m_pageSize, m_highlighting,
m_dbList, m_totalCount, m_currentCount, m_position, m_lastPage,
m_lastError);
/* ### Worker task end. ### */ /* ### Worker task end. ### */
...@@ -71,28 +80,31 @@ void TaskFindDatabox::run(void) ...@@ -71,28 +80,31 @@ void TaskFindDatabox::run(void)
enum TaskFindDatabox::Result TaskFindDatabox::findDatabox( enum TaskFindDatabox::Result TaskFindDatabox::findDatabox(
IsdsSession::IsdsContext &ctx, NetLayer *netLayer, const QString &searchText, IsdsSession::IsdsContext &ctx, NetLayer *netLayer, const QString &searchText,
const QString &searchType, const QString &searchScope, const QString &searchType, const QString &searchScope, int page,
DataboxListModel *databoxModel, QList<DataboxModelEntry> &dbList) int pageSize, bool highlighting, QList<DataboxModelEntry> &dbList,
int &totalCount, int &currentCount, int &position, bool &lastPage,
QString &lastError)
{ {
Q_UNUSED(databoxModel);
QByteArray xmlDataOut; QByteArray xmlDataOut;
if (ctx.username.isEmpty()) { if (ctx.username.isEmpty()) {
Q_ASSERT(0); Q_ASSERT(0);
lastError = QObject::tr("Internal error");
return DL_ERR; return DL_ERR;
} }
/* Send SOAP request to find databox */ /* Send SOAP request to find databox */
if (!netLayer->sendSoapRequest(ctx, FIND_SERVICE, if (!netLayer->sendSoapRequest(ctx, FIND_SERVICE,
XmlLayer::xmlCreateISDSSearch2SoapRequest(searchText, searchType, XmlLayer::xmlCreateISDSSearch2SoapRequest(searchText, searchType,
searchScope, 0, 100, false), xmlDataOut)) { searchScope, page, pageSize, highlighting), xmlDataOut)) {
lastError = ctx.last_isds_msg;
return DL_ISDS_ERROR; return DL_ISDS_ERROR;
} }
/* Parse databoxes from response */ /* Parse databoxes from response */
if (!XmlLayer::parseISDSSearch2SoapResponse(xmlDataOut, dbList, if (!XmlLayer::parseISDSSearch2SoapResponse(xmlDataOut, dbList,
ctx.last_isds_msg)) { totalCount, currentCount, position, lastPage, ctx.last_isds_msg)) {
lastError = ctx.last_isds_msg;
return DL_XML_ERROR; return DL_XML_ERROR;
} }
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#ifndef _TASK_FIND_DATABOX_H_ #ifndef _TASK_FIND_DATABOX_H_
#define _TASK_FIND_DATABOX_H_ #define _TASK_FIND_DATABOX_H_
#include "src/models/databoxmodel.h"
#include "src/net/isds_session.h" #include "src/net/isds_session.h"
#include "src/net/net_layer.h" #include "src/net/net_layer.h"
#include "src/worker/task.h" #include "src/worker/task.h"
...@@ -52,13 +51,15 @@ public: ...@@ -52,13 +51,15 @@ public:
* @param[in] netLayer Pointer to network manager. * @param[in] netLayer Pointer to network manager.
* @param[in] searchText Search text. * @param[in] searchText Search text.
* @param[in] searchType Search type option. * @param[in] searchType Search type option.
* @param[in] searchScope Search scope option. * @param[in] searchScope Search scope option.
* @param[in] databoxModel Pointer to databox model. * @param[in] page Page to be obtain.
* @param[in] pageSize Number of items on the page.
* @param[in] highlighting Highlight search phraze in results.
*/ */
explicit TaskFindDatabox(IsdsSession::IsdsContext &ctx, explicit TaskFindDatabox(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, const QString &searchText, NetLayer *netLayer, const QString &searchText,
const QString &searchType, const QString &searchScope, const QString &searchType, const QString &searchScope,
DataboxListModel *databoxModel); int page, int pageSize, bool highlighting);
/*! /*!
* @brief Performs actual find databox. * @brief Performs actual find databox.
...@@ -73,19 +74,34 @@ public: ...@@ -73,19 +74,34 @@ public:
* @param[in] netLayer Pointer to network manager. * @param[in] netLayer Pointer to network manager.
* @param[in] searchText Search text. * @param[in] searchText Search text.
* @param[in] searchType Search type option. * @param[in] searchType Search type option.
* @param[in] searchScope Search scope option. * @param[in] searchScope Search scope option.
* @param[in] databoxModel Pointer to databox model. * @param[in] page Page to be obtain.
* @param[in] pageSize Number of items on the page.
* @param[in] highlighting Highlight search phraze in results.
* @param[out] dbList List of databoxes. * @param[out] dbList List of databoxes.
* @param[out] totalCount Total number of databoxes.
* @param[out] currentCount Number o databoxes on the current page.
* @param[out] position Number of page.
* @param[out] lastPage True if search result are last page.
* @param[out] lastError Last ISDS error message.
* @return Error state. * @return Error state.
*/ */
static static
enum Result findDatabox(IsdsSession::IsdsContext &ctx, enum Result findDatabox(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, const QString &searchText, NetLayer *netLayer, const QString &searchText,
const QString &searchType, const QString &searchScope, const QString &searchType, const QString &searchScope,
DataboxListModel *databoxModel, QList<DataboxModelEntry> &dbList); int page, int pageSize, bool highlighting,
QList<DataboxModelEntry> &dbList, int &totalCount,
int &currentCount, int &position, bool &lastPage,
QString &lastError);
enum Result m_result; /*!< Return state. */ enum Result m_result; /*!< Return state. */
QList<DataboxModelEntry> m_dbList; /*!< Return list of databoxes. */ QList<DataboxModelEntry> m_dbList; /*!< Return list of databoxes. */
int m_totalCount; /*!< Total number of databoxes. */
int m_currentCount; /*!< Number o databoxes on the current page. */
int m_position; /*!< Number of page. */
bool m_lastPage; /*!< True if search result are last page. */
QString m_lastError; /*!< Last ISDS error message. */
private: private:
/*! /*!
...@@ -99,7 +115,9 @@ private: ...@@ -99,7 +115,9 @@ private:
const QString m_searchText; /*!< Search phrase. */ const QString m_searchText; /*!< Search phrase. */
const QString m_searchType; /*!< Search type. */ const QString m_searchType; /*!< Search type. */
const QString m_searchScope; /*!< Search scope. */ const QString m_searchScope; /*!< Search scope. */
DataboxListModel *m_databoxModel; /*!< Pointer to databox model. */ int m_page; /*!< Page to be obtain. */
int m_pageSize; /*!< Number of items on the page. */
bool m_highlighting; /*!< Highlight search phraze in results. */
}; };
#endif /* _TASK_FIND_DATABOX_H_ */ #endif /* _TASK_FIND_DATABOX_H_ */
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