Files: 11fc4a4c131af561b454a3251544add67c283036 / modules / query.js
1311 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.menu_items = function () { |
8 | return h('a', {href:'#/query'}, '/query') |
9 | } |
10 | |
11 | exports.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