remove sharing

This commit is contained in:
Mo Bitar
2017-01-14 12:33:28 -06:00
parent 66298b8799
commit 36ada08a33
17 changed files with 37 additions and 372 deletions

View File

@@ -10,8 +10,7 @@ if(window.crypto.subtle) {
angular.module('app.frontend', [
'ui.router',
'restangular',
'ngDialog'
'restangular'
])
.config(function (RestangularProvider, apiControllerProvider) {

View File

@@ -1,6 +1,5 @@
class BaseCtrl {
constructor($rootScope, modelManager, apiController, dbManager) {
apiController.getCurrentUser(function(){});
dbManager.openDatabase(null, function(){
// new database, delete syncToken so that items can be refetched entirely from server
apiController.clearSyncToken();

View File

@@ -171,7 +171,6 @@ angular.module('app.frontend')
this.onContentFocus = function() {
this.showSampler = false;
$rootScope.$broadcast("editorFocused");
this.editingUrl = false;
}
this.onNameBlur = function() {
@@ -202,64 +201,8 @@ angular.module('app.frontend')
}
}
this.editUrlPressed = function() {
this.showMenu = false;
var url = this.publicUrlForNote(this.note);
url = url.replace(this.note.presentation_name, "");
this.url = {base: url, token : this.note.presentation_name};
this.editingUrl = true;
}
this.saveUrl = function($event) {
$event.target.blur();
var original = this.note.presentation_name;
this.note.presentation_name = this.url.token;
this.note.setDirty(true);
apiController.sync(function(response){
if(response && response.error) {
this.note.presentation_name = original;
this.url.token = original;
alert("This URL is not available.");
} else {
this.editingUrl = false;
}
}.bind(this))
}
this.shareNote = function() {
function openInNewTab(url) {
var a = document.createElement("a");
a.target = "_blank";
a.href = url;
a.click();
}
apiController.shareItem(this.note, function(note){
openInNewTab(this.publicUrlForNote(note));
}.bind(this))
this.showMenu = false;
}
this.unshareNote = function() {
apiController.unshareItem(this.note, function(note){
})
this.showMenu = false;
}
this.publicUrlForNote = function() {
return this.note.presentationURL();
}
this.clickedMenu = function() {
if(this.note.locked) {
alert("This note has been shared without an account, and can therefore not be changed.")
} else {
this.showMenu = !this.showMenu;
}
this.showMenu = !this.showMenu;
}
this.deleteNote = function() {

View File

@@ -67,29 +67,6 @@ angular.module('app.frontend')
this.removeTag()(this.tag);
}
this.selectedTagShare = function() {
this.showMenu = false;
if(!apiController.isUserSignedIn()) {
alert("You must be signed in to share a tag.");
return;
}
if(this.tag.all) {
alert("You cannot share the 'All' tag.");
return;
}
apiController.shareItem(this.tag, function(response){})
}
this.selectedTagUnshare = function() {
this.showMenu = false;
apiController.unshareItem(this.tag, function(response){
})
}
this.selectFirstNote = function(createNew) {
var visibleNotes = this.tag.notes.filter(function(note){
return note.visible;

View File

@@ -1,12 +0,0 @@
angular.module('app.frontend')
.controller('UsernameModalCtrl', function ($scope, apiController, Restangular, callback, $timeout) {
$scope.formData = {};
$scope.saveUsername = function() {
apiController.setUsername($scope.formData.username, function(response){
var username = response.username;
callback(username);
$scope.closeThisDialog();
})
}
});

View File

@@ -115,15 +115,6 @@ class Item {
return [];
}
referencesAffectedBySharingChange() {
// should be overriden to determine which references should be decrypted/encrypted
return [];
}
isPublic() {
return this.presentation_name;
}
isEncrypted() {
return this.encryptionEnabled() && this.content.substring(0, 3) === '001' ? true : false;
}
@@ -131,9 +122,4 @@ class Item {
encryptionEnabled() {
return this.enc_item_key;
}
presentationURL() {
return this.presentation_url;
}
}

View File

@@ -65,19 +65,6 @@ class Note extends Item {
return this.tags;
}
referencesAffectedBySharingChange() {
return super.referencesAffectedBySharingChange();
}
get hasOnePublicTag() {
for (var tag of this.tags) {
if(tag.isPublic()) {
return true
}
}
return false;
}
safeText() {
return this.text || "";
}
@@ -90,14 +77,6 @@ class Note extends Item {
return {uuid: this.uuid}
}
isSharedIndividually() {
return this.presentation_name;
}
isPublic() {
return super.isPublic() || this.hasOnePublicTag;
}
get content_type() {
return "Note";
}

View File

@@ -62,8 +62,4 @@ class Tag extends Item {
allReferencedObjects() {
return this.notes;
}
referencesAffectedBySharingChange() {
return this.notes;
}
}

View File

@@ -20,13 +20,22 @@ angular.module('app.frontend')
}
this.$get = function($rootScope, Restangular, modelManager, ngDialog, dbManager) {
return new ApiController($rootScope, Restangular, modelManager, ngDialog, dbManager);
this.$get = function($rootScope, Restangular, modelManager, dbManager) {
return new ApiController($rootScope, Restangular, modelManager, dbManager);
}
function ApiController($rootScope, Restangular, modelManager, ngDialog, dbManager) {
function ApiController($rootScope, Restangular, modelManager, dbManager) {
this.user = {};
var userData = localStorage.getItem("user");
if(userData) {
this.user = JSON.parse(userData);
} else {
// legacy, check for uuid
var idData = localStorage.getItem("uuid");
if(idData) {
this.user = {uuid: idData};
}
}
this.syncToken = localStorage.getItem("syncToken");
/*
@@ -64,10 +73,6 @@ angular.module('app.frontend')
return localStorage.getItem("jwt");
}
this.userId = function() {
return localStorage.getItem("uuid");
}
this.getAuthParamsForEmail = function(email, callback) {
var request = Restangular.one("auth", "params");
request.get({email: email}).then(function(response){
@@ -79,22 +84,6 @@ angular.module('app.frontend')
})
}
this.getCurrentUser = function(callback) {
if(!localStorage.getItem("jwt")) {
callback(null);
return;
}
Restangular.one("users/current").get().then(function(response){
var user = response.plain();
_.merge(this.user, user);
callback();
}.bind(this))
.catch(function(response){
console.log("Error getting current user", response);
callback(response.data);
})
}
this.login = function(email, password, callback) {
this.getAuthParamsForEmail(email, function(authParams){
if(!authParams) {
@@ -108,7 +97,7 @@ angular.module('app.frontend')
_.merge(request, params);
request.post().then(function(response){
localStorage.setItem("jwt", response.token);
localStorage.setItem("uuid", response.user.uuid);
localStorage.setItem("user", JSON.stringify(response.user));
localStorage.setItem("auth_params", JSON.stringify(authParams));
callback(response);
})
@@ -128,7 +117,7 @@ angular.module('app.frontend')
_.merge(request, params);
request.post().then(function(response){
localStorage.setItem("jwt", response.token);
localStorage.setItem("uuid", response.user.uuid);
localStorage.setItem("user", JSON.stringify(response.user));
localStorage.setItem("auth_params", JSON.stringify(_.omit(authParams, ["pw_nonce"])));
callback(response);
})
@@ -189,20 +178,6 @@ angular.module('app.frontend')
}
/*
User
*/
this.setUsername = function(username, callback) {
var request = Restangular.one("users", this.userId());
request.username = username;
request.patch().then(function(response){
this.user.username = response.username;
callback(response.plain());
}.bind(this))
}
/*
Items
*/
@@ -329,7 +304,7 @@ angular.module('app.frontend')
}
this.createRequestParamsForItem = function(item, additionalFields) {
return this.paramsForItem(item, !item.isPublic(), additionalFields, false);
return this.paramsForItem(item, true, additionalFields, false);
}
this.paramsForExportFile = function(item, encrypted) {
@@ -345,8 +320,7 @@ angular.module('app.frontend')
console.assert(!item.dummy, "Item is dummy, should not have gotten here.", item.dummy)
var params = {uuid: item.uuid, content_type: item.content_type,
presentation_name: item.presentation_name, deleted: item.deleted};
var params = {uuid: item.uuid, content_type: item.content_type, deleted: item.deleted};
if(encrypted) {
this.encryptSingleItem(itemCopy, this.retrieveMk());
@@ -369,47 +343,6 @@ angular.module('app.frontend')
return params;
}
this.shareItem = function(item, callback) {
if(!this.isUserSignedIn()) {
alert("You must be signed in to share.");
return;
}
var shareFn = function() {
item.presentation_name = "_auto_";
var needsUpdate = [item].concat(item.referencesAffectedBySharingChange() || []);
needsUpdate.forEach(function(needingUpdate){
needingUpdate.setDirty(true);
})
this.sync();
}.bind(this)
if(!this.user.username) {
ngDialog.open({
template: 'frontend/modals/username.html',
controller: 'UsernameModalCtrl',
resolve: {
callback: function() {
return shareFn;
}
},
className: 'ngdialog-theme-default',
disableAnimation: true
});
} else {
shareFn();
}
}
this.unshareItem = function(item, callback) {
item.presentation_name = null;
var needsUpdate = [item].concat(item.referencesAffectedBySharingChange() || []);
needsUpdate.forEach(function(needingUpdate){
needingUpdate.setDirty(true);
})
this.sync(null);
}
/*
Import
*/
@@ -491,36 +424,13 @@ angular.module('app.frontend')
return makeTextFile(JSON.stringify(data, null, 2 /* pretty print */));
}
/*
Merging
*/
// this.mergeLocalDataRemotely = function(user, callback) {
// var request = Restangular.one("users", this.userId()).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.uuid == item.tag_id})[0];
// item.tag_name = tag.title;
// }
// })
// request.post().then(function(response){
// callback();
// localStorage.removeItem('user');
// })
// }
this.staticifyObject = function(object) {
return JSON.parse(JSON.stringify(object));
}
this.writeItemsToLocalStorage = function(items, callback) {
var params = items.map(function(item) {
return this.paramsForItem(item, false, ["created_at", "updated_at", "presentation_url", "dirty"], true)
return this.paramsForItem(item, false, ["created_at", "updated_at", "dirty"], true)
}.bind(this));
dbManager.saveItems(params, callback);