Module: RutemaWeb::UI::ViewUtilities

Included in:
SinatraApp
Defined in:
lib/rutema_web/sinatra.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


66
67
68
# File 'lib/rutema_web/sinatra.rb', line 66

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


70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rutema_web/sinatra.rb', line 70

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

63
64
65
# File 'lib/rutema_web/sinatra.rb', line 63

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

returns the pagination HTML for runs


83
84
85
86
87
88
89
90
91
# File 'lib/rutema_web/sinatra.rb', line 83

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


54
55
56
57
58
59
60
61
# File 'lib/rutema_web/sinatra.rb', line 54

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


50
51
52
# File 'lib/rutema_web/sinatra.rb', line 50

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

returns the pagination HTML for scenarios


93
94
95
96
97
98
99
100
101
# File 'lib/rutema_web/sinatra.rb', line 93

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


104
105
106
107
108
109
# File 'lib/rutema_web/sinatra.rb', line 104

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


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rutema_web/sinatra.rb', line 33

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


46
47
48
# File 'lib/rutema_web/sinatra.rb', line 46

def time_formatted time
  time.strftime(TIME_FORMAT)
end