Files: 8cf292c13507a00dd6f025dfa662409737ba7dea / modules_extra / query.js
1371 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.builtin_tabs = function () { |
12 | return ['/query'] |
13 | } |
14 | |
15 | exports.screen_view = function (path) { |
16 | if(path != '/query') return |
17 | var output, status, editor, stream, query |
18 | |
19 | function parse () { |
20 | try { |
21 | query = HJSON.parse(editor.value) |
22 | } catch (err) { |
23 | return status.textContent = err.message |
24 | } |
25 | status.textContent = 'okay' |
26 | } |
27 | |
28 | return h('div.column.scroll', |
29 | editor = h('textarea', {style: 'min-height:100px;', oninput: parse, onkeydown: function (e) { |
30 | if(!(e.keyCode === 13 && e.ctrlKey)) return |
31 | |
32 | status.textContent = 'running...' |
33 | parse() |
34 | output.innerHTML = '' |
35 | if(stream) stream.abort() |
36 | |
37 | console.log(query) |
38 | |
39 | stream = pull( |
40 | sbot_query({query: query, limit: 100}), |
41 | pull.drain(function (data) { |
42 | output.appendChild(h('pre.query__data', |
43 | JSON.stringify(data, null, 2) |
44 | )) |
45 | }, function (err) { |
46 | if(err) status.textContent = err.stack |
47 | }) |
48 | ) |
49 | }}), |
50 | status = h('div.query__status'), |
51 | output = h('div.column.query__output', {style: 'overflow-y: scroll;'}) |
52 | ) |
53 | } |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 |
Built with git-ssb-web