formatting and snackbar
This commit is contained in:
@@ -45,16 +45,16 @@ def builder(page):
|
|||||||
|
|
||||||
def create_ingredient_row(self, ingredient, details):
|
def create_ingredient_row(self, ingredient, details):
|
||||||
row = []
|
row = []
|
||||||
row.append(ft.TextField(label="Ingredient", value=ingredient, on_change=self.update_ingredient))
|
row.append(ft.TextField(label="Ingredient", value=ingredient, on_change=self.update_ingredient, width=300))
|
||||||
row.append(ft.TextField(label="Quantity", value=details['quantity'], on_change=self.update_quantity))
|
row.append(ft.TextField(label="Quantity", value=details['quantity'], on_change=self.update_quantity, width=200))
|
||||||
row.append(ft.TextField(label="Units (optional)", value=details['units'], on_change=self.update_units))
|
row.append(ft.TextField(label="Units (optional)", value=details['units'], on_change=self.update_units, width=200))
|
||||||
return row
|
return row
|
||||||
|
|
||||||
def create_new_ingredient_row(self):
|
def create_new_ingredient_row(self):
|
||||||
row = []
|
row = []
|
||||||
row.append(ft.TextField(label="Ingredient", value=""))
|
row.append(ft.TextField(label="Ingredient", value="", width=300))
|
||||||
row.append(ft.TextField(label="Quantity", value=""))
|
row.append(ft.TextField(label="Quantity", value="", width=200))
|
||||||
row.append(ft.TextField(label="Units (optional)", value=""))
|
row.append(ft.TextField(label="Units (optional)", value="", width=200))
|
||||||
return row
|
return row
|
||||||
|
|
||||||
def update_ingredients(self, name):
|
def update_ingredients(self, name):
|
||||||
@@ -78,26 +78,32 @@ def builder(page):
|
|||||||
def show_new_meal(self):
|
def show_new_meal(self):
|
||||||
self.new_meal = {}
|
self.new_meal = {}
|
||||||
selector_body.controls = [
|
selector_body.controls = [
|
||||||
ft.TextField(label="Meal", value="", autofocus=True),
|
ft.TextField(label="Meal", value="", autofocus=True, width=720),
|
||||||
ft.ListView(controls=[ft.Row(self.create_new_ingredient_row(),
|
ft.ListView(controls=[ft.Row(self.create_new_ingredient_row(),
|
||||||
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
|
alignment=ft.MainAxisAlignment.START,
|
||||||
width=300,
|
|
||||||
height=100,
|
|
||||||
)],
|
)],
|
||||||
expand=True,
|
expand=True,
|
||||||
spacing=5,
|
|
||||||
padding=5,
|
|
||||||
auto_scroll=False,
|
auto_scroll=False,
|
||||||
),
|
),
|
||||||
ft.ElevatedButton(text="Add Ingredient", on_click=lambda e: self.append_new_ingredient_row(selector_body)),
|
ft.Row(controls=[
|
||||||
ft.ElevatedButton(text="Add Meal", on_click=lambda e: self.add_new_meal(selector_body)),
|
ft.ElevatedButton(text="Add Ingredient", on_click=lambda e: self.append_new_ingredient_row(selector_body)),
|
||||||
ft.ElevatedButton(text="Back", on_click=lambda e: self.show_meal_selection(selector_body, page))
|
ft.ElevatedButton(text="Add Meal", on_click=lambda e: self.add_new_meal(selector_body)),
|
||||||
|
ft.ElevatedButton(text="Back", on_click=lambda e: self.show_meal_selection(selector_body, page))
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
page.title = "Add New Meal"
|
page.title = "Add New Meal"
|
||||||
page.update()
|
page.update()
|
||||||
|
|
||||||
def append_new_ingredient_row(self, selector_body):
|
def append_new_ingredient_row(self, selector_body):
|
||||||
|
# Don't add a new row if the last one is blank
|
||||||
|
if selector_body.controls[1].controls[-1].controls[0].value == "" or \
|
||||||
|
selector_body.controls[1].controls[-1].controls[1].value == "":
|
||||||
|
page.open(ft.SnackBar(ft.Text("Please fill in the current ingredient before adding a new one.")))
|
||||||
|
return
|
||||||
|
|
||||||
selector_body.controls[1].controls.append(ft.Row(self.create_new_ingredient_row(),
|
selector_body.controls[1].controls.append(ft.Row(self.create_new_ingredient_row(),
|
||||||
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
|
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
|
||||||
width=300,
|
width=300,
|
||||||
@@ -109,6 +115,12 @@ def builder(page):
|
|||||||
meal = selector_body.controls[0].value
|
meal = selector_body.controls[0].value
|
||||||
ing, qua, uni = [], [], []
|
ing, qua, uni = [], [], []
|
||||||
|
|
||||||
|
if meal == "" or \
|
||||||
|
selector_body.controls[1].controls.controls[0].value == "" or \
|
||||||
|
selector_body.controls[1].controls.controls[1].value == "":
|
||||||
|
page.open(ft.SnackBar(ft.Text("Please fill out the meal information.")))
|
||||||
|
return
|
||||||
|
|
||||||
for row in selector_body.controls[1].controls:
|
for row in selector_body.controls[1].controls:
|
||||||
#skip blank row
|
#skip blank row
|
||||||
if row.controls[0].value == "" or row.controls[1].value == "":
|
if row.controls[0].value == "" or row.controls[1].value == "":
|
||||||
@@ -128,14 +140,16 @@ def builder(page):
|
|||||||
def show_meal_details(self, selector_body, page):
|
def show_meal_details(self, selector_body, page):
|
||||||
expanded_meal = []
|
expanded_meal = []
|
||||||
|
|
||||||
|
if (selector_body.controls[0].controls[0].value == None):
|
||||||
|
page.open(ft.SnackBar(ft.Text("Please select a meal to update.")))
|
||||||
|
return
|
||||||
|
|
||||||
meal_name = selector_body.controls[0].controls[0].value
|
meal_name = selector_body.controls[0].controls[0].value
|
||||||
|
|
||||||
for details in meal_json[meal_name].items():
|
for details in meal_json[meal_name].items():
|
||||||
expanded_meal.append(
|
expanded_meal.append(
|
||||||
ft.Row(self.create_ingredient_row(details[0], details[1]),
|
ft.Row(self.create_ingredient_row(details[0], details[1]),
|
||||||
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
|
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
|
||||||
width=300,
|
|
||||||
height=100,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -144,13 +158,16 @@ def builder(page):
|
|||||||
ft.ListView(
|
ft.ListView(
|
||||||
controls=expanded_meal,
|
controls=expanded_meal,
|
||||||
expand=True,
|
expand=True,
|
||||||
spacing=5,
|
spacing=10,
|
||||||
padding=5,
|
padding=10,
|
||||||
auto_scroll=False,
|
auto_scroll=False,
|
||||||
),
|
),
|
||||||
ft.ElevatedButton(text="Update Meal", on_click=lambda e: self.update_ingredients(selector_body.controls[0].value)),
|
ft.Row(controls=[
|
||||||
ft.ElevatedButton(text="Back", on_click=lambda e: self.show_meal_selection(selector_body, page)),
|
ft.ElevatedButton(text="Save Changes", on_click=lambda e: self.update_ingredients(selector_body.controls[0].value)),
|
||||||
]
|
ft.ElevatedButton(text="Back", on_click=lambda e: self.show_meal_selection(selector_body, page)),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
if page.title == "Create and Edit Meals!":
|
if page.title == "Create and Edit Meals!":
|
||||||
page.title = f"Editing {meal_name}"
|
page.title = f"Editing {meal_name}"
|
||||||
page.update()
|
page.update()
|
||||||
@@ -164,14 +181,18 @@ def builder(page):
|
|||||||
self.get_meal_radios_group(),
|
self.get_meal_radios_group(),
|
||||||
],
|
],
|
||||||
expand=True,
|
expand=True,
|
||||||
spacing=5,
|
spacing=10,
|
||||||
padding=5,
|
padding=10,
|
||||||
auto_scroll=False,
|
auto_scroll=False,
|
||||||
),
|
),
|
||||||
ft.ElevatedButton(text="Update Meal",
|
ft.Row(
|
||||||
|
controls=[
|
||||||
|
ft.ElevatedButton(text="Update Meal",
|
||||||
on_click=lambda e: self.show_meal_details(selector_body, page)),
|
on_click=lambda e: self.show_meal_details(selector_body, page)),
|
||||||
ft.ElevatedButton(text="Add Meal", on_click=lambda e: self.show_new_meal())
|
ft.ElevatedButton(text="Add Meal", on_click=lambda e: self.show_new_meal())
|
||||||
]
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
if page.title != "Create and Edit Meals!":
|
if page.title != "Create and Edit Meals!":
|
||||||
page.title = f"Create and Edit Meals!"
|
page.title = f"Create and Edit Meals!"
|
||||||
@@ -186,7 +207,7 @@ def builder(page):
|
|||||||
|
|
||||||
selector_body = ft.Column(
|
selector_body = ft.Column(
|
||||||
controls = [],
|
controls = [],
|
||||||
height = 500,
|
height = 700,
|
||||||
expand = False,
|
expand = False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user