git ssb

16+

Dominic / patchbay



Tree: 416bd419c5213ab41ae675ce592e485b8d9aef75

Files: 416bd419c5213ab41ae675ce592e485b8d9aef75 / modules / query.js

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

Built with git-ssb-web