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