Skip to main content

max / makenotwork

7.5 KB · 249 lines History Blame Raw
1 //! Templates for the public git source browser, issues, and repo settings.
2
3 use std::sync::Arc;
4
5 use askama::Template;
6
7 use crate::auth::SessionUser;
8 use crate::git;
9 use crate::types::{Item, Project, Version};
10
11 use super::super::CsrfTokenOption;
12
13 /// An item paired with its versions, for release display on the git repo page.
14 pub struct ReleaseItem {
15 pub item: Item,
16 pub versions: Vec<Version>,
17 }
18
19 /// Repository overview: file tree at HEAD + README.
20 #[derive(Template)]
21 #[template(path = "pages/git/repo.html")]
22 pub struct GitRepoTemplate {
23 pub csrf_token: CsrfTokenOption,
24 pub session_user: Option<SessionUser>,
25 pub owner: String,
26 pub repo_name: String,
27 pub description: Option<String>,
28 pub current_ref: String,
29 pub refs: Vec<git::RefInfo>,
30 pub tree_items: Vec<git::TreeItem>,
31 pub readme_html: Option<String>,
32 pub host_url: Arc<str>,
33 /// Hostname for SSH clone URLs (e.g., "git.makenot.work"). Hidden when `None`.
34 pub git_ssh_host: Option<String>,
35 /// Linked project, if this repo is associated with a public project.
36 pub linked_project: Option<Project>,
37 /// Public items with versions from the linked project (releases).
38 pub release_items: Vec<ReleaseItem>,
39 /// Number of open issues for the nav bar badge.
40 pub open_issue_count: i64,
41 /// Whether the current viewer is the repo owner (for settings link).
42 pub is_owner: bool,
43 pub active_tab: &'static str,
44 }
45
46 /// Subdirectory listing with breadcrumb navigation.
47 #[derive(Template)]
48 #[template(path = "pages/git/tree.html")]
49 pub struct GitTreeTemplate {
50 pub csrf_token: CsrfTokenOption,
51 pub session_user: Option<SessionUser>,
52 pub owner: String,
53 pub repo_name: String,
54 pub current_ref: String,
55 pub refs: Vec<git::RefInfo>,
56 pub path: String,
57 pub parent_path: String,
58 /// Whether we're in a subdirectory (for ".." link and path joining).
59 pub in_subdir: bool,
60 pub breadcrumbs: Vec<git::Breadcrumb>,
61 pub tree_items: Vec<git::TreeItem>,
62 pub open_issue_count: i64,
63 pub is_owner: bool,
64 pub active_tab: &'static str,
65 }
66
67 /// File viewer with syntax highlighting and line numbers.
68 #[derive(Template)]
69 #[template(path = "pages/git/file.html")]
70 pub struct GitFileTemplate {
71 pub csrf_token: CsrfTokenOption,
72 pub session_user: Option<SessionUser>,
73 pub owner: String,
74 pub repo_name: String,
75 pub current_ref: String,
76 pub refs: Vec<git::RefInfo>,
77 pub file_path: String,
78 pub filename: String,
79 pub breadcrumbs: Vec<git::Breadcrumb>,
80 pub file_size: String,
81 pub line_count: usize,
82 pub is_binary: bool,
83 pub highlighted_lines: Vec<String>,
84 pub open_issue_count: i64,
85 pub is_owner: bool,
86 pub active_tab: &'static str,
87 }
88
89 /// Commit log with pagination.
90 #[derive(Template)]
91 #[template(path = "pages/git/commits.html")]
92 pub struct GitCommitsTemplate {
93 pub csrf_token: CsrfTokenOption,
94 pub session_user: Option<SessionUser>,
95 pub owner: String,
96 pub repo_name: String,
97 pub current_ref: String,
98 pub refs: Vec<git::RefInfo>,
99 pub commits: Vec<git::CommitInfo>,
100 pub page: usize,
101 pub has_more: bool,
102 pub open_issue_count: i64,
103 /// Whether the current viewer is the repo owner (for settings link).
104 pub is_owner: bool,
105 pub active_tab: &'static str,
106 }
107
108 /// Commit detail page with inline diffs.
109 #[derive(Template)]
110 #[template(path = "pages/git/commit.html")]
111 pub struct GitCommitDetailTemplate {
112 pub csrf_token: CsrfTokenOption,
113 pub session_user: Option<SessionUser>,
114 pub owner: String,
115 pub repo_name: String,
116 pub current_ref: String,
117 pub refs: Vec<git::RefInfo>,
118 pub detail: git::CommitDetail,
119 pub diff_files: Vec<git::DiffFile>,
120 pub total_files: usize,
121 pub total_additions: usize,
122 pub total_deletions: usize,
123 pub open_issue_count: i64,
124 pub is_owner: bool,
125 pub active_tab: &'static str,
126 }
127
128 /// Blame view for a single file.
129 #[derive(Template)]
130 #[template(path = "pages/git/blame.html")]
131 pub struct GitBlameTemplate {
132 pub csrf_token: CsrfTokenOption,
133 pub session_user: Option<SessionUser>,
134 pub owner: String,
135 pub repo_name: String,
136 pub current_ref: String,
137 pub refs: Vec<git::RefInfo>,
138 pub file_path: String,
139 pub filename: String,
140 pub breadcrumbs: Vec<git::Breadcrumb>,
141 pub blame_lines: Vec<git::BlameLine>,
142 pub open_issue_count: i64,
143 pub is_owner: bool,
144 pub active_tab: &'static str,
145 }
146
147 /// User's repository listing page.
148 #[derive(Template)]
149 #[template(path = "pages/git/repos.html")]
150 pub struct GitUserReposTemplate {
151 pub csrf_token: CsrfTokenOption,
152 pub session_user: Option<SessionUser>,
153 pub owner: String,
154 pub repos: Vec<crate::db::DbGitRepo>,
155 pub is_owner: bool,
156 }
157
158 /// Public explore page listing all public repos across all users.
159 #[derive(Template)]
160 #[template(path = "pages/git/explore.html")]
161 pub struct GitExploreTemplate {
162 pub csrf_token: CsrfTokenOption,
163 pub session_user: Option<SessionUser>,
164 pub repos: Vec<crate::db::git_repos::PublicRepoWithOwner>,
165 pub page: usize,
166 pub has_more: bool,
167 pub total_count: i64,
168 }
169
170 /// Per-file commit history with breadcrumb context.
171 #[derive(Template)]
172 #[template(path = "pages/git/file_log.html")]
173 pub struct GitFileLogTemplate {
174 pub csrf_token: CsrfTokenOption,
175 pub session_user: Option<SessionUser>,
176 pub owner: String,
177 pub repo_name: String,
178 pub current_ref: String,
179 pub refs: Vec<git::RefInfo>,
180 pub file_path: String,
181 pub filename: String,
182 pub breadcrumbs: Vec<git::Breadcrumb>,
183 pub commits: Vec<git::CommitInfo>,
184 pub page: usize,
185 pub has_more: bool,
186 pub open_issue_count: i64,
187 pub is_owner: bool,
188 pub active_tab: &'static str,
189 }
190
191 // Git Issues
192
193 /// Issue list page with status tabs and search (read-only).
194 #[derive(Template)]
195 #[template(path = "pages/git/issues.html")]
196 pub struct GitIssueListTemplate {
197 pub csrf_token: CsrfTokenOption,
198 pub session_user: Option<SessionUser>,
199 pub owner: String,
200 pub repo_name: String,
201 pub current_ref: String,
202 pub issues: Vec<crate::db::DbIssueWithMeta>,
203 pub open_count: i64,
204 pub closed_count: i64,
205 pub current_status: String,
206 pub search_query: String,
207 pub current_page: i64,
208 pub total_pages: i64,
209 /// Whether the current viewer is the repo owner (for settings link).
210 pub is_owner: bool,
211 /// Email address for submitting new issues.
212 pub email_address: String,
213 }
214
215 /// Issue detail page with comments (read-only).
216 #[derive(Template)]
217 #[template(path = "pages/git/issue.html")]
218 pub struct GitIssueDetailTemplate {
219 pub csrf_token: CsrfTokenOption,
220 pub session_user: Option<SessionUser>,
221 pub owner: String,
222 pub repo_name: String,
223 pub current_ref: String,
224 pub issue: crate::db::DbIssue,
225 pub author_username: String,
226 pub comments: Vec<crate::db::DbIssueCommentWithAuthor>,
227 pub is_owner: bool,
228 pub open_issue_count: i64,
229 /// Email address for submitting new issues.
230 pub email_address: String,
231 }
232
233 /// Repository settings page (owner only).
234 #[derive(Template)]
235 #[template(path = "pages/git/settings.html")]
236 pub struct GitRepoSettingsTemplate {
237 pub csrf_token: CsrfTokenOption,
238 pub session_user: Option<SessionUser>,
239 pub owner: String,
240 pub repo_name: String,
241 pub current_ref: String,
242 pub repo: crate::db::DbGitRepo,
243 pub open_issue_count: i64,
244 /// Owner's projects for the link dropdown.
245 pub projects: Vec<crate::db::DbProject>,
246 /// ID of the currently linked project as a string (for dropdown comparison).
247 pub linked_project_id: String,
248 }
249