Skip to content

Commit d2e3434

Browse files
Cadastrar, Listar, Editar, e Excluir Etiquetas/tags
1 parent a989c67 commit d2e3434

File tree

13 files changed

+419
-106
lines changed

13 files changed

+419
-106
lines changed

application/config/autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
|
9090
| $autoload['helper'] = array('url', 'file');
9191
*/
92-
$autoload['helper'] = array('url', 'auth', 'messages', 'labeltask', 'datetime', 'security', 'date', 'upload');
92+
$autoload['helper'] = array('url', 'auth', 'messages', 'labeltask', 'datetime', 'security', 'date', 'upload', 'tag');
9393

9494
/*
9595
| -------------------------------------------------------------------

application/config/routes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
$route['time/membro/adicionar'] = 'teamMember/addmember';
7171
$route['time/membro/remover/(:num)/(:num)'] = 'teamMember/removemember/$1/$2';
7272

73+
$route['etiqueta/inserir'] = 'tag/insert';
74+
$route['etiqueta/editar/(:num)'] = 'tag/edit/$1';
75+
$route['etiqueta/excluir/(:num)'] = 'tag/delete/$1';
76+
$route['etiqueta/atualizar/(:num)'] = 'tag/update/$1';
77+
7378
$route['tarefas'] = 'task';
7479
$route['inserir'] = 'task/insert';
7580
$route['editar/(:num)'] = 'task/edit/$1';

application/controllers/Tag.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
defined('BASEPATH') or exit('Sem Permissão');
3+
4+
class Tag extends CI_Controller{
5+
public function index(){
6+
7+
}
8+
9+
public function insert(){
10+
$user = authorize(1);
11+
12+
$new_tag = new stdClass();
13+
$new_tag->name = $this->input->post('name', true);
14+
$new_tag->color = $this->input->post('color', true);
15+
$new_tag->description = $this->input->post('description', true);
16+
$new_tag->created_in = datetime_current();
17+
$new_tag->user_id = $user->id_user;
18+
19+
$this->load->model('TagModel');
20+
$this->TagModel->insert($new_tag);
21+
22+
$this->session->set_flashdata('success', 'Etiqueta Criada');
23+
redirect('tarefas#tags');
24+
}
25+
26+
public function delete($id){
27+
$user = authorize(1);
28+
29+
$tag = $this->thisIsMyTag($id, $user->id_user);
30+
31+
$this->TagModel->deleteById($id);
32+
33+
$this->session->set_flashdata('success', 'Etiqueta Excluída');
34+
35+
redirect('tarefas#tags');
36+
}
37+
38+
public function edit($id){
39+
$user = authorize(1);
40+
41+
$tag = $this->thisIsMyTag($id, $user->id_user);
42+
43+
$page = [
44+
'page_title' => 'Editar Etiqueta',
45+
'page_content' => 'tag/edit',
46+
'user' => $user,
47+
'tag' => $tag,
48+
];
49+
50+
$this->load->view('public/base', $page);
51+
}
52+
53+
public function update($id){
54+
$user = authorize(1);
55+
56+
$tag = $this->thisIsMyTag($id, $user->id_user);
57+
58+
$tag->name = $this->input->post('name', true);
59+
$tag->description = $this->input->post('description', true);
60+
$tag->color = $this->input->post('color', true);
61+
62+
$this->TagModel->updateById($tag, $id);
63+
64+
$this->session->set_flashdata('success', 'Etiqueta Atualizada');
65+
redirect('tarefas#tags');
66+
}
67+
68+
public function thisIsMyTag($id_tag, $user_id){
69+
$this->load->model('TagModel');
70+
71+
$tag = $this->TagModel->searchByIdAndUser($id_tag, $user_id);
72+
73+
if(!$tag){
74+
$this->session->set_flashdata('error', 'Essa etiqueta não é sua');
75+
redirect('tarefas#tags');
76+
}
77+
78+
return $tag;
79+
}
80+
}

application/controllers/Task.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33

44
class Task extends CI_Controller{
55
public function index(){
6-
$this->load->model('TaskModel');
6+
$this->load->model(array('TaskModel', 'TagModel'));
77

88
$user = authorize(1);
99

1010
//$tasks = $this->TaskModel->searchAll($user->email);
1111
$tasks = false;
1212

13+
$tags = $this->TagModel->searchByUser($user->id_user);
14+
1315
$page = array(
1416
'page_content' => "task/list",
1517
'user' => $user,
1618
'tasks' => $tasks,
17-
'page_title' => 'Dashboard',
19+
'page_title' => 'Minhas Tarefas',
20+
'tasks' => array(),
21+
'tags' => $tags,
1822
);
1923

2024
$this->load->view("public/base", $page);

application/helpers/tag_helper.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
function tag_label_color($label){
4+
$colors = [
5+
'default' => 'Cinza',
6+
'primary' => 'Azul Escuro',
7+
'info' => 'Azul Claro',
8+
'warning' => 'Amarelo',
9+
'danger' => 'Vermelho',
10+
'success' => 'Verde',
11+
];
12+
13+
if(!isset($colors[$label])){
14+
return 'Sem Cor';
15+
}
16+
17+
return $colors[$label];
18+
}

application/models/TagModel.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
defined('BASEPATH') or exit('Sem Permissão');
3+
4+
class TagModel extends CI_Model{
5+
protected $table = 'tb_tag';
6+
7+
public function insert(stdClass $tag){
8+
$this->db->insert($this->table, $tag);
9+
return $this->db->insert_id();
10+
}
11+
12+
public function deleteById($id){
13+
$this->db->where('id_tag', $id);
14+
$this->db->delete($this->table);
15+
16+
return true;
17+
}
18+
19+
public function deleteByUser($user_id){
20+
$this->db->where('user_id', $user_id);
21+
$this->db->delete($this->table);
22+
23+
return true;
24+
}
25+
26+
public function updateById(stdClass $tag, $id){
27+
$this->db->where('id_tag', $id);
28+
$this->db->update($this->table, $tag);
29+
30+
return true;
31+
}
32+
33+
public function searchById($id){
34+
$this->db->where('id_tag', $id);
35+
$this->db->limit(1);
36+
$this->db->from($this->table);
37+
38+
return $this->db->get()->row();
39+
}
40+
41+
public function searchByUser($user_id){
42+
$this->db->where('user_id', $user_id);
43+
$this->db->from($this->table);
44+
45+
return $this->db->get()->result();
46+
}
47+
48+
public function searchByIdAndUser($id, $user_id){
49+
$this->db->where('id_tag', $id);
50+
$this->db->where('user_id', $user_id);
51+
$this->db->limit(1);
52+
$this->db->from($this->table);
53+
54+
return $this->db->get()->row();
55+
}
56+
}

application/views/tag/add.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<form action="<?php echo base_url('etiqueta/inserir'); ?>" method="post">
2+
<div class="row">
3+
<div class="col-lg-6 col-lg-offset-3">
4+
<label for="name">Titulo: </label>
5+
<input type="text" id="name" name="name" placeholder="Nome da Etiqueta" class="form-control" required><br>
6+
7+
<label for="color">Cor: </label>
8+
<select class="form-control" id="color" name="color" required>
9+
<option value="default">Cinza</option>
10+
<option value="success">Verde</option>
11+
<option value="info" >Azul Claro</option>
12+
<option value="primary">Azul Escuro</option>
13+
<option value="danger" >Vermelho</option>
14+
<option value="warning">Amarelo</option>
15+
</select>
16+
<Br>
17+
18+
<label for="description">Descrição: </label>
19+
<textarea name="description" id="description" placeholder="Descrição da Etiqueta" class="form-control" required></textarea>
20+
21+
<br>
22+
<button class="btn btn-block btn-lg btn-primary">ENVIAR</button>
23+
</div>
24+
</div>
25+
</form>

application/views/tag/edit.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<form action="<?php echo base_url('etiqueta/atualizar/'.$tag->id_tag); ?>" method="post">
2+
<div class="row">
3+
<div class="col-lg-6 col-lg-offset-3">
4+
<label for="name">Titulo: </label>
5+
<input type="text" value="<?php echo $tag->name; ?>" id="name" name="name" placeholder="Nome da Etiqueta" class="form-control" required><br>
6+
7+
<label for="color">Cor: </label>
8+
<select class="form-control" id="color" name="color" required>
9+
<option value="<?php echo $tag->color; ?>"><?php echo tag_label_color($tag->color); ?></option>
10+
<option value="default">Cinza</option>
11+
<option value="success">Verde</option>
12+
<option value="info" >Azul Claro</option>
13+
<option value="primary">Azul Escuro</option>
14+
<option value="danger" >Vermelho</option>
15+
<option value="warning">Amarelo</option>
16+
</select>
17+
<Br>
18+
19+
<label for="description">Descrição: </label>
20+
<textarea name="description" id="description" placeholder="Descrição da Etiqueta" class="form-control" required><?php echo $tag->description; ?></textarea>
21+
22+
<br>
23+
<button class="btn btn-block btn-lg btn-primary">ENVIAR</button>
24+
</div>
25+
</div>
26+
</form>

application/views/tag/list.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<script>
2+
$( document ).ready(function (){
3+
$('#table_tags').DataTable();
4+
5+
$('[data-target="#removeTag"]').on("click", function(){
6+
$('#confirmRemoveTag').attr('href','etiqueta/excluir/'+$(this).val());
7+
});
8+
});
9+
</script>
10+
11+
<?php
12+
echo '<table class="table table-hover table-striped " id="table_tags">';
13+
echo '<thead>';
14+
echo '<tr>';
15+
echo '<th>Nome</th>';
16+
echo '<th>Descrição</th>';
17+
echo '<th>Criado em</th>';
18+
echo '<th>Opções</th>';
19+
echo '</tr>';
20+
echo '</thead>';
21+
echo '<tbody>';
22+
foreach($tags as $id=>$tag){
23+
echo '<tr>';
24+
echo '<td><span class="label label-',$tag->color,'">',$tag->name,'</span></td>';
25+
echo '<td>',$tag->description,'</td>';
26+
echo '<td>',$tag->created_in,'</td>';
27+
28+
echo '<td>';
29+
echo '<button data-placement="top" title="Excluir" data-target="#removeTag" value="',$tag->id_tag,'" data-toggle="modal" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-trash"></span></button> ';
30+
echo '<a data-placement="top" title="Editar" href="',base_url('etiqueta/editar/'.$tag->id_tag),'" class="btn btn-sm btn-warning"><span class="glyphicon glyphicon-edit"></span></a> ';
31+
echo '</td>';
32+
echo '</tr>';
33+
}
34+
echo '</tbody>';
35+
echo '</table>';
36+
?>
37+
38+
<!-- Modal Concluir -->
39+
<div class="modal fade" id="removeTag" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
40+
<div class="modal-dialog modal-sm" role="document">
41+
<div class="modal-content">
42+
<div class="modal-header">
43+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
44+
<h4 class="modal-title" id="myModalLabel">Excluir Etiqueta</h4>
45+
</div>
46+
<div class="modal-body">
47+
<div class="alert alert-info">
48+
<strong>Você deseja excluir esta etiqueta?</strong>
49+
</div>
50+
</div>
51+
<div class="modal-footer">
52+
<div class="row">
53+
<div class="col-lg-6">
54+
<a href="" id="confirmRemoveTag" class="btn btn-block btn-lg btn-primary">Sim</a>
55+
</div>
56+
<div class="col-lg-6">
57+
<button type="button" class="btn btn-block btn-lg btn-default" data-dismiss="modal">Não</button>
58+
</div>
59+
</div>
60+
</div>
61+
</div>
62+
</div>
63+
</div>

application/views/task/add.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
<form action="<?php echo base_url('inserir'); ?>" method="post">
2-
<label for="title">Titulo</label>
3-
<input type="text" name="title" placeholder="O que você vai fazer?" class="form-control input-lg" required><br>
2+
<div class="row">
3+
<div class="col-lg-4">
4+
<label for="title">Titulo</label>
5+
<input type="text" name="title" placeholder="O que você vai fazer?" class="form-control" required><br>
6+
</div>
7+
<div class="col-lg-4">
8+
<label for="tag">Etiqueta</label>
9+
<select name="tag" required class="form-control">
10+
<option> -- Selecione -- </option>
11+
<?php
12+
13+
?>
14+
</select>
15+
</div>
16+
17+
<div class="col-lg-4">
18+
<label for="priority">Prioridade</label>
19+
<select name="priority" required class="form-control">
20+
<option>Baixa</option>
21+
<option selected>Normal</option>
22+
<option>Alta</option>
23+
</select>
24+
</div>
25+
</div>
426

527
<label for="desc">Descrição</label>
6-
<input type="text" name="desc" placeholder="Informe os detalhes" class="form-control input-lg" required><br>
28+
<textarea name="desc" placeholder="Informe os detalhes" class="form-control" required></textarea>
729

8-
<label>Prioridade</label>
9-
<select name="priority" required class="form-control input-lg">
10-
<option>Baixa</option>
11-
<option selected>Normal</option>
12-
<option>Alta</option>
13-
</select>
30+
<br><br>
1431

1532
<button class="btn btn-block btn-lg btn-primary">ENVIAR</button>
1633
</form>

0 commit comments

Comments
 (0)