FEA: filter for approval stages

This commit is contained in:
Keanu D?lle 2022-05-18 17:07:10 +02:00
parent 04341b00bf
commit cda9a16899
5 changed files with 73 additions and 9 deletions

View File

@ -17,6 +17,13 @@ EventBillingList = (function () {
pag.set_limit(limit);
load_events();
});
$("#event_billing_list_status_personnal_billing_done").off("change").on("change", function(){
if($(this).prop("checked")){
$("#event_billing_list_status_personnal_billing_done_filter_approval").prop("disabled", false);
}else{
$("#event_billing_list_status_personnal_billing_done_filter_approval").prop("disabled", true);
}
});
};
let load_templates = async function () {
const eb_list_card = $.get("/templates/eb_list_card.hbs");
@ -61,6 +68,11 @@ EventBillingList = (function () {
}
if ($("#event_billing_list_status_personnal_billing_done").prop("checked")){
event_states += "7,"
let billing_state = $("#event_billing_list_status_personnal_billing_done_filter_approval").val();
if(billing_state){
args += "&billing_states="+billing_state
}
}
if ($("#event_billing_list_status_billing_approved").prop("checked")){
event_states += "8,"

View File

@ -59,13 +59,20 @@
Personalabrechnung abgeschlossen
</label>
</div>
<div class="col-auto">
<select class="form-control" id="event_billing_list_status_personnal_billing_done_filter_approval" disabled>
<option value="">Alle Freigabestufen</option>
{{#each billing_states}}
<option value="{{entity_id}}">{{description}}</option>
{{/each}}
</select>
</div>
<div class="form-check" style="margin-left: 15px;">
<input class="form-check-input" type="checkbox" id="event_billing_list_status_billing_approved">
<label class="form-check-label" for="event_billing_list_status_billing_approved">
Freigegeben
Abgeschlossen
</label>
</div>
<button type="button" class="event_billing_list_load btn btn-primary" style="margin-left: 15px;">Laden
</button>
</div>

View File

@ -128,12 +128,14 @@ pub fn change_event(settings: &State<Settings>, data: Event) -> Result<Event, di
}
}
pub fn get_events(settings: &State<Settings>, startdate: NaiveDateTime, enddate: NaiveDateTime, limit: i64, offset: i64, groups: Option<Vec<uuid::Uuid>>, states: Option<Vec<i16>>) -> Result<Vec<Event>, diesel::result::Error>{
pub fn get_events(settings: &State<Settings>, startdate: NaiveDateTime, enddate: NaiveDateTime, limit: i64, offset: i64, groups: Option<Vec<uuid::Uuid>>, states: Option<Vec<i16>>, billing_states: Option<Vec<uuid::Uuid>>) -> Result<Vec<Event>, diesel::result::Error>{
use crate::schema::events::dsl::*;
use crate::schema::eu_instances::billing_state_id;
use crate::diesel::JoinOnDsl;
let connection = establish_connection(settings);
let mut query = events.order(start.asc()).filter(start.ge(startdate)).filter(end.le(enddate)).limit(limit).offset(offset).into_boxed();
let mut query = events.inner_join(crate::schema::eu_instances::table.on(crate::schema::eu_instances::event_id.eq(entity_id))).order(start.asc()).filter(start.ge(startdate)).filter(end.le(enddate)).limit(limit).offset(offset).into_boxed();
if let Some(groups) = groups {
query = query.filter(related_group.eq(any(groups)));
@ -143,7 +145,11 @@ pub fn get_events(settings: &State<Settings>, startdate: NaiveDateTime, enddate:
query = query.filter(state.eq(any(states)));
};
match query.get_results(&connection){
if let Some(billing_states) = billing_states{
query = query.filter(billing_state_id.eq(any(billing_states)));
}
match query.select((entity_id, name, start, end, site, organiser_id, etype, contact_on_site_name, contact_on_site_phone, member_responsible, related_group, other, other_intern, related_request, state)).distinct().get_results(&connection){
Ok(eventlist) => Ok(eventlist),
Err(e) => {
error!("Couldn't get events: {}", e);

View File

@ -18,7 +18,7 @@ pub struct EventList {
pub(crate) total_event_count: i64,
}
#[get("/api/events?<start>&<end>&<limit>&<offset>&<groups>&<states>", format = "json")]
#[get("/api/events?<start>&<end>&<limit>&<offset>&<groups>&<states>&<billing_states>", format = "json")]
pub fn read_events(
settings: &State<Settings>,
cookie: SessionCookie,
@ -28,6 +28,7 @@ pub fn read_events(
offset: Option<i64>,
groups: Option<String>,
states: Option<String>,
billing_states: Option<String>,
) -> Result<Json<EventList>, Json<ApiErrorWrapper>> {
let caller = parse_member_cookie(cookie.member)?;
@ -52,6 +53,23 @@ pub fn read_events(
},
None => None
};
let billing_states = match billing_states{
Some(states) => {
let mut res: Vec<uuid::Uuid> = vec![];
for state in states.split(","){
let parsed_state : uuid::Uuid = match state.parse(){
Ok(state) => state,
Err(e) => {
error!("Couldn't parse transmitted billing state: {}", e);
return Err(Json(ApiError::new(400, "Couldn't parse transmitted billing states".to_string()).to_wrapper()))
}
};
res.push(parsed_state)
}
Some(res)
},
None => None
};
let start = match start {
Some(mut start) => {
@ -95,7 +113,7 @@ pub fn read_events(
None => None,
};
let events = match get_events(settings, start, end, limit, offset, groups.clone(), states.clone()){
let events = match get_events(settings, start, end, limit, offset, groups.clone(), states.clone(), billing_states){
Ok(events) => events,
Err(e) => return Err(translate_diesel(e)),
};

View File

@ -2,7 +2,9 @@ use rocket::http::Status;
use rocket::State;
use rocket_dyn_templates::Template;
use crate::database::controller::billing::states::{BillingState, get_billing_states};
use crate::database::controller::groups::get_raw_groups;
use crate::database::model::groups::RawGroup;
use crate::helper::session_cookies::model::SessionCookie;
use crate::helper::sitebuilder::model::general::{Footer, Header, Script, Stylesheet};
use crate::helper::sitebuilder::model::sidebar::Sidebar;
@ -10,6 +12,16 @@ use crate::modules::event_billing::event::EventBilling;
use crate::modules::event_management::eventlist::EventList;
use crate::Settings;
#[derive(Serialize)]
pub struct EventBillingList {
pub header: Header,
pub footer: Footer,
pub sidebar: Sidebar,
pub caller: uuid::Uuid,
pub groups: Vec<RawGroup>,
pub billing_states: Vec<BillingState>
}
#[get("/portal/eb/list")]
pub fn event_billing_list(cookie: SessionCookie, settings: &State<Settings>) -> Result<Template, Status> {
let member = match cookie.member {
@ -49,12 +61,21 @@ pub fn event_billing_list(cookie: SessionCookie, settings: &State<Settings>) ->
Err(_e) => return Err(Status::InternalServerError)
};
let eventlist = EventList {
let billing_states = match get_billing_states(settings){
Ok(bs) => bs,
Err(e) => {
error!("Couldn't load billing states for billing list: {}", e);
return Err(Status::InternalServerError)
}
};
let eventlist = EventBillingList {
header,
footer,
sidebar,
caller: member.entity_id,
groups
groups,
billing_states
};
Ok(Template::render("module_eb_list", eventlist))