Skip to content

Commit

Permalink
improve event frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
flosse committed Mar 29, 2019
1 parent 5c1f204 commit e3d7c0c
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 104 deletions.
2 changes: 1 addition & 1 deletion dev-env.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let
moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
pkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
rustChannel = pkgs.rustChannelOf {
date = "2019-02-27";
date = "2019-03-28";
channel = "nightly";
};
in
Expand Down
61 changes: 61 additions & 0 deletions src/ports/web/frontend/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ fieldset {
color: #000;
}

.events {
max-width: 30em;
float: left;
min-width: 15em;
}

.events .no-results {
padding: 1em;
}

.events h3 {
text-align: center;
color: #fff;
Expand Down Expand Up @@ -144,8 +154,59 @@ fieldset {
margin-top: 0;
margin-bottom: 0;
}

.event-list li a h4 span.date {
float: right;
font-weight: normal;
}

.details {
float: left;
padding: 1.8em;
max-width: 20em;
}

.details, .events {
border-right: 1px solid #bbb;
}

.details a {
color: #111;
text-decoration: none;
}

.details h2, h3, h4 {
color: #444;
margin-top: 0.60em;
margin-bottom: 0.2em;
}
.details p {
margin-top: 0.3em;
margin-bottom: 0.3em;
}
.details .time {
margin-top: 0.1em;
}

.details .description {
color: #666;
margin-top: 0.8em;
margin-bottom: 0.8em;
}

.details.event .entity-type{
color: rgb(229, 98, 146);
}

.details ul.tags {
font-size: 0.8em;
margin: 0;
padding: 0;
list-style: none;
background: #ddd;
padding:0.2em;
padding-left:0.4em;
padding-right:0.4em;
border-radius: 0.4em;
color: #333;
}
12 changes: 6 additions & 6 deletions src/ports/web/frontend/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

ready(["OFDB_MAP_PINS", "OFDB_MAP_ZOOM", "OFDB_MAP_CENTER", "L"],
function(pins, zoom, center, L){
if (pins.length > 0){
var map = L.map('map').setView(center,zoom);
L.tileLayer(TILES, { attribution: 'slowtec GmbH', maxZoom: 18 }).addTo(map);
for(var i=0;i<pins.length;i++) {
var pin = pins[i];
L.marker([pin.lat,pin.lng]).addTo(map);
if (pins.length > 0){
for(var i=0;i<pins.length;i++) {
var pin = pins[i];
L.marker([pin.lat,pin.lng]).addTo(map);
}
}
}
});
});
})();
20 changes: 10 additions & 10 deletions src/ports/web/frontend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ pub fn get_main_css() -> Css<&'static str> {
Css(MAIN_CSS)
}

#[get("/events/<id>")]
pub fn get_event(db: sqlite::Connections, id: &RawStr) -> Result<Markup> {
let mut ev = usecases::get_event(&*db.shared()?, &id)?;
// TODO:Make sure within usecase that the creator email
// is not shown to unregistered users
ev.created_by = None;
Ok(view::event(None, ev))
}

#[get("/entries/<id>")]
pub fn get_entry_admin(pool: sqlite::Connections, id: &RawStr, admin: Admin) -> Result<Markup> {
//TODO: dry out
Expand Down Expand Up @@ -94,6 +85,15 @@ pub fn get_entry(pool: sqlite::Connections, id: &RawStr) -> Result<Markup> {
Ok(view::entry(None, (e, ratings).into()))
}

#[get("/events/<id>")]
pub fn get_event(db: sqlite::Connections, id: &RawStr) -> Result<Markup> {
let mut ev = usecases::get_event(&*db.shared()?, &id)?;
// TODO:Make sure within usecase that the creator email
// is not shown to unregistered users
ev.created_by = None;
Ok(view::event(None, ev))
}

#[get("/events?<query..>")]
pub fn get_events(db: sqlite::Connections, query: EventQuery) -> Result<Markup> {
if query.created_by.is_some() {
Expand Down Expand Up @@ -407,7 +407,7 @@ mod tests {
assert_eq!(res.status(), Status::Ok);
let body_str = res.body().and_then(|b| b.into_string()).unwrap();
assert!(body_str.contains("<h2>A great event</h2>"));
assert!(body_str.contains("<p>Foo bar baz</p>"));
assert!(body_str.contains("Foo bar baz</p>"));
}

}
Expand Down
195 changes: 108 additions & 87 deletions src/ports/web/frontend/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,84 +133,85 @@ pub fn event(email: Option<&str>, ev: Event) -> Markup {
crossorigin="anonymous";
}),
html! {
h2{ (ev.title) }
h4 { "Zeit" }
p{
(ev.start.to_string())
@if let Some(end) = ev.end{
" bis "
(end.to_string())
}
}
h4 { "Beschreibung" }
p{ (ev.description.unwrap_or_default()) }
div class="details event" {
div class="entity-type" { "Event" }
h2{ (ev.title) }
p class="time" {
(ev.start.format("%d.%m.%Y %H:%M"))
@if let Some(end) = ev.end{
" - "
(end.format("%d.%m.%Y %H:%M"))
}
}
p class="description" { (ev.description.unwrap_or_default()) }

@if let Some(ref location) = ev.location{
h4{ "Ort" }
@if let Some(ref addr) = location.address {
@if !addr.is_empty(){
@if let Some(ref s) = addr.street {
(s) br;
}
@if let Some(ref z) = addr.zip {
(z) " "
}
@if let Some(ref c) = addr.city {
(c) br;
}
@if let Some(ref c) = addr.country {
(c)
@if let Some(ref location) = ev.location{
h4{ "Ort" }
@if let Some(ref addr) = location.address {
@if !addr.is_empty(){
@if let Some(ref s) = addr.street {
(s) br;
}
@if let Some(ref z) = addr.zip {
(z) " "
}
@if let Some(ref c) = addr.city {
(c) br;
}
@if let Some(ref c) = addr.country {
(c)
}
}
}
}
h4 {"Koordinaten"}
p{
(format!("{:.2} / {:.2}",location.pos.lat().to_deg(), location.pos.lng().to_deg()))
}
}
@if let Some(org) = ev.organizer {
h4{"Veranstalter"}
p{(org)}
}
@if let Some(contact) = ev.contact{
@if !contact.is_empty(){
h4{ "Kontakt" }
@if let Some(email) = contact.email{
(email)
br;
}
@if let Some(phone) = contact.telephone{
(phone)
}
h4 { "Koordinaten" }
p{
(format!("{:.2} / {:.2}",location.pos.lat().to_deg(), location.pos.lng().to_deg()))
}
}
}
@if let Some(url) = ev.homepage{
h4{ "Webseite" }
p{
a href=(url) { (url) }
@if let Some(org) = ev.organizer {
h4{"Veranstalter"}
p{(org)}
}
@if let Some(contact) = ev.contact{
@if !contact.is_empty(){
h4{ "Kontakt" }
@if let Some(email) = contact.email{
(email)
br;
}
@if let Some(phone) = contact.telephone{
(phone)
}
}
}
@if let Some(reg) = ev.registration{
h4{ "Anmeldung"}
p {
@match reg{
RegistrationType::Email => "eMail" ,
RegistrationType::Phone => "Telefon",
}
@if let Some(url) = ev.homepage{
h4{ "Webseite" }
p{
a href=(url) { (url) }
}
}
@if let Some(reg) = ev.registration{
h4{ "Anmeldung" }
p {
@match reg{
RegistrationType::Email => "eMail" ,
RegistrationType::Phone => "Telefon",
RegistrationType::Homepage => "Webseite",
}
}
}
}
p {
h4{"Tags"}
ul{
@for t in ev.tags{
li {(t)}
p {
h4{ "Tags" }
ul class="tags" {
@for t in ev.tags{
li {(format!("#{}",t))}
}
}
}
}

}
@if let Some(l) = ev.location {
div id="map" style="height:300px;" { }
div id="map" style="height:100vh;" { }
(map_scripts(&[l.into()]))
}
},
Expand Down Expand Up @@ -288,37 +289,55 @@ fn map_scripts(pins: &[MapPin]) -> Markup {
}

pub fn events(events: &[Event]) -> Markup {
let locations: Vec<_> = events
.iter()
.filter_map(|e| e.location.as_ref())
.map(|l| l.into())
.collect();

page(
"List of Events",
None,
None,
None,
Some(html! {
link
rel="stylesheet"
href=(LEAFLET_CSS_URL)
integrity=(LEAFLET_CSS_SHA512)
crossorigin="anonymous";
}),
html! {
div class="events" {
h3 { "Events" }
ul class="event-list" {
@for e in events {
li {
a href=(format!("/events/{}", e.id)) {
div {
h4 {
span class="title" { (e.title) }
" "
span class="date" {
(e.start.format("%d.%m.%y"))
@if events.is_empty() {
p class="no-results" {
"Es konnten keine Events gefunden werden."
}
} @else {
ul class="event-list" {
@for e in events {
li {
a href=(format!("/events/{}", e.id)) {
div {
h4 {
span class="title" { (e.title) }
" "
span class="date" {
(e.start.format("%d.%m.%y"))
}
}
}
p {
@if let Some(ref l) = e.location {
@if let Some(ref a) = l.address {
@if let Some(ref city) = a.city {
span class="city" { (city) }
br;
p {
@if let Some(ref l) = e.location {
@if let Some(ref a) = l.address {
@if let Some(ref city) = a.city {
span class="city" { (city) }
br;
}
}
}
}
@if let Some(ref o) = e.organizer {
span class="organizer" { (o) }
@if let Some(ref o) = e.organizer {
span class="organizer" { (o) }
}
}
}
}
Expand All @@ -327,6 +346,8 @@ pub fn events(events: &[Event]) -> Markup {
}
}
}
div id="map" style="height:100vh;" { }
(map_scripts(&locations))
},
)
}
Expand Down

0 comments on commit e3d7c0c

Please sign in to comment.