fix(ui) AgendaView now shows correct events on small devices
This commit is contained in:
parent
38cc0d43d6
commit
c8ae458775
|
@ -27,7 +27,7 @@
|
||||||
<q-popup-proxy ref="proxy" transition-show="scale" transition-hide="scale">
|
<q-popup-proxy ref="proxy" transition-show="scale" transition-hide="scale">
|
||||||
<q-date
|
<q-date
|
||||||
ref="datepicker"
|
ref="datepicker"
|
||||||
:model-value="selectedDate"
|
:model-value="date(selectedDate)"
|
||||||
mask="YYYY-MM-DD"
|
mask="YYYY-MM-DD"
|
||||||
no-unset
|
no-unset
|
||||||
@update:model-value="updateDate"
|
@update:model-value="updateDate"
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<q-calendar-agenda
|
<q-calendar-agenda
|
||||||
v-model="selectedDate"
|
:model-value="date(realDate)"
|
||||||
:view="calendarRealView"
|
:view="calendarRealView"
|
||||||
:max-days="calendarDays"
|
:max-days="calendarDays"
|
||||||
:weekdays="[1, 2, 3, 4, 5, 6, 0]"
|
:weekdays="[1, 2, 3, 4, 5, 6, 0]"
|
||||||
|
@ -89,13 +89,14 @@
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ComponentPublicInstance, computed, defineComponent, onBeforeMount, ref } from 'vue';
|
import { ComponentPublicInstance, computed, defineComponent, onBeforeMount, ref } from 'vue';
|
||||||
import { useEventStore } from '../../store';
|
|
||||||
import EventSlot from './slots/EventSlot.vue';
|
|
||||||
import { date, QDate, QPopupProxy, useQuasar } from 'quasar';
|
|
||||||
import { startOfWeek } from '@flaschengeist/api';
|
|
||||||
import EditEvent from '../management/EditEvent.vue';
|
|
||||||
import { QCalendarAgenda } from '@quasar/quasar-ui-qcalendar';
|
import { QCalendarAgenda } from '@quasar/quasar-ui-qcalendar';
|
||||||
|
import { date, QDate, QPopupProxy, useQuasar } from 'quasar';
|
||||||
import { EditableEvent, emptyEvent } from '../../store/models';
|
import { EditableEvent, emptyEvent } from '../../store/models';
|
||||||
|
import { startOfWeek } from '@flaschengeist/api';
|
||||||
|
import { useEventStore } from '../../store';
|
||||||
|
|
||||||
|
import EventSlot from './slots/EventSlot.vue';
|
||||||
|
import EditEvent from '../management/EditEvent.vue';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'AgendaView',
|
name: 'AgendaView',
|
||||||
|
@ -108,13 +109,30 @@ export default defineComponent({
|
||||||
const datepicker = ref<QDate>();
|
const datepicker = ref<QDate>();
|
||||||
const proxy = ref<QPopupProxy>();
|
const proxy = ref<QPopupProxy>();
|
||||||
|
|
||||||
const selectedDate = ref(date.formatDate(new Date(), 'YYYY-MM-DD'));
|
// User selectable (day vs week)
|
||||||
const calendarView = ref('week');
|
const calendarView = ref('week');
|
||||||
|
// User selected date
|
||||||
|
const selectedDate = ref(date.buildDate({ hours: 0, minutes: 0, seconds: 0, milliseconds: 0 }));
|
||||||
|
|
||||||
const calendarRealView = computed(() => (calendarDays.value != 7 ? 'day' : 'week'));
|
// Real view depending on the screen size
|
||||||
const calendarDays = computed(() =>
|
const calendarRealView = computed(() =>
|
||||||
calendarView.value == 'day' || quasar.screen.xs ? 1 : quasar.screen.sm ? 3 : 7
|
calendarView.value === 'day' || quasar.screen.xs || quasar.screen.sm ? 'day' : 'week'
|
||||||
);
|
);
|
||||||
|
const calendarDays = computed(() => {
|
||||||
|
if (calendarView.value == 'day' || quasar.screen.xs) return 1;
|
||||||
|
if (calendarRealView.value == 'week') return 7;
|
||||||
|
return realDate.value.getDay() === 1 ? 3 : 4;
|
||||||
|
});
|
||||||
|
|
||||||
|
const realDate = computed(() => {
|
||||||
|
if (calendarView.value === 'day' || calendarRealView.value === 'week' || quasar.screen.xs)
|
||||||
|
return selectedDate.value;
|
||||||
|
|
||||||
|
const start = startOfWeek(selectedDate.value);
|
||||||
|
if (selectedDate.value.getDay() > 0 && selectedDate.value.getDay() <= 3) return start;
|
||||||
|
else return date.addToDate(start, { days: 3 });
|
||||||
|
});
|
||||||
|
|
||||||
const events = ref<Agendas>({});
|
const events = ref<Agendas>({});
|
||||||
const editor = ref<EditableEvent>();
|
const editor = ref<EditableEvent>();
|
||||||
|
|
||||||
|
@ -154,17 +172,12 @@ export default defineComponent({
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadAgendas() {
|
async function loadAgendas() {
|
||||||
const selected = date.adjustDate(selectedDate.value, {
|
const from =
|
||||||
milliseconds: 0,
|
calendarView.value === 'day' ? selectedDate.value : startOfWeek(selectedDate.value);
|
||||||
seconds: 0,
|
const to = date.addToDate(from, { days: calendarView.value === 'day' ? 1 : 7 });
|
||||||
minutes: 0,
|
|
||||||
hours: 0,
|
|
||||||
});
|
|
||||||
const start = calendarView.value === 'day' ? selected : startOfWeek(selected);
|
|
||||||
const end = date.addToDate(start, { days: calendarDays.value });
|
|
||||||
|
|
||||||
events.value = {};
|
events.value = {};
|
||||||
const { result } = await store.getEvents({ from: start, to: end });
|
const { result } = await store.getEvents({ from, to });
|
||||||
result.forEach((event) => {
|
result.forEach((event) => {
|
||||||
const day = event.start.getDay();
|
const day = event.start.getDay();
|
||||||
|
|
||||||
|
@ -175,26 +188,17 @@ export default defineComponent({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function calendarNext() {
|
function addDays(reverse: boolean) {
|
||||||
selectedDate.value = date.formatDate(
|
const oww = Math.floor((startOfWeek(selectedDate.value).getTime() / 1000) * 60 * 60 * 24);
|
||||||
date.addToDate(selectedDate.value, { days: calendarDays.value }),
|
selectedDate.value = date.addToDate(realDate.value, {
|
||||||
'YYYY-MM-DD'
|
days: reverse ? -1 : calendarDays.value,
|
||||||
);
|
});
|
||||||
|
if (oww != Math.floor((startOfWeek(selectedDate.value).getTime() / 1000) * 60 * 60 * 24))
|
||||||
void loadAgendas();
|
void loadAgendas();
|
||||||
}
|
}
|
||||||
|
|
||||||
function calendarPrev() {
|
function asMonth(value?: Date) {
|
||||||
selectedDate.value = date.formatDate(
|
return [
|
||||||
date.subtractFromDate(selectedDate.value, { days: calendarDays.value }),
|
|
||||||
'YYYY-MM-DD'
|
|
||||||
);
|
|
||||||
void loadAgendas();
|
|
||||||
}
|
|
||||||
|
|
||||||
function asMonth(value: string) {
|
|
||||||
if (value) {
|
|
||||||
return date.formatDate(new Date(value), 'MMMM', {
|
|
||||||
months: [
|
|
||||||
'Januar',
|
'Januar',
|
||||||
'Februar',
|
'Februar',
|
||||||
'März',
|
'März',
|
||||||
|
@ -207,35 +211,39 @@ export default defineComponent({
|
||||||
'Oktober',
|
'Oktober',
|
||||||
'November',
|
'November',
|
||||||
'Dezember',
|
'Dezember',
|
||||||
],
|
'-',
|
||||||
});
|
][value?.getMonth() || 12];
|
||||||
}
|
|
||||||
}
|
|
||||||
function asYear(value: string) {
|
|
||||||
if (value) {
|
|
||||||
return date.formatDate(new Date(value), 'YYYY');
|
|
||||||
}
|
}
|
||||||
|
function asYear(value?: Date) {
|
||||||
|
return value?.getFullYear() || '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
asYear,
|
asYear,
|
||||||
asMonth,
|
asMonth,
|
||||||
calendarDays,
|
calendarDays,
|
||||||
calendarNext,
|
calendarNext: () => addDays(false),
|
||||||
calendarPrev,
|
calendarPrev: () => addDays(true),
|
||||||
calendarRealView,
|
calendarRealView,
|
||||||
calendarView,
|
calendarView,
|
||||||
create,
|
create,
|
||||||
|
date: (d: Date) => date.formatDate(d, 'YYYY-MM-DD'),
|
||||||
edit,
|
edit,
|
||||||
editor,
|
editor,
|
||||||
editDone,
|
editDone,
|
||||||
events,
|
events,
|
||||||
datepicker,
|
datepicker,
|
||||||
proxy,
|
proxy,
|
||||||
|
realDate,
|
||||||
remove,
|
remove,
|
||||||
selectedDate,
|
selectedDate,
|
||||||
updateDate: (ds: string) => {
|
updateDate: (ds: string) => {
|
||||||
selectedDate.value = ds;
|
selectedDate.value = date.adjustDate(date.extractDate(ds, 'YYYY-MM-DD'), {
|
||||||
|
hours: 0,
|
||||||
|
minutes: 0,
|
||||||
|
seconds: 0,
|
||||||
|
milliseconds: 0,
|
||||||
|
});
|
||||||
proxy.value?.hide();
|
proxy.value?.hide();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue