summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.cxx4
m---------librtclient0
-rw-r--r--qrtclient/client.hxx2
-rw-r--r--qrtclient/tickethistory.hxx109
-rw-r--r--tickethistory.cxx90
5 files changed, 202 insertions, 3 deletions
diff --git a/client.cxx b/client.cxx
index b91c10b..6711461 100644
--- a/client.cxx
+++ b/client.cxx
@@ -121,10 +121,10 @@ namespace RTClient {
emit searchedTicket(ticketList);
}
- void Client::ticketHistory(int id)
+ void Client::ticketHistory(int id, bool longFormat)
{
rtclient_ticket_history_list* historyList = nullptr;
- rtclient_ticket_history(&historyList, id);
+ rtclient_ticket_history(&historyList, id, longFormat);
emit gotTicketHistory(historyList);
}
diff --git a/librtclient b/librtclient
-Subproject 494a46196ade016b606716b36045f6b08a3234b
+Subproject 601251148de5bd8a42649e3b888d7824eb1d774
diff --git a/qrtclient/client.hxx b/qrtclient/client.hxx
index b672620..e9e6b0f 100644
--- a/qrtclient/client.hxx
+++ b/qrtclient/client.hxx
@@ -63,7 +63,7 @@ namespace RTClient {
, QString const& due = nullptr
, QString const& text = nullptr);
void searchTicket(QString const& owner);
- void ticketHistory(int id);
+ void ticketHistory(int id, bool longFormat = false);
signals:
void loggedIn(QString const& name);
diff --git a/qrtclient/tickethistory.hxx b/qrtclient/tickethistory.hxx
new file mode 100644
index 0000000..7d68652
--- /dev/null
+++ b/qrtclient/tickethistory.hxx
@@ -0,0 +1,109 @@
+#ifndef QRTCLIENT_TICKET_HISTORY_HXX
+#define QRTCLIENT_TICKET_HISTORY_HXX
+
+#include <QAbstractListModel>
+#include <QDateTime>
+#include <rtclient/ticket.h>
+
+struct rtclient_ticket_history_list;
+
+namespace RTClient {
+
+ class TicketHistory
+ {
+ public:
+ TicketHistory(struct rtclient_ticket_history* history)
+ : m_id{history->id}
+ , m_ticket{history->ticket}
+ , m_timeTaken{history->time_taken}
+ , m_type{history->type}
+ , m_description{history->description}
+ , m_content{history->content}
+ , m_creator{history->creator}
+ {
+ if (history->field)
+ m_field = QString{history->field};
+ if (history->old_value)
+ m_oldValue = QString{history->old_value};
+ if (history->new_value)
+ m_newValue = QString{history->new_value};
+ if (history->data)
+ m_data = QString{history->data};
+ }
+ unsigned int id() const { return m_id; }
+ unsigned int ticket() const { return m_ticket; }
+ unsigned int timeTaken() const { return m_timeTaken; }
+// Q_ENUM(rtclient_ticket_history_type)
+ rtclient_ticket_history_type type() const { return m_type; }
+ QString const& field() const { return m_field; }
+ QString const& oldValue() const { return m_oldValue; }
+ QString const& newValue() const { return m_newValue; }
+ QString const& data() const { return m_data; }
+ QString const& description() const { return m_description; }
+ QString const& content() const { return m_content; }
+ QString const& creator() const { return m_creator; }
+ QDateTime const& created() const { return m_created; }
+
+ private:
+ unsigned int m_id;
+ unsigned int m_ticket;
+ unsigned int m_timeTaken;
+ rtclient_ticket_history_type m_type;
+ QString m_field;
+ QString m_oldValue;
+ QString m_newValue;
+ QString m_data;
+ QString m_description;
+ QString m_content;
+ QString m_creator;
+ QDateTime m_created;
+// QList<TicketHistoryAttachment>* m_attachments;
+ };
+
+ class TicketHistoryList : public QAbstractListModel
+ {
+ Q_OBJECT
+
+ public:
+ enum TicketHistoryRoles {
+ IdRole = Qt::UserRole + 1,
+ TicketRole,
+ TimeTakenRole,
+ TypeRole,
+ FieldRole,
+ OldValueRole,
+ NewValueRole,
+ DataRole,
+ DescriptionRole,
+ ContentRole,
+ CreatorRole,
+ CreatedRole/*,
+ AttachmentsRole*/
+ };
+
+ explicit TicketHistoryList(QObject* parent = nullptr)
+ : QAbstractListModel{parent} {}
+
+ int rowCount(QModelIndex const& parent
+ = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex& index
+ , int role = Qt::DisplayRole
+ ) const Q_DECL_OVERRIDE;
+
+ public slots:
+ void update(rtclient_ticket_history_list* list);
+
+ protected:
+ QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
+
+ signals:
+ void updated();
+
+ private:
+ QList<TicketHistory> histories;
+ void addTicketHistory(TicketHistory const& history);
+ };
+
+}
+
+#endif // QRTCLIENT_TICKET_HISTORY_HXX
diff --git a/tickethistory.cxx b/tickethistory.cxx
new file mode 100644
index 0000000..4243d7c
--- /dev/null
+++ b/tickethistory.cxx
@@ -0,0 +1,90 @@
+#include <cstddef>
+#include "qrtclient/tickethistory.hxx"
+
+namespace RTClient {
+
+ int TicketHistoryList::rowCount(QModelIndex const& parent) const
+ {
+ Q_UNUSED(parent)
+ return histories.count();
+ }
+
+ QVariant TicketHistoryList::data(QModelIndex const& index, int role) const
+ {
+ auto row = index.row();
+
+ if (row < 0 || row >= histories.count()) return QVariant();
+
+ auto history = histories[row];
+ switch (role) {
+ case IdRole:
+ return history.id();
+ case TicketRole:
+ return history.ticket();
+ case TimeTakenRole:
+ return history.timeTaken();
+ case TypeRole:
+ return history.type();
+ case FieldRole:
+ return history.field();
+ case OldValueRole:
+ return history.oldValue();
+ case NewValueRole:
+ return history.newValue();
+ case DataRole:
+ return history.data();
+ case DescriptionRole:
+ return history.description();
+ case ContentRole:
+ return history.content();
+ case CreatorRole:
+ return history.creator();
+ case CreatedRole:
+ return history.created();
+ /*
+ case AttachmentsRole:
+ return history.attachments();
+ */
+ default:
+ return QVariant();
+ }
+ }
+
+ QHash<int, QByteArray> TicketHistoryList::roleNames() const
+ {
+ return QHash<int, QByteArray>{
+ {IdRole, "id"}
+ , {TicketRole, "ticket"}
+ , {TimeTakenRole, "timeTaken"}
+ , {TypeRole, "type"}
+ , {FieldRole, "field"}
+ , {OldValueRole, "oldValue"}
+ , {NewValueRole, "newValue"}
+ , {DataRole, "data"}
+ , {DescriptionRole, "description"}
+ , {ContentRole, "content"}
+ , {CreatorRole, "creator"}
+ , {CreatedRole, "created"}
+// , {AttachmentsRole, "attachments"}
+ };
+ }
+
+ void TicketHistoryList::addTicketHistory(TicketHistory const& history)
+ {
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ histories << history;
+ endInsertRows();
+ }
+
+ void TicketHistoryList::update(rtclient_ticket_history_list* list)
+ {
+ if (list) {
+ for (size_t i = 0; i < list->length; i++)
+ addTicketHistory
+ (TicketHistory{list->histories[i]});
+ rtclient_ticket_history_list_free(list);
+ }
+ emit updated();
+ }
+
+}