fix 1x no cox stuff
This commit is contained in:
parent
4179b7bd6b
commit
56ae0ae429
@ -129,15 +129,18 @@ function setMaxAmountRowers(name: string, rowers: number) {
|
|||||||
// only_steering.parentElement?.parentElement?.parentElement?.classList.add('opacity-50');
|
// only_steering.parentElement?.parentElement?.parentElement?.classList.add('opacity-50');
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
let shipmaster = <HTMLElement>document.querySelector('#shipmaster-newrowerjs');
|
let shipmaster = <HTMLElement>document.querySelector('#shipmaster-'+name+'js');
|
||||||
let steering_person = <HTMLElement>document.querySelector('#steering_person-newrowerjs');
|
let steering_person = <HTMLElement>document.querySelector('#steering_person-'+name+'js');
|
||||||
if (rowers == 1){
|
if (rowers == 1){
|
||||||
if (shipmaster.parentNode) {
|
if (shipmaster.parentNode) {
|
||||||
(<HTMLElement>shipmaster.parentNode).classList.add('hidden');
|
(<HTMLElement>shipmaster.parentNode).classList.add('hidden');
|
||||||
}
|
}
|
||||||
|
shipmaster.removeAttribute('required');
|
||||||
|
|
||||||
if (steering_person.parentNode){
|
if (steering_person.parentNode){
|
||||||
(<HTMLElement>steering_person.parentNode).classList.add('hidden');
|
(<HTMLElement>steering_person.parentNode).classList.add('hidden');
|
||||||
}
|
}
|
||||||
|
steering_person.removeAttribute('required');
|
||||||
}else{
|
}else{
|
||||||
if (shipmaster.parentNode){
|
if (shipmaster.parentNode){
|
||||||
(<HTMLElement>shipmaster.parentNode).classList.remove('hidden');
|
(<HTMLElement>shipmaster.parentNode).classList.remove('hidden');
|
||||||
@ -196,6 +199,31 @@ function initNewChoice(select: HTMLInputElement) {
|
|||||||
if (select.dataset && select.dataset.seats) {
|
if (select.dataset && select.dataset.seats) {
|
||||||
seats = +select.dataset.seats;
|
seats = +select.dataset.seats;
|
||||||
}
|
}
|
||||||
|
console.log(seats);
|
||||||
|
|
||||||
|
let shipmaster = <HTMLElement>document.querySelector('#shipmaster-'+select.id+'js');
|
||||||
|
let steering_person = <HTMLElement>document.querySelector('#steering_person-'+select.id+'js');
|
||||||
|
if (seats == 1){
|
||||||
|
if (shipmaster.parentNode) {
|
||||||
|
(<HTMLElement>shipmaster.parentNode).classList.add('hidden');
|
||||||
|
}
|
||||||
|
shipmaster.removeAttribute('required');
|
||||||
|
|
||||||
|
if (steering_person.parentNode){
|
||||||
|
(<HTMLElement>steering_person.parentNode).classList.add('hidden');
|
||||||
|
}
|
||||||
|
steering_person.removeAttribute('required');
|
||||||
|
}else{
|
||||||
|
if (shipmaster.parentNode){
|
||||||
|
(<HTMLElement>shipmaster.parentNode).classList.remove('hidden');
|
||||||
|
}
|
||||||
|
shipmaster.setAttribute('required', 'required');
|
||||||
|
|
||||||
|
if (steering_person.parentNode){
|
||||||
|
(<HTMLElement>steering_person.parentNode).classList.remove('hidden');
|
||||||
|
}
|
||||||
|
steering_person.setAttribute('required', 'required');
|
||||||
|
}
|
||||||
const choice = new Choices(select, {
|
const choice = new Choices(select, {
|
||||||
removeItemButton: true,
|
removeItemButton: true,
|
||||||
loadingText: 'Wird geladen...',
|
loadingText: 'Wird geladen...',
|
||||||
|
@ -30,8 +30,8 @@ impl PartialEq for Logbook {
|
|||||||
#[derive(FromForm, Debug, Clone)]
|
#[derive(FromForm, Debug, Clone)]
|
||||||
pub struct LogToAdd {
|
pub struct LogToAdd {
|
||||||
pub boat_id: i32,
|
pub boat_id: i32,
|
||||||
pub shipmaster: i64,
|
pub shipmaster: Option<i64>,
|
||||||
pub steering_person: i64,
|
pub steering_person: Option<i64>,
|
||||||
pub shipmaster_only_steering: bool,
|
pub shipmaster_only_steering: bool,
|
||||||
pub departure: String,
|
pub departure: String,
|
||||||
pub arrival: Option<String>,
|
pub arrival: Option<String>,
|
||||||
@ -44,8 +44,8 @@ pub struct LogToAdd {
|
|||||||
|
|
||||||
#[derive(FromForm, Debug)]
|
#[derive(FromForm, Debug)]
|
||||||
pub struct LogToFinalize {
|
pub struct LogToFinalize {
|
||||||
pub shipmaster: i64,
|
pub shipmaster: Option<i64>,
|
||||||
pub steering_person: i64,
|
pub steering_person: Option<i64>,
|
||||||
pub shipmaster_only_steering: bool,
|
pub shipmaster_only_steering: bool,
|
||||||
pub departure: String,
|
pub departure: String,
|
||||||
pub arrival: String,
|
pub arrival: String,
|
||||||
@ -236,13 +236,18 @@ ORDER BY departure DESC
|
|||||||
|
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
db: &SqlitePool,
|
db: &SqlitePool,
|
||||||
log: LogToAdd,
|
mut log: LogToAdd,
|
||||||
created_by_user: &User,
|
created_by_user: &User,
|
||||||
) -> Result<(), LogbookCreateError> {
|
) -> Result<(), LogbookCreateError> {
|
||||||
let Some(boat) = Boat::find_by_id(db, log.boat_id).await else {
|
let Some(boat) = Boat::find_by_id(db, log.boat_id).await else {
|
||||||
return Err(LogbookCreateError::BoatNotFound);
|
return Err(LogbookCreateError::BoatNotFound);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if boat.amount_seats == 1 {
|
||||||
|
log.shipmaster = Some(log.rowers[0]);
|
||||||
|
log.steering_person = Some(log.rowers[0]);
|
||||||
|
}
|
||||||
|
|
||||||
if let Ok(log_to_finalize) = TryInto::<LogToFinalize>::try_into(log.clone()) {
|
if let Ok(log_to_finalize) = TryInto::<LogToFinalize>::try_into(log.clone()) {
|
||||||
//TODO: fix clone() above
|
//TODO: fix clone() above
|
||||||
|
|
||||||
@ -293,10 +298,10 @@ ORDER BY departure DESC
|
|||||||
return Err(LogbookCreateError::BoatAlreadyOnWater);
|
return Err(LogbookCreateError::BoatAlreadyOnWater);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !log.rowers.contains(&log.shipmaster) {
|
if !log.rowers.contains(&log.shipmaster.unwrap()) {
|
||||||
return Err(LogbookCreateError::ShipmasterNotInRowers);
|
return Err(LogbookCreateError::ShipmasterNotInRowers);
|
||||||
}
|
}
|
||||||
if !log.rowers.contains(&log.steering_person) {
|
if !log.rowers.contains(&log.steering_person.unwrap()) {
|
||||||
return Err(LogbookCreateError::SteeringPersonNotInRowers);
|
return Err(LogbookCreateError::SteeringPersonNotInRowers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,21 +408,26 @@ ORDER BY departure DESC
|
|||||||
&self,
|
&self,
|
||||||
db: &mut Transaction<'_, Sqlite>,
|
db: &mut Transaction<'_, Sqlite>,
|
||||||
user: &User,
|
user: &User,
|
||||||
log: LogToFinalize,
|
mut log: LogToFinalize,
|
||||||
) -> Result<(), LogbookUpdateError> {
|
) -> Result<(), LogbookUpdateError> {
|
||||||
//TODO: extract common tests with `create()`
|
//TODO: extract common tests with `create()`
|
||||||
if user.id != self.shipmaster {
|
if user.id != self.shipmaster {
|
||||||
return Err(LogbookUpdateError::NotYourEntry);
|
return Err(LogbookUpdateError::NotYourEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !log.rowers.contains(&log.shipmaster) {
|
let boat = Boat::find_by_id_tx(db, self.boat_id as i32).await.unwrap(); //ok
|
||||||
return Err(LogbookUpdateError::ShipmasterNotInRowers);
|
|
||||||
}
|
if boat.amount_seats == 1 {
|
||||||
if !log.rowers.contains(&log.steering_person) {
|
log.shipmaster = Some(log.rowers[0]);
|
||||||
return Err(LogbookUpdateError::SteeringPersonNotInRowers);
|
log.steering_person = Some(log.rowers[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let boat = Boat::find_by_id_tx(db, self.boat_id as i32).await.unwrap(); //ok
|
if !log.rowers.contains(&log.shipmaster.unwrap()) {
|
||||||
|
return Err(LogbookUpdateError::ShipmasterNotInRowers);
|
||||||
|
}
|
||||||
|
if !log.rowers.contains(&log.steering_person.unwrap()) {
|
||||||
|
return Err(LogbookUpdateError::SteeringPersonNotInRowers);
|
||||||
|
}
|
||||||
|
|
||||||
if !boat.shipmaster_allowed(&user).await && self.shipmaster != user.id {
|
if !boat.shipmaster_allowed(&user).await && self.shipmaster != user.id {
|
||||||
//second part:
|
//second part:
|
||||||
@ -546,8 +556,8 @@ mod test {
|
|||||||
&pool,
|
&pool,
|
||||||
LogToAdd {
|
LogToAdd {
|
||||||
boat_id: 3,
|
boat_id: 3,
|
||||||
shipmaster: 4,
|
shipmaster: Some(4),
|
||||||
steering_person: 4,
|
steering_person: Some(4),
|
||||||
shipmaster_only_steering: false,
|
shipmaster_only_steering: false,
|
||||||
departure: "2128-05-20T12:00".into(),
|
departure: "2128-05-20T12:00".into(),
|
||||||
arrival: None,
|
arrival: None,
|
||||||
@ -571,8 +581,8 @@ mod test {
|
|||||||
&pool,
|
&pool,
|
||||||
LogToAdd {
|
LogToAdd {
|
||||||
boat_id: 999,
|
boat_id: 999,
|
||||||
shipmaster: 5,
|
shipmaster: Some(5),
|
||||||
steering_person: 5,
|
steering_person: Some(5),
|
||||||
shipmaster_only_steering: false,
|
shipmaster_only_steering: false,
|
||||||
departure: "2128-05-20T12:00".into(),
|
departure: "2128-05-20T12:00".into(),
|
||||||
arrival: None,
|
arrival: None,
|
||||||
@ -597,8 +607,8 @@ mod test {
|
|||||||
&pool,
|
&pool,
|
||||||
LogToAdd {
|
LogToAdd {
|
||||||
boat_id: 5,
|
boat_id: 5,
|
||||||
shipmaster: 5,
|
shipmaster: Some(5),
|
||||||
steering_person: 5,
|
steering_person: Some(5),
|
||||||
shipmaster_only_steering: false,
|
shipmaster_only_steering: false,
|
||||||
departure: "2128-05-20T12:00".into(),
|
departure: "2128-05-20T12:00".into(),
|
||||||
arrival: None,
|
arrival: None,
|
||||||
@ -623,8 +633,8 @@ mod test {
|
|||||||
&pool,
|
&pool,
|
||||||
LogToAdd {
|
LogToAdd {
|
||||||
boat_id: 2,
|
boat_id: 2,
|
||||||
shipmaster: 5,
|
shipmaster: Some(5),
|
||||||
steering_person: 5,
|
steering_person: Some(5),
|
||||||
shipmaster_only_steering: false,
|
shipmaster_only_steering: false,
|
||||||
departure: "2128-05-20T12:00".into(),
|
departure: "2128-05-20T12:00".into(),
|
||||||
arrival: None,
|
arrival: None,
|
||||||
@ -649,8 +659,8 @@ mod test {
|
|||||||
&pool,
|
&pool,
|
||||||
LogToAdd {
|
LogToAdd {
|
||||||
boat_id: 3,
|
boat_id: 3,
|
||||||
shipmaster: 5,
|
shipmaster: Some(5),
|
||||||
steering_person: 5,
|
steering_person: Some(5),
|
||||||
shipmaster_only_steering: false,
|
shipmaster_only_steering: false,
|
||||||
departure: "2128-05-20T12:00".into(),
|
departure: "2128-05-20T12:00".into(),
|
||||||
arrival: Some("2128-05-20T11:00".into()),
|
arrival: Some("2128-05-20T11:00".into()),
|
||||||
@ -675,8 +685,8 @@ mod test {
|
|||||||
&pool,
|
&pool,
|
||||||
LogToAdd {
|
LogToAdd {
|
||||||
boat_id: 3,
|
boat_id: 3,
|
||||||
shipmaster: 2,
|
shipmaster: Some(2),
|
||||||
steering_person: 2,
|
steering_person: Some(2),
|
||||||
shipmaster_only_steering: false,
|
shipmaster_only_steering: false,
|
||||||
departure: "2128-05-20T12:00".into(),
|
departure: "2128-05-20T12:00".into(),
|
||||||
arrival: None,
|
arrival: None,
|
||||||
@ -701,8 +711,8 @@ mod test {
|
|||||||
&pool,
|
&pool,
|
||||||
LogToAdd {
|
LogToAdd {
|
||||||
boat_id: 3,
|
boat_id: 3,
|
||||||
shipmaster: 5,
|
shipmaster: Some(5),
|
||||||
steering_person: 1,
|
steering_person: Some(1),
|
||||||
shipmaster_only_steering: false,
|
shipmaster_only_steering: false,
|
||||||
departure: "2128-05-20T12:00".into(),
|
departure: "2128-05-20T12:00".into(),
|
||||||
arrival: None,
|
arrival: None,
|
||||||
@ -727,8 +737,8 @@ mod test {
|
|||||||
&pool,
|
&pool,
|
||||||
LogToAdd {
|
LogToAdd {
|
||||||
boat_id: 1,
|
boat_id: 1,
|
||||||
shipmaster: 5,
|
shipmaster: Some(5),
|
||||||
steering_person: 5,
|
steering_person: Some(5),
|
||||||
shipmaster_only_steering: false,
|
shipmaster_only_steering: false,
|
||||||
departure: "2128-05-20T12:00".into(),
|
departure: "2128-05-20T12:00".into(),
|
||||||
arrival: None,
|
arrival: None,
|
||||||
@ -777,8 +787,8 @@ mod test {
|
|||||||
comments: Some("Perfect water".into()),
|
comments: Some("Perfect water".into()),
|
||||||
logtype: None,
|
logtype: None,
|
||||||
rowers: vec![2],
|
rowers: vec![2],
|
||||||
shipmaster: 2,
|
shipmaster: Some(2),
|
||||||
steering_person: 2,
|
steering_person: Some(2),
|
||||||
shipmaster_only_steering: false,
|
shipmaster_only_steering: false,
|
||||||
departure: "1990-01-01T10:00".into(),
|
departure: "1990-01-01T10:00".into(),
|
||||||
arrival: "1990-01-01T12:00".into(),
|
arrival: "1990-01-01T12:00".into(),
|
||||||
@ -805,8 +815,8 @@ mod test {
|
|||||||
comments: Some("Perfect water".into()),
|
comments: Some("Perfect water".into()),
|
||||||
logtype: None,
|
logtype: None,
|
||||||
rowers: vec![1],
|
rowers: vec![1],
|
||||||
shipmaster: 1,
|
shipmaster: Some(1),
|
||||||
steering_person: 1,
|
steering_person: Some(1),
|
||||||
shipmaster_only_steering: false,
|
shipmaster_only_steering: false,
|
||||||
departure: "1990-01-01T10:00".into(),
|
departure: "1990-01-01T10:00".into(),
|
||||||
arrival: "1990-01-01T12:00".into(),
|
arrival: "1990-01-01T12:00".into(),
|
||||||
@ -834,8 +844,8 @@ mod test {
|
|||||||
comments: Some("Perfect water".into()),
|
comments: Some("Perfect water".into()),
|
||||||
logtype: None,
|
logtype: None,
|
||||||
rowers: vec![1, 2],
|
rowers: vec![1, 2],
|
||||||
shipmaster: 2,
|
shipmaster: Some(2),
|
||||||
steering_person: 2,
|
steering_person: Some(2),
|
||||||
shipmaster_only_steering: false,
|
shipmaster_only_steering: false,
|
||||||
departure: "1990-01-01T10:00".into(),
|
departure: "1990-01-01T10:00".into(),
|
||||||
arrival: "1990-01-01T12:00".into(),
|
arrival: "1990-01-01T12:00".into(),
|
||||||
|
@ -210,7 +210,11 @@ async fn create_kiosk(
|
|||||||
data: Form<LogToAdd>,
|
data: Form<LogToAdd>,
|
||||||
_kiosk: KioskCookie,
|
_kiosk: KioskCookie,
|
||||||
) -> Flash<Redirect> {
|
) -> Flash<Redirect> {
|
||||||
let creator = User::find_by_id(db, data.shipmaster as i32).await.unwrap();
|
let creator = if let Some(shipmaster) = data.shipmaster {
|
||||||
|
User::find_by_id(db, shipmaster as i32).await.unwrap()
|
||||||
|
} else {
|
||||||
|
User::find_by_id(db, data.rowers[0] as i32).await.unwrap()
|
||||||
|
};
|
||||||
Log::create(
|
Log::create(
|
||||||
db,
|
db,
|
||||||
format!(
|
format!(
|
||||||
|
Loading…
Reference in New Issue
Block a user