comparison demo/more/conference.ur @ 1012:32dbb5636ae7

Setting and updating your own review
author Adam Chlipala <adamc@hcoop.net>
date Thu, 22 Oct 2009 16:25:31 -0400
parents 16f7cb0891b6
children e47303e5d73d
comparison
equal deleted inserted replaced
1011:16f7cb0891b6 1012:32dbb5636ae7
248 {ps} 248 {ps}
249 </ul> 249 </ul>
250 </body></xml> 250 </body></xml>
251 251
252 and one id = 252 and one id =
253 me <- getLogin; 253 let
254 checkPaper id; 254 fun newReview r =
255 ro <- oneOrNoRows (SELECT paper.{{map fst M.paper}}, octet_length(paper.Document) AS N 255 me <- getLogin;
256 FROM paper 256 checkPaper id;
257 WHERE paper.Id = {[id]}); 257 dml (insert review ({Paper = sql_inject id, User = sql_inject me.Id}
258 authors <- queryX (SELECT user.Nam 258 ++ ensql M.review r M.reviewFolder));
259 FROM authorship 259 one id
260 JOIN user ON authorship.User = user.Id 260
261 WHERE authorship.Paper = {[id]}) 261 fun saveReview r =
262 (fn r => <xml><li>{[r.User.Nam]}</li></xml>); 262 me <- getLogin;
263 myReview <- oneOrNoRows1 (SELECT review.{{map fst M.review}} 263 checkPaper id;
264 FROM review 264 dml (update [map fst M.review] ! (ensql M.review r M.reviewFolder)
265 WHERE review.User = {[me.Id]} 265 review (WHERE T.Paper = {[id]} AND T.User = {[me.Id]}));
266 AND review.Paper = {[id]}); 266 one id
267 case ro of 267 in
268 None => error <xml>Paper not found!</xml> 268 me <- getLogin;
269 | Some r => return <xml><body> 269 checkPaper id;
270 <h1>Paper #{[id]}</h1> 270 ro <- oneOrNoRows (SELECT paper.{{map fst M.paper}}, octet_length(paper.Document) AS N
271 271 FROM paper
272 <h3>Authors:</h3> 272 WHERE paper.Id = {[id]});
273 <ul> 273 authors <- queryX (SELECT user.Nam
274 {authors} 274 FROM authorship
275 </ul> 275 JOIN user ON authorship.User = user.Id
276 276 WHERE authorship.Paper = {[id]})
277 {allContent M.paper r.Paper M.paperFolder}<br/> 277 (fn r => <xml><li>{[r.User.Nam]}</li></xml>);
278 278 myReview <- oneOrNoRows1 (SELECT review.{{map fst M.review}}
279 {if r.N = 0 then 279 FROM review
280 <xml><div>No paper uploaded yet.</div></xml> 280 WHERE review.User = {[me.Id]}
281 else 281 AND review.Paper = {[id]});
282 <xml><a link={download id}>Download paper</a> ({[r.N]} bytes)</xml>} 282 case ro of
283 283 None => error <xml>Paper not found!</xml>
284 <hr/> 284 | Some r => return <xml><body>
285 285 <h1>Paper #{[id]}</h1>
286 {case myReview of 286
287 None => <xml> 287 <h3>Authors:</h3>
288 <h2>Add Your Review</h2> 288 <ul>
289 289 {authors}
290 <form> 290 </ul>
291 {allWidgets M.review M.reviewFolder} 291
292 </form> 292 {allContent M.paper r.Paper M.paperFolder}<br/>
293 </xml> 293
294 | Some myReview => <xml> 294 {if r.N = 0 then
295 <h2>Edit Your Review</h2> 295 <xml><div>No paper uploaded yet.</div></xml>
296 296 else
297 <form> 297 <xml><a link={download id}>Download paper</a> ({[r.N]} bytes)</xml>}
298 {allPopulated M.review myReview M.reviewFolder} 298
299 </form> 299 <hr/>
300 </xml>} 300
301 </body></xml> 301 {case myReview of
302 None => <xml>
303 <h2>Add Your Review</h2>
304
305 <form>
306 {allWidgets M.review M.reviewFolder}
307 <submit value="Add" action={newReview}/>
308 </form>
309 </xml>
310 | Some myReview => <xml>
311 <h2>Edit Your Review</h2>
312
313 <form>
314 {allPopulated M.review myReview M.reviewFolder}
315 <submit value="Save" action={saveReview}/>
316 </form>
317 </xml>}
318 </body></xml>
319 end
302 320
303 and download id = 321 and download id =
304 checkPaper id; 322 checkPaper id;
305 ro <- oneOrNoRows (SELECT paper.Document 323 ro <- oneOrNoRows (SELECT paper.Document
306 FROM paper 324 FROM paper