fix for medicine forms
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
'cd /app',
|
||||
'reflex export --frontend-only --no-zip',
|
||||
'mv .web/_static /drone/src/web',
|
||||
'mv .web/_static /drone/src/web',
|
||||
],
|
||||
depends_on: [
|
||||
'builder',
|
||||
|
||||
@@ -15,9 +15,7 @@ class NewMedicineState(rx.State):
|
||||
"""Define your app state here."""
|
||||
|
||||
show_med_add_form: bool = False
|
||||
medicine: Optional[Medicine] = None
|
||||
medicine_name: str = ""
|
||||
last_scan: Scan = Scan(uuid="", timestamp=0)
|
||||
last_scan_uuid: str = ""
|
||||
last_scan_time: str = ""
|
||||
updated_uuid: bool = False
|
||||
@@ -29,20 +27,21 @@ class NewMedicineState(rx.State):
|
||||
self.set_scanning(True)
|
||||
self.lastupdatetime = time.time()
|
||||
self.last_scan_uuid = ""
|
||||
self.medicine_name = ""
|
||||
return NewMedicineState.do_scanning
|
||||
|
||||
def load_last_scan(self):
|
||||
with rx.session() as session:
|
||||
statement = select(Scan).order_by(Scan.timestamp.desc()).limit(1)
|
||||
results = session.exec(statement)
|
||||
self.last_scan = results.first()
|
||||
if self.last_scan is None:
|
||||
last_scan = results.first()
|
||||
if last_scan is None:
|
||||
return
|
||||
if self.last_scan.timestamp > self.lastupdatetime:
|
||||
self.last_scan_uuid = self.last_scan.uuid
|
||||
if last_scan.timestamp > self.lastupdatetime:
|
||||
self.last_scan_uuid = last_scan.uuid
|
||||
if not self.show_med_add_form:
|
||||
self.update_medicine(self.last_scan.uuid)
|
||||
self.updated_uuid = True
|
||||
if self.update_medicine(last_scan.uuid):
|
||||
self.updated_uuid = True
|
||||
self.lastupdatetime = time.time()
|
||||
ts = datetime.datetime.fromtimestamp(self.last_scan.timestamp)
|
||||
self.last_scan_time = ts.strftime("%Y-%m-%d %H:%M")
|
||||
@@ -54,11 +53,13 @@ class NewMedicineState(rx.State):
|
||||
with rx.session() as session:
|
||||
statement = select(Medicine).where(Medicine.uuid == uuid)
|
||||
results = session.exec(statement)
|
||||
self.medicine = results.first()
|
||||
if self.medicine is not None:
|
||||
self.medicine_name = (
|
||||
f"{self.medicine.name} - {self.medicine.owner.name}"
|
||||
medicine = results.first()
|
||||
if medicine is not None:
|
||||
medicine_name = (
|
||||
f"{medicine.name} - {medicine.owner.name}"
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
@rx.background
|
||||
async def do_scanning(self):
|
||||
@@ -184,9 +185,6 @@ def new_medicine_form():
|
||||
|
||||
|
||||
def taken_form():
|
||||
if NewMedicineState.medicine is None:
|
||||
return rx.vstack()
|
||||
|
||||
return rx.vstack(
|
||||
rx.heading(NewMedicineState.medicine_name, size="lg", color="darkblue"),
|
||||
rx.hstack(
|
||||
@@ -244,7 +242,10 @@ def medicine() -> rx.Component:
|
||||
border_bottom=styles.border,
|
||||
padding="1em",
|
||||
),
|
||||
rx.cond(NewMedicineState.show_med_add_form, new_medicine_form()),
|
||||
rx.cond(
|
||||
NewMedicineState.show_med_add_form,
|
||||
new_medicine_form()
|
||||
),
|
||||
rx.cond(
|
||||
NewMedicineState.updated_uuid,
|
||||
taken_form(),
|
||||
@@ -252,6 +253,5 @@ def medicine() -> rx.Component:
|
||||
"Scan the Med",
|
||||
),
|
||||
),
|
||||
rx.foreach(NewMedicineState.owners, rx.text),
|
||||
on_mount=NewMedicineState.start_scan,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user