1 class IssuesController < ApplicationController
4 include ActionView::Helpers::DateHelper
6 before_filter :login_required, :only => [ :new, :create, :edit, :update, :destroy, :comment]
11 @issues = Issue.find(:all)
13 respond_to do |format|
14 format.html # index.rhtml
15 format.xml { render :xml => @issues.to_xml }
22 @issue = Issue.find(params[:id])
24 respond_to do |format|
25 format.html { redirect_to nice_permalink_url(@issue) }
26 format.xml { render :xml => @issue.to_xml }
30 # GET /issues/YEAR/MO?/DA?
33 @issues = Issue.find(:all, :conditions => [" created_at BETWEEN ? and ? ", dates["from"], dates["to"] ],
34 :order => :created_at)
35 flash[:message] = "Issues for %s %s from %s" % [ dates["to"], distance_of_time_in_words( dates["requested"], dates["to"] ), dates["format"] ]
36 render :action => "index"
39 # GET /issues/YEAR/MO/DA/PERMALINK
42 # FIXME: this finds the correct issue, but won't do the forward correctly so you can't act on an issue you find
43 # @issues = Issue.find(:all, :joins => 'LEFT JOIN permalinks ON permalinks.issue_id = issues.id', :conditions => [" (issues.created_at BETWEEN ? and ?) and link_name = ? ", dates["from"], dates["to"], params[:permalink] ] )
45 @issues = Issue.find(:all, :include => [ :permalink, :created_by ], :conditions => [" (issues.created_at BETWEEN ? and ?) and link_name = ? ", dates["from"], dates["to"], params[:permalink] ] )
47 # FIXME: we should be smarter here where there is more than one issue with the same date and permalink name
50 respond_to do |format|
51 format.html { render :action => "show" }
52 format.xml { render :xml => @issue.to_xml }
56 # GET /issues/YEAR/MO/DA/PERMALINK/ID
57 def find_by_permalink_id
58 @issue = Issue.find(params[:id])
60 respond_to do |format|
61 format.html { render :action => "show" }
62 format.xml { render :xml => @issue.to_xml }
73 @issue = Issue.find(params[:id])
76 # GET /issues/comment/1
78 @issue = Issue.find(params[:id])
79 redirect_to issue_url(@issue)
85 @issue = Issue.new(params[:issue])
87 respond_to do |format|
89 flash[:notice] = 'Issue was successfully created.'
90 format.html { redirect_to issue_url(@issue) }
91 format.xml { head :created, :location => issue_url(@issue) }
93 format.html { render :action => "new" }
94 format.xml { render :xml => @issue.errors.to_xml }
102 @issue = Issue.find(params[:id])
104 respond_to do |format|
105 if @issue.update_attributes(params[:issue])
106 flash[:notice] = 'Issue was successfully updated.'
107 format.html { redirect_to issue_url(@issue) }
108 format.xml { head :ok }
110 format.html { render :action => "edit" }
111 format.xml { render :xml => @issue.errors.to_xml }
117 # DELETE /issues/1.xml
119 @issue = Issue.find(params[:id])
122 respond_to do |format|
123 format.html { redirect_to issues_url }
124 format.xml { head :ok }
130 # adapted from http://www.therailsway.com/tags/idiomatic%20ruby
132 # here we take in whatever dates we get or use the 1st of the month or year if the date isn't present
133 requested_date = Date.new(params[:year].to_i, (params[:month] || 1).to_i, (params[:day] || 1).to_i)
135 # Date#- subtracts days from a given date, which lets us find
136 # the end of last month.
138 from = requested_date - 1
139 else # correct in the ! params[:month] case as well
140 from = requested_date
143 # Date#>> lets us advance requested date by one month,
144 # giving us the first of the next month.
146 if ! params[:day] # year and month
147 to = requested_date >> 1
148 elsif ! params[:month] # year only
149 to = Date.new(requested_date.year + 1, requested_date.month, requested_date.day)
150 else # year and month and day
151 to = requested_date + 1
154 requested_format = requested_date.to_s(:day)
155 requested_format = requested_date.to_s(:month) if ! params[:day]
156 requested_format = requested_date.to_s(:year) if ! params[:month]
158 return { "to" => to, "from" => from, "requested" => requested_date ,"format" => requested_format }