item deletion
This commit is contained in:
@@ -81,7 +81,7 @@ angular.module('app.frontend')
|
||||
{title: "MySQL list users", content: "SELECT User FROM mysql.user;"},
|
||||
];
|
||||
|
||||
this.showSampler = !this.user.id && modelManager.filteredNotes.length == 0;
|
||||
this.showSampler = !this.user.uuid && modelManager.filteredNotes.length == 0;
|
||||
|
||||
this.demoNoteNames = _.map(this.demoNotes, function(note){
|
||||
return note.title;
|
||||
|
||||
@@ -144,7 +144,7 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
this.onAuthSuccess = function(user) {
|
||||
this.user.id = user.id;
|
||||
this.user.uuid = user.uuid;
|
||||
|
||||
if(this.user.shouldMerge && this.hasLocalData()) {
|
||||
apiController.mergeLocalDataRemotely(this.user, function(){
|
||||
|
||||
@@ -17,7 +17,15 @@ angular.module('app.frontend')
|
||||
if(response && !response.errors) {
|
||||
console.log("Get user response", response);
|
||||
$scope.defaultUser = new User(response);
|
||||
modelManager.items = _.map(response.items, function(json_obj){return new Item(json_obj)});
|
||||
modelManager.items = _.map(response.items, function(json_obj){
|
||||
if(json_obj.content_type == "Note") {
|
||||
return new Note(json_obj);
|
||||
} else if(json_obj.content_type == "Tag") {
|
||||
return new Tag(json_obj);
|
||||
} else {
|
||||
return new Item(json_obj);
|
||||
}
|
||||
});
|
||||
$rootScope.title = "Notes — Neeto";
|
||||
onUserSet();
|
||||
} else {
|
||||
@@ -41,9 +49,6 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
$scope.tagsSelectionMade = function(tag) {
|
||||
if(!tag.notes) {
|
||||
tag.notes = [];
|
||||
}
|
||||
$scope.selectedTag = tag;
|
||||
}
|
||||
|
||||
@@ -61,8 +66,7 @@ angular.module('app.frontend')
|
||||
*/
|
||||
$scope.tagsUpdateNoteTag = function(noteCopy, newTag, oldTag) {
|
||||
|
||||
var originalNote = _.find($scope.defaultUser.notes, {uuid: noteCopy.uuid});
|
||||
modelManager.removeTagFromNote(oldTag, originalNote);
|
||||
var originalNote = _.find(modelManager.notes, {uuid: noteCopy.uuid});
|
||||
if(!newTag.all) {
|
||||
modelManager.addTagToNote(newTag, originalNote);
|
||||
}
|
||||
@@ -98,11 +102,12 @@ angular.module('app.frontend')
|
||||
modelManager.addNote(note);
|
||||
|
||||
if(!$scope.selectedTag.all) {
|
||||
console.log("add tag");
|
||||
modelManager.addTagToNote($scope.selectedTag, note);
|
||||
$scope.updateAllTag();
|
||||
} else {
|
||||
$scope.selectedTag.notes.unshift(note);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -130,11 +135,13 @@ angular.module('app.frontend')
|
||||
$scope.selectedNote = null;
|
||||
}
|
||||
|
||||
$scope.updateAllTag();
|
||||
|
||||
if(note.dummy) {
|
||||
return;
|
||||
}
|
||||
|
||||
apiController.deleteItem($scope.defaultUser, note, function(success){})
|
||||
apiController.deleteItem(note, function(success){})
|
||||
apiController.saveDirtyItems(function(){});
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ angular.module('app.frontend')
|
||||
}
|
||||
}
|
||||
})
|
||||
.controller('NotesCtrl', function (apiController, modelManager, $timeout, ngDialog, $rootScope) {
|
||||
.controller('NotesCtrl', function (apiController, $timeout, ngDialog, $rootScope) {
|
||||
|
||||
$rootScope.$on("editorFocused", function(){
|
||||
this.showMenu = false;
|
||||
@@ -41,7 +41,11 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
this.noteFilter.text = "";
|
||||
this.setNotes(tag.notes, false);
|
||||
|
||||
tag.notes.forEach(function(note){
|
||||
note.visible = true;
|
||||
})
|
||||
this.selectFirstNote(false);
|
||||
|
||||
if(isFirstLoad) {
|
||||
$timeout(function(){
|
||||
@@ -67,7 +71,7 @@ angular.module('app.frontend')
|
||||
this.selectedTagShare = function() {
|
||||
this.showMenu = false;
|
||||
|
||||
if(!this.user.id) {
|
||||
if(!this.user.uuid) {
|
||||
alert("You must be signed in to share a tag.");
|
||||
return;
|
||||
}
|
||||
@@ -109,17 +113,8 @@ angular.module('app.frontend')
|
||||
return this.tag.presentation.url;
|
||||
}
|
||||
|
||||
this.setNotes = function(notes, createNew) {
|
||||
this.notes = notes;
|
||||
console.log("set notes", notes);
|
||||
notes.forEach(function(note){
|
||||
note.visible = true;
|
||||
})
|
||||
this.selectFirstNote(createNew);
|
||||
}
|
||||
|
||||
this.selectFirstNote = function(createNew) {
|
||||
var visibleNotes = this.notes.filter(function(note){
|
||||
var visibleNotes = this.tag.notes.filter(function(note){
|
||||
return note.visible;
|
||||
});
|
||||
|
||||
@@ -136,12 +131,9 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
this.createNewNote = function() {
|
||||
var title = "New Note" + (this.notes ? (" " + (this.notes.length + 1)) : "");
|
||||
var title = "New Note" + (this.tag.notes ? (" " + (this.tag.notes.length + 1)) : "");
|
||||
this.newNote = new Note({dummy: true});
|
||||
this.newNote.content.title = title;
|
||||
if(this.tag && !this.tag.all) {
|
||||
modelManager.addTagToNote(this.tag, this.newNote);
|
||||
}
|
||||
this.selectNote(this.newNote);
|
||||
this.addNew()(this.newNote);
|
||||
}
|
||||
|
||||
@@ -63,10 +63,7 @@ angular.module('app.frontend')
|
||||
return;
|
||||
}
|
||||
|
||||
this.newTag = new Tag({notes : []});
|
||||
if(!this.user.uuid) {
|
||||
this.newTag.uuid = Neeto.crypto.generateRandomKey()
|
||||
}
|
||||
this.newTag = new Tag();
|
||||
this.selectedTag = this.newTag;
|
||||
this.editingTag = this.newTag;
|
||||
this.addNew()(this.newTag);
|
||||
@@ -95,7 +92,7 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
this.save()(tag, function(savedTag){
|
||||
_.merge(tag, savedTag);
|
||||
// _.merge(tag, savedTag);
|
||||
this.selectTag(tag);
|
||||
this.newTag = null;
|
||||
}.bind(this));
|
||||
|
||||
@@ -46,10 +46,12 @@ class Item {
|
||||
addReference(reference) {
|
||||
this.content.references.push(reference);
|
||||
this.content.references = _.uniq(this.content.references);
|
||||
this.updateReferencesLocalMapping();
|
||||
}
|
||||
|
||||
removeReference(reference) {
|
||||
_.remove(this.content.references, _.find(this.content.references, {uuid: reference.uuid}));
|
||||
this.updateReferencesLocalMapping();
|
||||
}
|
||||
|
||||
referencesMatchingContentType(contentType) {
|
||||
@@ -62,7 +64,6 @@ class Item {
|
||||
// should be overriden to manage local properties
|
||||
}
|
||||
|
||||
/* Returns true if note is shared individually or via tag */
|
||||
isPublic() {
|
||||
return this.presentation;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@ class Note extends Item {
|
||||
return filtered;
|
||||
}
|
||||
|
||||
updateReferencesLocalMapping() {
|
||||
super.updateReferencesLocalMapping();
|
||||
this.tags = this.referencesMatchingContentType("Tag");
|
||||
}
|
||||
|
||||
get hasOnePublicTag() {
|
||||
var hasPublicTag = false;
|
||||
this.tags.forEach(function(tag){
|
||||
@@ -30,6 +35,10 @@ class Note extends Item {
|
||||
return hasPublicTag;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {uuid: this.uuid}
|
||||
}
|
||||
|
||||
isPublic() {
|
||||
return super.isPublic() || this.hasOnePublicTag;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,5 @@ class Tag extends Item {
|
||||
updateReferencesLocalMapping() {
|
||||
super.updateReferencesLocalMapping();
|
||||
this.notes = this.referencesMatchingContentType("Note");
|
||||
console.log("notes after maping", this.notes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ angular.module('app.frontend')
|
||||
*/
|
||||
|
||||
this.setUsername = function(user, username, callback) {
|
||||
var request = Restangular.one("users", user.id).one("set_username");
|
||||
var request = Restangular.one("users", user.uuid).one("set_username");
|
||||
request.username = username;
|
||||
request.post().then(function(response){
|
||||
callback(response.plain());
|
||||
@@ -183,6 +183,10 @@ angular.module('app.frontend')
|
||||
|
||||
this.saveDirtyItems = function(callback) {
|
||||
var dirtyItems = modelManager.dirtyItems;
|
||||
if(dirtyItems.length == 0) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
this.saveItems(dirtyItems, function(response){
|
||||
modelManager.clearDirtyItems();
|
||||
@@ -232,7 +236,7 @@ angular.module('app.frontend')
|
||||
|
||||
|
||||
this.deleteItem = function(item, callback) {
|
||||
if(!this.user.id) {
|
||||
if(!this.user.uuid) {
|
||||
this.writeUserToLocalStorage(this.user);
|
||||
callback(true);
|
||||
} else {
|
||||
@@ -244,7 +248,7 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
this.shareItem = function(item, callback) {
|
||||
if(!this.user.id) {
|
||||
if(!this.user.uuid) {
|
||||
alert("You must be signed in to share.");
|
||||
} else {
|
||||
Restangular.one("users", this.user.uuid).one("items", item.uuid).one("presentations").post()
|
||||
@@ -280,9 +284,9 @@ angular.module('app.frontend')
|
||||
*/
|
||||
|
||||
this.updatePresentation = function(resource, presentation, callback) {
|
||||
var request = Restangular.one("users", this.user.id)
|
||||
.one("items", resource.id)
|
||||
.one("presentations", resource.presentation.id);
|
||||
var request = Restangular.one("users", this.user.uuid)
|
||||
.one("items", resource.uuid)
|
||||
.one("presentations", resource.presentation.uuid);
|
||||
_.merge(request, presentation);
|
||||
request.patch().then(function(response){
|
||||
callback(response.plain());
|
||||
@@ -354,7 +358,7 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
return {
|
||||
id: presentation.id,
|
||||
id: presentation.uuid,
|
||||
uuid: presentation.uuid,
|
||||
root_path: presentation.root_path,
|
||||
relative_path: presentation.relative_path,
|
||||
@@ -367,7 +371,7 @@ angular.module('app.frontend')
|
||||
|
||||
var items = _.map(user.filteredItems(), function(item){
|
||||
return {
|
||||
id: item.id,
|
||||
id: item.uuid,
|
||||
uuid: item.uuid,
|
||||
content: item.content,
|
||||
tag_id: item.tag_id,
|
||||
@@ -379,7 +383,7 @@ angular.module('app.frontend')
|
||||
|
||||
var tags = _.map(user.tags, function(tag){
|
||||
return {
|
||||
id: tag.id,
|
||||
id: tag.uuid,
|
||||
uuid: tag.uuid,
|
||||
name: tag.name,
|
||||
created_at: tag.created_at,
|
||||
@@ -403,12 +407,12 @@ angular.module('app.frontend')
|
||||
Merging
|
||||
*/
|
||||
this.mergeLocalDataRemotely = function(user, callback) {
|
||||
var request = Restangular.one("users", user.id).one("merge");
|
||||
var request = Restangular.one("users", user.uuid).one("merge");
|
||||
var tags = user.tags;
|
||||
request.items = user.items;
|
||||
request.items.forEach(function(item){
|
||||
if(item.tag_id) {
|
||||
var tag = tags.filter(function(tag){return tag.id == item.tag_id})[0];
|
||||
var tag = tags.filter(function(tag){return tag.uuid == item.tag_id})[0];
|
||||
item.tag_name = tag.name;
|
||||
}
|
||||
})
|
||||
|
||||
@@ -91,7 +91,7 @@ angular
|
||||
|
||||
this.classList.remove('over');
|
||||
|
||||
var binId = this.id;
|
||||
var binId = this.uuid;
|
||||
var note = new Note(JSON.parse(e.dataTransfer.getData('Note')));
|
||||
scope.$apply(function(scope) {
|
||||
var fn = scope.drop();
|
||||
|
||||
@@ -30,12 +30,18 @@ class ItemManager {
|
||||
|
||||
// returns dirty item references that need saving
|
||||
deleteItem(item) {
|
||||
var dirty = [];
|
||||
_.remove(this.items, item);
|
||||
item.content.references.forEach(function(referencedItem){
|
||||
this.removeReferencesBetweenItems(referencedItem, item);
|
||||
}.bind(this))
|
||||
var length = item.content.references.length;
|
||||
// note that references are deleted in this for loop, so you have to be careful how you iterate
|
||||
for(var i = 0; i < length; i++) {
|
||||
var referencedItem = item.content.references[0];
|
||||
// console.log("removing references between items", referencedItem, item);
|
||||
var _dirty = this.removeReferencesBetweenItems(referencedItem, item);
|
||||
dirty = dirty.concat(_dirty);
|
||||
}
|
||||
|
||||
return item.content.references;
|
||||
return dirty;
|
||||
}
|
||||
|
||||
removeReferencesBetweenItems(itemOne, itemTwo) {
|
||||
|
||||
@@ -9,15 +9,14 @@ class ModelManager extends ItemManager {
|
||||
|
||||
set items(items) {
|
||||
super.items = items;
|
||||
this.notes = _.map(this.itemsForContentType("Note"), function(json_obj) {
|
||||
return new Note(json_obj);
|
||||
this.notes = this.itemsForContentType("Note");
|
||||
this.notes.forEach(function(note){
|
||||
note.updateReferencesLocalMapping();
|
||||
})
|
||||
|
||||
this.tags = _.map(this.itemsForContentType("Tag"), function(json_obj) {
|
||||
var tag = new Tag(json_obj);
|
||||
console.log("tag references upon import", tag.content.references);
|
||||
this.tags = this.itemsForContentType("Tag");
|
||||
this.tags.forEach(function(tag){
|
||||
tag.updateReferencesLocalMapping();
|
||||
return tag;
|
||||
})
|
||||
}
|
||||
|
||||
@@ -53,7 +52,6 @@ class ModelManager extends ItemManager {
|
||||
}
|
||||
|
||||
addTagToNote(tag, note) {
|
||||
console.log("adding tag to note", tag, note);
|
||||
var dirty = this.createReferencesBetweenItems(tag, note);
|
||||
this.refreshRelationshipsForTag(tag);
|
||||
this.refreshRelationshipsForNote(note);
|
||||
@@ -78,11 +76,13 @@ class ModelManager extends ItemManager {
|
||||
|
||||
deleteNote(note) {
|
||||
var dirty = this.deleteItem(note);
|
||||
_.remove(this.notes, note);
|
||||
this.addDirtyItems(dirty);
|
||||
}
|
||||
|
||||
deleteTag(tag) {
|
||||
var dirty = this.deleteItem(tag);
|
||||
_.remove(this.tags, tag);
|
||||
this.addDirtyItems(dirty);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user