Allow the for grepping message bodies from the web frontend

Fixes #6
Fixes #8
This commit is contained in:
R. Tyler Croy 2014-11-24 22:52:48 -08:00
parent 493deb7ddf
commit d998f4f8ca
2 changed files with 26 additions and 10 deletions

View File

@ -1,10 +1,18 @@
{{> header}} {{> header}}
<div class="container"> <div class="container">
<div class="progress" style="width: 100px;"> <div class="container">
<div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%"> <div class="progress" style="width: 100px;">
<span class="sr-only">Loading..</span> <div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
</div> <span class="sr-only">Loading..</span>
</div>
</div>
<div>
<form id="grep" role="form">
<input id="grepfield" class="form-control" type="search" placeholder="grep for.." size="20"/>
</form>
</div>
</div> </div>
<div id="messages"> <div id="messages">
@ -15,5 +23,13 @@
<script src="/js/ws.js?1"></script> <script src="/js/ws.js?1"></script>
<script type="text/javascript"> <script type="text/javascript">
watchTopic("{{name}}"); watchTopic("{{name}}");
$('#grep').submit(function(e) {
if (window.ws) {
window.ws.send($('#grepfield').val());
}
$('#grepfield').blur();
e.preventDefault();
});
</script> </script>
{{> footer}} {{> footer}}

View File

@ -44,16 +44,16 @@ ratpack {
} }
get('topics/:name/websocket') { ctx -> get('topics/:name/websocket') { ctx ->
println "creating thingies"
def client = new OfftopicClient(Configuration.instance) def client = new OfftopicClient(Configuration.instance)
println "client: ${client}" def grepper = null
websocket(ctx) { ws -> websocket(ctx) { ws ->
println "Connected ${ws}" println "Connected ${ws}"
client.onMessageCallback = { m -> client.onMessageCallback = { m ->
println "called back with ${m}" println "called back with ${m} (grep: ${grepper})"
ws.send(groovy.json.JsonOutput.toJson(m)) if ((grepper == null) || (m.raw =~ grepper)) {
println "sent message" ws.send(groovy.json.JsonOutput.toJson(m))
}
} }
client.createSubscribersFor(pathTokens.name) client.createSubscribersFor(pathTokens.name)
print "subscribers created for ${pathTokens.name}" print "subscribers created for ${pathTokens.name}"
@ -63,7 +63,7 @@ ratpack {
client.shutdown() client.shutdown()
} }
sock.onMessage { msg -> sock.onMessage { msg ->
println "client sent ${msg}" grepper = msg.text
} }
} }
} }