Skip to content

Commit b3ede98

Browse files
authored
Non-normal lunchtimes (#3)
* Initial draft of dynamic lunchtime updating * Improve system message * Create a updateHours task * Working version of non-normal opening hour detection * Improve juvenes selector * Schedule updateHours task * Update deps * fix: updateHours task name * Move startup tasks to a nitro plugin * Move startup tasks to a nitro plugin * Increase AllContentLoaded timeout * Increase AllContentLoaded timeout * Add logging * Cleanup * Bind vite to v5 nuxt/ui#2971 * Finalize opening time style
1 parent 41e8c35 commit b3ede98

13 files changed

+2317
-1626
lines changed

README.md

+15-4
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,26 @@ This repository contains the NuxtJS frontend and Nitro backend for fetching, upd
2929

3030
## Environment
3131

32-
| Variable | Description | Default |
33-
|---------------|------------------------|---------------------------|
34-
| NUXT_DB_URL | MongoDB connection URL | mongodb://127.0.0.1:27017 |
35-
| NUXT_DB_NAME | MongoDB database name | ou-lunch |
32+
| Variable | Description | Default |
33+
|--------------------|------------------------------|---------------------------|
34+
| NUXT_DB_URL | MongoDB connection URL | mongodb://127.0.0.1:27017 |
35+
| NUXT_DB_NAME | MongoDB database name | ou-lunch |
36+
| NUXT_HERO_CORE_URL | Url to a hero cloud instance | 127.0.0.1:1818 |
37+
| OPENAI_API_KEY | OpenAI API key | |
3638

3739
## Frontend
3840

3941
The frontend for this project is built with NuxtJS and is hosted at [ouf.fi](https://ouf.fi).
4042

43+
## Development
44+
Parts marked with `*` are only needed if developing the non-normal opening hours feature.
45+
46+
- Run `npm install` in the root directory to install the dependencies.
47+
- *Run `npm run start:cloud` to start the Ulixee Cloud instance.
48+
- Run `npm run start:db` to start the MongoDB database on Docker. You must have Docker installed.
49+
- Run `npm run dev` to start the NuxtJS frontend in development mode.
50+
- *To update the opening hours, visit `localhost:3000/_nitro/tasks/updateHours` in your browser.
51+
4152
## Contributing
4253

4354
Contributions are welcome! Please fork the repository and submit a pull request.

components/RestaurantMenu.vue

+37-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,40 @@
2222
<div class="h-0 w-full flex justify-center">
2323
<div
2424
v-if="openingHours"
25-
class="h-fit w-fit bottom-0 right-0 translate-y-1/2
25+
class="h-fit w-fit bottom-0 right-0 translate-y-1/2 flex
2626
border rounded px-1 -mb-1 dark:border-cool-700 border-cool-300 backdrop-blur-3xl"
27+
:class="{ '!border-yellow-600': nonNormalOpeningHours }"
2728
>
28-
<p class="text-cool-600 dark:text-cool-400 text-xs whitespace-nowrap">
29+
<p class="text-cool-600 dark:text-cool-400 text-xs whitespace-nowrap flex">
2930
{{ openingHours.open.hours }}:{{ openingHours.open.minutes.toString().padStart(2, '0') }}
3031
-
3132
{{ openingHours.close.hours }}:{{ openingHours.close.minutes.toString().padStart(2, '0') }}
3233
</p>
3334
</div>
35+
<UPopover
36+
v-if="nonNormalOpeningHours"
37+
mode="click"
38+
:label="$t('aria.nonNormalOpeningHours')"
39+
:ui="{ wrapper: 'w-0' }"
40+
>
41+
<UButton
42+
icon="iconoir:warning-circle-solid"
43+
color="orange"
44+
variant="link"
45+
size="xs"
46+
class="translate-y-1"
47+
:aria-label="$t('aria.nonNormalOpeningHours')"
48+
/>
49+
<template #panel>
50+
<div class="w-96 max-w-[90vw]">
51+
<UAlert
52+
type="warning"
53+
icon="iconoir:warning-circle-solid"
54+
:description="$t('restaurant.openingHoursDisclaimer')"
55+
/>
56+
</div>
57+
</template>
58+
</UPopover>
3459
</div>
3560
</template>
3661
<div v-if="menus?.length"
@@ -50,7 +75,7 @@
5075
<br>
5176
{{ $t("noMenu") }}
5277
<br>
53-
<UAlert class="mt-5" type="info" icon="ion:information-circle-outline" description="This message is only visible in development mode"/>
78+
<UAlert class="mt-5" type="info" icon="ion:information-circle-outline" description="This restaurant is hidden in production mode"/>
5479
</UCard>
5580
</DevOnly>
5681
</template>
@@ -105,7 +130,16 @@ export default defineNuxtComponent({
105130
openingHours() {
106131
if(!this.restaurant.openingHours) return;
107132
const today = this.date.getDay();
133+
const nonNormal = this.nonNormalOpeningHours;
134+
if(nonNormal) {
135+
// console.log(`Non-normal opening hours for ${this.restaurant.name} on ${this.date.toDateString()}: ${nonNormal.open.hours}:${nonNormal.open.minutes} - ${nonNormal.close.hours}:${nonNormal.close.minutes}`);
136+
return nonNormal;
137+
}
108138
return this.restaurant.openingHours.find(oh => oh.day === today);
139+
},
140+
nonNormalOpeningHours() {
141+
const today = this.date.getDay();
142+
return this.restaurant.nonNormalOpeningHours?.find(oh => (new Date(oh.day)).getDay() === today);
109143
}
110144
},
111145
});

i18n.config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default defineI18nConfig(() => ({
2424
page: 'restaurant\'s own page',
2525
restaurantInfo: 'More information about the restaurant',
2626
openingHours: 'Opening hours',
27+
nonNormalOpeningHours: 'Non-normal opening hours',
2728
},
2829
filters: {
2930
filter: 'Filter',
@@ -46,6 +47,7 @@ export default defineI18nConfig(() => ({
4647
staff: 'Staff',
4748
other: 'Visitors',
4849
disclaimer: 'Prices may not be accurate, please check the restaurant\'s own page for the most up-to-date information',
50+
openingHoursDisclaimer: 'We use large language models to extract non-normal opening hours from restaurant websites. Our system has detected non-normal opening hours for this restaurant. We cannot guarantee the accuracy of this information. Please check the restaurant\'s own page for the most up-to-date information.',
4951
}
5052
},
5153
fi: {
@@ -70,6 +72,7 @@ export default defineI18nConfig(() => ({
7072
page: 'ravintolan omat sivut',
7173
restaurantInfo: 'Lisätietoja ravintolasta',
7274
openingHours: 'Aukioloajat',
75+
nonNormalOpeningHours: 'Ei-normaalit aukioloajat',
7376
},
7477
filters: {
7578
filter: 'Suodata',
@@ -92,6 +95,7 @@ export default defineI18nConfig(() => ({
9295
staff: 'Henkilökunta',
9396
other: 'Vieraat',
9497
disclaimer: 'Hinnoissa voi ilmetä virheitä, tarkista ravintolan omilta sivuilta ajantasaisin tieto',
98+
openingHoursDisclaimer: 'Käytämme suuria kielimalleja poimimaan poikkeavia aukioloaikoja ravintoloiden verkkosivuilta. Järjestelmämme on havainnut poikkeavia aukioloaikoja tälle ravintolalle. Emme voi taata tämän tiedon tarkkuutta. Tarkista ajantasaisin tieto ravintolan omilta sivuilta.',
9599
}
96100
}
97101
}

nuxt.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ export default defineNuxtConfig({
5151
'0 6,7,8,9 * * *': ['updateMenu'],
5252
// Run updatePrices every Monday at 08:00 (UTC)
5353
'0 8 * * 1': ['updatePrices'],
54+
// Run updateHours every other day at 10:00 (UTC)
55+
'0 10 */2 * *': ['updateHours'],
5456
}
5557
},
5658
runtimeConfig: {
5759
dbUrl: 'mongodb://127.0.0.1:27017',
5860
dbName: 'ou-lunch',
61+
heroCoreUrl: '127.0.0.1:1818',
5962
},
6063
ogImage: {
6164
enabled: false,

0 commit comments

Comments
 (0)