Skip to content

Commit

Permalink
Atualizando backlogs e sprints para funcionar menos dependente do pro…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
hgflima committed Jan 27, 2014
1 parent ed1d3da commit 1f268fd
Show file tree
Hide file tree
Showing 29 changed files with 359 additions and 44 deletions.
32 changes: 16 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@ GEM
erubis (2.7.0)
execjs (2.0.2)
hike (1.2.3)
i18n (0.6.5)
jbuilder (1.5.2)
i18n (0.6.9)
jbuilder (1.5.3)
activesupport (>= 3.0.0)
multi_json (>= 1.2.0)
jquery-modal-rails (0.0.3)
jquery-modal-rails (0.0.4)
jquery-ui-rails
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
uuidtools
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (4.1.0)
jquery-ui-rails (4.1.1)
railties (>= 3.1.0)
json (1.8.1)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25)
mime-types (1.25.1)
minitest (4.7.5)
multi_json (1.8.2)
mysql2 (0.3.14)
multi_json (1.8.4)
mysql2 (0.3.15)
polyglot (0.3.3)
rack (1.5.2)
rack-test (0.6.2)
Expand All @@ -77,18 +77,18 @@ GEM
activesupport (= 4.0.1)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.1.0)
rdoc (3.12.2)
rake (10.1.1)
rdoc (4.1.1)
json (~> 1.4)
sass (3.2.12)
sass (3.2.14)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
sass (>= 3.1.10)
sprockets-rails (~> 2.0.0)
sdoc (0.3.20)
json (>= 1.1.3)
rdoc (~> 3.10)
sprockets (2.10.0)
sdoc (0.4.0)
json (~> 1.8)
rdoc (~> 4.0, < 5.0)
sprockets (2.10.1)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
Expand All @@ -104,15 +104,15 @@ GEM
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
turbolinks (1.3.1)
turbolinks (2.2.0)
coffee-rails
twitter-bootstrap-rails (2.2.8)
actionpack (>= 3.1)
execjs
rails (>= 3.1)
railties (>= 3.1)
tzinfo (0.3.38)
uglifier (2.3.1)
uglifier (2.4.0)
execjs (>= 0.3.0)
json (>= 1.8.0)
uuidtools (2.1.4)
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/sprints.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sprints.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Sprints controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
19 changes: 6 additions & 13 deletions app/controllers/backlogs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class BacklogsController < ApplicationController
# GET /backlogs
# GET /backlogs.json
def index
@backlogs = Backlog.all.order
@project = Project.find params[:project_id].to_i
@backlogs = @project.backlogs
end

# GET /backlogs/1
Expand Down Expand Up @@ -36,7 +37,7 @@ def create

respond_to do |format|
if @backlog.save
format.html { redirect_to @backlog.project, notice: 'Backlog criado com sucesso.' }
format.html { redirect_to project_backlogs_path(@backlog.project.id), notice: 'Backlog criado com sucesso.' }
format.json { render action: 'show', status: :created, location: @backlog }
else
format.html { render action: 'new' }
Expand All @@ -50,7 +51,7 @@ def create
def update
respond_to do |format|
if @backlog.update(backlog_params)
format.html { redirect_to @backlog.project, notice: 'Backlog atualizado com sucesso.' }
format.html { redirect_to project_backlogs_path(@backlog.project.id), notice: 'Backlog atualizado com sucesso.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
Expand All @@ -65,22 +66,14 @@ def destroy
project = @backlog.project
@backlog.destroy
respond_to do |format|
format.html { redirect_to project, :notice => "Backlog deletado com sucesso" }
format.html { redirect_to project_backlogs_path(project.id), :notice => "Backlog deletado com sucesso" }
format.json { head :no_content }
end
end

def sort

ids = params[:backlogs]
position = 0

ids.each do |id|
b = Backlog.find id
b.update_attribute(:position, position)
position = position + 1
end

Backlog.sort(params[:backlogs])
render :nothing => true, :status => 200

end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def index
# GET /projects/1.json
def show
@backlogs = @project.backlogs
@sprints = @project.sprints
end

# GET /projects/new
Expand Down
81 changes: 81 additions & 0 deletions app/controllers/sprints_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
class SprintsController < ApplicationController
before_action :set_sprint, only: [:show, :edit, :update, :destroy]

# GET /project/:project_id/sprints
# GET /project/:project_id/sprints.json
def index
@project = Project.find params[:project_id].to_i
@sprints = @project.sprints
end

# GET /project/:project_id/sprints/1
# GET /project/:project_id/sprints/1.json
def show
end

# GET /sprints/new
def new
#@sprint = Sprint.new
@project = Project.find params[:project_id].to_i
@sprint = @project.sprints.build
end

# GET /project/:project_id/sprints/1/edit
def edit
@project = Project.find params[:project_id].to_i
@sprint = Sprint.find params[:id].to_i
end

# POST /sprints
# POST /sprints.json
def create

@sprint = Sprint.new(sprint_params)

respond_to do |format|
if @sprint.save
format.html { redirect_to @sprint.project, notice: 'Sprint criado com sucesso.' }
format.json { render action: 'show', status: :created, location: @sprint }
else
format.html { render action: 'new' }
format.json { render json: @sprint.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /sprints/1
# PATCH/PUT /sprints/1.json
def update
respond_to do |format|
if @sprint.update(sprint_params)
format.html { redirect_to project_sprints_path(@sprint.project.id), notice: 'Sprint atualizado com sucesso.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @sprint.errors, status: :unprocessable_entity }
end
end
end

# DELETE /sprints/1
# DELETE /sprints/1.json
def destroy
project = @sprint.project
@sprint.destroy
respond_to do |format|
format.html { redirect_to project_sprints_path(project.id), :notice => "Sprint deletado com sucesso" }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_sprint
@sprint = Sprint.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def sprint_params
params.require(:sprint).permit(:title, :description, :project_id)
end
end
2 changes: 2 additions & 0 deletions app/helpers/sprints_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SprintsHelper
end
14 changes: 14 additions & 0 deletions app/models/backlog.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
class Backlog < ActiveRecord::Base
belongs_to :project

# Ordenar os backlogs na base de dados, seguindo a ordem da lista backlog_ids
def self.sort(backlog_ids)

position = 0

backlog_ids.each do |id|
b = Backlog.find id
b.update_attribute(:position, position)
position = position + 1
end

end

end
1 change: 1 addition & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Project < ActiveRecord::Base
has_many :backlogs, -> { order "position ASC" }, dependent: :destroy
has_many :sprints

def get_last_backlog_position
backlogs.maximum(:position)
Expand Down
3 changes: 3 additions & 0 deletions app/models/sprint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Sprint < ActiveRecord::Base
belongs_to :project
end
29 changes: 29 additions & 0 deletions app/views/backlogs/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<%- model_class = Backlog -%>
<% @active = 'backlogs' %>

<div class="page-header">
<h1><%= @project.name %></h1>
</div>

<%= render :partial => 'projects/navigation' %>

<table id="backlogs" class="table table-striped">
<thead>
<tr>
Expand All @@ -24,3 +32,24 @@
<% end %>
</tbody>
</table>

<%= link_to_modal "Adicionar backlog", new_project_backlog_path(@project.id), :class => "btn btn-primary"%>

<%= javascript_tag do %>

$(document).ready(function() {
$("#backlogs").tableDnD({
onDrop: function(table, row) {
$.ajax({
type: "POST",
url: "<%= sort_backlogs_project_path @project %>",
processData: false,
data: $.tableDnD.serialize(),
success: function(msg) {
}
});
}
});
});

<% end %>
1 change: 1 addition & 0 deletions app/views/backlogs/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%- model_class = Backlog -%>

<div class="page-header">
<h1><%=t '.title', :default => model_class.model_name.human.titleize %></h1>
</div>
Expand Down
5 changes: 5 additions & 0 deletions app/views/projects/_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul class="nav nav-tabs">
<li class="<%= 'active' if current_page?(project_backlogs_path) %>"><%= link_to "Backlogs", project_backlogs_path(@project) %></li>
<li class="<%= 'active' if current_page?(project_sprints_path) %>"><%= link_to "Sprints", project_sprints_path(@project) %></li>
<li><a href="#tab_members" data-toggle="tab">Membros do time</a></li>
</ul>
2 changes: 1 addition & 1 deletion app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<tbody>
<% @projects.each do |project| %>
<tr>
<td><%= link_to project.name, project_path(project) %></td>
<td><%= link_to project.name, project_backlogs_path(project) %></td>
<td><%= to_br_date(project.created_at) %></td>

<td>
Expand Down
14 changes: 6 additions & 8 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
</div>

<div class="tabbable">

<ul class="nav nav-tabs">
<li class="active"><a href="#tab_backlog" data-toggle="tab">Backlogs</a></li>
<li><a href="#tab_sprints" data-toggle="tab">Sprints</a></li>
<li><a href="#tab_members" data-toggle="tab">Membros do time</a></li>
</ul>

<%= render :partial => "projects/navigation" %>

<!-- tabs -->
<div class="tab-content">
Expand All @@ -22,7 +18,8 @@

<!-- sprints -->
<div class="tab-pane" id="tab_sprints">
<p>Sprints</p>
<%= render template: 'sprints/index' %>
<%= link_to_modal "Adicionar sprint", new_project_sprint_path(@project.id), :class => "btn btn-primary"%>
</div>

<!-- members -->
Expand Down Expand Up @@ -55,4 +52,5 @@
}
});
});
<% end %>

<% end %>
18 changes: 18 additions & 0 deletions app/views/sprints/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%= form_for [@project, @sprint] do |f| %>
<div class="control-group">
<%= f.label "Nome", :class => 'control-label' %>
<div class="controls">
<%= f.text_field :title, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<%= f.label "Descricao", :class => 'control-label' %>
<div class="controls">
<%= f.text_area :description, :class => 'text_field' %>
</div>
</div>
<div class="form-actions">
<%= f.hidden_field :project_id %>
<%= f.submit "Salvar", :class => 'btn btn-primary' %>
</div>
<% end %>
5 changes: 5 additions & 0 deletions app/views/sprints/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%- model_class = Sprint -%>
<div class="page-header">
<h1>Editing sprint</h1>
</div>
<%= render 'form' %>
Loading

0 comments on commit 1f268fd

Please sign in to comment.