item deletion

This commit is contained in:
Mo Bitar
2016-12-15 20:50:16 -06:00
parent 1722eb299c
commit 36c74ed14d
17 changed files with 148 additions and 121 deletions

View File

@@ -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;

View File

@@ -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(){

View File

@@ -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(){});
}

View File

@@ -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);
}

View File

@@ -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));