Commit b36938964724c375a4405fe69f835799cc9746a6
Merge branch 'query'
Dominic Tarr committed on 8/11/2016, 6:39:23 AMParent: 02f6ec268886a1f83acfd2683d727d8eb33cf9bb
Parent: 59e70425d04d8ac84f4eda15e78ca5ccbf4a2b36
Files changed
modules/query.js | added |
modules/query.js | ||
---|---|---|
@@ -1,0 +1,52 @@ | ||
1 | +var h = require('hyperscript') | |
2 | +var pull = require('pull-stream') | |
3 | +var HJSON = require('hjson') | |
4 | + | |
5 | +var sbot_query = require('../plugs').first(exports.sbot_query = []) | |
6 | + | |
7 | +exports.screen_view = function (path) { | |
8 | + if(path != '/query') return | |
9 | + var output, status, editor, stream, query | |
10 | + | |
11 | + function parse () { | |
12 | + try { | |
13 | + query = HJSON.parse(editor.value) | |
14 | + } catch (err) { | |
15 | + return status.textContent = err.message | |
16 | + } | |
17 | + status.textContent = 'okay' | |
18 | + } | |
19 | + | |
20 | + return h('div.column.scroll', | |
21 | + editor = h('textarea', {style: 'min-height:100px;', oninput: parse, onkeydown: function (e) { | |
22 | + if(!(e.keyCode === 13 && e.ctrlKey)) return | |
23 | + | |
24 | + status.textContent = 'running...' | |
25 | + parse() | |
26 | + output.innerHTML = '' | |
27 | + if(stream) stream.abort() | |
28 | + | |
29 | + console.log(query) | |
30 | + | |
31 | + stream = pull( | |
32 | + sbot_query({query: query, limit: 100}), | |
33 | + pull.drain(function (data) { | |
34 | + output.appendChild(h('pre.query__data', | |
35 | + JSON.stringify(data, null, 2) | |
36 | + )) | |
37 | + }, function (err) { | |
38 | + if(err) status.textContent = err.stack | |
39 | + }) | |
40 | + ) | |
41 | + }}), | |
42 | + status = h('div.query__status'), | |
43 | + output = h('div.column.query__output', {style: 'overflow-y: scroll;'}) | |
44 | + ) | |
45 | +} | |
46 | + | |
47 | + | |
48 | + | |
49 | + | |
50 | + | |
51 | + | |
52 | + |
Built with git-ssb-web