Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧑‍🍳 Show image instead of empty menu #98

Merged
merged 7 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions .github/workflows/ci_cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
Expand All @@ -58,7 +58,7 @@ jobs:

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
Expand All @@ -74,14 +74,15 @@ jobs:

environment:
name: release
url: https://github.com/Michele-Alberti/data-lunch/releases

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
Expand Down Expand Up @@ -127,22 +128,22 @@ jobs:
with:
ref: main
- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
username: ${{ vars.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
context: ./
file: ./docker/web/Dockerfile.web
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/data-lunch-app:stable
cache-from: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/data-lunch-app:buildcache
cache-to: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/data-lunch-app:buildcache,mode=max
tags: ${{ vars.DOCKER_HUB_USERNAME }}/data-lunch-app:stable
cache-from: type=registry,ref=${{ vars.DOCKER_HUB_USERNAME }}/data-lunch-app:buildcache
cache-to: type=registry,ref=${{ vars.DOCKER_HUB_USERNAME }}/data-lunch-app:buildcache,mode=max

# If on development just publish to TestPyPI
# Build the package for TestPyPI
Expand All @@ -157,7 +158,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
Expand All @@ -174,7 +175,7 @@ jobs:
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
Expand All @@ -194,7 +195,7 @@ jobs:

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/manual_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
username: ${{ vars.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
context: ./
file: ./docker/web/Dockerfile.web
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/data-lunch-app:${{ github.event.inputs.tag }}
cache-from: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/data-lunch-app:buildcache
cache-to: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/data-lunch-app:buildcache,mode=max
tags: ${{ vars.DOCKER_HUB_USERNAME }}/data-lunch-app:${{ github.event.inputs.tag }}
cache-from: type=registry,ref=${{ vars.DOCKER_HUB_USERNAME }}/data-lunch-app:buildcache
cache-to: type=registry,ref=${{ vars.DOCKER_HUB_USERNAME }}/data-lunch-app:buildcache,mode=max
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black
language_version: python3
Expand Down
3 changes: 2 additions & 1 deletion dlunch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ def create_app(config: DictConfig) -> pn.Template:
# Build dashboard (the header object is used if defined)
app.header.append(gi.header_row)
app.sidebar.append(gi.sidebar_tabs)
app.main.append(gi.no_menu_col)
app.main.append(gi.guest_override_alert)
app.main.append(gi.no_more_order_text)
app.main.append(gi.no_more_order_alert)
app.main.append(gi.main_header_row)
app.main.append(gi.quote)
app.main.append(pn.Spacer(height=15))
Expand Down
5 changes: 1 addition & 4 deletions dlunch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ def run_app(config: DictConfig):
# Backend exist only if auth is active
# Health is an endpoint for app health assessments
# Pass a dictionary for a multipage app
pages = {
"": lambda: create_app(config=config),
"health": pn.Column("Data-Lunch is alive!"),
}
pages = {"": lambda: create_app(config=config)}
if auth.is_auth_active(config=config):
pages["backend"] = lambda: create_backend(config=config)

Expand Down
6 changes: 6 additions & 0 deletions dlunch/conf/panel/gui/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ logo_filename: logo.png
logo_static_dir: images
logo_path: ${panel.gui.logo_static_dir}/${panel.gui.logo_filename}

# IMAGES
# No menu
no_menu_image_static_dir: images
no_menu_image_filename: no_menu.jpg
no_menu_image_path: ${panel.gui.no_menu_image_static_dir}/${panel.gui.no_menu_image_filename}

# CSS FILES
css_static_dir: css
css_files:
Expand Down
3 changes: 2 additions & 1 deletion dlunch/conf/server/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ static_dirs:
css: ${package_path}/static/css
compress_response: true
cookie_secret: ${oc.env:DATA_LUNCH_COOKIE_SECRET} # Secure cookies are required (this vakue can't be null)
enable_xsrf_cookies: true
enable_xsrf_cookies: true
liveness: health
25 changes: 22 additions & 3 deletions dlunch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,24 @@ def reload_menu(
gi.dataframe.hidden_columns = []
gi.dataframe.disabled = False

# If menu is empty show banner image, otherwise show menu
if df.empty:
gi.no_menu_col.visible = True
gi.main_header_row.visible = False
gi.quote.visible = False
gi.menu_flexbox.visible = False
gi.buttons_flexbox.visible = False
gi.results_divider.visible = False
gi.res_col.visible = False
else:
gi.no_menu_col.visible = False
gi.main_header_row.visible = True
gi.quote.visible = True
gi.menu_flexbox.visible = True
gi.buttons_flexbox.visible = True
gi.results_divider.visible = True
gi.res_col.visible = True

log.debug("menu reloaded")

# Load results
Expand Down Expand Up @@ -847,6 +865,7 @@ def df_list_by_lunch_time(
def clean_up_table(config, df_in):
# Add columns of totals
df = df_in.copy()
df = df.astype(object) # Avoid mixed types (float and notes str)
df[config.panel.gui.total_column_name] = df.sum(axis=1)
if config.panel.drop_unused_menu_items:
df = df[df[config.panel.gui.total_column_name] > 0]
Expand Down Expand Up @@ -875,9 +894,9 @@ def clean_up_table(config, df_in):
# TAKEAWAY
if not df_users_takeaways.empty:
df_users_takeaways = clean_up_table(config, df_users_takeaways)
df_dict[
f"{time} {config.panel.gui.takeaway_id}"
] = df_users_takeaways
df_dict[f"{time} {config.panel.gui.takeaway_id}"] = (
df_users_takeaways
)

return df_dict

Expand Down
50 changes: 42 additions & 8 deletions dlunch/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def reload_on_guest_override_callback(
styles={"text-align": "center"},
)
# "no more order" message
self.no_more_order_text = pn.pane.HTML(
self.no_more_order_alert = pn.pane.HTML(
"""
<div class="no-more-order-flag">
<div class="icon-container">
Expand All @@ -292,11 +292,6 @@ def reload_on_guest_override_callback(
sizing_mode="stretch_width",
stylesheets=[config.panel.gui.css_files.no_more_orders_path],
)
# Takeaway alert
self.takeaway_alert_sign = f"<span {config.panel.gui.takeaway_alert_icon_options}>{config.panel.gui.takeaway_svg_icon}</span>"
self.takeaway_alert_text = f"<span {config.panel.gui.takeaway_alert_text_options}>{config.panel.gui.takeaway_id}</span> "

# WIDGETS
# Alert for guest override
self.guest_override_alert = pn.pane.HTML(
"""
Expand All @@ -318,6 +313,38 @@ def reload_on_guest_override_callback(
sizing_mode="stretch_width",
stylesheets=[config.panel.gui.css_files.guest_override_path],
)
# Takeaway alert
self.takeaway_alert_sign = f"<span {config.panel.gui.takeaway_alert_icon_options}>{config.panel.gui.takeaway_svg_icon}</span>"
self.takeaway_alert_text = f"<span {config.panel.gui.takeaway_alert_text_options}>{config.panel.gui.takeaway_id}</span> "
# No menu image attribution
self.no_menu_image_attribution = pn.pane.HTML(
"""
<i>
Image by
<a
href="https://www.freepik.com/free-vector/tiny-cooks-making-spaghetti-dinner-isolated-flat-illustration_11235909.htm"
referrerpolicy="no-referrer"
rel="external"
target="_blank"
>
pch.vector
</a>
on Freepik
</i>
""",
align="end",
styles={
"color": "darkgray",
"font-size": "10px",
"font-weight": "light",
},
)

# WIDGETS
# JPG shown when no menu is available
self.no_menu_image = pn.pane.JPG(
config.panel.gui.no_menu_image_path, alt_text="no menu"
)
# Create dataframe instance
self.dataframe = pnw.Tabulator(
name="Order",
Expand Down Expand Up @@ -373,10 +400,17 @@ def reload_on_guest_override_callback(
)

# COLUMNS
# Create column shown when no menu is available
self.no_menu_col = pn.Column(
self.no_menu_image,
self.no_menu_image_attribution,
sizing_mode="stretch_width",
min_width=465,
)
# Create column for lunch time labels
self.time_col = pn.Column(width=85)
# Create column for resulting menus
self.res_col = pn.Column(sizing_mode="stretch_width", min_width=430)
self.res_col = pn.Column(sizing_mode="stretch_width", min_width=465)

# FLEXBOXES
self.menu_flexbox = pn.FlexBox(
Expand Down Expand Up @@ -407,7 +441,7 @@ def reload_on_no_more_order_callback(
models.set_flag(config=config, id="no_more_orders", value=toggle)

# Show "no more order" text
self.no_more_order_text.visible = toggle
self.no_more_order_alert.visible = toggle

# Deactivate send order and delete order buttons
self.send_order_button.disabled = toggle
Expand Down
Binary file added dlunch/static/images/no_menu.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ help:
@echo -e " ${WHITE} interrogate :${NC} runs interrogate to check code quality"
@echo -e " ${WHITE} package-build :${NC} build python package"
@echo -e " ${WHITE} package-publish :${NC} publish python package to PyPI"
@echo -e " ${WHITE} package-install :${NC} install package with pip from PyPI (use only in a test env)"
@echo -e " ${WHITE} package-test-publish:${NC} publish python package to TestPyPI"
@echo -e " ${WHITE} package-test-install:${NC} install package with pip from TestPyPI (use only in a test env)"
@echo -e " ${WHITE} pre-commit-run :${NC} runs pre-commit hooks"
Expand Down Expand Up @@ -225,7 +226,7 @@ docker-up: check-dialect
fi;
@echo -e "${GREEN}done${NC}"

docker-up-build: check-dialect build
docker-up-build: check-dialect docker-build
@echo -e "${YELLOW}start docker compose system${NC}"
if [[ ${PANEL_ENV} == "production" ]] ; then \
docker compose -p ${PROJECTNAME} \
Expand Down Expand Up @@ -303,7 +304,7 @@ package-publish:
twine upload --repository dlunch dist/*
@echo -e "${GREEN}done${NC}"

package-test-install:
package-install:
@echo -e "${YELLOW}install package from PyPI${NC}"
pip install dlunch
@echo -e "${GREEN}done${NC}"
Expand Down
Loading