Files: b36938964724c375a4405fe69f835799cc9746a6 / modules / query.js
1229 bytesRaw
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 | |
53 |
Built with git-ssb-web