1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
// Back - An extremely simple git issue tracking system. Inspired by tvix's
// panettone
//
// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de>
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// This file is part of Back.
//
// You should have received a copy of the License along with this program.
// If not, see <https://www.gnu.org/licenses/agpl.txt>.
use rocket::response::content::RawHtml;
use crate::{
config::BackConfig,
git_bug::{
format::HtmlString,
issue::{identity::Author, CollapsedIssue, Comment},
},
};
impl CollapsedIssue {
pub fn to_list_entry(&self) -> RawHtml<String> {
let comment_list = if self.comments.is_empty() {
String::new()
} else {
let comments_string = if self.comments.len() > 1 {
"comments"
} else {
"comment"
};
format!(
r#"
<span class="comment-count"> - {} {}</span>
"#,
self.comments.len(),
comments_string
)
};
let CollapsedIssue {
id,
title,
message: _,
author,
timestamp,
comments: _,
status: _,
last_status_change: _,
labels: _,
} = self;
let Author { name, email, id: _ } = author;
RawHtml(format!(
r#"
<li>
<a href="/issue/{id}">
<p>
<span class="issue-subject">{title}</span>
</p>
<span class="issue-number">{id}</span> - <span class="created-by-at">Opened by <span class="user-name">{name}</span> <span class="user-email"><{email}></span> at <span class="timestamp">{timestamp}</span></span>{comment_list} </a>
</li>
"#,
))
}
pub fn to_html(&self, config: &BackConfig) -> RawHtml<String> {
let comments = if self.comments.is_empty() {
String::new()
} else {
let fmt_comments: String = self
.comments
.iter()
.map(|val| {
let Comment {
id,
author,
message,
timestamp,
} = val;
let Author {
name,
email: _,
id: _,
} = author;
format!(
r#"
<li class="comment" id="{id}">
{message}
<p class="comment-info"><span class="user-name">{name} at {timestamp}</span></p>
</li>
"#,
)
})
.collect::<Vec<String>>()
.join("\n");
format!(
r#"
<ol class="issue-history">
{fmt_comments}
</ol>
"#
)
};
{
let CollapsedIssue {
id,
title,
message,
author,
timestamp,
comments: _,
status: _,
last_status_change: _,
labels: _,
} = self;
let Author { name, email, id: _ } = author;
let html_title = HtmlString::from(title.clone());
RawHtml(format!(
r#"
<!DOCTYPE html>
<html lang="en">
<head>
<title>{html_title} | Back</title>
<link href="/style.css" rel="stylesheet" type="text/css">
<meta content="width=device-width,initial-scale=1" name="viewport">
</head>
<body>
<div class="content">
<nav>
<a href="/issues/open">Open Issues</a>
<a href="/issues/closed">Closed Issues</a>
</nav>
<header>
<h1>{title}</h1>
<div class="issue-number">{id}</div>
</header>
<main>
<div class="issue-info">
<span class="created-by-at">Opened by <span class="user-name">{name}</span> <span class="user-email"><{email}></span> at <span class="timestamp">{timestamp}</span></span>
</div>
{message}
{comments}
</main>
<footer>
<nav>
<a href="/issues/open">Open Issues</a>
<a href="{}">Source code</a>
<a href="/issues/closed">Closed Issues</a>
</nav>
</footer>
</div>
</body>
</html>
"#,
config.source_code_repository_url
))
}
}
}
|