Skip to content

Commit 42001a2

Browse files
committed
#3357 nextclouddeckdialog: fix cards fetching and disable currently not needed code
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent 29ba1ea commit 42001a2

File tree

4 files changed

+110
-36
lines changed

4 files changed

+110
-36
lines changed

src/dialogs/nextclouddeckdialog.cpp

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@ NextcloudDeckDialog::~NextcloudDeckDialog() { delete ui; }
2525

2626
void NextcloudDeckDialog::setupUi() {
2727
setupMainSplitter();
28+
refreshUi();
2829

2930
ui->newItemEdit->installEventFilter(this);
3031
ui->cardItemTreeWidget->installEventFilter(this);
3132
ui->newItemEdit->setFocus();
3233

3334
// Adding shortcuts not working when defined in the ui file
34-
auto *shortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+S")), this);
35-
QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(on_saveButton_clicked()));
36-
shortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+I")), this);
37-
QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(onSaveAndInsertButtonClicked()));
38-
shortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+R")), this);
39-
QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(on_removeButton_clicked()));
35+
// auto *shortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+S")), this);
36+
// QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(on_saveButton_clicked()));
37+
// shortcut = new QShortcut(QKeySequence(QStringLiteral("Ctrl+I")), this);
38+
// QObject::connect(shortcut, SIGNAL(activated()), this,
39+
// SLOT(onSaveAndInsertButtonClicked())); shortcut = new
40+
// QShortcut(QKeySequence(QStringLiteral("Ctrl+R")), this); QObject::connect(shortcut,
41+
// SIGNAL(activated()), this, SLOT(on_removeButton_clicked()));
4042

4143
/*
4244
* Set up the note button menu
@@ -49,14 +51,14 @@ void NextcloudDeckDialog::setupUi() {
4951
insertAction->setToolTip(
5052
tr("Save the current todo item and insert a link"
5153
" to it into the current note"));
52-
connect(insertAction, SIGNAL(triggered()), this, SLOT(onSaveAndInsertButtonClicked()));
54+
// connect(insertAction, SIGNAL(triggered()), this, SLOT(onSaveAndInsertButtonClicked()));
5355

5456
QAction *importAction = noteMenu->addAction(tr("Import as note"));
5557
importAction->setIcon(
5658
QIcon::fromTheme(QStringLiteral("document-import"),
5759
QIcon(":icons/breeze-qownnotes/16x16/document-import.svg")));
5860
importAction->setToolTip(tr("Import the current todo item as new note"));
59-
connect(importAction, SIGNAL(triggered()), this, SLOT(onImportAsNoteButtonClicked()));
61+
// connect(importAction, SIGNAL(triggered()), this, SLOT(onImportAsNoteButtonClicked()));
6062

6163
// ui->noteButton->setMenu(noteMenu);
6264

@@ -154,3 +156,42 @@ void NextcloudDeckDialog::setupMainSplitter() {
154156

155157
ui->gridLayout->layout()->addWidget(this->mainSplitter);
156158
}
159+
160+
void NextcloudDeckDialog::refreshUi() { reloadCardList(); }
161+
162+
void NextcloudDeckDialog::reloadCardList() {
163+
NextcloudDeckService nextcloudDeckService(this);
164+
auto cards = nextcloudDeckService.getCards();
165+
166+
qDebug() << __func__ << " - 'cards': " << cards;
167+
168+
// Clear existing items
169+
ui->cardItemTreeWidget->clear();
170+
171+
// Populate the tree widget with cards
172+
for (const auto &card : cards) {
173+
auto *item = new QTreeWidgetItem(ui->cardItemTreeWidget);
174+
175+
// Set the summary (title) in the first column
176+
item->setText(0, card.title);
177+
178+
// Set the due date in the second column
179+
if (card.duedate.isValid()) {
180+
item->setText(1, card.duedate.toString("yyyy-MM-dd hh:mm"));
181+
} else {
182+
item->setText(1, tr("No due date"));
183+
}
184+
185+
// Store the card ID as user data for later reference
186+
item->setData(0, Qt::UserRole, card.id);
187+
188+
// Set tooltip with description if available
189+
if (!card.description.isEmpty()) {
190+
item->setToolTip(0, card.description);
191+
}
192+
}
193+
194+
// Auto-resize columns to content
195+
ui->cardItemTreeWidget->resizeColumnToContents(0);
196+
ui->cardItemTreeWidget->resizeColumnToContents(1);
197+
}

src/dialogs/nextclouddeckdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ class NextcloudDeckDialog : public MasterDialog {
3737

3838
void on_dueDateTimeCheckBox_toggled(bool checked);
3939

40+
void reloadCardList();
41+
4042
private:
4143
Ui::NextcloudDeckDialog *ui;
4244
void setupMainSplitter();
4345
QSplitter *mainSplitter;
4446
void setupUi();
47+
void refreshUi();
4548
};
4649

4750
#endif // NEXTCLOUDDECKDIALOG_H

src/services/nextclouddeckservice.cpp

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,9 @@ QList<NextcloudDeckService::Card> NextcloudDeckService::getCards() {
254254
// 10 sec timeout for the request
255255
timer.start(10000);
256256

257+
// Use the boards endpoint with details to get all cards from all stacks
257258
QUrl url(serverUrl + "/index.php/apps/deck/api/v1.1/boards/" + QString::number(this->boardId) +
258-
"/stacks/" + QString::number(this->stackId) + "/cards");
259+
"/stacks?details=true");
259260
qDebug() << __func__ << " - 'url': " << url;
260261

261262
QNetworkRequest networkRequest = QNetworkRequest(url);
@@ -289,38 +290,57 @@ QList<NextcloudDeckService::Card> NextcloudDeckService::getCards() {
289290
if (returnStatusCode >= 200 && returnStatusCode < 300) {
290291
// get the data from the network reply
291292
data = reply->readAll();
293+
qDebug() << __func__ << " - 'data': " << data;
294+
292295
QJsonDocument jsonDoc = QJsonDocument::fromJson(data);
293296

294297
if (jsonDoc.isArray()) {
295-
QJsonArray jsonArray = jsonDoc.array();
296-
297-
for (auto jsonValue : jsonArray) {
298-
QJsonObject object = jsonValue.toObject();
299-
300-
NextcloudDeckService::Card card;
301-
card.id = object["id"].toInt();
302-
card.title = object["title"].toString();
303-
card.description = object["description"].toString();
304-
card.order = object["order"].toInt();
305-
card.type = object["type"].toString();
306-
307-
// Parse datetime fields if they exist
308-
QString duedateStr = object["duedate"].toString();
309-
if (!duedateStr.isEmpty()) {
310-
card.duedate = QDateTime::fromString(duedateStr, Qt::ISODate);
311-
}
312-
313-
QString createdAtStr = object["createdAt"].toString();
314-
if (!createdAtStr.isEmpty()) {
315-
card.createdAt = QDateTime::fromString(createdAtStr, Qt::ISODate);
316-
}
298+
QJsonArray stacksArray = jsonDoc.array();
299+
300+
for (auto stackValue : stacksArray) {
301+
QJsonObject stackObject = stackValue.toObject();
302+
int currentStackId = stackObject["id"].toInt();
303+
304+
// Only process cards from the configured stack
305+
if (currentStackId == this->stackId) {
306+
QJsonArray cardsArray = stackObject["cards"].toArray();
307+
308+
for (auto cardValue : cardsArray) {
309+
QJsonObject object = cardValue.toObject();
310+
311+
NextcloudDeckService::Card card;
312+
card.id = object["id"].toInt();
313+
card.title = object["title"].toString();
314+
card.description = object["description"].toString();
315+
card.order = object["order"].toInt();
316+
card.type = object["type"].toString();
317+
318+
// Parse datetime fields from Unix timestamps
319+
qint64 duedateTimestamp = object["duedate"].toVariant().toLongLong();
320+
if (duedateTimestamp > 0) {
321+
card.duedate = QDateTime::fromSecsSinceEpoch(duedateTimestamp);
322+
}
323+
324+
qint64 createdAtTimestamp =
325+
object["createdAt"].toVariant().toLongLong();
326+
if (createdAtTimestamp > 0) {
327+
card.createdAt = QDateTime::fromSecsSinceEpoch(createdAtTimestamp);
328+
}
329+
330+
qint64 lastModifiedTimestamp =
331+
object["lastModified"].toVariant().toLongLong();
332+
if (lastModifiedTimestamp > 0) {
333+
card.lastModified =
334+
QDateTime::fromSecsSinceEpoch(lastModifiedTimestamp);
335+
}
336+
337+
qDebug() << __func__ << " - found card: " << card;
338+
cards.append(card);
339+
}
317340

318-
QString lastModifiedStr = object["lastModified"].toString();
319-
if (!lastModifiedStr.isEmpty()) {
320-
card.lastModified = QDateTime::fromString(lastModifiedStr, Qt::ISODate);
341+
// We found our stack, no need to continue
342+
break;
321343
}
322-
323-
cards.append(card);
324344
}
325345
}
326346

src/services/nextclouddeckservice.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define QOWNNOTES_NEXTCLOUDDECKSERVICE_H
33

44
#include <QDateTime>
5+
#include <QDebug>
56
#include <QObject>
67
#include <QtNetwork/QNetworkRequest>
78

@@ -34,6 +35,15 @@ class NextcloudDeckService : public QObject {
3435
QString type;
3536
QDateTime createdAt;
3637
QDateTime lastModified;
38+
39+
friend QDebug operator<<(QDebug dbg, const Card& card) {
40+
dbg.nospace() << "Card: <id>" << card.id << " <title>" << card.title << " <description>"
41+
<< card.description << " <duedate>" << card.duedate.toString(Qt::ISODate)
42+
<< " <order>" << card.order << " <type>" << card.type << " <createdAt>"
43+
<< card.createdAt.toString(Qt::ISODate) << " <lastModified>"
44+
<< card.lastModified.toString(Qt::ISODate);
45+
return dbg.space();
46+
}
3747
};
3848

3949
public:

0 commit comments

Comments
 (0)