Author: Manos Pitsidianakis [manos@pitsidianak.is]
Hash: bedb47981bda78900b5657a98c75836c5cb60f42
Timestamp: Sun, 29 Oct 2023 11:18:22 +0000 (10 months ago)

+77 -1 +/-2 browse
web: add accept sub request option
web: add accept sub request option

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
1diff --git a/web/src/lists.rs b/web/src/lists.rs
2index e9c2009..27358dc 100644
3--- a/web/src/lists.rs
4+++ b/web/src/lists.rs
5 @@ -463,6 +463,18 @@ pub async fn list_edit_POST(
6 },
7 )?;
8 }
9+ ChangeSetting::AcceptSubscriptionRequest { pk: IntPOST(pk) } => {
10+ session.add_message(match db.accept_candidate_subscription(pk) {
11+ Ok(subscription) => Message {
12+ message: format!("Added: {subscription:#?}").into(),
13+ level: Level::Success,
14+ },
15+ Err(err) => Message {
16+ message: format!("Could not accept subscription request! Reason: {err}").into(),
17+ level: Level::Error,
18+ },
19+ })?;
20+ }
21 }
22
23 Ok(Redirect::to(&format!(
24 @@ -504,6 +516,9 @@ pub enum ChangeSetting {
25 #[serde(default)]
26 archive_url: Option<String>,
27 },
28+ AcceptSubscriptionRequest {
29+ pk: IntPOST,
30+ },
31 }
32
33 #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
34 @@ -723,12 +738,14 @@ pub async fn list_candidates(
35 .connection
36 .prepare("SELECT * FROM candidate_subscription WHERE list = ?;")?;
37 let iter = stmt.query_map([&list.pk], |row| {
38+ let pk: i64 = row.get("pk")?;
39 let address: String = row.get("address")?;
40 let name: Option<String> = row.get("name")?;
41 let accepted: Option<i64> = row.get("accepted")?;
42 let created: i64 = row.get("created")?;
43 let last_modified: i64 = row.get("last_modified")?;
44 Ok(minijinja::context! {
45+ pk,
46 address,
47 name,
48 accepted => accepted.is_some(),
49 @@ -774,6 +791,8 @@ pub async fn list_candidates(
50 crumbs,
51 };
52 Ok(Html(
53- TEMPLATES.get_template("lists/subs.html")?.render(context)?,
54+ TEMPLATES
55+ .get_template("lists/sub-requests.html")?
56+ .render(context)?,
57 ))
58 }
59 diff --git a/web/src/templates/lists/sub-requests.html b/web/src/templates/lists/sub-requests.html
60new file mode 100644
61index 0000000..72d6137
62--- /dev/null
63+++ b/web/src/templates/lists/sub-requests.html
64 @@ -0,0 +1,57 @@
65+ {% include "header.html" %}
66+ <div class="body body-grid">
67+ <style>
68+ table {
69+ border-collapse: collapse;
70+ border: 2px solid rgb(200,200,200);
71+ letter-spacing: 1px;
72+ }
73+
74+ td, th {
75+ border: 1px solid rgb(190,190,190);
76+ padding: 0.1rem 1rem;
77+ }
78+
79+ th {
80+ background-color: var(--background-tertiary);
81+ }
82+
83+ td {
84+ text-align: center;
85+ }
86+
87+ caption {
88+ padding: 10px;
89+ }
90+ </style>
91+ <p>{{ subs|length }} entr{{ subs|length|pluralize("y","ies") }}.</a></p>
92+ {% if subs %}
93+ <div style="overflow: scroll;">
94+ <table>
95+ <tr>
96+ {% for key,val in subs|first|items %}
97+ <th>{{ key }}</th>
98+ {% endfor %}
99+ <th></th>
100+ </tr>
101+ {% for s in subs %}
102+ <tr>
103+ {% for key,val in s|items %}
104+ <td>{{ val }}</td>
105+ {% endfor %}
106+ <td>
107+ {% if not s.accepted %}
108+ <form method="post" action="{{ list_edit_path(list.id) }}" class="settings-form">
109+ <input type="hidden" name="type" value="accept-subscription-request">
110+ <input type="hidden" name="pk" value="{{ s.pk }}">
111+ <input type="submit" value="Accept">
112+ </form>
113+ {% endif %}
114+ </td>
115+ </tr>
116+ {% endfor %}
117+ </table>
118+ </div>
119+ {% endif %}
120+ </div>
121+ {% include "footer.html" %}