Class: StoriesController

Inherits:
ApplicationController show all
Defined in:
lib/branston/app/controllers/stories_controller.rb

Overview

This file is part of Branston.

Branston is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation.

Branston is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Branston.  If not, see <http://www.gnu.org/licenses/>.

Instance Method Summary collapse

Instance Method Details

#createObject

POST /stories POST /stories.xml



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/branston/app/controllers/stories_controller.rb', line 95

def create
  @story = Story.new(params[:story])
  @story.author = current_user
  @story.iteration = @iteration

  respond_to do |format|
    if @story.save
      flash[:notice] = 'Story was successfully created.'
      format.html { redirect_to iteration_stories_path(@iteration) }
      format.xml  { render :xml => @story, :status => :created, :location => @story }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @story.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /stories/1 DELETE /stories/1.xml



139
140
141
142
143
144
145
146
147
# File 'lib/branston/app/controllers/stories_controller.rb', line 139

def destroy
  @story = Story.find_by_slug(params[:id])
  @story.destroy

  respond_to do |format|
    format.html { redirect_to iteration_stories_path(@iteration) }
    format.xml  { head :ok }
  end
end

#editObject

GET /stories/1/edit



89
90
91
# File 'lib/branston/app/controllers/stories_controller.rb', line 89

def edit
  @story = Story.find_by_slug(params[:id])
end

#generate_featureObject



26
27
28
29
30
31
32
33
# File 'lib/branston/app/controllers/stories_controller.rb', line 26

def generate_feature
  @story = Story.find_by_slug(params[:id])
  if @story.nil?
    @story = Story.find(:first, :include => :scenarios, :conditions => ['slug LIKE ?', "%#{id}%"] )
  end
  @story.generate(@story)
  render :text => 'done'
end

#indexObject

GET /stories GET /stories.xml



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/branston/app/controllers/stories_controller.rb', line 37

def index
  @current_stories = Story.for_iteration(@iteration.id).in_progress
  @backlog_stories = Story.for_iteration(@iteration.id).unassigned
  @quality_assurance_stories = Story.for_iteration(@iteration.id).in_quality_assurance
  @completed_stories = Story.for_iteration(@iteration.id).completed
  @total_assigned_points = 0
  Story.for_iteration(@iteration.id).map { |s|
    @total_assigned_points += s.points
  }

  @assignment_difference = @total_assigned_points - @iteration.velocity

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @stories }
  end
end

#newObject

GET /stories/new GET /stories/new.xml



79
80
81
82
83
84
85
86
# File 'lib/branston/app/controllers/stories_controller.rb', line 79

def new
  @story = Story.new(:iteration => @iteration)

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @story }
  end
end

#showObject

GET /stories/1 GET /stories/1.xml



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/branston/app/controllers/stories_controller.rb', line 57

def show
  @story = Story.find_by_slug(params[:id])
  @iteration = @story.iteration unless @story.nil?

  respond_to do |format|
    if @story
      format.html
      format.xml {
        render :xml => (@story.to_xml :include => {
          :scenarios => { :include => [:preconditions, :outcomes] }
        })
      }
      format.js { @active = true }
    else
      format.html { render_optional_error_file 404 }
      format.all  { render :nothing => true, :status => 404 }
    end
  end
end

#updateObject

PUT /stories/“1 PUT /stories/1.xml



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/branston/app/controllers/stories_controller.rb', line 114

def update
  @story = Story.find_by_slug(params[:id])

  if params[:story] and params[:story][:status]
    @story.assign if params[:story][:status] == 'in_progress'
    @story.check_quality if params[:story][:status] == 'quality_assurance'
    @story.back_to_new if params[:story][:status] == 'new'
    @story.finish if params[:story][:status] == 'completed'
  end

  respond_to do |format|
    if @story.update_attributes(params[:story])
      flash[:notice] = 'Story was successfully updated.'
      format.html { redirect_to iteration_story_path(@iteration, @story) }
      format.xml  { head :ok }
      format.js { redirect_to iteration_stories_path(@iteration) }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @story.errors, :status => :unprocessable_entity }
    end
  end
end