Basic issue management
[hcoop/portal.git] / issue.mlt
CommitLineData
1cb3df3f
AC
1<% val catId = Web.stoi ($"cat");
2val cat = Support.lookupCategory catId;
3val admin = Group.inGroupNum (#grp cat);
4val you = Init.getUserId()
5
6ref viewingIssue = NONE;
7
8@header[("title", ["Support: " ^ Web.html (#name cat)])];
9
10ref showNormal = true;
11
12if $"cmd" = "new" then
13 showNormal := false %>
14
15<h3><b>New issue</b></h3>
16
17<form action="issue">
18<input type="hidden" name="cat" value="<% catId %>">
19<input type="hidden" name="cmd" value="add">
20<table>
21<tr> <td align="right"><b>Title</b>:</td> <td><input name="title"></td> </tr>
22<tr> <td align="right"><input type="checkbox" name="priv"></td> <td>Only make this issue accessible to the admins for this support category.</td> </tr>
23<tr> <td><input type="submit" value="Add"></td> </tr>
24</table>
25</form>
26
27<% elseif $"cmd" = "add" then
28 val title = $"title";
29 if not (Support.validTitle title) then
30 %><h3><b>Invalid title</b></h3><%
31 else
32 val id = Support.addIssue (you, catId, title, $"priv" = "on", Support.NEW);
33 viewingIssue := SOME id
34 end
35
36elseif $"mod" <> "" then
37 showNormal := false;
38 val id = Web.stoi ($"mod");
39 val issue = Support.lookupIssue id;
40 if catId <> #cat issue then
41 %><h3><b>Inconsistent cat field</b></h3><%
42 elseif not admin then
43 %><h3><b>You aren't authorized to modify that.</b></h3><%
44 else %>
45<h3><b>Modify issue</b></h3>
46
47<form action="issue">
48<input type="hidden" name="cat" value="<% catId %>">
49<input type="hidden" name="save" value="<% id %>">
50<table>
51<tr> <td align="right"><b>Category</b>:</td> <td><select name="newCat">
52<% foreach cat in Support.listCategories () do %>
53 <option value="<% #id cat %>"<% if #id cat = catId then %> selected<% end %>><% Web.html (#name cat) %></option>
54<% end %></select></td> </tr>
55<tr> <td align="right"><b>Title</b>:</td> <td><input name="title" value="<% Web.html (#title issue) %>"></td> </tr>
56<tr> <td align="right"><input type="checkbox" name="priv"<% if #priv issue then %> checked<% end %>></td> <td>Only make this issue accessible to the admins for this support category.</td> </tr>
57<tr> <td align="right"><b>Status</b>:</td> <td><select name="status">
58 <option value="0"<% if #status issue = Support.NEW then %> selected<% end %>>New</option>
59 <option value="1"<% if #status issue = Support.PENDING then %> selected<% end %>>Pending</option>
60 <option value="2"<% if #status issue = Support.CLOSED then %> selected<% end %>>Closed</option>
61</select></td> </tr>
62<tr> <td><input type="submit" value="Add"></td> </tr>
63</table>
64</form>
65<% end
66
67elseif $"save" <> "" then
68 val id = Web.stoi ($"save");
69 val issue = Support.lookupIssue id;
70 val title = $"title";
71 val status = Web.stoi ($"status");
72 val newCat = Support.lookupCategory (Web.stoi ($"newCat"));
73
74 if catId <> #cat issue then
75 %><h3><b>Inconsistent cat field</b></h3><%
76 elseif (iff admin then not (Group.inGroupNum (#grp newCat)) else false) then
77 %><h3><b>Authorization failure</b></h3><%
78 elseif not (Support.validTitle title) then
79 %><h3><b>Invalid title</b></h3><%
80 elseif (iff status < 0 then false else status > 2) then
81 %><h3><b>Invalid status</b></h3><%
82 else
83 Support.modIssue {issue with cat = #id newCat, title = title,
84 priv = ($"priv" = "on"),
85 status = (case status of
86 0 => Support.NEW
87 | 1 => Support.PENDING
88 | _ => Support.CLOSED)};
89 viewingIssue := SOME id
90 %><h3><b>Issue saved</b></h3<%
91 end
92
93elseif $"del" <> "" then
94 showNormal := false;
95 val id = Web.stoi ($"del");
96 val issue = Support.lookupIssue id;
97
98 if catId <> #cat issue then
99 %><h3><b>Inconsistent cat field</b></h3><%
100 elseif not admin then
101 %><h3><b>Authorization failure</b></h3><%
102 else
103 %><h3><b>Are you sure you want to delete "<% Web.html (#title issue) %>"?</b></h3>
104 <a href="issue?cat=<% catId %>&del2=<% id %>">Yes, delete "<% Web.html (#title issue) %>"!</a><%
105 end
106
107elseif $"del2" <> "" then
108 val id = Web.stoi ($"del2");
109 val issue = Support.lookupIssue id;
110
111 if catId <> #cat issue then
112 %><h3><b>Inconsistent cat field</b></h3><%
113 elseif not admin then
114 %><h3><b>Authorization failure</b></h3><%
115 else
116 Support.deleteIssue id
117 %><h3><b>Issue "<% Web.html (#title issue) %>" deleted</b></h3><%
118 end
119
120elseif $"id" <> "" then
121 viewingIssue := SOME (Web.stoi ($"id"))
122end;
123
124switch viewingIssue of
125 SOME id =>
126 val issue = Support.lookupIssue id;
127 val canEdit = (iff #usr issue = you then true else admin);
128 val canView = (iff #priv issue then canEdit else true);
129 if catId <> #cat issue then
130 %><h3><b>Inconsistent cat field</b></h3><%
131 elseif not canView then
132 %><h3><b>You aren't authorized to view that.</b></h3><%
133 else
134 val user = Init.lookupUser (#usr issue) %>
135
136<table>
137<tr> <td align="right"><b>Title</b>:</td> <td><% Web.html (#title issue) %></td> </tr>
138<tr> <td align="right"><b>Created by</b>:</td> <td><a href="user?id=<% #usr issue %>"><% #name user %></a></td> </tr>
139<tr> <td align="right"><b>At</b>:</td> <td><% #stamp issue %></td> </tr>
140<tr> <td align="right"><b>Private</b>:</td> <td><% if #priv issue then %>yes<% else %>no<% end %></td> </tr>
141<tr> <td align="right"><b>Status</b>:</td> <td><% switch #status issue of
142 Support.NEW => %>New<%
143 | Support.PENDING => %>Pending<%
144 | Support.CLOSED => %>Closed<%
145 end %></td> </tr>
146</table>
147
148<% if admin then %>
149<a href="issue?cat=<% catId %>&mod=<% id %>">Modify this issue</a><br>
150<a href="issue?cat=<% catId %>&del=<% id %>">Delete this issue</a><br>
151<% end %>
152
153<% end
154
155 | NONE =>
156if showNormal then %>
157
158<a href="issue?cat=<% catId %>&cmd=new">New issue</a>
159
160<h3><b>Open issues</b></h3>
161
162<table>
163<% val issues = iff admin then Support.listOpenCategoryIssuesAdmin catId
164 else Support.listOpenCategoryIssues (catId, you);
165
166foreach issue in issues do
167 val user = Init.lookupUser (#usr issue) %>
168 <tr> <td><a href="issue?cat=<% catId %>&id=<% #id issue %>"><% Web.html (#title issue) %></a>
169<% if #priv issue then %><i>(private)</i><% end %>
170 </td>
171 <td><a href="user?id=<% #usr issue %>"><% #name user %></a></td>
172 <td><% #stamp issue %></td>
173 <td><% switch #status issue of
174 Support.NEW => %>New<%
175 | Support.PENDING => %>Pending<%
176 | Support.CLOSED => %>Closed<%
177 end %></td> </tr>
178<% end %>
179
180<% end
181end %>
182
183<% @footer[] %>