Module: Mutx::View

Defined in:
lib/mutx/view/view.rb,
lib/mutx/view/parser.rb,
lib/mutx/view/sections.rb

Defined Under Namespace

Classes: Parser, Sections

Class Method Summary collapse

Class Method Details

.access_report?(result) ⇒ Boolean

Returns:

  • (Boolean)


175
176
177
178
179
180
181
# File 'lib/mutx/view/view.rb', line 175

def self.access_report? result
  if result["status"] =~ /stopped|running/
    #"onclick=\"javascript:refreshAndOpen('/results/log/#{result["_id"]}');\""
  else
    "onclick=\"javascript:refreshAndOpen('/results/report/#{result['_id']}');\"" if result["status"]=='finished' and result["has_report"]
  end
end

.color(value) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/mutx/view/view.rb', line 150

def self.color value
  case value.downcase
    when /running/
      "success"
    when /finished|ready/
      "primary"
    when /(stopped|failed)/
      "danger"
    when /\d+ scenarios? \(\d+ pending\).*\d+ steps?/
      "warning"
    when /\d+ scenarios? \(\d+ passed\).*\d+ steps?/
      "success"
    when /\d+ scenarios? \(\d+ failed\).*\d+ steps?/
      "danger"
    when /(undefined|pending)/
      "warning"
    else
      "default"
  end
end

.formatted_for(seconds = nil) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/mutx/view/view.rb', line 188

def self.formatted_for seconds=nil
  begin
    return "0 seconds" if seconds.nil? or !seconds.is_a? Fixnum
    elapsed   = ""
    hours = minutes = 0
    if seconds > 3600
      hours     = seconds / 3600
      seconds   = seconds % 3600
    end
    if seconds > 60
      minutes   = seconds / 60
      seconds   = seconds % 60
    end
    elapsed  += "#{hours} h " if hours > 0
    elapsed  += " #{minutes} m " if minutes > 0
    elapsed  += "#{seconds} s" if seconds
    "#{elapsed}"
  rescue => e
    "0 s"
  end
end

.from_to(task) ⇒ Object



237
238
239
240
241
242
243
244
# File 'lib/mutx/view/view.rb', line 237

def self.from_to task
  if task["start_time"]!= "" and task["stop_time"]!= ""
    from_to = "from " + task["start_time"] + " to " + task["stop_time"]
  end
  
  "<p class=\"small\">#{from_to}</p>" if from_to
  
end

.icon_for(what) ⇒ String

Returns an gliphy icon by given word It maps words with icon

Parameters:

  • what (String)

    a word

Returns:

  • (String)

    the icon html with color, text and alt attribute



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/mutx/view/view.rb', line 40

def self.icon_for what
  gliphy, color, text, alt = case what.gsub(/(?:\s|-)/,"").downcase
  
  when /attach/
    ["paperclip",nil,nil,"Attachment"]

  when /back/
    ["circle-arrow-left",nil,nil,"Go Back"]

  when /console/
    ["log-in","black",nil,"console output"]
  
  when /cron/
    return "<span class=\"fa fa-clock-o\" aria-hidden=\"true\" alt=\"This test start automatically every minutes\"></span>"
    
  when /edit/
    ["edit","gray",nil,"Edit"]

  when /forward/
    ["circle-arrow-right",nil,nil,"Forward"]      
  
  when /feature/
    ["file",nil,nil,"Features"]
  
  when /info/
    ["info-sign",nil,nil,"Information"]
  
  when /left/
    ["chevron-left",nil,nil,nil]
  
  when /lock/
    return "<span class=\"fa fa-lock\" aria-hidden=\"true\" style=\"color:red\" alt=\"Only admin can run this\"></span>"
    
  when /notification/
    ["envelope",nil,nil,"Notification"]
  
  when /^on$/
    ["off","green",nil,"On"]
  
  when /^off$/
    ["off","red",nil,"Off"]
  
  when /repo/
    ["hdd",nil,nil,"repo"]
  
  when /right/
    ["chevron-right",nil,nil,nil]
  
  when /result/
    ["th-list",nil,nil,"Results"]        
  
  when /search/
    ["search",nil,nil,"Search"]

  when /stop/
    ["stop",nil,nil,"Search"]
  
  when /task/
    ["tasks",nil,nil,"tasks"]
  
  when /test/
    ["th-list",nil,nil,"test"]
   
  when /viewed/
    ["eye-open","blue",nil,"Viewed"]
  
  when /unviewed/
    ["eye-close",nil,nil,"Unviewed"]
  
  when /(?:run|execute|send)/
    ["send",nil,nil,"#{what}"]
  
  when /(?:share|execute)/
    ["share",nil,nil,"#{what}"]
  
  when /(?:cicle|repeat)/
    ["repeat",nil,nil,"#{what}"]
  
  when /(?:book|doc|help)/
    ["book",nil,nil,"#{what}"]

  when /(?:ok|passed|hasvalue)/
    ["ok","green",nil,"#{what}"]
  
  when /(?:empty|failed)/
    ["remove","red",nil,"#{what}"]
  
  when /(?:admin|conf|setup)/
    ["cog",nil,nil,"#{what}"]
  
  else
    ["fire","yellow",nil,"Undefined icon for #{what}"]
  end
  "<span class=\"glyphicon glyphicon-#{gliphy}\" aria-hidden=\"true\" style=\"color:#{color}\" alt=\"#{alt}\"></span>&nbsp;#{text}"
end

.icon_for_result_status(result) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mutx/view/view.rb', line 9

def self.icon_for_result_status result
  return "<i class=\"fa fa-cog fa-spin fa-1x fa-fw margin-bottom\" style=\"color:green\"></i>Running" if ["running","started"].include? result["status"]
  value = result["result_value"] || result["status"]
  gliphy, text, color = case value.gsub(/(?:\s|-|_)/,"").downcase
  when /time/
    ["hourglass","Time out", "red"]
  when /finish/
    ["ok","Finished","gray"]
  when /stopped/
    ["ban-circle","Stopped", "red"]
  when /passed/
    ["thumbs-up","Passed","green"]
  when /failed/
    ["thumbs-down","Failed","red"]
  else 
    ["fire","Unknown","light-gray"]
  end
  "<span class=\"glyphicon glyphicon-#{gliphy}\" aria-hidden=\"true\" style=\"color:#{color}\"></span>&nbsp;<span style=\"color:#{color}\">#{text}</span>"
end

.icon_for_running(result = nil, size = 1) ⇒ Object



29
30
31
32
33
34
# File 'lib/mutx/view/view.rb', line 29

def self.icon_for_running result=nil, size=1
  size = 2 if size == "big"
  size = 1 if size == "small"
  link = " onclick=\"goClean('/results/{{result['_id']}}/log/');\"" if result
  "<i class=\"fa fa-cog fa-spin fa-#{size}x fa-fw margin-bottom\" #{link}></i>"
end

.label_color_for(result) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/mutx/view/view.rb', line 136

def self.label_color_for result
  if result["status"]
    label_color = color result["status"]
    "<a class='label label-#{label_color}' #{access_report?(result)}>#{result['status'].capitalize}</a>"
  else
    "<a href='#' class='label label-default' >No summary</a>"
  end
end

.label_color_for_result_id(result_id) ⇒ Object



183
184
185
186
# File 'lib/mutx/view/view.rb', line 183

def self.label_color_for_result_id result_id
  result = Mutx::API::Result.info result_id
  self.label_color_for result if result
end

.only_label_for(result) ⇒ Object



145
146
147
148
# File 'lib/mutx/view/view.rb', line 145

def self.only_label_for result
  label_color = color result["status"]
  "<div class='label label-#{label_color}'>#{result['status'].capitalize}</div>"
end

.pathObject



5
6
7
# File 'lib/mutx/view/view.rb', line 5

def self.path
  File.expand_path('../', __FILE__)
end

.result_started_at(result_id) ⇒ Object



210
211
212
213
# File 'lib/mutx/view/view.rb', line 210

def self.result_started_at result_id
  result = Mutx::API::Result.info result_id
  self.formatted_for result["started_at"] if result
end

.round_plus(number) ⇒ Object



246
247
248
249
250
251
# File 'lib/mutx/view/view.rb', line 246

def self.round_plus number
  return "10000+" if number > 10000
  return "#{number/100}00+" if number > 1000
  return "#{number/100}00+" if number > 100
  "#{number}"
end

.run_on(task) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/mutx/view/view.rb', line 215

def self.run_on task
  run_on = []
  run_on << 'Sunday'    if task["su"]=="on"
  run_on << 'Monday'    if task["mo"]=="on"
  run_on << 'Tuesday'   if task["tu"]=="on"
  run_on << 'Wednesday' if task["we"]=="on"
  run_on << 'Thursday'  if task["th"]=="on"
  run_on << 'Friday'    if task["fr"]=="on"
  run_on << 'Saturday'  if task["sa"]=="on"
  
  run_on << "everyday" if run_on.empty?
  
  html = ""
  unless run_on.empty?
    html += "<p class=\"small\">on:&nbsp;"
    run_on.each do |day|
      html += "<span class='label label-primary'>#{day}&nbsp;</span>&nbsp;"
    end
  end
  html
end

.unviewedObject



171
172
173
# File 'lib/mutx/view/view.rb', line 171

def self.unviewed
  '<span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>'
end