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

View file

@ -1,10 +1,15 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
Dialog {
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 {
id: flickable
@ -12,9 +17,10 @@ Page {
contentHeight: column.height
PullDownMenu {
quickSelect: true
MenuItem {
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
width: parent.width// - 2*x
PageHeader {
title: note.title
DialogHeader {
title: account.model.get(noteIndex).title
}
TextArea {
id: contentArea
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
DialogHeader {
id: header
//title: qsTr("Nextcloud Login")
acceptText: qsTr("Login")
}

View file

@ -1,10 +1,21 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
id: page
Dialog {
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: [
{ regex: new RegExp(/(^#\s)(.*)$/gm), replace: '<h1>$2</h1>' },
{ regex: new RegExp(/(^##\s)(.*)$/gm), replace: '<h2>$2</h2>' },
@ -17,32 +28,35 @@ Page {
]
SilicaFlickable {
id: flickable
anchors.fill: parent
contentHeight: column.height
PullDownMenu {
/*PullDownMenu {
quickSelect: true
MenuItem {
text: qsTr("Edit")
onClicked: pageStack.push(Qt.resolvedUrl("EditPage.qml"), { note: note } )
}
}
}*/
Column {
id: column
width: parent.width
PageHeader {
title: note.title
DialogHeader {
title: account.model.get(noteIndex).title
acceptText: qsTr("Edit")
cancelText: qsTr("Notes")
}
LinkedLabel {
x: Theme.horizontalPageMargin
width: parent.width - 2*x
textFormat: Text.StyledText
text: note.content
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++) {
text = text.replace(markdown[i].regex, markdown[i].replace)
}

View file

@ -13,10 +13,9 @@ Item {
property bool unencryptedConnection
property var model: ListModel { }
property string file: StandardPaths.data + "/" + uuid + ".json"
property bool saveFile: false
//property string file: StandardPaths.data + "/" + uuid + ".json"
//property bool saveFile: false
property bool busy: false
//property date lastUpdate: new Date(0)
ConfigurationGroup {
id: account
@ -43,6 +42,7 @@ Item {
onUnencryptedConnectionChanged: account.setValue("unencryptedConnection", unencryptedConnection)
function clear() {
model.clear()
account.clear()
}
@ -50,9 +50,11 @@ Item {
busy = true
var endpoint = server + "/index.php/apps/notes/api/v0.2/notes"
if (data && (method === "GET" || method === "PUT" || method === "DELETE"))
if (data.id)
if (data && (method === "GET" || method === "PUT" || method === "DELETE")) {
if (data.id) {
endpoint = endpoint + "/" + data.id
}
}
var apiReq = new XMLHttpRequest
apiReq.open(method, endpoint, true)
@ -63,13 +65,50 @@ Item {
apiReq.onreadystatechange = function() {
if (apiReq.readyState === XMLHttpRequest.DONE) {
if (apiReq.status === 200) {
console.log("Successfull request!")
console.log("Successfull API request!")
//console.log(apiReq.responseText)
// TODO handle non arrays
model.clear()
var elements = JSON.parse(apiReq.responseText)
for (var element in elements) {
model.append(elements[element])
var json = JSON.parse(apiReq.responseText)
switch(method) {
case "GET":
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) {
@ -87,7 +126,7 @@ Item {
busy = false
}
else {
console.log("HTTP ready state: " + apiReq.readyState)
//console.log("HTTP ready state: " + apiReq.readyState)
}
}
if (method === "GET") {
@ -127,18 +166,6 @@ Item {
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() {
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: {
if (saveFile) {
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).toLocaleString(Qt.locale(), Locale.ShortFormat) :
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
placeholderText: qsTr("Nextcloud Notes")
onTextChanged: notes.search(text.toLowerCase())
EnterKey.iconSource: "image://theme/icon-m-enter-close"
EnterKey.onClicked: focus = false
enabled: notesList.count > 0
enabled: notesList.count > 0*/
}
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
Connections {
@ -96,7 +85,7 @@ Page {
onClicked: {
console.log("Toggle 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
}
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 {
Label {
@ -176,7 +165,6 @@ Page {
TouchInteractionHint {
id: addAccountHint
//Component.onCompleted: if(!account.valid) restart()
interactionMode: TouchInteraction.Pull
direction: TouchInteraction.Down
}

View file

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