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 {
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
width: parent.width - favoriteButton.width
text: note.category
placeholderText: qsTr("Category")
label: placeholderText
placeholderText: qsTr("No category")
label: qsTr("Category")
}
}
}

View file

@ -13,30 +13,27 @@ Dialog {
{ noHeaderId: true,
simplifiedAutoLink: 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,
emoji: true } )
function reloadContent() {
var tmpNote = account.getNote(note.id)
if (tmpNote) {
note = tmpNote
}
modifiedDetail.value = new Date(note.modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
favoriteDetail.value = note.favorite ? qsTr("yes") : qsTr("no")
categoryDetail.value = note.category
function parseContent() {
note = account.getNote(note.id, false)
//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
convertedText = convertedText.replace(/^<li>\[ \]\s(.*)<\/li>$/gm,
convertedText = convertedText.replace(/^<li>\[ \] (.*)<\/li>$/gm,
function(match, p1, offset) {
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
convertedText = convertedText.replace(/^<li>\[[xX]\]\s(.*)<\/li>$/gm,
convertedText = convertedText.replace(/^<li>\[[xX]\] (.*)<\/li>$/gm,
function(match, p1, offset) {
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
//console.log(contentLabel.text)
@ -44,18 +41,16 @@ Dialog {
acceptDestination: Qt.resolvedUrl("EditPage.qml")
acceptDestinationProperties: { account: account; note: note }
Component.onCompleted: acceptDestinationProperties = { account: account, note: note }
onStatusChanged: {
if (status === PageStatus.Active) {
//account.getNote(note.id)
reloadContent()
}
Component.onCompleted: {
parseContent()
acceptDestinationProperties = { account: account, note: note }
}
Connections {
target: account
onBusyChanged: {
if (account.busy === false) {
reloadContent()
note = account.getNote(note.id, false)
parseContent()
}
}
}
@ -118,30 +113,28 @@ Dialog {
var occurence = -1
var newContent = note.content
if (/^tasklist:checkbox_(\d+)$/m.test(link)) {
newContent = newContent.replace(/^- \[ \]\s(.*)$/gm,
newContent = newContent.replace(/^- \[ \] (.*)$/gm,
function(match, p1, offset, string) {
occurence++
if (occurence === parseInt(link.split('_')[1])) {
return '- [x] ' + p1
}
else {
return match
}
return '- [x] ' + p1 }
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)) {
newContent = newContent.replace(/^- \[x\]\s(.*)$/gm,
newContent = newContent.replace(/^- \[[xX]\] (.*)$/gm,
function(match, p1, offset, string) {
occurence++
if (occurence === parseInt(link.split('_')[1])) {
return '- [ ] ' + p1
}
else {
return match
}
return '- [ ] ' + p1 }
else { return match }
} )
account.updateNote(note.id, { 'content': newContent } )
note.content = newContent
parseContent()
account.updateNote(note.id, { 'content': note.content } )
}
else {
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 {
id: separator
width: parent.width
@ -156,14 +155,37 @@ Dialog {
horizontalAlignment: Qt.AlignHCenter
}
Column {
width: parent.width
DetailItem {
id: modifiedDetail
label: qsTr("Modified")
Row {
x: Theme.horizontalPageMargin
width: parent.width - x
IconButton {
id: favoriteButton
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
label: qsTr("Favorite")
}
@ -171,8 +193,7 @@ Dialog {
id: categoryDetail
label: qsTr("Category")
visible: value.length > 0
}
}
}*/
}
}

View file

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

View file

@ -59,23 +59,19 @@ Page {
}
header: PageHeader {
title: nextcloudAccounts.itemAt(appSettings.currentAccount).name //qsTr("Nextclound Notes")
description: nextcloudAccounts.itemAt(appSettings.currentAccount).username + "@" + nextcloudAccounts.itemAt(appSettings.currentAccount).server
//title: nextcloudAccounts.itemAt(appSettings.currentAccount).name //qsTr("Nextclound Notes")
description: searchField.text === "" ? nextcloudAccounts.itemAt(appSettings.currentAccount).username + "@" + nextcloudAccounts.itemAt(appSettings.currentAccount).server :
searchField.placeholderText
BusyIndicator {
x: Theme.horizontalPageMargin
anchors.verticalCenter: parent.verticalCenter
running: nextcloudAccounts.itemAt(appSettings.currentAccount) ? nextcloudAccounts.itemAt(appSettings.currentAccount).busy && !busyIndicator.running : false
}
/*SearchField {
SearchField {
id: searchField
width: parent.width
placeholderText: qsTr("Nextcloud Notes")
onTextChanged: notes.search(text.toLowerCase())
//enabled: notesList.count > 0
placeholderText: nextcloudAccounts.itemAt(appSettings.currentAccount).name
EnterKey.iconSource: "image://theme/icon-m-enter-close"
EnterKey.onClicked: focus = false
enabled: notesList.count > 0*/
onTextChanged: nextcloudAccounts.itemAt(appSettings.currentAccount).search(text.toLowerCase())
}
}
currentIndex: -1
@ -92,12 +88,12 @@ Page {
height: contentHeight + menu.height
width: parent.width
highlighted: down || menu.active
ListView.onAdd: AddAnimation {
/*ListView.onAdd: AddAnimation {
target: note
}
ListView.onRemove: RemoveAnimation {
target: note
}
}*/
RemorseItem {
id: remorse
}
@ -116,7 +112,6 @@ Page {
icon.source: (favorite ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
(note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
onClicked: {
console.log("Toggle favorite")
nextcloudAccounts.itemAt(appSettings.currentAccount).updateNote(id, {'favorite': !favorite} )
}
}
@ -227,9 +222,16 @@ Page {
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 {
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")
hintText: nextcloudAccounts.itemAt(appSettings.currentAccount).statusText
}

View file

@ -12,6 +12,12 @@
# * date Author's Name <author's email> version-release
# - 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
- Implemented checkboxes
- Link to external website containing the markdown syntax

View file

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

View file

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

View file

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