First version that is somehow usable.

This commit is contained in:
Scharel Clemens 2018-11-18 11:25:28 +01:00
parent d2601ba749
commit 344f78b70f
7 changed files with 122 additions and 74 deletions

View file

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

View file

@ -1,10 +1,15 @@
import QtQuick 2.0 import QtQuick 2.0
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
Page { Dialog {
id: page id: page
property var note onAccepted: {
account.updateNote(account.model.get(noteIndex).id, { 'category': categoryField.text, 'content': contentArea.text, 'favorite': favoriteButton.down } )
}
property var account
property int noteIndex
SilicaFlickable { SilicaFlickable {
id: flickable id: flickable
@ -12,9 +17,10 @@ Page {
contentHeight: column.height contentHeight: column.height
PullDownMenu { PullDownMenu {
quickSelect: true
MenuItem { MenuItem {
text: qsTr("Markdown Cheatsheet") text: qsTr("Markdown Cheatsheet")
onClicked: pageStack.push(Qt.resolvedUrl("MarkDownPage.qml")) onClicked: pageStack.push(Qt.resolvedUrl("MarkdownPage.qml"))
} }
} }
@ -22,13 +28,34 @@ Page {
id: column id: column
width: parent.width// - 2*x width: parent.width// - 2*x
PageHeader { DialogHeader {
title: note.title title: account.model.get(noteIndex).title
} }
TextArea { TextArea {
id: contentArea
width: parent.width width: parent.width
text: note.content text: account.model.get(noteIndex).content
}
Row {
x: Theme.horizontalPageMargin
width: parent.width - x
IconButton {
id: favoriteButton
width: Theme.iconSizeMedium
icon.source: (account.model.get(noteIndex).favorite ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
(favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
onClicked: account.model.get(noteIndex).favorite = !account.model.get(noteIndex).favorite
}
TextField {
id: categoryField
width: parent.width - favoriteButton.width
text: account.model.get(noteIndex).category
placeholderText: qsTr("Category")
label: placeholderText
}
} }
} }

View file

@ -26,7 +26,6 @@ Dialog {
width: parent.width width: parent.width
DialogHeader { DialogHeader {
id: header
//title: qsTr("Nextcloud Login") //title: qsTr("Nextcloud Login")
acceptText: qsTr("Login") acceptText: qsTr("Login")
} }

View file

@ -1,10 +1,21 @@
import QtQuick 2.0 import QtQuick 2.0
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
Page { Dialog {
id: page id: noteDialog
acceptDestination: Qt.resolvedUrl("EditPage.qml")
acceptDestinationProperties: { account: account; noteIndex: noteIndex }
/*onAcceptPendingChanged: {
if (acceptPending) {
acceptDestinationInstance.note = note
}
}*/
Component.onCompleted: acceptDestinationProperties = { account: account, noteIndex: noteIndex }//acceptDestinationInstance.note = note
property var account
property int noteIndex
property var note
property var markdown: [ property var markdown: [
{ regex: new RegExp(/(^#\s)(.*)$/gm), replace: '<h1>$2</h1>' }, { regex: new RegExp(/(^#\s)(.*)$/gm), replace: '<h1>$2</h1>' },
{ regex: new RegExp(/(^##\s)(.*)$/gm), replace: '<h2>$2</h2>' }, { regex: new RegExp(/(^##\s)(.*)$/gm), replace: '<h2>$2</h2>' },
@ -17,32 +28,35 @@ Page {
] ]
SilicaFlickable { SilicaFlickable {
id: flickable
anchors.fill: parent anchors.fill: parent
contentHeight: column.height contentHeight: column.height
PullDownMenu { /*PullDownMenu {
quickSelect: true quickSelect: true
MenuItem { MenuItem {
text: qsTr("Edit") text: qsTr("Edit")
onClicked: pageStack.push(Qt.resolvedUrl("EditPage.qml"), { note: note } ) onClicked: pageStack.push(Qt.resolvedUrl("EditPage.qml"), { note: note } )
} }
} }*/
Column { Column {
id: column id: column
width: parent.width width: parent.width
PageHeader { DialogHeader {
title: note.title title: account.model.get(noteIndex).title
acceptText: qsTr("Edit")
cancelText: qsTr("Notes")
} }
LinkedLabel { LinkedLabel {
x: Theme.horizontalPageMargin x: Theme.horizontalPageMargin
width: parent.width - 2*x width: parent.width - 2*x
textFormat: Text.StyledText textFormat: Text.StyledText
text: note.content
Component.onCompleted: { Component.onCompleted: {
var lines = account.model.get(noteIndex).content.split('\n')
lines.splice(0,1);
text = lines.join('\n');
for (var i=0; i < markdown.length; i++) { for (var i=0; i < markdown.length; i++) {
text = text.replace(markdown[i].regex, markdown[i].replace) text = text.replace(markdown[i].regex, markdown[i].replace)
} }

View file

@ -13,10 +13,9 @@ Item {
property bool unencryptedConnection property bool unencryptedConnection
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 date lastUpdate: new Date(0)
ConfigurationGroup { ConfigurationGroup {
id: account id: account
@ -43,6 +42,7 @@ Item {
onUnencryptedConnectionChanged: account.setValue("unencryptedConnection", unencryptedConnection) onUnencryptedConnectionChanged: account.setValue("unencryptedConnection", unencryptedConnection)
function clear() { function clear() {
model.clear()
account.clear() account.clear()
} }
@ -50,9 +50,11 @@ Item {
busy = true busy = true
var endpoint = server + "/index.php/apps/notes/api/v0.2/notes" var endpoint = server + "/index.php/apps/notes/api/v0.2/notes"
if (data && (method === "GET" || method === "PUT" || method === "DELETE")) if (data && (method === "GET" || method === "PUT" || method === "DELETE")) {
if (data.id) if (data.id) {
endpoint = endpoint + "/" + data.id endpoint = endpoint + "/" + data.id
}
}
var apiReq = new XMLHttpRequest var apiReq = new XMLHttpRequest
apiReq.open(method, endpoint, true) apiReq.open(method, endpoint, true)
@ -63,13 +65,50 @@ Item {
apiReq.onreadystatechange = function() { apiReq.onreadystatechange = function() {
if (apiReq.readyState === XMLHttpRequest.DONE) { if (apiReq.readyState === XMLHttpRequest.DONE) {
if (apiReq.status === 200) { if (apiReq.status === 200) {
console.log("Successfull request!") console.log("Successfull API request!")
//console.log(apiReq.responseText) //console.log(apiReq.responseText)
// TODO handle non arrays
model.clear() var json = JSON.parse(apiReq.responseText)
var elements = JSON.parse(apiReq.responseText) switch(method) {
for (var element in elements) { case "GET":
model.append(elements[element]) if (Array.isArray(json)) {
console.log("Got all notes")
model.clear()
for (var element in json) {
model.append(json[element])
}
update = new Date()
}
else {
console.log("Got a single note")
for (var i = 0; i < model.count; i++) {
var listItem = model.get(i)
if (listItem.id === json.id){
model.set(i, json)
}
}
}
break;
case "POST":
console.log("Created a note")
model.append(json)
model.move(model.count-1, 0, 1)
break;
case "PUT":
console.log("Updated a note")
for (var i = 0; i < model.count; i++) {
var listItem = model.get(i)
if (listItem.id === json.id){
model.set(i, json)
}
}
break;
case "DELETE":
console.log("Deleted a note")
break;
default:
console.log("Unsupported method: " + method)
break;
} }
}/* }/*
else if (apiReq.status === 304) { else if (apiReq.status === 304) {
@ -87,7 +126,7 @@ Item {
busy = false busy = false
} }
else { else {
console.log("HTTP ready state: " + apiReq.readyState) //console.log("HTTP ready state: " + apiReq.readyState)
} }
} }
if (method === "GET") { if (method === "GET") {
@ -127,18 +166,6 @@ Item {
callApi("DELETE", { 'id': id } ) callApi("DELETE", { 'id': id } )
} }
//onJsonChanged: refresh()
function flush() {
json = ""
var filePut = new XMLHttpRequest
filePut.open("PUT", file)
filePut.send(json)
model.clear()
update = new Date(0)
status = 200
}
function refresh() { function refresh() {
search("") search("")
} }
@ -159,20 +186,6 @@ Item {
} }
} }
function parseJson() {
var elements = JSON.parse(json)
if (elements === null) {
console.log("Error parsing " + uuid + "-JSON")
elements = ""
json = ""
return null
}
else {
model.clear()
return elements
}
}
/*Component.onCompleted: { /*Component.onCompleted: {
if (saveFile) { if (saveFile) {
if (account.name === "") { if (account.name === "") {

View file

@ -46,34 +46,23 @@ Page {
new Date(nextcloudAccounts.itemAt(appSettings.currentAccount).update).valueOf() !== 0 ? new Date(nextcloudAccounts.itemAt(appSettings.currentAccount).update).valueOf() !== 0 ?
new Date(nextcloudAccounts.itemAt(appSettings.currentAccount).update).toLocaleString(Qt.locale(), Locale.ShortFormat) : new Date(nextcloudAccounts.itemAt(appSettings.currentAccount).update).toLocaleString(Qt.locale(), Locale.ShortFormat) :
qsTr("never"))) : "" qsTr("never"))) : ""
//(new Date(appSettings.value("accountUpdates", [appSettings.currentAccount])).value === 0 ?
//new Date(appSettings.value("accountUpdates", [appSettings.currentAccount])).toLocaleString(Qt.locale(), Locale.ShortFormat) :
//qsTr("never"))
} }
} }
header: SearchField { header: PageHeader {
title: qsTr("Nextclound Notes")
description: nextcloudAccounts.itemAt(appSettings.currentAccount).username + "@" + nextcloudAccounts.itemAt(appSettings.currentAccount).server
/*SearchField {
width: parent.width width: parent.width
placeholderText: qsTr("Nextcloud Notes") placeholderText: qsTr("Nextcloud Notes")
onTextChanged: notes.search(text.toLowerCase()) onTextChanged: notes.search(text.toLowerCase())
EnterKey.iconSource: "image://theme/icon-m-enter-close" EnterKey.iconSource: "image://theme/icon-m-enter-close"
EnterKey.onClicked: focus = false EnterKey.onClicked: focus = false
enabled: notesList.count > 0 enabled: notesList.count > 0*/
} }
currentIndex: -1 currentIndex: -1
Component.onCompleted: {
if (nextcloudAccounts.itemAt(appSettings.currentAccount)) {
nextcloudAccounts.itemAt(appSettings.currentAccount).getNotes()
}
}
//Component.onCompleted: notes.getNotes()
//Component.onCompleted: notes.getNote("1212725")
//Component.onCompleted: notes.createNote("Hello World!", "Test")
//Component.onCompleted: notes.updateNote(1212725, "# Hello World!\nIs this working?", "Test")
//Component.onCompleted: notes.deleteNote(1212725)
model: nextcloudAccounts.itemAt(appSettings.currentAccount)? nextcloudAccounts.itemAt(appSettings.currentAccount).model : 0 model: nextcloudAccounts.itemAt(appSettings.currentAccount)? nextcloudAccounts.itemAt(appSettings.currentAccount).model : 0
Connections { Connections {
@ -96,7 +85,7 @@ Page {
onClicked: { onClicked: {
console.log("Toggle favorite") console.log("Toggle favorite")
favorite = !favorite favorite = !favorite
notes.updateNote(id, {'favorite': favorite} ) nextcloudAccounts.itemAt(appSettings.currentAccount).updateNote(id, {'favorite': favorite} )
} }
} }
@ -129,7 +118,7 @@ Page {
color: note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor color: note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor
} }
onClicked: pageStack.push(Qt.resolvedUrl("NotePage.qml"), { note: notesList.model.get(index) } ) onClicked: pageStack.push(Qt.resolvedUrl("NotePage.qml"), { account: nextcloudAccounts.itemAt(appSettings.currentAccount), noteIndex: index } )
menu: ContextMenu { menu: ContextMenu {
Label { Label {
@ -176,7 +165,6 @@ Page {
TouchInteractionHint { TouchInteractionHint {
id: addAccountHint id: addAccountHint
//Component.onCompleted: if(!account.valid) restart()
interactionMode: TouchInteraction.Pull interactionMode: TouchInteraction.Pull
direction: TouchInteraction.Down direction: TouchInteraction.Down
} }

View file

@ -29,6 +29,10 @@
<source>Markdown Cheatsheet</source> <source>Markdown Cheatsheet</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>LoginDialog</name> <name>LoginDialog</name>
@ -86,6 +90,10 @@
<source>Edit</source> <source>Edit</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Notes</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>NotesPage</name> <name>NotesPage</name>