X-Git-Url: http://git.hcoop.net/hcoop/portal.git/blobdiff_plain/18eeb7495e094565c1a5044296606fecd53814db..d46bc501d1e822483137e7c3a5c4a924b21629f6:/requestH.sml diff --git a/requestH.sml b/requestH.sml index f6bb4af..03e168d 100644 --- a/requestH.sml +++ b/requestH.sml @@ -11,7 +11,8 @@ datatype status = | INSTALLED | REJECTED -type request = { id : int, usr : int, node : int, data : string, msg : string, status : status, stamp : C.timestamp } +type request = { id : int, usr : int, node : int, data : string, msg : string, status : status, + stamp : C.timestamp, cstamp : C.timestamp option } val statusFromInt = fn 0 => NEW @@ -27,10 +28,11 @@ val statusToInt = fun statusFromSql v = statusFromInt (C.intFromSql v) fun statusToSql s = C.intToSql (statusToInt s) -fun mkRow [id, usr, node, data, msg, status, stamp] = +fun mkRow [id, usr, node, data, msg, status, stamp, cstamp] = {id = C.intFromSql id, usr = C.intFromSql usr, node = C.intFromSql node, data = C.stringFromSql data, - msg = C.stringFromSql msg, status = statusFromSql status, stamp = C.timestampFromSql stamp} + msg = C.stringFromSql msg, status = statusFromSql status, stamp = C.timestampFromSql stamp, + cstamp = if C.isNull cstamp then NONE else SOME (C.timestampFromSql cstamp)} | mkRow r = rowError ("APT request", r) fun add {usr, node, data, msg} = @@ -38,9 +40,9 @@ fun add {usr, node, data, msg} = val db = getDb () val id = nextSeq (db, seq) in - C.dml db ($`INSERT INTO ^table (id, usr, node, data, msg, status, stamp) + C.dml db ($`INSERT INTO ^table (id, usr, node, data, msg, status, stamp, cstamp) VALUES (^(C.intToSql id), ^(C.intToSql usr), ^(C.intToSql node), ^(C.stringToSql data), ^(C.stringToSql msg), - 0, CURRENT_TIMESTAMP)`); + 0, CURRENT_TIMESTAMP, NULL)`); id end @@ -48,6 +50,11 @@ fun modify (req : request) = let val db = getDb () in + if #status req <> NEW then + ignore (C.dml db ($`UPDATE ^table SET cstamp = CURRENT_TIMESTAMP WHERE id = ^(C.intToSql (#id req))`)) + else + (); + ignore (C.dml db ($`UPDATE ^table SET usr = ^(C.intToSql (#usr req)), data = ^(C.stringToSql (#data req)), node = ^(C.intToSql (#node req)), @@ -59,7 +66,7 @@ fun delete id = ignore (C.dml (getDb ()) ($`DELETE FROM ^table WHERE id = ^(C.intToSql id)`)) fun lookup id = - case C.oneOrNoRows (getDb ()) ($`SELECT id, usr, node, data, msg, status, stamp + case C.oneOrNoRows (getDb ()) ($`SELECT id, usr, node, data, msg, status, stamp, cstamp FROM ^table WHERE id = ^(C.intToSql id)`) of SOME row => mkRow row @@ -69,12 +76,12 @@ fun mkRow' (name :: rest) = (C.stringFromSql name, mkRow rest) | mkRow' r = rowError ("Apt.request'", r) fun list () = - C.map (getDb ()) mkRow' ($`SELECT name, ^table.id, usr, node, data, msg, status, stamp + C.map (getDb ()) mkRow' ($`SELECT name, ^table.id, usr, node, data, msg, status, stamp, cstamp FROM ^table JOIN WebUser ON usr = WebUser.id ORDER BY stamp DESC`) fun listOpen () = - C.map (getDb ()) mkRow' ($`SELECT name, ^table.id, usr, node, data, msg, status, stamp + C.map (getDb ()) mkRow' ($`SELECT name, ^table.id, usr, node, data, msg, status, stamp, cstamp FROM ^table JOIN WebUser ON usr = WebUser.id WHERE status = 0 ORDER BY stamp DESC`) @@ -147,12 +154,17 @@ val statusToString = | REJECTED => "Rejected" fun notifyMod {old, new, changer, req} = - notify (fn (_, mail) => + if old = new then + notify (fn (_, mail) => (Mail.mwrite (mail, changer); - Mail.mwrite (mail, " has changed the status of this request from "); - Mail.mwrite (mail, statusToString old); - Mail.mwrite (mail, " to "); - Mail.mwrite (mail, statusToString new); - Mail.mwrite (mail, ".\n\n"))) req + Mail.mwrite (mail, " has added a comment to this request.\n\n"))) req + else + notify (fn (_, mail) => + (Mail.mwrite (mail, changer); + Mail.mwrite (mail, " has changed the status of this request from "); + Mail.mwrite (mail, statusToString old); + Mail.mwrite (mail, " to "); + Mail.mwrite (mail, statusToString new); + Mail.mwrite (mail, ".\n\n"))) req end