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 {
id: nextcloudAccounts
delegate: NotesApi { uuid: nextcloudUUIDs.value[index] }
delegate: NotesApi {
uuid: nextcloudUUIDs.value[index]
}
function add() {
push(uuidv4())
}

View file

@ -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(/^<li>\[ \]\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
}
}

View file

@ -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()
}