Class: Mg::ReportsController

Inherits:
Mg
  • Object
show all
Defined in:
lib/mountain-goat/controllers/mg/reports_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /mg_reports POST /mg_reports.xml



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mountain-goat/controllers/mg/reports_controller.rb', line 50

def create
  @report = Mg::Report.new(params[:report])

  respond_to do |format|
    if @report.save
      format.html { flash[:notice] = 'Your report was successfully created, now add some report items.'; redirect_to(edit_mg_report_url @report) }
      format.xml  { render :xml => @report, :status => :created, :location => @report }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @report.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /mg_reports/1 DELETE /mg_reports/1.xml



108
109
110
111
112
113
114
115
116
# File 'lib/mountain-goat/controllers/mg/reports_controller.rb', line 108

def destroy
  @report = Mg::Report.find(params[:id])
  @report.destroy

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

#editObject

GET /mg_reports/1/edit



44
45
46
# File 'lib/mountain-goat/controllers/mg/reports_controller.rb', line 44

def edit
  @report = Mg::Report.find(params[:id])
end

#hideObject

GET /mg/reports/1/hide GET /mg/reports/1/hide.xml



82
83
84
85
86
87
88
89
90
91
# File 'lib/mountain-goat/controllers/mg/reports_controller.rb', line 82

def hide
  @report = Mg::Report.find(params[:id])
  @report.update_attribute(:deleted_at, Time.new)
  flash[:notice] = "Report #{@report.title} has been hidden."
  
  respond_to do |format|
    format.html { redirect_to mg_reports_url }
    format.xml  { head :ok }
  end
end

#indexObject

GET /mg_reports GET /mg_reports.xml



4
5
6
7
8
9
10
11
12
# File 'lib/mountain-goat/controllers/mg/reports_controller.rb', line 4

def index
  @reports = Mg::Report.find( :all, :conditions => { :deleted_at => nil } )
  @hidden_reports = Mg::Report.find( :all, :conditions => "deleted_at IS NOT NULL" )

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

#newObject

GET /mg_reports/new GET /mg_reports/new.xml



34
35
36
37
38
39
40
41
# File 'lib/mountain-goat/controllers/mg/reports_controller.rb', line 34

def new
  @report = Mg::Report.new

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

#showObject

GET /mg_reports/1 GET /mg_reports/1.xml



16
17
18
19
20
21
22
23
# File 'lib/mountain-goat/controllers/mg/reports_controller.rb', line 16

def show
  @report = Mg::Report.find(params[:id])

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

#show_svgObject



25
26
27
28
29
30
# File 'lib/mountain-goat/controllers/mg/reports_controller.rb', line 25

def show_svg
  @report = Mg::Report.find(params[:id])

  render :text => render_to_string(:partial => "mg/reports/report", :layout => '_pdf', :locals => { :report => @report } )
  response.content_type = 'application/xhtml+xml'
end

#unhideObject

GET /mg/reports/1/unhide GET /mg/reports/1/unhide.xml



95
96
97
98
99
100
101
102
103
104
# File 'lib/mountain-goat/controllers/mg/reports_controller.rb', line 95

def unhide
  @report = Mg::Report.find(params[:id])
  @report.update_attribute(:deleted_at, nil)
  flash[:notice] = "Report #{@report.title} has been restored."
  
  respond_to do |format|
    format.html { redirect_to mg_reports_url }
    format.xml  { head :ok }
  end
end

#updateObject

PUT /mg_reports/1 PUT /mg_reports/1.xml



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/mountain-goat/controllers/mg/reports_controller.rb', line 66

def update
  @report = Mg::Report.find(params[:id])

  respond_to do |format|
    if @report.update_attributes(params[:report])
      format.html { redirect_to(@report, :notice => 'Mg::Report was successfully updated.') }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @report.errors, :status => :unprocessable_entity }
    end
  end
end