← urwebplay

add links

8ed0c834fbe3cac24e013002deada7c81e9fb0fe · ovidiucs · Dec 23, 2015 20:19

+28 −3 · 3 files changed

  • urblog.ur +26 −3
  • urblog.urp +1 −0
  • urblog.urs +1 −0
diff --git a/urblog.ur b/urblog.ur
index c0e8a29..b19b444 100644
--- a/urblog.ur
+++ b/urblog.ur
@@ -7,8 +7,8 @@ fun list () =
     rows <- queryX (SELECT * FROM entry)
             (fn row => 
 				<xml>
-					<div>
-						<h1>{[row.Entry.Title]}</h1><br />
+					<div class={blogEntry}>
+						<h1><a link={detail row.Entry.Id}>{[row.Entry.Title]}</a></h1>
 							<h2>By {[row.Entry.Author]} at {[row.Entry.Created]}</h2>
 						<p>{[row.Entry.Body]}</p>
 					</div>
@@ -25,7 +25,30 @@ fun list () =
         {rows}
 		  </body>
     	</xml>
-
+and detail (i:int) =
+    res <- oneOrNoRows (SELECT * FROM entry WHERE entry.Id = {[i]});
+    return
+    (case res of
+        None => <xml>
+            <head><title>Entry Not Found</title></head>
+            <body>
+                <h1>Entry not found</h1>
+            </body>
+            </xml>
+      | Some r => <xml>
+                   <head>
+                     <title>{[r.Entry.Title]}</title>
+                     <link rel="stylesheet" type="text/css" href="http://expdev.net/urtutorial/step4/style.css"/>
+				   </head>
+				   <body>
+				   <h1>{[r.Entry.Title]}</h1>
+                   <h2>By {[r.Entry.Author]} at {[r.Entry.Created]}</h2>
+                   <div class={blogEntry}>
+                   <p>{[r.Entry.Body]}</p>
+                   </div>
+				   <a link={list ()}>Back to all entries</a>
+                   </body>
+                 </xml>)	
 fun main () = return <xml>
   <head>
     <title>UrBlog</title>
diff --git a/urblog.urp b/urblog.urp
index 0f474ae..ed7a6e7 100644
--- a/urblog.urp
+++ b/urblog.urp
@@ -1,4 +1,5 @@
 allow url http://expdev.net/urtutorial/step3/style.css
+allow url http://expdev.net/urtutorial/step4/style.css
 database dbname=urblog
 sql urblog.sql
 
diff --git a/urblog.urs b/urblog.urs
index a246a28..c1318f2 100644
--- a/urblog.urs
+++ b/urblog.urs
@@ -1,2 +1,3 @@
 val main : unit -> transaction page
 val list : unit -> transaction page
+val detail : int -> transaction page