From dacf1910dc19a2048ab6f6a250dcb1eaca12239a Mon Sep 17 00:00:00 2001 From: Slava Pestov <slava@slava-pestovs-macbook-pro.local> Date: Sun, 15 Mar 2009 20:13:17 -0500 Subject: [PATCH] First cut of webapps.site-watcheR --- extra/webapps/site-watcher/authors.txt | 1 + extra/webapps/site-watcher/site-list.xml | 41 ++++++++++++++ .../webapps/site-watcher/site-watcher.factor | 54 +++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 extra/webapps/site-watcher/authors.txt create mode 100644 extra/webapps/site-watcher/site-list.xml create mode 100644 extra/webapps/site-watcher/site-watcher.factor diff --git a/extra/webapps/site-watcher/authors.txt b/extra/webapps/site-watcher/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/extra/webapps/site-watcher/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/extra/webapps/site-watcher/site-list.xml b/extra/webapps/site-watcher/site-list.xml new file mode 100644 index 0000000000..9bd1467fc7 --- /dev/null +++ b/extra/webapps/site-watcher/site-list.xml @@ -0,0 +1,41 @@ +<?xml version='1.0' ?> + +<t:chloe xmlns:t="http://factorcode.org/chloe/1.0"> + +<html> + <head> + <title>SiteWatcher</title> + </head> + <body> + <h1>SiteWatcher</h1> + <h2>It tells you if your web site goes down.</h2> + <table> + <t:bind-each t:name="sites"> + <tr> + <td> <t:label t:name="url" /> </td> + <td> <t:button t:action="$site-watcher-app/remove" t:for="url">Remove</t:button> </td> + </tr> + </t:bind-each> + </table> + <p> + <t:button t:action="$site-watcher-app/check">Check now</t:button> + </p> + <hr /> + <h3>Add a new site</h3> + <t:form t:action="$site-watcher-app/add"> + <table> + <tr> + <th>URL:</th> + <td> <t:field t:name="url" t:size="80" /> </td> + </tr> + <tr> + <th>E-mail:</th> + <td> <t:field t:name="email" t:size="80" /> </td> + </tr> + </table> + <p> <button type="submit">Done</button> </p> + </t:form> + </body> +</html> + +</t:chloe> diff --git a/extra/webapps/site-watcher/site-watcher.factor b/extra/webapps/site-watcher/site-watcher.factor new file mode 100644 index 0000000000..a71a14a37a --- /dev/null +++ b/extra/webapps/site-watcher/site-watcher.factor @@ -0,0 +1,54 @@ +! Copyright (C) 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors furnace.actions furnace.alloy furnace.redirection +html.forms http.server http.server.dispatchers namespaces site-watcher +site-watcher.private kernel urls validators db.sqlite assocs ; +IN: webapps.site-watcher + +TUPLE: site-watcher-app < dispatcher ; + +CONSTANT: site-list-url URL" $site-watcher-app/" + +: <site-list-action> ( -- action ) + <page-action> + { site-watcher-app "site-list" } >>template + [ + begin-form + sites get values "sites" set-value + ] >>init ; + +: <add-site-action> ( -- action ) + <action> + [ + { { "url" [ v-url ] } { "email" [ v-email ] } } validate-params + ] >>validate + [ + "email" value "url" value watch-site + site-list-url <redirect> + ] >>submit ; + +: <remove-site-action> ( -- action ) + <action> + [ + { { "url" [ v-url ] } } validate-params + ] >>validate + [ + "url" value delete-site + site-list-url <redirect> + ] >>submit ; + +: <check-sites-action> ( -- action ) + <action> + [ + sites get [ check-sites ] [ report-sites ] bi + site-list-url <redirect> + ] >>submit ; + +: <site-watcher-app> ( -- dispatcher ) + site-watcher-app new-dispatcher + <site-list-action> "" add-responder + <add-site-action> "add" add-responder + <remove-site-action> "remove" add-responder + <check-sites-action> "check" add-responder ; + +<site-watcher-app> "resource:test.db" <sqlite-db> <alloy> main-responder set-global \ No newline at end of file