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);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
%a.navbar-brand{"ui-sref" => "home"}
|
||||
.header-name
|
||||
neeto
|
||||
%span.tagline{"ng-if" => "!ctrl.user.id", "ng-cloak" => "true"} secure code box for developers
|
||||
%span.tagline{"ng-if" => "!ctrl.user.uuid", "ng-cloak" => "true"} secure code box for developers
|
||||
|
||||
.menu.navbar-text.navbar-right
|
||||
.items
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"tags" => "tags", "user" => "defaultUser", "update-note-tag" => "tagsUpdateNoteTag"}
|
||||
|
||||
%notes-section{"remove-tag" => "notesRemoveTag", "user" => "defaultUser", "add-new" => "notesAddNew", "selection-made" => "notesSelectionMade",
|
||||
"tag" => "selectedTag", "user-id" => "defaultUser.id", "remove" => "deleteNote"}
|
||||
"tag" => "selectedTag", "user-id" => "defaultUser.uuid", "remove" => "deleteNote"}
|
||||
|
||||
%editor-section{"ng-if" => "selectedNote", "note" => "selectedNote", "remove" => "deleteNote",
|
||||
"user" => "defaultUser", "save" => "saveNote"}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
%input.input{"ng-model" => "ctrl.url.token", "ng-keyup" => "$event.keyCode == 13 && ctrl.saveUrl($event)",
|
||||
"ng-change" => "ctrl.urlChanged()", "ng-focus" => "ctrl.onUrlFocus()",
|
||||
"select-on-click" => "true", "autofocus" => "true"}
|
||||
.note{"ng-repeat" => "note in ctrl.notes | filter: ctrl.filterNotes",
|
||||
.note{"ng-repeat" => "note in ctrl.tag.notes | filter: ctrl.filterNotes",
|
||||
"ng-click" => "ctrl.selectNote(note)", "ng-class" => "{'selected' : ctrl.selectedNote == note}",
|
||||
"ng-attr-draggable" => "{{note.dummy ? undefined : 'true'}}", "note" => "note"}
|
||||
.name
|
||||
|
||||
132
vendor/assets/javascripts/transpiled.js
vendored
132
vendor/assets/javascripts/transpiled.js
vendored
@@ -229,7 +229,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
|
||||
this.demoNotes = [{ title: "Live print a file with tail", content: "tail -f log/production.log" }, { title: "Create SSH tunnel", content: "ssh -i .ssh/key.pem -N -L 3306:example.com:3306 ec2-user@example.com" }, { title: "List of processes running on port", content: "lsof -i:8080" }, { title: "Set ENV from file", content: "export $(cat .envfile | xargs)" }, { title: "Find process by name", content: "ps -ax | grep <application name>" }, { title: "NPM install without sudo", content: "sudo chown -R $(whoami) ~/.npm" }, { title: "Email validation regex", content: "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$" }, { title: "Ruby generate 256 bit key", content: "Digest::SHA256.hexdigest(SecureRandom.random_bytes(32))" }, { title: "Mac add user to user tag", content: "sudo dsedittag -o edit -a USERNAME -t user GROUPNAME" }, { title: "Kill Mac OS System Apache", content: "sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist" }, { title: "Docker run with mount binding and port", content: "docker run -v /home/vagrant/www/app:/var/www/app -p 8080:80 -d kpi/s3" }, { title: "MySQL grant privileges", content: "GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'%’;" }, { 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;
|
||||
@@ -574,7 +574,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
};
|
||||
|
||||
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 () {
|
||||
@@ -607,7 +607,13 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
console.log("Get user response", response);
|
||||
$scope.defaultUser = new User(response);
|
||||
modelManager.items = _.map(response.items, function (json_obj) {
|
||||
return new Item(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();
|
||||
@@ -632,9 +638,6 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
};
|
||||
|
||||
$scope.tagsSelectionMade = function (tag) {
|
||||
if (!tag.notes) {
|
||||
tag.notes = [];
|
||||
}
|
||||
$scope.selectedTag = tag;
|
||||
};
|
||||
|
||||
@@ -652,8 +655,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
*/
|
||||
$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);
|
||||
}
|
||||
@@ -689,8 +691,8 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
modelManager.addNote(note);
|
||||
|
||||
if (!$scope.selectedTag.all) {
|
||||
console.log("add tag");
|
||||
modelManager.addTagToNote($scope.selectedTag, note);
|
||||
$scope.updateAllTag();
|
||||
} else {
|
||||
$scope.selectedTag.notes.unshift(note);
|
||||
}
|
||||
@@ -721,11 +723,13 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
$scope.selectedNote = null;
|
||||
}
|
||||
|
||||
$scope.updateAllTag();
|
||||
|
||||
if (note.dummy) {
|
||||
return;
|
||||
}
|
||||
|
||||
apiController.deleteItem($scope.defaultUser, note, function (success) {});
|
||||
apiController.deleteItem(note, function (success) {});
|
||||
apiController.saveDirtyItems(function () {});
|
||||
};
|
||||
|
||||
@@ -763,7 +767,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
});
|
||||
}
|
||||
};
|
||||
}).controller('NotesCtrl', function (apiController, modelManager, $timeout, ngDialog, $rootScope) {
|
||||
}).controller('NotesCtrl', function (apiController, $timeout, ngDialog, $rootScope) {
|
||||
|
||||
$rootScope.$on("editorFocused", function () {
|
||||
this.showMenu = false;
|
||||
@@ -779,7 +783,11 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
}
|
||||
|
||||
this.noteFilter.text = "";
|
||||
this.setNotes(tag.notes, false);
|
||||
|
||||
tag.notes.forEach(function (note) {
|
||||
note.visible = true;
|
||||
});
|
||||
this.selectFirstNote(false);
|
||||
|
||||
if (isFirstLoad) {
|
||||
$timeout(function () {
|
||||
@@ -805,7 +813,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
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;
|
||||
}
|
||||
@@ -848,17 +856,8 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
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;
|
||||
});
|
||||
|
||||
@@ -875,12 +874,9 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
@@ -967,10 +963,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
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);
|
||||
@@ -999,7 +992,7 @@ angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
}
|
||||
|
||||
this.save()(tag, function (savedTag) {
|
||||
_.merge(tag, savedTag);
|
||||
// _.merge(tag, savedTag);
|
||||
this.selectTag(tag);
|
||||
this.newTag = null;
|
||||
}.bind(this));
|
||||
@@ -1077,11 +1070,13 @@ var Item = function () {
|
||||
value: function addReference(reference) {
|
||||
this.content.references.push(reference);
|
||||
this.content.references = _.uniq(this.content.references);
|
||||
this.updateReferencesLocalMapping();
|
||||
}
|
||||
}, {
|
||||
key: 'removeReference',
|
||||
value: function removeReference(reference) {
|
||||
_.remove(this.content.references, _.find(this.content.references, { uuid: reference.uuid }));
|
||||
this.updateReferencesLocalMapping();
|
||||
}
|
||||
}, {
|
||||
key: 'referencesMatchingContentType',
|
||||
@@ -1092,12 +1087,9 @@ var Item = function () {
|
||||
}
|
||||
}, {
|
||||
key: 'updateReferencesLocalMapping',
|
||||
value: function updateReferencesLocalMapping() {}
|
||||
// should be overriden to manage local properties
|
||||
|
||||
|
||||
/* Returns true if note is shared individually or via tag */
|
||||
|
||||
value: function updateReferencesLocalMapping() {
|
||||
// should be overriden to manage local properties
|
||||
}
|
||||
}, {
|
||||
key: 'isPublic',
|
||||
value: function isPublic() {
|
||||
@@ -1144,6 +1136,17 @@ var Note = function (_Item) {
|
||||
}
|
||||
|
||||
_createClass(Note, [{
|
||||
key: 'updateReferencesLocalMapping',
|
||||
value: function updateReferencesLocalMapping() {
|
||||
_get(Note.prototype.__proto__ || Object.getPrototypeOf(Note.prototype), 'updateReferencesLocalMapping', this).call(this);
|
||||
this.tags = this.referencesMatchingContentType("Tag");
|
||||
}
|
||||
}, {
|
||||
key: 'toJSON',
|
||||
value: function toJSON() {
|
||||
return { uuid: this.uuid };
|
||||
}
|
||||
}, {
|
||||
key: 'isPublic',
|
||||
value: function isPublic() {
|
||||
return _get(Note.prototype.__proto__ || Object.getPrototypeOf(Note.prototype), 'isPublic', this).call(this) || this.hasOnePublicTag;
|
||||
@@ -1203,7 +1206,6 @@ var Tag = function (_Item2) {
|
||||
value: function updateReferencesLocalMapping() {
|
||||
_get(Tag.prototype.__proto__ || Object.getPrototypeOf(Tag.prototype), 'updateReferencesLocalMapping', this).call(this);
|
||||
this.notes = this.referencesMatchingContentType("Note");
|
||||
console.log("notes after maping", this.notes);
|
||||
}
|
||||
}, {
|
||||
key: 'content_type',
|
||||
@@ -1362,7 +1364,7 @@ var User = function User(json_obj) {
|
||||
*/
|
||||
|
||||
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());
|
||||
@@ -1400,6 +1402,10 @@ var User = function User(json_obj) {
|
||||
|
||||
this.saveDirtyItems = function (callback) {
|
||||
var dirtyItems = modelManager.dirtyItems;
|
||||
if (dirtyItems.length == 0) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
this.saveItems(dirtyItems, function (response) {
|
||||
modelManager.clearDirtyItems();
|
||||
@@ -1447,7 +1453,7 @@ var User = function User(json_obj) {
|
||||
};
|
||||
|
||||
this.deleteItem = function (item, callback) {
|
||||
if (!this.user.id) {
|
||||
if (!this.user.uuid) {
|
||||
this.writeUserToLocalStorage(this.user);
|
||||
callback(true);
|
||||
} else {
|
||||
@@ -1458,7 +1464,7 @@ var User = function User(json_obj) {
|
||||
};
|
||||
|
||||
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().then(function (response) {
|
||||
@@ -1492,7 +1498,7 @@ var User = function User(json_obj) {
|
||||
*/
|
||||
|
||||
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());
|
||||
@@ -1561,7 +1567,7 @@ var User = function User(json_obj) {
|
||||
}
|
||||
|
||||
return {
|
||||
id: presentation.id,
|
||||
id: presentation.uuid,
|
||||
uuid: presentation.uuid,
|
||||
root_path: presentation.root_path,
|
||||
relative_path: presentation.relative_path,
|
||||
@@ -1574,7 +1580,7 @@ var User = function User(json_obj) {
|
||||
|
||||
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,
|
||||
@@ -1586,7 +1592,7 @@ var User = function User(json_obj) {
|
||||
|
||||
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,
|
||||
@@ -1607,13 +1613,13 @@ var User = function User(json_obj) {
|
||||
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;
|
||||
return tag.uuid == item.tag_id;
|
||||
})[0];
|
||||
item.tag_name = tag.name;
|
||||
}
|
||||
@@ -1798,12 +1804,18 @@ var ItemManager = function () {
|
||||
}, {
|
||||
key: 'deleteItem',
|
||||
value: function 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;
|
||||
}
|
||||
}, {
|
||||
key: 'removeReferencesBetweenItems',
|
||||
@@ -1897,7 +1909,6 @@ var ModelManager = function (_ItemManager) {
|
||||
}, {
|
||||
key: 'addTagToNote',
|
||||
value: function addTagToNote(tag, note) {
|
||||
console.log("adding tag to note", tag, note);
|
||||
var dirty = this.createReferencesBetweenItems(tag, note);
|
||||
this.refreshRelationshipsForTag(tag);
|
||||
this.refreshRelationshipsForNote(note);
|
||||
@@ -1926,12 +1937,14 @@ var ModelManager = function (_ItemManager) {
|
||||
key: 'deleteNote',
|
||||
value: function deleteNote(note) {
|
||||
var dirty = this.deleteItem(note);
|
||||
_.remove(this.notes, note);
|
||||
this.addDirtyItems(dirty);
|
||||
}
|
||||
}, {
|
||||
key: 'deleteTag',
|
||||
value: function deleteTag(tag) {
|
||||
var dirty = this.deleteItem(tag);
|
||||
_.remove(this.tags, tag);
|
||||
this.addDirtyItems(dirty);
|
||||
}
|
||||
}, {
|
||||
@@ -1943,15 +1956,14 @@ var ModelManager = function (_ItemManager) {
|
||||
key: 'items',
|
||||
set: function set(items) {
|
||||
_set(ModelManager.prototype.__proto__ || Object.getPrototypeOf(ModelManager.prototype), 'items', items, this);
|
||||
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;
|
||||
});
|
||||
},
|
||||
get: function get() {
|
||||
@@ -2069,7 +2081,7 @@ angular.module('app.frontend').directive('droppable', function () {
|
||||
|
||||
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();
|
||||
|
||||
2
vendor/assets/javascripts/transpiled.js.map
vendored
2
vendor/assets/javascripts/transpiled.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user