Worked on login handling. Still in early development.

This commit is contained in:
Scharel Clemens 2018-10-22 22:53:14 +02:00
parent 6262b35302
commit 0deafe6b08
7 changed files with 144 additions and 53 deletions

View file

@ -28,7 +28,8 @@ DISTFILES += qml/harbour-nextcloudnotes.qml \
qml/pages/NotePage.qml \ qml/pages/NotePage.qml \
qml/pages/NotesPage.qml \ qml/pages/NotesPage.qml \
qml/pages/LoginDialog.qml \ qml/pages/LoginDialog.qml \
qml/pages/EditPage.qml qml/pages/EditPage.qml \
qml/pages/SettingsPage.qml
SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172 SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172

View file

@ -10,24 +10,23 @@ ApplicationWindow
ConfigurationGroup { ConfigurationGroup {
id: appSettings id: appSettings
path: "/apps/harbour-nextcloudnotes/settings" path: "/apps/harbour-nextcloudnotes/settings"
property string lastUpdate: qsTr("never") property var accounts: value("accounts", [])
property url server: "" property int currentAccount: 0
property string username: ""
property string password: ""
property bool unsecureConnection: false
// For testing // For testing
Component.onCompleted: { Component.onCompleted: {
//server = "" //appSettings.clear()
//username = "" for(var i=0; i<accounts.length; i++) {
//password = "" console.log("Server: " + accounts[i].server)
console.log("Server: " + server) console.log("Username: " + accounts[i].username)
console.log("Username: " + username) console.log("Password: " + accounts[i].password)
console.log("Password: " + password) }
//notes.account = appSettings.accounts[appSettings.currentAccount]
} }
} }
property var notes: NotesApi { property var notes: NotesApi {
name: "notes" name: "notes"
account: appSettings.accounts[appSettings.currentAccount]
saveFile: false saveFile: false
} }
Connections { Connections {

View file

@ -4,15 +4,16 @@ import Sailfish.Silica 1.0
Dialog { Dialog {
id: loginDialog id: loginDialog
property url server property var account
property string username
property string password
canAccept: (serverField.acceptableInput && usernameField.text.length > 0 && passwordField.text.length > 0) canAccept: (serverField.acceptableInput && usernameField.text.length > 0 && passwordField.text.length > 0)
onAccepted: { onAccepted: {
server = serverField.text account = {
username = usernameField.text server: serverField.text,
password = passwordField.text username: usernameField.text,
password: passwordField.text,
lastUpdate: new Date(0)
}
} }
Column { Column {
@ -35,7 +36,7 @@ Dialog {
id: serverField id: serverField
focus: true focus: true
width: parent.width width: parent.width
text: (server.toString().length > 0) ? server : "https://" text: (typeof(account) !== 'undefined' && account.server.toString().length > 0) ? account.server : "https://"
placeholderText: qsTr("Nextcloud server") placeholderText: qsTr("Nextcloud server")
label: placeholderText + " " + qsTr("(starting with \"https://\")") label: placeholderText + " " + qsTr("(starting with \"https://\")")
inputMethodHints: Qt.ImhUrlCharactersOnly inputMethodHints: Qt.ImhUrlCharactersOnly
@ -49,7 +50,7 @@ Dialog {
TextField { TextField {
id: usernameField id: usernameField
width: parent.width width: parent.width
text: (username.length > 0) ? username : "" text: (typeof(account) !== 'undefined' && account.username.length > 0) ? account.username : ""
placeholderText: qsTr("Username") placeholderText: qsTr("Username")
label: placeholderText label: placeholderText
inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase
@ -62,7 +63,7 @@ Dialog {
PasswordField { PasswordField {
id: passwordField id: passwordField
width: parent.width width: parent.width
text: (password.length > 0) ? password : "" text: (typeof(account) !== 'undefined' && account.password.length > 0) ? account.password : ""
label: placeholderText label: placeholderText
errorHighlight: text.length === 0 && focus === true errorHighlight: text.length === 0 && focus === true
EnterKey.enabled: text.length > 0 EnterKey.enabled: text.length > 0

View file

@ -3,6 +3,7 @@ import Sailfish.Silica 1.0
Item { Item {
property string name property string name
property var account
property var model: ListModel { } property var model: ListModel { }
property string json property string json
@ -14,7 +15,7 @@ Item {
function callApi(method, data) { function callApi(method, data) {
busy = true busy = true
var endpoint = appSettings.server + "/index.php/apps/notes/api/v0.2/notes" var endpoint = account.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
@ -24,7 +25,7 @@ Item {
apiReq.setRequestHeader('User-Agent', 'SailfishOS/harbour-nextcloudnotes') apiReq.setRequestHeader('User-Agent', 'SailfishOS/harbour-nextcloudnotes')
apiReq.setRequestHeader('OCS-APIRequest', 'true') apiReq.setRequestHeader('OCS-APIRequest', 'true')
apiReq.setRequestHeader("Content-Type", "application/json") apiReq.setRequestHeader("Content-Type", "application/json")
apiReq.setRequestHeader("Authorization", "Basic " + Qt.btoa(appSettings.username + ":" + appSettings.password)) apiReq.setRequestHeader("Authorization", "Basic " + Qt.btoa(account.username + ":" + account.password))
apiReq.onreadystatechange = function() { apiReq.onreadystatechange = function() {
if (apiReq.readyState === XMLHttpRequest.DONE) { if (apiReq.readyState === XMLHttpRequest.DONE) {
if (apiReq.status === 200) { if (apiReq.status === 200) {

View file

@ -11,30 +11,25 @@ Page {
PullDownMenu { PullDownMenu {
busy: notes.busy busy: notes.busy
MenuLabel {
visible: typeof(appSettings.accounts[appSettings.currentAccount]) !== 'undefined'
text: visible ? qsTr("Last update") + ": " + new Date(appSettings.accounts[appSettings.currentAccount].lastUpdate).toLocaleString(Qt.locale(), Locale.ShortFormat) : ""
}
MenuItem {
text: qsTr("Reload")
visible: typeof(appSettings.accounts[appSettings.currentAccount]) !== 'undefined'
onClicked: notes.getNotes()
}
MenuItem { MenuItem {
text: qsTr("Settings") text: qsTr("Settings")
onClicked: { onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
var login = pageStack.push(Qt.resolvedUrl("LoginDialog.qml"), { server: appSettings.server, username: appSettings.username, password: appSettings.password } )
login.accepted.connect(function() {
console.log(login.username + ":" + login.password + "@" + login.server)
appSettings.server = login.server
appSettings.username = login.username
appSettings.password = login.password
notes.getNotes()
})
}
} }
MenuItem { MenuItem {
text: qsTr("Add note") text: qsTr("Add note")
enabled: typeof(appSettings.accounts[appSettings.currentAccount]) !== 'undefined'
onClicked: console.log("Add note") onClicked: console.log("Add note")
} }
MenuItem {
text: qsTr("Update")
onClicked: notes.getNotes()
}
MenuLabel {
text: qsTr("Last update") + ": " + new Date(appSettings.lastUpdate).toLocaleString(Qt.locale(), Locale.ShortFormat)
}
} }
header: SearchField { header: SearchField {
@ -49,9 +44,10 @@ Page {
currentIndex: -1 currentIndex: -1
Component.onCompleted: { Component.onCompleted: {
if (appSettings.server.toString().length > 0 && appSettings.username.length > 0 && appSettings.password.length > 0) if (appSettings.accounts.length > 0) {
notes.getNotes() notes.getNotes()
} }
}
//Component.onCompleted: notes.getNotes() //Component.onCompleted: notes.getNotes()
//Component.onCompleted: notes.getNote("1212725") //Component.onCompleted: notes.getNote("1212725")
@ -141,19 +137,33 @@ Page {
running: visible running: visible
} }
ViewPlaceholder {
id: noLoginPlaceholder
enabled: (appSettings.accounts.length === 0)
text: qsTr("No accounts yet")
}
ViewPlaceholder { ViewPlaceholder {
enabled: notesList.count === 0 && !notes.busy && !noLoginPlaceholder.enabled enabled: notesList.count === 0 && !notes.busy && !noLoginPlaceholder.enabled
text: qsTr("No notes yet") text: qsTr("No notes yet")
hintText: qsTr("Pull down to add a note") hintText: qsTr("Pull down to add a note")
} }
ViewPlaceholder {
id: noLoginPlaceholder
enabled: (appSettings.server.length === 0 || appSettings.username.length === 0 || appSettings.password.length === 0)
text: qsTr("No Nextcloud account")
hintText: qsTr("Pull down to go to the settings")
}
VerticalScrollDecorator { flickable: notesList } VerticalScrollDecorator { flickable: notesList }
} }
TouchInteractionHint {
id: addAccountHint
Component.onCompleted: if (appSettings.accounts.length === 0) restart()
interactionMode: TouchInteraction.Pull
direction: TouchInteraction.Down
}
InteractionHintLabel {
anchors.fill: parent
text: qsTr("Open the settings to add a new Nextcloud account")
opacity: addAccountHint.running ? 1.0 : 0.0
Behavior on opacity { FadeAnimation {} }
width: parent.width
}
} }

View file

@ -0,0 +1,67 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
id: page
SilicaFlickable {
id: flickable
anchors.fill: parent
contentHeight: column.height
Column {
id: column
width: parent.width
spacing: Theme.paddingMedium
PageHeader {
title: qsTr("Settings")
}
SectionHeader {
text: qsTr("Accounts")
}
Label {
id: noAccountsLabel
visible: typeof(appSettings.accounts) !== 'undefined'
text: qsTr("No Nextcloud account yet")
font.pixelSize: Theme.fontSizeExtraLarge
color: Theme.secondaryHighlightColor
anchors.horizontalCenter: parent.horizontalCenter
}
Repeater {
model: appSettings.accounts
delegate: BackgroundItem {
Label {
text: appSettings.accounts[index].username + "@" + appSettings.accounts[index].server
x: Theme.horizontalPageMargin
width: parent.width - 2*x
}
onClicked: {
var login = pageStack.push(Qt.resolvedUrl("LoginDialog.qml"), { account: appSettings.accounts[index] } )
login.accepted.connect(function() {
console.log(login.account.username + ":" + login.account.password + "@" + login.account.server.toString())
appSettings.accounts[index] = login.account
})
}
}
}
Button {
text: qsTr("Add account")
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
var login = pageStack.push(Qt.resolvedUrl("LoginDialog.qml"))
login.accepted.connect(function() {
console.log(login.account.username + ":" + login.account.password + "@" + login.account.server.toString())
appSettings.currentAccount = appSettings.accounts.length
appSettings.accounts[appSettings.currentAccount] = login.account
notes.getNotes()
})
}
}
}
VerticalScrollDecorator {}
}
}

View file

@ -69,22 +69,34 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Update</source> <source>Reload</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>No Nextcloud account</source> <source>No accounts yet</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Pull down to go to the settings</source> <source>Open the settings to add a new Nextcloud account</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context> <context>
<name>harbour-nextcloudnotes</name> <name>SettingsPage</name>
<message> <message>
<source>never</source> <source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Accounts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Add account</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No Nextcloud account yet</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>