From 767c80bb3da8a934d4ec0a559f905230128d79f0 Mon Sep 17 00:00:00 2001 From: Chris Triantafillis Date: Thu, 12 Sep 2013 04:02:01 +0300 Subject: [PATCH] Fixed move note to archive and back --- CNotes.qml | 62 ++++++++++++++++++++-------------------- U1Backend.qml | 13 ++++++++- components/NoteItem.qml | 8 ++---- pages/CreateNotePage.qml | 1 - view/NotesListView.qml | 4 +-- 5 files changed, 47 insertions(+), 41 deletions(-) diff --git a/CNotes.qml b/CNotes.qml index 7e83316..5226266 100755 --- a/CNotes.qml +++ b/CNotes.qml @@ -52,12 +52,12 @@ MainView { property bool createNote: false property string specificTag - property variant notes - property variant categoriesModel - property variant archivesModel +// property variant notes +// property variant categoriesModel +// property variant archivesModel property variant filterNotesModel - property variant archiveNotes - property variant allNotes +// property variant archiveNotes +// property variant allNotes property variant noteLinksModel property variant imagesModel @@ -65,23 +65,23 @@ MainView { property variant database property variant backend - notes: ListModel { - onCountChanged: { - if (count > 0) { - notesListView.currentIndex = count - 1 - } - } - } +// notes: ListModel { +// onCountChanged: { +// if (count > 0) { +// notesListView.currentIndex = count - 1 +// } +// } +// } - categoriesModel: ListModel {} +// categoriesModel: ListModel {} - archivesModel: ListModel { - onCountChanged: { - if (count > 0) { - notesListView.currentIndex = count - 1 - } - } - } +// archivesModel: ListModel { +// onCountChanged: { +// if (count > 0) { +// notesListView.currentIndex = count - 1 +// } +// } +// } filterNotesModel: ListModel {} @@ -195,6 +195,14 @@ MainView { defaults: {"categories": ["None", "Work", "Things to do"] } } + U1db.Document { + id: tagsDocument + database: database + docId: "tags" + create: true + defaults: {"tags": []} + } + backend: U1Backend { id: backend } @@ -267,13 +275,6 @@ MainView { return } -// mainView.title = model[currentIndex].title -// mainView.title = model.get(currentIndex).title -// mainView.body = model.get(currentIndex).body -// mainView.category = model.get(currentIndex).category -// mainView.tag = model.get(currentIndex).tag -// mainView.archive = model.get(currentIndex).archive - if (wideAspect) { noteViewRow.visible = true } @@ -294,9 +295,9 @@ MainView { Popover { id: tagsPopover - property variant usedTags: Storage.getUsedTags() Component.onCompleted: { + var usedTags= database.getDoc("tags").tags var end = usedTags.length - 4 if (usedTags.length < 4) { end = 0 @@ -391,11 +392,10 @@ MainView { // Check if tag already exists! if (!containTag(tagTextField.text.split(",")[i])) { if (tagsModel.count == 3) { - Storage.addTag(tagsModel.get(0), tagTextField.text.split(",")[i]) - tagsModel.remove(0) + mainView.backend.addTag(tagsModel.get(0), tagTextField.text.split(",")[i]) } else { - Storage.addTag("", tagTextField.text.split(",")[i]) + mainView.backend.addTag("", tagTextField.text.split(",")[i]) } tagsModel.append({tag: tagTextField.text.split(",")[i]}) diff --git a/U1Backend.qml b/U1Backend.qml index 902c3e9..d0b8b6a 100755 --- a/U1Backend.qml +++ b/U1Backend.qml @@ -62,7 +62,6 @@ Item { j++ } } - setValues(newValues, doc) } @@ -168,4 +167,16 @@ Item { mainView.database.putDoc(newValues, "categories") } + + function addTag(old, newTag) { + var values = mainView.database.getDoc("tags") + + if (old !== "") { + values["tags"][0] = values["tags"][1] + values["tags"][1] = values["tags"][2] + } + + values["tags"][values["tags"].length] = newTag + mainView.database.putDoc(values, "tags") + } } diff --git a/components/NoteItem.qml b/components/NoteItem.qml index dd6e5fb..f1eb17d 100755 --- a/components/NoteItem.qml +++ b/components/NoteItem.qml @@ -34,18 +34,16 @@ Subtitled { subText: getHtmlText(_body) onItemRemoved: { - var id mainView.createNote = false + if (_view === "main") { - id = _id mainView.backend.setNote(_id, _title, _body, _category, _tag, 'true', 'archive', _links, "archive") - mainView.backend.removeNote(id, "notes") + mainView.backend.removeNote(index, "notes") } else { - id = _id mainView.backend.setNote(_id, _title, _body, _category, _tag, 'false', 'main', _links, "notes") - mainView.backend.removeNote(id, "archive") + mainView.backend.removeNote(index, "archive") } } diff --git a/pages/CreateNotePage.qml b/pages/CreateNotePage.qml index 8dafff0..8dfb57d 100755 --- a/pages/CreateNotePage.qml +++ b/pages/CreateNotePage.qml @@ -95,7 +95,6 @@ Tabs { ListItem.ValueSelector { id: categoriesSelector - property variant categories: Storage.fetchAllCategories() width: parent.width text: i18n.tr("Category") diff --git a/view/NotesListView.qml b/view/NotesListView.qml index d18d2dc..0481dda 100755 --- a/view/NotesListView.qml +++ b/view/NotesListView.qml @@ -17,9 +17,7 @@ ListView { delegate: NoteItem { - _id: { - return idCount - } + _id: idCount _title: getCorrectDoc().notes[index].title