Just some small changes.

This commit is contained in:
Scharel Clemens 2019-02-24 16:40:47 +01:00
parent 2941f32eb4
commit fc8072bb60
7 changed files with 39 additions and 68 deletions

View file

@ -20,7 +20,6 @@ Item {
onUuidChanged: {
appSettings.currentAccount = uuid
account.path = "/apps/harbour-nextcloudnotes/accounts/" + uuid
model.clear()
onUuidChanged: console.log("Account : " + account.name)
}
/*function clear() {
@ -34,11 +33,9 @@ Item {
if (data) {
if (method === "POST" || method === "PUT") {
console.log("Adding note...")
//addToModel(data)
}
else if (data.id && method === "DELETE") {
console.log("Deleting note...")
//removeFromModel(data.id)
}
if (method === "GET" || method === "PUT" || method === "DELETE") {
if (data.id) {
@ -61,43 +58,8 @@ Item {
statusText = apiReq.statusText
status = apiReq.status
if (apiReq.status === 200) {
//console.log(apiReq.responseText)
response = apiReq.responseText
var json = JSON.parse(response)
switch(method) {
case "GET":
if (Array.isArray(json)) {
console.log("Received all notes via API: " + endpoint)
model.clear()
for (var element in json) {
addToModel(json[element])
}
account.update = new Date()
}
else {
console.log("Received a single note via API: " + endpoint)
addToModel(json)
}
break
case "POST":
console.log("Created a note via API: " + endpoint)
addToModel(json)
pageStack.push(Qt.resolvedUrl("../pages/NotePage.qml"), { note: json } )
//pageStack.completeAnimation()
//pageStack.navigateForward()
break
case "PUT":
console.log("Updated a note via API: " + endpoint)
addToModel(json)
break
case "DELETE":
console.log("Deleted a note via API: " + endpoint)
removeFromModel(data.id)
break
default:
console.log("Unsupported method: " + method)
break
}
//console.log(response)
}
else if(apiReq.status === 0) {
statusText = qsTr("Unable to connect")

View file

@ -110,6 +110,7 @@ ApplicationWindow
id: api
uuid: appSettings.currentAccount
onResponseChanged: noteListModel.applyJSON(response)
onUuidChanged: noteListModel.clear()
}
NotesModel {

View file

@ -13,12 +13,13 @@ Dialog {
}
function reloadContent() {
note = api.getNote(note.id)
api.getNoteFromApi(note.id)
/*note = api.getNote(note.id)
dialogHeader.title = note.title
contentArea.text = note.content
favoriteButton.selected = note.favorite
categoryField.text = note.category
modifiedDetail.modified = note.modified
modifiedDetail.modified = note.modified*/
}
SilicaFlickable {

View file

@ -50,12 +50,13 @@ Dialog {
}
function reloadContent() {
note = api.getNote(note.id)
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
parseContent()
parseContent()*/
}
function parseContent() {

View file

@ -12,12 +12,7 @@ NotesModel::NotesModel(QObject *parent) : QAbstractListModel(parent)
}
NotesModel::~NotesModel() {
beginRemoveRows(QModelIndex(), 0, rowCount());
for (int i = 0; i < m_notes.size(); i++) {
delete m_notes[i].note;
}
m_notes.clear();
endRemoveRows();
clear();
}
void NotesModel::setSortBy(int sortBy) {
@ -147,6 +142,16 @@ bool NotesModel::removeNote(int id) {
return noteRemoved;
}
void NotesModel::clear() {
m_searchText.clear();
beginRemoveRows(QModelIndex(), 0, rowCount());
for (int i = 0; i < m_notes.size(); i++) {
delete m_notes[i].note;
}
m_notes.clear();
endRemoveRows();
}
void NotesModel::search(QString searchText) {
if (m_searchText != searchText) {
m_searchText = searchText;

View file

@ -31,6 +31,7 @@ public:
Q_INVOKABLE bool applyJSON(QString json, bool replaceIfArray = true);
Q_INVOKABLE bool removeNote(int id);
Q_INVOKABLE void clear();
Q_INVOKABLE void search(QString searchText);
Q_INVOKABLE void clearSearch();

View file

@ -84,32 +84,32 @@
<context>
<name>EditPage</name>
<message>
<location filename="../qml/pages/EditPage.qml" line="30"/>
<location filename="../qml/pages/EditPage.qml" line="31"/>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="34"/>
<location filename="../qml/pages/EditPage.qml" line="35"/>
<source>Markdown syntax</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="62"/>
<location filename="../qml/pages/EditPage.qml" line="63"/>
<source>No content</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="147"/>
<location filename="../qml/pages/EditPage.qml" line="148"/>
<source>No category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="148"/>
<location filename="../qml/pages/EditPage.qml" line="149"/>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/EditPage.qml" line="163"/>
<location filename="../qml/pages/EditPage.qml" line="164"/>
<source>Modified</source>
<translation type="unfinished"></translation>
</message>
@ -219,52 +219,52 @@
<context>
<name>NotePage</name>
<message>
<location filename="../qml/pages/NotePage.qml" line="105"/>
<location filename="../qml/pages/NotePage.qml" line="106"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="109"/>
<location filename="../qml/pages/NotePage.qml" line="110"/>
<source>Reload</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="109"/>
<location filename="../qml/pages/NotePage.qml" line="110"/>
<source>Updating...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="115"/>
<location filename="../qml/pages/NotePage.qml" line="116"/>
<source>Last update</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="118"/>
<location filename="../qml/pages/NotePage.qml" line="119"/>
<source>never</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="125"/>
<location filename="../qml/pages/NotePage.qml" line="126"/>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="126"/>
<location filename="../qml/pages/NotePage.qml" line="127"/>
<source>Notes</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="246"/>
<location filename="../qml/pages/NotePage.qml" line="247"/>
<source>No category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="247"/>
<location filename="../qml/pages/NotePage.qml" line="248"/>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NotePage.qml" line="262"/>
<location filename="../qml/pages/NotePage.qml" line="263"/>
<source>Modified</source>
<translation type="unfinished"></translation>
</message>
@ -272,17 +272,17 @@
<context>
<name>NotesApi</name>
<message>
<location filename="../qml/components/NotesApi.qml" line="109"/>
<location filename="../qml/components/NotesApi.qml" line="65"/>
<source>Unable to connect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/components/NotesApi.qml" line="247"/>
<location filename="../qml/components/NotesApi.qml" line="147"/>
<source>Today</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/components/NotesApi.qml" line="249"/>
<location filename="../qml/components/NotesApi.qml" line="149"/>
<source>Yesterday</source>
<translation type="unfinished"></translation>
</message>