287 lines
6.3 KiB
Vue
287 lines
6.3 KiB
Vue
<script setup lang="ts">
|
||
|
||
import {onMounted, reactive, ref, watch} from "vue";
|
||
import Input from "@/components/Input.vue";
|
||
import {useRouter} from "vue-router";
|
||
|
||
const props = defineProps<{
|
||
groups: any[],
|
||
admin: boolean
|
||
}>()
|
||
|
||
const emit = defineEmits(["change", "new", "delete", "edit"])
|
||
const router = useRouter()
|
||
|
||
const prev = ref<number | null>(null)
|
||
const cur = ref(0)
|
||
const next = ref<number | null>(null)
|
||
|
||
const newPlan = reactive({
|
||
id: 0,
|
||
from: null,
|
||
to: null
|
||
})
|
||
|
||
// watch(props, (value, oldValue, onCleanup) => {
|
||
// setToCurrentDate()
|
||
// })
|
||
|
||
onMounted(() => {
|
||
setToCurrentDate()
|
||
})
|
||
|
||
function getGroups() {
|
||
if (newPlan.id != 0) {
|
||
return [newPlan].concat(props.groups)
|
||
} else {
|
||
return props.groups
|
||
}
|
||
}
|
||
|
||
function setToCurrentDate() {
|
||
const date = new Date().getTime()
|
||
let g = props.groups.findIndex(g => date >= g.from && date <= g.to)
|
||
if (g == -1) {
|
||
prev.value = 1;
|
||
cur.value = 0;
|
||
next.value = null
|
||
g = props.groups[0]
|
||
} else {
|
||
prev.value = g + 1
|
||
cur.value = g
|
||
next.value = g - 1
|
||
}
|
||
emit("change", get(cur.value)?.id ?? 0)
|
||
}
|
||
|
||
function forward() {
|
||
prev.value--;
|
||
cur.value--;
|
||
next.value--;
|
||
|
||
// emit("change", get(cur.value).id)
|
||
router.push("/" + get(cur.value).id)
|
||
}
|
||
|
||
function back() {
|
||
prev.value++;
|
||
cur.value++;
|
||
next.value++;
|
||
// emit("change", get(cur.value).id)
|
||
router.push("/" + get(cur.value).id)
|
||
}
|
||
|
||
function two(s) {
|
||
return (s < 10 ? "0" : "") + s
|
||
}
|
||
|
||
function formatDate(time) {
|
||
const date = new Date(time)
|
||
return two(date.getDate()) + ". " + getNameOfMonth(date.getMonth())
|
||
}
|
||
|
||
function formatDateShort(time) {
|
||
const date = new Date(time)
|
||
return two(date.getDate()) + "." + two(date.getMonth() + 1) + "."
|
||
}
|
||
|
||
function getNameOfMonth(month): string {
|
||
switch (month) {
|
||
case 0:
|
||
return "Januar";
|
||
case 1:
|
||
return "Februar";
|
||
case 2:
|
||
return "März";
|
||
case 3:
|
||
return "April";
|
||
case 4:
|
||
return "Mai";
|
||
case 5:
|
||
return "Juni";
|
||
case 6:
|
||
return "Juli";
|
||
case 7:
|
||
return "August";
|
||
case 8:
|
||
return "September";
|
||
case 9:
|
||
return "Oktober";
|
||
case 10:
|
||
return "November";
|
||
case 11:
|
||
return "Dezember";
|
||
}
|
||
return "?"
|
||
}
|
||
|
||
function get(i) {
|
||
if (i < 0) return null;
|
||
return getGroups()[i]
|
||
}
|
||
|
||
function index(id) {
|
||
return id
|
||
}
|
||
|
||
function dateToValueString(time) {
|
||
const date = new Date(time)
|
||
return date.getFullYear() + "-" + two(date.getMonth() + 1) + "-" + two(date.getDate())
|
||
}
|
||
|
||
</script>
|
||
|
||
<template>
|
||
<div class="bar">
|
||
<div class="top-row">
|
||
<button class="flat arrow" v-if="prev != null && prev <= groups.length - 1" @click="back">
|
||
<i>arrow_left_alt</i>
|
||
<span class="date-label">{{ formatDateShort(get(prev).from) }} - {{ formatDateShort(get(prev).to) }}</span>
|
||
</button>
|
||
<div v-else></div>
|
||
|
||
<div class="title">
|
||
<template v-if="groups.length > 0">
|
||
<span class="prefix">Miniplan vom</span>
|
||
{{ formatDate(get(cur).from) }} – {{ formatDate(get(cur).to) }}
|
||
</template>
|
||
<span v-else>Keine Gottesdienstgruppen vorhanden</span>
|
||
</div>
|
||
|
||
<button class="flat arrow" v-if="next != null && next > 0" @click="forward">
|
||
<span class="date-label">{{ formatDateShort(get(next).from) }} - {{ formatDateShort(get(next).to) }}</span>
|
||
<i>arrow_right_alt</i>
|
||
</button>
|
||
<div v-else></div>
|
||
</div>
|
||
|
||
<div class="admin-row" v-if="admin && groups.length > 0">
|
||
<button class="flat" @click="$emit('new')"><i>add</i> Neuer Plan</button>
|
||
<button class="flat icon" @click="$emit('delete', get(cur).id)"><i>delete</i></button>
|
||
<button class="flat icon" @click="$emit('edit', get(cur).id)"><i>edit</i></button>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<style scoped lang="less">
|
||
|
||
.bar {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
border-bottom: 1px solid #d7d5d5;
|
||
z-index: 10;
|
||
padding: 8px 12px;
|
||
gap: 6px;
|
||
|
||
.top-row {
|
||
display: grid;
|
||
align-items: center;
|
||
width: 100%;
|
||
gap: 6px;
|
||
grid-template-columns: 60px 1fr 60px;
|
||
}
|
||
|
||
.arrow {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
flex-shrink: 0;
|
||
padding: 6px 8px 6px 6px;
|
||
|
||
i {
|
||
font-size: 22px;
|
||
}
|
||
|
||
.date-label {
|
||
display: none;
|
||
}
|
||
}
|
||
|
||
.title {
|
||
flex: 1;
|
||
text-align: center;
|
||
font-weight: 700;
|
||
font-size: 14px;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
min-width: 0;
|
||
margin: 0 auto;
|
||
|
||
.prefix {
|
||
display: none;
|
||
}
|
||
}
|
||
|
||
.admin-row {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 6px;
|
||
width: 100%;
|
||
padding-top: 4px;
|
||
border-top: 1px solid #eee;
|
||
|
||
button {
|
||
font-size: 13px;
|
||
padding: 4px 10px 4px 6px;
|
||
|
||
i {
|
||
font-size: 18px;
|
||
margin-right: 4px;
|
||
}
|
||
|
||
&.icon {
|
||
padding: 4px 8px;
|
||
|
||
i {
|
||
margin-right: 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
@media(min-width: 800px) {
|
||
padding: 10px 16px;
|
||
gap: 0;
|
||
|
||
.top-row {
|
||
flex: 1;
|
||
gap: 10px;
|
||
grid-template-columns: 180px 1fr 180px;
|
||
}
|
||
|
||
.arrow {
|
||
padding: 6px 14px 6px 10px;
|
||
|
||
.date-label {
|
||
display: inline;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
white-space: nowrap;
|
||
}
|
||
}
|
||
|
||
.title {
|
||
font-size: 16px;
|
||
white-space: normal;
|
||
|
||
.prefix {
|
||
display: inline;
|
||
font-weight: 400;
|
||
color: #777;
|
||
}
|
||
}
|
||
|
||
.admin-row {
|
||
width: auto;
|
||
border-top: none;
|
||
padding-top: 0;
|
||
margin-left: 12px;
|
||
}
|
||
}
|
||
|
||
}
|
||
</style>
|