]> gitweb.factorcode.org Git - factor.git/commitdiff
ui.frp examples updated
authorSam Anklesaria <sam@Tintin.local>
Sun, 14 Jun 2009 18:08:49 +0000 (13:08 -0500)
committerSam Anklesaria <sam@Tintin.local>
Sun, 14 Jun 2009 18:08:49 +0000 (13:08 -0500)
extra/darcs-ui
extra/recipes/recipes.factor [new file with mode: 0644]

index 4112107342733e412dda8c1b747aa2ec1f27ddb6..e2554b2ebae120bbd315ccbca8aa833bc8cb830e 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 4112107342733e412dda8c1b747aa2ec1f27ddb6
+Subproject commit e2554b2ebae120bbd315ccbca8aa833bc8cb830e
diff --git a/extra/recipes/recipes.factor b/extra/recipes/recipes.factor
new file mode 100644 (file)
index 0000000..788dfb1
--- /dev/null
@@ -0,0 +1,49 @@
+USING: accessors arrays db.tuples db.sqlite persistency
+io.files.temp kernel monads sequences ui ui.frp.gadgets
+ui.frp.layout ui.frp.signals ui.gadgets.scrollers ui.gadgets.labels
+colors.constants ui.pens.solid combinators math locals strings
+ui.tools.inspector ;
+FROM: sets => prune ;
+IN: recipes
+STORED-TUPLE: recipe title votes txt genre ;
+: <recipe> ( title genre text -- recipe ) recipe new swap >>txt swap >>genre swap >>title ;
+"recipes.db" temp-file <sqlite-db> recipe define-db
+: top-recipes ( -- recipes ) <query> T{ recipe } >>tuple "votes" >>order get-tuples ;
+: top-genres ( -- genres ) top-recipes [ genre>> ] map prune 5 (head-slice) ;
+: interface ( -- book ) [ 
+     [
+        [ $ TOOLBAR $ <spacer> $ GENRES $ ] <hbox> { 5 0 } >>gap COLOR: gray <solid> >>interior ,
+        $ RECIPES $
+     ] <vbox> ,
+     [
+        [ "Title:" <label> , $ TITLE $ "Genre:" <label> , $ GENRE $ ] <hbox> ,
+        $ BODY $
+        $ BUTTON $
+     ] <vbox> ,
+  ] <frp-book*> { 350 245 } >>pref-dim ;
+:: recipe-browser ( -- ) [
+    interface
+      <frp-table*> :> tbl
+      "okay" <frp-border-button> BUTTON -> :> ok
+      "Submit Recipe" <frp-button> [ store-tuple ] >>value TOOLBAR -> :> submit
+      submit ok [ [ drop ] ] <$ 2array <merge> [ drop ] >>value :> quot
+      ok t <basic> "all" <frp-button> GENRES -> 3array <merge> [ top-recipes ] <$ :> updates
+      updates [ top-genres UI[ <frp-button> GENRES ->? ] map <merge> ] bind*
+        [ text>> T{ recipe } swap >>genre get-tuples ] fmap
+      tbl swap updates 2array <merge> >>model
+        [ [ title>> ] [ genre>> ] bi 2array ] >>quot
+        { "Title" "Genre" } >>column-titles dup <scroller> RECIPES ,% 1
+        actions>> submit [ "" dup dup <recipe> ] <$ 2array <merge>
+        { [ [ title>> ] fmap <frp-field> TITLE ->% .5 ]
+          [ [ genre>> ] fmap <frp-field> GENRE ->% .5 ]
+          [ [ txt>> ] fmap <frp-editor> BODY ->% 1 ]
+        } cleave
+        [ <recipe> ] 3fmap-|
+      [ [ 1 ] <$ ]
+      [ quot ok <updates> #1 [ call( recipe -- ) 0 ] 2fmap-& ] bi
+      2array <merge> 0 <basic> <switch> >>model
+   ] with-interface "recipes" open-window ;
+
+MAIN: recipe-browser
+
+! should clear out old values on submission
\ No newline at end of file