This commit is contained in:
Mo Bitar
2016-12-15 12:52:34 -06:00
parent 1d4905d17d
commit 6a2e3e9ec1
34 changed files with 2594 additions and 264 deletions

View File

@@ -0,0 +1,85 @@
class ModelManager extends ItemManager {
set items(items) {
super.items = items;
this.notes = _.map(this.items.itemsForContentType("Note"), function(json_obj) {
return new Note(json_obj);
})
this.groups = _.map(this.items.itemsForContentType("Group"), function(json_obj) {
var group = Group(json_obj);
group.updateReferencesLocalMapping();
return group;
})
}
addDirtyItems(items) {
if(this.dirtyItems) {
this.dirtyItems = [];
}
this.dirtyItems.concat(items);
}
get dirtyItems() {
return this.dirtyItems || [];
}
get filteredNotes() {
return Note.filterDummyNotes(this.notes);
}
clearDirtyItems() {
this.dirtyItems = [];
}
addNote(note) {
if(!_.find(this.notes, {uuid: note.uuid})) {
this.notes.unshift(note);
}
}
addTag(tag) {
this.tags.unshift(tag);
}
addTagToNote(tag, note) {
var dirty = this.createReferencesBetweenItems(tag, note);
this.refreshRelationshipsForTag(tag);
this.refreshRelationshipsForNote(note);
this.addDirtyItems(dirty);
}
refreshRelationshipsForTag(tag) {
tag.notes = tag.referencesMatchingContentType("Note");
tag.notes.sort(function(a,b){
return new Date(b.created_at) - new Date(a.created_at);
});
}
refreshRelationshipsForNote(note) {
note.groups = note.referencesMatchingContentType("Group");
}
removeTagFromNote(tag, note) {
var dirty = this.removeReferencesBetweenItems(tag, note);
this.addDirtyItems(dirty);
}
deleteNote(note) {
var dirty = this.deleteItem(note);
this.addDirtyItems(dirty);
}
deleteTag(tag) {
var dirty = this.deleteItem(tag);
this.addDirtyItems(dirty);
}
filteredNotes() {
return Note.filterDummyNotes(this.notes);
}
}
angular.module('app.frontend').service('modelManager', ModelManager);