Commit cb2d9344 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Nicer front page and polished task page

parent 1bcaad8c
......@@ -2,6 +2,8 @@ use webfw_iron::{to_json, json_val};
use rusqlite::Connection;
use rand::{thread_rng, Rng};
use db_conn::{MedalConnection, MedalObject};
use db_objects::{Submission, Group};
......@@ -16,6 +18,29 @@ pub fn blaa() -> (String, json_val::Map<String, json_val::Value>) {
("greeting".to_owned(), data)
}
pub fn index<T: MedalConnection>(conn: &T, session_token: Option<String>) -> (String, json_val::Map<String, json_val::Value>) {
let mut data = json_val::Map::new();
//let mut contests = Vec::new();
if let Some(token) = session_token {
if let Some(session) = conn.get_session(token) {
data.insert("logged_in".to_string(), to_json(&true));
data.insert("username".to_string(), to_json(&session.username));
data.insert("firstname".to_string(), to_json(&session.firstname));
data.insert("lastname".to_string(), to_json(&session.lastname));
data.insert("teacher".to_string(), to_json(&session.is_teacher));
}
}
/*contests.push("blaa".to_string());
data.insert("contest".to_string(), to_json(&contests));*/
("index".to_owned(), data)
}
#[derive(Serialize, Deserialize)]
......@@ -173,7 +198,8 @@ pub fn login_with_code<T: MedalConnection>(conn: &T, code: String) -> Result<Res
pub fn logout<T: MedalConnection>(conn: &T, session_token: Option<String>) -> () {
match session_token {
Some(token) => conn.logout(token), _ => ()
Some(token) => conn.logout(token),
_ => ()
}
}
......@@ -313,10 +339,15 @@ pub fn add_group<T: MedalConnection>(conn: &T, session_token: String, csrf_token
return Err(("error".to_owned(), data));
}
let group_code: String = Some('g').into_iter().chain(thread_rng().gen_ascii_chars())
.filter(|x| {let x = *x; !(x == 'l' || x == 'I' || x == '1' || x == 'O' || x == 'o' || x == '0')})
.take(7).collect();
// todo: check for collisions
let mut group = Group {
id: None,
name: name,
groupcode: "blub".to_string(),
groupcode: group_code,
tag: tag,
admin: session.id,
members: Vec::new()
......
......@@ -37,4 +37,4 @@ Die Zeit ist abgelaufen!
<p>
Der Wettbewerb kann nach dem starten nicht mehr pausiert werden.
{{/if}}
\ No newline at end of file
{{/if}}
......@@ -12,12 +12,6 @@ Marker: {{group.tag}}</p>
<th>Logincode</th>
<th>Jahrgangstufe</th>
</tr>
<tr>
<td><a href="/user/1">Robert Czechowski</a></td>
<td>ag83uten</td>
<td>3</td>
<td><a href="/user/1">bearbeiten …</a></td>
</tr>
{{#each member}}
<tr>
......@@ -27,6 +21,7 @@ Marker: {{group.tag}}</p>
<td><a href="/user/{{id}}">bearbeiten …</a></td>
</tr>
{{/each}}
</table>
......
<h1>Task: {{name}}</h1>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<style>
body{
margin: 0px;
font-family:sans-serif;
}
#bar, #bar>div {
display:inline-block;
padding: 8px;
margin:0px;
background: #84bd00;
color:white;
font-size:14pt;
height: 40px;
overflow-y:hidden;
}
#bar {
display:block;
padding:0px;
}
#bar>#nav {
float:right;
}
#bar>#time {
float:right;
padding:0px 8px;
text-align:right;
}
#timetext{
padding:0px;
margin:0px;
font-size:10pt;
}
#timetime{
padding:0px;
margin:0px;
margin-top:-2px;
font-size:18pt;
}
#ttsec {
font-size:10pt;
}
#bar>#hamburger, #bar>#menu, #bar>#time {
background: #608a00;
font-weight:bold;
}
#bar>div.highlight {
background: #f4f9e8;
color:black;
}
iframe {
width: 100vw;border: 0px;height: calc(100vh - 45px);
}
</style>
</head><body style="">
<div id="bar">
<div id="menu">
&nbsp; JwInf 2018
</div>
<div>
{{name}}
</div>
<div>
★★
</div>
<div class="highlight">
☆☆☆
</div>
<div>
☆☆☆☆
</div>
<div id="time">
<div id="timetext">
Verbleibende Zeit
</div>
<div id="timetime">
0:28<span id="ttsec">:14</span>
</div>
</div>
<div id="nav">
🡅 Übersicht
</div>
<div id="nav">
🡆
</div>
<div id="nav">
🡄
</div>
<script>
function enterFullscreen(element) {
if(element.requestFullscreen) {
element.requestFullscreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.msRequestFullscreen) {
element.msRequestFullscreen();
} else if(element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
}
}
function exitFullscreen() {
if(document.exitFullscreen) {
document.exitFullscreen();
} else if(document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
var fullscreen = false;
function toggleFullscreen(element) {
if (fullscreen) {
exitFullscreen();
fullscreen = false;
}
else {
enterFullscreen(element);
fullscreen = true;
}
}
</script>
<div id="nav" onclick="toggleFullscreen(document.documentElement);">
⇱ Vollbild
</div>
</div>
</div>
<iframe src="/tasks/{{taskpath}}#taskid={{taskid}}&csrftoken={{csrftoken}}" name="taskframe">Leider unterstützt ihr Browser keine Frames. Sie können die Aufgabe auch manuell aufrufen: <a href="/{{taskpath}}#taskid={{taskid}}&csrftoken={{csrftoken}}">Aufgabe manuell bearbeiten</a>.</iframe>
</body></html>
<iframe src="/{{taskpath}}#taskid={{taskid}}&csrftoken={{csrftoken}}" height="500" width="800" name="taskframe">Leider unterstützt ihr Browser keine Frames. Sie können die Aufgabe auch manuell aufrufen: <a href="/{{taskpath}}#taskid={{taskid}}&csrftoken={{csrftoken}}">Aufgabe manuell bearbeiten</a>.</iframe>
\ No newline at end of file
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