rorvswild 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,9 @@
1
- <div id="RorVsWild.Local" class="<%= widget_css %>">
2
- <div data-barber="RorVsWild.Local" data-editor-url="<%= editor_url %>">
3
- </div>
1
+ <div id="RorVsWild.Local" class="<%= widget_css %>" >
2
+ <% if @current_request %>
3
+ <div data-barber="RorVsWild.Local" data-editor-url="<%= editor_url %>" data-request-uuid="<%= @current_request["uuid"] %>"></div>
4
+ <% else %>
5
+ <div data-barber="RorVsWild.Local" data-editor-url="<%= editor_url %>"></div>
6
+ <% end %>
4
7
  </div>
5
8
 
6
9
  <script type="x-tmpl-mustache" data-partial="RorVsWild.Local">
@@ -16,12 +19,14 @@
16
19
  </svg>
17
20
  </a>
18
21
 
19
- {{#currentRequest}}
20
- <span class="rorvswild-local-panel__header__title">breakdown</span>
21
- {{/currentRequest}}
22
- {{^currentRequest}}
23
- <span class="rorvswild-local-panel__header__title">history</span>
24
- {{/currentRequest}}
22
+ <nav id="rorvswild-local-nav">
23
+ <ul>
24
+ <li data-events="click->goToRequestIndex" class="tab--requests">Requests</li>
25
+ <li data-events="click->goToJobIndex" class="tab--jobs">Jobs</li>
26
+ <li data-events="click->goToErrors" class="tab--errors">Errors</li>
27
+ </ul>
28
+ </nav>
29
+
25
30
  <span class="rorvswild-local-panel__header__icons">
26
31
  <a href="https://github.com/BaseSecrete/rorvswild" class="rorvswild-local-panel__github" title="Source code">
27
32
  <svg width="16px" height="16px" viewBox="0 0 16 16">
@@ -38,23 +43,10 @@
38
43
  </span>
39
44
  </div>
40
45
  </div>
46
+
41
47
  <div class="rorvswild-local-panel__content">
42
48
  <div class="rorvswild-local-panel__width-limiter">
43
- {{#currentRequest}}
44
- <div data-events="click->goToHistory" class="rorvswild-local-panel__back-button" title="Go to history">
45
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
46
- <line x1="20" y1="12" x2="4" y2="12"></line>
47
- <polyline points="10 18 4 12 10 6"></polyline>
48
- </svg>
49
- </div>
50
- {{> RorVsWild.Local.RequestDetails}}
51
- {{/currentRequest}}
52
-
53
- {{^currentRequest}}
54
- {{#requests}}
55
- {{> RorVsWild.Local.RequestSummary}}
56
- {{/requests}}
57
- {{/currentRequest}}
49
+ {{{renderBody}}}
58
50
  </div>
59
51
  </div>
60
52
  <div class="rorvswild-local-panel__footer">
@@ -62,72 +54,278 @@
62
54
  </div>
63
55
  </div>
64
56
 
65
- {{#embedded}}
66
- <div class="rorvswild-local-toggler" data-events="click->toggle">{{lastRuntime}}<small>ms</small></div>
67
- {{/embedded}}
57
+ <% if @current_request %>
58
+ {{#embedded}}
59
+ <div class="rorvswild-local-toggler" data-events="click->toggle" data-uuid="<%= @current_request["uuid"] %>"><%= @current_request["runtime"].round %><small>ms</small></div>
60
+ {{/embedded}}
61
+ <% end %>
62
+ </script>
63
+
64
+ <script type="x-tmpl-mustache" data-partial="RorVsWild.Local.RequestIndex">
65
+ {{^requests}}
66
+ <h2 class="rorvswild-local-panel--blank">No requests</h2>
67
+ {{/requests}}
68
+ {{#requests}}
69
+ <div data-events="click->goToRequestDetail" data-uuid="{{uuid}}" class="rorvswild-local-panel__row">
70
+ <div class="rorvswild-local-panel__name">
71
+ <span>{{name}}</span>
72
+ <div class="rorvswild-local-panel__path">{{path}}</div>
73
+ </div>
74
+ <span class="rorvswild-local-panel__runtime">{{runtime}}<small>ms</small></span>
75
+ <span class="rorvswild-local-panel__started-at">{{queuedAt}}</span>
76
+ </div>
77
+ {{/requests}}
78
+ </script>
79
+
80
+ <script type="x-tmpl-mustache" data-partial="RorVsWild.Local.JobIndex">
81
+ {{^jobs}}
82
+ <h2 class="rorvswild-local-panel--blank">No jobs</h2>
83
+ {{/jobs}}
84
+ {{#jobs}}
85
+ <div data-events="click->goToJobDetail" data-uuid="{{uuid}}"" class="rorvswild-local-panel__row">
86
+ <div class="rorvswild-local-panel__name">
87
+ <span>{{name}}</span>
88
+ <div class="rorvswild-local-panel__path">{{path}}</div>
89
+ </div>
90
+ <span class="rorvswild-local-panel__runtime">{{runtime}}<small>ms</small></span>
91
+ <span class="rorvswild-local-panel__started-at">{{queuedAt}}</span>
92
+ </div>
93
+ {{/jobs}}
68
94
  </script>
69
95
 
70
96
  <script type="x-tmpl-mustache" data-partial="RorVsWild.Local.RequestSummary">
71
- <div data-events="click->goToRequestDetails" data-request-id="{{id}}" class="rorvswild-local-panel__request">
72
- <div class="rorvswild-local-panel__request__name">
97
+ <div data-events="click->goToRequestDetail" data-uuid="{{uuid}}" class="rorvswild-local-panel__row">
98
+ <div class="rorvswild-local-panel__name">
73
99
  <span>{{name}}</span>
74
- <div class="rorvswild-local-panel__request__path">
100
+ <div class="rorvswild-local-panel__path">
75
101
  {{path}}
76
102
  </div>
77
103
  </div>
78
- <span class="rorvswild-local-panel__request__runtime">{{runtime}}<small>ms</small></span>
79
- <span class="rorvswild-local-panel__request__started-at">{{queuedAt}}</span>
104
+ <span class="rorvswild-local-panel__runtime">{{runtime}}<small>ms</small></span>
105
+ <span class="rorvswild-local-panel__started-at">{{queuedAt}}</span>
80
106
  </div>
81
107
  </script>
82
108
 
83
- <script type="x-tmpl-mustache" data-partial="RorVsWild.Local.RequestDetails">
84
- <div class="rorvswild-local-panel__request-details">
85
- <div class="rorvswild-local-panel__request-details__request">
86
- <span class="rorvswild-local-panel__request__name">
87
- <h2 class="rorvswild-local-panel__request__name__title">{{name}}</h2>
88
- <span class="rorvswild-local-panel__request__path">
89
- {{path}}
109
+ <script type="x-tmpl-mustache" data-partial="RorVsWild.Local.RequestDetail">
110
+ {{#currentRequest}}
111
+ <div class="rorvswild-local-panel__details">
112
+ <div class="rorvswild-local-panel__details__header">
113
+ <span class="rorvswild-local-panel__name">
114
+ <h2 class="rorvswild-local-panel__title">{{name}}</h2>
115
+ <span class="rorvswild-local-panel__path">
116
+ {{path}}
117
+ </span>
90
118
  </span>
91
- </span>
92
- <span class="rorvswild-local-panel__request__runtime">{{runtime}}<small>ms</small></span>
93
- <span class="rorvswild-local-panel__request__started-at">{{queuedAt}}</span>
119
+ <span class="rorvswild-local-panel__runtime">{{runtime}}<small>ms</small></span>
120
+ <span class="rorvswild-local-panel__started-at">{{queuedAt}}</span>
121
+ </div>
122
+ {{> RorVsWild.Local.Sections}}
94
123
  </div>
95
- <div class="rorvswild-local-panel__request-details__sections">
96
- {{#sections}}
97
- {{> RorVsWild.Local.Section}}
98
- {{/sections}}
124
+ {{/currentRequest}}
125
+ </script>
126
+
127
+ <script type="x-tmpl-mustache" data-partial="RorVsWild.Local.JobDetail">
128
+ {{#currentJob}}
129
+ <div class="rorvswild-local-panel__details">
130
+ <div class="rorvswild-local-panel__details__header">
131
+ <span class="rorvswild-local-panel__name">
132
+ <h2 class="rorvswild-local-panel__title">{{name}}</h2>
133
+ <span class="rorvswild-local-panel__path">
134
+ {{path}}
135
+ </span>
136
+ </span>
137
+ <span class="rorvswild-local-panel__runtime">{{runtime}}<small>ms</small></span>
138
+ <span class="rorvswild-local-panel__started-at">{{queuedAt}}</span>
139
+ </div>
140
+ {{> RorVsWild.Local.Sections}}
99
141
  </div>
142
+ {{/currentJob}}
143
+ </script>
144
+
145
+ <script type="x-tmpl-mustache" data-partial="RorVsWild.Local.Sections">
146
+ <div class="rorvswild-local-panel__details__sections">
147
+ {{> RorVsWild.Local.SectionImpactPerKind}}
148
+ {{#sections}}
149
+ {{> RorVsWild.Local.Section}}
150
+ {{/sections}}
100
151
  </div>
101
152
  </script>
102
153
 
154
+ <script type="x-tmpl-mustache" data-partial="RorVsWild.Local.SectionImpactPerKind">
155
+ <ul class="rorvswild-local-panel__breakdown">
156
+ {{#sectionsImpactPerKind}}
157
+ <li style="width: {{impact}}%" title="{{kind}} {{impact}}%">
158
+ <span class="rorvswild-local-panel__breakdown__label">{{kind}}</span> <span class="rorvswild-local-panel__breakdown__value">{{impact}}%</span>
159
+ </li>
160
+ {{/sectionsImpactPerKind}}
161
+ </ul>
162
+ </script>
163
+
103
164
  <script type="x-tmpl-mustache" data-partial="RorVsWild.Local.Section">
104
- <div class="rorvswild-local-panel__request-details__section" id="section-{{id}}">
105
- <div class="rorvswild-local-panel__request-details__section__main">
106
- <span class="rorvswild-local-panel__request-details__section__file">
107
- {{#command}}
108
- <button data-events="click->toggleCommand" data-target="#section-{{id}}" class="rorvswild-local-panel__request-details__section__kind"><span>{{kind}}</button>
109
- {{/command}}
110
- {{^command}}
111
- <span class="rorvswild-local-panel__request-details__section__kind">{{kind}}</span>
112
- {{/command}}
113
- {{#url}}
114
- <a href="{{url}}" class="rorvswild-local-panel__request-details__section__file__name" title="Open in your editor">{{file}}<span>:{{line}}</span></a>
115
- {{/url}}
116
- {{^url}}
117
- <span class="rorvswild-local-panel__request-details__section__file__name">{{file}}<span>:{{line}}</span></span>
118
- {{/url}}
165
+ <div class="rorvswild-local-panel__details__section" id="section-{{id}}">
166
+ <div class="rorvswild-local-panel__details__section__main">
167
+ <span class="rorvswild-local-panel__details__section__file">
168
+ <button data-events="click->toggleCommand" data-target="#section-{{id}}" class="rorvswild-local-panel__details__section__kind"><span>{{kind}}</button>
169
+ {{#locationUrl}}
170
+ <a href="{{locationUrl}}" class="rorvswild-local-panel__file__name" title="Open in your editor">{{location}}</a>
171
+ {{/locationUrl}}
172
+ {{^locationUrl}}
173
+ <span class="rorvswild-local-panel__file__name">{{file}}<span>:{{line}}</span></span>
174
+ {{/locationUrl}}
119
175
  </span>
120
- <span class="rorvswild-local-panel__request-details__section__average" title="average runtime">{{averageRuntime}}<small>ms</small></span>
121
- <span class="rorvswild-local-panel__request-details__section__calls" title="calls">x{{calls}}</span>
122
- <span class="rorvswild-local-panel__request-details__section__impact" title="impact">{{impact}}<small>&#37;</small></span>
176
+ <span class="rorvswild-local-panel__details__section__average" title="Self runtime">{{selfRuntime}}<small>ms</small></span>
177
+ <span class="rorvswild-local-panel__details__section__impact" title="Impact">{{impact}}<small>&#37;</small></span>
123
178
  </div>
124
- {{#command}}
125
- <div class="rorvswild-local-panel__request-details__section__code">
179
+
180
+ <div class="rorvswild-local-panel__details__section__code">
181
+ <dl>
182
+ <div>
183
+ <dt title="self + children">Total runtime</dt>
184
+ <dd title="{{selfRuntime}} + {{childrenRuntime}}">{{totalRuntime}}<small>ms</small></dd>
185
+ </div>
186
+ <div>
187
+ <dt title="total - self">Children runtime</dt>
188
+ <dd title="{{totalRuntime}} - {{selfRuntime}}">{{childrenRuntime}}<small>ms</small></dd>
189
+ </div>
190
+ <div>
191
+ <dt title="total - children">Self runtime</dt>
192
+ <dd title="{{totalRuntime}} - {{childrenRuntime}}">{{selfRuntime}}<small>ms</small></dd>
193
+ </div>
194
+ <div>
195
+ <dt>Calls</dt>
196
+ <dd class="dd--calls">{{calls}}<small>x</small></dd>
197
+ </div>
198
+ <div>
199
+ <dt title="self runtime / calls">Average runtime</dt>
200
+ <dd title="{{selfRuntime}} / {{calls}}">{{averageRuntime}}<small>ms</small></dd>
201
+ </div>
202
+ </dl>
203
+ {{#command}}
126
204
  <pre><code class="{{language}}">{{command}}</code></pre>
127
- </div>
128
- {{/command}}
205
+ {{/command}}
206
+ </div>
129
207
  </div>
130
208
  </script>
131
209
 
210
+ <script type="x-tmpl-mustache" data-partial="RorVsWild.Local.ErrorIndex">
211
+ {{^errors}}
212
+ <h2 class="rorvswild-local-panel--blank">No errors</h2>
213
+ {{/errors}}
214
+ {{#errors}}
215
+ <div data-events="click->goToErrorDetail" data-uuid="{{uuid}}" class="rorvswild-local-panel__row rorvswild-local-panel__error">
216
+ <div class="rorvswild-local-panel__name">
217
+ <span>{{exception}}</span> {{shortMessage}}
218
+ <div class="rorvswild-local-panel__path">{{file}}:{{line}}</div>
219
+ </div>
220
+ <span class="rorvswild-local-panel__started-at">{{queuedAt}}</span>
221
+ </div>
222
+ {{/errors}}
223
+ </script>
224
+
225
+ <script type="x-tmpl-mustache" data-partial="RorVsWild.Local.ErrorDetail">
226
+ {{#currentError}}
227
+ <div class="rorvswild-local-panel__details rorvswild-local-panel__error">
228
+ <div class="rorvswild-local-panel__details__header">
229
+ <span class="rorvswild-local-panel__name">
230
+ <h2 class="rorvswild-local-panel__title">{{exception}}</h2>
231
+ <span class="rorvswild-local-panel__path">
232
+ {{#locationUrl}}
233
+ <a href="{{locationUrl}}" class="rorvswild-local-panel__file__name" title="Open in your editor">{{file}}:{{line}}</a>
234
+ {{/locationUrl}}
235
+ {{^locationUrl}}
236
+ {{file}}:{{line}}
237
+ {{/locationUrl}}
238
+ </span>
239
+ </span>
240
+ <span class="rorvswild-local-panel__started-at">{{queuedAt}}</span>
241
+ </div>
242
+
243
+ {{#message}}
244
+ <div class="rorvswild-local-panel__card">
245
+ <h3 class="rorvswild-local-panel__card__title">Message</h3>
246
+ <code><pre class="language-none">{{message}}</pre></code>
247
+ </div>
248
+ {{/message}}
249
+
250
+ <div class="rorvswild-local-panel__card">
251
+ <h3 class="rorvswild-local-panel__card__title">Backtrace</h3>
252
+ {{#compactBacktraceLocations}}
253
+ <pre class="language-markup"><a href="{{url}}" class="rorvswild-local-panel__file__name" title="Open in your editor">{{path}}</a></pre>
254
+ {{/compactBacktraceLocations}}
255
+ <details>
256
+ <summary>
257
+ view full trace
258
+ </summary>
259
+ <code><pre class="language-none">{{formattedBacktrace}}</pre></code>
260
+ </details>
261
+ </div>
262
+
263
+ {{#request}}
264
+ <div class="rorvswild-local-panel__card">
265
+ <h3 class="rorvswild-local-panel__card__title">Request</h3>
266
+ <dl>
267
+ <div><dt>name</dt><dd>{{name}}</dd></div>
268
+ <div><dt>method</dt><dd>{{method}}</dd></div>
269
+ <div><dt>URL</dt><dd>{{url}}</dd></div>
270
+ </dl>
271
+ </div>
272
+ {{/request}}
273
+
274
+ {{#job}}
275
+ <div class="rorvswild-local-panel__card">
276
+ <h3 class="rorvswild-local-panel__card__title">Job</h3>
277
+ <dl>
278
+ <div><dt>name</dt><dd>{{name}}</dd></div>
279
+ </dl>
280
+ </div>
281
+ {{/job}}
282
+
283
+ {{#hasParameters}}
284
+ <div class="rorvswild-local-panel__card">
285
+ <h3 class="rorvswild-local-panel__card__title">Parameters</h3>
286
+ <pre class="language-json"><code>{{parametersInJson}}</code></pre>
287
+ </div>
288
+ {{/hasParameters}}
289
+
290
+ {{#hasRequestHeaders}}
291
+ <div class="rorvswild-local-panel__card">
292
+ <h3 class="rorvswild-local-panel__card__title">Headers</h3>
293
+ <dl>
294
+ {{#eachRequestHeader}}
295
+ <div>
296
+ <dt>{{name}}</dt><dd>{{value}}</dd>
297
+ </div>
298
+ {{/eachRequestHeader}}
299
+ </dl>
300
+ </div>
301
+ {{/hasRequestHeaders}}
302
+
303
+ {{#hasContext}}
304
+ <div class="rorvswild-local-panel__card">
305
+ <h3 class="rorvswild-local-panel__card__title">Context</h3>
306
+ <dl>
307
+ {{#eachContext}}
308
+ <div>
309
+ <dt>{{name}}</dt><dd>{{value}}</dd>
310
+ </div>
311
+ {{/eachContext}}
312
+ </dl>
313
+ </div>
314
+ {{/hasContext}}
315
+
316
+ <div class="rorvswild-local-panel__card">
317
+ <h3 class="rorvswild-local-panel__card__title">Environment</h3>
318
+ <dl>
319
+ {{#eachEnvironment}}
320
+ <div>
321
+ <dt>{{name}}</dt><dd>{{value}}</dd>
322
+ </div>
323
+ {{/eachEnvironment}}
324
+ </dl>
325
+ </div>
326
+ </div>
327
+ {{/currentError}}
328
+ </script>
329
+
132
330
  <link rel="stylesheet" media="all" href="/rorvswild.css"/>
133
331
  <script src="/rorvswild.js"></script>
@@ -17,6 +17,9 @@ module RorVsWild
17
17
  when "/rorvswild.css" then serve_stylesheet
18
18
  when "/rorvswild.js" then serve_javascript
19
19
  when "/rorvswild.json" then serve_json
20
+ when "/rorvswild/requests.json" then serve_requests
21
+ when "/rorvswild/jobs.json" then serve_jobs
22
+ when "/rorvswild/errors.json" then serve_errors
20
23
  else serve_embed_profiler(env)
21
24
  end
22
25
  end
@@ -34,6 +37,7 @@ module RorVsWild
34
37
  log_incompatible_middleware_warning
35
38
  elsif body.respond_to?(:each)
36
39
  content_length = 0
40
+ @current_request = RorVsWild.agent.queue.requests.first
37
41
  body.each do |string|
38
42
  inject_into(string)
39
43
  content_length += string.size
@@ -56,6 +60,18 @@ module RorVsWild
56
60
  [200, {"Content-Type" => "application/json"}, StringIO.new(RorVsWild.agent.queue.requests.to_json)]
57
61
  end
58
62
 
63
+ def serve_requests
64
+ [200, {"Content-Type" => "application/json"}, StringIO.new(RorVsWild.agent.queue.requests.to_json)]
65
+ end
66
+
67
+ def serve_jobs
68
+ [200, {"Content-Type" => "application/json"}, StringIO.new(RorVsWild.agent.queue.jobs.to_json)]
69
+ end
70
+
71
+ def serve_errors
72
+ [200, {"Content-Type" => "application/json"}, StringIO.new(RorVsWild.agent.queue.errors.to_json)]
73
+ end
74
+
59
75
  private
60
76
 
61
77
  def widget_css
@@ -1,18 +1,56 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RorVsWild
2
4
  module Local
3
5
  class Queue
4
- attr_reader :requests
5
- def initialize
6
- @requests = []
7
- end
8
-
9
6
  def push_job(data)
7
+ push_to(data, "jobs")
8
+ push_error(data[:error]) if data[:error]
10
9
  end
11
10
 
12
11
  def push_request(data)
13
- requests.unshift(data)
12
+ push_to(data, "requests")
13
+ push_error(data[:error]) if data[:error]
14
+ end
15
+
16
+ def push_error(data)
17
+ push_to(data, "errors")
18
+ end
19
+
20
+ def requests
21
+ load_data("requests")
22
+ end
23
+
24
+ def jobs
25
+ load_data("jobs")
26
+ end
27
+
28
+ def errors
29
+ load_data("errors")
30
+ end
31
+
32
+ private
33
+
34
+ def push_to(data, name)
14
35
  data[:queued_at] = Time.now
15
- requests.pop if requests.size > 100
36
+ data[:uuid] = SecureRandom.uuid
37
+ array = load_data(name)
38
+ array.unshift(data)
39
+ array.pop if array.size > 100
40
+ save_data(array, name)
41
+ end
42
+
43
+ def save_data(data, name)
44
+ File.open(File.join(directoy, "#{name}.json"), "w") { |file| JSON.dump(data, file) }
45
+ end
46
+
47
+ def load_data(name)
48
+ JSON.load_file(File.join(directoy, "#{name}.json")) rescue []
49
+ end
50
+
51
+ def directoy
52
+ dir = File.directory?("tmp") ? "tmp" : Dir.tmpdir
53
+ FileUtils.mkpath(File.join(dir, "rorvswild"))[0]
16
54
  end
17
55
  end
18
56
  end