Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
medal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
40
Issues
40
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bwinf
medal
Compare Revisions
9225e5150e495123abb1c0e7de17e7252c8add62...1c780ac3fe6aef08862ba3079e72b493455990b3
Source
1c780ac3fe6aef08862ba3079e72b493455990b3
Select Git revision
...
Target
9225e5150e495123abb1c0e7de17e7252c8add62
Select Git revision
Compare
Commits (2)
Template jwinf: Make contest.hbs a rebased template
· 9996a14e
Robert Czechowski
authored
Jul 14, 2020
9996a14e
Cleanup old routes no longer needed in webfw_iron
· 1c780ac3
Robert Czechowski
authored
Jul 14, 2020
1c780ac3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
199 additions
and
347 deletions
+199
-347
src/core.rs
src/core.rs
+33
-51
src/webfw_iron.rs
src/webfw_iron.rs
+9
-66
templates/jwinf/contest.hbs
templates/jwinf/contest.hbs
+157
-230
No files found.
src/core.rs
View file @
1c780ac3
...
...
@@ -74,6 +74,22 @@ fn fill_user_data(session: &SessionUser, data: &mut json_val::Map<String, serde_
data
.insert
(
"parent"
.to_string
(),
to_json
(
&
"base"
));
}
fn
fill_oauth_data
((
self_url
,
oauth_providers
):
(
Option
<
String
>
,
Option
<
Vec
<
OauthProvider
>>
),
data
:
&
mut
json_val
::
Map
<
String
,
serde_json
::
Value
>
)
{
let
mut
oauth_links
:
Vec
<
(
String
,
String
,
String
)
>
=
Vec
::
new
();
if
let
Some
(
oauth_providers
)
=
oauth_providers
{
for
oauth_provider
in
oauth_providers
{
oauth_links
.push
((
oauth_provider
.provider_id
.to_owned
(),
oauth_provider
.login_link_text
.to_owned
(),
oauth_provider
.url
.to_owned
()));
}
}
data
.insert
(
"self_url"
.to_string
(),
to_json
(
&
self_url
));
data
.insert
(
"oauth_links"
.to_string
(),
to_json
(
&
oauth_links
));
}
fn
grade_to_string
(
grade
:
i32
)
->
String
{
match
grade
{
0
=>
"Noch kein Schüler"
.to_string
(),
...
...
@@ -90,7 +106,7 @@ fn grade_to_string(grade: i32) -> String {
}
pub
fn
index
<
T
:
MedalConnection
>
(
conn
:
&
T
,
session_token
:
Option
<
String
>
,
(
self_url
,
oauth_providers
)
:
(
Option
<
String
>
,
Option
<
Vec
<
OauthProvider
>>
))
oauth_infos
:
(
Option
<
String
>
,
Option
<
Vec
<
OauthProvider
>>
))
->
(
String
,
json_val
::
Map
<
String
,
json_val
::
Value
>
)
{
let
mut
data
=
json_val
::
Map
::
new
();
...
...
@@ -103,23 +119,13 @@ pub fn index<T: MedalConnection>(conn: &T, session_token: Option<String>,
}
}
let
mut
oauth_links
:
Vec
<
(
String
,
String
,
String
)
>
=
Vec
::
new
();
if
let
Some
(
oauth_providers
)
=
oauth_providers
{
for
oauth_provider
in
oauth_providers
{
oauth_links
.push
((
oauth_provider
.provider_id
.to_owned
(),
oauth_provider
.login_link_text
.to_owned
(),
oauth_provider
.url
.to_owned
()));
}
}
data
.insert
(
"self_url"
.to_string
(),
to_json
(
&
self_url
));
data
.insert
(
"oauth_links"
.to_string
(),
to_json
(
&
oauth_links
));
fill_oauth_data
(
oauth_infos
,
&
mut
data
);
data
.insert
(
"parent"
.to_string
(),
to_json
(
&
"base"
));
(
"index"
.to_owned
(),
data
)
}
pub
fn
status
<
T
:
MedalConnection
>
(
conn
:
&
T
)
->
String
{
conn
.get_debug_information
()
}
pub
fn
status
<
T
:
MedalConnection
>
(
conn
:
&
T
,
_
:
()
)
->
String
{
conn
.get_debug_information
()
}
pub
fn
debug
<
T
:
MedalConnection
>
(
conn
:
&
T
,
session_token
:
Option
<
String
>
)
->
(
String
,
json_val
::
Map
<
String
,
json_val
::
Value
>
)
{
...
...
@@ -172,7 +178,7 @@ pub enum ContestVisibility {
}
pub
fn
show_contests
<
T
:
MedalConnection
>
(
conn
:
&
T
,
session_token
:
&
str
,
(
self_url
,
oauth_providers
)
:
(
Option
<
String
>
,
Option
<
Vec
<
OauthProvider
>>
),
oauth_infos
:
(
Option
<
String
>
,
Option
<
Vec
<
OauthProvider
>>
),
visibility
:
ContestVisibility
)
->
MedalValue
{
...
...
@@ -185,17 +191,7 @@ pub fn show_contests<T: MedalConnection>(conn: &T, session_token: &str,
data
.insert
(
"can_start"
.to_string
(),
to_json
(
&
true
));
}
let
mut
oauth_links
:
Vec
<
(
String
,
String
,
String
)
>
=
Vec
::
new
();
if
let
Some
(
oauth_providers
)
=
oauth_providers
{
for
oauth_provider
in
oauth_providers
{
oauth_links
.push
((
oauth_provider
.provider_id
.to_owned
(),
oauth_provider
.login_link_text
.to_owned
(),
oauth_provider
.url
.to_owned
()));
}
}
data
.insert
(
"self_url"
.to_string
(),
to_json
(
&
self_url
));
data
.insert
(
"oauth_links"
.to_string
(),
to_json
(
&
oauth_links
));
fill_oauth_data
(
oauth_infos
,
&
mut
data
);
let
now
=
time
::
get_time
();
let
v
:
Vec
<
ContestInfo
>
=
...
...
@@ -280,8 +276,11 @@ fn check_contest_constraints(session: &SessionUser, contest: &Contest) -> Contes
grade_matching
}
}
pub
fn
show_contest
<
T
:
MedalConnection
>
(
conn
:
&
T
,
contest_id
:
i32
,
session_token
:
&
str
,
query_string
:
Option
<
String
>
)
->
MedalValueResult
{
pub
fn
show_contest
<
T
:
MedalConnection
>
(
conn
:
&
T
,
contest_id
:
i32
,
session_token
:
&
str
,
query_string
:
Option
<
String
>
,
oauth_infos
:
(
Option
<
String
>
,
Option
<
Vec
<
OauthProvider
>>
))
->
MedalValueResult
{
let
session
=
conn
.get_session_or_new
(
&
session_token
);
let
contest
=
conn
.get_contest_by_id_complete
(
contest_id
);
...
...
@@ -295,7 +294,10 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token
public
:
contest
.public
};
let
mut
data
=
json_val
::
Map
::
new
();
data
.insert
(
"parent"
.to_string
(),
to_json
(
&
"base"
));
data
.insert
(
"empty"
.to_string
(),
to_json
(
&
"empty"
));
data
.insert
(
"contest"
.to_string
(),
to_json
(
&
ci
));
fill_oauth_data
(
oauth_infos
,
&
mut
data
);
let
constraints
=
check_contest_constraints
(
&
session
,
&
contest
);
...
...
@@ -484,7 +486,7 @@ pub fn start_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_toke
}
pub
fn
login
<
T
:
MedalConnection
>
(
conn
:
&
T
,
login_data
:
(
String
,
String
),
(
self_url
,
oauth_providers
)
:
(
Option
<
String
>
,
Option
<
Vec
<
OauthProvider
>>
))
oauth_infos
:
(
Option
<
String
>
,
Option
<
Vec
<
OauthProvider
>>
))
->
Result
<
String
,
MedalValue
>
{
let
(
username
,
password
)
=
login_data
;
...
...
@@ -497,17 +499,7 @@ pub fn login<T: MedalConnection>(conn: &T, login_data: (String, String),
data
.insert
(
"username"
.to_string
(),
to_json
(
&
username
));
data
.insert
(
"parent"
.to_string
(),
to_json
(
&
"base"
));
let
mut
oauth_links
:
Vec
<
(
String
,
String
,
String
)
>
=
Vec
::
new
();
if
let
Some
(
oauth_providers
)
=
oauth_providers
{
for
oauth_provider
in
oauth_providers
{
oauth_links
.push
((
oauth_provider
.provider_id
.to_owned
(),
oauth_provider
.login_link_text
.to_owned
(),
oauth_provider
.url
.to_owned
()));
}
}
data
.insert
(
"self_url"
.to_string
(),
to_json
(
&
self_url
));
data
.insert
(
"oauth_links"
.to_string
(),
to_json
(
&
oauth_links
));
fill_oauth_data
(
oauth_infos
,
&
mut
data
);
Err
((
"login"
.to_owned
(),
data
))
}
...
...
@@ -515,7 +507,7 @@ pub fn login<T: MedalConnection>(conn: &T, login_data: (String, String),
}
pub
fn
login_with_code
<
T
:
MedalConnection
>
(
conn
:
&
T
,
code
:
&
str
,
(
self_url
,
oauth_providers
)
:
(
Option
<
String
>
,
Option
<
Vec
<
OauthProvider
>>
))
conn
:
&
T
,
code
:
&
str
,
oauth_infos
:
(
Option
<
String
>
,
Option
<
Vec
<
OauthProvider
>>
))
->
Result
<
Result
<
String
,
String
>
,
(
String
,
json_val
::
Map
<
String
,
json_val
::
Value
>
)
>
{
match
conn
.login_with_code
(
None
,
&
code
)
{
Ok
(
session_token
)
=>
Ok
(
Ok
(
session_token
)),
...
...
@@ -527,17 +519,7 @@ pub fn login_with_code<T: MedalConnection>(
data
.insert
(
"code"
.to_string
(),
to_json
(
&
code
));
data
.insert
(
"parent"
.to_string
(),
to_json
(
&
"base"
));
let
mut
oauth_links
:
Vec
<
(
String
,
String
,
String
)
>
=
Vec
::
new
();
if
let
Some
(
oauth_providers
)
=
oauth_providers
{
for
oauth_provider
in
oauth_providers
{
oauth_links
.push
((
oauth_provider
.provider_id
.to_owned
(),
oauth_provider
.login_link_text
.to_owned
(),
oauth_provider
.url
.to_owned
()));
}
}
data
.insert
(
"self_url"
.to_string
(),
to_json
(
&
self_url
));
data
.insert
(
"oauth_links"
.to_string
(),
to_json
(
&
oauth_links
));
fill_oauth_data
(
oauth_infos
,
&
mut
data
);
Err
((
"login"
.to_owned
(),
data
))
}
...
...
src/webfw_iron.rs
View file @
1c780ac3
...
...
@@ -297,16 +297,9 @@ fn greet_personal<C>(req: &mut Request) -> IronResult<Response>
// hier ggf. Daten aus dem Request holen
let
config
=
req
.get
::
<
Read
<
SharedConfiguration
>>
()
.unwrap
();
let
(
self_url
,
oauth_providers
)
=
(
config
.self_url
.clone
(),
config
.oauth_providers
.clone
());
let
oauth_infos
=
(
config
.self_url
.clone
(),
config
.oauth_providers
.clone
());
let
(
template
,
mut
data
)
=
{
// hier ggf. Daten aus dem Request holen
let
mutex
=
req
.get
::
<
Write
<
SharedDatabaseConnection
<
C
>>>
()
.unwrap
();
let
conn
=
mutex
.lock
()
.unwrap_or_else
(|
e
|
e
.into_inner
());
// Antwort erstellen und zurücksenden
core
::
index
(
&*
conn
,
session_token
,
(
self_url
,
oauth_providers
))
};
let
(
template
,
mut
data
)
=
with_conn!
[
core
::
index
,
C
,
req
,
session_token
,
oauth_infos
];
/*if let Some(server_message) = &config.server_message {
data.insert("server_message".to_string(), to_json(&server_message));
...
...
@@ -321,12 +314,7 @@ fn greet_personal<C>(req: &mut Request) -> IronResult<Response>
fn
dbstatus
<
C
>
(
req
:
&
mut
Request
)
->
IronResult
<
Response
>
where
C
:
MedalConnection
+
std
::
marker
::
Send
+
'static
{
let
status
=
{
let
mutex
=
req
.get
::
<
Write
<
SharedDatabaseConnection
<
C
>>>
()
.unwrap
();
let
conn
=
mutex
.lock
()
.unwrap_or_else
(|
e
|
e
.into_inner
());
core
::
status
(
&*
conn
)
};
let
status
=
with_conn!
[
core
::
status
,
C
,
req
,
()];
let
mut
resp
=
Response
::
new
();
resp
.set_mut
(
status
)
.set_mut
(
status
::
Ok
);
...
...
@@ -337,12 +325,7 @@ fn debug<C>(req: &mut Request) -> IronResult<Response>
where
C
:
MedalConnection
+
std
::
marker
::
Send
+
'static
{
let
session_token
=
req
.get_session_token
();
let
(
template
,
data
)
=
{
let
mutex
=
req
.get
::
<
Write
<
SharedDatabaseConnection
<
C
>>>
()
.unwrap
();
let
conn
=
mutex
.lock
()
.unwrap_or_else
(|
e
|
e
.into_inner
());
core
::
debug
(
&*
conn
,
session_token
)
};
let
(
template
,
data
)
=
with_conn!
[
core
::
debug
,
C
,
req
,
session_token
];
let
mut
resp
=
Response
::
new
();
resp
.set_mut
(
Template
::
new
(
&
template
,
data
))
.set_mut
(
status
::
Ok
);
...
...
@@ -415,55 +398,17 @@ fn contests<C>(req: &mut Request) -> IronResult<Response>
Ok
(
resp
)
}
fn
opencontests
<
C
>
(
req
:
&
mut
Request
)
->
IronResult
<
Response
>
where
C
:
MedalConnection
+
std
::
marker
::
Send
+
'static
{
let
session_token
=
req
.require_session_token
()
?
;
let
config
=
req
.get
::
<
Read
<
SharedConfiguration
>>
()
.unwrap
();
let
(
self_url
,
oauth_providers
)
=
(
config
.self_url
.clone
(),
config
.oauth_providers
.clone
());
let
(
template
,
mut
data
)
=
with_conn!
[
core
::
show_contests
,
C
,
req
,
&
session_token
,
(
self_url
,
oauth_providers
),
core
::
ContestVisibility
::
Open
];
config
.server_message
.as_ref
()
.map
(|
sm
|
data
.insert
(
"server_message"
.to_string
(),
to_json
(
&
sm
)));
let
mut
resp
=
Response
::
new
();
resp
.set_mut
(
Template
::
new
(
&
template
,
data
))
.set_mut
(
status
::
Ok
);
Ok
(
resp
)
}
fn
currentcontests
<
C
>
(
req
:
&
mut
Request
)
->
IronResult
<
Response
>
where
C
:
MedalConnection
+
std
::
marker
::
Send
+
'static
{
let
session_token
=
req
.require_session_token
()
?
;
let
config
=
req
.get
::
<
Read
<
SharedConfiguration
>>
()
.unwrap
();
let
(
self_url
,
oauth_providers
)
=
(
config
.self_url
.clone
(),
config
.oauth_providers
.clone
());
let
(
template
,
mut
data
)
=
with_conn!
[
core
::
show_contests
,
C
,
req
,
&
session_token
,
(
self_url
,
oauth_providers
),
core
::
ContestVisibility
::
Current
];
config
.server_message
.as_ref
()
.map
(|
sm
|
data
.insert
(
"server_message"
.to_string
(),
to_json
(
&
sm
)));
let
mut
resp
=
Response
::
new
();
resp
.set_mut
(
Template
::
new
(
&
template
,
data
))
.set_mut
(
status
::
Ok
);
Ok
(
resp
)
}
fn
contest
<
C
>
(
req
:
&
mut
Request
)
->
IronResult
<
Response
>
where
C
:
MedalConnection
+
std
::
marker
::
Send
+
'static
{
let
contest_id
=
req
.expect_int
::
<
i32
>
(
"contestid"
)
?
;
let
session_token
=
req
.require_session_token
()
?
;
let
query_string
=
req
.url
.query
()
.map
(|
s
|
s
.to_string
());
let
(
template
,
data
)
=
with_conn!
[
core
::
show_contest
,
C
,
req
,
contest_id
,
&
session_token
,
query_string
]
.aug
(
req
)
?
;
let
config
=
req
.get
::
<
Read
<
SharedConfiguration
>>
()
.unwrap
();
let
oauth_infos
=
(
config
.self_url
.clone
(),
config
.oauth_providers
.clone
());
let
(
template
,
data
)
=
with_conn!
[
core
::
show_contest
,
C
,
req
,
contest_id
,
&
session_token
,
query_string
,
oauth_infos
]
.aug
(
req
)
?
;
let
mut
resp
=
Response
::
new
();
resp
.set_mut
(
Template
::
new
(
&
template
,
data
))
.set_mut
(
status
::
Ok
);
...
...
@@ -1236,8 +1181,6 @@ pub fn start_server<C>(conn: C, config: Config) -> iron::error::HttpResult<iron:
let
router
=
router!
(
greet
:
get
"/"
=>
greet_personal
::
<
C
>
,
contests
:
get
"/contest/"
=>
contests
::
<
C
>
,
contestsopen
:
get
"/contest/open/"
=>
opencontests
::
<
C
>
,
contestscurrent
:
get
"/contest/current/"
=>
currentcontests
::
<
C
>
,
contest
:
get
"/contest/:contestid"
=>
contest
::
<
C
>
,
contestresults
:
get
"/contest/:contestid/result/"
=>
contestresults
::
<
C
>
,
contestresults_download
:
get
"/contest/:contestid/result/download"
=>
contestresults_download
::
<
C
>
,
...
...
templates/jwinf/contest.hbs
View file @
1c780ac3
{{#
*
inline
"page"
}}
{{#if
not_bare
}}
<!DOCTYPE html>
<html
lang=
"en"
style=
"background-color: #fafafa;"
>
<head>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=450"
>
<title>
Jugendwettbewerb Informatik: Programmieren – leichter, als du denkst!
</title>
<link
rel=
"stylesheet"
href=
"/static/lib/bulma/medal-bulma-0.7.5.css"
>
<link
rel=
"icon"
href=
"/static/images/favicon.png"
type=
"image/png"
>
<style>
ul
{
list-style-type
:
none
;
font-size
:
x-large
;
margin-left
:
20px
;
}
</style>
</head>
<body
style=
"background-color: white;"
>
<div
class=
"container"
style=
"padding: 1.5rem;"
>
<div
class=
"columns"
>
<div
class=
"column is-7"
>
<a
href=
"/"
>
<img
style=
"float:left; margin-right: 10px;"
src=
"/static/images/klein.png"
>
</a>
<h1
class=
"title"
>
Jugendwettbewerb Informatik
</h1>
<h2
class=
"subtitle"
>
Programmieren – leichter, als du denkst!
</h2>
</div>
<div
class=
"column is-one-third"
>
{{#if
logged_in
}}
<div
class=
"columns"
>
<div
class=
"column is-8"
>
Eingeloggt als
<em>
{{
username
}}
</em>
{{#if
firstname
}}{{#if
lastname
}}
(
{{
firstname
}}
{{
lastname
}}
)
{{/if}}{{/if}}
{{#if
teacher
}}
[Lehrer]
{{/if}}
<br>
<a
href=
"/profile"
class=
"button is-info is-small"
>
👤
Profil
</a>
{{#if
teacher
}}
<a
href=
"/group/"
class=
"button is-warning is-small"
>
⚙
Gruppenverwaltung
</a>
{{/if}}
</div>
<div
class=
"column"
><a
href=
"/logout"
class=
"button is-small is-danger"
type=
"submit"
>
⨯
Logout
</a></div>
</div>
<div
class=
"columns"
>
<div
class=
"column"
></div>
</div>
{{/if}}
</div>
</div>
{{#if
teacher
}}
<!-- <div class="columns alogin">
<div
class=
"column is-8 is-offset-2"
>
<a href="/group/">
<div class="notification is-warning">
<h3 class="title is-5">Gruppenverwaltung</h3>
<p>Gruppen für die Wettbewerbsteilnahme anlegen und verwalten</p>
<h3
class=
"title is-4"
>
{{#if
has_duration
}}
Wettbewerb:
{{else}}
Trainingsaufgaben:
{{/if}}
{{
contest
.
name
}}
</h3>
{{#if
contest
.
duration
}}
<h4
class=
"subtitle is-5"
>
Dauer:
{{
contest
.
duration
}}
Minuten
</h4>
{{/if}}
</div>
</a>
</div>
</div> -->
<!-- <div class="columns alogin">
<div class="column is-8 is-offset-2">
{{#if
teacher
}}
<div
class=
"columns"
>
<div
class=
"column is-6 is-offset-3"
>
<a
href=
"/contest/
{{
contest
.
id
}}
/result/"
>
<div
class=
"notification is-info"
>
<h3
class=
"title is-5"
>
Gruppenergebnisse
</h3>
...
...
@@ -73,40 +18,18 @@
</div>
</a>
</div>
</div> --
>
</div
>
{{/if}}
<div
class=
"columns"
id=
"bare_content"
>
{{/if}}
<div
class=
"columns"
>
<div
class=
"column is-8 is-offset-2"
>
<h3
class=
"title is-4"
>
{{#if
has_duration
}}
Wettbewerb:
{{else}}
Trainingsaufgaben:
{{/if}}
{{
contest
.
name
}}
</h3>
{{#if
contest
.
duration
}}
<h4
class=
"subtitle is-5"
>
Dauer:
{{
contest
.
duration
}}
Minuten
</h4>
{{/if}}
</div>
</div>
{{#if
teacher
}}
<div
class=
"columns"
>
<div
class=
"column is-6 is-offset-3"
>
<a
href=
"/contest/
{{
contest
.
id
}}
/result/"
>
<div
class=
"notification is-info"
>
<h3
class=
"title is-5"
>
Gruppenergebnisse
</h3>
<p>
Ergebnisse meiner Gruppen für diesen Wettbewerb einsehen
</p>
</div>
</a>
</div>
</div>
{{/if}}
<div
class=
"columns"
id=
"bare_content"
>
{{/if}}
<div
class=
"column is-6 is-offset-3"
>
<div
style=
"min-height: 400px; margin-bottom:100px;"
class=
"content"
>
<!-- <h3 class="title is-4">
{{#if
has_duration
}}
Wettbewerb:
{{else}}
Trainingsaufgaben:
{{/if}}
{{
contest
.
name
}}
</h3>
{{#if
contest
.
duration
}}
<h4 class="subtitle is-5">Dauer:
{{
contest
.
duration
}}
Minuten</h4>
{{/if}}
-->
{{#if
is_started
}}
<p>
{{#if
has_duration
}}
...
...
@@ -216,15 +139,11 @@
</div>
</div>
{{#if
not_bare
}}
</div>
</div>
<footer
class=
"footer"
>
<div
class=
"content has-text-centered"
>
<p>
</p>
</div>
</footer>
<script>
// Reload page content as soon as you come back from another task via the back button in order to show the newly achieved stars
...
...
@@ -244,6 +163,14 @@
window
.
onpageshow
=
reload_content
;
</script>
</body>
</html>
{{/if}}
{{/
inline
}}
{{#if
not_bare
}}
{{~>
(
parent
)
~}}
{{else}}
{{~>
(
empty
)
~}}
{{/if}}