Implemented searching, larger checkboxes, better asynchronious behaviour, small bugfixes

This commit is contained in:
Scharel Clemens 2018-12-03 20:33:37 +01:00
parent 3c1223f9a9
commit ad71500c20
8 changed files with 167 additions and 125 deletions

View file

@ -28,7 +28,7 @@ Dialog {
} }
MenuItem { MenuItem {
text: qsTr("Markdown syntax") text: qsTr("Markdown syntax")
onClicked: Qt.openUrlExternally("https://github.com/showdownjs/showdown/wiki/Showdown's-Markdown-syntax")//pageStack.push(Qt.resolvedUrl("MarkdownPage.qml")) onClicked: Qt.openUrlExternally("https://github.com/showdownjs/showdown/wiki/Showdown's-Markdown-syntax")
} }
} }
@ -69,10 +69,9 @@ Dialog {
id: categoryField id: categoryField
width: parent.width - favoriteButton.width width: parent.width - favoriteButton.width
text: note.category text: note.category
placeholderText: qsTr("Category") placeholderText: qsTr("No category")
label: placeholderText label: qsTr("Category")
} }
} }
} }

View file

@ -13,30 +13,27 @@ Dialog {
{ noHeaderId: true, { noHeaderId: true,
simplifiedAutoLink: true, simplifiedAutoLink: true,
tables: true, tables: true,
tasklists: false, // this is handled by the function reloadContent() because LinkedLabel HTML support is to basic tasklists: false, // this is handled by the function parseContent() because LinkedLabel HTML support is to basic
simpleLineBreaks: true, simpleLineBreaks: true,
emoji: true } ) emoji: true } )
function reloadContent() { function parseContent() {
var tmpNote = account.getNote(note.id) note = account.getNote(note.id, false)
if (tmpNote) { //modifiedDetail.value = new Date(note.modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
note = tmpNote //favoriteDetail.value = note.favorite ? qsTr("yes") : qsTr("no")
} //categoryDetail.value = note.category
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 convertedText = converter.makeHtml(note.content)
var occurence = -1 var occurence = -1
convertedText = convertedText.replace(/^<li>\[ \]\s(.*)<\/li>$/gm, convertedText = convertedText.replace(/^<li>\[ \] (.*)<\/li>$/gm,
function(match, p1, offset) { function(match, p1, offset) {
occurence++ occurence++
return '<li><a href="tasklist:checkbox_' + occurence + '">☐ ' + p1 + '</a></li>' return '<li><font size="' + 4 + '"><a href="tasklist:checkbox_' + occurence + '">☐ ' + p1 + '</a></font></li>'
} ) } )
occurence = -1 occurence = -1
convertedText = convertedText.replace(/^<li>\[[xX]\]\s(.*)<\/li>$/gm, convertedText = convertedText.replace(/^<li>\[[xX]\] (.*)<\/li>$/gm,
function(match, p1, offset) { function(match, p1, offset) {
occurence++ occurence++
return '<li><a href="tasklist:uncheckbox_' + occurence + '">☑ ' + p1 + '</a></li>' return '<li><font size="' + 4 + '"><a href="tasklist:uncheckbox_' + occurence + '">☑ ' + p1 + '</a></font></li>'
} ) } )
contentLabel.text = convertedText contentLabel.text = convertedText
//console.log(contentLabel.text) //console.log(contentLabel.text)
@ -44,18 +41,16 @@ Dialog {
acceptDestination: Qt.resolvedUrl("EditPage.qml") acceptDestination: Qt.resolvedUrl("EditPage.qml")
acceptDestinationProperties: { account: account; note: note } acceptDestinationProperties: { account: account; note: note }
Component.onCompleted: acceptDestinationProperties = { account: account, note: note } Component.onCompleted: {
onStatusChanged: { parseContent()
if (status === PageStatus.Active) { acceptDestinationProperties = { account: account, note: note }
//account.getNote(note.id)
reloadContent()
}
} }
Connections { Connections {
target: account target: account
onBusyChanged: { onBusyChanged: {
if (account.busy === false) { if (account.busy === false) {
reloadContent() note = account.getNote(note.id, false)
parseContent()
} }
} }
} }
@ -118,30 +113,28 @@ Dialog {
var occurence = -1 var occurence = -1
var newContent = note.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(/^- \[ \] (.*)$/gm,
function(match, p1, offset, string) { function(match, p1, offset, string) {
occurence++ occurence++
if (occurence === parseInt(link.split('_')[1])) { if (occurence === parseInt(link.split('_')[1])) {
return '- [x] ' + p1 return '- [x] ' + p1 }
} else { return match }
else {
return match
}
} ) } )
account.updateNote(note.id, { 'content': newContent } ) note.content = newContent
parseContent()
account.updateNote(note.id, { 'content': note.content } )
} }
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(/^- \[[xX]\] (.*)$/gm,
function(match, p1, offset, string) { function(match, p1, offset, string) {
occurence++ occurence++
if (occurence === parseInt(link.split('_')[1])) { if (occurence === parseInt(link.split('_')[1])) {
return '- [ ] ' + p1 return '- [ ] ' + p1 }
} else { return match }
else {
return match
}
} ) } )
account.updateNote(note.id, { 'content': newContent } ) note.content = newContent
parseContent()
account.updateNote(note.id, { 'content': note.content } )
} }
else { else {
Qt.openUrlExternally(link) Qt.openUrlExternally(link)
@ -149,6 +142,12 @@ Dialog {
} }
} }
DetailItem {
id: modifiedDetail
label: qsTr("Modified")
value: new Date(note.modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
}
Separator { Separator {
id: separator id: separator
width: parent.width width: parent.width
@ -156,14 +155,37 @@ Dialog {
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
} }
Column { Row {
width: parent.width x: Theme.horizontalPageMargin
width: parent.width - x
DetailItem { IconButton {
id: modifiedDetail id: favoriteButton
label: qsTr("Modified") property bool selected: note.favorite
width: Theme.iconSizeMedium
icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
(favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
onClicked: {
account.updateNote(note.id, {'favorite': !note.favorite})
} }
DetailItem { }
TextField {
id: categoryField
width: parent.width - favoriteButton.width
text: note.category
placeholderText: qsTr("No category")
label: qsTr("Category")
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
EnterKey.onClicked: {
categoryField.focus = false
}
onFocusChanged: {
if (focus === false) {
account.updateNote(note.id, {'content': note.content, 'category': text}) // This does not seem to work without adding the content
}
}
}
}
/*DetailItem {
id: favoriteDetail id: favoriteDetail
label: qsTr("Favorite") label: qsTr("Favorite")
} }
@ -171,8 +193,7 @@ Dialog {
id: categoryDetail id: categoryDetail
label: qsTr("Category") label: qsTr("Category")
visible: value.length > 0 visible: value.length > 0
} }*/
}
} }
} }

View file

@ -14,11 +14,12 @@ 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: [ ]
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 bool searchActive: false
property int status: 204 property int status: 204
property string statusText: "No Content" property string statusText: "No Content"
@ -28,7 +29,7 @@ Item {
Connections { Connections {
target: appSettings target: appSettings
onSortByChanged: mapDataToModel() onSortByChanged: _mapDataToModel()
} }
ConfigurationGroup { ConfigurationGroup {
@ -61,7 +62,7 @@ Item {
account.clear() account.clear()
} }
function callApi(method, data) { function _APIcall(method, data) {
busy = true busy = true
var endpoint = url var endpoint = url
@ -87,21 +88,21 @@ Item {
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 modelData = json
mapDataToModel() _mapDataToModel()
update = new Date() update = new Date()
} }
else { else {
console.log("Received a single note via API: " + endpoint) console.log("Received a single note via API: " + endpoint)
addToModelData(json) _addToModelData(json)
} }
break; break;
case "POST": case "POST":
console.log("Created a note via API: " + endpoint) console.log("Created a note via API: " + endpoint)
addToModelData(json) _addToModelData(json)
break; break;
case "PUT": case "PUT":
console.log("Updated a note via API: " + endpoint) console.log("Updated a note via API: " + endpoint)
addToModelData(json) _addToModelData(json)
break; break;
case "DELETE": case "DELETE":
console.log("Deleted a note via API: " + endpoint) console.log("Deleted a note via API: " + endpoint)
@ -141,36 +142,47 @@ Item {
} }
} }
function getNotes() { function getNotes(refresh) {
callApi("GET") if (typeof(refresh) === 'undefined')
refresh = true
if (refresh)
_APIcall("GET")
return modelData
} }
function getNote(id) { function getNote(id, refresh) {
if (id) if (typeof(refresh) === 'undefined')
callApi("GET", { 'id': id } ) refresh = true
if (id) {
if (refresh)
_APIcall("GET", { 'id': id } )
var note
modelData.forEach(function(currentValue) { modelData.forEach(function(currentValue) {
if (currentValue.id === id) if (currentValue.id === id)
return currentValue note = currentValue
} ) } )
return note
}
} }
function createNote(data) { function createNote(data) {
callApi("POST", data) if (data)
_APIcall("POST", data)
} }
function updateNote(id, data) { function updateNote(id, data) {
if (id) { if (id && data) {
data.id = id data.id = id
callApi("PUT", data) _APIcall("PUT", data)
} }
} }
function deleteNote(id) { function deleteNote(id) {
if (id) if (id)
callApi("DELETE", { 'id': id } ) _APIcall("DELETE", { 'id': id } )
} }
function addToModelData(data) { function _addToModelData(data) {
var dataUpdated = false var dataUpdated = false
modelData.forEach(function(currentValue, index, array) { modelData.forEach(function(currentValue, index, array) {
if (currentValue.id === data.id) { if (currentValue.id === data.id) {
@ -181,19 +193,19 @@ Item {
if (!dataUpdated) { if (!dataUpdated) {
modelData.push(data) modelData.push(data)
} }
mapDataToModel() _mapDataToModel()
} }
function removeFromModelData(id) { function _removeFromModelData(id) {
modelData.forEach(function(currentValue, index, array) { modelData.forEach(function(currentValue, index, array) {
if (currentValue.id === id) { if (currentValue.id === id) {
modelData.splice(i, 1) modelData.splice(i, 1)
} }
} ) } )
mapDataToModel() _mapDataToModel()
} }
function mapDataToModel() { function _mapDataToModel() {
modelData.forEach(function(value) { value.date = getPrettyDate(value.modified) } ) modelData.forEach(function(value) { value.date = getPrettyDate(value.modified) } )
switch(appSettings.sortBy) { switch(appSettings.sortBy) {
case "date": case "date":
@ -208,6 +220,7 @@ Item {
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
} }
if (!searchActive) {
for (var element in modelData) { for (var element in modelData) {
model.set(element, modelData[element]) model.set(element, modelData[element])
} }
@ -216,24 +229,21 @@ Item {
model.remove(element) model.remove(element)
} }
} }
function refresh() {
search("")
} }
function search(query) { function search(query) {
if (query !== "") {
searchActive = true
model.clear() model.clear()
var elements = parseJson() for (var element in modelData) {
for (var element in elements) { if (modelData[element].title.toLowerCase().indexOf(query) >= 0 | modelData[element].content.toLowerCase().indexOf(query) >= 0) {
elements[element].section = "" model.append(modelData[element])
var match = false
for (var child in elements[element]) {
if (elements[element][child]) {
match = (elements[element][child].toString().toLowerCase().indexOf(query) >= 0) || match
} }
} }
if (query === "" || match) }
model.append(elements[element]) else {
searchActive = false
_mapDataToModel()
} }
} }

View file

@ -59,23 +59,19 @@ 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: searchField.text === "" ? nextcloudAccounts.itemAt(appSettings.currentAccount).username + "@" + nextcloudAccounts.itemAt(appSettings.currentAccount).server :
searchField.placeholderText
BusyIndicator { SearchField {
x: Theme.horizontalPageMargin id: searchField
anchors.verticalCenter: parent.verticalCenter
running: nextcloudAccounts.itemAt(appSettings.currentAccount) ? nextcloudAccounts.itemAt(appSettings.currentAccount).busy && !busyIndicator.running : false
}
/*SearchField {
width: parent.width width: parent.width
placeholderText: qsTr("Nextcloud Notes") //enabled: notesList.count > 0
onTextChanged: notes.search(text.toLowerCase()) placeholderText: nextcloudAccounts.itemAt(appSettings.currentAccount).name
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*/ onTextChanged: nextcloudAccounts.itemAt(appSettings.currentAccount).search(text.toLowerCase())
}
} }
currentIndex: -1 currentIndex: -1
@ -92,12 +88,12 @@ Page {
height: contentHeight + menu.height height: contentHeight + menu.height
width: parent.width width: parent.width
highlighted: down || menu.active highlighted: down || menu.active
ListView.onAdd: AddAnimation { /*ListView.onAdd: AddAnimation {
target: note target: note
} }
ListView.onRemove: RemoveAnimation { ListView.onRemove: RemoveAnimation {
target: note target: note
} }*/
RemorseItem { RemorseItem {
id: remorse id: remorse
} }
@ -116,7 +112,6 @@ Page {
icon.source: (favorite ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") + icon.source: (favorite ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
(note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor) (note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
onClicked: { onClicked: {
console.log("Toggle favorite")
nextcloudAccounts.itemAt(appSettings.currentAccount).updateNote(id, {'favorite': !favorite} ) nextcloudAccounts.itemAt(appSettings.currentAccount).updateNote(id, {'favorite': !favorite} )
} }
} }
@ -227,9 +222,16 @@ Page {
hintText: qsTr("Pull down to add a note") hintText: qsTr("Pull down to add a note")
} }
ViewPlaceholder {
id: noSearchPlaceholder
enabled: nextcloudAccounts.itemAt(appSettings.currentAccount) ? (notesList.count === 0 && nextcloudAccounts.itemAt(appSettings.currentAccount).modelData.length > 0) : false
text: qsTr("No result")
hintText: qsTr("Try another query")
}
ViewPlaceholder { ViewPlaceholder {
id: errorPlaceholder id: errorPlaceholder
enabled: notesList.count === 0 && !busyIndicator.running && !noNotesPlaceholder.enabled && !noLoginPlaceholder.enabled enabled: notesList.count === 0 && !busyIndicator.running && !noSearchPlaceholder.enabled && !noNotesPlaceholder.enabled && !noLoginPlaceholder.enabled
text: qsTr("An error occurred") text: qsTr("An error occurred")
hintText: nextcloudAccounts.itemAt(appSettings.currentAccount).statusText hintText: nextcloudAccounts.itemAt(appSettings.currentAccount).statusText
} }

View file

@ -12,6 +12,12 @@
# * date Author's Name <author's email> version-release # * date Author's Name <author's email> version-release
# - Summary of changes # - Summary of changes
* Mon Dec 03 2018 Scharel Clemens <harbour-nextcloudnotes@scharel.name> 0.1-4
- Implemented searching
- Larger checkboxes
- Better asynchronious behaviour
- Small bugfixes
* Wed Nov 28 2018 Scharel Clemens <harbour-nextcloudnotes@scharel.name> 0.1-3 * Wed Nov 28 2018 Scharel Clemens <harbour-nextcloudnotes@scharel.name> 0.1-3
- Implemented checkboxes - Implemented checkboxes
- Link to external website containing the markdown syntax - Link to external website containing the markdown syntax

View file

@ -14,7 +14,7 @@ Name: harbour-nextcloudnotes
%{?qtc_builddir:%define _builddir %qtc_builddir} %{?qtc_builddir:%define _builddir %qtc_builddir}
Summary: Nextcloud Notes Summary: Nextcloud Notes
Version: 0.1 Version: 0.1
Release: 3 Release: 4
Group: Qt/Qt Group: Qt/Qt
License: LICENSE License: LICENSE
URL: http://example.org/ URL: http://example.org/

View file

@ -1,7 +1,7 @@
Name: harbour-nextcloudnotes Name: harbour-nextcloudnotes
Summary: Nextcloud Notes Summary: Nextcloud Notes
Version: 0.1 Version: 0.1
Release: 3 Release: 4
# The contents of the Group field should be one of the groups listed here: # The contents of the Group field should be one of the groups listed here:
# https://github.com/mer-tools/spectacle/blob/master/data/GROUPS # https://github.com/mer-tools/spectacle/blob/master/data/GROUPS
Group: Qt/Qt Group: Qt/Qt

View file

@ -57,6 +57,10 @@
<source>Markdown syntax</source> <source>Markdown syntax</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>No category</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>GPLLicense</name> <name>GPLLicense</name>
@ -145,22 +149,14 @@
<source>Modified</source> <source>Modified</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Favorite</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>yes</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>no</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Category</source> <source>Category</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>No category</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>NotesApi</name> <name>NotesApi</name>
@ -235,6 +231,14 @@
<source>Updating...</source> <source>Updating...</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>No result</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Try another query</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>