Skip to content

Commit

Permalink
Merge pull request #19 from filips123/fix-lunch-schedule-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
filips123 authored Mar 21, 2021
2 parents cc388aa + e454508 commit 3341722
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
40 changes: 21 additions & 19 deletions API/gimvicurnik/updaters/eclassroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,18 +512,19 @@ def _parse_daily_lunch_schedule(self, date, tables):
notes = notes if notes else None
last_notes = notes

class_ = row[2].strip()
classes = row[2].replace("(", "").replace(")", "").split(",")
location = row[4].strip()

schedule.append(
{
"class_id": get_or_create(self.session, model=Class, name=class_)[0].id,
"date": date,
"time": time,
"location": location,
"notes": notes,
}
)
for class_ in classes:
schedule.append(
{
"class_id": get_or_create(self.session, model=Class, name=class_.strip())[0].id,
"date": date,
"time": time,
"location": location,
"notes": notes,
}
)

# Store schedule in database
self.session.query(LunchSchedule).filter(LunchSchedule.date == date).delete()
Expand All @@ -547,17 +548,18 @@ def _parse_weekly_lunch_schedule(self, date, tables):
row = [a for b in row for a in b.split("\n")]

time = datetime.datetime.strptime(row[0].strip(), "%H:%M").time()
class_ = row[1].strip()
classes = row[1].replace("(", "").replace(")", "").split(",")
location = row[2].strip()

schedule.append(
{
"class_id": get_or_create(self.session, model=Class, name=class_)[0].id,
"date": date,
"time": time,
"location": location,
}
)
for class_ in classes:
schedule.append(
{
"class_id": get_or_create(self.session, model=Class, name=class_.strip())[0].id,
"date": date,
"time": time,
"location": location,
}
)

date += datetime.timedelta(days=1)

Expand Down
13 changes: 7 additions & 6 deletions website/src/components/menus/MenuDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
</v-card-text>

<v-card-text v-if="menu.lunch"
:class="{ 'pb-0': currentEntityValid && currentLunchSchedule, 'text--darken-4': !$vuetify.theme.dark, 'text--lighten-4': $vuetify.theme.dark }"
:class="{ 'pb-0': currentEntityValid && currentLunchSchedules, 'text--darken-4': !$vuetify.theme.dark, 'text--lighten-4': $vuetify.theme.dark }"
class="grey--text">
<h2 class="font-weight-regular pb-2">Kosilo</h2>
<p v-html=convertNewlines(menu.lunch[getLunchType()]) />
</v-card-text>

<v-card-text v-if="currentEntityValid && currentLunchSchedule"
<v-card-text v-if="currentEntityValid && currentLunchSchedules"
:class="{ 'text--darken-4': !$vuetify.theme.dark, 'text--lighten-4': $vuetify.theme.dark }"
class="grey--text pb-2">
<h2 class="font-weight-regular pb-2">Razpored kosila</h2>
<p>
<p v-for="currentLunchSchedule in currentLunchSchedules" :key="currentLunchSchedule.time">
Ura: {{ currentLunchSchedule.time }}<br />
Prostor: {{ currentLunchSchedule.location }}<br />
Opombe: {{ currentLunchSchedule.notes }}<br />
Expand All @@ -50,7 +50,7 @@ import { LunchSchedule, Menu } from '@/store/modules/storage'
@Component
export default class MenuDisplay extends Vue {
@Prop({ default: false }) mobile!: boolean
@Prop() date!: Date
@Prop() date!: string

@Prop() lunchSchedule!: LunchSchedule[]
@Prop() menu!: Menu
Expand All @@ -63,8 +63,9 @@ export default class MenuDisplay extends Vue {
return !!this.currentEntity && this.currentEntity.type === EntityType.Class
}

get currentLunchSchedule (): LunchSchedule | undefined {
return this.lunchSchedule.find(schedule => this.currentEntity?.data.includes(schedule.class))
get currentLunchSchedules (): LunchSchedule[] | null {
const lunchSchedules = this.lunchSchedule.filter(schedule => this.currentEntity?.data.includes(schedule.class))
return lunchSchedules.length ? lunchSchedules : null
}

formatDay (date: string): string {
Expand Down
3 changes: 2 additions & 1 deletion website/src/views/Menus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<v-row v-if="$root.$children[0].isMobile" class="menus" justify="center">
<v-tabs-items ref="tabs" v-model="currentDay" :touch="tabsItemsTouch">
<v-tab-item v-for="(dayName, dayIndex) in daysInWeek" :key="dayIndex">
<menu-display :date="documents[dayIndex].date"
<menu-display v-if="dayIndex in documents"
:date="documents[dayIndex].date"
:lunch-schedule="documents[dayIndex].lunchSchedule"
:menu="documents[dayIndex].menu"
class="ma-3"
Expand Down

0 comments on commit 3341722

Please sign in to comment.