forge
Explore
Log in

Don't you dare go Hollow

iz

Clone
★ 0

0 watching0 forksRustAGPL-3.0567.3 KiB3950aceTahinli27 days ago34 commits

admin.rs739 lines, 28.4 KiBHistoryRawDownload
1//! The administrator pages: sender and reminders with the message to members (`/settings`), mail rules
2//! (`/rules`) and logs (`/logs`). Each page is plain data in, markup out. Handlers build the data in
3//! `pages/`; nothing here reads the store.
4//!
5//! The password of the sender is never a field value: the form shows only whether one is set. Every
6//! value is escaped by `view!`, and no script or handler is emitted.
7
8use topcoat::Result;
9use topcoat::view::{View, component, view};
10
11use crate::i18n::Lang;
12use crate::i18n::admin::{K, fill, t};
13use crate::i18n::structure::{K as StructureK, t as structure_t};
14use crate::views::board::flag;
15use crate::views::structure::{limits_section, members_section, server_section, storage_section};
16use crate::views::{alert, notice};
17
18/// The sender form as it is shown. The password is never here, only `password_set`.
19#[derive(Debug, Clone, Default)]
20pub struct SenderForm {
21 /// Host name.
22 pub host: String,
23 /// Port, as text.
24 pub port: String,
25 /// `implicit`, `starttls` or `plain`.
26 pub tls: String,
27 /// SMTP user name.
28 pub username: String,
29 /// From address.
30 pub from_address: String,
31 /// From name.
32 pub from_name: String,
33 /// Whether a password is stored.
34 pub password_set: bool,
35}
36
37/// A row of the rules list: the name, the sentence the rule says, and whether it is on.
38#[derive(Debug, Clone)]
39pub struct RuleRow {
40 /// Rule id.
41 pub id: String,
42 /// The admin's name for the rule.
43 pub name: String,
44 /// The rule in one sentence.
45 pub sentence: String,
46 /// Whether the rule is on.
47 pub enabled: bool,
48}
49
50/// The rule form as it is shown: the typed values, or the saved rule being edited.
51#[derive(Debug, Clone, Default)]
52pub struct RuleFormView {
53 /// The name.
54 pub name: String,
55 /// The trigger word.
56 pub trigger: String,
57 /// The column id (only for the status trigger).
58 pub column: String,
59 /// The project id, or empty for any.
60 pub tag: String,
61 /// The audience word.
62 pub audience: String,
63 /// The subject template.
64 pub subject: String,
65 /// Whether the mail carries the details block.
66 pub include_details: bool,
67 /// Whether the rule is on.
68 pub enabled: bool,
69}
70
71/// One activity row of the logs.
72#[derive(Debug, Clone)]
73pub struct ActivityRow {
74 /// When it happened, as stored.
75 pub at: String,
76 /// Who did it, by name.
77 pub who: String,
78 /// The event kind.
79 pub kind: String,
80 /// The details, as stored JSON text.
81 pub detail: String,
82}
83
84/// The sections of the logs page.
85#[derive(Debug, Clone, Copy, PartialEq, Eq)]
86pub enum LogSection {
87 /// Mail queued for sending.
88 Outbox,
89 /// The rules' decisions.
90 Decisions,
91 /// The board's activity.
92 Activity,
93}
94
95/// The rows of one logs page. Only the section in `section` is filled.
96#[derive(Debug, Clone)]
97pub struct LogsView {
98 /// The section shown.
99 pub section: LogSection,
100 /// Outbox rows, newest first.
101 pub outbox: Vec<iz_core::store::outbox::OutboxRow>,
102 /// Rule decisions, newest first.
103 pub decisions: Vec<iz_core::store::outbox::Decision>,
104 /// Activity rows, newest first.
105 pub activity: Vec<ActivityRow>,
106 /// The kind filter text, as typed.
107 pub kind: String,
108 /// The link to the older page, when there is one.
109 pub next: Option<String>,
110 /// A confirmation, already translated.
111 pub notice: Option<String>,
112}
113
114/// The settings page: sender, reminders and the message to members.
115#[derive(Debug, Clone)]
116pub struct SettingsView {
117 /// The language.
118 pub lang: Lang,
119 /// Whether the sender is complete enough to send.
120 pub configured: bool,
121 /// The sender form.
122 pub sender: SenderForm,
123 /// Lead time of the reminders, in minutes.
124 pub reminder_lead: u32,
125 /// Reminder mails one member may get per hour.
126 pub reminder_cap: u32,
127 /// A confirmation to show above the page, already translated.
128 pub notice: Option<String>,
129 /// A refusal to show above the page, already translated or a store message.
130 pub alert: Option<String>,
131 /// Members and their roles, in name order.
132 pub members: Vec<crate::views::structure::MemberRow>,
133 /// The attachment size limit in MiB, as text for the form.
134 pub limit_mib: String,
135 /// The allowed attachment extensions, space separated, for the form.
136 pub extensions: String,
137 /// Read-only facts about the server.
138 pub server: crate::views::structure::ServerInfo,
139 /// Where attachments are kept and how far the move between places has got.
140 pub storage: crate::views::structure::StorageInfo,
141 /// The Backups card: whether backups are on, and the outcome of the last runs.
142 pub backup: BackupCard,
143 /// The Recently deleted card: tasks deleted within the restore window, newest first.
144 pub deleted: Vec<DeletedRow>,
145}
146
147/// One row of the Recently deleted card. `at` is already in the viewer's zone.
148#[derive(Debug, Clone, Default)]
149pub struct DeletedRow {
150 /// Task id, for the restore form.
151 pub id: String,
152 /// Readable key `PREFIX-n`.
153 pub key: String,
154 /// Title.
155 pub title: String,
156 /// When it was deleted, as `YYYY-MM-DD HH:MM`.
157 pub at: String,
158 /// The name of who deleted it, when the activity trail recorded it.
159 pub by: Option<String>,
160}
161
162/// The Backups card. Times are already in the viewer's zone; an empty text means nothing was recorded.
163#[derive(Debug, Clone, Default)]
164pub struct BackupCard {
165 /// Whether scheduled backups are on (`[backup] dir` is set). The button and the status show only then.
166 pub enabled: bool,
167 /// When the latest attempt started, as `YYYY-MM-DD HH:MM`.
168 pub last_attempt: String,
169 /// When the last success finished, as `YYYY-MM-DD HH:MM`.
170 pub last_success: String,
171 /// The error of the latest attempt, shown in an alert. Empty when that attempt succeeded.
172 pub last_error: String,
173 /// Whether no success is recent enough: the warning is shown only when backups are on.
174 pub stale: bool,
175}
176
177/// One status line of the Backups card: its label with the time, or "none yet" when nothing was recorded.
178fn backup_line(lang: Lang, key: K, stamp: &str) -> String {
179 let when = if stamp.is_empty() {
180 t(lang, K::BackupNever)
181 } else {
182 stamp
183 };
184 fill(t(lang, key), &[when])
185}
186
187/// The alert for a failed latest attempt, with the short error the worker recorded.
188#[component]
189async fn backup_failed_alert(lang: Lang, error: &str) -> Result<impl View> {
190 let text = fill(t(lang, K::BackupFailed), &[error]);
191 Ok(view! { alert(message: text.as_str()) })
192}
193
194/// The rules page: the list, the form (new or editing), and the choices of the form.
195#[derive(Debug, Clone)]
196pub struct RulesView {
197 /// The language.
198 pub lang: Lang,
199 /// The rules, oldest first.
200 pub rules: Vec<RuleRow>,
201 /// The columns the status trigger can name, `(id, name)`.
202 pub columns: Vec<(String, String)>,
203 /// The projects the rule can be limited to, `(id, name)`.
204 pub tags: Vec<(String, String)>,
205 /// The form to show.
206 pub form: RuleFormView,
207 /// The id of the rule being edited, or `None` for a new rule.
208 pub editing: Option<String>,
209 /// Whether the form is shown.
210 pub show_form: bool,
211 /// A confirmation, already translated.
212 pub notice: Option<String>,
213 /// A refusal, already translated or a store message.
214 pub alert: Option<String>,
215}
216
217/// The tabs of the administrator area. `current` is the page shown.
218#[component]
219pub async fn admin_tabs(lang: Lang, current: &str) -> Result<impl View> {
220 let settings = if current == "settings" {
221 "tab current"
222 } else {
223 "tab"
224 };
225 let rules = if current == "rules" {
226 "tab current"
227 } else {
228 "tab"
229 };
230 let logs = if current == "logs" {
231 "tab current"
232 } else {
233 "tab"
234 };
235 let tags = if current == "tags" {
236 "tab current"
237 } else {
238 "tab"
239 };
240 let columns = if current == "columns" {
241 "tab current"
242 } else {
243 "tab"
244 };
245 Ok(view! {
246 <nav class="tabs" aria-label=(t(lang, K::SettingsTitle))>
247 <a class=(settings) href="/settings">(t(lang, K::NavSettings))</a>
248 <a class=(tags) href="/tags">(structure_t(lang, StructureK::NavTags))</a>
249 <a class=(columns) href="/columns">(structure_t(lang, StructureK::NavColumns))</a>
250 <a class=(rules) href="/rules">(t(lang, K::NavRules))</a>
251 <a class=(logs) href="/logs">(t(lang, K::NavLogs))</a>
252 </nav>
253 })
254}
255
256/// The settings page body.
257#[component]
258pub async fn settings_content(page: &SettingsView, csrf: &str) -> Result<impl View> {
259 let lang = page.lang;
260 let sender = &page.sender;
261 let tls_implicit = sender.tls == "implicit";
262 let tls_starttls = sender.tls == "starttls";
263 let tls_plain = sender.tls == "plain";
264 let lead = page.reminder_lead.to_string();
265 let cap = page.reminder_cap.to_string();
266 let password_state = if sender.password_set {
267 t(lang, K::PasswordSet)
268 } else {
269 t(lang, K::PasswordNotSet)
270 };
271 Ok(view! {
272 <h1>(t(lang, K::SettingsTitle))</h1>
273 admin_tabs(lang: lang, current: "settings")
274 if let Some(message) = &page.alert {
275 alert(message: message.as_str())
276 }
277 if let Some(message) = &page.notice {
278 notice(message: message.as_str())
279 }
280 <section class="card">
281 <h2>(t(lang, K::SenderHeading))</h2>
282 <p class="field-hint">(t(lang, K::SenderHelp))</p>
283 if !page.configured {
284 <p class="field-hint">(t(lang, K::SenderNotConfigured))</p>
285 }
286 <form method="post" action="/settings/sender" class="stack">
287 <input type="hidden" name="csrf" value=(csrf)>
288 <div class="field">
289 <label for="mail-host">(t(lang, K::FieldHost))</label>
290 <input id="mail-host" name="host" value=(sender.host.as_str()) maxlength="253" autocomplete="off">
291 </div>
292 <div class="field">
293 <label for="mail-port">(t(lang, K::FieldPort))</label>
294 <input id="mail-port" name="port" inputmode="numeric" value=(sender.port.as_str()) maxlength="5">
295 </div>
296 <div class="field">
297 <label for="mail-tls">(t(lang, K::FieldTls))</label>
298 <select id="mail-tls" name="tls">
299 <option value="implicit" selected=(flag(tls_implicit))>(t(lang, K::TlsImplicit))</option>
300 <option value="starttls" selected=(flag(tls_starttls))>(t(lang, K::TlsStartTls))</option>
301 <option value="plain" selected=(flag(tls_plain))>(t(lang, K::TlsPlain))</option>
302 </select>
303 </div>
304 <div class="field">
305 <label for="mail-user">(t(lang, K::FieldUsername))</label>
306 <input id="mail-user" name="username" value=(sender.username.as_str()) maxlength="254" autocomplete="off">
307 </div>
308 <div class="field">
309 <label for="mail-password">(t(lang, K::FieldPassword))</label>
310 <input id="mail-password" type="password" name="password" maxlength="512" autocomplete="new-password">
311 <p class="field-hint">(password_state) " " (t(lang, K::PasswordHint))</p>
312 </div>
313 <div class="field">
314 <label for="mail-from">(t(lang, K::FieldFromAddress))</label>
315 <input id="mail-from" type="email" name="from_address" value=(sender.from_address.as_str()) maxlength="254">
316 </div>
317 <div class="field">
318 <label for="mail-from-name">(t(lang, K::FieldFromName))</label>
319 <input id="mail-from-name" name="from_name" value=(sender.from_name.as_str()) maxlength="100">
320 <p class="field-hint">(t(lang, K::FromNameHint))</p>
321 </div>
322 <button class="button primary" type="submit">(t(lang, K::SaveSender))</button>
323 </form>
324 <div class="actions">
325 <form method="post" action="/settings/sender/check">
326 <input type="hidden" name="csrf" value=(csrf)>
327 <button class="button" type="submit">(t(lang, K::CheckConnection))</button>
328 </form>
329 <form method="post" action="/settings/sender/test">
330 <input type="hidden" name="csrf" value=(csrf)>
331 <button class="button" type="submit">(t(lang, K::SendTestMail))</button>
332 </form>
333 </div>
334 </section>
335 <section class="card">
336 <h2>(t(lang, K::RemindersHeading))</h2>
337 <form method="post" action="/settings/reminders" class="stack">
338 <input type="hidden" name="csrf" value=(csrf)>
339 <div class="field">
340 <label for="rem-lead">(t(lang, K::ReminderLead))</label>
341 <input id="rem-lead" name="lead" inputmode="numeric" value=(lead.as_str()) maxlength="4">
342 </div>
343 <div class="field">
344 <label for="rem-cap">(t(lang, K::ReminderCap))</label>
345 <input id="rem-cap" name="cap" inputmode="numeric" value=(cap.as_str()) maxlength="4">
346 </div>
347 <button class="button" type="submit">(t(lang, K::SaveReminders))</button>
348 </form>
349 </section>
350 <section class="card">
351 <h2>(t(lang, K::MessageHeading))</h2>
352 <p class="field-hint">(t(lang, K::MessageHelp))</p>
353 <form method="post" action="/settings/message" class="stack">
354 <input type="hidden" name="csrf" value=(csrf)>
355 <div class="field">
356 <label for="msg-subject">(t(lang, K::MessageSubject))</label>
357 <input id="msg-subject" name="subject" maxlength="200" required=(flag(true))>
358 </div>
359 <div class="field">
360 <label for="msg-body">(t(lang, K::MessageBody))</label>
361 <textarea id="msg-body" name="body" maxlength="20000" required=(flag(true))></textarea>
362 </div>
363 <button class="button" type="submit">(t(lang, K::SendMessage))</button>
364 </form>
365 </section>
366 <section class="card" id="backups">
367 <h2>(t(lang, K::BackupHeading))</h2>
368 if page.backup.enabled {
369 <p class="field-hint">(t(lang, K::BackupHelp))</p>
370 if page.backup.stale {
371 <div class="warning" role="status">(t(lang, K::BackupStale))</div>
372 }
373 if !page.backup.last_error.is_empty() {
374 backup_failed_alert(lang: lang, error: page.backup.last_error.as_str())
375 }
376 <p class="field-hint">(backup_line(lang, K::BackupLastSuccess, page.backup.last_success.as_str()))</p>
377 <p class="field-hint">(backup_line(lang, K::BackupLastAttempt, page.backup.last_attempt.as_str()))</p>
378 <form method="post" action="/settings/backup">
379 <input type="hidden" name="csrf" value=(csrf)>
380 <button class="button" type="submit">(t(lang, K::BackupNow))</button>
381 </form>
382 } else {
383 <p class="field-hint">(t(lang, K::BackupOff))</p>
384 }
385 </section>
386 <section class="card" id="deleted">
387 <h2>(t(lang, K::DeletedHeading))</h2>
388 <p class="field-hint">(t(lang, K::DeletedHelp))</p>
389 if page.deleted.is_empty() {
390 <p class="field-hint">(t(lang, K::DeletedEmpty))</p>
391 } else {
392 <table class="admin-table">
393 <thead>
394 <tr>
395 <th>(t(lang, K::DeletedTaskHeader))</th>
396 <th>(t(lang, K::DeletedAtHeader))</th>
397 <th>(t(lang, K::DeletedByHeader))</th>
398 <th></th>
399 </tr>
400 </thead>
401 <tbody>
402 for row in page.deleted.iter() {
403 <tr>
404 <td>(row.key.as_str()) " " (row.title.as_str())</td>
405 <td>(row.at.as_str())</td>
406 <td>
407 if let Some(name) = &row.by {
408 (name.as_str())
409 } else {
410 (t(lang, K::DeletedUnknown))
411 }
412 </td>
413 <td>
414 <form method="post" action=(format!("/settings/deleted/{}/restore", row.id)) class="inline">
415 <input type="hidden" name="csrf" value=(csrf)>
416 <button class="button" type="submit">(t(lang, K::RestoreButton))</button>
417 </form>
418 </td>
419 </tr>
420 }
421 </tbody>
422 </table>
423 }
424 </section>
425 members_section(lang: lang, members: &page.members, csrf: csrf)
426 storage_section(lang: lang, info: &page.storage, csrf: csrf)
427 limits_section(lang: lang, limit_mib: page.limit_mib.as_str(), extensions: page.extensions.as_str(), csrf: csrf)
428 server_section(lang: lang, info: &page.server)
429 })
430}
431
432/// The rules page body: the list with the sentence of each rule, then the form.
433#[component]
434pub async fn rules_content(page: &RulesView, csrf: &str) -> Result<impl View> {
435 let lang = page.lang;
436 let form = &page.form;
437 let heading = if page.editing.is_some() {
438 t(lang, K::EditRule)
439 } else {
440 t(lang, K::NewRule)
441 };
442 let audiences = ["assignees", "board", "creator", "watchers"];
443 let triggers = iz_core::rules::TRIGGERS;
444 Ok(view! {
445 <h1>(t(lang, K::RulesTitle))</h1>
446 <p class="field-hint">(t(lang, K::RulesHelp))</p>
447 admin_tabs(lang: lang, current: "rules")
448 if let Some(message) = &page.alert {
449 alert(message: message.as_str())
450 }
451 if let Some(message) = &page.notice {
452 notice(message: message.as_str())
453 }
454 <section class="card">
455 if page.rules.is_empty() {
456 <p>(t(lang, K::NoRules))</p>
457 }
458 <ul class="rule-list">
459 for rule in page.rules.iter() {
460 <li class="rule-row">
461 <div>
462 <strong>(rule.name.as_str())</strong>
463 <p>(rule.sentence.as_str())</p>
464 </div>
465 <div class="actions">
466 <form method="post" action=(format!("/rules/{}/enabled", rule.id)) class="inline">
467 <input type="hidden" name="csrf" value=(csrf)>
468 <input type="hidden" name="enabled" value=(if rule.enabled { "" } else { "1" })>
469 <button class="button" type="submit">(if rule.enabled { t(lang, K::RuleOn) } else { t(lang, K::RuleOff) })</button>
470 </form>
471 <a class="button" href=(format!("/rules?edit={}", rule.id))>(t(lang, K::Edit))</a>
472 <form method="post" action=(format!("/rules/{}/delete", rule.id)) class="inline">
473 <input type="hidden" name="csrf" value=(csrf)>
474 <button class="button danger" type="submit">(t(lang, K::Delete))</button>
475 </form>
476 </div>
477 </li>
478 }
479 </ul>
480 <a class="button primary" href="/rules?new=1">(t(lang, K::NewRule))</a>
481 </section>
482 if page.show_form {
483 <section class="card">
484 <h2>(heading)</h2>
485 <form method="post" action=(match &page.editing { Some(id) => format!("/rules/{id}/edit"), None => "/rules".to_owned() }) class="stack">
486 <input type="hidden" name="csrf" value=(csrf)>
487 <div class="field">
488 <label for="rule-name">(t(lang, K::FieldName))</label>
489 <input id="rule-name" name="name" maxlength="120" value=(form.name.as_str()) required=(flag(true))>
490 </div>
491 <div class="field">
492 <label for="rule-trigger">(t(lang, K::FieldTrigger))</label>
493 <select id="rule-trigger" name="trigger">
494 for word in triggers.iter() {
495 <option value=(*word) selected=(flag(form.trigger == *word))>(trigger_label(lang, word))</option>
496 }
497 </select>
498 </div>
499 <div class="field">
500 <label for="rule-column">(t(lang, K::FieldColumn))</label>
501 <select id="rule-column" name="column">
502 <option value="" selected=(flag(form.column.is_empty()))>(t(lang, K::AnyColumn))</option>
503 for (id, name) in page.columns.iter() {
504 <option value=(id.as_str()) selected=(flag(form.column == *id))>(name.as_str())</option>
505 }
506 </select>
507 </div>
508 <div class="field">
509 <label for="rule-tag">(t(lang, K::FieldProject))</label>
510 <select id="rule-tag" name="tag">
511 <option value="" selected=(flag(form.tag.is_empty()))>(t(lang, K::AnyProject))</option>
512 for (id, name) in page.tags.iter() {
513 <option value=(id.as_str()) selected=(flag(form.tag == *id))>(name.as_str())</option>
514 }
515 </select>
516 </div>
517 <div class="field">
518 <label for="rule-audience">(t(lang, K::FieldAudience))</label>
519 <select id="rule-audience" name="audience">
520 for word in audiences.iter() {
521 <option value=(*word) selected=(flag(form.audience == *word))>(audience_label(lang, word))</option>
522 }
523 </select>
524 </div>
525 <div class="field">
526 <label for="rule-subject">(t(lang, K::FieldSubject))</label>
527 <input id="rule-subject" name="subject" maxlength="120" value=(form.subject.as_str()) required=(flag(true))>
528 <p class="field-hint">(t(lang, K::SubjectHint))</p>
529 </div>
530 <label class="check">
531 <input type="checkbox" name="include_details" value="on" checked=(flag(form.include_details))>
532 (t(lang, K::IncludeDetails))
533 </label>
534 <label class="check">
535 <input type="checkbox" name="enabled" value="on" checked=(flag(form.enabled))>
536 (t(lang, K::Enabled))
537 </label>
538 <div class="actions">
539 <button class="button primary" type="submit">(t(lang, K::SaveRule))</button>
540 <a class="button" href="/rules">(t(lang, K::CancelEdit))</a>
541 </div>
542 </form>
543 </section>
544 }
545 })
546}
547
548/// The logs page body: the section tabs, the filter for the activity, and the rows of the section.
549#[component]
550pub async fn logs_content(page: &LogsView, csrf: &str, lang: Lang) -> Result<impl View> {
551 let outbox = page.section == LogSection::Outbox;
552 let decisions = page.section == LogSection::Decisions;
553 let activity = page.section == LogSection::Activity;
554 Ok(view! {
555 <h1>(t(lang, K::LogsTitle))</h1>
556 if let Some(message) = &page.notice {
557 notice(message: message.as_str())
558 }
559 <nav class="tabs" aria-label=(t(lang, K::LogsTitle))>
560 <a class=(if outbox { "tab current" } else { "tab" }) href="/logs?section=outbox">(t(lang, K::SectionOutbox))</a>
561 <a class=(if decisions { "tab current" } else { "tab" }) href="/logs?section=decisions">(t(lang, K::SectionDecisions))</a>
562 <a class=(if activity { "tab current" } else { "tab" }) href="/logs?section=activity">(t(lang, K::SectionActivity))</a>
563 </nav>
564 admin_tabs(lang: lang, current: "logs")
565 if outbox {
566 <section class="card">
567 if page.outbox.is_empty() {
568 <p>(t(lang, K::NothingYet))</p>
569 } else {
570 <table class="log-table">
571 <thead><tr>
572 <th>(t(lang, K::ColWhen))</th>
573 <th>(t(lang, K::ColRecipient))</th>
574 <th>(t(lang, K::ColSubject))</th>
575 <th>(t(lang, K::ColState))</th>
576 <th>(t(lang, K::ColAttempts))</th>
577 <th>(t(lang, K::ColLastError))</th>
578 <th></th>
579 </tr></thead>
580 <tbody>
581 for (row, attempts) in page.outbox.iter().map(|r| (r, r.attempts.to_string())) {
582 <tr>
583 <td>(row.created_at.as_str())</td>
584 <td>(row.recipient_name.as_str()) " <" (row.recipient_email.as_str()) ">"</td>
585 <td>(row.subject.as_str())</td>
586 <td>(outbox_state(lang, row.state.as_str()))</td>
587 <td>(attempts.as_str())</td>
588 <td>(row.last_error.as_deref().unwrap_or(""))</td>
589 <td>
590 if row.state == "failed" || row.state == "abandoned" {
591 <form method="post" action=(format!("/logs/outbox/{}/retry", row.id)) class="inline">
592 <input type="hidden" name="csrf" value=(csrf)>
593 <button class="button" type="submit">(t(lang, K::Retry))</button>
594 </form>
595 }
596 </td>
597 </tr>
598 }
599 </tbody>
600 </table>
601 }
602 </section>
603 }
604 if decisions {
605 <section class="card">
606 if page.decisions.is_empty() {
607 <p>(t(lang, K::NothingYet))</p>
608 } else {
609 <table class="log-table">
610 <thead><tr>
611 <th>(t(lang, K::ColWhen))</th>
612 <th>(t(lang, K::ColRule))</th>
613 <th>(t(lang, K::ColTask))</th>
614 <th>(t(lang, K::ColOutcome))</th>
615 <th>(t(lang, K::ColDetail))</th>
616 </tr></thead>
617 <tbody>
618 for row in page.decisions.iter() {
619 <tr>
620 <td>(row.at.as_str())</td>
621 <td>(row.rule_name.as_str())</td>
622 <td>(row.task_key.as_deref().unwrap_or(""))</td>
623 <td>(outcome_label(lang, row.outcome.as_str()))</td>
624 <td>(reason_label(lang, row.detail.as_str()))</td>
625 </tr>
626 }
627 </tbody>
628 </table>
629 }
630 </section>
631 }
632 if activity {
633 <section class="card">
634 <form method="get" action="/logs" class="filter-bar">
635 <input type="hidden" name="section" value="activity">
636 <label for="log-kind">(t(lang, K::FilterKind))</label>
637 <input id="log-kind" name="kind" value=(page.kind.as_str()) maxlength="40">
638 <button class="button" type="submit">(t(lang, K::Apply))</button>
639 </form>
640 if page.activity.is_empty() {
641 <p>(t(lang, K::NothingYet))</p>
642 } else {
643 <table class="log-table">
644 <thead><tr>
645 <th>(t(lang, K::ColWhen))</th>
646 <th>(t(lang, K::ColWho))</th>
647 <th>(t(lang, K::ColWhat))</th>
648 <th>(t(lang, K::ColDetail))</th>
649 </tr></thead>
650 <tbody>
651 for row in page.activity.iter() {
652 <tr>
653 <td>(row.at.as_str())</td>
654 <td>(row.who.as_str())</td>
655 <td>(row.kind.as_str())</td>
656 <td><code>(row.detail.as_str())</code></td>
657 </tr>
658 }
659 </tbody>
660 </table>
661 }
662 </section>
663 }
664 if let Some(href) = page.next.as_ref() {
665 <p><a class="button" href=(href.as_str())>(t(lang, K::Older))</a></p>
666 }
667 })
668}
669
670/// The word for a trigger in the rules list and form.
671pub fn trigger_label(lang: Lang, word: &str) -> &'static str {
672 t(
673 lang,
674 match word {
675 "status" => K::TrigStatus,
676 "unblocked" => K::TrigUnblocked,
677 "created" => K::TrigCreated,
678 "assigned" => K::TrigAssigned,
679 "unassigned" => K::TrigUnassigned,
680 "commented" => K::TrigCommented,
681 "deadline_set" => K::TrigDeadlineSet,
682 "deadline_cleared" => K::TrigDeadlineCleared,
683 "retitled" => K::TrigRetitled,
684 "linked" => K::TrigLinked,
685 "unlinked" => K::TrigUnlinked,
686 _ => K::TrigDeleted,
687 },
688 )
689}
690
691/// The phrase of an audience.
692pub fn audience_label(lang: Lang, word: &str) -> &'static str {
693 t(
694 lang,
695 match word {
696 "assignees" => K::AudAssignees,
697 "board" => K::AudBoard,
698 "creator" => K::AudCreator,
699 _ => K::AudWatchers,
700 },
701 )
702}
703
704/// The label of an outbox state.
705fn outbox_state(lang: Lang, state: &str) -> &'static str {
706 t(
707 lang,
708 match state {
709 "sent" => K::StateSent,
710 "failed" => K::StateFailed,
711 "abandoned" => K::StateAbandoned,
712 _ => K::StatePending,
713 },
714 )
715}
716
717/// The label of a decision outcome.
718fn outcome_label(lang: Lang, outcome: &str) -> &'static str {
719 t(
720 lang,
721 match outcome {
722 "owed" => K::OutOwed,
723 "already_owed" => K::OutAlreadyOwed,
724 "no_recipients" => K::OutNoRecipients,
725 "not_matched" => K::OutNotMatched,
726 "disabled" => K::OutDisabled,
727 _ => K::OutTaskGone,
728 },
729 )
730}
731
732/// The label of the reason a decision gave, as stored (`column` or `project`).
733fn reason_label(lang: Lang, detail: &str) -> &'static str {
734 match detail {
735 "column" => t(lang, K::ReasonColumn),
736 "project" => t(lang, K::ReasonProject),
737 _ => "",
738 }
739}