working functionality

This commit is contained in:
Mo Bitar
2016-12-15 17:37:26 -06:00
parent 6a2e3e9ec1
commit 1722eb299c
31 changed files with 944 additions and 760 deletions

View File

@@ -1,6 +1,6 @@
class Item {
constructor(json_obj) {
var content;
Object.defineProperty(this, "content", {
@@ -12,14 +12,13 @@ class Item {
if(typeof value === 'string') {
try {
decodedValue = JSON.parse(value);
var decodedValue = JSON.parse(value);
finalValue = decodedValue;
}
catch(e) {
finalValue = value;
}
}
content = finalValue;
},
enumerable: true,
@@ -27,14 +26,35 @@ class Item {
_.merge(this, json_obj);
if(!this.uuid) {
this.uuid = Neeto.crypto.generateUUID();
}
this.setContentRaw = function(rawContent) {
content = rawContent;
}
if(!this.content) {
this.content = {};
}
if(!this.content.references) {
this.content.references = [];
}
}
addReference(reference) {
this.content.references.push(reference);
this.content.references = _.uniq(this.content.references);
}
removeReference(reference) {
_.remove(this.content.references, _.find(this.content.references, {uuid: reference.uuid}));
}
referencesMatchingContentType(contentType) {
return this.references.filter(function(reference){
return reference.content_type == content_type;
return this.content.references.filter(function(reference){
return reference.content_type == contentType;
});
}
@@ -42,7 +62,7 @@ class Item {
// should be overriden to manage local properties
}
/* Returns true if note is shared individually or via group */
/* Returns true if note is shared individually or via tag */
isPublic() {
return this.presentation;
}
@@ -58,4 +78,5 @@ class Item {
presentationURL() {
return this.presentation.url;
}
}

View File

@@ -1,33 +1,37 @@
class Note extends Item {
constructor(json_obj) {
super(json_obj);
if(!this.content) {
this.content = {title: "", text: ""};
if(!this.tags) {
this.tags = [];
}
if(!this.content.title) {
this.content.title = "";
this.content.text = "";
}
}
filterDummyNotes(notes) {
static 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;
get hasOnePublicTag() {
var hasPublicTag = false;
this.tags.forEach(function(tag){
if(tag.isPublic()) {
hasPublicTag = true;
return;
}
})
return hasPublicGroup;
return hasPublicTag;
}
isPublic() {
return super.isPublic() || this.hasOnePublicGroup;
return super.isPublic() || this.hasOnePublicTag;
}
get content_type() {

View File

@@ -2,9 +2,23 @@ class Tag extends Item {
constructor(json_obj) {
super(json_obj);
if(!this.notes) {
this.notes = [];
}
if(!this.content.name) {
this.content.name = "";
}
}
get content_type() {
return "Tag";
}
updateReferencesLocalMapping() {
super.updateReferencesLocalMapping();
this.notes = this.referencesMatchingContentType("Note");
console.log("notes after maping", this.notes);
}
}