factor/unmaintained/recipes/recipes.factor

61 lines
2.7 KiB
Factor
Raw Normal View History

USING: accessors arrays colors.constants combinators
db.sqlite db.tuples db.types kernel locals math
monads persistency sequences sequences.extras ui ui.gadgets.controls
ui.gadgets.layout models.combinators ui.gadgets.labels
ui.gadgets.scrollers ui.pens.solid io.files.temp ;
2009-06-14 14:08:49 -04:00
FROM: sets => prune ;
IN: recipes
2009-06-26 16:25:50 -04:00
2009-06-16 15:36:01 -04:00
STORED-TUPLE: recipe { title { VARCHAR 100 } } { votes INTEGER } { txt TEXT } { genre { VARCHAR 100 } } ;
: <recipe> ( title genre text -- recipe ) recipe new swap >>txt swap >>genre swap >>title 0 >>votes ;
"recipes.db" temp-file <sqlite-db> recipe define-db
2009-06-16 15:36:01 -04:00
: top-recipes ( offset search -- recipes ) <query> T{ recipe } rot >>title >>tuple
"votes" >>order 30 >>limit swap >>offset get-tuples ;
: top-genres ( -- genres ) f f top-recipes [ genre>> ] map prune 4 short head-slice ;
2009-06-16 15:36:01 -04:00
2009-06-14 14:08:49 -04:00
: interface ( -- book ) [
[
2009-06-24 21:06:12 -04:00
[ $ TOOLBAR $ ] <hbox> COLOR: AliceBlue <solid> >>interior ,
[ "Genres:" <label> , <spacer> $ ALL $ $ GENRES $ ] <hbox>
2009-06-16 15:36:01 -04:00
{ 5 0 } >>gap COLOR: gray <solid> >>interior ,
2009-06-14 14:08:49 -04:00
$ RECIPES $
] <vbox> ,
[
[ "Title:" <label> , $ TITLE $ "Genre:" <label> , $ GENRE $ ] <hbox> ,
$ BODY $
$ BUTTON $
] <vbox> ,
] <book*> { 350 245 } >>pref-dim ;
2009-06-16 15:36:01 -04:00
2009-06-18 16:32:11 -04:00
:: recipe-browser ( -- ) [ [
2009-06-14 14:08:49 -04:00
interface
<table*> :> tbl
"okay" <model-border-btn> BUTTON -> :> ok
IMG-MODEL-BTN: submit [ store-tuple ] >>value TOOLBAR -> :> submit
IMG-MODEL-BTN: love 1 >>value TOOLBAR ->
IMG-MODEL-BTN: hate -1 >>value -> 2array merge :> votes
IMG-MODEL-BTN: back -> [ -30 ] <$
IMG-MODEL-BTN: more -> [ 30 ] <$ 2array merge :> viewed
<spacer> <model-field*> ->% 1 :> search
submit ok [ [ drop ] ] <$ 2array merge [ drop ] >>value :> quot
viewed 0 [ + ] fold search ok t <basic> "all" <model-btn> ALL ->
2009-08-05 17:24:56 -04:00
tbl selection>> votes [ [ + ] curry change-votes modify-tuple ] 2$>
4array merge
[ drop [ f ] [ "%" dup surround <pattern> ] if-empty top-recipes ] 3fmap :> ups
ups [ top-genres [ <model-btn> GENRES -> ] map merge ] bind*
2009-06-14 14:08:49 -04:00
[ text>> T{ recipe } swap >>genre get-tuples ] fmap
tbl swap ups 2merge >>model
2009-06-14 14:08:49 -04:00
[ [ title>> ] [ genre>> ] bi 2array ] >>quot
2009-06-16 16:50:48 -04:00
{ "Title" "Genre" } >>column-titles dup <scroller> RECIPES ,% 1 actions>>
submit [ "" dup dup <recipe> ] <$ 2array merge
{ [ [ title>> ] fmap <model-field> TITLE ->% .5 ]
[ [ genre>> ] fmap <model-field> GENRE ->% .5 ]
[ [ txt>> ] fmap <model-editor> BODY ->% 1 ]
2009-06-14 14:08:49 -04:00
} cleave
[ <recipe> ] 3fmap
2009-06-14 14:08:49 -04:00
[ [ 1 ] <$ ]
[ quot ok updates #1 [ call( recipe -- ) 0 ] 2fmap ] bi
2merge 0 <basic> switch-models >>model
2009-06-18 16:32:11 -04:00
] with-interface "recipes" open-window ] with-ui ;
2009-06-14 14:08:49 -04:00
2009-06-16 15:36:01 -04:00
MAIN: recipe-browser