diff --git a/qml/harbour-nextcloudnotes.qml b/qml/harbour-nextcloudnotes.qml index fea0397..0cdef86 100644 --- a/qml/harbour-nextcloudnotes.qml +++ b/qml/harbour-nextcloudnotes.qml @@ -37,7 +37,9 @@ ApplicationWindow Repeater { id: nextcloudAccounts - delegate: NotesApi { uuid: nextcloudUUIDs.value[index] } + delegate: NotesApi { + uuid: nextcloudUUIDs.value[index] + } function add() { push(uuidv4()) } diff --git a/qml/pages/NotePage.qml b/qml/pages/NotePage.qml index 44701a8..2274f24 100644 --- a/qml/pages/NotePage.qml +++ b/qml/pages/NotePage.qml @@ -5,9 +5,18 @@ import Sailfish.Silica 1.0 Dialog { id: noteDialog property var showdown: ShowDown.showdown - property var converter: new showdown.Converter( { noHeaderId: true, simplifiedAutoLink: true, tables: true, tasklists: false, simpleLineBreaks: true, emoji: true } ) + property var converter: new showdown.Converter( + { noHeaderId: true, + simplifiedAutoLink: true, + tables: true, + tasklists: false, // this is handled by the function reloadContent() because LinkedLabel HTML support is to basic + simpleLineBreaks: true, + 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 occurence = -1 convertedText = convertedText.replace(/^
  • \[ \]\s(.*)<\/li>$/gm, @@ -35,16 +44,7 @@ Dialog { } } Connections { - target: account/*.model.get(noteIndex) - onTitleChanged: { - console.log("Title changed") - dialogHeader.title = account.model.get(noteIndex).title - } - onContentChanged: { - console.log("Content changed") - contentLabel.plainText = account.model.get(noteIndex).content - contentLabel.parse() - }*/ + target: account onBusyChanged: { if (account.busy === false) { reloadContent() @@ -155,16 +155,16 @@ Dialog { width: parent.width DetailItem { + id: modifiedDetail label: qsTr("Modified") - value: new Date(account.model.get(noteIndex).modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat) } DetailItem { + id: favoriteDetail label: qsTr("Favorite") - value: account.model.get(noteIndex).favorite ? qsTr("yes") : qsTr("no") } DetailItem { + id: categoryDetail label: qsTr("Category") - value: account.model.get(noteIndex).category visible: value.length > 0 } } diff --git a/qml/pages/NotesApi.qml b/qml/pages/NotesApi.qml index 3c2a3bc..0b178c8 100644 --- a/qml/pages/NotesApi.qml +++ b/qml/pages/NotesApi.qml @@ -86,6 +86,10 @@ 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() @@ -167,25 +171,25 @@ Item { } function addToModelData(data) { - for (var i = 0; i < modelData.length; i++) { - if (modelData[i].id === data.id) { - modelData[i] = data - break + var dataUpdated = false + modelData.forEach(function(currentValue, index, array) { + if (currentValue.id === data.id) { + array[index] = data + dataUpdated = true } - } - if (i === modelData.length) { + } ) + if (!dataUpdated) { modelData.push(data) } mapDataToModel() } function removeFromModelData(id) { - for (var i = 0; i < modelData.length; i++) { - if (modelData[i].id === id) { + modelData.forEach(function(currentValue, index, array) { + if (currentValue.id === id) { modelData.splice(i, 1) - break } - } + } ) mapDataToModel() }