Skip to content

Commit

Permalink
Fixed editNotePage, images, filterView
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Triantafillis committed Sep 11, 2013
1 parent 85b51fd commit a24c298
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 110 deletions.
70 changes: 43 additions & 27 deletions CNotes.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ MainView {

property bool wideAspect: width > units.gu(80)

property string idCount : "0"
property string idCount
property string id
property string title
property string body
Expand All @@ -48,9 +48,11 @@ MainView {
property string archive
property string mode
property string link
property string links
property string imageLocation
property bool showArchive: false
property bool createNote: false
property string specificTag

property variant notes
property variant categoriesModel
Expand Down Expand Up @@ -107,36 +109,53 @@ MainView {
}
}

function loadNotes() {
allNotes = Storage.fetchNotes('false')
function setIdCount() {
idCount = 0
for (var i = 0; i < allNotes.length; i++) {
var noteId = allNotes[i]
mainView.notes.append({id:noteId, title:Storage.getTitle(noteId), body:Storage.getBody(noteId),
category:Storage.getCategory(noteId), tag:Storage.getTags(noteId), archive:'false', view:"main"})

if (noteId > idCount)
idCount = noteId
}

}
var archive = database.getDoc("archive")

function loadArchiveNotes() {
archiveNotes = Storage.fetchNotes('true')
for (var i = 0; i < archiveNotes.length; i++) {
var noteId = archiveNotes[i]
archivesModel.append({id:noteId, title:Storage.getTitle(noteId), body:Storage.getBody(noteId),
category:Storage.getCategory(noteId), tag:Storage.getTags(noteId), archive:'true', view:"archive"})
var all = database.getDoc("notes")
for (var i = 0; i < archive["notes"].length; i++) {
all["notes"][all["notes"].length] = archive["notes"][i]
}
}

function loadCategories() {
var cat = Storage.fetchAllCategories()
for (var i = 0; i < cat.length; i++) {
categoriesModel.append({categoryName: cat[i]})
for (var i = 0; i < all["notes"].length; i++) {
if (all["notes"][i].id > idCount) {
idCount = all["notes"][i].id
}
}
}

// function loadNotes() {
// allNotes = Storage.fetchNotes('false')
// idCount = 0
// for (var i = 0; i < allNotes.length; i++) {
// var noteId = allNotes[i]
// mainView.notes.append({id:noteId, title:Storage.getTitle(noteId), body:Storage.getBody(noteId),
// category:Storage.getCategory(noteId), tag:Storage.getTags(noteId), archive:'false', view:"main"})

// if (noteId > idCount)
// idCount = noteId
// }

// }

// function loadArchiveNotes() {
// archiveNotes = Storage.fetchNotes('true')
// for (var i = 0; i < archiveNotes.length; i++) {
// var noteId = archiveNotes[i]
// archivesModel.append({id:noteId, title:Storage.getTitle(noteId), body:Storage.getBody(noteId),
// category:Storage.getCategory(noteId), tag:Storage.getTags(noteId), archive:'true', view:"archive"})
// }
// }

// function loadCategories() {
// var cat = Storage.fetchAllCategories()
// for (var i = 0; i < cat.length; i++) {
// categoriesModel.append({categoryName: cat[i]})
// }
// }

function containTag(t) {
for (var i = 0; i < tagsModel.count; i++) {
if (t === tagsModel.get(i).tag) {
Expand Down Expand Up @@ -218,10 +237,7 @@ MainView {
Component.onDestruction: dirParser.remove('./U1Database')

Component.onCompleted: {

// TODO delete next lines
Storage.initialize()
dirParser.removeDir('./categories')
setIdCount()

rootPageStack.push(mainConditionalPage)
}
Expand Down
112 changes: 100 additions & 12 deletions U1Backend.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import Ubuntu.Components 0.1

Item {

function setNote(title, body, tag, category, archive, view, links, doc) {
function setNote(id, title, body, category, tag, archive, view, links, doc) {
var values
if (doc === "notes") {
values = mainView.database.getDoc("notes")
values["notes"][mainView.database.getDoc("notes").notes.length] = {'title': title, 'body': body,
values["notes"][mainView.database.getDoc("notes").notes.length] = {'id': id, 'title': title, 'body': body,
'category': category, 'tag': tag, 'archive': archive, 'view': view, 'links': links}

mainView.database.putDoc(values, "notes")
Expand All @@ -19,22 +19,38 @@ Item {
}
else {
values = mainView.database.getDoc("archive")
values["notes"][mainView.database.getDoc("archive").notes.length] = {'title': title, 'body': body,
values["notes"][mainView.database.getDoc("archive").notes.length] = {'id': id, 'title': title, 'body': body,
'category': category, 'tag': tag, 'archive': archive, 'view': view, 'links': links}

mainView.database.putDoc(values, "archive")
}
}

function removeNote(id, docId) {
var values
id = parseInt(id)
if (docId === "notes") {
values = mainView.database.getDoc("notes")
function replaceNote(pos, doc, title, body, category, tag, archive, view) {
pos = parseInt(pos)
var values = getValues(doc)

values["notes"][pos].title = title
values["notes"][pos].body = body
values["notes"][pos].tag = tag
values["notes"][pos].category = category
values["notes"][pos].archive = archive
values["notes"][pos].view = view

setValues(values, doc)

if (mainView.showArchive) {
notesListView.model = mainView.database.getDoc("archive").notes
}
else {
values = mainView.database.getDoc("archive")
notesListView.model = mainView.database.getDoc("notes").notes
}
}

function removeNote(id, doc) {

id = parseInt(id)
var values = getValues(doc)

var j = 0
var newValues = {"notes": []}
Expand All @@ -46,12 +62,84 @@ Item {
}
}

if (docId === "notes") {
mainView.database.putDoc(newValues, "notes")
setValues(newValues, doc)
}

function getValues(doc) {
var values
if (doc === "notes") {
values = mainView.database.getDoc("notes")
}
else {
mainView.database.putDoc(newValues, "archive")
values = mainView.database.getDoc("archive")
}

return values
}

function setValues(values, doc) {
if (doc === "notes") {
mainView.database.putDoc(values, "notes")
}
else {
mainView.database.putDoc(values, "archive")
}
}

function fecthAllNotesWithTag(tag) {
var res = {"notes": []}
var archive = mainView.database.getDoc("archive")

var all = mainView.database.getDoc("notes")
for (var i = 0; i < archive["notes"].length; i++) {
all["notes"][all["notes"].length] = archive["notes"][i]
}

var j = 0
for (var i = 0; i < all["notes"].length; i++) {
if (containTag(tag, all["notes"][i].tag)) {
res["notes"][j] = all["notes"][i]
j++
}
}

return res
}

function containTag(tag, tags) {
var t = tags.split(",")
for (var i = 0; i < t.length; i++) {
if (tag === t[i]) {
return true
}
}

return false
}

function fetchAllNotesWithCategory(cat) {
var res = {"notes": []}
var archive = mainView.database.getDoc("archive")

var all = mainView.database.getDoc("notes")
for (var i = 0; i < archive["notes"].length; i++) {
all["notes"][all["notes"].length] = archive["notes"][i]
}

var j = 0
for (var i = 0; i < all["notes"].length; i++) {
if (all["notes"][i].category === cat) {
res["notes"][j] = all["notes"][i]
j++
}
}

return res
}

function deleteArchive() {
mainView.database.putDoc({"notes" : []}, "archive")
notesListView.model = mainView.database.getDoc("archive").notes
}

function addCategory(name) {
Expand Down
7 changes: 6 additions & 1 deletion components/LinksTab.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ Tab {

function loadLinks() {
linksListView.model.clear()
var links = notesListView.model[mainView.id].links
var links
try {
links = notesListView.model[mainView.id].links
} catch (error) {
links = mainView.links
}

for (var i = 0; i < links.split(",").length; i++) {
if (links.split(",")[i] !== "Unknown") {
Expand Down
19 changes: 19 additions & 0 deletions components/MainToolbar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ ToolbarItems {
}
}

ToolbarButton {
action: Action {
id: deleteArchive
objectName: "deleteArchive"

iconSource: Qt.resolvedUrl("../images/close.svg")
text: i18n.tr("Delete all")

onTriggered: mainView.backend.deleteArchive()
}

visible: {
if (mainView.showArchive) {
return true
}
return false
}
}

ToolbarButton {
action: Action {
id: archivesPageAction
Expand Down
5 changes: 3 additions & 2 deletions components/NoteItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ Subtitled {
mainView.createNote = false
if (_view === "main") {
id = _id
mainView.backend.setNote(_title, _body, _category, _tag, 'true', 'archive', _links, "archive")
mainView.backend.setNote(_id, _title, _body, _category, _tag, 'true', 'archive', _links, "archive")
mainView.backend.removeNote(id, "notes")
}
else {
id = _id
mainView.backend.setNote(_title, _body, _category, _tag, 'false', 'main', _links, "notes")
mainView.backend.setNote(_id, _title, _body, _category, _tag, 'false', 'main', _links, "notes")
mainView.backend.removeNote(id, "archive")
}
}
Expand All @@ -60,6 +60,7 @@ Subtitled {
mainView.tag = _tag
mainView.position = model.index
mainView.archive = _archive
mainView.links = _links

if (mainView.wideAspect)
return
Expand Down
17 changes: 10 additions & 7 deletions components/NoteViewRow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,29 @@ Row {

onClicked: {
mainView.filter = "Tag"
mainView.specificTag = tag
showNotesWithFilter (tag)
}
}
}

function showNotesWithFilter (f) {
filterNotesModel.clear()

var allNotes
if (mainView.filter == "Tag") {
allNotes = Storage.fetchAllNotesWithTag(f)
allNotes = mainView.backend.fecthAllNotesWithTag(f)
}
else {
allNotes = Storage.fetchAllNotesWithCategory(f)
allNotes = mainView.backend.fetchAllNotesWithCategory(f)
}

for (var i = 0; i < allNotes.length; i++) {
var noteId = allNotes[i]
filterNotesModel.append({id:noteId, title:Storage.getTitle(noteId), body:Storage.getBody(noteId),
category:Storage.getCategory(noteId), tag:Storage.getTags(noteId), archive:Storage.getArchive(noteId),
view:Storage.getView(noteId)})
for (var i = 0; i < allNotes["notes"].length; i++) {
var values = allNotes.notes[i]
filterNotesModel.append({title:values.title, body:values.body, tag:values.tag, category:values.category,
archive:values.archive, view:values.view, links:values.links})
}

rootPageStack.push(Qt.resolvedUrl("../view/FilterNoteView.qml"))
}
}
Loading

0 comments on commit a24c298

Please sign in to comment.