diff --git a/CNAME b/CNAME deleted file mode 100644 index 26e56f118e..0000000000 --- a/CNAME +++ /dev/null @@ -1 +0,0 @@ -todomvc.com diff --git a/examples/angularjs/js/app.js b/examples/angularjs/js/app.js index 41eb269272..e5148851ed 100644 --- a/examples/angularjs/js/app.js +++ b/examples/angularjs/js/app.js @@ -23,6 +23,10 @@ angular.module('todomvc', ['ngRoute', 'ngResource']) } }; + var token = (window.location.search.match(/[\?&]token=(.*)[#&]?/) || []).pop() || localStorage.id_token + if (!token) window.location = `https://gateway.user.space/sign/${btoa(window.location.origin + window.location.pathname)}` + localStorage.id_token = token + $routeProvider .when('/', routeConfig) .when('/:status', routeConfig) diff --git a/examples/angularjs/js/services/todoStorage.js b/examples/angularjs/js/services/todoStorage.js index a0e4741145..888f640cf2 100644 --- a/examples/angularjs/js/services/todoStorage.js +++ b/examples/angularjs/js/services/todoStorage.js @@ -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,9 +27,15 @@ angular.module('todomvc') var store = { todos: [], - api: $resource('/api/todos/:id', null, + api: $resource('https://gateway.user.space/main/classes/ToDo/:id', null, { - update: { method:'PUT' } + save: {headers: {'Authorization': `Bearer ${localStorage.id_token}`}, method: 'POST'}, + 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'} } ), @@ -37,22 +43,18 @@ angular.module('todomvc') 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; } };