Tried to handle notes over id, not index in the subpages. Not that successfully until now.
This commit is contained in:
parent
b782150923
commit
3c1223f9a9
5 changed files with 41 additions and 32 deletions
|
@ -39,6 +39,7 @@ ApplicationWindow
|
||||||
id: nextcloudAccounts
|
id: nextcloudAccounts
|
||||||
delegate: NotesApi {
|
delegate: NotesApi {
|
||||||
uuid: nextcloudUUIDs.value[index]
|
uuid: nextcloudUUIDs.value[index]
|
||||||
|
saveFile: true
|
||||||
}
|
}
|
||||||
function add() {
|
function add() {
|
||||||
push(uuidv4())
|
push(uuidv4())
|
||||||
|
|
|
@ -6,11 +6,11 @@ Dialog {
|
||||||
id: page
|
id: page
|
||||||
|
|
||||||
onAccepted: {
|
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 var account
|
||||||
property int noteIndex
|
property var note
|
||||||
|
|
||||||
SilicaFlickable {
|
SilicaFlickable {
|
||||||
id: flickable
|
id: flickable
|
||||||
|
@ -21,9 +21,9 @@ Dialog {
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: qsTr("Reset")
|
text: qsTr("Reset")
|
||||||
onClicked: {
|
onClicked: {
|
||||||
categoryField.text = account.model.get(noteIndex).category
|
categoryField.text = note.category
|
||||||
contentArea.text = account.model.get(noteIndex).content
|
contentArea.text = note.content
|
||||||
favoriteButton.selected = account.model.get(noteIndex).favorite
|
favoriteButton.selected = note.favorite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
|
@ -44,7 +44,7 @@ Dialog {
|
||||||
id: contentArea
|
id: contentArea
|
||||||
width: parent.width
|
width: parent.width
|
||||||
focus: true
|
focus: true
|
||||||
text: account.model.get(noteIndex).content
|
text: note.content
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
// TODO Autocomplete list symbols
|
// TODO Autocomplete list symbols
|
||||||
/*var preText = text.substring(0, cursorPosition)
|
/*var preText = text.substring(0, cursorPosition)
|
||||||
|
@ -59,7 +59,7 @@ Dialog {
|
||||||
width: parent.width - x
|
width: parent.width - x
|
||||||
IconButton {
|
IconButton {
|
||||||
id: favoriteButton
|
id: favoriteButton
|
||||||
property bool selected: account.model.get(noteIndex).favorite
|
property bool selected: note.favorite
|
||||||
width: Theme.iconSizeMedium
|
width: Theme.iconSizeMedium
|
||||||
icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
|
icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
|
||||||
(favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
|
(favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
|
||||||
|
@ -68,7 +68,7 @@ Dialog {
|
||||||
TextField {
|
TextField {
|
||||||
id: categoryField
|
id: categoryField
|
||||||
width: parent.width - favoriteButton.width
|
width: parent.width - favoriteButton.width
|
||||||
text: account.model.get(noteIndex).category
|
text: note.category
|
||||||
placeholderText: qsTr("Category")
|
placeholderText: qsTr("Category")
|
||||||
label: placeholderText
|
label: placeholderText
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,10 @@ import Sailfish.Silica 1.0
|
||||||
|
|
||||||
Dialog {
|
Dialog {
|
||||||
id: noteDialog
|
id: noteDialog
|
||||||
|
|
||||||
|
property var account
|
||||||
|
property var note
|
||||||
|
|
||||||
property var showdown: ShowDown.showdown
|
property var showdown: ShowDown.showdown
|
||||||
property var converter: new showdown.Converter(
|
property var converter: new showdown.Converter(
|
||||||
{ noHeaderId: true,
|
{ noHeaderId: true,
|
||||||
|
@ -14,10 +18,14 @@ Dialog {
|
||||||
emoji: true } )
|
emoji: true } )
|
||||||
|
|
||||||
function reloadContent() {
|
function reloadContent() {
|
||||||
modifiedDetail.value = new Date(account.model.get(noteIndex).modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
|
var tmpNote = account.getNote(note.id)
|
||||||
favoriteDetail.value = account.model.get(noteIndex).favorite ? qsTr("yes") : qsTr("no")
|
if (tmpNote) {
|
||||||
categoryDetail.value = account.model.get(noteIndex).category
|
note = tmpNote
|
||||||
var convertedText = converter.makeHtml(account.model.get(noteIndex).content)
|
}
|
||||||
|
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
|
var occurence = -1
|
||||||
convertedText = convertedText.replace(/^<li>\[ \]\s(.*)<\/li>$/gm,
|
convertedText = convertedText.replace(/^<li>\[ \]\s(.*)<\/li>$/gm,
|
||||||
function(match, p1, offset) {
|
function(match, p1, offset) {
|
||||||
|
@ -35,11 +43,11 @@ Dialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
acceptDestination: Qt.resolvedUrl("EditPage.qml")
|
acceptDestination: Qt.resolvedUrl("EditPage.qml")
|
||||||
acceptDestinationProperties: { account: account; noteIndex: noteIndex }
|
acceptDestinationProperties: { account: account; note: note }
|
||||||
Component.onCompleted: acceptDestinationProperties = { account: account, noteIndex: noteIndex }
|
Component.onCompleted: acceptDestinationProperties = { account: account, note: note }
|
||||||
onStatusChanged: {
|
onStatusChanged: {
|
||||||
if (status === PageStatus.Active) {
|
if (status === PageStatus.Active) {
|
||||||
account.getNote(account.model.get(noteIndex).id)
|
//account.getNote(note.id)
|
||||||
reloadContent()
|
reloadContent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,9 +60,6 @@ Dialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
property var account
|
|
||||||
property int noteIndex
|
|
||||||
|
|
||||||
SilicaFlickable {
|
SilicaFlickable {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
contentHeight: mainColumn.height
|
contentHeight: mainColumn.height
|
||||||
|
@ -74,13 +79,13 @@ Dialog {
|
||||||
text: qsTr("Delete")
|
text: qsTr("Delete")
|
||||||
enabled: account ? true : false
|
enabled: account ? true : false
|
||||||
//visible: appSettings.currentAccount >= 0
|
//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 {
|
MenuItem {
|
||||||
text: enabled ? qsTr("Reload") : qsTr("Updating...")
|
text: enabled ? qsTr("Reload") : qsTr("Updating...")
|
||||||
enabled: account ? !account.busy : false
|
enabled: account ? !account.busy : false
|
||||||
//visible: appSettings.currentAccount >= 0
|
//visible: appSettings.currentAccount >= 0
|
||||||
onClicked: account.getNote(account.model.get(noteIndex).id)
|
onClicked: account.getNote(note.id)
|
||||||
}
|
}
|
||||||
MenuLabel {
|
MenuLabel {
|
||||||
visible: appSettings.currentAccount >= 0
|
visible: appSettings.currentAccount >= 0
|
||||||
|
@ -111,7 +116,7 @@ Dialog {
|
||||||
defaultLinkActions: false
|
defaultLinkActions: false
|
||||||
onLinkActivated: {
|
onLinkActivated: {
|
||||||
var occurence = -1
|
var occurence = -1
|
||||||
var newContent = account.model.get(noteIndex).content
|
var newContent = note.content
|
||||||
if (/^tasklist:checkbox_(\d+)$/m.test(link)) {
|
if (/^tasklist:checkbox_(\d+)$/m.test(link)) {
|
||||||
newContent = newContent.replace(/^- \[ \]\s(.*)$/gm,
|
newContent = newContent.replace(/^- \[ \]\s(.*)$/gm,
|
||||||
function(match, p1, offset, string) {
|
function(match, p1, offset, string) {
|
||||||
|
@ -123,7 +128,7 @@ Dialog {
|
||||||
return match
|
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)) {
|
else if (/^tasklist:uncheckbox_(\d+)$/m.test(link)) {
|
||||||
newContent = newContent.replace(/^- \[x\]\s(.*)$/gm,
|
newContent = newContent.replace(/^- \[x\]\s(.*)$/gm,
|
||||||
|
@ -136,7 +141,7 @@ Dialog {
|
||||||
return match
|
return match
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
account.updateNote(account.model.get(noteIndex).id, { 'content': newContent } )
|
account.updateNote(note.id, { 'content': newContent } )
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Qt.openUrlExternally(link)
|
Qt.openUrlExternally(link)
|
||||||
|
|
|
@ -14,10 +14,10 @@ Item {
|
||||||
property bool unsecureConnection
|
property bool unsecureConnection
|
||||||
property bool unencryptedConnection
|
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 var model: ListModel { }
|
||||||
//property string file: StandardPaths.data + "/" + uuid + ".json"
|
property string file: StandardPaths.data + "/" + uuid + ".json"
|
||||||
//property bool saveFile: false
|
property bool saveFile: false
|
||||||
property bool busy: false
|
property bool busy: false
|
||||||
property int status: 204
|
property int status: 204
|
||||||
property string statusText: "No Content"
|
property string statusText: "No Content"
|
||||||
|
@ -86,10 +86,6 @@ 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()
|
||||||
|
@ -152,6 +148,10 @@ Item {
|
||||||
function getNote(id) {
|
function getNote(id) {
|
||||||
if (id)
|
if (id)
|
||||||
callApi("GET", { 'id': id } )
|
callApi("GET", { 'id': id } )
|
||||||
|
modelData.forEach(function(currentValue) {
|
||||||
|
if (currentValue.id === id)
|
||||||
|
return currentValue
|
||||||
|
} )
|
||||||
}
|
}
|
||||||
|
|
||||||
function createNote(data) {
|
function createNote(data) {
|
||||||
|
@ -200,15 +200,16 @@ Item {
|
||||||
modelData.sort(function(a, b) { return b.modified-a.modified } )
|
modelData.sort(function(a, b) { return b.modified-a.modified } )
|
||||||
break
|
break
|
||||||
case "category":
|
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)) } )
|
modelData.sort(function(a, b) { return ((a.category > b.category) ? 1 : ((b.category > a.category) ? -1 : 0)) } )
|
||||||
break
|
break
|
||||||
case "title":
|
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)) } )
|
modelData.sort(function(a, b) { return ((a.title > b.title) ? 1 : ((b.title > a.title) ? -1 : 0)) } )
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for (var element in modelData) {
|
for (var element in modelData) {
|
||||||
model.set(element, modelData[element])
|
model.set(element, modelData[element])
|
||||||
//model.setProperty(element, "date", getPrettyDate(modelData[element].modified))
|
|
||||||
}
|
}
|
||||||
element++
|
element++
|
||||||
while (model.count > element) {
|
while (model.count > element) {
|
||||||
|
|
|
@ -61,6 +61,7 @@ Page {
|
||||||
header: PageHeader {
|
header: PageHeader {
|
||||||
title: nextcloudAccounts.itemAt(appSettings.currentAccount).name //qsTr("Nextclound Notes")
|
title: nextcloudAccounts.itemAt(appSettings.currentAccount).name //qsTr("Nextclound Notes")
|
||||||
description: nextcloudAccounts.itemAt(appSettings.currentAccount).username + "@" + nextcloudAccounts.itemAt(appSettings.currentAccount).server
|
description: nextcloudAccounts.itemAt(appSettings.currentAccount).username + "@" + nextcloudAccounts.itemAt(appSettings.currentAccount).server
|
||||||
|
|
||||||
BusyIndicator {
|
BusyIndicator {
|
||||||
x: Theme.horizontalPageMargin
|
x: Theme.horizontalPageMargin
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
@ -176,7 +177,8 @@ Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
onClicked: pageStack.push(Qt.resolvedUrl("NotePage.qml"),
|
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)
|
onPressAndHold: menu.open(note)
|
||||||
|
|
||||||
ContextMenu {
|
ContextMenu {
|
||||||
|
|
Loading…
Reference in a new issue