Skip to content

Commit

Permalink
adicionado CRUD de backlogs
Browse files Browse the repository at this point in the history
  • Loading branch information
hgflima committed Nov 28, 2013
1 parent 2eac062 commit ed1d3da
Show file tree
Hide file tree
Showing 10 changed files with 726 additions and 5 deletions.
Empty file.
664 changes: 664 additions & 0 deletions app/assets/javascripts/jquery.tablednd.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/assets/javascripts/projects.js.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# 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/


22 changes: 21 additions & 1 deletion app/controllers/backlogs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class BacklogsController < ApplicationController
# GET /backlogs
# GET /backlogs.json
def index
@backlogs = Backlog.all
@backlogs = Backlog.all.order
end

# GET /backlogs/1
Expand All @@ -27,7 +27,12 @@ def edit
# POST /backlogs
# POST /backlogs.json
def create

@backlog = Backlog.new(backlog_params)

# adiciona o backlog no final da lista
p = Project.find params[:project_id]
@backlog.position = (p.get_last_backlog_position + 1)

respond_to do |format|
if @backlog.save
Expand Down Expand Up @@ -64,6 +69,21 @@ def destroy
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

render :nothing => true, :status => 200

end

private
# Use callbacks to share common setup or constraints between actions.
Expand Down
7 changes: 6 additions & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class Project < ActiveRecord::Base
has_many :backlogs, dependent: :destroy
has_many :backlogs, -> { order "position ASC" }, dependent: :destroy

def get_last_backlog_position
backlogs.maximum(:position)
end

end
4 changes: 2 additions & 2 deletions app/views/backlogs/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%- model_class = Backlog -%>
<table class="table table-striped">
<table id="backlogs" class="table table-striped">
<thead>
<tr>
<th>Backlog</th>
Expand All @@ -9,7 +9,7 @@
</thead>
<tbody>
<% @backlogs.each do |backlog| %>
<tr>
<tr id="<%= backlog.id %>">
<td><%= backlog.title %></td>
<td><%= to_br_date(backlog.created_at) %></td>
<td>
Expand Down
18 changes: 18 additions & 0 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,21 @@
<div id="create-backlog" style="display: none;">
<%= render template: 'backlogs/new' %>
</div>

<%= 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 %>
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

resources :projects do
resources :backlogs
member do
post 'sort-backlogs' => 'backlogs#sort', :as => 'sort_backlogs'
end
end


# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20131125220515_add_position_to_backlogs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddPositionToBacklogs < ActiveRecord::Migration

def change
add_column :backlogs, :position, :integer, :default => 0
end

end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20131123183728) do
ActiveRecord::Schema.define(version: 20131125220515) do

create_table "backlogs", force: true do |t|
t.string "title", limit: 64
t.text "description"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "position", default: 0
end

add_index "backlogs", ["project_id"], name: "index_backlogs_on_project_id", using: :btree
Expand Down

0 comments on commit ed1d3da

Please sign in to comment.