Update of /cvsroot/hcoop/portal In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv17587
Modified Files: poll.mlt poll.sig poll.sml tables.sql Log Message: Poll voting limit by membership length Index: poll.sig =================================================================== RCS file: /cvsroot/hcoop/portal/poll.sig,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** poll.sig 28 Sep 2005 14:54:19 -0000 1.3 --- poll.sig 24 Feb 2008 17:41:23 -0000 1.4 *************** *** 1,4 **** signature POLL = sig ! type poll = {id : int, usr : int, title : string, descr : string, starts : string, ends : string, votes : int} 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} val lookupPoll : int -> poll *************** *** 7,11 **** val listPollsLimit : int -> poll list ! val addPoll : int * string * string * string * string * int -> 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 -> int val modPoll : poll -> unit val deletePoll : int -> unit *************** *** 42,44 **** --- 42,48 ---- val countVoters : int -> int val listPollVoters : int -> Init.user list + + val votingMembershipRequirement : int + + val membershipLength : int -> int end Index: tables.sql =================================================================== RCS file: /cvsroot/hcoop/portal/tables.sql,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** tables.sql 16 Dec 2007 17:06:55 -0000 1.30 --- tables.sql 24 Feb 2008 17:41:23 -0000 1.31 *************** *** 105,108 **** --- 105,109 ---- ends DATE NOT NULL, votes INTEGER NOT NULL, + official 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.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** poll.mlt 24 Jan 2008 23:09:10 -0000 1.9 --- poll.mlt 24 Feb 2008 17:41:22 -0000 1.10 *************** *** 28,34 **** --- 28,38 ---- <tr> <td>End:</td> <td><% Web.html (#ends poll) %></td> </tr> <tr> <td>Votes/person:</td> <td><% #votes poll %></td> </tr> + <tr> <td>Official:</td> <td><% if #official poll then "yes" else "no" end %></td> </tr> <tr> <td>Description:</td> <td><% Web.htmlNl (#descr poll) %></td> </tr> </table> + <% if #official poll and Poll.membershipLength (Init.getUserId ()) < Poll.votingMembershipRequirement then %> + <h3>You haven't been a member long enough to vote in an official poll.</h3> + <% else %> <h3>Choices</h3> *************** *** 48,52 **** </form> ! <% elseif $"vote2" <> "" then val id = Web.stoi ($"vote2"); val poll = Poll.lookupPoll id; --- 52,57 ---- </form> ! <% end ! elseif $"vote2" <> "" then val id = Web.stoi ($"vote2"); val poll = Poll.lookupPoll id; *************** *** 57,61 **** | v => map Web.stoi v; ! if length votes > #votes poll then %><h3>You can't vote for that many different choices!</h3><% elseif not (Poll.noDupes votes) then --- 62,68 ---- | v => map Web.stoi v; ! if #official poll and Poll.membershipLength (Init.getUserId ()) < Poll.votingMembershipRequirement then ! %><h3>You haven't been a member long enough to vote in an official poll.</h3><% ! elseif length votes > #votes poll then %><h3>You can't vote for that many different choices!</h3><% elseif not (Poll.noDupes votes) then *************** *** 71,74 **** --- 78,82 ---- val ends = $"ends"; val votes = Web.stoi ($"votes"); + val official = $"official" = "on"; if title = "" then %><h3>Your poll must have a title.</h3><% *************** *** 80,84 **** %><h3>You must specify a positive number of votes per person.</h3><% else ! val id = Poll.addPoll (Init.getUserId(), title, $"descr", starts, ends, votes); 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); editingPoll := SOME id; %><h3>Poll added!</h3><% *************** *** 99,102 **** --- 107,111 ---- <tr> <td>End date:</td> <td><input name="ends" value="<% Web.html (#ends poll) %>"></td> </tr> <tr> <td>Max votes/person:</td> <td><input name="votes" value="<% #votes poll %>"></td> </tr> + <tr> <td>Official:</td> <td><input type="checkbox" name="official"<% if #official poll then " checked" end %>></td> </tr> <tr> <td>Description:</td> <td><textarea name="descr" wrap="soft" rows="5" cols="80"><% Web.html (#descr poll) %></textarea></td> </tr> <tr> <td><input type="submit" name="cmd" value="Save"></td> </tr> *************** *** 113,116 **** --- 122,126 ---- val ends = $"ends"; val votes = Web.stoi ($"votes"); + val official = $"official" = "on"; if title = "" then %><h3>Your poll must have a title.</h3><% *************** *** 122,126 **** %><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}; editingPoll := SOME (#id poll); %><h3>Poll record saved.</h3><% --- 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><% *************** *** 225,228 **** --- 235,239 ---- <tr> <td>End:</td> <td><% Web.html (#ends poll) %></td> </tr> <tr> <td>Votes/person:</td> <td><% #votes poll %></td> </tr> + <tr> <td>Official:</td> <td><% if #official poll then "yes" else "no" end %></td> </tr> <tr> <td>Description:</td> <td><% Web.htmlNl (#descr poll) %></td> </tr> </table> *************** *** 264,267 **** --- 275,279 ---- <tr> <td>End:</td> <td><% Web.html (#ends poll) %></td> </tr> <tr> <td>Votes/person:</td> <td><% #votes poll %></td> </tr> + <tr> <td>Official:</td> <td><% if #official poll then "yes" else "no" end %></td> </tr> <tr> <td>Description:</td> <td><% Web.htmlNl (#descr poll) %></td> </tr> </table> *************** *** 316,320 **** if showNormal then ! val polls = Poll.listCurrentPolls (); switch polls of _::_ => %> --- 328,336 ---- if showNormal then ! val mlen = Poll.membershipLength (Init.getUserId ()) %> ! ! <p>You have been an HCoop member for <% mlen %> days, so you <b>are<% if mlen < Poll.votingMembershipRequirement then %> not<% end %></b> eligible to vote in official polls.</p> ! ! <% val polls = Poll.listCurrentPolls (); switch polls of _::_ => %> *************** *** 339,342 **** --- 355,359 ---- <tr> <td>End date:</td> <td><input name="ends"></td> </tr> <tr> <td>Max votes/person:</td> <td><input name="votes"></td> </tr> + <tr> <td>Official:</td> <td><input type="checkbox" name="official"></td> </tr> <tr> <td>Description:</td> <td><textarea name="descr" wrap="soft" rows="5" cols="80"></textarea></td> </tr> <tr> <td><input type="submit" value="Create"></td> </tr> Index: poll.sml =================================================================== RCS file: /cvsroot/hcoop/portal/poll.sml,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** poll.sml 22 Nov 2007 19:24:00 -0000 1.7 --- poll.sml 24 Feb 2008 17:41:23 -0000 1.8 *************** *** 4,17 **** open Util Sql Init ! type poll = {id : int, usr : int, title : string, descr : string, starts : string, ends : string, votes : int} ! fun mkPollRow [id, usr, title, descr, starts, ends, votes] = {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} | mkPollRow row = Init.rowError ("poll", row) fun lookupPoll id = ! case C.oneOrNoRows (getDb ()) ($`SELECT id, usr, title, descr, starts, ends, votes FROM Poll WHERE id = ^(C.intToSql id)`) of --- 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 *************** *** 20,29 **** fun listPolls () = ! C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes FROM Poll ORDER BY ends, starts DESC, title`) fun listCurrentPolls () = ! C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes FROM Poll WHERE EXTRACT(EPOCH FROM starts) <= EXTRACT(EPOCH FROM CURRENT_DATE) --- 20,29 ---- 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) *************** *** 32,48 **** fun listPollsLimit lim = ! C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes FROM Poll ORDER BY starts DESC, ends, title LIMIT ^(C.intToSql lim)`) ! fun addPoll (usr, title, descr, starts, ends, votes) = let val db = getDb () val id = nextSeq (db, "PollSeq") in ! C.dml db ($`INSERT INTO Poll (id, usr, title, descr, starts, ends, votes) VALUES (^(C.intToSql id), ^(C.intToSql usr), ^(C.stringToSql title), ^(C.stringToSql descr), ! ^(C.stringToSql starts), ^(C.stringToSql ends), ^(C.intToSql votes))`); id end --- 32,48 ---- 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 *************** *** 56,60 **** descr = ^(C.stringToSql (#descr poll)), starts = ^(C.stringToSql (#starts poll)), ends = ^(C.stringToSql (#ends poll)), ! votes = ^(C.intToSql (#votes poll)) WHERE id = ^(C.intToSql (#id poll))`)) 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 *************** *** 216,218 **** --- 216,227 ---- ORDER BY name`) + val votingMembershipRequirement = 45 + + fun membershipLength id = + case C.oneRow (getDb ()) ($`SELECT EXTRACT(DAY FROM (CURRENT_TIMESTAMP - joined)) + FROM WebUser + WHERE id = ^(C.intToSql id)`) of + [days] => C.intFromSql days + | row => Init.rowError ("membershipLength", row) + end ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ hcoop-cvs mailing list hcoop-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hcoop-cvs