First cut of webapps.site-watcheR

db4
Slava Pestov 2009-03-15 20:13:17 -05:00
parent 710ce74512
commit dacf1910dc
3 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1 @@
Slava Pestov

View File

@ -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>

View File

@ -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