presentations
This commit is contained in:
@@ -228,20 +228,20 @@ angular.module('app.frontend')
|
||||
this.editUrlPressed = function() {
|
||||
this.showMenu = false;
|
||||
var url = this.publicUrlForNote(this.note);
|
||||
url = url.replace(this.note.presentation.root_path, "");
|
||||
this.url = {base: url, token : this.note.presentation.root_path};
|
||||
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.relative_path;
|
||||
this.note.presentation.relative_path = this.url.token;
|
||||
var original = this.note.presentation_name;
|
||||
this.note.presentation_name = this.url.token;
|
||||
|
||||
apiController.updatePresentation(this.note, this.note.presentation, function(response){
|
||||
apiController.saveItems([this.note], function(response){
|
||||
if(!response) {
|
||||
this.note.presentation.relative_path = original;
|
||||
this.note.presentation_name = original;
|
||||
this.url.token = original;
|
||||
alert("This URL is not available.");
|
||||
} else {
|
||||
@@ -259,14 +259,14 @@ angular.module('app.frontend')
|
||||
a.click();
|
||||
}
|
||||
|
||||
apiController.shareItem(this.user, this.note, function(note){
|
||||
apiController.shareItem(this.note, function(note){
|
||||
openInNewTab(this.publicUrlForNote(note));
|
||||
}.bind(this))
|
||||
this.showMenu = false;
|
||||
}
|
||||
|
||||
this.unshareNote = function() {
|
||||
apiController.unshareItem(this.user, this.note, function(note){
|
||||
apiController.unshareItem(this.note, function(note){
|
||||
|
||||
})
|
||||
this.showMenu = false;
|
||||
|
||||
@@ -25,7 +25,7 @@ angular.module('app.frontend')
|
||||
}
|
||||
}
|
||||
})
|
||||
.controller('NotesCtrl', function (apiController, $timeout, ngDialog, $rootScope) {
|
||||
.controller('NotesCtrl', function (apiController, $timeout, $rootScope) {
|
||||
|
||||
$rootScope.$on("editorFocused", function(){
|
||||
this.showMenu = false;
|
||||
@@ -81,38 +81,16 @@ angular.module('app.frontend')
|
||||
return;
|
||||
}
|
||||
|
||||
var callback = function(username) {
|
||||
apiController.shareItem(this.user, this.tag, function(response){
|
||||
})
|
||||
}.bind(this);
|
||||
|
||||
if(!this.user.username) {
|
||||
ngDialog.open({
|
||||
template: 'frontend/modals/username.html',
|
||||
controller: 'UsernameModalCtrl',
|
||||
resolve: {
|
||||
user: function() {return this.user}.bind(this),
|
||||
callback: function() {return callback}
|
||||
},
|
||||
className: 'ngdialog-theme-default',
|
||||
disableAnimation: true
|
||||
});
|
||||
} else {
|
||||
callback(this.user.username);
|
||||
}
|
||||
apiController.shareItem(this.tag, function(response){})
|
||||
}
|
||||
|
||||
this.selectedTagUnshare = function() {
|
||||
this.showMenu = false;
|
||||
apiController.unshareItem(this.user, this.tag, function(response){
|
||||
apiController.unshareItem(this.tag, function(response){
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
this.publicUrlForTag = function() {
|
||||
return this.tag.presentation.url;
|
||||
}
|
||||
|
||||
this.selectFirstNote = function(createNew) {
|
||||
var visibleNotes = this.tag.notes.filter(function(note){
|
||||
return note.visible;
|
||||
|
||||
@@ -64,8 +64,13 @@ class Item {
|
||||
// should be overriden to manage local properties
|
||||
}
|
||||
|
||||
referencesAffectedBySharingChange() {
|
||||
// should be overriden to determine which references should be decrypted/encrypted
|
||||
return null;
|
||||
}
|
||||
|
||||
isPublic() {
|
||||
return this.presentation;
|
||||
return this.presentation_name;
|
||||
}
|
||||
|
||||
isEncrypted() {
|
||||
@@ -77,7 +82,7 @@ class Item {
|
||||
}
|
||||
|
||||
presentationURL() {
|
||||
return this.presentation.url;
|
||||
return this.presentation_url;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ class Note extends Item {
|
||||
this.tags = this.referencesMatchingContentType("Tag");
|
||||
}
|
||||
|
||||
referencesAffectedBySharingChange() {
|
||||
return super.referencesAffectedBySharingChange();
|
||||
}
|
||||
|
||||
get hasOnePublicTag() {
|
||||
var hasPublicTag = false;
|
||||
this.tags.forEach(function(tag){
|
||||
|
||||
@@ -20,4 +20,8 @@ class Tag extends Item {
|
||||
super.updateReferencesLocalMapping();
|
||||
this.notes = this.referencesMatchingContentType("Note");
|
||||
}
|
||||
|
||||
referencesAffectedBySharingChange() {
|
||||
return this.referencesMatchingContentType("Note");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,34 +18,6 @@ angular.module('app.frontend')
|
||||
}
|
||||
})
|
||||
|
||||
.state('presentation', {
|
||||
url: '/:root_path',
|
||||
parent: 'base',
|
||||
views: {
|
||||
'content@' : {
|
||||
templateUrl: 'frontend/presentation.html',
|
||||
controller: "PresentationCtrl"
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
presentation: getPresentation
|
||||
}
|
||||
})
|
||||
|
||||
.state('tag', {
|
||||
url: '/:root_path/:secondary_path',
|
||||
parent: 'base',
|
||||
views: {
|
||||
'content@' : {
|
||||
templateUrl: 'frontend/presentation.html',
|
||||
controller: "PresentationCtrl"
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
presentation: getPresentation
|
||||
}
|
||||
})
|
||||
|
||||
// Auth routes
|
||||
.state('auth', {
|
||||
abstract: true,
|
||||
@@ -89,20 +61,6 @@ angular.module('app.frontend')
|
||||
}
|
||||
});
|
||||
|
||||
function getPresentation ($q, $state, $stateParams, Restangular) {
|
||||
var deferred = $q.defer();
|
||||
var restangularQuery = Restangular.one('presentations', 'show_by_path');
|
||||
restangularQuery.get({root_path: $stateParams.root_path, secondary_path: $stateParams.secondary_path})
|
||||
.then(function(response) {
|
||||
deferred.resolve(response);
|
||||
})
|
||||
.catch(function(response) {
|
||||
$state.go('404');
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Default fall back route
|
||||
$urlRouterProvider.otherwise(function($injector, $location){
|
||||
var state = $injector.get('$state');
|
||||
|
||||
@@ -20,11 +20,11 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
|
||||
this.$get = function(Restangular, modelManager) {
|
||||
return new ApiController(Restangular, modelManager);
|
||||
this.$get = function(Restangular, modelManager, ngDialog) {
|
||||
return new ApiController(Restangular, modelManager, ngDialog);
|
||||
}
|
||||
|
||||
function ApiController(Restangular, modelManager) {
|
||||
function ApiController(Restangular, modelManager, ngDialog) {
|
||||
|
||||
this.setUser = function(user) {
|
||||
this.user = user;
|
||||
@@ -65,6 +65,7 @@ angular.module('app.frontend')
|
||||
Restangular.one("users/current").get().then(function(response){
|
||||
var plain = response.plain();
|
||||
var items = plain.items;
|
||||
console.log("retreived items", plain);
|
||||
this.decryptItemsWithLocalKey(items);
|
||||
callback(plain);
|
||||
}.bind(this))
|
||||
@@ -143,9 +144,9 @@ angular.module('app.frontend')
|
||||
*/
|
||||
|
||||
this.setUsername = function(user, username, callback) {
|
||||
var request = Restangular.one("users", user.uuid).one("set_username");
|
||||
var request = Restangular.one("users", user.uuid);
|
||||
request.username = username;
|
||||
request.post().then(function(response){
|
||||
request.patch().then(function(response){
|
||||
callback(response.plain());
|
||||
})
|
||||
}
|
||||
@@ -205,9 +206,6 @@ angular.module('app.frontend')
|
||||
request.post().then(function(response) {
|
||||
var savedItems = response.items;
|
||||
console.log("response items", savedItems);
|
||||
// items.forEach(function(item) {
|
||||
// _.merge(item, _.find(savedItems, {uuid: item.uuid}));
|
||||
// })
|
||||
callback(response);
|
||||
})
|
||||
}
|
||||
@@ -215,7 +213,8 @@ angular.module('app.frontend')
|
||||
this.createRequestParamsForItem = function(item) {
|
||||
var itemCopy = _.cloneDeep(item);
|
||||
|
||||
var params = {uuid: item.uuid, content_type: item.content_type};
|
||||
var params = {uuid: item.uuid, content_type: item.content_type, presentation_name: item.presentation_name};
|
||||
|
||||
itemCopy.content.references = _.map(itemCopy.content.references, function(reference){
|
||||
return {uuid: reference.uuid, content_type: reference.content_type};
|
||||
})
|
||||
@@ -248,55 +247,43 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
this.shareItem = function(item, callback) {
|
||||
console.log("sharing item", item);
|
||||
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){
|
||||
var presentation = response.plain();
|
||||
_.merge(item, {presentation: presentation});
|
||||
callback(item);
|
||||
return;
|
||||
}
|
||||
|
||||
// decrypt references
|
||||
if(item.references.length > 0) {
|
||||
this.saveBatchItems(item.references, function(success){})
|
||||
}
|
||||
})
|
||||
var shareFn = function() {
|
||||
item.presentation_name = "_auto_";
|
||||
var needsUpdate = [item].concat(item.referencesAffectedBySharingChange() || []);
|
||||
this.saveItems(needsUpdate, function(success){})
|
||||
}.bind(this)
|
||||
|
||||
if(!this.user.username) {
|
||||
ngDialog.open({
|
||||
template: 'frontend/modals/username.html',
|
||||
controller: 'UsernameModalCtrl',
|
||||
resolve: {
|
||||
user: function() {return this.user}.bind(this),
|
||||
callback: function() {
|
||||
return shareFn;
|
||||
}
|
||||
},
|
||||
className: 'ngdialog-theme-default',
|
||||
disableAnimation: true
|
||||
});
|
||||
} else {
|
||||
shareFn();
|
||||
}
|
||||
}
|
||||
|
||||
this.unshareItem = function(item, callback) {
|
||||
var request = Restangular.one("users", this.user.uuid).one("items", item.uuid).one("presentations", item.presentation.uuid);
|
||||
request.remove().then(function(response){
|
||||
item.presentation = null;
|
||||
callback(null);
|
||||
|
||||
// encrypt references
|
||||
if(item.references.length > 0) {
|
||||
this.saveBatchItems(item.references, function(success){})
|
||||
}
|
||||
})
|
||||
console.log("unsharing item", item);
|
||||
item.presentation_name = null;
|
||||
var needsUpdate = [item].concat(item.referencesAffectedBySharingChange() || []);
|
||||
this.saveItems(needsUpdate, function(success){})
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Presentations
|
||||
*/
|
||||
|
||||
this.updatePresentation = function(resource, presentation, callback) {
|
||||
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());
|
||||
})
|
||||
.catch(function(error){
|
||||
callback(nil);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Import
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user