From: Adam C. <ad...@us...> - 2009-08-04 15:34:09
|
Update of /cvsroot/hcoop/portal In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv27854 Modified Files: poll.mlt poll.sig poll.sml tables.sql Log Message: Initial support for poll 'ready' bits Index: poll.sig =================================================================== RCS file: /cvsroot/hcoop/portal/poll.sig,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** poll.sig 24 Feb 2008 17:41:23 -0000 1.4 --- poll.sig 4 Aug 2009 15:33:55 -0000 1.5 *************** *** 1,4 **** signature POLL = sig ! type poll = {id : int, usr : int, title : string, descr : string, starts : string, ends : string, votes : int, official : bool} val lookupPoll : int -> poll --- 1,4 ---- signature POLL = sig ! type poll = {id : int, usr : int, title : string, descr : string, starts : string, ends : string, votes : int, official : bool, ready : bool} val lookupPoll : int -> poll *************** *** 7,11 **** val listPollsLimit : int -> poll list ! val addPoll : int * string * string * string * string * int * bool -> int val modPoll : poll -> unit val deletePoll : int -> unit --- 7,11 ---- val listPollsLimit : int -> poll list ! val addPoll : int * string * string * string * string * int * bool * bool -> int val modPoll : poll -> unit val deletePoll : int -> unit Index: tables.sql =================================================================== RCS file: /cvsroot/hcoop/portal/tables.sql,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** tables.sql 9 Apr 2008 13:45:02 -0000 1.32 --- tables.sql 4 Aug 2009 15:33:55 -0000 1.33 *************** *** 106,109 **** --- 106,110 ---- votes INTEGER NOT NULL, official BOOL NOT NULL, + ready BOOL NOT NULL, FOREIGN KEY (usr) REFERENCES WebUser(id) ON DELETE CASCADE); Index: poll.mlt =================================================================== RCS file: /cvsroot/hcoop/portal/poll.mlt,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** poll.mlt 24 Feb 2008 17:41:22 -0000 1.10 --- poll.mlt 4 Aug 2009 15:33:54 -0000 1.11 *************** *** 88,92 **** %><h3>You must specify a positive number of votes per person.</h3><% else ! val id = Poll.addPoll (Init.getUserId(), title, $"descr", starts, ends, votes, official); editingPoll := SOME id; %><h3>Poll added!</h3><% --- 88,92 ---- %><h3>You must specify a positive number of votes per person.</h3><% else ! val id = Poll.addPoll (Init.getUserId(), title, $"descr", starts, ends, votes, official, false); editingPoll := SOME id; %><h3>Poll added!</h3><% *************** *** 104,107 **** --- 104,108 ---- <table class="blanks"> <tr> <td>Title:</td> <td><input name="title" value="<% Web.html (#title poll) %>"></td> </tr> + <tr> <td>Ready?</td> <td><input type="checkbox" name="ready" <% if #ready poll then " checked" else "" end %>></td> </tr> <tr> <td>Start date:</td> <td><input name="starts" value="<% Web.html (#starts poll) %>"></td> </tr> <tr> <td>End date:</td> <td><input name="ends" value="<% Web.html (#ends poll) %>"></td> </tr> *************** *** 123,127 **** val votes = Web.stoi ($"votes"); val official = $"official" = "on"; ! if title = "" then %><h3>Your poll must have a title.</h3><% elseif not pollAdmin and not (Poll.dateGeNow starts) then --- 124,131 ---- val votes = Web.stoi ($"votes"); val official = $"official" = "on"; ! val ready = $"ready" = "on"; ! if not (Poll.canModify poll) then ! %><h3>You can't modify this poll anymore, because voting is already open.</h3><% ! elseif title = "" then %><h3>Your poll must have a title.</h3><% elseif not pollAdmin and not (Poll.dateGeNow starts) then *************** *** 132,136 **** %><h3>You must specify a positive number of votes per person.</h3><% else ! Poll.modPoll {poll with title = title, descr = $"descr", starts = starts, ends = ends, votes = votes, official = official}; editingPoll := SOME (#id poll); %><h3>Poll record saved.</h3><% --- 136,141 ---- %><h3>You must specify a positive number of votes per person.</h3><% else ! Poll.modPoll {poll with title = title, descr = $"descr", starts = starts, ends = ends, votes = votes, official = official, ! ready = ready}; editingPoll := SOME (#id poll); %><h3>Poll record saved.</h3><% *************** *** 154,158 **** editingPoll := SOME id; val descr = $"descr"; ! if descr = "" then %><h3>Your poll choice must have a description.</h3><% else --- 159,166 ---- editingPoll := SOME id; val descr = $"descr"; ! val poll = Poll.lookupPoll id; ! if not (Poll.canModify poll) then ! %><h3>You can't modify this poll anymore, because voting is already open.</h3><% ! elseif descr = "" then %><h3>Your poll choice must have a description.</h3><% else Index: poll.sml =================================================================== RCS file: /cvsroot/hcoop/portal/poll.sml,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** poll.sml 24 Feb 2008 17:41:23 -0000 1.8 --- poll.sml 4 Aug 2009 15:33:55 -0000 1.9 *************** *** 4,17 **** open Util Sql Init ! type poll = {id : int, usr : int, title : string, descr : string, starts : string, ends : string, votes : int, official : bool} ! fun mkPollRow [id, usr, title, descr, starts, ends, votes, official] = {id = C.intFromSql id, usr = C.intFromSql usr, title = C.stringFromSql title, descr = C.stringFromSql descr, starts = C.stringFromSql starts, ! ends = C.stringFromSql ends, votes = C.intFromSql votes, official = C.boolFromSql official} | mkPollRow row = Init.rowError ("poll", row) fun lookupPoll id = ! case C.oneOrNoRows (getDb ()) ($`SELECT id, usr, title, descr, starts, ends, votes, official FROM Poll WHERE id = ^(C.intToSql id)`) of --- 4,18 ---- open Util Sql Init ! type poll = {id : int, usr : int, title : string, descr : string, starts : string, ends : string, votes : int, official : bool, ready : bool} ! fun mkPollRow [id, usr, title, descr, starts, ends, votes, official, ready] = {id = C.intFromSql id, usr = C.intFromSql usr, title = C.stringFromSql title, descr = C.stringFromSql descr, starts = C.stringFromSql starts, ! ends = C.stringFromSql ends, votes = C.intFromSql votes, official = C.boolFromSql official, ! ready = C.boolFromSql ready} | mkPollRow row = Init.rowError ("poll", row) fun lookupPoll id = ! case C.oneOrNoRows (getDb ()) ($`SELECT id, usr, title, descr, starts, ends, votes, official, ready FROM Poll WHERE id = ^(C.intToSql id)`) of *************** *** 20,48 **** fun listPolls () = ! C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes, official FROM Poll ORDER BY ends, starts DESC, title`) fun listCurrentPolls () = ! C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes, official FROM Poll WHERE EXTRACT(EPOCH FROM starts) <= EXTRACT(EPOCH FROM CURRENT_DATE) AND EXTRACT(EPOCH FROM ends) >= EXTRACT(EPOCH FROM CURRENT_DATE) ORDER BY ends, starts DESC, title`) fun listPollsLimit lim = ! C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes, official FROM Poll ORDER BY starts DESC, ends, title LIMIT ^(C.intToSql lim)`) ! fun addPoll (usr, title, descr, starts, ends, votes, official) = let val db = getDb () val id = nextSeq (db, "PollSeq") in ! C.dml db ($`INSERT INTO Poll (id, usr, title, descr, starts, ends, votes, official) VALUES (^(C.intToSql id), ^(C.intToSql usr), ^(C.stringToSql title), ^(C.stringToSql descr), ! ^(C.stringToSql starts), ^(C.stringToSql ends), ^(C.intToSql votes), ^(C.boolToSql official))`); id end --- 21,53 ---- fun listPolls () = ! C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes, official, ready FROM Poll + WHERE ready ORDER BY ends, starts DESC, title`) fun listCurrentPolls () = ! C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes, official, ready FROM Poll WHERE EXTRACT(EPOCH FROM starts) <= EXTRACT(EPOCH FROM CURRENT_DATE) AND EXTRACT(EPOCH FROM ends) >= EXTRACT(EPOCH FROM CURRENT_DATE) + AND (ready OR usr = ^(C.intToSql (Init.getUserId ()))) ORDER BY ends, starts DESC, title`) fun listPollsLimit lim = ! C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes, official, ready FROM Poll ORDER BY starts DESC, ends, title + WHERE (ready OR usr = ^(C.intToSql (Init.getUserId ()))) LIMIT ^(C.intToSql lim)`) ! fun addPoll (usr, title, descr, starts, ends, votes, official, ready) = let val db = getDb () val id = nextSeq (db, "PollSeq") in ! C.dml db ($`INSERT INTO Poll (id, usr, title, descr, starts, ends, votes, official, ready) VALUES (^(C.intToSql id), ^(C.intToSql usr), ^(C.stringToSql title), ^(C.stringToSql descr), ! ^(C.stringToSql starts), ^(C.stringToSql ends), ^(C.intToSql votes), ^(C.boolToSql official), ! ^(C.boolToSql ready))`); id end *************** *** 56,60 **** descr = ^(C.stringToSql (#descr poll)), starts = ^(C.stringToSql (#starts poll)), ends = ^(C.stringToSql (#ends poll)), ! votes = ^(C.intToSql (#votes poll)), official = ^(C.boolToSql (#official poll)) WHERE id = ^(C.intToSql (#id poll))`)) end --- 61,66 ---- descr = ^(C.stringToSql (#descr poll)), starts = ^(C.stringToSql (#starts poll)), ends = ^(C.stringToSql (#ends poll)), ! votes = ^(C.intToSql (#votes poll)), official = ^(C.boolToSql (#official poll)), ! ready = ^(C.boolToSql (#ready poll)) WHERE id = ^(C.intToSql (#id poll))`)) end *************** *** 173,177 **** Group.inGroupName "poll" orelse (#usr poll = Init.getUserId() ! andalso dateLtNow (#starts poll)) fun requireCanModify poll = --- 179,184 ---- Group.inGroupName "poll" orelse (#usr poll = Init.getUserId() ! andalso (dateLtNow (#starts poll) ! orelse not (#ready poll))) fun requireCanModify poll = *************** *** 189,193 **** fun takingVotes (poll : poll) = ! dateLeNow (#starts poll) andalso dateGeNow (#ends poll) fun noDupes l = --- 196,200 ---- fun takingVotes (poll : poll) = ! #ready poll andalso dateLeNow (#starts poll) andalso dateGeNow (#ends poll) fun noDupes l = |