Still no big changes

This commit is contained in:
Scharel Clemens 2019-06-20 20:25:32 +02:00
commit 3b1e1cca8c
5 changed files with 79 additions and 91 deletions

View file

@ -6,8 +6,16 @@ import "../js/showdown/dist/showdown.js" as ShowDown
Dialog {
id: noteDialog
property var note
property int noteID
property int id
property int modified
property string title
property string category
property string content
property bool favorite
property string etag
property bool error
property string errorMessage
property string date
property var showdown: ShowDown.showdown
property var converter: new showdown.Converter(
@ -30,27 +38,26 @@ Dialog {
}
onStatusChanged: {
if (status === DialogStatus.Opened) {
api.getNoteFromApi(noteID)
api.getNoteFromApi(id)
}
}
Component.onCompleted: {
noteID = note.id
parseContent()
}
function reloadContent() {
api.getNoteFromApi(note.id)
/*note = api.getNote(note.id)
dialogHeader.title = note.title
favoriteButton.selected = note.favorite
categoryField.text = note.category
modifiedDetail.modified = note.modified
api.getNoteFromApi(id)
/*note = api.getNote(id)
dialogHeader.title = title
favoriteButton.selected = favorite
categoryField.text = category
modifiedDetail.modified = modified
parseContent()*/
}
function parseContent() {
//note = api.getNoteFromApi(note.id, false)
var convertedText = converter.makeHtml(note.content)
//note = api.getNoteFromApi(id, false)
var convertedText = converter.makeHtml(content)
var occurence = -1
convertedText = convertedText.replace(/^<li>(<p>)?\[ \] (.*)(<.*)$/gmi,
function(match, p1, p2, p3, offset) {
@ -93,7 +100,7 @@ Dialog {
MenuItem {
text: qsTr("Delete")
onClicked: remorse.execute("Deleting", function() { api.deleteNote(note.id) } )
onClicked: remorse.execute("Deleting", function() { api.deleteNote(id) } )
}
MenuItem {
text: enabled ? qsTr("Reload") : qsTr("Updating...")
@ -111,7 +118,7 @@ Dialog {
DialogHeader {
id: dialogHeader
title: note.title
title: title
acceptText: qsTr("Edit")
cancelText: qsTr("Notes")
}
@ -143,7 +150,7 @@ Dialog {
onLinkActivated: {
//console.log(link)
var occurence = -1
var newContent = note.content
var newContent = content
if (/^tasklist:checkbox_(\d+)$/m.test(link)) {
newContent = newContent.replace(/- \[ \] (.*)$/gm,
function(match, p1, offset, string) {
@ -152,9 +159,9 @@ Dialog {
return (appSettings.useCapitalX ? '- [X] ' : '- [x] ') + p1 }
else { return match }
} )
note.content = newContent
content = newContent
parseContent()
api.updateNote(note.id, { 'content': note.content } )
api.updateNote(id, { 'content': content } )
}
else if (/^tasklist:uncheckbox_(\d+)$/m.test(link)) {
newContent = newContent.replace(/- \[[xX]\] (.*)$/gm,
@ -164,9 +171,9 @@ Dialog {
return '- [ ] ' + p1 }
else { return match }
} )
note.content = newContent
content = newContent
parseContent()
api.updateNote(note.id, { 'content': note.content } )
api.updateNote(id, { 'content': content } )
}
else {
Qt.openUrlExternally(link)
@ -221,18 +228,18 @@ Dialog {
width: parent.width - x
IconButton {
id: favoriteButton
property bool selected: note.favorite
property bool selected: 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: {
api.updateNote(note.id, {'favorite': !note.favorite})
api.updateNote(id, {'favorite': !favorite})
}
}
TextField {
id: categoryField
width: parent.width - favoriteButton.width
text: note.category
text: category
placeholderText: qsTr("No category")
label: qsTr("Category")
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
@ -240,8 +247,8 @@ Dialog {
categoryField.focus = false
}
onFocusChanged: {
if (focus === false && text !== note.category) {
api.updateNote(note.id, {'content': note.content, 'category': text}) // This does not seem to work without adding the content
if (focus === false && text !== category) {
api.updateNote(id, {'content': content, 'category': text}) // This does not seem to work without adding the content
}
}
}
@ -250,7 +257,7 @@ Dialog {
DetailItem {
id: modifiedDetail
label: qsTr("Modified")
property int modified: note.modified
property int modified: modified
value: new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
}
}

View file

@ -103,7 +103,17 @@ Page {
}
onClicked: pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"),
{ note: notesList.model.get(index) })
{ id: id,
modified: modified,
title: title,
category: category,
content: content,
favorite: favorite,
etag: etag,
error: error,
errorMessage: errorMessage,
date: date
})
onPressAndHold: menu.open(note)
Separator {

View file

@ -57,9 +57,8 @@ void NotesModel::clearSearch() {
search();
}
bool NotesModel::applyJSON(QString json) {
bool NotesModel::applyJSON(const QString &json) {
qDebug() << "Applying new JSON input";// << json;
uint notesModified = 0;
QJsonParseError error;
QJsonDocument jdoc = QJsonDocument::fromJson(json.toUtf8(), &error);
if (!jdoc.isNull() && error.error == QJsonParseError::NoError) {
@ -76,13 +75,13 @@ bool NotesModel::applyJSON(QString json) {
//qDebug() << "Adding it to the model...";
Note note = Note::fromjson(jobj); // TODO connect signals
if (!note.error()) {
int oldPosition = indexOf(note.id());
Note oldNote = get(oldPosition);
if (oldPosition >= 0 && note.etag() != oldNote.etag()) {
int position = indexOf(note.id());
Note oldNote = get(position);
if (position >= 0 && note.etag() != oldNote.etag()) {
qDebug() << "-- Existing note " << note.title() << "changed, updating the model...";
replaceNote(note);
}
else if (oldPosition < 0) {
else if (position < 0) {
qDebug() << "-- New note" << note.title() << ", adding it to the model...";
insertNote(note);
}
@ -101,21 +100,6 @@ bool NotesModel::applyJSON(QString json) {
}
jarr.pop_front();
}
// TODO the current implementation does not respect the changement of the index
/*for (int i = 0; i < notesToRemove.size(); i++) {
qDebug() << "Removing note" << m_notes[notesToRemove[i]].note.title;
beginRemoveRows(QModelIndex(), notesToRemove[i], notesToRemove[i]);
m_notes.removeAt(notesToRemove[i]);
endRemoveRows();
}*/
/*for (int i = 0; i < notesToAdd.size(); i++) {
beginInsertRows(QModelIndex(), notesToAdd[i].param, notesToAdd[i].param);
ModelNote<Note, bool> note;
note.note = notesToAdd[i].note;
qDebug() << "Adding note"<< note.note.title << "on position" << notesToAdd[i].param;
m_notes.insert(notesToAdd[i].param, note);
endInsertRows();
}*/
}
else if (jdoc.isObject()) {
qDebug() << "It's a single object...";
@ -134,17 +118,12 @@ bool NotesModel::applyJSON(QString json) {
m_notes.insert(position, noteToInsert);
endInsertRows();
}
notesModified++;
}
}
else {
qDebug() << "Unknown JSON document. This message should never occure!";
return false;
}
if (notesModified > 0) {
sort(); // TODO react to signal connect()
search(m_searchText);
}
return true;
}
else
{
@ -153,7 +132,7 @@ bool NotesModel::applyJSON(QString json) {
return error.error == QJsonParseError::NoError;
}
int NotesModel::insertNote(Note &note) {
int NotesModel::insertNote(const Note &note) {
int position = insertPosition(note);
ModelNote<Note, bool> modelNote;
modelNote.note = note;
@ -164,20 +143,12 @@ int NotesModel::insertNote(Note &note) {
return position;
}
bool NotesModel::removeNote(Note &note) {
bool NotesModel::removeNote(const Note &note) {
return removeNote(note.id());
}
bool NotesModel::removeNote(int id) {
bool noteRemoved = false;
int position = indexOf(id);
if (position >= 0) {
noteRemoved = removeAt(position);;
}
return noteRemoved;
}
bool NotesModel::removeAt(int position) {
if (position >= 0 && position < m_notes.size()) {
beginRemoveRows(QModelIndex(), position, position);
m_notes.removeAt(position);
@ -187,7 +158,7 @@ bool NotesModel::removeAt(int position) {
return false;
}
bool NotesModel::replaceNote(Note &note) {
bool NotesModel::replaceNote(const Note &note) {
int position = indexOf(note.id());
if (position >= 0 && position < m_notes.size()) {
ModelNote<Note, bool> modelNote;

View file

@ -32,12 +32,11 @@ public:
Q_INVOKABLE void search(QString searchText = QString());
Q_INVOKABLE void clearSearch();
Q_INVOKABLE bool applyJSON(QString json);
Q_INVOKABLE int insertNote(Note &note);
Q_INVOKABLE bool removeNote(Note &note);
Q_INVOKABLE bool removeNote(int id);
Q_INVOKABLE bool replaceNote(Note &note);
Q_INVOKABLE bool removeAt(int position);
Q_INVOKABLE bool applyJSON(const QString &json);
Q_INVOKABLE int insertNote(const Note &note);
Q_INVOKABLE bool removeNote(const Note &note);
Q_INVOKABLE bool removeNote(int position);
Q_INVOKABLE bool replaceNote(const Note &note);
Q_INVOKABLE void clear();
Q_INVOKABLE int indexOf(int id) const;
@ -96,6 +95,7 @@ private:
void sort();
//void update();
//void insertJnote(const QJsonObject &jobj);
int insertPosition(const Note &n) const;
bool noteLessThan(const Note &n1, const Note &n2) const;
/*static bool noteLessThanByDate(const Note &n1, const Note &n2);

View file

@ -232,52 +232,52 @@
<context>
<name>NotePage</name>
<message>
<location filename="../qml/pages/NotePage.qml" line="95"/>
<location filename="../qml/pages/NotePage.qml" line="102"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="99"/>
<location filename="../qml/pages/NotePage.qml" line="106"/>
<source>Reload</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="99"/>
<location filename="../qml/pages/NotePage.qml" line="106"/>
<source>Updating...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="105"/>
<location filename="../qml/pages/NotePage.qml" line="112"/>
<source>Last update</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="108"/>
<location filename="../qml/pages/NotePage.qml" line="115"/>
<source>never</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="115"/>
<location filename="../qml/pages/NotePage.qml" line="122"/>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="116"/>
<location filename="../qml/pages/NotePage.qml" line="123"/>
<source>Notes</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="236"/>
<location filename="../qml/pages/NotePage.qml" line="243"/>
<source>No category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="237"/>
<location filename="../qml/pages/NotePage.qml" line="244"/>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="252"/>
<location filename="../qml/pages/NotePage.qml" line="259"/>
<source>Modified</source>
<translation type="unfinished"></translation>
</message>
@ -328,57 +328,57 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="187"/>
<location filename="../qml/pages/NotesPage.qml" line="197"/>
<source>Modified</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="190"/>
<location filename="../qml/pages/NotesPage.qml" line="200"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="192"/>
<location filename="../qml/pages/NotesPage.qml" line="202"/>
<source>Deleting note</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="217"/>
<location filename="../qml/pages/NotesPage.qml" line="227"/>
<source>No account yet</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="218"/>
<location filename="../qml/pages/NotesPage.qml" line="228"/>
<source>Got to the settings to add an account</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="224"/>
<location filename="../qml/pages/NotesPage.qml" line="234"/>
<source>No notes yet</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="225"/>
<location filename="../qml/pages/NotesPage.qml" line="235"/>
<source>Pull down to add a note</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="231"/>
<location filename="../qml/pages/NotesPage.qml" line="241"/>
<source>No result</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="232"/>
<location filename="../qml/pages/NotesPage.qml" line="242"/>
<source>Try another query</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="238"/>
<location filename="../qml/pages/NotesPage.qml" line="248"/>
<source>An error occurred</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotesPage.qml" line="249"/>
<location filename="../qml/pages/NotesPage.qml" line="259"/>
<source>Open the settings to configure your Nextcloud accounts</source>
<translation type="unfinished"></translation>
</message>