Class: Rutema::UI::MainController

Inherits:
Ramaze::Controller
  • Object
show all
Includes:
Settings, ViewUtilities
Defined in:
lib/rutemaweb/ramaze_controller.rb

Constant Summary collapse

PAGE_SIZE =

The number of items to show in lists

10

Constants included from ViewUtilities

ViewUtilities::IMG_LEFT, ViewUtilities::IMG_RIGHT, ViewUtilities::IMG_SCE_ERROR, ViewUtilities::IMG_SCE_OK, ViewUtilities::IMG_SCE_WARN, ViewUtilities::IMG_STEP_ERROR, ViewUtilities::IMG_STEP_OK, ViewUtilities::IMG_STEP_WARN, ViewUtilities::TIME_FORMAT

Instance Method Summary collapse

Methods included from Settings

#show_setup_teardown=, #show_setup_teardown?

Methods included from ViewUtilities

#cfg_link, #context_table, #run_link, #run_page_link, #run_summary, #run_url, #scenario_page_link, #scenario_status, #status_icon, #time_formatted

Instance Method Details

#errorObject



223
224
225
# File 'lib/rutemaweb/ramaze_controller.rb', line 223

def error
  @content="There was an error"
end

#indexObject



138
139
140
141
142
143
# File 'lib/rutemaweb/ramaze_controller.rb', line 138

def index
  @title="Rutema"
  @panel_content=panel_runs
  @content_title="Welcome to Rutema"
  @content="<p>This is the rutema web interface.<br/>It allows you to browse the contents of the test results database.</p><p>Currently you can view the results for each separate run, the results for a specific scenario (a complete list of all steps executed in the scenario with standard and error output logs) or the complete execution history of a scenario.</p><p>The panel on the left shows a list of the ten most recent runs.</p>"
end

#run(run_id = "") ⇒ Object

Displays the details of a run

Routes to /runs if no id is provided



165
166
167
168
169
170
171
172
173
174
175
# File 'lib/rutemaweb/ramaze_controller.rb', line 165

def run run_id=""
  @panel_content=nil
  if !run_id.empty?
    @panel_content=panel_runs
    @title="Run #{run_id}"
    @content_title="Summary of run #{run_id}"
    @content=single_run(run_id)
  else
    runs
  end
end

#runs(page = 0) ⇒ Object

Displays a paginated list of all runs



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/rutemaweb/ramaze_controller.rb', line 145

def runs page=0
  @title="All runs"
  @content_title="Runs"
  @content=""
  dt=[]
  total_pages=(Rutema::Model::Run.count/PAGE_SIZE)+1
  page_number=validated_page_number(page,total_pages)

  runs=Rutema::Model::Run.find_on_page(page_number,PAGE_SIZE)
  runs.each do |r| 
    dt<<[status_icon(r.status),run_summary(r),r.config_file]
  end
  @content<< Ruport::Data::Table.new(:data=>dt,:column_names=>["status","description","configuration"]).to_html
  @content<<"<br/>"
  @content<<run_page_link(page_number,total_pages)
  return @content
end

#scenario(scenario_id = "") ⇒ Object

Displays the details of a scenario



210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/rutemaweb/ramaze_controller.rb', line 210

def scenario scenario_id=""
  @panel_content=""
  if !scenario_id.empty?
    if scenario_id.to_i==0
      @content=scenario_by_name(scenario_id)
    else
      @content=scenario_in_a_run(scenario_id.to_i)
    end
  else
    return scenarios
  end
end

#scenarios(page = 0) ⇒ Object

Displays a paginated list of scenarios



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/rutemaweb/ramaze_controller.rb', line 178

def scenarios page=0
  @title="All scenarios"
  @content_title="Scenarios"
  @content=""
  @panel_content=panel_runs
  runs=Hash.new
  #find which runs contain each scenario with the same name
  Ramaze::Log.debug("Getting the runs for each scenario")
  conditions="name NOT LIKE '%_teardown' AND name NOT LIKE '%_setup'"
  Rutema::Model::Scenario.find(:all, :conditions=>conditions).each do |sc|
    nm=sc.name
    runs[nm]||=[]
    runs[nm]<<sc.run.id
  end
  #the size of the hash is also the number of unique scenario names
  total_pages=(runs.size / PAGE_SIZE)+1
  page_number=validated_page_number(page,total_pages)
  Ramaze::Log.debug("Getting scenarios for page #{page_number}")
  scens=Rutema::Model::Scenario.find_on_page(page_number,PAGE_SIZE,conditions)
  #and now build the table data
  dt=Array.new
  scens.each do |sc|
    nm=sc.name
    #sort the run ids
    runs[nm]=runs[nm].sort.reverse[0..4]
    dt<<["<a href=\"/scenario/#{nm}\">#{nm}</a> : ",sc.title,runs[nm].map{|r| " <a href=\"/run/#{r}\">#{r}</a>"}.join(" "),"#{failure_rate(sc.name)}%"]
  end
  @content<<Ruport::Data::Table.new(:data=>dt,:column_names=>["name","title","last 5 runs","failure rate"]).to_html
  @content<<"<br/>"
  @content<<scenario_page_link(page_number,total_pages)
end

#settingsObject



227
228
229
230
231
232
233
234
# File 'lib/rutemaweb/ramaze_controller.rb', line 227

def settings
  if request.post?
  end
  @panel_content=panel_runs()
  @title="Settings"
  @content_title="Settings"
  @content=""
end