collections fixes: post editing, parent config, sorting

This commit is contained in:
Isaac Visintainer 2018-09-12 14:36:50 -07:00 committed by ixv
parent e094ce8984
commit 026f02cb63
5 changed files with 181 additions and 144 deletions

View File

@ -3,7 +3,7 @@
::
/? 309
/- hall
/+ collections
/+ collections, cram
::
:: cols:
::
@ -151,9 +151,19 @@
|= [pax=path raw=raw-item]
^- json
=/ owner (fall (~(get by meta.raw) %owner) ~.anon)
=/ dat (fall (~(get by meta.raw) %last-modified) (scot %da now.bol))
=/ nom (fall (~(get by meta.raw) %name) ~.no-title)
=/ typ (fall (~(get by meta.raw) %type) ~.no-type)
=/ dat (fall (~(get by meta.raw) %last-modified) (scot %da now.bol))
=/ nom (fall (~(get by meta.raw) %name) ~.no-title)
=/ typ (fall (~(get by meta.raw) %type) ~.no-type)
::
=/ elm=manx elm:(static:cram (ream data.raw))
=/ snip=marl tal:(hedtal +.elm)
=/ inner (crip (en-xml:html -.snip)) :: inner html
::
=/ parent-spur [%collections-config (slag 1 (flop pax))]
=/ bek=beak byk.bol(r [%da now.bol])
=/ parent-path (en-beam:format [bek parent-spur])
=/ parent-conf (config-to-json .^(config %cx parent-path))
::
%- pairs:enjs:format
:~ ['owner' [%s owner]]
['path' [%a (turn pax |=(a=@ta `json`[%s a]))]]
@ -161,6 +171,8 @@
['date' [%s dat]]
['type' [%s typ]]
['content' [%s data.raw]]
['snip' [%s inner]]
['parent-config' parent-conf]
==
::
:: +front-to-wain: XX
@ -267,9 +279,10 @@
?~ acts.act ta-this
=* a i.acts.act
::
=/ sap (en-beam:format [byk.bol (flop (path +<.a))])
=/ now-id=@da (sub now.bol (div (dis now.bol ~s0..fffe) 2))
=/ dat (scot %da now-id)
=/ bek=beak byk.bol(r [%da now-id])
=/ sap (en-beam:format [bek (flop (path +<.a))])
::
=. ta-this
?- -.a
@ -302,7 +315,7 @@
?. (allowed-by src.bol +.perms)
ta-this
=/ conf=config
:* [byk.bol (flop (weld pax.a /[dat]/collections-config))]
:* [bek (flop (weld pax.a /[dat]/collections-config))]
name.a
desc.a
our.bol
@ -329,7 +342,11 @@
ta-this
::
%post
=/ perms .^([dict:clay dict:clay] %cp (weld sap /[dat]/umd))
=? pax.a !edit.a
(weld pax.a /[dat])
=? sap !edit.a
(en-beam:format [bek (flop pax.a)])
=/ perms .^([dict:clay dict:clay] %cp (weld sap /umd))
?. (allowed-by src.bol +.perms)
ta-this
=. content.a (crip (weld (trip content.a) "\0a"))
@ -343,16 +360,16 @@
[%type type.a]
==
=. ta-this
%+ ta-write (weld pax.a /[dat]/umd)
%+ ta-write (weld pax.a /umd)
[%umd !>((update-umd-front front content.a))]
:: restrict permissions on umd file
=. ta-this
%^ ta-set-permissions (weld pax.a /[dat]/umd)
%^ ta-set-permissions (weld pax.a /umd)
[%black ((set whom:clay) ~)] :: read
[%white ((set whom:clay) [[& src.bol] ~ ~])] :: write
:: open permissions on comments
=. ta-this
%^ ta-set-permissions (weld pax.a /[dat])
%^ ta-set-permissions pax.a
[%black ((set whom:clay) ~)] :: read
[%black ((set whom:clay) ~)] :: write
ta-this
@ -634,10 +651,11 @@
|= pax=path
^+ ta-this
=/ sup=path [%collections-config (flop pax)]
=/ pat (en-beam:format [byk.bol sup])
=/ bek byk.bol(r [%da now.bol])
=/ pat (en-beam:format [bek sup])
=/ dat=@da (slav %da (snag 0 (flop pax)))
=/ cay=config
:* [byk.bol sup]
:* [bek sup]
'comments'
'comments'
our.bol
@ -655,13 +673,15 @@
++ ta-write
|= [pax=path cay=cage]
^+ ta-this
=. pax (en-beam:format byk.bol (flop pax))
=/ bek byk.bol(r [%da now.bol])
=. pax (en-beam:format bek (flop pax))
%+ ta-emit ost.bol
[%info (weld /ta-write pax) our.bol (foal pax cay)]
::
++ ta-remove
|= pax=path
=. pax (en-beam:format byk.bol (flop pax))
=/ bek byk.bol(r [%da now.bol])
=. pax (en-beam:format bek (flop pax))
^+ ta-this
%+ ta-emit ost.bol
[%info (weld /ta-remove pax) our.bol (fray pax)]

View File

@ -2,7 +2,7 @@
:::: /hoon/collections/lib
::
/? 309
/+ cram
/+ cram, elem-to-react-json
::
::
|%
@ -45,7 +45,7 @@
[%perms pax=path r=rule:clay w=rule:clay]
::
[%collection pax=path name=@t desc=@t comments=? visible=? type=@tas]
[%post pax=path name=@t type=@tas comments=? content=@t]
[%post pax=path name=@t type=@tas comments=? content=@t edit=?]
[%comment pax=path content=@t]
==
::
@ -53,5 +53,122 @@
$% [%umd @t]
[%collections-config config]
==
::::
:::: /mar/snip
::::
++ words 1
++ hedtal
=| met/marl
|= a/marl ^- {hed/marl tal/marl}
?~ a [~ ~]
:: looks like it only terminates if it finds an h1?
?. ?=($h1 n.g.i.a)
?: ?=($meta n.g.i.a)
$(a t.a, met [i.a met])
=+ had=$(a c.i.a)
?^ -.had had
$(a t.a)
[c.i.a (weld (flop met) (limit words t.a))]
::
::
++ limit
|= {lim/@u mal/marl}
=< res
|- ^- {rem/@u res/marl}
?~ mal [lim ~]
?~ lim [0 ~]
=+ ^- {lam/@u hed/manx}
?: ?=(_;/(**) i.mal)
[lim ;/(tay)]:(deword lim v.i.a.g.i.mal)
[rem ele(c res)]:[ele=i.mal $(mal c.i.mal)]
[rem - res]:[hed $(lim lam, mal t.mal)]
::
++ deword
|= {lim/@u tay/tape} ^- {lim/@u tay/tape}
?~ tay [lim tay]
?~ lim [0 ~]
=+ wer=(dot 1^1 tay)
?~ q.wer
[lim - tay]:[i.tay $(tay t.tay)]
=+ nex=$(lim (dec lim), tay q.q.u.q.wer)
[-.nex [(wonk wer) +.nex]]
::
:: json
::
++ item-to-json
|= itm=item
^- json
?- -.itm
::
%collection
%+ frond:enjs:format
%collection (collection-to-json col.itm)
::
%raw
%- frond:enjs:format
[%item (raw-to-json raw.itm)]
::
%both
%- pairs:enjs:format
:~ [%item (raw-to-json raw.itm)]
[%collection (collection-to-json col.itm)]
==
==
::
++ collection-to-json
|= col=collection
^- json
%- pairs:enjs:format
:~ [%meta (config-to-json meta.col)]
:+ %data %a
%+ turn ~(tap by data.col)
|= [nom=knot ite=item]
^- json
%- pairs:enjs:format
:~ [%filename %s nom]
[%item (item-to-json ite)]
==
==
::
++ raw-to-json
|= raw=raw-item
^- json
=/ elm=manx elm:(static:cram (ream data.raw))
=/ rec=json (elem-to-react-json elm)
%- pairs:enjs:format
:~ [%data rec]
[%meta (meta-to-json meta.raw)]
==
::
++ config-to-json
|= con=config
^- json
?: =(con *config)
~
%- pairs:enjs:format
:~ :- %full-path
:- %a
%+ turn (en-beam:format full-path.con)
|= a=@ta
[%s a]
:- %name [%s name.con]
:- %desc [%s description.con]
:- %owner (ship:enjs:format owner.con)
:- %date-created (time:enjs:format date-created.con)
:- %last-modified (time:enjs:format last-modified.con)
:- %type [%s type.con]
:- %comments [%b comments.con]
:- %sort-key ?~(sort-key.con ~ (numb:enjs:format u.sort-key.con))
:- %visible [%b visible.con]
==
::
++ meta-to-json
|= meta=(map knot cord)
^- json
%- pairs:enjs:format
%+ turn ~(tap by meta)
|= [key=@t val=@t]
^- [@t json]
[key [%s val]]
::
--

View File

@ -90,6 +90,7 @@
type+(su:dejs sym)
comments+bo:dejs
content+so:dejs
edit+bo:dejs
==
::
++ comment

View File

@ -59,7 +59,12 @@
|= col=collection:collections
^- manx
;ul.vanilla
;* %+ turn ~(tap by data.col)
;* %+ 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)
(lth a-dat b-dat)
|= [nom=knot ite=item:collections]
^- manx
;li.collection-post.mt-6
@ -71,7 +76,7 @@
|= raw=raw-item:collections
^- manx
=/ elm elm:(static:cram (ream data.raw))
=/ ht (hedtal +.elm)
=/ ht (hedtal:collections +.elm)
=/ title (fall (~(get by meta.raw) %name) -.s.bem.gas)
=/ date (fall (~(get by meta.raw) %date-created) 'missing date')
=/ owner (fall (~(get by meta.raw) %owner) 'anonymous')
@ -109,7 +114,12 @@
==
::
;ul
;* %+ turn ~(tap by data.col) :: XX TODO: sort
;* %+ 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
:: XX TODO: accept types other than comments
@ -139,6 +149,16 @@
==
==
::
++ extract-date-created
|= i=item:collections
^- @da
?- -.i
%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]
@ -174,7 +194,7 @@
|= [nom=knot raw=raw-item:collections]
^- manx
=/ elm=manx elm:(static:cram (ream data.raw))
=/ ht (hedtal +.elm)
=/ ht (hedtal:collections +.elm)
=? tal.ht ?=(~ hed.ht)
(scag 5 c.elm)
=/ title (fall (~(get by meta.raw) %name) nom)
@ -200,7 +220,7 @@
|= [nom=knot col=collection:collections raw=raw-item:collections]
^- manx
=/ elm=manx elm:(static:cram (ream data.raw))
=/ ht (hedtal +.elm)
=/ ht (hedtal:collections +.elm)
=? tal.ht ?=(~ hed.ht)
(scag 5 c.elm)
=/ title (fall (~(get by meta.raw) %name) nom)
@ -265,46 +285,4 @@
[%urb-structure-type "collection-post"]
==
==
::::
:::: /mar/snip
::::
++ words 1
++ hedtal
=| met/marl
|= a/marl ^- {hed/marl tal/marl}
?~ a [~ ~]
:: looks like it only terminates if it finds an h1?
?. ?=($h1 n.g.i.a)
?: ?=($meta n.g.i.a)
$(a t.a, met [i.a met])
=+ had=$(a c.i.a)
?^ -.had had
$(a t.a)
[c.i.a (weld (flop met) (limit words t.a))]
::
::
++ limit
|= {lim/@u mal/marl}
=< res
|- ^- {rem/@u res/marl}
?~ mal [lim ~]
?~ lim [0 ~]
=+ ^- {lam/@u hed/manx}
?: ?=(_;/(**) i.mal)
[lim ;/(tay)]:(deword lim v.i.a.g.i.mal)
[rem ele(c res)]:[ele=i.mal $(mal c.i.mal)]
[rem - res]:[hed $(lim lam, mal t.mal)]
::
++ deword
|= {lim/@u tay/tape} ^- {lim/@u tay/tape}
?~ tay [lim tay]
?~ lim [0 ~]
=+ wer=(dot 1^1 tay)
?~ q.wer
[lim - tay]:[i.tay $(tay t.tay)]
=+ nex=$(lim (dec lim), tay q.q.u.q.wer)
[-.nex [(wonk wer) +.nex]]
::
::
::
--

View File

@ -1,88 +1,9 @@
/? 309
/+ collections, cram, elem-to-react-json
/+ collections
/= gas /$ fuel:html
/= jon
/^ json
/; =< item-to-json
|%
::
++ item-to-json
|= itm=item:collections
^- json
?- -.itm
::
%collection
%+ frond:enjs:format
%collection (collection-to-json col.itm)
::
%raw
%- frond:enjs:format
[%item (raw-to-json raw.itm)]
::
%both
%- pairs:enjs:format
:~ [%item (raw-to-json raw.itm)]
[%collection (collection-to-json col.itm)]
==
==
::
++ collection-to-json
|= col=collection:collections
^- json
%- pairs:enjs:format
:~ [%meta (config-to-json meta.col)]
:+ %data %a
%+ turn ~(tap by data.col)
|= [nom=knot ite=item:collections]
^- json
%- pairs:enjs:format
:~ [%filename %s nom]
[%item (item-to-json ite)]
==
==
::
++ raw-to-json
|= raw=raw-item:collections
^- json
=/ elm=manx elm:(static:cram (ream data.raw))
=/ rec=json (elem-to-react-json elm)
%- pairs:enjs:format
:~ [%data rec]
[%meta (meta-to-json meta.raw)]
==
::
++ config-to-json
|= con=config:collections
^- json
?: =(con *config:collections)
~
%- pairs:enjs:format
:~ :- %full-path
:- %a
%+ turn (en-beam:format full-path.con)
|= a=@ta
[%s a]
:- %name [%s name.con]
:- %desc [%s description.con]
:- %owner (ship:enjs:format owner.con)
:- %date-created (time:enjs:format date-created.con)
:- %last-modified (time:enjs:format last-modified.con)
:- %type [%s type.con]
:- %comments [%b comments.con]
:- %sort-key ?~(sort-key.con ~ (numb:enjs:format u.sort-key.con))
:- %visible [%b visible.con]
==
::
++ meta-to-json
|= meta=(map knot cord)
^- json
%- pairs:enjs:format
%+ turn ~(tap by meta)
|= [key=@t val=@t]
^- [@t json]
[key [%s val]]
::
--
/; item-to-json:collections
::
/collections-web-item/
::