Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Added a Meeting Page #100

Merged
merged 3 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/attend/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
//! Attendance is stored in the `attendance` table where each
//! row is a time someone attended something.

use crate::models::Meeting;
use crate::models::User;
use crate::schema::*;

/// Models an attendance in the database
#[derive(Debug, PartialEq, Clone, Queryable, Identifiable, Associations, Serialize)]
#[belongs_to(Meeting)]
#[belongs_to(User)]
pub struct Attendance {
/// ID of the attendance
Expand Down
45 changes: 45 additions & 0 deletions src/groups/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rocket::response::Redirect;
use rocket_contrib::json::Json;

use crate::attend::code::attendance_code;
use crate::attend::models::*;
use crate::guards::*;
use crate::ObservDbConn;

Expand Down Expand Up @@ -126,6 +127,34 @@ pub fn meetings(gid: i32) -> Redirect {
Redirect::to(format!("/groups/{}", gid))
}

/// GET handler for `/groups/<gid>/meetings/<mid>`
#[get("/groups/<gid>/meetings/<mid>")]
pub fn individual_meetings(conn: ObservDbConn, l: MentorGuard, gid: i32, mid: i32) -> Option<MeetingTemplate> {
use crate::schema::groups::dsl::*;
let g: Group = groups
.find(gid)
.first(&*conn)
.expect("Failed to get groups from database");

use crate::schema::meetings::dsl::*;
let m: Meeting = meetings
.find(mid)
.first(&*conn)
.expect("Failed to get meetings from database");

if m.group_id != gid {
return None
}
else {
Some(MeetingTemplate {
logged_in: Some(l.0),
users: meeting_users(&*conn, &m),
group: g,
meeting: m,
})
}
}

/// GET handler for `/groups/<gid>/meetings.json`
#[get("/groups/<gid>/meetings.json")]
pub fn meetings_json(conn: ObservDbConn, _l: MentorGuard, gid: i32) -> Json<Vec<Meeting>> {
Expand Down Expand Up @@ -390,3 +419,19 @@ fn group_users(conn: &SqliteConnection, group: &Group) -> Vec<User> {
})
.collect()
}

/// Returns a list of users who attended a given meeting
fn meeting_users(conn: &SqliteConnection, meeting: &Meeting) -> Vec<User> {
Attendance::belonging_to(meeting)
.load::<Attendance>(conn)
.expect("Failed to get relations from database")
.iter()
.map(|r| {
use crate::schema::users::dsl::*;
users
.find(r.user_id)
.first(conn)
.expect("Failed to get user from database")
})
.collect()
}
1 change: 1 addition & 0 deletions src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//! - `/groups/<gid>/meetings
//! - `/groups/<gid>/meetings.json
//! - `/groups/<gid>/meetings/new
//! - '/groups/<gid>/meetings/<mid>

pub mod handlers;
pub mod models;
Expand Down
2 changes: 1 addition & 1 deletion src/groups/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Attendable for Meeting {
false
}
fn url(&self) -> String {
format!("/h/{}", self.group_id)
format!("/groups/{}/meetings/{}", self.group_id, self.id)
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/groups/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,21 @@ pub struct AddUserTemplate {
pub group: Group,
pub all_users: Vec<User>,
}

/// Add Meeting page template
///
/// HTML file: `group/meeting.html`
///
/// The page that shows the attedance code and attendees for a meeting
#[derive(Template)]
#[template(path = "group/meeting.html")]
pub struct MeetingTemplate {
/// Login information for the group
pub logged_in: OptUser,
/// Group that contains this meeting
pub group: Group,
/// Users this template is for
pub users: Vec<User>,
/// Meeting that uses this template
pub meeting: Meeting
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub fn rocket(test_config: Option<rocket::Config>) -> rocket::Rocket {
group_user_delete,
group_delete,
meetings,
individual_meetings,
meetings_json,
meeting_new_post,
group_edit,
Expand Down
2 changes: 1 addition & 1 deletion templates/grade-summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h3>Attendance {{ summary.attendances.len() }} / {{ summary.needed_attendances }
<summary>Show all Attendance</summary>
<ul>
{% for at in summary.attendances %}
<li><a href="{{ at.url() }}">{{ at.name() }} {{ at.time() }}</a></li>
<li><a href="{{ at.url() }}">{{ at.name() }} </a></li>
{% endfor %}
</ul>
</details>
4 changes: 2 additions & 2 deletions templates/group/group.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ <h2>Meetings</h2>
{% match logged_in %}
{% when Some with (u) %}
<li>
Meeting at {{ meeting.happened_at }}
<a href="/groups/{{ group.id }}/meetings/{{ meeting.id }}">Meeting</a> at {{ meeting.happened_at }}
{% if u.tier > 0 %}
code:
<code>{{ meeting.code }}</code>
<a href="/big?text={{ meeting.code }}">View</a>
<a href="/big?text={{ meeting.code }}">View Code</a>
{% endif %}
</li>
{% when None %}
Expand Down
29 changes: 29 additions & 0 deletions templates/group/meeting.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends "base.html" %}

{% block title %}{{ group.name }} Meeting on {{ meeting.happened_at }} {% endblock %}

{% block head %}
<style>
</style>
{% endblock %}

{% block content %}

{% match group.location %}
{% when Some with (val) %}
Room: {{ val }}
{% when None %}
{% endmatch %}
<br>
Code: <code> {{ meeting.code }} </code>

<h2>Attendees</h2>
<ul>
{% for user in users %}
<li>
<a href="/users/{{ user.id }}">{{ user.real_name }} ({{ user.handle }})</a>
</li>
{% endfor %}
</ul>

{% endblock %}