Move dynamic input to BrickChanger

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

View File

@ -143,7 +143,9 @@ class BrickPart(RebrickablePart):
return self return self
# Update the missing part # 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 # We need a positive integer
try: try:
missing = int(missing) missing = int(missing)

View File

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

View File

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

View File

@ -24,7 +24,7 @@
<div class="input-group"> <div class="input-group">
<input class="form-control form-control-sm flex-shrink-1" type="text" id="{{ prefix }}-{{ id }}" value="{% if value %}{{ value }}{% endif %}" <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() %} {% 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 %} {% else %}
disabled disabled
{% endif %} {% endif %}