git ssb

16+

Dominic / patchbay



Tree: 3003c7f2e378ab411b09eaa11adef56245af1868

Files: 3003c7f2e378ab411b09eaa11adef56245af1868 / modules_extra / query.js

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

Built with git-ssb-web