git ssb

16+

Dominic / patchbay



Tree: 39613c79e32b11885ab4a4e58342b54df3f85b4b

Files: 39613c79e32b11885ab4a4e58342b54df3f85b4b / modules_extra / query.js

1610 bytesRaw
1var h = require('hyperscript')
2var pull = require('pull-stream')
3var HJSON = require('hjson')
4
5exports.needs = { sbot_query: 'first' }
6
7exports.gives = {
8 menu_items: true,
9 builtin_tabs: true,
10 screen_view: true
11}
12
13exports.create = function (api) {
14
15 return {
16 menu_items: function () {
17 return h('a', {href:'#/query'}, '/query')
18 },
19
20 builtin_tabs: function () {
21 return ['/query']
22 },
23
24 screen_view: function (path) {
25 if(path != '/query') return
26 var output, status, editor, stream, query
27
28 function parse () {
29 try {
30 query = HJSON.parse(editor.value)
31 } catch (err) {
32 return status.textContent = err.message
33 }
34 status.textContent = 'okay'
35 }
36
37 return h('div.column.scroll',
38 editor = h('textarea', {style: 'min-height:100px;', oninput: parse, onkeydown: function (e) {
39 if(!(e.keyCode === 13 && e.ctrlKey)) return
40
41 status.textContent = 'running...'
42 parse()
43 output.innerHTML = ''
44 if(stream) stream.abort()
45
46 console.log(query)
47
48 stream = pull(
49 api.sbot_query({query: query, limit: 100}),
50 pull.drain(function (data) {
51 output.appendChild(h('pre.query__data',
52 JSON.stringify(data, null, 2)
53 ))
54 }, function (err) {
55 if(err) status.textContent = err.stack
56 })
57 )
58 }}),
59 status = h('div.query__status'),
60 output = h('div.column.query__output', {style: 'overflow-y: scroll;'})
61 )
62 }
63 }
64}
65

Built with git-ssb-web