es6
This commit is contained in:
@@ -1,21 +1,13 @@
|
||||
angular.module('app.frontend')
|
||||
.controller('BaseCtrl', function ($rootScope, $scope, $state, $auth, apiController) {
|
||||
$rootScope.$on('auth:password-change-success', function(ev) {
|
||||
$state.go("home");
|
||||
});
|
||||
|
||||
$rootScope.$on('auth:password-change-error', function(ev, reason) {
|
||||
alert("Error: " + reason);
|
||||
});
|
||||
|
||||
$rootScope.resetPasswordSubmit = function() {
|
||||
var new_keys = Neeto.crypto.generateEncryptionKeysForUser($rootScope.resetData.password, $rootScope.resetData.email);
|
||||
var data = _.clone($rootScope.resetData);
|
||||
data.password = new_keys.pw;
|
||||
data.password_confirmation = new_keys.pw;
|
||||
$auth.updatePassword(data);
|
||||
apiController.setGk(new_keys.gk);
|
||||
}
|
||||
class BaseCtrl {
|
||||
constructor($rootScope, modelManager) {
|
||||
// $rootScope.resetPasswordSubmit = function() {
|
||||
// var new_keys = Neeto.crypto.generateEncryptionKeysForUser($rootScope.resetData.password, $rootScope.resetData.email);
|
||||
// var data = _.clone($rootScope.resetData);
|
||||
// data.password = new_keys.pw;
|
||||
// data.password_confirmation = new_keys.pw;
|
||||
// $auth.updatePassword(data);
|
||||
// apiController.setGk(new_keys.gk);
|
||||
// }
|
||||
|
||||
// var note = new Note();
|
||||
// note.content = {title: "hello", text: "world"};
|
||||
@@ -24,5 +16,7 @@ angular.module('app.frontend')
|
||||
// console.log("note json", JSON.stringify(note));
|
||||
//
|
||||
// console.log("Copy", _.cloneDeep(note));
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
|
||||
|
||||
@@ -259,14 +259,14 @@ angular.module('app.frontend')
|
||||
a.click();
|
||||
}
|
||||
|
||||
apiController.shareNote(this.user, this.note, function(note){
|
||||
apiController.shareItem(this.user, this.note, function(note){
|
||||
openInNewTab(this.publicUrlForNote(note));
|
||||
}.bind(this))
|
||||
this.showMenu = false;
|
||||
}
|
||||
|
||||
this.unshareNote = function() {
|
||||
apiController.unshareNote(this.user, this.note, function(note){
|
||||
apiController.unshareItem(this.user, this.note, function(note){
|
||||
|
||||
})
|
||||
this.showMenu = false;
|
||||
|
||||
@@ -27,7 +27,7 @@ angular.module('app.frontend')
|
||||
}
|
||||
}
|
||||
})
|
||||
.controller('GroupsCtrl', function (apiController) {
|
||||
.controller('GroupsCtrl', function () {
|
||||
|
||||
var initialLoad = true;
|
||||
|
||||
@@ -54,8 +54,8 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
this.newGroup = new Group({notes : []});
|
||||
if(!this.user.id) {
|
||||
this.newGroup.id = Neeto.crypto.generateRandomKey()
|
||||
if(!this.user.uuid) {
|
||||
this.newGroup.uuid = Neeto.crypto.generateRandomKey()
|
||||
}
|
||||
this.selectedGroup = this.newGroup;
|
||||
this.editingGroup = this.newGroup;
|
||||
@@ -97,18 +97,6 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
this.handleDrop = function(e, newGroup, note) {
|
||||
if(this.selectedGroup.all) {
|
||||
// coming from all, remove from original group if applicable
|
||||
if(note.group_id) {
|
||||
var originalGroup = this.groups.filter(function(group){
|
||||
return group.id == note.group_id;
|
||||
})[0];
|
||||
_.remove(originalGroup.notes, note);
|
||||
}
|
||||
} else {
|
||||
_.remove(this.selectedGroup.notes, note);
|
||||
}
|
||||
|
||||
this.updateNoteGroup()(note, newGroup, this.selectedGroup);
|
||||
}.bind(this)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
angular.module('app.frontend')
|
||||
.controller('HomeCtrl', function ($scope, $rootScope, Restangular, $timeout, $state, $sce, $auth, apiController) {
|
||||
.controller('HomeCtrl', function ($scope, $rootScope, $timeout, apiController, modelManager) {
|
||||
$rootScope.bodyClass = "app-body-class";
|
||||
$rootScope.title = "Notes — Neeto, a secure code box for developers";
|
||||
$rootScope.description = "A secure code box for developers to store common commands and useful notes.";
|
||||
@@ -7,7 +7,7 @@ angular.module('app.frontend')
|
||||
var onUserSet = function() {
|
||||
|
||||
$scope.allGroup = new Group({name: "All", all: true});
|
||||
$scope.groups = $scope.defaultUser.groups;
|
||||
$scope.groups = modelManager.groups;
|
||||
|
||||
apiController.verifyEncryptionStatusOfAllItems($scope.defaultUser, function(success){
|
||||
|
||||
@@ -16,7 +16,8 @@ angular.module('app.frontend')
|
||||
|
||||
apiController.getCurrentUser(function(response){
|
||||
if(response && !response.errors) {
|
||||
$scope.defaultUser = new User(response.plain());
|
||||
$scope.defaultUser = new User(response);
|
||||
modelManager.items = response.items;
|
||||
$rootScope.title = "Notes — Neeto";
|
||||
onUserSet();
|
||||
} else {
|
||||
@@ -30,9 +31,7 @@ angular.module('app.frontend')
|
||||
*/
|
||||
|
||||
$scope.updateAllGroup = function() {
|
||||
var allNotes = Note.filterDummyNotes($scope.defaultUser.notes);
|
||||
$scope.defaultUser.notes = allNotes;
|
||||
$scope.allGroup.notes = allNotes;
|
||||
$scope.allGroup.notes = modelManager.filteredNotes;
|
||||
}
|
||||
|
||||
$scope.groupsWillMakeSelection = function(group) {
|
||||
@@ -49,11 +48,11 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
$scope.groupsAddNew = function(group) {
|
||||
$scope.defaultUser.groups.unshift(group);
|
||||
modelManager.addTag(group);
|
||||
}
|
||||
|
||||
$scope.groupsSave = function(group, callback) {
|
||||
apiController.saveItem($scope.defaultUser, group, callback);
|
||||
apiController.saveItems([group], callback);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -62,18 +61,13 @@ angular.module('app.frontend')
|
||||
*/
|
||||
$scope.groupsUpdateNoteGroup = function(noteCopy, newGroup, oldGroup) {
|
||||
|
||||
var originalNote = _.find($scope.defaultUser.notes, {id: noteCopy.id});
|
||||
|
||||
$scope.defaultUser.itemManager.removeReferencesBetweenItems(oldGroup, originalNote);
|
||||
|
||||
var originalNote = _.find($scope.defaultUser.notes, {uuid: noteCopy.uuid});
|
||||
modelManager.removeTagFromNote(oldGroup, originalNote);
|
||||
if(!newGroup.all) {
|
||||
$scope.defaultUser.itemManager.createReferencesBetweenItems(newGroup, originalNote);
|
||||
newGroup.updateReferencesLocalMapping();
|
||||
modelManager.addTagToNote(newGroup, originalNote);
|
||||
}
|
||||
|
||||
apiController.saveBatchItems($scope.defaultUser, [originalNote, newGroup, oldGroup], function(){
|
||||
|
||||
});
|
||||
apiController.saveDirtyItems(function(){});
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -88,7 +82,7 @@ angular.module('app.frontend')
|
||||
// force scope groups to update on sub directives
|
||||
$scope.groups = [];
|
||||
$timeout(function(){
|
||||
$scope.groups = $scope.defaultUser.groups;
|
||||
$scope.groups = modelManager.groups;
|
||||
})
|
||||
});
|
||||
} else {
|
||||
@@ -106,12 +100,10 @@ angular.module('app.frontend')
|
||||
note.id = Neeto.crypto.generateRandomKey();
|
||||
}
|
||||
|
||||
$scope.defaultUser.notes.unshift(note);
|
||||
modelManager.addNote(note);
|
||||
|
||||
if(!$scope.selectedGroup.all) {
|
||||
$scope.selectedGroup.notes.unshift(note);
|
||||
note.group_id = $scope.selectedGroup.id;
|
||||
|
||||
modelManager.addTagToNote($scope.selectedGroup, note);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,11 +112,8 @@ angular.module('app.frontend')
|
||||
*/
|
||||
|
||||
$scope.saveNote = function(note, callback) {
|
||||
apiController.saveNote($scope.defaultUser, note, function(){
|
||||
// add to All notes if it doesnt exist
|
||||
if(!_.find($scope.defaultUser.notes, {id: note.id})) {
|
||||
$scope.defaultUser.notes.unshift(note);
|
||||
}
|
||||
apiController.saveItems([note], function(){
|
||||
modelManager.addNote(note);
|
||||
note.hasChanges = false;
|
||||
|
||||
if(callback) {
|
||||
@@ -134,15 +123,8 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
$scope.deleteNote = function(note) {
|
||||
_.remove($scope.defaultUser.notes, note);
|
||||
if($scope.selectedGroup.all && note.group_id) {
|
||||
var originalGroup = _.find($scope.groups, {id: note.group_id});
|
||||
if(originalGroup) {
|
||||
_.remove(originalGroup.notes, note);
|
||||
}
|
||||
} else {
|
||||
_.remove($scope.selectedGroup.notes, note);
|
||||
}
|
||||
|
||||
modelManager.deleteNote(note);
|
||||
|
||||
if(note == $scope.selectedNote) {
|
||||
$scope.selectedNote = null;
|
||||
@@ -152,8 +134,8 @@ angular.module('app.frontend')
|
||||
return;
|
||||
}
|
||||
|
||||
apiController.deleteNote($scope.defaultUser, note, function(success){
|
||||
})
|
||||
apiController.deleteItem($scope.defaultUser, note, function(success){})
|
||||
apiController.saveDirtyItems(function(){});
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -77,7 +77,7 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
var callback = function(username) {
|
||||
apiController.shareGroup(this.user, this.group, function(response){
|
||||
apiController.shareItem(this.user, this.group, function(response){
|
||||
})
|
||||
}.bind(this);
|
||||
|
||||
@@ -99,7 +99,7 @@ angular.module('app.frontend')
|
||||
|
||||
this.selectedGroupUnshare = function() {
|
||||
this.showMenu = false;
|
||||
apiController.unshareGroup(this.user, this.group, function(response){
|
||||
apiController.unshareItem(this.user, this.group, function(response){
|
||||
|
||||
})
|
||||
}
|
||||
@@ -138,7 +138,7 @@ angular.module('app.frontend')
|
||||
var title = "New Note" + (this.notes ? (" " + (this.notes.length + 1)) : "");
|
||||
this.newNote = new Note({dummy: true});
|
||||
this.newNote.content.title = title;
|
||||
this.newNote.group = this.group;
|
||||
modelManager.addTagToNote(this.group, this.newNote);
|
||||
this.selectNote(this.newNote);
|
||||
this.addNew()(this.newNote);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user