Feature: Show licenses in profile

This commit is contained in:
Keanu D?lle 2020-09-07 22:38:18 +02:00
parent e7873d1688
commit b9fe8194b7
13 changed files with 102 additions and 2 deletions

View File

@ -9,6 +9,7 @@ create table licenses_members
constraint members_licenses_license_categories_name_fk
references license_categories
on update cascade on delete cascade,
drive_permission boolean default false not null,
constraint members_licenses_pk
primary key (member_id, license_name)
);

View File

@ -142,8 +142,13 @@
<div class="card bg-light mb-3">
<div class="card-header">Fahrberechtigungen & Führerscheine</div>
<div class="card-body">
<h5 class="card-title">Light card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
{{#each licenses}}
<button type="button" class="btn {{#if drive_permission}}btn-success{{else}}{{#if license}}btn-warning{{/if}}{{/if}}" data-toggle="tooltip" data-placement="bottom" title="{{category_description}}">{{category_name}}</button>
{{/each}}
<hr>
<button type="button" class="btn btn-success">Führerschein + Fahrerlaubnis vorhanden</button>
<button type="button" class="btn btn-warning">Führerschein vorhanden, keine Fahrerlaubnis</button>
</div>
</div>
</div>

View File

@ -0,0 +1,42 @@
use crate::database::controller::connector::establish_connection;
use crate::database::model::member_licenses::RawMemberLicense;
use crate::helper::settings::Settings;
use crate::modules::member_management::model::licenses::MemberLicense;
use diesel::pg::types::sql_types::Uuid;
use diesel::serialize::IsNull;
use diesel::{sql_query, ExpressionMethods, JoinOnDsl, RunQueryDsl};
use rocket::State;
pub fn get_member_licenses(
settings: &State<Settings>,
entity_id: uuid::Uuid,
) -> Vec<MemberLicense> {
use crate::schema::license_categories::dsl::*;
use crate::schema::licenses_members::dsl::*;
let connection = establish_connection(settings);
let data: Result<Vec<RawMemberLicense>, diesel::result::Error> = sql_query(
"SELECT * FROM licenses_members
RIGHT JOIN license_categories lc on licenses_members.license_name = lc.name
WHERE member_id = $1 OR member_id IS NULL ORDER BY lc.name ASC;",
)
.bind::<Uuid, _>(entity_id)
.load(&connection);
match data {
Ok(data) => {
let mut output: Vec<MemberLicense> = Vec::new();
for license in data {
output.push(MemberLicense::from(license));
}
output
}
Err(e) => {
error!("Couldn't get licenses for member {} : {}", entity_id, e);
vec![]
}
}
}

View File

@ -1,5 +1,6 @@
pub mod addresses;
pub mod connector;
pub mod groups;
pub mod member_licenses;
pub mod members;
pub mod users;

View File

@ -0,0 +1,11 @@
use diesel::sql_types::*;
#[derive(Queryable, QueryableByName, Clone, Deserialize, Serialize)]
pub struct RawMemberLicense {
#[sql_type = "Text"]
pub(crate) name: String,
#[sql_type = "Nullable<Bool>"]
pub(crate) drive_permission: Option<bool>,
#[sql_type = "Nullable<Text>"]
pub(crate) description: Option<String>,
}

View File

@ -1,5 +1,6 @@
pub mod addresses;
pub mod entities;
pub mod groups;
pub mod member_licenses;
pub mod members;
pub mod users;

View File

@ -0,0 +1,24 @@
use crate::database::model::member_licenses::RawMemberLicense;
use crate::modules::member_management::model::licenses::MemberLicense;
impl From<(RawMemberLicense)> for MemberLicense {
fn from(raw: (RawMemberLicense)) -> Self {
let mut license: bool = true;
let drive_permission = match raw.drive_permission {
Some(drive_permission) => drive_permission,
None => {
license = false;
false
}
};
let member_license = MemberLicense {
category_name: raw.name,
category_description: raw.description,
drive_permission,
license,
};
member_license
}
}

View File

@ -1,4 +1,5 @@
pub mod filter_form_from_form_trait;
pub mod licenses_trait;
pub mod member_check_permission;
pub mod member_trait;
pub mod render;

View File

@ -0,0 +1,7 @@
#[derive(Queryable, Clone, Deserialize, Serialize)]
pub struct MemberLicense {
pub(crate) category_name: String,
pub(crate) category_description: Option<String>,
pub(crate) drive_permission: bool,
pub(crate) license: bool,
}

View File

@ -3,6 +3,7 @@ use crate::database::model::members::RawMember;
use crate::helper::sitebuilder::model::general::{Footer, Header};
use crate::helper::sitebuilder::model::sidebar::Sidebar;
use crate::modules::member_management::model::group::Group;
use crate::modules::member_management::model::licenses::MemberLicense;
use crate::modules::member_management::model::member::MemberWithAccess;
use std::collections::HashMap;
@ -22,6 +23,7 @@ pub struct MemberModuleProfile {
pub member: RawMember,
pub member_age: Option<i32>,
pub address: Option<Address>,
pub licenses: Vec<MemberLicense>,
pub readonly: bool,
pub sidebar: Sidebar,
}

View File

@ -1,4 +1,5 @@
pub mod filter_form;
pub mod group;
pub mod licenses;
pub mod member;
pub mod member_module;

View File

@ -1,4 +1,5 @@
use crate::database::controller::addresses::get_addresses_for_entity_only_one_allowed;
use crate::database::controller::member_licenses::get_member_licenses;
use crate::database::controller::members::{get_member_by_user_uuid, get_raw_member_by_uuid};
use crate::helper::age_calculator::calculate_age;
use crate::helper::session_cookies::model::SessionCookie;
@ -69,6 +70,7 @@ pub fn handle_view(
};
let address = get_addresses_for_entity_only_one_allowed(settings, raw_member.entity_id);
let licenses = get_member_licenses(settings, raw_member.entity_id);
return Ok(Template::render(
"module_member_management_profile",
@ -78,6 +80,7 @@ pub fn handle_view(
member: raw_member,
member_age: age,
address,
licenses,
readonly: true,
sidebar,
},

View File

@ -107,6 +107,7 @@ table! {
licenses_members (member_id, license_name) {
member_id -> Uuid,
license_name -> Text,
drive_permission -> Bool,
}
}