Finished user-level contact stuff
authorAdam Chlipala <adamc@hcoop.net>
Sat, 16 Apr 2005 21:39:38 +0000 (21:39 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Sat, 16 Apr 2005 21:39:38 +0000 (21:39 +0000)
TODO
contact.mlt
contact.sig
contact.sml
dir.mlt [new file with mode: 0644]
user.mlt [new file with mode: 0644]

diff --git a/TODO b/TODO
index 859db30..f7412b7 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,5 +1,4 @@
 Member data
-       - Contact information
        - Geographic location
        - Hosted web site registry
        - Summarize these with publicly accessible static pages
index 75b6978..eed7986 100644 (file)
@@ -5,6 +5,51 @@ ref showNormal = true;
 if $"cmd" = "add" then
        val id = Contact.addContact (Init.getUserId(), Web.stoi ($"knd"), $"v", Contact.privFromInt (Web.stoi ($"priv"))) %>
        <h3><b>Contact added</b></h3>
+
+<% elseif $"mod" <> "" then
+       showNormal := false;
+       val id = Web.stoi ($"mod");
+       val cont = Contact.lookupContact id %>
+
+<h3><b>Modify contact entry</b></h3>
+
+<form action="contact">
+<input type="hidden" name="save" value="<% id %>">
+<table>
+<tr> <td align="right"><b>Kind</b>:</td> <td><select name="knd">
+<% foreach kind in Contact.listKinds () do %>
+       <option value="<% #id kind %>"<% if #knd cont = #id kind then %> selected<% end %>><% Web.html (#name kind) %></option>
+<% end %>
+</select></td> </tr>
+<tr> <td align="right"><b>Value</b>:</td> <td><input name="v" value="<% Web.html (#v cont) %>"></td> </tr>
+<tr> <td align="right"><b>Readable by</b>:</td> <td><select name="priv">
+       <option value="0"<% if #priv cont = Contact.PUBLIC then %> selected<% end %>>Anyone</option>
+       <option value="1"<% if #priv cont = Contact.MEMBERS then %> selected<% end %>>Members only</option>
+       <option value="2"<% if #priv cont = Contact.ADMINS then %> selected<% end %>>Admins only</option>
+</select></td> </tr>
+<tr> <td><input type="submit" value="Save"></td> </tr>
+</table>
+</form>
+
+<% elseif $"save" <> "" then
+       val id = Web.stoi ($"save");
+       val cont = Contact.lookupContact id;
+       Contact.modContact {cont with knd = Web.stoi ($"knd"), v = $"v", priv = Contact.privFromInt (Web.stoi ($"priv"))} %>
+       <h3><b>Contact entry saved</b></h3>
+
+<% elseif $"del" <> "" then
+       showNormal := false;
+       val id = Web.stoi ($"del");
+       val cont = Contact.lookupContact id %>
+       <h3><b>Are you sure you want to delete contact entry "<% Web.html (#v cont) %>"?</b></h3>
+       <a href="contact?del2=<% id %>">Yes, delete "<% Web.html (#v cont) %>"!</a>
+
+<% elseif $"del2" <> "" then
+       val id = Web.stoi ($"del2");
+       val cont = Contact.lookupContact id;
+       Contact.deleteContact id %>
+       <h3><b>Contact entry "<% Web.html (#v cont) %>" deleted</b></h3>
+
 <% end;
 
 if showNormal then %>
@@ -34,7 +79,13 @@ if showNormal then %>
 <table>
 <% foreach (kind, cont) in Contact.listUserContacts (Init.getUserId(), Contact.ADMINS) do %>
        <tr> <td align="right" valign="top"><b><% Web.html (#name kind) %></b>:</td>
-       <td><% Contact.format (kind, cont) %></td> </tr>
+       <td><% Contact.format (kind, cont) %></td>
+       <td><i><% switch #priv cont of
+                 Contact.PUBLIC => %>Public<%
+               | Contact.MEMBERS => %>Members only<%
+               | Contact.ADMINS => %>Admins only<%
+       end %></i></td>
+       <td><a href="contact?mod=<% #id cont %>">[Modify]</a> <a href="contact?del=<% #id cont %>">[Delete]</a></tr>
 <% end %>
 </table>
 
index 1fb0454..1c11d72 100644 (file)
@@ -22,6 +22,7 @@ sig
     val modContact : contact -> unit
     val deleteContact : int -> unit
     val listUserContacts : int * priv -> (kind * contact) list
+    val listContactsByKind : int * priv -> (string * contact) list
 
     val format : kind * contact -> string
 end
\ No newline at end of file
index 345ab51..3c3698d 100644 (file)
@@ -103,7 +103,7 @@ fun lookupContact id =
     let
        val c = getDb ()
     in
-       (case C.oneOrNoRows c ($`SELECT id, usr, knd, v, priv Contact WHERE id = ^(C.intToSql id)`) of
+       (case C.oneOrNoRows c ($`SELECT id, usr, knd, v, priv FROM Contact WHERE id = ^(C.intToSql id)`) of
             NONE => raise Fail "Contact not found"
           | SOME r => mkContactRow r)
     end
@@ -134,6 +134,18 @@ fun listUserContacts (usr, priv) =
                                            AND priv <= ^(privToSql priv)
                                         ORDER BY name, v`)
 
+fun mkKindContactRow r =
+    case r of
+       name :: rest => (C.stringFromSql name, mkContactRow rest)
+      | _ => Init.rowError ("name/contact", r)
+
+fun listContactsByKind (knd, priv) =
+    C.map (getDb ()) mkKindContactRow ($`SELECT name, Contact.id, usr, knd, v, priv
+                                        FROM Contact JOIN WebUser ON WebUser.id = usr
+                                        WHERE knd = ^(C.intToSql knd)
+                                           AND priv <= ^(privToSql priv)
+                                        ORDER BY name`)
+
 fun format (kind : kind, cont : contact) =
     case #makeUrl kind of
        SOME (pre, post) => String.concat ["<a href=\"", pre, Web.html (#v cont), post, "\">", Web.html (#v cont), "</a>"]
diff --git a/dir.mlt b/dir.mlt
new file mode 100644 (file)
index 0000000..c973671
--- /dev/null
+++ b/dir.mlt
@@ -0,0 +1,22 @@
+<% if $"id" = "" then
+       @header [("title", ["Contact information directory"])]
+
+       foreach kind in Contact.listKinds () do %>
+               <a href="dir?id=<% #id kind %>"><% Web.html (#name kind) %></a><br>
+       <% end
+else
+       val id = Web.stoi ($"id");
+       val kind = Contact.lookupKind id;
+       @header [("title", [Web.html (#name kind) ^ " directory"])];
+
+       val level = iff Group.inGroupName "contact" then Contact.ADMINS else Contact.MEMBERS;
+
+       %><table><%
+       foreach (name, cont) in Contact.listContactsByKind (id, level) do %>
+               <tr> <td align="right"><a href="user?id=<% #usr cont %>"><% name %></a></td>
+               <td><% Contact.format (kind, cont) %></td> </tr>
+       <% end
+       %></table><%
+end;
+
+@footer[] %>
\ No newline at end of file
diff --git a/user.mlt b/user.mlt
new file mode 100644 (file)
index 0000000..498fc49
--- /dev/null
+++ b/user.mlt
@@ -0,0 +1,25 @@
+<% val id = Web.stoi ($"id");
+val user = Init.lookupUser id;
+
+@header[("title", [#name user])] %>
+
+<table>
+<tr> <td align="right"><b>Member</b>:</td> <td><% #name user %></td> </tr>
+<tr> <td align="right"><b>Real name</b>:</td> <td><% Web.html (#rname user) %></td> </tr>
+<tr> <td align="right"><b>Hcoop e-mail</b>:</td> <td><a href="mailto:<% #name user %>@hcoop.net"><tt><% #name user %>@hcoop.net</tt></a></td> </tr>
+<tr> <td align="right"><b>Joined</b>:</td> <td><% #joined user %></td> </tr>
+
+<tr> </tr>
+
+<tr> <td><b>Contact information</b></td> </tr>
+
+<% val level = iff Group.inGroupName "contact" then Contact.ADMINS else Contact.MEMBERS;
+
+foreach (kind, cont) in Contact.listUserContacts (id, level) do %>
+       <tr> <td align="right" valign="top"><b><% Web.html (#name kind) %></b>:</td>
+       <td><% Contact.format (kind, cont) %></td> </tr>
+<% end %>
+
+</table>
+
+<% @footer[] %>