harbour-nextcloudnotes/qml/pages/NotePage.qml

182 lines
7.6 KiB
QML
Raw Normal View History

import "../js/showdown-1.9.0/dist/showdown.js" as ShowDown
2018-10-16 18:50:58 +03:00
import QtQuick 2.0
import Sailfish.Silica 1.0
2018-11-18 13:25:28 +03:00
Dialog {
id: noteDialog
property var account
property var note
property var showdown: ShowDown.showdown
2018-11-30 17:12:16 +03:00
property var converter: new showdown.Converter(
{ noHeaderId: true,
simplifiedAutoLink: true,
tables: true,
tasklists: false, // this is handled by the function reloadContent() because LinkedLabel HTML support is to basic
simpleLineBreaks: true,
emoji: true } )
2018-11-18 13:25:28 +03:00
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
var convertedText = converter.makeHtml(note.content)
2018-11-28 16:05:36 +03:00
var occurence = -1
convertedText = convertedText.replace(/^<li>\[ \]\s(.*)<\/li>$/gm,
function(match, p1, offset) {
occurence++
return '<li><a href="tasklist:checkbox_' + occurence + '">☐ ' + p1 + '</a></li>'
} )
occurence = -1
convertedText = convertedText.replace(/^<li>\[[xX]\]\s(.*)<\/li>$/gm,
2018-11-28 16:05:36 +03:00
function(match, p1, offset) {
occurence++
return '<li><a href="tasklist:uncheckbox_' + occurence + '">☑ ' + p1 + '</a></li>'
} )
contentLabel.text = convertedText
//console.log(contentLabel.text)
}
2018-11-18 13:25:28 +03:00
acceptDestination: Qt.resolvedUrl("EditPage.qml")
acceptDestinationProperties: { account: account; note: note }
Component.onCompleted: acceptDestinationProperties = { account: account, note: note }
2018-11-18 17:01:32 +03:00
onStatusChanged: {
if (status === PageStatus.Active) {
//account.getNote(note.id)
reloadContent()
2018-11-18 17:01:32 +03:00
}
}
Connections {
2018-11-30 17:12:16 +03:00
target: account
onBusyChanged: {
if (account.busy === false) {
reloadContent()
}
2018-11-18 17:01:32 +03:00
}
}
2018-11-18 13:25:28 +03:00
2018-10-16 18:50:58 +03:00
SilicaFlickable {
anchors.fill: parent
2018-11-26 19:21:33 +03:00
contentHeight: mainColumn.height
2018-10-16 18:50:58 +03:00
Column {
2018-11-26 19:21:33 +03:00
id: mainColumn
2018-10-21 02:44:23 +03:00
width: parent.width
2018-11-26 19:21:33 +03:00
RemorsePopup {
id: remorse
onTriggered: pageStack.pop()
}
PullDownMenu {
busy: account ? account.busy : false
MenuItem {
text: qsTr("Delete")
enabled: account ? true : false
//visible: appSettings.currentAccount >= 0
onClicked: remorse.execute("Deleting", function() { account.deleteNote(notey.id) } )
}
MenuItem {
text: enabled ? qsTr("Reload") : qsTr("Updating...")
enabled: account ? !account.busy : false
//visible: appSettings.currentAccount >= 0
onClicked: account.getNote(note.id)
}
MenuLabel {
visible: appSettings.currentAccount >= 0
text: account ? (
qsTr("Last update") + ": " + (
new Date(account.update).valueOf() !== 0 ?
new Date(account.update).toLocaleString(Qt.locale(), Locale.ShortFormat) :
qsTr("never"))) : ""
}
}
2018-10-16 18:50:58 +03:00
2018-11-18 13:25:28 +03:00
DialogHeader {
2018-11-18 17:01:32 +03:00
id: dialogHeader
2018-11-28 16:05:36 +03:00
dialog: noteDialog
2018-11-18 13:25:28 +03:00
acceptText: qsTr("Edit")
cancelText: qsTr("Notes")
2018-10-16 18:50:58 +03:00
}
2018-11-26 19:21:33 +03:00
Column {
width: parent.width
spacing: Theme.paddingLarge
LinkedLabel {
id: contentLabel
x: Theme.horizontalPageMargin
width: parent.width - 2*x
textFormat: Text.StyledText
2018-11-28 16:05:36 +03:00
defaultLinkActions: false
onLinkActivated: {
var occurence = -1
var newContent = note.content
2018-11-28 16:05:36 +03:00
if (/^tasklist:checkbox_(\d+)$/m.test(link)) {
newContent = newContent.replace(/^- \[ \]\s(.*)$/gm,
function(match, p1, offset, string) {
occurence++
if (occurence === parseInt(link.split('_')[1])) {
return '- [x] ' + p1
}
else {
return match
}
} )
account.updateNote(note.id, { 'content': newContent } )
2018-11-28 16:05:36 +03:00
}
else if (/^tasklist:uncheckbox_(\d+)$/m.test(link)) {
newContent = newContent.replace(/^- \[x\]\s(.*)$/gm,
function(match, p1, offset, string) {
occurence++
if (occurence === parseInt(link.split('_')[1])) {
return '- [ ] ' + p1
}
else {
return match
}
} )
account.updateNote(note.id, { 'content': newContent } )
2018-11-28 16:05:36 +03:00
}
else {
Qt.openUrlExternally(link)
}
}
2018-11-26 19:21:33 +03:00
}
Separator {
id: separator
width: parent.width
color: Theme.primaryColor
horizontalAlignment: Qt.AlignHCenter
}
Column {
width: parent.width
DetailItem {
2018-11-30 17:12:16 +03:00
id: modifiedDetail
2018-11-26 19:21:33 +03:00
label: qsTr("Modified")
}
DetailItem {
2018-11-30 17:12:16 +03:00
id: favoriteDetail
2018-11-26 19:21:33 +03:00
label: qsTr("Favorite")
}
DetailItem {
2018-11-30 17:12:16 +03:00
id: categoryDetail
2018-11-26 19:21:33 +03:00
label: qsTr("Category")
visible: value.length > 0
2018-10-21 02:44:23 +03:00
}
}
2018-10-16 18:50:58 +03:00
}
}
2018-10-21 02:44:23 +03:00
2018-10-16 18:50:58 +03:00
VerticalScrollDecorator {}
}
}