Worked on NotesApi

This commit is contained in:
Scharel Clemens 2018-11-30 15:12:16 +01:00
parent 717d0855e1
commit b782150923
3 changed files with 31 additions and 25 deletions

View file

@ -37,7 +37,9 @@ ApplicationWindow
Repeater { Repeater {
id: nextcloudAccounts id: nextcloudAccounts
delegate: NotesApi { uuid: nextcloudUUIDs.value[index] } delegate: NotesApi {
uuid: nextcloudUUIDs.value[index]
}
function add() { function add() {
push(uuidv4()) push(uuidv4())
} }

View file

@ -5,9 +5,18 @@ import Sailfish.Silica 1.0
Dialog { Dialog {
id: noteDialog id: noteDialog
property var showdown: ShowDown.showdown 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() { 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 convertedText = converter.makeHtml(account.model.get(noteIndex).content)
var occurence = -1 var occurence = -1
convertedText = convertedText.replace(/^<li>\[ \]\s(.*)<\/li>$/gm, convertedText = convertedText.replace(/^<li>\[ \]\s(.*)<\/li>$/gm,
@ -35,16 +44,7 @@ Dialog {
} }
} }
Connections { Connections {
target: account/*.model.get(noteIndex) target: account
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()
}*/
onBusyChanged: { onBusyChanged: {
if (account.busy === false) { if (account.busy === false) {
reloadContent() reloadContent()
@ -155,16 +155,16 @@ Dialog {
width: parent.width width: parent.width
DetailItem { DetailItem {
id: modifiedDetail
label: qsTr("Modified") label: qsTr("Modified")
value: new Date(account.model.get(noteIndex).modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
} }
DetailItem { DetailItem {
id: favoriteDetail
label: qsTr("Favorite") label: qsTr("Favorite")
value: account.model.get(noteIndex).favorite ? qsTr("yes") : qsTr("no")
} }
DetailItem { DetailItem {
id: categoryDetail
label: qsTr("Category") label: qsTr("Category")
value: account.model.get(noteIndex).category
visible: value.length > 0 visible: value.length > 0
} }
} }

View file

@ -86,6 +86,10 @@ Item {
case "GET": case "GET":
if (Array.isArray(json)) { if (Array.isArray(json)) {
console.log("Received all notes via API: " + endpoint) console.log("Received all notes via API: " + endpoint)
/*modelData = []
json.forEach(function(currentValue, index, array) {
modelData[currentValue.id] = currentValue
} )*/
modelData = json modelData = json
mapDataToModel() mapDataToModel()
update = new Date() update = new Date()
@ -167,25 +171,25 @@ Item {
} }
function addToModelData(data) { function addToModelData(data) {
for (var i = 0; i < modelData.length; i++) { var dataUpdated = false
if (modelData[i].id === data.id) { modelData.forEach(function(currentValue, index, array) {
modelData[i] = data if (currentValue.id === data.id) {
break array[index] = data
dataUpdated = true
} }
} } )
if (i === modelData.length) { if (!dataUpdated) {
modelData.push(data) modelData.push(data)
} }
mapDataToModel() mapDataToModel()
} }
function removeFromModelData(id) { function removeFromModelData(id) {
for (var i = 0; i < modelData.length; i++) { modelData.forEach(function(currentValue, index, array) {
if (modelData[i].id === id) { if (currentValue.id === id) {
modelData.splice(i, 1) modelData.splice(i, 1)
break
} }
} } )
mapDataToModel() mapDataToModel()
} }