Commit d6bf1411 authored by Robert Czechowski's avatar Robert Czechowski

Enable configuration options to be passed through to certain (later possibly...

Enable configuration options to be passed through to certain (later possibly all) templates directly
parent ad74d675
......@@ -32,12 +32,11 @@ pub struct Config {
pub cookie_signing_secret: Option<String>,
pub disable_results_page: Option<bool>,
pub enable_password_login: Option<bool>,
pub server_message: Option<String>,
pub teacher_page: Option<String>,
pub require_sex: Option<bool>,
pub allow_sex_na: Option<bool>,
pub allow_sex_diverse: Option<bool>,
pub allow_sex_other: Option<bool>,
pub template_params: Option<::std::collections::BTreeMap<String, String>>,
}
#[derive(StructOpt, Debug)]
......
......@@ -1173,8 +1173,7 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id:
Ok(result)
}
pub fn teacher_infos<T: MedalConnection>(conn: &T, session_token: &str, teacher_page: Option<&str>)
-> MedalValueResult {
pub fn teacher_infos<T: MedalConnection>(conn: &T, session_token: &str) -> MedalValueResult {
let session = conn.get_session(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?;
if !session.is_teacher {
return Err(MedalError::AccessDenied);
......@@ -1183,10 +1182,6 @@ pub fn teacher_infos<T: MedalConnection>(conn: &T, session_token: &str, teacher_
let mut data = json_val::Map::new();
fill_user_data(&session, &mut data);
if let Some(teacher_page) = teacher_page {
data.insert("teacher_page".to_string(), to_json(&teacher_page));
}
Ok(("teacher".to_string(), data))
}
......
......@@ -214,7 +214,6 @@ fn main() {
// Let options override config values
opt.databasefile.map(|x| config.database_file = Some(x));
opt.databaseurl.map(|x| config.database_url = Some(x));
opt.teacherpage.map(|x| config.teacher_page = Some(x));
opt.port.map(|x| config.port = Some(x));
config.no_contest_scan = if opt.nocontestscan { Some(true) } else { config.no_contest_scan };
config.open_browser = if opt.openbrowser { Some(true) } else { config.open_browser };
......
......@@ -315,10 +315,7 @@ fn greet_personal<C>(req: &mut Request) -> IronResult<Response>
let config = req.get::<Read<SharedConfiguration>>().unwrap();
let (template, mut data) = with_conn![core::index, C, req, session_token, login_info(&config)];
/*if let Some(server_message) = &config.server_message {
data.insert("server_message".to_string(), to_json(&server_message));
}*/
config.server_message.as_ref().map(|sm| data.insert("server_message".to_string(), to_json(&sm)));
data.insert("config".to_string(), to_json(&config.template_params));
// Antwort erstellen und zurücksenden
let mut resp = Response::new();
......@@ -398,7 +395,7 @@ fn contests<C>(req: &mut Request) -> IronResult<Response>
let config = req.get::<Read<SharedConfiguration>>().unwrap();
let (template, mut data) = with_conn![core::show_contests, C, req, &session_token, login_info(&config), visibility];
config.server_message.as_ref().map(|sm| data.insert("server_message".to_string(), to_json(&sm)));
data.insert("config".to_string(), to_json(&config.template_params));
if query_string.contains("results") {
data.insert("direct_link_to_results".to_string(), to_json(&true));
......@@ -784,12 +781,10 @@ fn profile<C>(req: &mut Request) -> IronResult<Response>
let si = {
let config = req.get::<Read<SharedConfiguration>>().unwrap();
core::SexInformation {
require_sex: config.require_sex.unwrap_or(false),
allow_sex_na: config.allow_sex_na.unwrap_or(true),
allow_sex_diverse: config.allow_sex_diverse.unwrap_or(false),
allow_sex_other: config.allow_sex_other.unwrap_or(true),
}
core::SexInformation { require_sex: config.require_sex.unwrap_or(false),
allow_sex_na: config.allow_sex_na.unwrap_or(true),
allow_sex_diverse: config.allow_sex_diverse.unwrap_or(false),
allow_sex_other: config.allow_sex_other.unwrap_or(true) }
};
let (template, data) = with_conn![core::show_profile, C, req, &session_token, None, query_string, si].aug(req)?;
......@@ -839,12 +834,10 @@ fn user<C>(req: &mut Request) -> IronResult<Response>
let si = {
let config = req.get::<Read<SharedConfiguration>>().unwrap();
core::SexInformation {
require_sex: config.require_sex.unwrap_or(false),
allow_sex_na: config.allow_sex_na.unwrap_or(true),
allow_sex_diverse: config.allow_sex_diverse.unwrap_or(false),
allow_sex_other: config.allow_sex_other.unwrap_or(true),
}
core::SexInformation { require_sex: config.require_sex.unwrap_or(false),
allow_sex_na: config.allow_sex_na.unwrap_or(true),
allow_sex_diverse: config.allow_sex_diverse.unwrap_or(false),
allow_sex_other: config.allow_sex_other.unwrap_or(true) }
};
let (template, data) =
......@@ -895,9 +888,9 @@ fn teacherinfos<C>(req: &mut Request) -> IronResult<Response>
let config = req.get::<Read<SharedConfiguration>>().unwrap();
let (template, data) =
with_conn![core::teacher_infos, C, req, &session_token, config.teacher_page.as_ref().map(|x| &**x)].aug(req)?;
// .as_ref().map(|x| &**x) can be written as .as_deref() since rust 1.40
let (template, mut data) = with_conn![core::teacher_infos, C, req, &session_token].aug(req)?;
data.insert("config".to_string(), to_json(&config.template_params));
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......
......@@ -16,7 +16,7 @@
}
</style>
</head>
<body style="background-color: {{#if server_message}}#fbebeb{{else}}white{{/if}};">
<body style="background-color: {{#if config.server_message}}#fbebeb{{else}}white{{/if}};">
<div class="container" style="padding: 1.5rem;">
<div class="columns">
<div class="column is-7">
......@@ -68,7 +68,7 @@
<form action="/clogin" method="post" autocomplete="off" class="columns blogin">
<div class="column is-8"><input class="input is-small" type="text" name="code" placeholder="Gruppencode oder Logincode" autofocus></div>
<div class="column"><input class="button is-small is-success" type="submit" value="↪ &nbsp; Login" style="font-weight:bold;">
&nbsp; <a href="https://bwinf.de/jugendwettbewerb/teilnehmen/schueler/" style="font-size: small;"> (?)</a>
{{#if config.login_helper_link}} &nbsp; <a href="{{ config.login_helper_link }}" style="font-size: small;"> (?)</a>{{/if}}
</div>
</form>
{{#if self_url}}
......@@ -85,12 +85,12 @@
</div>
</div>
{{#if server_message}}
{{#if config.server_message}}
{{#if firstlogin }}{{else}}
<div class="columns">
<div class="column is-8 is-offset-2">
<div class="notification is-danger">
{{{ server_message }}}
{{{ config.server_message }}}
</div>
</div>
</div>
......
......@@ -36,13 +36,15 @@
</div>
</div>
<div class="tile">
<div class="tile is-6 is-parent">
<a href="https://bwinf.de/jwinfportal" class="tile is-child notification">
<h3 class="title is-4">➚ Informationen</h3>
<img src="/static/images/logomittext.png" style="width:60%; margin: -25px 20% 25px;">
➚ Informationen zur Anmeldung und Teilnahme am Wettbewerb, Termine, Materialien und mehr …
</a>
</div>
{{#if config.information_link}}
<div class="tile is-6 is-parent">
<a href="{{ config.information_link }}" class="tile is-child notification">
<h3 class="title is-4">➚ Informationen</h3>
<img src="/static/images/logomittext.png" style="width:60%; margin: -25px 20% 25px;">
➚ Informationen zur Anmeldung und Teilnahme am Wettbewerb, Termine, Materialien und mehr …
</a>
</div>
{{/if}}
<div class="tile is-parent is-6">
<a href="/contest/?filter=challenge" class="tile is-child notification" style="background-color: #fff1ea">
<h3 class="title is-4">Herausforderungen</h3>
......
......@@ -2,8 +2,8 @@
<div class="columns">
<div class="column is-8 is-offset-2">
<h3 class="title is-4">Lehrer-Informationen</h3>
{{#if teacher_page }}
<iframe src="/tasks/{{ teacher_page }}" style="height: calc(100vh - 550px); min-height:200px; width: 100%"></iframe>
{{#if config.teacher_page }}
<iframe src="/tasks/{{ config.teacher_page }}" style="height: calc(100vh - 550px); min-height:200px; width: 100%"></iframe>
{{else}}
<em>Noch keine Informationen vorhanden</em>
{{/if}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment