Skip to content

Commit d52174f

Browse files
committed
View tutorial finished.
1 parent 719ecbb commit d52174f

6 files changed

Lines changed: 62 additions & 5 deletions

File tree

simpleNodeViews/controllers/tasks.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = function (app) {
2-
var Task = app.models.task
2+
var Task = app.models.task;
33

44
return {
55
index: function (request, response) {
@@ -35,7 +35,24 @@ module.exports = function (app) {
3535
destroy: function (request, response) {
3636
Task.remove(request.params.id);
3737
response.redirect('/');
38+
},
39+
create: function (request, response) {
40+
response.render('createform', {
41+
action: '/',
42+
title: 'Nova Tarefa'
43+
});
44+
},
45+
//Nosso método EDIT
46+
edit: function (request, response) {
47+
var task = Task.find(request.params.id);
48+
49+
response.render('createform', {
50+
task: task,
51+
title: 'Editar',
52+
action: '/task/' + request.params.id,
53+
});
3854
}
55+
3956
}
4057

4158
}

simpleNodeViews/models/task.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,12 @@ function remove(id) {
3333
return
3434
}
3535

36-
module.exports = {all, save, update, remove};
36+
//Nosso método find
37+
function find (id) {
38+
return tasks.data.filter(function (task) {
39+
return task._id == id
40+
})[0];
41+
}
42+
43+
//Adicione ele aqui também
44+
module.exports = {all, save, update, remove, find};

simpleNodeViews/routes/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ module.exports = function (app) {
33
app.post('/', app.controllers.tasks.store);
44
app.post('/task/:id', app.controllers.tasks.update);
55
app.get('/task/:id', app.controllers.tasks.destroy);
6+
app.get('/create', app.controllers.tasks.create);
7+
app.get('/edit/:id', app.controllers.tasks.edit);
68
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<div class="container">
2+
<div class="col-md-6 col-md-offset-3">
3+
<div class="page-header">
4+
<h1>
5+
{{title}} <a class="btn btn-primary pull-right" href="/">Home</span></a>
6+
</h1>
7+
</div><!-- /.page-header -->
8+
<form class="form" action="{{action}}" method="post">
9+
<div class="form-group">
10+
<label>Titulo:</label>
11+
<input class="form-control" type="text" class="form-group" name="title" value="{{task.title}}">
12+
</div>
13+
14+
15+
{{#if task}}
16+
<div class="checkbox">
17+
<label>
18+
<input type="checkbox" value="1" name="status" {{#if task.status}} checked {{/if}}>
19+
<span>Concluído</span>
20+
</label>
21+
</div>
22+
{{/if}}
23+
24+
25+
<button class="btn btn-primary btn-block">
26+
{{#if task}} Salvar {{else}} Criar {{/if}}
27+
</button>
28+
</form>
29+
</div><!-- /.col-sm-4 -->
30+
</div><!-- /.container -->

simpleNodeViews/views/home.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="col-md-6 col-md-offset-3">
33
<div class="page-header">
44
<h1>
5-
Tarefas <a class="btn btn-primary pull-right" href="#">Adicionar tarefa</span></a>
5+
Tarefas <a class="btn btn-primary pull-right" href="/create">Adicionar tarefa</span></a>
66
</h1>
77
</div><!-- /.page-header -->
88

simpleNodeViews/views/partials/tasklist.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<td>Não concluído</td>
99
{{/if}}
1010
<td width="100px">
11-
<a class="btn btn-info" href="#"><span class="fa fa-pencil"></span></a>
12-
<a class="btn btn-danger" href="#"><span class="fa fa-trash"></span></a>
11+
<a class="btn btn-info" href="/edit/{{_id}}"><span class="fa fa-pencil"></span></a>
12+
<a class="btn btn-danger" href="/task/{{_id}}"><span class="fa fa-trash"></span></a>
1313
</td>
1414
</tr>
1515
{{/each}}

0 commit comments

Comments
 (0)