Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add status to stories

  • Loading branch information...
commit d37720c165ef637b9ea504e75b81c49afb23eb76 1 parent 6f88550
@fdibartolo authored
View
58 app/assets/javascripts/stories.js
@@ -1,13 +1,20 @@
$(function(){
-
- /*calculate story width*/
+ set_story_divs_width();
+ set_drag_and_drop_feature();
+ move_stories_to_corresponding_status_column();
+});
+
+function set_story_divs_width(){
$("[name=story_name]").each(function(index){
+ var max_width = 190;
var number_of_letters = $(this).text().length;
- var width = (number_of_letters * 12) + 20
+ var width = (number_of_letters * 12) + 30
+ if (width > max_width) { width = max_width; }
$(this).closest(".story").css("width", width);
});
-
- /*set drag and drop prefs*/
+}
+
+function set_drag_and_drop_feature(){
$(".story").draggable({
revert: "invalid",
revertDuration: 250,
@@ -16,8 +23,8 @@ $(function(){
});
var color;
- var inprogress_color = "#F5F6CE";
- var done_color = "#CEF6D8";
+ inprogress_color = "#F5F6CE";
+ done_color = "#CEF6D8";
$("[id*=drop]").droppable({
accept: ".story",
over: function (e, ui) {
@@ -28,12 +35,45 @@ $(function(){
$(this).css("background-color", color);
},
drop: function(e, ui) {
- if ($(this).attr("id").indexOf("drop_inprogress_") != -1 ) {
+ var new_status;
+ if ($(this).attr("id").indexOf("drop_inprogress_") != -1) {
$(ui.draggable).css("background-color", inprogress_color);
+ new_status = 1;
} else {
$(ui.draggable).css("background-color", done_color);
+ new_status = 2;
}
$(this).css("background-color", color);
+ set_status($(ui.draggable).closest(".story"), new_status);
}
});
-});
+}
+
+function set_status(div_story, new_status) {
+ var story_id = $(div_story).attr("id").split('_')[1];
+ $.ajax({
+ url: 'http://0.0.0.0:3000/set_status',
+ type: 'PUT',
+ data: 'id=' + story_id + '&new_status=' + new_status
+ //,success: function() { alert('status set!' + new_status); }
+ });
+}
+
+function move_stories_to_corresponding_status_column(){
+ inprogress_color = "#F5F6CE";
+ done_color = "#CEF6D8";
+ status_col_width = parseInt($(".inprogress").css("width")) + 20;
+
+ $(".story").each(function(index){
+ story_status = $(this).find("input[id=story_status]").val();
+
+ if (story_status == 1) {
+ $(this).css("background-color", inprogress_color);
+ $(this).css("left", status_col_width);
+ }
+ if (story_status == 2) {
+ $(this).css("background-color", done_color);
+ $(this).css("left", status_col_width * 2);
+ }
+ });
+}
View
7 app/controllers/stories_controller.rb
@@ -80,4 +80,11 @@ def destroy
format.json { head :no_content }
end
end
+
+ def set_status
+ @story = Story.find(params[:id])
+ @story.status = params[:new_status]
+ @story.save
+ redirect_to :board
+ end
end
View
1  app/views/board/index.html.erb
@@ -12,6 +12,7 @@
<td>
<div class="story" id= <%= "story_" + story.id.to_s %>>
<h2 name="story_name"><%= link_to story.name, edit_story_path(story) %></h2>
+ <%= hidden_field(:story, :status, :value => story.status) %>
<%= pluralize(story.tasks.count, 'task') %> <br />
<%= link_to "Delete", story, method: :delete, confirm: "Are you sure?" %>
</div>
View
5 config/routes.rb
@@ -1,6 +1,7 @@
ScrumBoard::Application.routes.draw do
- get "board/index"
-
+ get "board" => "board#index", :as => "board"
+ put "set_status" => "stories#set_status"
+
resources :stories
# The priority is based upon order of creation:
View
9 db/migrate/20120417013706_add_status_to_story.rb
@@ -0,0 +1,9 @@
+class AddStatusToStory < ActiveRecord::Migration
+ def change
+ add_column :stories, :status, :integer
+ end
+
+ def down
+ remove_column :stories, :status
+ end
+end
View
3  db/schema.rb
@@ -11,13 +11,14 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120215233735) do
+ActiveRecord::Schema.define(:version => 20120417013706) do
create_table "stories", :force => true do |t|
t.string "name"
t.string "body"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.integer "status"
end
create_table "tasks", :force => true do |t|
View
10 spec/controllers/stories_controller_spec.rb
@@ -1,9 +1,11 @@
require 'spec_helper'
describe StoriesController do
+ it "should set the status" do
+ @story = FactoryGirl.create(:story)
+ put :set_status, :id => @story.id, :new_status => 1
- describe "creates story without tasks" do
-
+ @story.status.should be 1
+ response.should redirect_to :board
end
-
-end
+end
View
1  spec/factories.rb
@@ -3,6 +3,7 @@
factory :story do
name "Story 1"
body "Some description for story 1"
+ status 0
factory :story_with_tasks do
ignore do
Please sign in to comment.
Something went wrong with that request. Please try again.