Skip to content
This repository has been archived by the owner on Jul 30, 2022. It is now read-only.

Commit

Permalink
save issue planning date (Drag & Drop)
Browse files Browse the repository at this point in the history
  • Loading branch information
daqing committed Jun 5, 2011
1 parent 6bb2ff5 commit ab91937
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 43 deletions.
10 changes: 10 additions & 0 deletions app/controllers/issues_controller.rb
Expand Up @@ -154,6 +154,16 @@ def assign_to
format.js
end
end

def planning
@issue = Issue.find(params[:id])
if @issue.update_attributes(:planned_date => Date.parse(params[:date]))
render :json => {:success => true}
else
render :json => {:success => false}
end

end

def search
@result = []
Expand Down
3 changes: 2 additions & 1 deletion app/models/issue.rb
@@ -1,5 +1,5 @@
# == Schema Information
# Schema version: 20110520083521
# Schema version: 20110605071315
#
# Table name: issues
#
Expand All @@ -13,6 +13,7 @@
# user_id :integer
# label :string(255)
# milestone_id :integer
# planned_date :date
#

require 'rmmseg'
Expand Down
3 changes: 1 addition & 2 deletions app/views/users/_my_assigned_issue.html.erb
@@ -1,6 +1,5 @@
<div class="row assigned_issue sortable" id="issue_<%= my_assigned_issue.id %>">
<div class="row assigned_issue draggable" id="issue_<%= my_assigned_issue.id %>" data-id="<%= my_assigned_issue.id %>">
<span class="drag_handle"><%= image_tag 'cursor_drag_arrow.png', :width => 16, :height => 16, :align => :absmiddle %></span>
<%= issue_title_link(my_assigned_issue) %>
<span class="state state-<%= my_assigned_issue.current_state.name.to_s %>"><%= my_assigned_issue.current_state_name %></span>
</div>

68 changes: 33 additions & 35 deletions app/views/users/show.html.erb
Expand Up @@ -22,7 +22,24 @@
</table>
<% if @my_profile %>
<% content_for :on_ready_hook do %>
$.make_sortable('my_assigned_issues', '<%= assigned_issues_sort_path %>');
$(".draggable").draggable();
$("table.calendar td").droppable({
drop: function(event, ui) {
var col = $(this);

var issue_id = ui.draggable.attr('data-id');
var date = col.attr('data-value');

$.post('/issues/' + issue_id + '/planning', {date: date}, function(response) {
if (response['success']) {
col.effect('highlight');
} else {
col.css('backgroundColor', 'red');
}
}, 'json');
},
accept: '.draggable'
});
<% end %>
<% end %>
</div>
Expand All @@ -38,51 +55,32 @@
<% this_month = today.month %>
<% beginning = today.beginning_of_week.yesterday %>
<table border="0" class="calendar" cellspacing="0">
<tr>
<caption><%= t('date.month_names')[this_month] %></caption>
</tr>
<tr>
<% (0..6).each do |i| %>
<th><%= t('date.abbr_day_names')[i] %></th>
<% end %>
</tr>
<% beginning = today.beginning_of_week %>
<% beginning_to_today = (today - beginning).to_i - 1 %>
<% next_day = beginning.next %>
<% 2.times do %>
<tr>
<% if beginning.month < this_month %>
<td class="past_month"><%= beginning.day %></td>
<% else %>
<td><%= beginning.day %></td>
<% end %>
<% next_day = beginning.next %>
<% beginning_to_today.times do %>
<% if next_day.month < this_month %>
<td class="past_month"><%= next_day.day %></td>
<% else %>
<td><%= next_day.day %></td>
<% (0..6).each do %>
<% class_name = [] %>
<% if next_day.month != this_month %>
<% class_name << 'other_month' %>
<% end %>
<% next_day = next_day.next %>
<% end %>
<td class="today"><%= today.day %></td>
<% next_day = today.next %>
<% if beginning_to_today < 5 %>
<% (5 - beginning_to_today).times do %>
<% if next_day.month > this_month %>
<td class="next_month"><%= next_day.day %></td>
<% else %>
<td><%= next_day.day %></td>
<% end %>
<% next_day = next_day.next %>
<% end %>
<% end %>
</tr>
<tr>
<% 7.times do %>
<% if next_day.month > this_month %>
<td class="next_month"><%= next_day.day %></td>
<% else %>
<td><%= next_day.day %></td>
<% if next_day == today %>
<% class_name << 'today' %>
<% end %>
<td class="<%= class_name.join(' ') %>" data-value="<%= next_day.to_s('%Y%M%d') %>">
<%= next_day.day %>
</td>
<% next_day = next_day.next %>
<% end %>
</tr>
<% end %>
</table>
</div>
<div class="spacer"></div>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -32,6 +32,7 @@
member do
post 'change_state'
post 'assign_to'
post 'planning'
end

collection do
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20110605071315_add_planned_date_to_issues.rb
@@ -0,0 +1,9 @@
class AddPlannedDateToIssues < ActiveRecord::Migration
def self.up
add_column :issues, :planned_date, :date
end

def self.down
remove_column :issues, :planned_date
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110604071850) do
ActiveRecord::Schema.define(:version => 20110605071315) do

create_table "activities", :force => true do |t|
t.integer "user_id"
Expand Down Expand Up @@ -63,6 +63,7 @@
t.integer "user_id"
t.string "label"
t.integer "milestone_id"
t.date "planned_date"
end

create_table "milestones", :force => true do |t|
Expand Down
7 changes: 4 additions & 3 deletions public/stylesheets/layout.css
Expand Up @@ -318,6 +318,7 @@ p img {
height: auto;
}
table.calendar { width: 100%; padding: 0;}
table.calendar td { padding: 30px 20px; border: 1px solid #EEE; color: black; text-align: right;}
table.calendar td.past_month, table.calendar td.next_month { color: #999;}
table.calendar td.today { color: green; font-weight: bold;}
table.calendar td { width: 100px; height: 60px;border: 1px solid #EEE; color: black; text-align: right;}
table.calendar td.other_month { color: #999;}
table.calendar td.today { color: green; font-weight: bold;}
.draggable { width: 150px;}
3 changes: 2 additions & 1 deletion test/fixtures/issues.yml
@@ -1,5 +1,5 @@
# == Schema Information
# Schema version: 20110520083521
# Schema version: 20110605071315
#
# Table name: issues
#
Expand All @@ -13,6 +13,7 @@
# user_id :integer
# label :string(255)
# milestone_id :integer
# planned_date :date
#

# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
Expand Down

0 comments on commit ab91937

Please sign in to comment.