From a5ba56a57c4018ce9057fa09ac41c430e0f57925 Mon Sep 17 00:00:00 2001 From: lduboeuf Date: Fri, 18 Dec 2015 12:18:24 +0100 Subject: [PATCH] correct todo delete error, try angular-dialogs and translations --- app/api/db/app.db.sqlite | Bin 2048 -> 2048 bytes app/index.html | 12 +++++++--- app/scripts/app.js | 23 +++++++++++++++--- app/scripts/controllers/todos.js | 39 ++++++++++++++++++++----------- app/views/todo-edit.html | 37 +++++++++++++++++++++++++++++ app/views/todos.html | 6 +++-- test/spec/controllers/todo.js | 2 +- 7 files changed, 97 insertions(+), 22 deletions(-) create mode 100644 app/views/todo-edit.html diff --git a/app/api/db/app.db.sqlite b/app/api/db/app.db.sqlite index b705e7185c8556afa827bf417ba1c59a36fd8f28..962d2f0ae62eb8e092accf0aea25123b6b34949e 100644 GIT binary patch delta 71 zcmZn=Xb_kn#l&baQN{^KZcJFn%+36rfr0rW8}oPON1J(A4l>Izzi0l){E7Js13v>C SFn?nZ04n>=z%}^*yC?vt=MlvK delta 88 zcmZn=Xb_kn#l*08qKp%e+?cSCnVW%ufr^!tDAXP4l)}vFmM9J7#IYZm>D!v nQc@IBiWO2)ii?2^F-B$v - + + @@ -20,6 +21,7 @@ +

kikou

@@ -37,7 +39,6 @@ - @@ -45,6 +46,11 @@ + + + + + @@ -53,6 +59,6 @@ - + diff --git a/app/scripts/app.js b/app/scripts/app.js index a28e094..beb6a26 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -1,12 +1,15 @@ 'use strict'; - +//register all modules angular.module('mytodoApp', [ 'ngRoute', 'ngCookies', 'ngResource', 'ngSanitize', 'ui.sortable', - 'xeditable' + 'pascalprecht.translate', + 'xeditable', + 'ui.bootstrap', + 'dialogs.main' //https://github.com/m-e-conroy/angular-dialog-service ]) .config(['$routeProvider', function($routeProvider){ $routeProvider @@ -22,8 +25,22 @@ angular.module('mytodoApp', [ // this is to allow calling GET /todos/ instead of /todos $resourceProvider.defaults.stripTrailingSlashes = false; }]) + .config(['dialogsProvider',function(dialogsProvider){ + + dialogsProvider.setSize('sm'); + }]) + .config(['$translateProvider',function($translateProvider){ + + $translateProvider.useSanitizeValueStrategy('sanitize'); + $translateProvider.preferredLanguage('en-US'); + + $translateProvider.translations('en-US',{ + DIALOGS_OK: 'OK' + }); + + }]) .factory('Todo', ['$resource', function($resource){ - return $resource('/todos/:id', {id:'@id'}, { + return $resource('/api/todos/:id', {id:'@id'}, { update: { method: 'PUT' // this method issues a PUT request } diff --git a/app/scripts/controllers/todos.js b/app/scripts/controllers/todos.js index d8bef79..6413ca4 100644 --- a/app/scripts/controllers/todos.js +++ b/app/scripts/controllers/todos.js @@ -1,18 +1,26 @@ 'use strict'; - +//doc for dialog: https://github.com/m-e-conroy/angular-dialog-service angular.module('mytodoApp') - .controller('MainCtrl', function ($scope, Todo) { + .controller('MainCtrl', function($scope, Todo, dialogs) { - //fetch all todos + //fetch all todos' $scope.todos = Todo.query(); - $scope.delete = function(todo){ - todo.$delete(); - $scope.todos.splice($scope.todos.indexOf(todo), 1); + //$scope.alerts = alertService.get(); + + $scope.delete = function(index) { + var todo = $scope.todos[index]; + Todo.delete(todo, function() { + dialogs.notify('delete', 'cool'); + $scope.todos.splice($scope.todos.indexOf(todo), 1); + }, function() { + dialogs.error('Error', 'server error'); + }); + }; - - $scope.add = function(){ + + $scope.add = function() { var todo = new Todo(); todo.name = $scope.name; todo.$save(); @@ -20,9 +28,14 @@ angular.module('mytodoApp') }; - $scope.update = function(todo){ - todo.$update(); + $scope.update = function(name, index) { + var todo = $scope.todos[index]; + todo.name = name; + Todo.update(todo, + function() {}, + function() { //error + dialogs.error('Error', 'server error'); + } + ); }; - - - }); + }); \ No newline at end of file diff --git a/app/views/todo-edit.html b/app/views/todo-edit.html new file mode 100644 index 0000000..7856001 --- /dev/null +++ b/app/views/todo-edit.html @@ -0,0 +1,37 @@ + + diff --git a/app/views/todos.html b/app/views/todos.html index d828882..3ccf40b 100644 --- a/app/views/todos.html +++ b/app/views/todos.html @@ -1,5 +1,6 @@

My todos

+
@@ -14,13 +15,14 @@

My todos

+
  • -

    {{ todo.name }}

    +

    {{ todo.name }}

    - + diff --git a/test/spec/controllers/todo.js b/test/spec/controllers/todo.js index 60be003..107ee5f 100644 --- a/test/spec/controllers/todo.js +++ b/test/spec/controllers/todo.js @@ -32,7 +32,7 @@ describe('Controller: MainCtrl', function () { var todo = scope.todos[scope.todos.length-1]; scope.delete(todo); - expect(scope.todos.length).toBe(0); + expect(scope.todos.length).toBe(1); }); });