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

@@ -1,4 +1,5 @@
class Note extends Item {
class Item {
constructor(json_obj) {
var content;
@@ -24,40 +25,37 @@ class Note extends Item {
enumerable: true,
});
_.merge(this, json_obj);
this.setContentRaw = function(rawContent) {
content = rawContent;
}
_.merge(this, json_obj);
if(!this.content) {
this.content = {title: "", text: ""};
}
}
filterDummyNotes(notes) {
var filtered = notes.filter(function(note){return note.dummy == false || note.dummy == null});
return filtered;
referencesMatchingContentType(contentType) {
return this.references.filter(function(reference){
return reference.content_type == content_type;
});
}
updateReferencesLocalMapping() {
super.updateReferencesLocalMapping();
this.groups = this.referencesMatchingContentType("Group");
// should be overriden to manage local properties
}
get hasOnePublicGroup() {
var hasPublicGroup = false;
this.groups.forEach(function(group){
if(group.isPublic()) {
hasPublicGroup = true;
return;
}
})
return hasPublicGroup;
/* Returns true if note is shared individually or via group */
isPublic() {
return this.presentation;
}
function isPublic() {
return super.isPublic() || this.hasOnePublicGroup;
isEncrypted() {
return this.encryptionEnabled() && typeof this.content === 'string' ? true : false;
}
encryptionEnabled() {
return this.loc_eek;
}
presentationURL() {
return this.presentation.url;
}
}

View File

@@ -0,0 +1,36 @@
class Note extends Item {
constructor(json_obj) {
super(json_obj);
if(!this.content) {
this.content = {title: "", text: ""};
}
}
filterDummyNotes(notes) {
var filtered = notes.filter(function(note){return note.dummy == false || note.dummy == null});
return filtered;
}
get hasOnePublicGroup() {
var hasPublicGroup = false;
this.groups.forEach(function(group){
if(group.isPublic()) {
hasPublicGroup = true;
return;
}
})
return hasPublicGroup;
}
isPublic() {
return super.isPublic() || this.hasOnePublicGroup;
}
get content_type() {
return "Note";
}
}

View File

@@ -0,0 +1,10 @@
class Tag extends Item {
constructor(json_obj) {
super(json_obj);
}
get content_type() {
return "Tag";
}
}

View File

@@ -0,0 +1,5 @@
class User {
constructor(json_obj) {
_.merge(this, json_obj);
}
}

View File

@@ -1,13 +0,0 @@
class Group extends Item {
constructor(json_obj) {
_.merge(this, json_obj);
}
updateReferencesLocalMapping() {
super.updateReferencesLocalMapping();
this.notes = this.referencesMatchingContentType("Note");
this.notes.sort(function(a,b){
return new Date(b.created_at) - new Date(a.created_at);
});
}
}

View File

@@ -1,29 +0,0 @@
class Item {
referencesMatchingContentType(contentType) {
return this.references.filter(function(reference){
return reference.content_type == content_type;
});
}
updateReferencesLocalMapping() {
// should be overriden to manage local properties
}
/* Returns true if note is shared individually or via group */
isPublic() {
return this.presentation;
}
isEncrypted() {
return this.encryptionEnabled() && typeof this.content === 'string' ? true : false;
}
encryptionEnabled() {
return this.loc_eek;
}
presentationURL() {
return this.presentation.url;
}
}

View File

@@ -1,55 +0,0 @@
class ItemManager() {
set items(items) {
this.items = items;
resolveReferences();
}
referencesForItemId(itemId) {
return _.find(this.items, {uuid: itemId});
}
resolveReferences() {
this.items.forEach(function(item){
// build out references
_.map(item.references, function(reference){
return referencesForItemId(reference.uuid);
})
});
}
itemsForContentType(contentType) {
this.items.filter(function(item){
return item.content_type == contentType;
});
}
// returns dirty item references that need saving
deleteItem(item) {
_.remove(this.items, item);
item.references.forEach(function(reference){
removeReferencesFromItem(reference, item);
})
return item.references;
}
removeReferencesBetweenItems(itemOne, itemTwo) {
_.remove(itemOne.references, _.find(itemOne.references, {uuid: itemTwo.uuid}));
_.remove(itemTwo.references, _.find(itemTwo.references, {uuid: itemOne.uuid}));
return [itemOne, itemTwo];
}
removeReferencesBetweenItems(itemOne, itemTwo) {
itemOne.references.push(itemTwo);
itemTwo.references.push(itemOne);
return [itemOne, itemTwo];
}
createReferencesBetweenItems(itemOne, itemTwo) {
itemOne.references.push(itemTwo);
itemTwo.references.push(itemOne);
return [itemOne, itemTwo];
}
}

View File

@@ -1,23 +0,0 @@
class User {
constructor(json_obj) {
_.merge(this, json_obj);
this.itemManager = new ItemManager();
this.itemManager.items = this.items;
this.items = null;
this.notes = _.map(this.itemManager.itemsForContentType("Note"), function(json_obj) {
return new Note(json_obj);
})
this.groups = _.map(this.itemManager.itemsForContentType("Group"), function(json_obj) {
var group = Group(json_obj);
group.updateReferencesLocalMapping();
return group;
})
}
filteredNotes() {
return Note.filterDummyNotes(this.notes);
}
}