From 3c1223f9a9c26c2e845b6b545989e0f0f60ef6c4 Mon Sep 17 00:00:00 2001 From: Scharel Clemens Date: Fri, 30 Nov 2018 18:40:03 +0100 Subject: [PATCH] Tried to handle notes over id, not index in the subpages. Not that successfully until now. --- qml/harbour-nextcloudnotes.qml | 1 + qml/pages/EditPage.qml | 16 ++++++++-------- qml/pages/NotePage.qml | 35 +++++++++++++++++++--------------- qml/pages/NotesApi.qml | 17 +++++++++-------- qml/pages/NotesPage.qml | 4 +++- 5 files changed, 41 insertions(+), 32 deletions(-) diff --git a/qml/harbour-nextcloudnotes.qml b/qml/harbour-nextcloudnotes.qml index 0cdef86..16bdd51 100644 --- a/qml/harbour-nextcloudnotes.qml +++ b/qml/harbour-nextcloudnotes.qml @@ -39,6 +39,7 @@ ApplicationWindow id: nextcloudAccounts delegate: NotesApi { uuid: nextcloudUUIDs.value[index] + saveFile: true } function add() { push(uuidv4()) diff --git a/qml/pages/EditPage.qml b/qml/pages/EditPage.qml index ed57c34..927fa03 100644 --- a/qml/pages/EditPage.qml +++ b/qml/pages/EditPage.qml @@ -6,11 +6,11 @@ Dialog { id: page onAccepted: { - account.updateNote(account.model.get(noteIndex).id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.selected } ) + account.updateNote(note.id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.selected } ) } property var account - property int noteIndex + property var note SilicaFlickable { id: flickable @@ -21,9 +21,9 @@ Dialog { MenuItem { text: qsTr("Reset") onClicked: { - categoryField.text = account.model.get(noteIndex).category - contentArea.text = account.model.get(noteIndex).content - favoriteButton.selected = account.model.get(noteIndex).favorite + categoryField.text = note.category + contentArea.text = note.content + favoriteButton.selected = note.favorite } } MenuItem { @@ -44,7 +44,7 @@ Dialog { id: contentArea width: parent.width focus: true - text: account.model.get(noteIndex).content + text: note.content onTextChanged: { // TODO Autocomplete list symbols /*var preText = text.substring(0, cursorPosition) @@ -59,7 +59,7 @@ Dialog { width: parent.width - x IconButton { id: favoriteButton - property bool selected: account.model.get(noteIndex).favorite + property bool selected: note.favorite width: Theme.iconSizeMedium icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") + (favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor) @@ -68,7 +68,7 @@ Dialog { TextField { id: categoryField width: parent.width - favoriteButton.width - text: account.model.get(noteIndex).category + text: note.category placeholderText: qsTr("Category") label: placeholderText } diff --git a/qml/pages/NotePage.qml b/qml/pages/NotePage.qml index 2274f24..db2964f 100644 --- a/qml/pages/NotePage.qml +++ b/qml/pages/NotePage.qml @@ -4,6 +4,10 @@ import Sailfish.Silica 1.0 Dialog { id: noteDialog + + property var account + property var note + property var showdown: ShowDown.showdown property var converter: new showdown.Converter( { noHeaderId: true, @@ -14,10 +18,14 @@ Dialog { emoji: true } ) function reloadContent() { - modifiedDetail.value = new Date(account.model.get(noteIndex).modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat) - favoriteDetail.value = account.model.get(noteIndex).favorite ? qsTr("yes") : qsTr("no") - categoryDetail.value = account.model.get(noteIndex).category - var convertedText = converter.makeHtml(account.model.get(noteIndex).content) + var tmpNote = account.getNote(note.id) + if (tmpNote) { + note = tmpNote + } + modifiedDetail.value = new Date(note.modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat) + favoriteDetail.value = note.favorite ? qsTr("yes") : qsTr("no") + categoryDetail.value = note.category + var convertedText = converter.makeHtml(note.content) var occurence = -1 convertedText = convertedText.replace(/^
  • \[ \]\s(.*)<\/li>$/gm, function(match, p1, offset) { @@ -35,11 +43,11 @@ Dialog { } acceptDestination: Qt.resolvedUrl("EditPage.qml") - acceptDestinationProperties: { account: account; noteIndex: noteIndex } - Component.onCompleted: acceptDestinationProperties = { account: account, noteIndex: noteIndex } + acceptDestinationProperties: { account: account; note: note } + Component.onCompleted: acceptDestinationProperties = { account: account, note: note } onStatusChanged: { if (status === PageStatus.Active) { - account.getNote(account.model.get(noteIndex).id) + //account.getNote(note.id) reloadContent() } } @@ -52,9 +60,6 @@ Dialog { } } - property var account - property int noteIndex - SilicaFlickable { anchors.fill: parent contentHeight: mainColumn.height @@ -74,13 +79,13 @@ Dialog { text: qsTr("Delete") enabled: account ? true : false //visible: appSettings.currentAccount >= 0 - onClicked: remorse.execute("Deleting", function() { account.deleteNote(account.model.get(noteIndex).id) } ) + onClicked: remorse.execute("Deleting", function() { account.deleteNote(notey.id) } ) } MenuItem { text: enabled ? qsTr("Reload") : qsTr("Updating...") enabled: account ? !account.busy : false //visible: appSettings.currentAccount >= 0 - onClicked: account.getNote(account.model.get(noteIndex).id) + onClicked: account.getNote(note.id) } MenuLabel { visible: appSettings.currentAccount >= 0 @@ -111,7 +116,7 @@ Dialog { defaultLinkActions: false onLinkActivated: { var occurence = -1 - var newContent = account.model.get(noteIndex).content + var newContent = note.content if (/^tasklist:checkbox_(\d+)$/m.test(link)) { newContent = newContent.replace(/^- \[ \]\s(.*)$/gm, function(match, p1, offset, string) { @@ -123,7 +128,7 @@ Dialog { return match } } ) - account.updateNote(account.model.get(noteIndex).id, { 'content': newContent } ) + account.updateNote(note.id, { 'content': newContent } ) } else if (/^tasklist:uncheckbox_(\d+)$/m.test(link)) { newContent = newContent.replace(/^- \[x\]\s(.*)$/gm, @@ -136,7 +141,7 @@ Dialog { return match } } ) - account.updateNote(account.model.get(noteIndex).id, { 'content': newContent } ) + account.updateNote(note.id, { 'content': newContent } ) } else { Qt.openUrlExternally(link) diff --git a/qml/pages/NotesApi.qml b/qml/pages/NotesApi.qml index 0b178c8..3b3306c 100644 --- a/qml/pages/NotesApi.qml +++ b/qml/pages/NotesApi.qml @@ -14,10 +14,10 @@ Item { property bool unsecureConnection property bool unencryptedConnection - property var modelData: [ ] // TODO use note id as key { note1.id: note1, note2.id, note2, ... } + property var modelData: [ ] // TODO use note id as key { note1.id: note1, note2.id: note2, ... } property var model: ListModel { } - //property string file: StandardPaths.data + "/" + uuid + ".json" - //property bool saveFile: false + property string file: StandardPaths.data + "/" + uuid + ".json" + property bool saveFile: false property bool busy: false property int status: 204 property string statusText: "No Content" @@ -86,10 +86,6 @@ Item { case "GET": if (Array.isArray(json)) { console.log("Received all notes via API: " + endpoint) - /*modelData = [] - json.forEach(function(currentValue, index, array) { - modelData[currentValue.id] = currentValue - } )*/ modelData = json mapDataToModel() update = new Date() @@ -152,6 +148,10 @@ Item { function getNote(id) { if (id) callApi("GET", { 'id': id } ) + modelData.forEach(function(currentValue) { + if (currentValue.id === id) + return currentValue + } ) } function createNote(data) { @@ -200,15 +200,16 @@ Item { modelData.sort(function(a, b) { return b.modified-a.modified } ) break case "category": + modelData.sort(function(a, b) { return b.modified-a.modified } ) modelData.sort(function(a, b) { return ((a.category > b.category) ? 1 : ((b.category > a.category) ? -1 : 0)) } ) break case "title": + modelData.sort(function(a, b) { return b.modified-a.modified } ) modelData.sort(function(a, b) { return ((a.title > b.title) ? 1 : ((b.title > a.title) ? -1 : 0)) } ) break } for (var element in modelData) { model.set(element, modelData[element]) - //model.setProperty(element, "date", getPrettyDate(modelData[element].modified)) } element++ while (model.count > element) { diff --git a/qml/pages/NotesPage.qml b/qml/pages/NotesPage.qml index 4bc3e65..4e01c8b 100644 --- a/qml/pages/NotesPage.qml +++ b/qml/pages/NotesPage.qml @@ -61,6 +61,7 @@ Page { header: PageHeader { title: nextcloudAccounts.itemAt(appSettings.currentAccount).name //qsTr("Nextclound Notes") description: nextcloudAccounts.itemAt(appSettings.currentAccount).username + "@" + nextcloudAccounts.itemAt(appSettings.currentAccount).server + BusyIndicator { x: Theme.horizontalPageMargin anchors.verticalCenter: parent.verticalCenter @@ -176,7 +177,8 @@ Page { } onClicked: pageStack.push(Qt.resolvedUrl("NotePage.qml"), - { account: nextcloudAccounts.itemAt(appSettings.currentAccount), noteIndex: index } ) + { account: nextcloudAccounts.itemAt(appSettings.currentAccount), + note: nextcloudAccounts.itemAt(appSettings.currentAccount).modelData[index]} ) onPressAndHold: menu.open(note) ContextMenu {