Module: Rutema::UI::ViewUtilities

Included in:
MainController, StatisticsController
Defined in:
lib/rutemaweb/ramaze_controller.rb

Overview

Helper methods that create HTML snippets

Constant Summary collapse

IMG_SCE_OK =

image filename to use for succesfull scenarios

"/images/run_ok.png"
IMG_SCE_ERROR =

image filename to use for failed scenarios

"/images/run_error.png"
IMG_SCE_WARN =

image filename to use for unexecuted scenarios

"/images/run_warn.png"
IMG_STEP_OK =

image filename to use for succesfull steps

"/images/step_ok.png"
IMG_STEP_ERROR =

image filename to use for failed steps

"/images/step_error.png"
IMG_STEP_WARN =

image filename to use for unexecuted steps

"/images/step_warn.png"
TIME_FORMAT =

Time format to use for the start and stop times

"%d/%m/%Y\n%H:%M:%S"
IMG_LEFT =

The left arrow

"/images/left.png"
IMG_RIGHT =

The right arrow

"images/right.png"

Instance Method Summary collapse

Instance Method Details



64
65
66
# File 'lib/rutemaweb/ramaze_controller.rb', line 64

def cfg_link cfg
  "<a class=\"smallgreytext\" href=\"/statistics/config_report/#{cfg}\">#{cfg}</a>"
end

#context_table(context) ⇒ Object

will render a hash in a table of key||value rows



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rutemaweb/ramaze_controller.rb', line 68

def context_table context
  ret=""
  if context.is_a?(Hash)
    ret="<p>"
    ret<<"Run configured from #{context[:config_file]}<br/>" if context[:config_file]
    ret<<"Started at #{time_formatted(context[:start_time])}<br/>"
    ret<<"Ended at #{time_formatted(context[:end_time])}<br/>"
    ret<<"Total duration #{context[:end_time]-context[:start_time]} seconds</p>"
  end
  return ret
end


61
62
63
# File 'lib/rutemaweb/ramaze_controller.rb', line 61

def run_link r
  "<a class=\"smallgreytext\" href=\"#{run_url(r)}\">Run #{r.id}</a>"
end

returns the pagination HTML for runs



81
82
83
84
85
86
87
88
89
# File 'lib/rutemaweb/ramaze_controller.rb', line 81

def run_page_link page_number,page_total
  ret=""
  unless page_total==1
    ret<<"<a href=\"/runs/#{page_number-1}\">Previous</a>" unless page_number==0
    ret<<" | Page #{page_number+1}"
    ret<<" | <a href=\"/runs/#{page_number+1}\">Next</a>" unless page_number==page_total-1
  end
  return ret
end

#run_summary(r) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/rutemaweb/ramaze_controller.rb', line 52

def run_summary r
  Ramaze::Log.debug("Summary snippet for #{r}") if @logger
  msg="#{run_link(r)}"
  if r.context.is_a?(Hash)
    msg<<" started at #{time_formatted(r.context[:start_time])}"
  end
  return msg
end

#run_url(run) ⇒ Object

Returns the URL of details page for a run



48
49
50
# File 'lib/rutemaweb/ramaze_controller.rb', line 48

def run_url run
  "/run/#{run.id}"
end

returns the pagination HTML for scenarios



91
92
93
94
95
96
97
98
99
# File 'lib/rutemaweb/ramaze_controller.rb', line 91

def scenario_page_link page_number,page_total
  ret=""
  unless page_total==1
    ret<<"<a href=\"/scenarios/#{page_number-1}\">Previous</a>" unless page_number==0
    ret<<" | Page #{page_number+1}"
    ret<<" | <a href=\"/scenarios/#{page_number+1}\">Next</a>" unless page_number==page_total-1
  end
  return ret
end

#scenario_status(r) ⇒ Object

Gives the HTML to use for the status column of a scenario list



102
103
104
105
106
107
# File 'lib/rutemaweb/ramaze_controller.rb', line 102

def scenario_status r
  img_src=IMG_SCE_WARN
  img_src=IMG_SCE_OK if "success"==r.status
  img_src=IMG_SCE_ERROR if "error"==r.status
  "<img src=\"#{img_src}\" align=\"center\"/>"
end

#status_icon(status) ⇒ Object

returns the image tag appropriate for the given status



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rutemaweb/ramaze_controller.rb', line 31

def status_icon status
  return case status
  when :warning ,"not_executed" 
    "<img src=\"#{IMG_STEP_WARN}\" align=\"center\"/>"
  when :success, "success"
    "<img src=\"#{IMG_STEP_OK}\" align=\"center\"/>"
  when :error, "error"
    "<img src=\"#{IMG_STEP_ERROR}\" align=\"center\"/>"
  else
    "<img src=\"#{IMG_STEP_WARN}\" align=\"center\"/>"
  end
end

#time_formatted(time) ⇒ Object

Returns a string with the correct time format for display



44
45
46
# File 'lib/rutemaweb/ramaze_controller.rb', line 44

def time_formatted time
  time.strftime(TIME_FORMAT)
end