diff --git a/app.js b/app.js index b01acc6..29c4139 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,4 @@ -var todoApp = angular.module('todoApp', []); +var todoApp = angular.module('todoApp', ['ngRoute']); todoApp.directive('taskListView', function() { diff --git a/controllers/routes.js b/controllers/routes.js new file mode 100644 index 0000000..2220229 --- /dev/null +++ b/controllers/routes.js @@ -0,0 +1,16 @@ +var todoApp = angular.module('todoApp'); + +todoApp.config(function($routeProvider) { + + $routeProvider + + .when('/', { + templateUrl: '/pages/listTasks.html', + controller: 'taskController' + }) + + .when('/createTask', { + templateUrl: '/pages/createTask.html', + controller: 'taskController' + }) +}); \ No newline at end of file diff --git a/controllers/taskControllers.js b/controllers/taskControllers.js index e69de29..914048f 100644 --- a/controllers/taskControllers.js +++ b/controllers/taskControllers.js @@ -0,0 +1,113 @@ +// Module +var todoApp = angular.module('todoApp', ['ngRoute']); + + +// Controllers +todoApp.controller('taskController', ['$scope', '$http', 'dbService', '$window', function($scope, $http, dbService, $window) { + + $scope.default = [ + {'id' : '0', 'name' : 'Not Started'}, + {'id' : '1', 'name' : 'In Progress'}, + {'id' : '2', 'name' : 'Done'} + ]; + + // $scope.default = [0, 1, 2]; + + var getTasks = function() { + dbService.getTasks().then((response) => { + //console.log(response.data); + $scope.tasks = response.data; + + }, (response) => { + $scope.getErrMsg = 'Error: ' + response; + }); + } + + + // Add Task + $scope.addTask = function() { + dbService.createTask($scope.task); + redirectHome(); + } + + + + + // Edit Task + $scope.getTask = function(task_id) { + + dbService.getTask(task_id).then((response) => { + console.log(response); + console.log(response.data); + $scope.task = response.data[0]; + // $scope.$watch('task', function() { + // $scope.task = response.data; + // }); + console.log("Scope: " + $scope); + console.log("Scoperr: " + $scope.task.name + " | " ); + redirectPage('edit', task_id); + + console.log('Entrou'); + + }, (response) => { + $scope.getErrMsg = 'Error: ' + response; + }); + + + } + + + // Delete Task + $scope.deleteTask = function(task_id) { + dbService.deleteTask(task_id); + redirectHome(); + } + + function redirectHome(){ + $window.location.href = '/'; + } + + + function redirectPage(pageName, pageid) { + switch(pageName) { + case 'home': + $window.location.href = '/'; + break; + + case 'add': + $window.location.href = '/createTask'; + break; + + case 'edit': + $window.location.href = '#/editTask/' + pageid; + break; + + default: + $window.location.href = '/'; + } + } + + + getTasks(); +}]); + + +todoApp.config(function($routeProvider) { + + $routeProvider + + .when('/', { + templateUrl: '/pages/listTasks.html', + controller: 'taskController' + }) + + .when('/createTask', { + templateUrl: '/pages/createTask.html', + controller: 'taskController' + }) + + .when('/editTask/:id', { + templateUrl: '/pages/editTask.html', + controller: 'taskController' + }) +}); \ No newline at end of file diff --git a/controllers/taskControllers2.js b/controllers/taskControllers2.js new file mode 100644 index 0000000..3945128 --- /dev/null +++ b/controllers/taskControllers2.js @@ -0,0 +1,129 @@ +// Module +var todoApp = angular.module('todoApp', ['ngRoute']); + + +// Controllers +todoApp.controller('taskController', ['$scope', '$http', 'dbService', '$window', '$routeParams', function($scope, $http, dbService, $window, $routeParams) { + + $scope.default = [ + {'id' : '0', 'name' : 'Not Started'}, + {'id' : '1', 'name' : 'In Progress'}, + {'id' : '2', 'name' : 'Done'} + ]; + + // $scope.default = [0, 1, 2]; + + var getTasks = function() { + + console.log('Parametros ' + $routeParams.id); + + if ($routeParams.id) { + + dbService.getTask($routeParams.id).then((response) => { + $scope.task = response.data[0]; + }, (response) => { + $scope.getErrMsg = 'Error: ' + response; + }); + + } else { + dbService.getTasks().then((response) => { + //console.log(response.data); + $scope.tasks = response.data; + + }, (response) => { + $scope.getErrMsg = 'Error: ' + response; + }); + } + + } + + + // Add Task + $scope.addTask = function() { + dbService.createTask($scope.task); + redirectHome(); + } + + + + + // Edit Task + $scope.getTask = function(task_id) { + + redirectPage('edit', task_id); + /** dbService.getTask(task_id).then((response) => { + //console.log(response); + //console.log(response.data); + //$scope.task = response.data[0]; + // $scope.$watch('task', function() { + // $scope.task = response.data; + // }); + //console.log("Scope: " + $scope); + //console.log("Scoperr: " + $scope.task.name + " | " ); + + $scope.task = response.data[0]; + + console.log('Entrou'); + + }, (response) => { + $scope.getErrMsg = 'Error: ' + response; + });*/ + + + } + + + // Delete Task + $scope.deleteTask = function(task_id) { + dbService.deleteTask(task_id); + redirectHome(); + } + + function redirectHome(){ + $window.location.href = '/'; + } + + + function redirectPage(pageName, pageid) { + switch(pageName) { + case 'home': + $window.location.href = '/'; + break; + + case 'add': + $window.location.href = '/createTask'; + break; + + case 'edit': + $window.location.href = '#/editTask/' + pageid; + break; + + default: + $window.location.href = '/'; + } + } + + + getTasks(); +}]); + + +todoApp.config(function($routeProvider) { + + $routeProvider + + .when('/', { + templateUrl: '/pages/listTasks.html', + controller: 'taskController' + }) + + .when('/createTask', { + templateUrl: '/pages/createTask.html', + controller: 'taskController' + }) + + .when('/editTask/:id', { + templateUrl: '/pages/editTask.html', + controller: 'taskController' + }) +}); \ No newline at end of file diff --git a/directives/directives.js b/directives/directives.js index e69de29..d29a1f6 100644 --- a/directives/directives.js +++ b/directives/directives.js @@ -0,0 +1,31 @@ +var todoApp = angular.module('todoApp'); + + +// todoApp.directive('taskListView', function() { + +// return { +// restrict: 'AECM', +// templateUrl: '/pages/listTasks.html', +// replace: true, +// controller: 'taskController', +// scope: { +// tasks: "=", +// errorMessage: "@" +// }, +// } +// }); + + +// todoApp.directive('editTaskView', function() { + +// return { +// restrict: 'AECM', +// templateUrl: '/pages/editTask.html', +// replace: true, +// controller: 'taskController', +// scope: { +// task: "=", +// errorMessage: "@" +// }, +// } +// }) \ No newline at end of file diff --git a/index.html b/index.html index d687e06..be74b7b 100644 --- a/index.html +++ b/index.html @@ -2,57 +2,41 @@
- - - + + + + + + + + + + + + -| {{task.name}} | -{{task.description}} | -{{task.assignee}} | -Not Started | -In Progress | -Done | -Update | -Delete | - -
| # | +Name | +Description | +Assignee | +Date | +Status | +Actions | +||
|---|---|---|---|---|---|---|---|---|
| {{task.id}} | +{{task.name}} | +{{task.description}} | +{{task.assignee}} | +{{task.date}} | +Not Started |
+ In Progress |
+ Done |
+ + Edit + Delete + | +
| {{task.name}} | -{{task.description}} | -{{task.assignee}} | -{{task.date}} | -{{task.status}} | -