FIX: repaired template search in event edit view; removed bug which prevented every event with vehicle_positions from loading

This commit is contained in:
Keanu D?lle 2022-03-08 15:11:38 +01:00
parent 7569644edb
commit feb90ffed2
5 changed files with 24 additions and 11 deletions

View File

@ -10,10 +10,8 @@
<div class="card-body">
<p class="font-weight-bold">Einheit einfügen:</p>
<div class="form-group row">
<label for="edit_event_cast_template_search-searchbar" class="col-sm-3 col-form-label">Vorlage: </label>
<div class="col-sm-9">
{{> search base="edit_event_cast_template_search" type="template"}}
</div>
<label class="col-sm-3 col-form-label">Vorlage: </label>
<div class="col-sm-9">{{search2 type="template" classname="search_template"}}</div>
</div>
<div class="form-group row">
<label for="edit_event_cast_instance_name" class="col-sm-3 col-form-label">Name: </label>

View File

@ -163,7 +163,7 @@ EventEditModule = (function () {
}
};
let add_template_instance = function () {
let template = $("#edit_event_cast_template_search").data("entity-id");
let template =$(".search_template").data("value-id");
let instance_name = $("#edit_event_cast_instance_name").val();
if (!template || !instance_name) {
@ -253,7 +253,7 @@ EventEditModule = (function () {
var vehicle_search = new MiniSearchbar("search_" + $(this).data("instance-id") + "_" + $(this).data("position-id"), callback, $(this).data("entity-id"), $(this).data("identifier"), delete_callback);
vehicle_search.setup();
});
Search2.setup();
$(".search_instance_position_member").off("change").on("change", async function () {
let search = $(this).closest(".search2");
let position_id = search.closest(".eu_cast_instance_personal_position").data("position-id") || undefined;
@ -280,7 +280,7 @@ EventEditModule = (function () {
remove_entity_from_position(instance_id, position_id);
}
});
Search2.setup();
});
}
},

View File

@ -132,6 +132,21 @@ Search2 = (function () {
let res = res_map.get($(this).data("entity-id"));
setValue(this, res.entity_id, res.name);
};
}else if (type === "template") {
options.url = "/api/events/units/templates/";
options.get_data = {
"q": searchbar.val()
};
options.res_handler = function (data) {
$.each(data.templates, function (index, value) {
res_map.set(value.entity_id, value);
overlay_list.append("<span tabindex=\"0\" class=\"search2-result-overlay-list-entry\" data-entity-id=\"" + value.entity_id + "\"><li class='list-group-item' title='" + value.description + "'><span class=\"badge badge-secondary\">Hinzufügen:</span> " + value.name + "</li></span>");
});
};
options.overlay_click_handler = function () {
let res = res_map.get($(this).data("entity-id"));
setValue(this, res.entity_id, res.name);
};
} else {
console.error("Unknown search type: " + type);
return;

View File

@ -493,7 +493,7 @@ pub fn add_position_instances_for_instance(settings: &State<Settings>, instance_
for position in positions{
for i in 1..position.num+1{
match diesel::insert_into(eu_position_instances).values((instance_id.eq(instance_id2), position_id.eq(position.position.entity_id))).execute(&connection){
Ok(_) => {},
Ok(_) => {debug!("Inserted new eu_position_instance with position_id {} and instance_id {}.", position.position.entity_id, instance_id2)},
Err(e) => return Err(e)
}
}

View File

@ -92,8 +92,7 @@ impl PositionInstance {
};
let position_data = match get_eu_position(settings, raw.position_id) {
Ok(position) => position,
Err(e) => {
error!("Couldn't retrieve position data for RawPositionInstance -> PositionInstance conversion: {}. Maybe there are position instances with invalid position_ids?", e);
Err(e) => { //TODO: distinguish personal & vehicle positions
return Err(())
}
};
@ -167,7 +166,8 @@ pub fn read_positions_for_instance(settings: &State<Settings>, cookie: SessionCo
match PositionInstance::from_raw(&position, settings, &cookie) {
Ok(pi) => res.push(pi),
Err(_) => {
return Err(Json(ApiError::new(500, "Couldn't retrieve position instance".to_string()).to_wrapper()))
//return Err(Json(ApiError::new(500, "Couldn't retrieve position instance".to_string()).to_wrapper()))
//TODO: distinguish vehicle & personnel positions
}
}
}