From: adamch Date: Sun, 17 Apr 2005 20:52:53 +0000 (+0000) Subject: Basic issue management X-Git-Url: https://git.hcoop.net/hcoop/zz_old/portal.git/commitdiff_plain/184f6cde4a5968a170f879052e127b1994952004 Basic issue management --- diff --git a/issue.mlt b/issue.mlt new file mode 100644 index 0000000..48c78ef --- /dev/null +++ b/issue.mlt @@ -0,0 +1,183 @@ +<% val catId = Web.stoi ($"cat"); +val cat = Support.lookupCategory catId; +val admin = Group.inGroupNum (#grp cat); +val you = Init.getUserId() + +ref viewingIssue = NONE; + +@header[("title", ["Support: " ^ Web.html (#name cat)])]; + +ref showNormal = true; + +if $"cmd" = "new" then + showNormal := false %> + +

New issue

+ +
+ + + + + + +
Title:
Only make this issue accessible to the admins for this support category.
+
+ +<% elseif $"cmd" = "add" then + val title = $"title"; + if not (Support.validTitle title) then + %>

Invalid title

<% + else + val id = Support.addIssue (you, catId, title, $"priv" = "on", Support.NEW); + viewingIssue := SOME id + end + +elseif $"mod" <> "" then + showNormal := false; + val id = Web.stoi ($"mod"); + val issue = Support.lookupIssue id; + if catId <> #cat issue then + %>

Inconsistent cat field

<% + elseif not admin then + %>

You aren't authorized to modify that.

<% + else %> +

Modify issue

+ +
+ + + + + + + + +
Category:
Title:
checked<% end %>> Only make this issue accessible to the admins for this support category.
Status:
+
+<% end + +elseif $"save" <> "" then + val id = Web.stoi ($"save"); + val issue = Support.lookupIssue id; + val title = $"title"; + val status = Web.stoi ($"status"); + val newCat = Support.lookupCategory (Web.stoi ($"newCat")); + + if catId <> #cat issue then + %>

Inconsistent cat field

<% + elseif (iff admin then not (Group.inGroupNum (#grp newCat)) else false) then + %>

Authorization failure

<% + elseif not (Support.validTitle title) then + %>

Invalid title

<% + elseif (iff status < 0 then false else status > 2) then + %>

Invalid status

<% + else + Support.modIssue {issue with cat = #id newCat, title = title, + priv = ($"priv" = "on"), + status = (case status of + 0 => Support.NEW + | 1 => Support.PENDING + | _ => Support.CLOSED)}; + viewingIssue := SOME id + %>

Issue saved "" then + showNormal := false; + val id = Web.stoi ($"del"); + val issue = Support.lookupIssue id; + + if catId <> #cat issue then + %>

Inconsistent cat field

<% + elseif not admin then + %>

Authorization failure

<% + else + %>

Are you sure you want to delete "<% Web.html (#title issue) %>"?

+ Yes, delete "<% Web.html (#title issue) %>"!<% + end + +elseif $"del2" <> "" then + val id = Web.stoi ($"del2"); + val issue = Support.lookupIssue id; + + if catId <> #cat issue then + %>

Inconsistent cat field

<% + elseif not admin then + %>

Authorization failure

<% + else + Support.deleteIssue id + %>

Issue "<% Web.html (#title issue) %>" deleted

<% + end + +elseif $"id" <> "" then + viewingIssue := SOME (Web.stoi ($"id")) +end; + +switch viewingIssue of + SOME id => + val issue = Support.lookupIssue id; + val canEdit = (iff #usr issue = you then true else admin); + val canView = (iff #priv issue then canEdit else true); + if catId <> #cat issue then + %>

Inconsistent cat field

<% + elseif not canView then + %>

You aren't authorized to view that.

<% + else + val user = Init.lookupUser (#usr issue) %> + + + + + + + +
Title: <% Web.html (#title issue) %>
Created by: <% #name user %>
At: <% #stamp issue %>
Private: <% if #priv issue then %>yes<% else %>no<% end %>
Status: <% switch #status issue of + Support.NEW => %>New<% + | Support.PENDING => %>Pending<% + | Support.CLOSED => %>Closed<% + end %>
+ +<% if admin then %> +Modify this issue
+Delete this issue
+<% end %> + +<% end + + | NONE => +if showNormal then %> + +New issue + +

Open issues

+ + +<% val issues = iff admin then Support.listOpenCategoryIssuesAdmin catId + else Support.listOpenCategoryIssues (catId, you); + +foreach issue in issues do + val user = Init.lookupUser (#usr issue) %> + + + + +<% end %> + +<% end +end %> + +<% @footer[] %> \ No newline at end of file diff --git a/support.mlt b/support.mlt index 3c87e04..2af6750 100644 --- a/support.mlt +++ b/support.mlt @@ -66,10 +66,10 @@ if $"sub" <> "" then if showNormal then %> -

New issue in:

+

Choose a category:

<% foreach (sub, cat) in Support.listCategoriesWithSubscriptions you do %> -<% Web.html (#name cat) %>: <% Web.html (#descr cat) %> +<% Web.html (#name cat) %>: <% Web.html (#descr cat) %> <% if sub then %> [Unsubscribe] <% else %> diff --git a/support.sig b/support.sig index 2c5e127..e36295d 100644 --- a/support.sig +++ b/support.sig @@ -19,6 +19,9 @@ sig val lookupIssue : int -> issue val listIssues : unit -> issue list + val listCategoryIssues : int -> issue list + val listOpenCategoryIssues : int * int -> issue list + val listOpenCategoryIssuesAdmin : int -> issue list val addIssue : int * int * string * bool * status -> int val modIssue : issue -> unit val deleteIssue : int -> unit @@ -32,4 +35,6 @@ sig val subscribed : subscription -> bool val subscribe : subscription -> unit val unsubscribe : subscription -> unit + + val validTitle : string -> bool end \ No newline at end of file diff --git a/support.sml b/support.sml index 5b9c714..5370150 100644 --- a/support.sml +++ b/support.sml @@ -95,6 +95,27 @@ fun listIssues () = FROM SupIssue ORDER BY stamp DESC`) +fun listCategoryIssues cat = + C.map (getDb ()) mkIssueRow ($`SELECT id, usr, cat, title, priv, status, stamp + FROM SupIssue + WHERE cat = ^(C.intToSql cat) + ORDER BY stamp DESC`) + +fun listOpenCategoryIssues (cat, usr) = + C.map (getDb ()) mkIssueRow ($`SELECT id, usr, cat, title, priv, status, stamp + FROM SupIssue + WHERE cat = ^(C.intToSql cat) + AND status < 2 + AND (NOT priv OR usr = ^(C.intToSql usr)) + ORDER BY stamp DESC`) + +fun listOpenCategoryIssuesAdmin cat = + C.map (getDb ()) mkIssueRow ($`SELECT id, usr, cat, title, priv, status, stamp + FROM SupIssue + WHERE cat = ^(C.intToSql cat) + AND status < 2 + ORDER BY stamp DESC`) + fun addIssue (usr, cat, title, priv, status) = let val db = getDb () @@ -188,5 +209,6 @@ fun unsubscribe {usr, cat} = ignore (C.dml (getDb ()) ($`DELETE FROM SupSubscription WHERE usr = ^(C.intToSql usr) AND cat = ^(C.intToSql cat)`)) +fun validTitle s = CharVector.exists (fn ch => not (Char.isSpace ch)) s end \ No newline at end of file
<% Web.html (#title issue) %> +<% if #priv issue then %>(private)<% end %> + <% #name user %><% #stamp issue %><% switch #status issue of + Support.NEW => %>New<% + | Support.PENDING => %>Pending<% + | Support.CLOSED => %>Closed<% + end %>