-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from TreinaDev/feature/tarefas
Feature/tarefas
- Loading branch information
Showing
26 changed files
with
629 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
class TasksController < ApplicationController | ||
before_action :authenticate_user!, only: %i[new create show index edit update start finish cancel] | ||
before_action :set_project, only: %i[new create index] | ||
before_action :set_contributors, only: %i[new create edit update] | ||
before_action :set_task, only: %i[show edit update start finish cancel] | ||
before_action :check_user, only: %i[edit update] | ||
|
||
def index | ||
@tasks = @project.tasks | ||
end | ||
|
||
def new | ||
@task = @project.tasks.build | ||
end | ||
|
||
def create | ||
@task = @project.tasks.build(task_params) | ||
@task.author_id = current_user.id | ||
|
||
if @task.save | ||
redirect_to task_path(@task), notice: t('.success') | ||
else | ||
flash.now[:alert] = t('.fail') | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def show; end | ||
|
||
def edit; end | ||
|
||
def update | ||
if @task.update(task_params) | ||
redirect_to task_path(@task), notice: t('.success') | ||
else | ||
flash.now[:alert] = t('.fail') | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def start | ||
@task.in_progress! | ||
redirect_to task_path, notice: t('.success') | ||
end | ||
|
||
def finish | ||
@task.finished! | ||
redirect_to task_path, notice: t('.success') | ||
end | ||
|
||
def cancel | ||
@task.cancelled! | ||
redirect_to task_path, notice: t('.success') | ||
end | ||
|
||
private | ||
|
||
def set_project | ||
@project = Project.find(params[:project_id]) | ||
end | ||
|
||
def set_contributors | ||
# TODO | ||
# Limitar para os colaboradores do projeto | ||
@contributors = User.all | ||
end | ||
|
||
def set_task | ||
@task = Task.find(params[:id]) | ||
end | ||
|
||
def task_params | ||
params.require(:task).permit(:title, :description, :due_date, :assigned_id) | ||
end | ||
|
||
def check_user | ||
redirect_to root_path, alert: t('.fail') \ | ||
unless @task.author == current_user || @task.assigned == current_user || @task.project.user == current_user | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
class Project < ApplicationRecord | ||
belongs_to :user | ||
has_many :user_roles, dependent: :destroy | ||
has_many :tasks, dependent: :destroy | ||
|
||
validates :title, :description, :category, presence: true | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Task < ApplicationRecord | ||
belongs_to :project | ||
belongs_to :author, class_name: 'User' | ||
belongs_to :assigned, class_name: 'User', optional: true | ||
|
||
enum status: { uninitialized: 0, in_progress: 3, finished: 5, expired: 7, cancelled: 9 } | ||
|
||
validates :title, presence: true | ||
|
||
validate :due_date_is_future | ||
|
||
private | ||
|
||
def due_date_is_future | ||
errors.add(:due_date, ' deve ser futuro.') if due_date.present? && due_date < Time.zone.today.to_date | ||
end | ||
end |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<%= form_with(model: [@project, @task]) do |f| %> | ||
<% if @task.errors.any? %> | ||
<div class='text-danger'> | ||
<h3><%= I18n.t('.errors_title') %>:</h3> | ||
<ul> | ||
<% @task.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="mb-3"> | ||
<%= f.label :title, class: 'form-label' %> | ||
<%= f.text_field :title, class: 'form-control' %> | ||
</div> | ||
<div class="mb-3"> | ||
<%= f.label :description, class: 'form-label' %> | ||
<%= f.text_area :description, class: 'form-control' %> | ||
</div> | ||
<div class="mb-3"> | ||
<%= f.label :due_date, class: 'form-label' %> | ||
<%= f.date_field :due_date, value: f.object.try(:strftime,"%d/%m/%Y"), class: 'form-control' %> | ||
</div> | ||
<div class="mb-3"> | ||
<%= f.label :assigned_id, class: 'form-label' %> | ||
<%= f.collection_select :assigned_id, @contributors, :id, :email, :include_blank => true, class: 'form-control' %> | ||
</div> | ||
<div> | ||
<%= f.submit I18n.t('tasks.save'), class: 'btn btn-primary'%> | ||
</div> | ||
<% end %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1><%= I18n.t('tasks.edit_task')%></h1> | ||
|
||
<%= render 'form' %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h1><%= Task.model_name.human.pluralize %></h1> | ||
|
||
<%= link_to I18n.t('tasks.new_task'), new_project_task_path(@project) %> | ||
<br> | ||
<br> | ||
<ul> | ||
<% @tasks.each do |task| %> | ||
<li><h4><%= link_to task.title, task_path(task) %> | ||
<span style="font-size: small;"><%= I18n.l task.due_date if task.due_date %></span></h4></li> | ||
<% end %> | ||
</ul> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1><%= I18n.t('tasks.create_task')%></h1> | ||
|
||
<%= render 'form' %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<h1><%= Task.model_name.human %>: <%= @task.title %></h1> | ||
|
||
<dt><%= Task.human_attribute_name :description %></dt> | ||
<dd><%= @task.description %></dd> | ||
|
||
<dt><%= Task.human_attribute_name :author %></dt> | ||
<dd><%= @task.author.email %></dd> | ||
|
||
<dt><%= Task.human_attribute_name :status %></dt> | ||
<dd><%= I18n.t(@task.status) %></dd> | ||
|
||
<dt><%= Task.human_attribute_name :assigned %></dt> | ||
<% if @task.assigned %> | ||
<dd><%= @task.assigned.email %></dd> | ||
<% else %> | ||
<dd><%= I18n.t('tasks.no_assigned') %></dd> | ||
<% end %> | ||
|
||
<dt><%= Task.human_attribute_name :due_date %></dt> | ||
<% if @task.due_date %> | ||
<dd><%= I18n.l @task.due_date %></dd> | ||
<% else %> | ||
<dd><%= I18n.t('tasks.no_due_date') %></dd> | ||
<% end %> | ||
|
||
<br> | ||
<%= button_to I18n.t('tasks.start_task'), start_task_path(@task), class: 'btn btn-primary' if @task.uninitialized? %> | ||
|
||
<%= button_to I18n.t('tasks.finish_task'), finish_task_path(@task), class: 'btn btn-primary' if @task.in_progress? %> | ||
<br> | ||
|
||
<%= button_to I18n.t('tasks.cancel_task'), cancel_task_path(@task), class: 'btn btn-danger' if @task.uninitialized? || @task.in_progress? %> | ||
<br> | ||
|
||
<%= link_to I18n.t('tasks.edit_task'), edit_task_path(@task) %> | ||
|
||
<%= link_to I18n.t('.back'), project_tasks_path(@task.project) %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pt-BR: | ||
errors_title: Erros | ||
back: Voltar |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
pt-BR: | ||
uninitialized: Não iniciada | ||
in_progress: Em andamento | ||
finished: Finalizada | ||
expired: Expirada | ||
cancelled: Cancelada | ||
activerecord: | ||
models: | ||
task: | ||
one: Tarefa | ||
other: Tarefas | ||
attributes: | ||
task: | ||
title: Título | ||
description: Descrição | ||
due_date: Prazo | ||
project_id: Projeto | ||
author_id: Autor | ||
author: Autor | ||
assigned_id: Responsável | ||
assigned: Responsável | ||
status: Status | ||
tasks: | ||
create: | ||
success: Tarefa criada com sucesso. | ||
fail: Não foi possível criar a tarefa. | ||
update: | ||
success: Tarefa editada com sucesso. | ||
fail: Não foi possível editar a tarefa. | ||
start: | ||
success: Tarefa iniciada. | ||
finish: | ||
success: Tarefa finalizada. | ||
cancel: | ||
success: Tarefa cancelada. | ||
check_user: | ||
fails: 'Você não possui acesso a esta tarefa.' | ||
edit_task: Editar Tarefa | ||
start_task: Iniciar Tarefa | ||
finish_task: Finalizar Tarefa | ||
cancel_task: Cancelar Tarefa | ||
new_task: Nova Tarefa | ||
create_task: Criar Tarefa | ||
no_due_date: Sem prazo | ||
no_assigned: Sem responsável | ||
save: Salvar |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateTasks < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :tasks do |t| | ||
t.string :title, null: false | ||
t.text :description | ||
t.references :project, null: false, foreign_key: true | ||
t.date :due_date | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
6 changes: 6 additions & 0 deletions
6
db/migrate/20240118133253_add_author_and_assigned_to_tasks.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddAuthorAndAssignedToTasks < ActiveRecord::Migration[7.1] | ||
def change | ||
add_reference :tasks, :author, foreign_key: { to_table: :users } | ||
add_reference :tasks, :assigned, foreign_key: { to_table: :users } | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddStatusToTask < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :tasks, :status, :integer, default: 0 | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
ash = FactoryBot.create(:user, email: '[email protected]', cpf: '837.513.746-47') | ||
FactoryBot.create(:profile, user: ash, first_name: 'Ash', last_name: 'Ketchum', | ||
ash.profile.update(first_name: 'Ash', last_name: 'Ketchum', | ||
work_experience: 'Treinador Pokemon', education: 'Escola Pokemon') | ||
|
||
brock = FactoryBot.create(:user, email: '[email protected]', cpf: '000.000.001-91') | ||
FactoryBot.create(:profile, user: brock, first_name: 'Brock', last_name: '', | ||
work_experience: 'Treinador de Pokemon de rocha', education: 'Escola Pokemon') | ||
brock.profile.update(first_name: 'Brock', last_name: 'Harrison', | ||
work_experience: 'Treinador Pokemon de rocha', education: 'Escola Pokemon') | ||
|
||
misty = FactoryBot.create(:user, email: '[email protected]', cpf: '293.912.970-30') | ||
FactoryBot.create(:profile, user: misty, first_name: '', last_name: '', | ||
work_experience: '', education: '') | ||
misty.profile.update(first_name: 'Mysty', last_name: '', | ||
work_experience: 'Treinadora Pokemon de agua', education: 'Escola Pokemon') | ||
|
||
|
||
FactoryBot.create(:project, user: ash) | ||
FactoryBot.create(:project, user: brock, title: 'Líder de Ginásio', description: 'Me tornar líder do estádio de pedra.', category: 'Auto Ajuda') | ||
pokemon_project = FactoryBot.create(:project, user: brock, title: 'Líder de Ginásio', | ||
description: 'Me tornar líder do estádio de pedra.', | ||
category: 'Auto Ajuda') | ||
|
||
FactoryBot.create(:task, project: pokemon_project, title:'Pegar um geodude', | ||
description:'Para completar o meu time de pedra, preciso de um geodude, vamos captura-lo', | ||
assigned: brock, due_date: 2.months.from_now.to_date, author: brock) | ||
|
||
FactoryBot.create(:task, project: pokemon_project, title:'Parar a equipe rocket', | ||
description:'A equipe rocket está aprontando novamente, temos que para-los', | ||
assigned: ash, due_date: Time.zone.tomorrow, author: ash) | ||
|
||
FactoryBot.create(:task, project: pokemon_project, title:'Derrotar um Charmander', | ||
description: 'Lutar contra outro treinador com um Charmander.', | ||
assigned: ash, due_date: 1.week.from_now, author: ash) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FactoryBot.define do | ||
factory :task do | ||
title { 'Bugfix' } | ||
description { 'Fix de um bug' } | ||
project | ||
author { User.last } | ||
assigned { User.last } | ||
due_date { 10.days.from_now.to_date } | ||
end | ||
end |
Oops, something went wrong.