-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,10 @@ angular.module('todomvc', ['ngRoute', 'ngResource']) | |
} | ||
}; | ||
|
||
This comment has been minimized.
Sorry, something went wrong. |
||
var token = (window.location.search.match(/[\?&]token=(.*)[#&]?/) || []).pop() || localStorage.id_token | ||
This comment has been minimized.
Sorry, something went wrong.
sebasjm
Author
|
||
if (!token) window.location = `https://gateway.user.space/sign/${btoa(window.location.origin + window.location.pathname)}` | ||
This comment has been minimized.
Sorry, something went wrong.
sebasjm
Author
|
||
localStorage.id_token = token | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
$routeProvider | ||
.when('/', routeConfig) | ||
.when('/:status', routeConfig) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ angular.module('todomvc') | |
|
||
// Detect if an API backend is present. If so, return the API module, else | ||
// hand off the localStorage adapter | ||
return $http.get('/api') | ||
return $http.get('https://gateway.user.space/main/classes/ToDo', {headers: {'Authorization': `Bearer ${localStorage.id_token}`}}) | ||
.then(function () { | ||
return $injector.get('api'); | ||
}, function () { | ||
|
@@ -27,32 +27,34 @@ angular.module('todomvc') | |
var store = { | ||
todos: [], | ||
|
||
api: $resource('/api/todos/:id', null, | ||
api: $resource('https://gateway.user.space/main/classes/ToDo/:id', null, | ||
This comment has been minimized.
Sorry, something went wrong.
sebasjm
Author
|
||
{ | ||
update: { method:'PUT' } | ||
save: {headers: {'Authorization': `Bearer ${localStorage.id_token}`}, method: 'POST'}, | ||
This comment has been minimized.
Sorry, something went wrong. |
||
query: {headers: {'Authorization': `Bearer ${localStorage.id_token}`}}, | ||
update: {headers: {'Authorization': `Bearer ${localStorage.id_token}`}, method: 'POST', transformRequest : function(data) { | ||
// remove attributes that we dont want to update | ||
return angular.toJson( Object.assign({}, data, {'_method' : 'PUT', createdAt: undefined, updatedAt: undefined, objectId: undefined}) ); | ||
}}, | ||
delete: {headers: {'Authorization': `Bearer ${localStorage.id_token}`}, method: 'DELETE'} | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
), | ||
|
||
clearCompleted: function () { | ||
var originalTodos = store.todos.slice(0); | ||
|
||
var incompleteTodos = store.todos.filter(function (todo) { | ||
if (todo.completed) store.api.delete({id : todo.objectId}) | ||
return !todo.completed; | ||
}); | ||
|
||
angular.copy(incompleteTodos, store.todos); | ||
|
||
return store.api.delete(function () { | ||
}, function error() { | ||
angular.copy(originalTodos, store.todos); | ||
}); | ||
return angular.copy(incompleteTodos, store.todos); | ||
}, | ||
|
||
delete: function (todo) { | ||
var originalTodos = store.todos.slice(0); | ||
|
||
store.todos.splice(store.todos.indexOf(todo), 1); | ||
return store.api.delete({ id: todo.id }, | ||
return store.api.delete({ id: todo.objectId }, | ||
function () { | ||
}, function error() { | ||
angular.copy(originalTodos, store.todos); | ||
|
@@ -61,7 +63,7 @@ angular.module('todomvc') | |
|
||
get: function () { | ||
return store.api.query(function (resp) { | ||
angular.copy(resp, store.todos); | ||
angular.copy(resp.results, store.todos); | ||
}); | ||
}, | ||
|
||
|
@@ -70,7 +72,7 @@ angular.module('todomvc') | |
|
||
return store.api.save(todo, | ||
function success(resp) { | ||
todo.id = resp.id; | ||
todo.objectId = resp.objectId; | ||
store.todos.push(todo); | ||
}, function error() { | ||
angular.copy(originalTodos, store.todos); | ||
|
@@ -79,7 +81,7 @@ angular.module('todomvc') | |
}, | ||
|
||
put: function (todo) { | ||
return store.api.update({ id: todo.id }, todo) | ||
return store.api.update({ id: todo.objectId }, todo) | ||
.$promise; | ||
} | ||
}; | ||
|
Here is how you integrate https://user.space with your open source and single page application. First you need to solve the login part. You can do that by copy-pasting the next three lines at the start of your application. With this you will be sure that the user is logged in.