Move dynamic input to BrickChanger

This commit is contained in:
Gregoo 2025-01-29 15:58:41 +01:00
parent ead0b1f90d
commit fd479d40f9
4 changed files with 12 additions and 8 deletions

View File

@ -143,7 +143,9 @@ class BrickPart(RebrickablePart):
return self
# Update the missing part
def update_missing(self, missing: Any, /) -> None:
def update_missing(self, json: Any | None, /) -> None:
missing = json.get('value', '') # type: ignore
# We need a positive integer
try:
missing = int(missing)

View File

@ -137,9 +137,7 @@ def missing_part(
minifigure=brickminifigure,
)
missing = request.json.get('missing', '') # type: ignore
brickpart.update_missing(missing)
brickpart.update_missing(request.json)
# Info
logger.info('Set {set} ({id}): updated part ({part} color: {color}, spare: {spare}, minifigure: {figure}) missing count to {missing}'.format( # noqa: E501
@ -152,7 +150,7 @@ def missing_part(
missing=brickpart.fields.missing,
))
return jsonify({'missing': missing})
return jsonify({'missing': brickpart.fields.missing})
# Refresh a set

View File

@ -15,8 +15,10 @@ class BrickChanger {
// Register an event depending on the type
if (this.html_type == "checkbox") {
var listener = "change";
} else if(this.html_type == "text") {
var listener = "change";
} else {
var listener = "click";
throw Error("Unsupported input type for BrickChanger");
}
this.html_element.addEventListener(listener, ((changer) => (e) => {
@ -70,8 +72,10 @@ class BrickChanger {
// Grab the value depending on the type
if (this.html_type == "checkbox") {
var value = this.html_element.checked;
} else {
} else if(this.html_type == "text") {
var value = this.html_element.value;
} else {
throw Error("Unsupported input type for BrickChanger");
}
const response = await fetch(this.url, {

View File

@ -24,7 +24,7 @@
<div class="input-group">
<input class="form-control form-control-sm flex-shrink-1" type="text" id="{{ prefix }}-{{ id }}" value="{% if value %}{{ value }}{% endif %}"
{% if g.login.is_authenticated() %}
onchange="change_part_missing_amount(this, '{{ id }}', '{{ html_id }}', '{{ url }}')"
data-changer-id="{{ id }}" data-changer-prefix="{{ prefix }}" data-changer-url="{{ url }}"
{% else %}
disabled
{% endif %}