Merge pull request #1119 from urbit/la-iv/modulo

Landscape integration into lighter than eyre
This commit is contained in:
ixv 2019-03-29 16:55:24 -07:00 committed by GitHub
commit 2fa6a0dc69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 1181 additions and 83169 deletions

260
app/landscape.hoon Normal file
View File

@ -0,0 +1,260 @@
/+ *server, collections
/= index
/: /===/app/landscape/index /!noun/
/= script
/^ octs
/; as-octs:mimes:html
/: /===/app/landscape/js/index-min
/| /js/
/~ ~
==
/= style
/^ octs
/; as-octs:mimes:html
/: /===/app/landscape/css/index
/| /css/
/~ ~
==
/= profile
/: /===/app/landscape/profile /!noun/
/= inbox
/: /===/app/landscape/inbox /!noun/
/= stream
/: /===/app/landscape/stream /!noun/
/= coll-elem
/: /===/app/landscape/collections/elem /!noun/
/= coll-new
/: /===/app/landscape/collections/new /!noun/
::
|%
::
+$ move [bone card]
::
+$ card
$% [%http-response =http-event:http]
[%connect wire binding:http-server term]
[%peer wire dock path]
[%diff diff]
[%quit ~]
==
+$ diff
$% [%hymn manx]
[%json json]
==
::
--
::
|_ [bol=bowl:gall ~]
::
++ this .
::
++ prep
|= old=(unit ~)
^- (quip move _this)
?~ old
:_ this
[ost.bol %connect / [~ /'~landscape'] %landscape]~
[~ this]
::
++ bound
|= [wir=wire success=? binding=binding:http-server]
^- (quip move _this)
[~ this]
::
++ peer-xship
|= wir=wire
^- (quip move _this)
?+ wir
!! :: XX should we really crash on data sent from another ship?
::
[%top @t *]
=/ jon=? =(t.t.wir [%json ~])
=/ dif=diff (coll-elem our.bol (slav %da i.t.wir) ~ jon)
:_ this
:~ [ost.bol %diff dif]
[ost.bol %quit ~]
==
::
[%new @t *]
=/ jon=? =(t.t.wir [%json ~])
=/ pos [*@da %new]
=/ dif=diff (coll-elem our.bol (slav %da i.t.wir) `pos jon)
:_ this
:~ [ost.bol %diff dif]
[ost.bol %quit ~]
==
::
[%view @t @t *]
=/ jon=? =(t.t.t.wir [%json ~])
=/ pos [(slav %da i.t.t.wir) %default]
=/ dif=diff (coll-elem our.bol (slav %da i.t.wir) `pos jon)
:_ this
:~ [ost.bol %diff dif]
[ost.bol %quit ~]
==
::
[%edit @t @t *]
=/ jon=? =(t.t.t.wir [%json ~])
=/ pos [(slav %da i.t.t.wir) %edit]
=/ dif=diff (coll-elem our.bol (slav %da i.t.wir) `pos jon)
:_ this
:~ [ost.bol %diff dif]
[ost.bol %quit ~]
==
==
::
++ diff-hymn
|= [wir=wire hym=manx]
^- (quip move _this)
:_ this
[ost.bol %http-response (html-response:app (manx-to-octs (index hym)))]~
::
++ poke-handle-http-request
%- (require-authorization:app ost.bol move this)
|= =inbound-request:http-server
^- (quip move _this)
::
=+ request-line=(parse-request-line url.request.inbound-request)
?+ site.request-line
:_ this
[ost.bol %http-response not-found:app]~
::
:: inbox page
::
[%'~landscape' ~]
=/ index-html=octs (manx-to-octs (index inbox))
:_ this
[ost.bol %http-response (html-response:app index-html)]~
::
:: styling
::
[%'~landscape' %css ~]
:_ this
[ost.bol %http-response (css-response:app style)]~
::
:: javascript
::
[%'~landscape' %js ~]
:_ this
[ost.bol %http-response (js-response:app script)]~
::
:: profile page
::
[%'~landscape' %profile @t ~]
=/ profile-html=octs
(manx-to-octs (index (profile i.t.t.site.request-line)))
:_ this
[ost.bol %http-response (html-response:app profile-html)]~
::
:: chat page
::
[%'~landscape' %stream ~]
=/ stream-html=octs (manx-to-octs (index stream))
:_ this
[ost.bol %http-response (html-response:app stream-html)]~
::
:: collections top level page
::
[%'~landscape' %collections @t @t ~]
=/ shp=@p (slav %p i.t.t.site.request-line)
=/ col=@da (slav %da i.t.t.t.site.request-line)
?: =(shp our.bol)
:: local request
::
=/ jon=? =(ext.request-line [~ ~.json])
=/ dif=diff (coll-elem shp col ~ jon)
?- -.dif
%hymn
=/ oct=octs (manx-to-octs (index +.dif))
:_ this
[ost.bol %http-response (html-response:app oct)]~
::
%json
=/ oct=octs (json-to-octs +.dif)
:_ this
[ost.bol %http-response (json-response:app oct)]~
==
:: foreign request
::
?: =(ext.request-line [~ ~.json])
:: json format
::
=/ pax=path /xship/top/(scot %da col)/json
:_ this
[ost.bol %peer pax [shp %landscape] pax]~
::
:: html format
=/ pax=path /xship/top/(scot %da col)
:_ this
[ost.bol %peer pax [shp %landscape] pax]~
::
:: collections new post page
::
[%'~landscape' %collections @t @t %new ~]
=/ shp=@p (slav %p i.t.t.site.request-line)
=/ col=@da (slav %da i.t.t.t.site.request-line)
?: =(shp our.bol)
=/ dif=diff (coll-elem shp col `[*@da %new] |)
?> ?=(%hymn -.dif)
=/ new-html=octs
(manx-to-octs (index +.dif))
:_ this
[ost.bol %http-response (html-response:app new-html)]~
=/ pax=path /xship/new/(scot %da col)
:_ this
[ost.bol %peer pax [shp %landscape] pax]~
::
:: collections view post page
::
[%'~landscape' %collections @t @t @t ~]
=/ shp=@p (slav %p i.t.t.site.request-line)
=/ col=@da (slav %da i.t.t.t.site.request-line)
=/ pos=@da (slav %da i.t.t.t.t.site.request-line)
?: =(shp our.bol)
=/ jon=? =(ext.request-line [~ ~.json])
=/ dif=diff (coll-elem shp col `[pos %default] jon)
?- -.dif
%hymn
=/ oct=octs (manx-to-octs (index +.dif))
:_ this
[ost.bol %http-response (html-response:app oct)]~
::
%json
=/ oct=octs (json-to-octs +.dif)
:_ this
[ost.bol %http-response (json-response:app oct)]~
==
:: foreign request
::
?: =(ext.request-line [~ ~.json])
:: json format
::
=/ pax=path /xship/view/(scot %da col)/(scot %da pos)/json
:_ this
[ost.bol %peer pax [shp %landscape] pax]~
::
:: html format
=/ pax=path /xship/view/(scot %da col)/(scot %da pos)
:_ this
[ost.bol %peer pax [shp %landscape] pax]~
::
:: collections edit post page
::
[%'~landscape' %collections @t @t @t %edit ~]
=/ shp=@p (slav %p i.t.t.site.request-line)
=/ col=@da (slav %da i.t.t.t.site.request-line)
=/ pos=@da (slav %da i.t.t.t.t.site.request-line)
?: =(shp our.bol)
=/ dif=diff (coll-elem shp col `[pos %edit] |)
?> ?=(%hymn -.dif)
=/ edit-html=octs
(manx-to-octs (index +.dif))
:_ this
[ost.bol %http-response (html-response:app edit-html)]~
=/ pax=path /xship/edit/(scot %da col)/(scot %da pos)
:_ this
[ost.bol %peer pax [shp %landscape] pax]~
::
==
::
--

View File

@ -0,0 +1,14 @@
::
::::
::
|= [shp=@p col=@da pos=@da dat=@t]
^- manx
;div.container
;div
=urb-component "TopicCreatePage"
=urb-ship "{<shp>}"
=urb-claypath "{<col>}"
=urb-content (trip dat)
;input(type "hidden", name "urb-header", value "collection-write", station "query");
==
==

View File

@ -0,0 +1,344 @@
::
::::
::
/? 309
/+ collections, cram
/= coll-new
/: /===/app/landscape/collections/new /!noun/
/= coll-edit
/: /===/app/landscape/collections/edit /!noun/
/= cols
/^ collection:collections
/; |= a=(map knot item:collections)
[*config:collections a]
/: /===/web/collections /_ /collections-item/
::
::
|%
+$ post-page [p=@da q=?(%default %edit %new)]
--
|= [shp=@p col=@da pos=(unit post-page) json=?]
^- $% [%hymn manx]
[%json ^json]
==
=/ itm=(unit item:collections) (~(get by data.cols) (scot %da col))
?: json
?~ itm [%json ~]
[%json (item-to-json:collections u.itm)]
?~ itm
[%hymn ;div:(Invalid collection)]
=< [%hymn (item-to-elem u.itm)]
|%
++ item-to-elem
!:
|= itm=item:collections
?~ pos
?> ?=(%collection -.itm)
^- manx
;div.container
;div.row
;div.flex-col-2;
;div.flex-col-x
;div.collection-index
;+ (meta-to-elem itm)
;+ (collection-to-elem col.itm)
==
==
;+ ?: =(type.meta.col.itm %blog)
;div.flex-col-5;
?: =(type.meta.col.itm %fora)
;div.flex-col-4;
;div.flex-col-4;
==
==
::
::
?> ?=(%collection -.itm)
=/ posttt=(unit item:collections) (~(get by data.col.itm) (scot %da p.u.pos))
?: ?&(?=(~ posttt) !=(q.u.pos %new))
;div: Invalid collection
^- manx
?- q.u.pos
%default
?< ?=(~ posttt)
?> ?=(%both -.u.posttt)
;div.container
;div.row
;div.flex-col-2;
;div.flex-col-x
;div.collection-index
;+ (meta-to-elem u.posttt)
;+ (both-to-elem col.u.posttt raw.u.posttt)
==
==
;div.flex-col-2;
==
==
::
%edit
?< ?=(~ posttt)
?> ?=(%both -.u.posttt)
=/ dat data.raw.u.posttt
;div.row
;div.flex-col-2;
;div.flex-col-x
;div.collection-index
;+ (meta-to-elem u.posttt)
;+ (coll-edit shp col p.u.pos dat)
==
==
;div.flex-col-2;
==
::
%new
;div.row
;div.flex-col-2;
;div.flex-col-x
;div.collection-index
;+ (meta-to-elem itm)
;+ (coll-new shp col)
==
==
;div.flex-col-2;
==
==
::
++ collection-to-elem
|= col=collection:collections
^- manx
;ul.vanilla
;* %+ roll
%+ sort ~(tap by data.col)
|= [[knot a=item:collections] [knot b=item:collections]]
=/ a-dat (extract-date-created a)
=/ b-dat (extract-date-created b)
(lth a-dat b-dat)
|= [[nom=knot ite=item:collections] out=marl]
^- marl
?: ?=(%error -.ite)
out
:_ out
^- manx
;li.collection-post.mt-6
;+ (item-to-snip nom ite)
==
==
::
++ raw-to-elem
|= raw=raw-item:collections
^- manx
=/ elm elm:(static:cram (ream data.raw))
=/ ht (hedtal:collections +.elm)
=/ title (fall (~(get by meta.raw) %name) /spur)
=/ date (fall (~(get by meta.raw) %date-created) 'missing date')
=/ author (fall (~(get by meta.raw) %author) 'anonymous')
::
;div.mb-18.mt-4
;+ elm
==
::
++ both-to-elem
|= [col=collection:collections raw=raw-item:collections]
^- manx
;div
;+ (raw-to-elem raw)
::
;div
;div.flex.align-center.mb-5
;div(urb-component "IconComment");
;div.ml-2.text-small.text-mono.text-600: {<~(wyt by data.col)>}
==
::
;ul.vanilla
;* %+ turn
%+ sort ~(tap by data.col)
|= [[knot a=item:collections] [knot b=item:collections]]
=/ a-dat (extract-date-created a)
=/ b-dat (extract-date-created b)
(lte a-dat b-dat)
|= [nom=knot ite=item:collections]
^- manx
?> ?=(%raw -.ite)
=/ author (fall (~(get by meta.raw.ite) %author) 'anonymous')
=/ host (fall (~(get by meta.raw.ite) %host) 'anonymous')
=/ date (fall (~(get by meta.raw.ite) %date-created) 'missing date')
;li.mb-6
;div.flex.align-center
;div.mr-2
=urb-component "Sigil"
=urb-ship "{(trip author)}"
=urb-size "18"
=urb-suffix "true";
;div
;a.vanilla.text-mono.text-small.text-700.mr-4
=href "/~~/{(trip host)}/==/web/landscape/profile"
; {(trip author)}
==
==
;div.text-host-breadcrumb
=urb-component "Elapsed"
=urb-timestring "{(trip date)}";
==
;div.collection-comment-content
;+ elm:(static:cram (ream data.raw.ite))
==
==
==
::
;div
=urb-component "CommentCreate"
=urb-pax "{<(flop /spur)>}"
=urb-ship "{<shp>}";
==
==
::
++ extract-date-created
|= i=item:collections
^- @da
?- -.i
%error *@da
%collection date-created.meta.col.i
%both date-created.meta.col.i
%raw (slav %da (~(got by meta.raw.i) %date-created))
==
::
::
::
++ item-to-snip
|= [nom=knot itm=item:collections]
^- manx
?- -.itm
%error
;div: Invalid collection
%collection
(collection-to-snip nom col.itm)
%raw
(raw-to-snip nom raw.itm)
%both
(both-to-snip nom col.itm raw.itm)
==
::
++ collection-to-snip
|= [nom=knot col=collection:collections]
^- manx
=/ lnk=tape
"/~landscape/collections/{<shp>}/{(scow %p p.full-path.meta.col)}/{(spud (flop (slag 1 s.full-path.meta.col)))}"
;div
;div.collection-date: {<date-created.meta.col>}
;h2.mt-0.mb-0
;a(href lnk): {(trip name.meta.col)}
==
;div.who.text-mono.text-600: {<author.meta.col>}
;div.meta-cont
;div.com-count.ml-12
; {(trip (scot %ud ~(wyt by data.col)))} comments
==
==
==
::
++ raw-to-snip
|= [nom=knot raw=raw-item:collections]
^- manx
=/ elm=manx elm:(static:cram (ream data.raw))
=/ ht (hedtal:collections +.elm)
=? tal.ht ?=(~ hed.ht)
(scag 5 c.elm)
=/ title (fall (~(get by meta.raw) %name) nom)
=/ date (fall (~(get by meta.raw) %date-created) 'missing date')
=/ author (fall (~(get by meta.raw) %author) 'anonymous')
=/ lnk=tape
"/~landscape/collections/{<shp>}/{(scow %da col)}/{(trip nom)}"
::
;div
;div.collection-date: {(trip date)}
;h2
;+ ?~ hed.ht
;a(href lnk): {(trip title)}
;a(href lnk): *{hed.ht}
==
;div.who.text-mono.text-600: {(trip author)}
;div.snippet
;* tal.ht
==
==
::
++ both-to-snip
|= [nom=knot col=collection:collections raw=raw-item:collections]
^- manx
=/ elm=manx elm:(static:cram (ream data.raw))
=/ ht (hedtal:collections +.elm)
=? tal.ht ?=(~ hed.ht)
(scag 5 c.elm)
=/ title (fall (~(get by meta.raw) %name) nom)
=/ lnk=tape
"/~landscape/collections/{<shp>}/{(scow %da ^col)}/{(trip nom)}"
::
;div
;div.collection-date: {<date-created.meta.col>}
;h2.mt-0.mb-0.text-500
;+ ?~ hed.ht
;a(href lnk): {(trip title)}
;a(href lnk): *{hed.ht}
==
;div.text-mono.text-small.text-300.mt-1.mb-1: {<author.meta.col>}
;div
;div.icon-label.justify-start
;div(urb-component "IconComment");
;div.ml-2
; {(trip (scot %ud ~(wyt by data.col)))}
==
==
==
==
::
++ meta-to-elem
|= itm=item:collections
^- manx
=/ mat=mart
:~ [%type "hidden"]
[%name "urb-metadata"]
==
:_ ~
:- %input
%+ weld mat
^- mart
?- -.itm
%error ~
%collection
=* met meta.col.itm
:~ [%urb-name (trip name.met)]
[%urb-author (scow %p author.met)]
[%urb-host (scow %p p.full-path.met)]
[%urb-date-created (scow %da date-created.met)]
[%urb-last-modified (scow %da last-modified.met)]
[%urb-content-type (trip type.met)]
[%urb-structure-type "collection-index"]
[%urb-path (spud /web/collections/(scot %da date-created.meta.col.itm))]
[%urb-show "default"]
==
%raw
=/ met ~(got by meta.raw.itm)
:~ [%urb-name (trip (met %name))]
[%urb-author (trip (met %author))]
[%urb-host (trip (met %host))]
[%urb-date-created (trip (met %date-created))]
[%urb-last-modified (trip (met %last-modified))]
[%urb-content-type (trip (met %type))]
[%urb-structure-type "collection-post"]
[%urb-path (spud (flop /web/collections/raw))]
[%urb-show "default"]
==
%both
=/ met ~(got by meta.raw.itm)
:~ [%urb-name (trip (met %name))]
[%urb-author (trip (met %author))]
[%urb-host (trip (met %host))]
[%urb-date-created (trip (met %date-created))]
[%urb-last-modified (trip (met %last-modified))]
[%urb-content-type (trip (met %type))]
[%urb-structure-type "collection-post"]
[%urb-path (spud (flop /web/collections/both))]
[%urb-show "default"]
==
==
--

View File

@ -0,0 +1,18 @@
::
::::
::
|= [shp=@p col=@da]
^- manx
;div.container
;div
=urb-component "TopicCreatePage"
=urb-ship "{<shp>}"
=urb-claypath "{<col>}"
=urb-content "";
;input
=type "hidden"
=name "urb-header"
=value "collection-post-default"
=station "query"
=urb-structure-type "collection-index";
==

View File

@ -1,5 +1,4 @@
^- manx
;div
;div(urb-component "InboxPage");
;input(type "hidden", name "urb-metadata", urb-structure-type "header-inbox");

22
app/landscape/index.hoon Normal file
View File

@ -0,0 +1,22 @@
|= inner=manx
^- manx
;html
::
;head
;title: Landscape
;meta(charset "utf-8");
;meta
=name "viewport"
=content "width=device-width, initial-scale=1, shrink-to-fit=no";
;link(rel "stylesheet", href "/~landscape/css.css");
;script@"/~/channel/channel.js";
;script@"/session.js";
==
::
;body
;div#root
;+ inner
==
;script@"/~landscape/js.js";
==
==

1
app/landscape/js/index-min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,26 @@
|= who=@t
^- manx
;div
;input(type "hidden", name "urb-metadata", urb-structure-type "header-profile", urb-author "{(trip who)}");
;div.container
;div.row
;div.flex-col-2;
;div.flex-col-x
;div.profile-avatar
;div(urb-component "Sigil", urb-size "320", urb-ship "{(trip who)}", urb-suffix "false");
;div(urb-component "ProfileMsgBtn", urb-ship "{(trip who)}");
==
==
==
;div.row.mt-9
;div.flex-offset-2.flex-col-x
;h2.text-500: Meta
==
==
;div.row.mt-4.align-center
;div.flex-col-2;
;h3.text-500.flex-col-1.mt-0: Started:
;div.flex-col-x.text-mono: ~2018.4.12..6.45.12
==
==
==

212
app/modulo.hoon Normal file
View File

@ -0,0 +1,212 @@
/- *modulo
/+ *server
/= index
/^ octs
/; as-octs:mimes:html
/: /===/app/modulo/index
/| /html/
/~ ~
==
/= modulo-js
/^ octs
/; as-octs:mimes:html
/: /===/app/modulo/script
/| /js/
/~ ~
==
=, format
|%
:: +move: output effect
::
+$ move [bone card]
:: +card: output effect payload
::
+$ card
$% [%connect wire binding:http-server term]
[%serve wire binding:http-server generator:http-server]
[%disconnect wire binding:http-server]
[%http-response =http-event:http]
[%poke wire dock poke]
[%diff %json json]
==
+$ poke
$% [%modulo-bind app=term]
[%modulo-unbind app=term]
==
::
+$ state
$% $: %0
session=(map term @t)
order=(list term)
cur=(unit [term @])
==
==
::
++ session-as-json
|= [cur=(unit [term @]) session=(map term @t) order=(list term)]
^- json
?~ cur
*json
%- pairs:enjs
:~ [%app %s -.u.cur]
[%url %s (~(got by session) -.u.cur)]
:- %list
:- %a
%+ turn order
|= [a=term]
[%s a]
==
::
--
::
|_ [bow=bowl:gall sta=state]
::
++ this .
::
++ prep
|= old=(unit *)
^- (quip move _this)
?~ old
:_ this
[ost.bow %connect / [~ /] %modulo]~
[~ this]
::
:: alerts us that we were bound. we need this because the vane calls back.
::
++ bound
|= [wir=wire success=? binding=binding:http-server]
^- (quip move _this)
[~ this]
::
++ peer-applist
|= [pax=path]
^- (quip move _this)
:_ this
[ost.bow %diff %json (session-as-json cur.sta session.sta order.sta)]~
::
++ session-js
^- octs
:: ?~ cur.sta
:: *octs
%- as-octt:mimes:html
;: weld
:: (trip 'window.onload = function() {')
"window.ship = '{+:(scow %p our.bow)}';"
"window.urb = new Channel();"
==
:: (trip '};')
:: ==
:: " window.state = "
:: (en-json:html (session-as-json cur.sta session.sta order.sta))
:: (trip '}();')
:: %- trip
:: '''
:: document.onkeydown = (event) => {
:: if (!event.metaKey || event.keyCode !== 75) { return; }
:: window.parent.postMessage("commandPalette", "*");
:: };
:: '''
::
:: +poke-handle-http-request: received on a new connection established
::
++ poke-handle-http-request
%- (require-authorization:app ost.bow move this)
|= =inbound-request:http-server
^- (quip move _this)
::
=/ request-line (parse-request-line url.request.inbound-request)
=/ site (flop site.request-line)
?~ site
[[ost.bow %http-response (redirect:app '~landscape')]~ this]
?+ site
[[ost.bow %http-response (html-response:app index)]~ this]
[%session *]
[[ost.bow %http-response (js-response:app session-js)]~ this]
[%script *]
[[ost.bow %http-response (js-response:app modulo-js)]~ this]
==
:: +poke-handle-http-cancel: received when a connection was killed
::
++ poke-handle-http-cancel
|= =inbound-request:http-server
^- (quip move _this)
:: the only long lived connections we keep state about are the stream ones.
::
[~ this]
::
++ poke-modulo-bind
|= bin=term
^- (quip move _this)
=/ url (crip "~{(scow %tas bin)}")
?: (~(has by session.sta) bin)
[~ this]
:- [`move`[ost.bow %connect / [~ /[url]] bin] ~]
%= this
session.sta
(~(put by session.sta) bin url)
::
order.sta
(weld order.sta ~[bin])
::
cur.sta
?~ cur.sta `[bin 0]
cur.sta
==
::
++ poke-modulo-unbind
|= bin=term
^- (quip move _this)
=/ url (crip "~{(scow %tas bin)}")
?. (~(has by session.sta) bin)
[~ this]
=/ ind (need (find ~[bin] order.sta))
=/ neworder (oust [ind 1] order.sta)
:- [`move`[ost.bow %disconnect / [~ /(crip "~{(scow %tas bin)}")]] ~]
%= this
session.sta (~(del by session.sta) bin)
order.sta neworder
cur.sta
::
?: =(1 (lent order.sta))
~
?: (lth ind +:(need cur.sta))
`[-:(need cur.sta) (dec +:(need cur.sta))]
?: =(ind +:(need cur.sta))
`[(snag 0 neworder) 0]
cur.sta
==
::
++ poke-modulo-command
|= com=command
^- (quip move _this)
=/ length (lent order.sta)
?~ cur.sta
[~ this]
?: =(length 1)
[~ this]
=/ new-cur=(unit [term @])
?- -.com
%forward
?: =((dec length) +.u.cur.sta)
`[(snag 0 order.sta) 0]
=/ ind +(+.u.cur.sta)
`[(snag ind order.sta) ind]
%back
?: =(0 +.u.cur.sta)
=/ ind (dec length)
`[(snag ind order.sta) ind]
=/ ind (dec +.u.cur.sta)
`[(snag ind order.sta) ind]
%go
=/ ind (find [app.com]~ order.sta)
?~ ind
cur.sta
`[app.com u.ind]
==
:_ this(cur.sta new-cur)
%+ turn (prey:pubsub:userlib /applist bow)
|= [=bone ^]
[bone %diff %json (session-as-json new-cur session.sta order.sta)]
::
--

28
app/modulo/index.html Normal file
View File

@ -0,0 +1,28 @@
<!doctype html>
<html>
<head>
<script type="application/javascript" src="~/channel/channel.js"></script>
<script type="application/javascript" src="/session.js"></script>
<style type="text/css">
.command-palette {
position: relative;
background-color: #f6f6f6;
top:10%;
left:10%;
width: 80%;
border: none;
outline: none;
height: 48px;
font-size: 20px;
line-height: 48px;
}
</style>
</head>
<body>
<div id="frame"></div>
<div id="popup" style="display:hidden;">
<input id="input" class="command-palette" type="text" style="visibility:hidden !important;" />
</div>
<script type="application/javascript" src="/script.js"></script>
</body>
</html>

69
app/modulo/script.js Normal file
View File

@ -0,0 +1,69 @@
function setFrame() {
let iframe = document.createElement('iframe');
iframe.setAttribute('src', window.state.url);
iframe.setAttribute('width', '100%;');
iframe.setAttribute('height', '100%;');
iframe.setAttribute('style', 'border-style: none !important;');
let inner = document.getElementById("frame");
inner.innerHTML = "";
inner.appendChild(iframe);
iframe.focus();
}
function doSub() {
window.urb.subscribe(window.ship, "modulo", "/applist",
(err) => {
console.log(err);
},
(event) => {
console.log(event);
window.state = event;
setFrame();
},
() => {
doSub();
}
);
}
var palette = false;
window.addEventListener("message", (event) => {
let popup = document.getElementById("popup");
let input = document.getElementById("input");
if (palette) {
palette = false;
popup.style = "display:hidden;";
input.style = "visibility:hidden !important;";
input.value = "";
} else {
palette = true;
popup.style = "position:absolute; left: 0; top: 0; display:block; width: 100%; height: 100%; margin: 0 0; background-color:white;";
input.style = "";
input.focus();
input.addEventListener("keyup", (e) => {
if (e.keyCode !== 13) { return; }
popup.style = "display:hidden;";
popup.style = "visibility:hidden !important;";
window.urb.poke(window.ship, "modulo", "modulo-command",
{
go: input.value
},
(json) => {
console.log(json);
},
(err) => {
console.log(err);
}
);
});
}
});
setFrame();
doSub();

View File

@ -79,13 +79,21 @@
=+ myr=(clan:title our)
::
?: ?=($pawn myr)
[[%base %collections] [%base %hall] [%base %talk] [%base %dojo] ~]
:~ [%base %collections]
[%base %hall]
[%base %talk]
[%base %dojo]
[%base %landscape]
[%base %modulo]
==
:~ [%home %collections]
[%home %acme]
[%home %dns]
[%home %dojo]
[%home %hall]
[%home %talk]
[%home %landscape]
[%home %modulo]
==
::
++ deft-fish :: default connects

121
lib/server.hoon Normal file
View File

@ -0,0 +1,121 @@
=, http-server
|%
::
:: +parse-request-line: take a cord and parse out a url
::
++ parse-request-line
|= url=@t
^- [[ext=(unit @ta) site=(list @t)] args=(list [key=@t value=@t])]
(fall (rush url ;~(plug apat:de-purl:html yque:de-purl:html)) [[~ ~] ~])
::
++ manx-to-octs
|= man=manx
^- octs
(as-octt:mimes:html (en-xml:html man))
::
++ json-to-octs
|= jon=json
^- octs
(as-octt:mimes:html (en-json:html jon))
::
++ app
|%
::
:: +require-authorization: redirect to the login page when unauthenticated
::
++ require-authorization
|* [=bone move=mold this=*]
|= handler=$-(inbound-request:http-server (quip move _this))
|= =inbound-request:http-server
^- (quip move _this)
::
?: authenticated.inbound-request
(handler inbound-request)
::
:_ this
^- (list move)
=/ redirect=cord
%- crip
"/~/login?redirect={(trip url.request.inbound-request)}"
[bone [%http-response %start [307 ['location' redirect]~] ~ %.y]]~
::
++ html-response
|= oct-html=octs
^- http-event:http
[%start [200 ['content-type' 'text/html']~] [~ oct-html] %.y]
::
++ js-response
|= oct-js=octs
^- http-event:http
[%start [200 ['content-type' 'application/js']~] [~ oct-js] %.y]
::
++ json-response
|= oct-js=octs
^- http-event:http
[%start [200 ['content-type' 'application/json']~] [~ oct-js] %.y]
::
++ css-response
|= oct-css=octs
^- http-event:http
[%start [200 ['content-type' 'text/css']~] [~ oct-css] %.y]
::
++ not-found
^- http-event:http
[%start [404 ~] ~ %.y]
::
++ login-redirect
|= =inbound-request:http-server
^- http-event:http
=/ redirect=cord
%- crip
"/~/login?redirect={(trip url.request.inbound-request)}"
[%start [307 ['location' redirect]~] ~ %.y]
::
++ redirect
|= redirect=cord
^- http-event:http
[%start [307 ['location' redirect]~] ~ %.y]
::
--
++ gen
|%
::
++ html-response
|= =octs
^- simple-payload:http
[[200 ['content-type' 'text/html']~] `octs]
::
++ js-response
|= =octs
^- simple-payload:http
[[200 ['content-type' 'application/js']~] `octs]
::
++ json-response
|= =octs
^- simple-payload:http
[[200 ['content-type' 'application/json']~] `octs]
::
++ css-response
|= =octs
^- simple-payload:http
[[200 ['content-type' 'text/css']~] `octs]
::
++ not-found
^- simple-payload:http
[[404 ~] ~]
::
++ login-redirect
|= =request:http
^- simple-payload:http
=/ redirect=cord
%- crip
"/~/login?redirect={(trip url.request)}"
[[307 ['location' redirect]~] ~]
::
++ redirect
|= redirect=cord
^- simple-payload:http
[[307 ['location' redirect]~] ~]
::
--
--

6
mar/modulo/bind.hoon Normal file
View File

@ -0,0 +1,6 @@
|_ ter=term
++ grab
|%
++ noun term
--
--

14
mar/modulo/command.hoon Normal file
View File

@ -0,0 +1,14 @@
/- *modulo
=, format
|_ com=command
++ grab
|%
++ noun command
++ json
%- of:dejs
:~ forward+ul:dejs
back+ul:dejs
go+(su:dejs sym)
==
--
--

6
mar/modulo/unbind.hoon Normal file
View File

@ -0,0 +1,6 @@
|_ ter=term
++ grab
|%
++ noun term
--
--

7
sur/modulo.hoon Normal file
View File

@ -0,0 +1,7 @@
|%
+$ command
$% [%forward ~]
[%back ~]
[%go app=term]
==
--

View File

@ -1326,10 +1326,11 @@
$wind `%j
$wipe `%f
::
$request `%l
$serve `%r
$connect `%r
$rule `%r
$request `%l
$serve `%r
$connect `%r
$disconnect `%r
$rule `%r
==
--
--

View File

@ -626,10 +626,6 @@
return this.requestId++;
}
};
export function newChannel() {
return new Channel;
}
'''
:: +format-ud-as-integer: prints a number for consumption outside urbit
::
@ -856,16 +852,22 @@
%- crip
"urbauth={<session>}; Path=/; Max-Age=86400"
::
=/ new-location=@t
?~ redirect=(get-header:http 'redirect' u.parsed)
'/'
u.redirect
?~ redirect=(get-header:http 'redirect' u.parsed)
%- handle-response
:* %start
:- status-code=200
^= headers
:~ ['set-cookie' cookie-line]
==
data=~
complete=%.y
==
::
%- handle-response
:* %start
:- status-code=307
^= headers
:~ ['location' new-location]
:~ ['location' u.redirect]
['set-cookie' cookie-line]
==
data=~
@ -1333,10 +1335,13 @@
|= [channel-id=@t json-text=wall]
^- [(list move) server-state]
::
=/ channel=channel
(~(got by session.channel-state.state) channel-id)
=/ channel=(unit channel)
(~(get by session.channel-state.state) channel-id)
?~ channel
~& [%received-event-for-nonexistent-channel channel-id]
[~ state]
::
=/ event-id next-id.channel
=/ event-id next-id.u.channel
::
=/ event-stream-lines=wall
%- weld :_ [""]~
@ -1346,10 +1351,10 @@
(weld "data: " tape)
:: if a client is connected, send this event to them.
::
=? moves ?=([%| *] state.channel)
=? moves ?=([%| *] state.u.channel)
^- (list move)
:_ moves
:+ p.state.channel %give
:+ p.state.u.channel %give
^- gift:able:http-server
:* %response %continue
::

View File

@ -1,12 +0,0 @@
::
::::
::
/= gas /$ fuel:html
^- manx
;div
;div
=urb-component "Details"
=urb-ship "{(scow %p p.bem.gas)}"
=urb-path "{<(flop s.bem.gas)>}";
;input(type "hidden", name "urb-header", value "collection-write", station "query");
==

View File

@ -1,21 +0,0 @@
::
::::
::
/+ collections
/= gas /$ fuel:html
=/ sho=@t (fall (~(get by qix.gas) %show) %default)
|= [raw=(unit raw-item:collections) pax=path]
=/ body ?~(raw '' data.u.raw)
=/ front ?~(raw ~ meta.u.raw)
=/ lastmod (fall (~(get by front) %last-modified) ~.missing-date)
^- manx
;div
;div
=urb-component "TopicCreatePage"
=urb-ship "{(scow %p p.bem.gas)}"
=urb-claypath "{<pax>}"
=urb-content "{(trip body)}"
=urb-show "{(trip sho)}"
=urb-lastedit "{(trip lastmod)}";
;input(type "hidden", name "urb-header", value "collection-write", station "query");
==

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
{"onboard":true}

View File

@ -1,40 +0,0 @@
/+ collections
/= gas /$ fuel:html
|%
:: is this collection on the profile?
++ is-pro
|= col=collection:collections
visible.meta.col
--
^- manx
;div
;input(type "hidden", name "urb-metadata", urb-structure-type "header-profile", urb-author "{(scow %p p.bem.gas)}");
;div.container
;div.row
;div.flex-col-2;
;div.flex-col-x
;div.profile-avatar
;div(urb-component "Sigil", urb-size "310", urb-ship "{(scow %p p.bem.gas)}", urb-suffix "false");
;div(urb-component "ProfileMsgBtn", urb-ship "{(scow %p p.bem.gas)}");
==
==
==
;div.row.mt-9
;div.flex-offset-2.flex-col-x
;h2.text-500: Meta
==
==
;div.row.mt-4.align-center
;div.flex-col-2;
;h3.text-500.flex-col-1.mt-0: Started:
;div.flex-col-x.text-mono: ~2018.4.12..6.45.12
==
;div.row.mt-3.align-center
;div.flex-col-2;
;h3.text-500.flex-col-1.mt-0: Issued:
;div.flex-col-x
;a.text-mono(href "/~~/{(scow %p (^sein:title p.bem.gas))}/==/web/landscape/profile"): {(scow %p (^sein:title p.bem.gas))}
==
==
==
==

View File

@ -1,38 +0,0 @@
/= gas /$ fuel:html
/= error /: /===/web/404 /!hymn/
:: only authenticated user should be allowed to see this
::
?. (~(has in (~(got by aut.ced.gas) %$)) (scot %p p.bem.gas))
error
=/ cod=tape
%+ slag 1
%+ scow %p
.^(@p %j /(scot %p p.bem.gas)/code/(scot r.bem.gas)/(scot %p p.bem.gas))
^- manx
;div
;input(type "hidden", name "urb-metadata", urb-structure-type "header-profile", urb-author "{(scow %p p.bem.gas)}");
;div.container(urb-devices "")
;div.row.mt-4
;div.flex-col-2;
;div.flex-col-x
;a.vanilla.btn.btn-primary(href (trip 'javascript:(function(){document.querySelectorAll("[urb-devices]")[0].classList.add("hide"); document.querySelectorAll("[urb-qr]")[0].classList.remove("hide");})()')): Connect device
;div.mt-6
;a.h3.vanilla.text-red(href "javascript:void(0)"): Log Out ↓
==
==
==
==
;div.container.hide(urb-qr "")
;div.row.mt-4
;div.flex-col-2;
;div.flex-col-x
;div
=urb-component "QRCodeComponent"
=urb-ship "{(scow %p p.bem.gas)}"
=urb-code "{cod}";
;h2.mt-8.mt-0.text-500.profile-qr-desc: Scan this code to connect your device
;a.mt-4.vanilla.btn.btn-primary(href (trip 'javascript:(function(){document.querySelectorAll("[urb-qr]")[0].classList.add("hide"); document.querySelectorAll("[urb-devices]")[0].classList.remove("hide");})()')): Done
==
==
==
==

View File

@ -1,3 +0,0 @@
^- manx
;div(urb-component "StreamCreatePage");