aboutsummaryrefslogtreecommitdiff
path: root/src/forms.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-06-24 19:04:23 +0200
committerMartin Fischer <martin@push-f.com>2021-06-24 19:41:05 +0200
commit26298bcd7ef204db4396ca2d0e603fc183220cd2 (patch)
tree9478019c3a365cb71b7cc41e12885ad25d7592b5 /src/forms.rs
parentd49d835e63ec654e3a5bf75b3b365354460382e8 (diff)
refactor: simplify Page and Context structs
Previously the Page struct contained references to the Controller and the http::request::Parts, so that page.render() could call controller.user_info_html(parts). This commit removes these references from the Page struct, so that it can implement Default in the future. The Context struct needs to be moved around since it contains git2::Repository, which isn't Send. Previously the Context struct also contained the http::request::Parts, so they were moved along. This commit extracts Parts out of the Context struct, so that our service function can access Parts after invoking our build_request method, allowing us to easily log request details for errors in the future.
Diffstat (limited to 'src/forms.rs')
-rw-r--r--src/forms.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/forms.rs b/src/forms.rs
index fc16d09..240d300 100644
--- a/src/forms.rs
+++ b/src/forms.rs
@@ -1,3 +1,4 @@
+use hyper::http::request::Parts;
use serde::Deserialize;
use sputnik::html_escape;
@@ -19,7 +20,8 @@ pub fn edit_text_form<'a, C: Controller>(
error: Option<&str>,
controller: &'a C,
ctx: &'a Context,
-) -> Page<'a> {
+ parts: &Parts,
+) -> Page {
let mut page = Page {
title: format!(
"{} {}",
@@ -33,12 +35,10 @@ pub fn edit_text_form<'a, C: Controller>(
header: data
.oid
.is_some()
- .then(|| action_links("edit", controller, ctx)),
+ .then(|| action_links("edit", controller, ctx, parts)),
body: String::new(),
- controller,
- parts: &ctx.parts,
};
- if let Some(access_info_html) = controller.access_info_html(&ctx) {
+ if let Some(access_info_html) = controller.access_info_html(&ctx, parts) {
page.body.push_str(&access_info_html);
}
if let Some(hint_html) = controller.edit_hint_html(ctx) {
@@ -90,13 +90,12 @@ pub fn move_form<C: Controller>(
error: Option<&str>,
controller: &C,
ctx: &Context,
+ parts: &Parts,
) -> Result<Response, Error> {
let mut page = Page {
title: format!("Move {}", filename),
- controller,
- parts: &ctx.parts,
body: String::new(),
- header: Some(action_links("move", controller, ctx)),
+ header: Some(action_links("move", controller, ctx, parts)),
};
if let Some(error) = error {
@@ -120,7 +119,8 @@ pub fn upload_form<'a, C: Controller>(
file_exists: bool,
controller: &'a C,
ctx: &'a Context,
-) -> Page<'a> {
+ parts: &Parts,
+) -> Page {
let filename = ctx.path.file_name().unwrap().to_str().unwrap();
Page {
title: format!("Uploading {}", filename),
@@ -130,8 +130,6 @@ pub fn upload_form<'a, C: Controller>(
<button>Upload</button>\
</form>"
.into(),
- header: file_exists.then(|| action_links("edit", controller, &ctx)),
- controller,
- parts: &ctx.parts,
+ header: file_exists.then(|| action_links("edit", controller, &ctx, parts)),
}
}