|
| 1 | + |
| 2 | +<script LANGUAGE="JavaScript"> |
| 3 | +<!-- |
| 4 | +function confirmSubmit() |
| 5 | +{ |
| 6 | +var agree=confirm("Are you sure you wish to continue?"); |
| 7 | +if (agree) |
| 8 | + return true ; |
| 9 | +else |
| 10 | + return false ; |
| 11 | +} |
| 12 | + |
| 13 | +function setSample() { |
| 14 | + var text = document.getElementById("query_attributes").textContent; |
| 15 | + var textArea = document.getElementById('querytext'); |
| 16 | + textArea.value = text; |
| 17 | + return false; |
| 18 | +} |
| 19 | +// --> |
| 20 | +</script> |
| 21 | + |
| 22 | +<% |
| 23 | + app_hash = {} |
| 24 | + class_hash = {} |
| 25 | + event_hash = {} |
| 26 | + query_string = params[:query].to_s.strip |
| 27 | + |
| 28 | + query_attributes = nil |
| 29 | + query_error = nil |
| 30 | + if query_string.length > 0 |
| 31 | + begin |
| 32 | + query_attributes = ::SidekiqBus::Server::Helpers.parse_query(query_string) |
| 33 | + raise "Not a JSON Object" unless query_attributes.is_a?(Hash) |
| 34 | + rescue Exception => e |
| 35 | + query_attributes = nil |
| 36 | + query_error = e.message |
| 37 | + end |
| 38 | + |
| 39 | + if query_attributes |
| 40 | + # sort keys for display |
| 41 | + query_attributes = ::SidekiqBus::Server::Helpers.sort_query(query_attributes) |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + # collect each differently |
| 46 | + ::QueueBus::Application.all.each do |app| |
| 47 | + app_key = app.app_key |
| 48 | + |
| 49 | + subscriptions = ::SidekiqBus::Server::Helpers.query_subscriptions(app, query_attributes) |
| 50 | + subscriptions.each do |sub| |
| 51 | + class_name = sub.class_name |
| 52 | + queue = sub.queue_name |
| 53 | + filters = sub.matcher.filters |
| 54 | + sub_key = sub.key |
| 55 | + |
| 56 | + if filters["bus_event_type"] |
| 57 | + event = filters["bus_event_type"] |
| 58 | + else |
| 59 | + event = "see filter" |
| 60 | + end |
| 61 | + |
| 62 | + app_hash[app_key] ||= [] |
| 63 | + app_hash[app_key] << [sub_key, event, class_name, queue, filters] |
| 64 | + |
| 65 | + class_hash[class_name] ||= [] |
| 66 | + class_hash[class_name] << [app_key, sub_key, event, queue, filters] |
| 67 | + |
| 68 | + event_hash[event] ||= [] |
| 69 | + event_hash[event] << [app_key, sub_key, class_name, queue, filters] |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | + # sort each list item by secondary label |
| 74 | + class_hash.each do |_, array| |
| 75 | + array.sort!{ |a,b| a.first <=> b.first } |
| 76 | + end |
| 77 | + event_hash.each do |_, array| |
| 78 | + array.sort!{ |a,b| a.first <=> b.first } |
| 79 | + end |
| 80 | + |
| 81 | + # helper to display either |
| 82 | + def display_row(name, val, button=nil, first=false) |
| 83 | + form = "" |
| 84 | + if button |
| 85 | + text, url = button |
| 86 | + form = "<form method='POST' action='#{url}' style='float:left; padding:0 5px 0 0;margin:0;'>#{csrf_tag}<input type='submit' name='' value='#{h(text)}' style='padding:0;margin:0;' onclick=\"return confirmSubmit();\"/><input type='hidden' name='name' value='#{h(name)}' /></form>" |
| 87 | + end |
| 88 | + |
| 89 | + if !val |
| 90 | + out = "<td> </td><td> </td>" |
| 91 | + else |
| 92 | + one, two, three, queue, filters = val |
| 93 | + out = "<td>#{h(one)}</td><td>#{h(two)}</td><td>#{h(three)}</td><td><a href='#{"queues/#{queue}"}'>#{h(queue)}</a></td>" |
| 94 | + out << "<td>#{h(::QueueBus::Util.encode(filters).gsub(/\"bus_special_value_(\w+)\"/){ "(#{$1})" }).gsub(" ", " ").gsub('","', '", "')}</td>" |
| 95 | + end |
| 96 | + |
| 97 | + if first |
| 98 | + "<tr><td>#{h(name)}#{form}</td>#{out}</tr>\n" |
| 99 | + else |
| 100 | + "<tr><td> </td>#{out}</tr>\n" |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | + def output_hash(hash, action=nil) |
| 105 | + out = "" |
| 106 | + hash.keys.sort.each do |item| |
| 107 | + display = hash[item] |
| 108 | + first = display.shift |
| 109 | + out << display_row(item, first, action, true) |
| 110 | + display.each do |val| |
| 111 | + out << display_row(item, val, action) |
| 112 | + end |
| 113 | + end |
| 114 | + out |
| 115 | + end |
| 116 | +%> |
| 117 | + |
| 118 | +<h1 class='wi'>Sample Event</h1> |
| 119 | +<p class='intro'>Enter JSON of an event to see applicable subscriptions.</p> |
| 120 | +<div style="text-align: center;width:700px;"> |
| 121 | + -<form method="GET" action="<%= "bus" %>" style="float:none;padding:0;margin:0;"> |
| 122 | + <textarea id="querytext" name="query" style="padding: 10px;height:150px;width:700px;font-size:14px;font-family:monospace"><%= |
| 123 | + h(query_string) |
| 124 | + %></textarea> |
| 125 | + <br/> |
| 126 | + <button onclick="window.location.href = '<%= "bus" %>'; return false;">Clear</button> |
| 127 | + <input type="submit" name="" value="Filter results to this event"/> |
| 128 | + </form> |
| 129 | +</div> |
| 130 | + |
| 131 | +<% if query_error %> |
| 132 | + <blockquote><pre style="text-align:left;font-family:monospace;margin:5px 0 5px 0;padding:10px;background:#f2dede;color:#a94442;"><code><%= |
| 133 | + h(query_error.strip) |
| 134 | + %></code></pre></blockquote> |
| 135 | +<% end %> |
| 136 | +<% if query_attributes %> |
| 137 | + <blockquote><pre style="text-align:left;font-family:monospace;margin:5px 0 5px 0;padding:10px;background:#dff0d8;color:#3c763d;"><code id="query_attributes"><%= |
| 138 | + h(JSON.pretty_generate(query_attributes).strip) |
| 139 | + %></code></pre></blockquote> |
| 140 | + <div style="text-align:right;"> |
| 141 | + <button onclick="return setSample();">Set Sample</button> |
| 142 | + </div> |
| 143 | +<% end %> |
| 144 | + |
| 145 | +<hr/> |
| 146 | + |
| 147 | +<h1 class='wi'>Applications</h1> |
| 148 | +<p class='intro'>The apps below have registered the given classes and queues.</p> |
| 149 | +<table class='table-striped table-bordered'> |
| 150 | + <thead class="thead-dark"> |
| 151 | + <tr> |
| 152 | + <th>App Key</th> |
| 153 | + <th>Subscription Key</th> |
| 154 | + <th>Event Type</th> |
| 155 | + <th>Class Name</th> |
| 156 | + <th>Queue</th> |
| 157 | + <th>Filters</th> |
| 158 | + </tr> |
| 159 | + </thead> |
| 160 | + |
| 161 | + <%= output_hash(app_hash, query_attributes ? false : ["Unsubscribe", "bus/unsubscribe"]) %> |
| 162 | +</table> |
| 163 | + |
| 164 | +<p> </p> |
| 165 | + |
| 166 | +<h1 class='wi'>Events</h1> |
| 167 | +<p class='intro'>The events below have been registered by the given applications and queues.</p> |
| 168 | + |
| 169 | +<table class='table-striped table-bordered'> |
| 170 | + <thead class="thead-dark"> |
| 171 | + <tr> |
| 172 | + <th>Event Type</th> |
| 173 | + <th>App Key</th> |
| 174 | + <th>Subscription Key</th> |
| 175 | + <th>Class Name</th> |
| 176 | + <th>Queue</th> |
| 177 | + <th>Filters</th> |
| 178 | + </tr> |
| 179 | + </thead> |
| 180 | + <%= output_hash(event_hash, false) %> |
| 181 | +</table> |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | +<p> </p> |
| 186 | + |
| 187 | +<h1 class='wi'>Classes</h1> |
| 188 | +<p class='intro'>The classes below have been registered by the given applications and queues.</p> |
| 189 | +<table class='table-striped table-bordered'> |
| 190 | + <thead class="thead-dark"> |
| 191 | + <tr> |
| 192 | + <th>Class Name</th> |
| 193 | + <th>App Key</th> |
| 194 | + <th>Subscription Key</th> |
| 195 | + <th>Event Type</th> |
| 196 | + <th>Queue</th> |
| 197 | + <th>Filters</th> |
| 198 | + </tr> |
| 199 | + </thead> |
| 200 | + <%= output_hash(class_hash, false) %> |
| 201 | +</table> |
| 202 | + |
0 commit comments