Last active
December 31, 2015 14:49
-
-
Save Tasemu/8002741 to your computer and use it in GitHub Desktop.
Projects and tasks with angularjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.factory('Project', function($resource) { | |
return $resource( | |
'/api/v1/projects/:id.json', | |
{id: '@id'}, | |
{ | |
update: { | |
method: 'PUT', | |
params: { id: '@id' }, | |
isArray: false | |
} | |
} | |
); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.controller('ProjectCtrl', ['$scope', 'Project', 'Task', '$routeParams', '$location', function($scope, Project, Task, $routeParams, $location) { | |
$scope.updateProjects = function() { | |
if (!$routeParams.id) { | |
Project.query(function(data) { | |
$scope.projects = data; | |
}); | |
} else { | |
$scope.projects = Project.get({id: $routeParams.id}) | |
} | |
}; | |
$scope.deleteProject = function(project) { | |
Project.delete({id: project.id}, function() { | |
$scope.updateProjects({id: project.id}); | |
$location.path('/'); | |
}); | |
}; | |
$scope.deleteTask = function(task) { | |
Task.delete({id: task.id}, function() { | |
$scope.updateProjects({id: task.id}); | |
}); | |
}; | |
$scope.updateProject = function(formData) { | |
$scope.projects.name = formData.name; | |
$scope.projects.description = formData.description; | |
$scope.projects.client = formData.client; | |
$scope.projects.due = formData.due; | |
$scope.projects.$update({id: formData.id}, function() { | |
$location.path('/'); | |
}); | |
}; | |
$scope.saveProject = function(project) { | |
Project.save({}, project, function() { | |
$location.path('/'); | |
}); | |
}; | |
$scope.updateProjects(); | |
$scope.progs = []; | |
for (var i = 0; i > $scope.projects.tasks.length; i++) { | |
progs.push($scope.projects.tasks.array[i].progress); | |
}; | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
id: 1, | |
name: "Project 1", | |
description: "this project", | |
client: "monty", | |
due: "2013-12-15", | |
tasks: [ | |
{ | |
id: 2, | |
name: "Task 2", | |
progress: 22, | |
project_id: 1, | |
created_at: "2013-12-17T03:08:53.849Z", | |
updated_at: "2013-12-17T05:06:31.602Z" | |
}, | |
{ | |
id: 1, | |
name: "Task 1", | |
progress: 75, | |
project_id: 1, | |
created_at: "2013-12-17T03:08:53.845Z", | |
updated_at: "2013-12-17T05:25:50.405Z" | |
} | |
], | |
created_at: "2013-12-17T03:08:53.719Z", | |
updated_at: "2013-12-17T06:57:52.699Z" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment