Neues Plugin IT-Service (OpenNIT); Abteilung bei „Geschrieben von“
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 4m42s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m41s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m32s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m30s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m35s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 4m42s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m41s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m32s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m30s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m35s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c713194a83
commit
c1117829c3
139 changed files with 2455 additions and 398 deletions
14
plugins-core/it-service/plugin.json
Normal file
14
plugins-core/it-service/plugin.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"slug": "it-service",
|
||||
"name": "IT-Service (OpenNIT)",
|
||||
"version": "1.0.0",
|
||||
"description": "IT-Self-Service über OpenNIT: eigene Geräte einsehen, Tickets zu Geräten oder allgemein erstellen, eigene Tickets verfolgen und beantworten, Leihgeräte anfragen und reservieren.",
|
||||
"author": "Inhaus",
|
||||
"namespace": "Inhaus\\Plugins\\ItService\\",
|
||||
"class": "Inhaus\\Plugins\\ItService\\ItServicePlugin",
|
||||
"enabled_by_default": false,
|
||||
"requires": {
|
||||
"core": ">=0.16.0",
|
||||
"php": ">=8.3"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
<script setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { ChevronLeft, ChevronRight } from '@lucide/vue';
|
||||
|
||||
/**
|
||||
* Zwei Monate zum Wählen eines Zeitraums; belegte Tage (slots) sind gesperrt.
|
||||
* v-model:start / v-model:end als „YYYY-MM-DD“.
|
||||
*/
|
||||
const props = defineProps({
|
||||
slots: { type: Array, default: () => [] },
|
||||
start: { type: String, default: '' },
|
||||
end: { type: String, default: '' },
|
||||
maxDays: { type: Number, default: 180 },
|
||||
});
|
||||
const emit = defineEmits(['update:start', 'update:end']);
|
||||
|
||||
const iso = (date) => `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
||||
const today = iso(new Date());
|
||||
const cursor = ref(new Date(new Date().getFullYear(), new Date().getMonth(), 1));
|
||||
|
||||
const booked = computed(() => {
|
||||
const days = new Set();
|
||||
|
||||
for (const slot of props.slots) {
|
||||
const day = new Date(`${slot.start}T12:00:00`);
|
||||
const last = new Date(`${slot.end || slot.start}T12:00:00`);
|
||||
|
||||
for (let i = 0; day <= last && i < 400; i++) {
|
||||
days.add(iso(day));
|
||||
day.setDate(day.getDate() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return days;
|
||||
});
|
||||
|
||||
const monthFormat = new Intl.DateTimeFormat('de-DE', { month: 'long', year: 'numeric' });
|
||||
const months = computed(() => [0, 1].map((offset) => {
|
||||
const first = new Date(cursor.value.getFullYear(), cursor.value.getMonth() + offset, 1);
|
||||
const days = [];
|
||||
const lead = (first.getDay() + 6) % 7; // Montag zuerst
|
||||
|
||||
for (let i = 0; i < lead; i++) days.push(null);
|
||||
|
||||
for (let d = 1; d <= new Date(first.getFullYear(), first.getMonth() + 1, 0).getDate(); d++) {
|
||||
days.push(iso(new Date(first.getFullYear(), first.getMonth(), d)));
|
||||
}
|
||||
|
||||
return { label: monthFormat.format(first), days };
|
||||
}));
|
||||
|
||||
function rangeFree(from, to) {
|
||||
for (const day of booked.value) {
|
||||
if (day >= from && day <= to) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function pick(day) {
|
||||
if (!day || day < today || booked.value.has(day)) return;
|
||||
|
||||
if (!props.start || props.end || day < props.start) {
|
||||
emit('update:start', day);
|
||||
emit('update:end', '');
|
||||
} else if (rangeFree(props.start, day)) {
|
||||
emit('update:end', day);
|
||||
} else {
|
||||
emit('update:start', day);
|
||||
emit('update:end', '');
|
||||
}
|
||||
}
|
||||
|
||||
function state(day) {
|
||||
if (!day) return 'empty';
|
||||
if (booked.value.has(day)) return 'booked';
|
||||
if (day < today) return 'past';
|
||||
if (day === props.start || day === props.end) return 'edge';
|
||||
if (props.start && props.end && day > props.start && day < props.end) return 'inside';
|
||||
|
||||
return 'free';
|
||||
}
|
||||
|
||||
const classes = {
|
||||
booked: 'bg-red-50 text-red-400 line-through cursor-not-allowed dark:bg-red-950/30',
|
||||
past: 'text-muted-foreground/40 cursor-not-allowed',
|
||||
edge: 'bg-brand text-brand-foreground font-semibold',
|
||||
inside: 'bg-brand-soft text-brand-soft-foreground',
|
||||
free: 'hover:bg-accent',
|
||||
empty: '',
|
||||
};
|
||||
|
||||
function shift(step) {
|
||||
cursor.value = new Date(cursor.value.getFullYear(), cursor.value.getMonth() + step, 1);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
<button type="button" class="grid size-8 place-items-center rounded-md hover:bg-accent" aria-label="Früher" @click="shift(-1)"><ChevronLeft class="size-4" /></button>
|
||||
<span class="text-xs text-muted-foreground">Beginn und Ende anklicken</span>
|
||||
<button type="button" class="grid size-8 place-items-center rounded-md hover:bg-accent" aria-label="Später" @click="shift(1)"><ChevronRight class="size-4" /></button>
|
||||
</div>
|
||||
<div class="grid gap-4 sm:grid-cols-2">
|
||||
<div v-for="month in months" :key="month.label">
|
||||
<p class="mb-1.5 text-center text-sm font-medium">{{ month.label }}</p>
|
||||
<div class="grid grid-cols-7 gap-0.5 text-center text-xs">
|
||||
<span v-for="w in ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']" :key="w" class="py-1 text-muted-foreground">{{ w }}</span>
|
||||
<button
|
||||
v-for="(day, i) in month.days"
|
||||
:key="day ?? `e${i}`"
|
||||
type="button"
|
||||
class="aspect-square rounded-md tabular-nums transition-colors"
|
||||
:class="classes[state(day)]"
|
||||
:disabled="!day || state(day) === 'booked' || state(day) === 'past'"
|
||||
:title="state(day) === 'booked' ? 'Belegt' : undefined"
|
||||
@click="pick(day)"
|
||||
>
|
||||
{{ day ? Number(day.slice(8)) : '' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="mt-2 flex items-center gap-3 text-[11px] text-muted-foreground">
|
||||
<span class="inline-flex items-center gap-1"><span class="size-2.5 rounded-sm bg-red-100 dark:bg-red-950" /> belegt</span>
|
||||
<span class="inline-flex items-center gap-1"><span class="size-2.5 rounded-sm bg-brand" /> Ihr Zeitraum</span>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
label: { type: String, required: true },
|
||||
tone: { type: String, default: 'neutral' }, // open | progress | waiting | done | neutral
|
||||
});
|
||||
|
||||
const classes = computed(() => ({
|
||||
open: 'bg-sky-100 text-sky-800 dark:bg-sky-900/50 dark:text-sky-200',
|
||||
progress: 'bg-amber-100 text-amber-800 dark:bg-amber-900/50 dark:text-amber-200',
|
||||
waiting: 'bg-violet-100 text-violet-800 dark:bg-violet-900/50 dark:text-violet-200',
|
||||
done: 'bg-emerald-100 text-emerald-800 dark:bg-emerald-900/50 dark:text-emerald-200',
|
||||
neutral: 'bg-muted text-muted-foreground',
|
||||
})[props.tone]);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span class="inline-flex shrink-0 items-center rounded-full px-2 py-0.5 text-[11px] font-semibold whitespace-nowrap" :class="classes">{{ label }}</span>
|
||||
</template>
|
||||
149
plugins-core/it-service/resources/js/pages/Index.vue
Normal file
149
plugins-core/it-service/resources/js/pages/Index.vue
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
<script setup>
|
||||
import { watch } from 'vue';
|
||||
import { Deferred, Link, router, usePage } from '@inertiajs/vue3';
|
||||
import { CalendarClock, CircleAlert, Laptop, LifeBuoy, MessageSquarePlus, Plug, ShieldCheck, TicketCheck, X } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import EmptyState from '@/components/EmptyState.vue';
|
||||
import PageHeader from '@/components/PageHeader.vue';
|
||||
import Panel from '@/components/Panel.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import StatusBadge from '../components/StatusBadge.vue';
|
||||
import { formatDate, loanTone, ticketTone } from '../status';
|
||||
|
||||
defineProps({
|
||||
configured: { type: Boolean, default: false },
|
||||
intro: { type: String, default: null },
|
||||
assets: { type: Object, default: null },
|
||||
tickets: { type: Object, default: null },
|
||||
loans: { type: Object, default: null },
|
||||
});
|
||||
|
||||
const page = usePage();
|
||||
watch(() => page.props.flash.status, (status) => status && toast.success(status), { immediate: true });
|
||||
watch(() => page.props.errors?.loan, (error) => error && toast.error(error));
|
||||
|
||||
function warranty(asset) {
|
||||
if (!asset.warranty_end) return null;
|
||||
const end = new Date(asset.warranty_end);
|
||||
const days = Math.round((end - new Date()) / 86_400_000);
|
||||
|
||||
if (Number.isNaN(days)) return { text: `Garantie bis ${asset.warranty_end}`, tone: '' };
|
||||
if (days < 0) return { text: `Garantie abgelaufen (${formatDate(asset.warranty_end)})`, tone: 'text-muted-foreground' };
|
||||
if (days < 90) return { text: `Garantie endet am ${formatDate(asset.warranty_end)}`, tone: 'text-amber-700 dark:text-amber-300' };
|
||||
|
||||
return { text: `Garantie bis ${formatDate(asset.warranty_end)}`, tone: 'text-muted-foreground' };
|
||||
}
|
||||
|
||||
function cancel(loan) {
|
||||
if (window.confirm(`Ausleihe „${loan.device}“ stornieren?`)) {
|
||||
router.post(`/it-service/ausleihen/${loan.id}/stornieren`, {}, { preserveScroll: true });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout title="Meine IT">
|
||||
<PageHeader title="Meine IT" description="Ihre Geräte, Tickets und Leihgeräte an einem Ort.">
|
||||
<template v-if="configured" #actions>
|
||||
<Button variant="outline" as-child><Link href="/it-service/leihgeraete"><CalendarClock /> Leihgerät ausleihen</Link></Button>
|
||||
<Button as-child><Link href="/it-service/tickets/neu"><MessageSquarePlus /> Ticket erstellen</Link></Button>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<div v-if="!configured" class="rounded-lg border bg-card">
|
||||
<EmptyState :icon="Plug" title="Der IT-Service ist noch nicht eingerichtet" text="Die Administration verbindet das Portal unter „Portal → IT-Service“ mit OpenNIT." />
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div v-if="intro" class="prose prose-sm mb-6 max-w-none rounded-lg border border-brand-200 bg-brand-soft/60 px-5 py-4 dark:prose-invert" v-html="intro" />
|
||||
|
||||
<div class="grid grid-cols-1 gap-6 lg:grid-cols-12">
|
||||
<!-- Tickets -->
|
||||
<Panel title="Meine Tickets" class="min-w-0 lg:col-span-7 xl:col-span-8">
|
||||
<Deferred data="tickets">
|
||||
<template #fallback>
|
||||
<div class="grid gap-2"><Skeleton v-for="n in 4" :key="n" class="h-14" /></div>
|
||||
</template>
|
||||
<p v-if="!tickets.ok" class="flex items-center gap-2 text-sm text-destructive"><CircleAlert class="size-4" /> {{ tickets.error }}</p>
|
||||
<EmptyState v-else-if="!tickets.data.length" :icon="TicketCheck" title="Keine Tickets" text="Wenn etwas nicht funktioniert: „Ticket erstellen“ – die IT kümmert sich darum." />
|
||||
<ul v-else class="-mx-2 divide-y">
|
||||
<li v-for="ticket in tickets.data" :key="ticket.id">
|
||||
<Link :href="`/it-service/tickets/${ticket.id}`" class="flex items-center gap-3 rounded-md px-2 py-3 hover:bg-accent/60">
|
||||
<span class="grid size-9 shrink-0 place-items-center rounded-md" :class="ticket.open ? 'bg-brand-soft text-brand-text' : 'bg-muted text-muted-foreground'">
|
||||
<LifeBuoy class="size-4" />
|
||||
</span>
|
||||
<span class="min-w-0 flex-1">
|
||||
<span class="block truncate text-sm font-medium" :class="{ 'text-muted-foreground': !ticket.open }">{{ ticket.subject }}</span>
|
||||
<span class="block text-xs text-muted-foreground">
|
||||
<template v-if="ticket.number">#{{ ticket.number }} · </template>erstellt {{ formatDate(ticket.created_at, true) }}
|
||||
</span>
|
||||
</span>
|
||||
<StatusBadge :label="ticket.status_label" :tone="ticketTone(ticket)" />
|
||||
</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</Deferred>
|
||||
</Panel>
|
||||
|
||||
<div class="grid content-start gap-6 lg:col-span-5 xl:col-span-4">
|
||||
<!-- Geräte -->
|
||||
<Panel title="Meine Geräte">
|
||||
<Deferred data="assets">
|
||||
<template #fallback>
|
||||
<div class="grid gap-2"><Skeleton v-for="n in 2" :key="n" class="h-20" /></div>
|
||||
</template>
|
||||
<p v-if="!assets.ok" class="flex items-center gap-2 text-sm text-destructive"><CircleAlert class="size-4" /> {{ assets.error }}</p>
|
||||
<p v-else-if="!assets.data.length" class="text-[13px] text-muted-foreground">Ihnen sind keine Geräte zugeordnet.</p>
|
||||
<ul v-else class="grid gap-3">
|
||||
<li v-for="asset in assets.data" :key="asset.id" class="rounded-lg border p-3">
|
||||
<div class="flex items-start gap-3">
|
||||
<span class="grid size-10 shrink-0 place-items-center rounded-md bg-muted text-foreground/70"><Laptop class="size-5" /></span>
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="font-medium leading-tight">{{ asset.name }}</p>
|
||||
<p class="mt-0.5 text-xs text-muted-foreground">
|
||||
{{ [asset.type, asset.manufacturer && asset.model ? `${asset.manufacturer} ${asset.model}` : asset.model].filter(Boolean).join(' · ') }}
|
||||
</p>
|
||||
<dl class="mt-2 grid gap-0.5 text-xs">
|
||||
<div v-if="asset.inventory" class="flex gap-1.5"><dt class="text-muted-foreground">Inventar-Nr.</dt><dd class="font-mono">{{ asset.inventory }}</dd></div>
|
||||
<div v-if="asset.serial" class="flex gap-1.5"><dt class="text-muted-foreground">Seriennummer</dt><dd class="font-mono">{{ asset.serial }}</dd></div>
|
||||
<div v-if="warranty(asset)" class="flex items-center gap-1.5" :class="warranty(asset).tone"><ShieldCheck class="size-3.5" /> {{ warranty(asset).text }}</div>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" class="mt-3 w-full" as-child>
|
||||
<Link :href="`/it-service/tickets/neu?geraet=${asset.id}`"><MessageSquarePlus /> Problem mit diesem Gerät melden</Link>
|
||||
</Button>
|
||||
</li>
|
||||
</ul>
|
||||
</Deferred>
|
||||
</Panel>
|
||||
|
||||
<!-- Ausleihen -->
|
||||
<Panel title="Meine Ausleihen" action-label="Leihgeräte" action-href="/it-service/leihgeraete">
|
||||
<Deferred data="loans">
|
||||
<template #fallback>
|
||||
<div class="grid gap-2"><Skeleton v-for="n in 2" :key="n" class="h-12" /></div>
|
||||
</template>
|
||||
<p v-if="!loans.ok" class="flex items-center gap-2 text-sm text-destructive"><CircleAlert class="size-4" /> {{ loans.error }}</p>
|
||||
<p v-else-if="!loans.data.length" class="text-[13px] text-muted-foreground">Keine laufenden Ausleihen oder Anfragen.</p>
|
||||
<ul v-else class="-mx-1 divide-y">
|
||||
<li v-for="loan in loans.data" :key="loan.id" class="flex items-center gap-3 px-1 py-2.5">
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="truncate text-sm font-medium">{{ loan.device }}</p>
|
||||
<p class="text-xs text-muted-foreground tabular-nums">{{ formatDate(loan.start) }} – {{ formatDate(loan.end) }}</p>
|
||||
</div>
|
||||
<StatusBadge :label="loan.status_label" :tone="loanTone(loan)" />
|
||||
<button v-if="loan.cancellable" type="button" class="grid size-7 place-items-center rounded-md text-muted-foreground hover:bg-accent hover:text-destructive" :title="`„${loan.device}“ stornieren`" @click="cancel(loan)">
|
||||
<X class="size-4" />
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</Deferred>
|
||||
</Panel>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</AppLayout>
|
||||
</template>
|
||||
139
plugins-core/it-service/resources/js/pages/Loans.vue
Normal file
139
plugins-core/it-service/resources/js/pages/Loans.vue
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
<script setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Link, router, useForm } from '@inertiajs/vue3';
|
||||
import { ArrowLeft, CalendarClock, CircleAlert, LoaderCircle, MonitorSmartphone, Send } from '@lucide/vue';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import EmptyState from '@/components/EmptyState.vue';
|
||||
import FormField from '@/components/FormField.vue';
|
||||
import NativeSelect from '@/components/NativeSelect.vue';
|
||||
import PageHeader from '@/components/PageHeader.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import { http } from '@/lib/http';
|
||||
import RangeCalendar from '../components/RangeCalendar.vue';
|
||||
import { formatDate } from '../status';
|
||||
|
||||
const props = defineProps({
|
||||
filters: { type: Object, required: true },
|
||||
types: { type: Object, required: true },
|
||||
devices: { type: Object, required: true },
|
||||
});
|
||||
|
||||
const filter = ref({ typ: props.filters.type ?? '', von: props.filters.from ?? '', bis: props.filters.to ?? '' });
|
||||
const typeOptions = computed(() => (props.types.ok ? props.types.data.map((t) => ({ value: t, label: t })) : []));
|
||||
|
||||
watch(filter, (value) => {
|
||||
const query = Object.fromEntries(Object.entries(value).filter(([, v]) => v));
|
||||
router.get('/it-service/leihgeraete', query, { preserveState: true, preserveScroll: true, replace: true });
|
||||
}, { deep: true });
|
||||
|
||||
// Anfrage-Dialog
|
||||
const device = ref(null);
|
||||
const slots = ref([]);
|
||||
const slotsError = ref(null);
|
||||
const loadingSlots = ref(false);
|
||||
const form = useForm({ device_id: null, planned_start: '', planned_end: '', purpose: '' });
|
||||
|
||||
async function open(item) {
|
||||
device.value = item;
|
||||
form.reset();
|
||||
form.clearErrors();
|
||||
form.device_id = item.id;
|
||||
form.planned_start = props.filters.from ?? '';
|
||||
form.planned_end = props.filters.to ?? '';
|
||||
slots.value = [];
|
||||
slotsError.value = null;
|
||||
loadingSlots.value = true;
|
||||
|
||||
try {
|
||||
slots.value = (await http.get(`/it-service/leihgeraete/${item.id}/belegung`)).slots;
|
||||
} catch (error) {
|
||||
slotsError.value = error.message;
|
||||
} finally {
|
||||
loadingSlots.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function submit() {
|
||||
form.post('/it-service/leihgeraete/anfragen', { onSuccess: () => (device.value = null) });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout title="Leihgeräte">
|
||||
<Link href="/it-service" class="mb-3 inline-flex items-center gap-1.5 text-sm font-medium text-muted-foreground hover:text-foreground"><ArrowLeft class="size-4" /> Meine IT</Link>
|
||||
<PageHeader title="Leihgeräte" description="Laptops, Beamer, Kameras & Co. für einen bestimmten Zeitraum ausleihen." />
|
||||
|
||||
<div class="mb-6 grid gap-3 rounded-lg border bg-card p-4 sm:grid-cols-3">
|
||||
<FormField id="type" label="Gerätetyp">
|
||||
<NativeSelect id="type" v-model="filter.typ" :options="typeOptions" placeholder="Alle Typen" />
|
||||
</FormField>
|
||||
<FormField id="from" label="Benötigt ab">
|
||||
<Input id="from" v-model="filter.von" type="date" />
|
||||
</FormField>
|
||||
<FormField id="to" label="Benötigt bis">
|
||||
<Input id="to" v-model="filter.bis" type="date" :min="filter.von || undefined" />
|
||||
</FormField>
|
||||
</div>
|
||||
|
||||
<p v-if="!devices.ok" class="flex items-center gap-2 rounded-lg border bg-card p-4 text-sm text-destructive"><CircleAlert class="size-4" /> {{ devices.error }}</p>
|
||||
<div v-else-if="!devices.data.length" class="rounded-lg border bg-card">
|
||||
<EmptyState :icon="MonitorSmartphone" title="Keine passenden Leihgeräte" text="Anderen Zeitraum oder Gerätetyp versuchen." />
|
||||
</div>
|
||||
<div v-else class="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
|
||||
<article v-for="item in devices.data" :key="item.id" class="flex flex-col rounded-lg border bg-card p-4">
|
||||
<div class="flex items-start gap-3">
|
||||
<span class="grid size-10 shrink-0 place-items-center rounded-md bg-muted text-foreground/70"><MonitorSmartphone class="size-5" /></span>
|
||||
<div class="min-w-0 flex-1">
|
||||
<h2 class="font-medium leading-tight">{{ item.title }}</h2>
|
||||
<p v-if="item.type" class="text-xs text-muted-foreground">{{ item.type }}</p>
|
||||
</div>
|
||||
<span
|
||||
class="rounded-full px-2 py-0.5 text-[11px] font-semibold"
|
||||
:class="item.available ? 'bg-emerald-100 text-emerald-800 dark:bg-emerald-900/50 dark:text-emerald-200' : 'bg-muted text-muted-foreground'"
|
||||
>
|
||||
{{ item.available ? 'verfügbar' : 'belegt' }}
|
||||
</span>
|
||||
</div>
|
||||
<p v-if="item.description" class="mt-3 line-clamp-3 text-[13px] text-muted-foreground">{{ item.description }}</p>
|
||||
<Button class="mt-4" variant="outline" @click="open(item)"><CalendarClock /> Zeitraum wählen</Button>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<Dialog :open="!!device" @update:open="(v) => !v && (device = null)">
|
||||
<DialogContent class="sm:max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ device?.title }} ausleihen</DialogTitle>
|
||||
<DialogDescription>Die IT bestätigt die Anfrage bzw. organisiert die Übergabe.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form class="grid gap-4" @submit.prevent="submit">
|
||||
<div v-if="loadingSlots" class="grid h-64 place-items-center text-sm text-muted-foreground"><LoaderCircle class="size-5 animate-spin" /></div>
|
||||
<template v-else>
|
||||
<p v-if="slotsError" class="text-xs text-muted-foreground">Belegung konnte nicht geladen werden – bitte Zeitraum trotzdem wählen.</p>
|
||||
<RangeCalendar v-model:start="form.planned_start" v-model:end="form.planned_end" :slots="slots" />
|
||||
</template>
|
||||
<div class="grid gap-3 sm:grid-cols-2">
|
||||
<FormField id="start" label="Von" :error="form.errors.planned_start">
|
||||
<Input id="start" v-model="form.planned_start" type="date" required />
|
||||
</FormField>
|
||||
<FormField id="end" label="Bis" :error="form.errors.planned_end">
|
||||
<Input id="end" v-model="form.planned_end" type="date" :min="form.planned_start || undefined" required />
|
||||
</FormField>
|
||||
</div>
|
||||
<FormField id="purpose" label="Wofür? (optional)" :error="form.errors.purpose">
|
||||
<Textarea id="purpose" v-model="form.purpose" rows="2" maxlength="500" placeholder="z. B. Präsentation beim Fachtag" />
|
||||
</FormField>
|
||||
<DialogFooter>
|
||||
<p v-if="form.planned_start && form.planned_end" class="mr-auto self-center text-[13px] text-muted-foreground">{{ formatDate(form.planned_start) }} – {{ formatDate(form.planned_end) }}</p>
|
||||
<Button type="button" variant="outline" @click="device = null">Abbrechen</Button>
|
||||
<Button type="submit" :disabled="form.processing || !form.planned_start || !form.planned_end">
|
||||
<LoaderCircle v-if="form.processing" class="animate-spin" /><Send v-else /> Anfragen
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</AppLayout>
|
||||
</template>
|
||||
103
plugins-core/it-service/resources/js/pages/Ticket.vue
Normal file
103
plugins-core/it-service/resources/js/pages/Ticket.vue
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
<script setup>
|
||||
import { watch } from 'vue';
|
||||
import { Link, useForm, usePage } from '@inertiajs/vue3';
|
||||
import { ArrowLeft, Headset, Laptop, LoaderCircle, MapPin, Paperclip, Send, Tag, UserRound } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import StatusBadge from '../components/StatusBadge.vue';
|
||||
import { formatDate, ticketTone } from '../status';
|
||||
|
||||
const props = defineProps({
|
||||
ticket: { type: Object, required: true },
|
||||
});
|
||||
|
||||
const page = usePage();
|
||||
const me = page.props.auth?.user;
|
||||
watch(() => page.props.flash.status, (status) => status && toast.success(status), { immediate: true });
|
||||
|
||||
const form = useForm({ message: '' });
|
||||
|
||||
function send() {
|
||||
form.post(`/it-service/tickets/${props.ticket.id}/antworten`, { preserveScroll: true, onSuccess: () => form.reset() });
|
||||
}
|
||||
|
||||
const size = (bytes) => (bytes ? (bytes > 1_048_576 ? `${(bytes / 1_048_576).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`) : '');
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout :title="ticket.subject">
|
||||
<Link href="/it-service" class="mb-3 inline-flex items-center gap-1.5 text-sm font-medium text-muted-foreground hover:text-foreground"><ArrowLeft class="size-4" /> Meine IT</Link>
|
||||
|
||||
<div class="grid grid-cols-1 items-start gap-6 lg:grid-cols-12">
|
||||
<div class="grid min-w-0 grid-cols-1 gap-6 lg:col-span-8">
|
||||
<!-- Ticket -->
|
||||
<article class="rounded-xl border bg-card p-6 shadow-xs">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<p class="text-xs font-medium text-muted-foreground"><template v-if="ticket.number">Ticket #{{ ticket.number }} · </template>erstellt {{ formatDate(ticket.created_at, true) }}</p>
|
||||
<h1 class="mt-1 text-2xl font-semibold tracking-tight text-balance">{{ ticket.subject }}</h1>
|
||||
</div>
|
||||
<StatusBadge :label="ticket.status_label" :tone="ticketTone(ticket)" class="text-xs" />
|
||||
</div>
|
||||
<p v-if="ticket.description" class="mt-5 text-[15px] leading-relaxed whitespace-pre-line">{{ ticket.description }}</p>
|
||||
</article>
|
||||
|
||||
<!-- Verlauf -->
|
||||
<section v-if="ticket.replies.length" aria-label="Verlauf" class="grid gap-4">
|
||||
<div v-for="(reply, index) in ticket.replies" :key="index" class="flex gap-3" :class="reply.from_staff ? '' : 'flex-row-reverse'">
|
||||
<span v-if="reply.from_staff" class="grid size-9 shrink-0 place-items-center rounded-full bg-brand text-brand-foreground"><Headset class="size-4" /></span>
|
||||
<PersonAvatar v-else-if="me" :person="me" class="size-9" />
|
||||
<span v-else class="grid size-9 shrink-0 place-items-center rounded-full bg-muted"><UserRound class="size-4" /></span>
|
||||
<div class="max-w-[85%] rounded-xl border px-4 py-3" :class="reply.from_staff ? 'bg-card' : 'border-brand-200 bg-brand-soft/60'">
|
||||
<p class="mb-1 text-xs text-muted-foreground">
|
||||
<span class="font-medium text-foreground">{{ reply.from_staff ? reply.author || 'IT-Service' : 'Sie' }}</span>
|
||||
<template v-if="reply.created_at"> · {{ formatDate(reply.created_at, true) }}</template>
|
||||
</p>
|
||||
<p class="text-sm leading-relaxed whitespace-pre-line">{{ reply.message }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Antworten -->
|
||||
<form class="rounded-xl border bg-card p-4 shadow-xs" @submit.prevent="send">
|
||||
<label for="message" class="text-sm font-medium">{{ ticket.open ? 'Antworten' : 'Das Ticket ist abgeschlossen – mit einer Antwort können Sie sich erneut melden.' }}</label>
|
||||
<Textarea id="message" v-model="form.message" rows="4" maxlength="20000" class="mt-2" placeholder="Ihre Nachricht an die IT …" />
|
||||
<p v-if="form.errors.message" class="mt-1 text-[13px] text-destructive">{{ form.errors.message }}</p>
|
||||
<div class="mt-3 flex justify-end">
|
||||
<Button type="submit" :disabled="form.processing || !form.message.trim()">
|
||||
<LoaderCircle v-if="form.processing" class="animate-spin" /><Send v-else /> Senden
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<aside class="grid content-start gap-4 lg:col-span-4">
|
||||
<section class="rounded-xl border bg-card p-5 shadow-xs">
|
||||
<h2 class="mb-3 text-xs font-semibold tracking-wider text-muted-foreground uppercase">Details</h2>
|
||||
<dl class="grid gap-2.5 text-sm">
|
||||
<div v-if="ticket.asset" class="flex items-center gap-2"><Laptop class="size-4 text-muted-foreground" /><dt class="sr-only">Gerät</dt><dd>{{ ticket.asset }}</dd></div>
|
||||
<div v-if="ticket.category" class="flex items-center gap-2"><Tag class="size-4 text-muted-foreground" /><dt class="sr-only">Kategorie</dt><dd>{{ ticket.category }}</dd></div>
|
||||
<div v-if="ticket.location" class="flex items-center gap-2"><MapPin class="size-4 text-muted-foreground" /><dt class="sr-only">Standort</dt><dd>{{ ticket.location }}</dd></div>
|
||||
<div class="flex items-center gap-2"><Headset class="size-4 text-muted-foreground" /><dt class="sr-only">Bearbeitet von</dt><dd>{{ ticket.assignees.length ? ticket.assignees.join(', ') : 'Noch nicht zugewiesen' }}</dd></div>
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section v-if="ticket.attachments.length" class="rounded-xl border bg-card p-5 shadow-xs">
|
||||
<h2 class="mb-3 text-xs font-semibold tracking-wider text-muted-foreground uppercase">Anhänge</h2>
|
||||
<ul class="grid gap-1">
|
||||
<li v-for="file in ticket.attachments" :key="file.id">
|
||||
<a :href="`/it-service/anhaenge/${file.id}`" class="flex items-center gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-accent">
|
||||
<Paperclip class="size-4 text-muted-foreground" />
|
||||
<span class="min-w-0 flex-1 truncate">{{ file.name }}</span>
|
||||
<span class="text-xs text-muted-foreground">{{ size(file.size) }}</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</aside>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
103
plugins-core/it-service/resources/js/pages/TicketCreate.vue
Normal file
103
plugins-core/it-service/resources/js/pages/TicketCreate.vue
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { Link, useForm } from '@inertiajs/vue3';
|
||||
import { ArrowLeft, CircleAlert, HelpCircle, Laptop, LoaderCircle, Send } from '@lucide/vue';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import FormField from '@/components/FormField.vue';
|
||||
import NativeSelect from '@/components/NativeSelect.vue';
|
||||
import PageHeader from '@/components/PageHeader.vue';
|
||||
import Panel from '@/components/Panel.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
|
||||
const props = defineProps({
|
||||
assetId: { type: Number, default: null },
|
||||
assets: { type: Object, required: true },
|
||||
options: { type: Object, required: true },
|
||||
});
|
||||
|
||||
const myAssets = computed(() => (props.assets.ok ? props.assets.data : []));
|
||||
const categories = computed(() => (props.options.ok ? props.options.data.categories : []));
|
||||
const locations = computed(() => (props.options.ok ? props.options.data.locations : []));
|
||||
|
||||
const form = useForm({
|
||||
asset_id: myAssets.value.some((a) => a.id === props.assetId) ? props.assetId : null,
|
||||
subject: '',
|
||||
description: '',
|
||||
category_id: null,
|
||||
location_id: null,
|
||||
});
|
||||
|
||||
function submit() {
|
||||
form.transform((data) => ({
|
||||
...data,
|
||||
asset_id: data.asset_id || null,
|
||||
category_id: data.category_id ? Number(data.category_id) : null,
|
||||
location_id: data.location_id ? Number(data.location_id) : null,
|
||||
})).post('/it-service/tickets');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout title="Ticket erstellen">
|
||||
<Link href="/it-service" class="mb-3 inline-flex items-center gap-1.5 text-sm font-medium text-muted-foreground hover:text-foreground"><ArrowLeft class="size-4" /> Meine IT</Link>
|
||||
<PageHeader title="Ticket erstellen" description="Beschreiben Sie kurz, was nicht funktioniert – die IT meldet sich." />
|
||||
|
||||
<form class="grid grid-cols-1 items-start gap-6 lg:grid-cols-12" @submit.prevent="submit">
|
||||
<Panel title="Worum geht es?" class="lg:col-span-5 xl:col-span-4">
|
||||
<div class="grid gap-2" role="radiogroup" aria-label="Gerät">
|
||||
<label
|
||||
v-for="asset in myAssets"
|
||||
:key="asset.id"
|
||||
class="flex cursor-pointer items-center gap-3 rounded-lg border p-3 transition-colors"
|
||||
:class="form.asset_id === asset.id ? 'border-brand bg-brand-soft/60 ring-1 ring-brand' : 'hover:bg-accent/60'"
|
||||
>
|
||||
<input v-model="form.asset_id" type="radio" :value="asset.id" class="sr-only" />
|
||||
<span class="grid size-9 shrink-0 place-items-center rounded-md bg-muted text-foreground/70"><Laptop class="size-4" /></span>
|
||||
<span class="min-w-0">
|
||||
<span class="block text-sm font-medium">{{ asset.name }}</span>
|
||||
<span class="block truncate text-xs text-muted-foreground">{{ [asset.type, asset.serial && `SN ${asset.serial}`].filter(Boolean).join(' · ') }}</span>
|
||||
</span>
|
||||
</label>
|
||||
<label
|
||||
class="flex cursor-pointer items-center gap-3 rounded-lg border p-3 transition-colors"
|
||||
:class="!form.asset_id ? 'border-brand bg-brand-soft/60 ring-1 ring-brand' : 'hover:bg-accent/60'"
|
||||
>
|
||||
<input v-model="form.asset_id" type="radio" :value="null" class="sr-only" />
|
||||
<span class="grid size-9 shrink-0 place-items-center rounded-md bg-muted text-foreground/70"><HelpCircle class="size-4" /></span>
|
||||
<span>
|
||||
<span class="block text-sm font-medium">Allgemeines Anliegen</span>
|
||||
<span class="block text-xs text-muted-foreground">ohne bestimmtes Gerät, z. B. Zugang, Software, Frage</span>
|
||||
</span>
|
||||
</label>
|
||||
<p v-if="!assets.ok" class="flex items-center gap-2 text-xs text-muted-foreground"><CircleAlert class="size-3.5" /> Ihre Geräte konnten nicht geladen werden.</p>
|
||||
</div>
|
||||
</Panel>
|
||||
|
||||
<Panel title="Beschreibung" class="lg:col-span-7 xl:col-span-8">
|
||||
<div class="grid gap-4">
|
||||
<FormField id="subject" label="Betreff" :error="form.errors.subject">
|
||||
<Input id="subject" v-model="form.subject" maxlength="200" placeholder="z. B. Drucker im 2. OG druckt nicht" required />
|
||||
</FormField>
|
||||
<FormField id="description" label="Was ist passiert?" :error="form.errors.description" hint="Seit wann? Gibt es eine Fehlermeldung? Was haben Sie schon versucht?">
|
||||
<Textarea id="description" v-model="form.description" rows="7" maxlength="20000" required />
|
||||
</FormField>
|
||||
<div class="grid gap-4 sm:grid-cols-2">
|
||||
<FormField v-if="categories.length" id="category" label="Kategorie" :error="form.errors.category_id">
|
||||
<NativeSelect id="category" v-model="form.category_id" :options="categories" placeholder="– bitte wählen –" />
|
||||
</FormField>
|
||||
<FormField v-if="locations.length" id="location" label="Standort" :error="form.errors.location_id">
|
||||
<NativeSelect id="location" v-model="form.location_id" :options="locations" placeholder="– bitte wählen –" />
|
||||
</FormField>
|
||||
</div>
|
||||
<div class="flex justify-end border-t pt-4">
|
||||
<Button type="submit" :disabled="form.processing">
|
||||
<LoaderCircle v-if="form.processing" class="animate-spin" /><Send v-else /> Ticket absenden
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Panel>
|
||||
</form>
|
||||
</AppLayout>
|
||||
</template>
|
||||
25
plugins-core/it-service/resources/js/status.js
Normal file
25
plugins-core/it-service/resources/js/status.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/** Farbe der Status-Plakette zu Tickets und Ausleihen */
|
||||
export function ticketTone(ticket) {
|
||||
const status = (ticket.status || '').toLowerCase();
|
||||
|
||||
if (!ticket.open) return 'done';
|
||||
if (['in_progress', 'in_bearbeitung', 'assigned'].includes(status)) return 'progress';
|
||||
if (['pending', 'waiting', 'wartend', 'on_hold'].includes(status)) return 'waiting';
|
||||
|
||||
return 'open';
|
||||
}
|
||||
|
||||
export function loanTone(loan) {
|
||||
return { pending: 'waiting', reserved: 'open', active: 'progress', returned: 'done' }[loan.status] ?? 'neutral';
|
||||
}
|
||||
|
||||
const dateFormat = new Intl.DateTimeFormat('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' });
|
||||
const dateTimeFormat = new Intl.DateTimeFormat('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' });
|
||||
|
||||
/** Datumsangaben aus OpenNIT („2026-04-17 10:30“ oder ISO) lesbar machen */
|
||||
export function formatDate(value, withTime = false) {
|
||||
if (!value) return '';
|
||||
const date = new Date(String(value).replace(' ', 'T'));
|
||||
|
||||
return Number.isNaN(date.getTime()) ? String(value) : (withTime && /\d{2}:\d{2}/.test(value) ? dateTimeFormat : dateFormat).format(date);
|
||||
}
|
||||
53
plugins-core/it-service/resources/js/widgets/MyIt.vue
Normal file
53
plugins-core/it-service/resources/js/widgets/MyIt.vue
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<script setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { CalendarClock, LifeBuoy, MessageSquarePlus } from '@lucide/vue';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import Panel from '@/components/Panel.vue';
|
||||
import { http } from '@/lib/http';
|
||||
|
||||
/**
|
||||
* „Meine IT“ auf der Startseite. Lädt die Zahlen selbst nach, damit die Startseite
|
||||
* nicht auf OpenNIT warten muss.
|
||||
*/
|
||||
const data = ref(null);
|
||||
const failed = ref(false);
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
data.value = await http.get('/it-service/uebersicht');
|
||||
} catch {
|
||||
failed.value = true;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Panel title="Meine IT" action-label="Öffnen" action-href="/it-service">
|
||||
<div v-if="!data && !failed" class="grid grid-cols-2 gap-2"><Skeleton class="h-16" /><Skeleton class="h-16" /></div>
|
||||
<template v-else-if="data">
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<Link href="/it-service" class="rounded-md bg-muted px-3 py-2.5 hover:bg-brand-soft">
|
||||
<span class="block text-xl font-semibold tabular-nums">{{ data.open_tickets }}</span>
|
||||
<span class="flex items-center gap-1 text-xs text-muted-foreground"><LifeBuoy class="size-3.5" /> offene Tickets</span>
|
||||
</Link>
|
||||
<Link href="/it-service" class="rounded-md bg-muted px-3 py-2.5 hover:bg-brand-soft">
|
||||
<span class="block text-xl font-semibold tabular-nums">{{ data.loans }}</span>
|
||||
<span class="flex items-center gap-1 text-xs text-muted-foreground"><CalendarClock class="size-3.5" /> Ausleihen</span>
|
||||
</Link>
|
||||
</div>
|
||||
<ul v-if="data.latest.length" class="mt-3 grid gap-0.5">
|
||||
<li v-for="ticket in data.latest" :key="ticket.id">
|
||||
<Link :href="`/it-service/tickets/${ticket.id}`" class="flex items-center justify-between gap-2 rounded px-1 py-1 text-[13px] hover:bg-accent">
|
||||
<span class="truncate">{{ ticket.subject }}</span>
|
||||
<span class="shrink-0 text-[11px] text-muted-foreground">{{ ticket.status_label }}</span>
|
||||
</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
<p v-else class="text-[13px] text-muted-foreground">Der IT-Service ist gerade nicht erreichbar.</p>
|
||||
<Link href="/it-service/tickets/neu" class="mt-3 flex items-center gap-1.5 border-t pt-3 text-[13px] font-medium text-brand-text hover:underline">
|
||||
<MessageSquarePlus class="size-4" /> IT-Problem melden
|
||||
</Link>
|
||||
</Panel>
|
||||
</template>
|
||||
20
plugins-core/it-service/routes/web.php
Normal file
20
plugins-core/it-service/routes/web.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inhaus\Plugins\ItService\Http\Controllers\ItServiceController;
|
||||
|
||||
Route::middleware('auth')->prefix('it-service')->name('it-service.')->controller(ItServiceController::class)
|
||||
->where(['id' => '[0-9]+'])
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::get('/uebersicht', 'summary')->name('summary');
|
||||
Route::get('/tickets/neu', 'createTicket')->name('tickets.create');
|
||||
Route::post('/tickets', 'storeTicket')->name('tickets.store');
|
||||
Route::get('/tickets/{id}', 'ticket')->name('tickets.show');
|
||||
Route::post('/tickets/{id}/antworten', 'reply')->name('tickets.reply');
|
||||
Route::get('/anhaenge/{id}', 'attachment')->name('attachments.show');
|
||||
Route::get('/leihgeraete', 'loanDevices')->name('loans.devices');
|
||||
Route::get('/leihgeraete/{id}/belegung', 'slots')->name('loans.slots');
|
||||
Route::post('/leihgeraete/anfragen', 'requestLoan')->name('loans.request');
|
||||
Route::post('/ausleihen/{id}/stornieren', 'cancelLoan')->name('loans.cancel');
|
||||
});
|
||||
135
plugins-core/it-service/src/Filament/Pages/ItServiceSettings.php
Normal file
135
plugins-core/it-service/src/Filament/Pages/ItServiceSettings.php
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\ItService\Filament\Pages;
|
||||
|
||||
use App\Support\Audit;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Inhaus\Plugins\ItService\OpenNit\Client;
|
||||
use Inhaus\Plugins\ItService\OpenNit\OpenNitException;
|
||||
use Inhaus\Plugins\ItService\OpenNit\Settings;
|
||||
use UnitEnum;
|
||||
|
||||
class ItServiceSettings extends Page
|
||||
{
|
||||
protected string $view = 'filament.pages.settings-form';
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedLifebuoy;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Portal';
|
||||
|
||||
protected static ?int $navigationSort = 60;
|
||||
|
||||
protected static ?string $navigationLabel = 'IT-Service';
|
||||
|
||||
protected static ?string $title = 'IT-Service (OpenNIT)';
|
||||
|
||||
protected static ?string $slug = 'it-service';
|
||||
|
||||
/** @var array<string, mixed>|null */
|
||||
public ?array $data = [];
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('it-service.manage') ?? false;
|
||||
}
|
||||
|
||||
public function mount(Settings $settings): void
|
||||
{
|
||||
$this->form->fill([
|
||||
'url' => $settings->url(),
|
||||
'token' => null,
|
||||
'secret' => null,
|
||||
'auto_reserve' => match ($settings->autoReserve()) {
|
||||
true => 'yes', false => 'no', null => 'default'
|
||||
},
|
||||
'intro' => $settings->intro(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
$settings = app(Settings::class);
|
||||
|
||||
return $schema->statePath('data')->components([
|
||||
Section::make('Verbindung zu OpenNIT')
|
||||
->description('Token und Signing-Secret erzeugen Sie in OpenNIT unter /admin/api (Token-Verwaltung) mit den Scopes „tickets“, „assets“ und „loans“. Beide werden verschlüsselt gespeichert. Die Zuordnung zu Personen erfolgt über die E-Mail-Adresse im Portal.')
|
||||
->schema([
|
||||
TextInput::make('url')
|
||||
->label('API-Adresse')
|
||||
->placeholder('https://itdoku.example.de/api/ex')
|
||||
->url()
|
||||
->required()
|
||||
->regex('#^https://#i')
|
||||
->validationMessages(['regex' => 'Die API ist nur über HTTPS erreichbar.']),
|
||||
TextInput::make('token')
|
||||
->label('Token')
|
||||
->password()
|
||||
->revealable()
|
||||
->placeholder($settings->token() !== '' ? '•••••••• (gespeichert – leer lassen, um ihn zu behalten)' : '')
|
||||
->required(fn () => $settings->token() === ''),
|
||||
TextInput::make('secret')
|
||||
->label('Signing-Secret')
|
||||
->password()
|
||||
->revealable()
|
||||
->placeholder($settings->secret() !== '' ? '•••••••• (gespeichert – leer lassen, um es zu behalten)' : '')
|
||||
->required(fn () => $settings->secret() === ''),
|
||||
]),
|
||||
Section::make('Leihgeräte')
|
||||
->schema([
|
||||
Select::make('auto_reserve')
|
||||
->label('Anfragen aus dem Portal')
|
||||
->options([
|
||||
'default' => 'Wie in OpenNIT eingestellt',
|
||||
'no' => 'Immer als Anfrage – die IT bestätigt',
|
||||
'yes' => 'Sofort fest reservieren',
|
||||
])
|
||||
->selectablePlaceholder(false)
|
||||
->default('default'),
|
||||
]),
|
||||
Section::make('Hinweistext')
|
||||
->description('Erscheint oben auf „Meine IT“, z. B. Telefonnummer der IT-Hotline oder Servicezeiten.')
|
||||
->schema([
|
||||
RichEditor::make('intro')->hiddenLabel()->toolbarButtons([['bold', 'italic', 'link'], ['bulletList'], ['undo', 'redo']]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(Settings $settings): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
$settings->save($data);
|
||||
Audit::log('it-service.settings', ['url' => $settings->url()]);
|
||||
|
||||
Notification::make()->success()->title('IT-Service gespeichert')->send();
|
||||
$this->mount($settings);
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('test')
|
||||
->label('Verbindung testen')
|
||||
->icon(Heroicon::OutlinedSignal)
|
||||
->color('gray')
|
||||
->action(function (Client $client) {
|
||||
try {
|
||||
$categories = count((array) ($client->get('/ticket-categories')['categories'] ?? []));
|
||||
$types = count((array) ($client->get('/device-types')['types'] ?? []));
|
||||
Notification::make()->success()->title('Verbindung klappt')->body("{$categories} Ticket-Kategorien und {$types} Gerätetypen gefunden.")->send();
|
||||
} catch (OpenNitException $e) {
|
||||
Notification::make()->danger()->title('Keine Verbindung')->body($e->getMessage().($e->status ? " (HTTP {$e->status})" : ''))->persistent()->send();
|
||||
}
|
||||
}),
|
||||
Action::make('portal')->label('Meine IT ansehen')->icon(Heroicon::OutlinedEye)->color('gray')->url('/it-service')->openUrlInNewTab(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\ItService\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\RichText;
|
||||
use Closure;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\ItService\ItService;
|
||||
use Inhaus\Plugins\ItService\OpenNit\OpenNitException;
|
||||
use Inhaus\Plugins\ItService\OpenNit\Settings;
|
||||
use Symfony\Component\HttpFoundation\Response as HttpResponse;
|
||||
|
||||
/**
|
||||
* „Meine IT“: Geräte, Tickets und Leihgeräte der angemeldeten Person aus OpenNIT.
|
||||
*/
|
||||
class ItServiceController extends Controller
|
||||
{
|
||||
public function __construct(private readonly ItService $it, private readonly Settings $settings) {}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
return Inertia::render('it-service::Index', [
|
||||
'configured' => $this->it->configured(),
|
||||
'intro' => $this->settings->intro() ? app(RichText::class)->sanitize($this->settings->intro()) : null,
|
||||
// Jeder Bereich einzeln: fällt einer aus, bleiben die anderen sichtbar
|
||||
'assets' => Inertia::defer(fn () => $this->attempt(fn () => $this->it->assets($user))),
|
||||
'tickets' => Inertia::defer(fn () => $this->attempt(fn () => $this->it->tickets($user))),
|
||||
'loans' => Inertia::defer(fn () => $this->attempt(fn () => $this->it->loans($user))),
|
||||
]);
|
||||
}
|
||||
|
||||
/** Zahlen für die Startseiten-Kachel (lädt die Kachel selbst nach) */
|
||||
public function summary(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
try {
|
||||
$tickets = $this->it->tickets($user);
|
||||
$loans = $this->it->loans($user);
|
||||
} catch (OpenNitException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 503);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'open_tickets' => count(array_filter($tickets, fn ($t) => $t['open'])),
|
||||
'latest' => array_slice(array_values(array_filter($tickets, fn ($t) => $t['open'])), 0, 3),
|
||||
'loans' => count(array_filter($loans, fn ($l) => in_array($l['status'], ['pending', 'reserved', 'active'], true))),
|
||||
]);
|
||||
}
|
||||
|
||||
public function createTicket(Request $request): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
return Inertia::render('it-service::TicketCreate', [
|
||||
'assetId' => $request->integer('geraet') ?: null,
|
||||
'assets' => $this->attempt(fn () => $this->it->assets($user)),
|
||||
'options' => $this->attempt(fn () => $this->it->ticketOptions()),
|
||||
]);
|
||||
}
|
||||
|
||||
public function storeTicket(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'subject' => ['required', 'string', 'max:200'],
|
||||
'description' => ['required', 'string', 'max:20000'],
|
||||
'category_id' => ['nullable', 'integer'],
|
||||
'location_id' => ['nullable', 'integer'],
|
||||
'asset_id' => ['nullable', 'integer'],
|
||||
], [], ['subject' => 'Betreff', 'description' => 'Beschreibung']);
|
||||
|
||||
$id = $this->orFail(fn () => $this->it->createTicket($request->user(), $data), 'subject');
|
||||
|
||||
return $id > 0
|
||||
? to_route('it-service.tickets.show', $id)->with('status', 'Ticket erstellt – die IT meldet sich.')
|
||||
: to_route('it-service.index')->with('status', 'Ticket erstellt – die IT meldet sich.');
|
||||
}
|
||||
|
||||
public function ticket(Request $request, int $id): Response
|
||||
{
|
||||
try {
|
||||
$ticket = $this->it->ticket($request->user(), $id);
|
||||
} catch (OpenNitException $e) {
|
||||
abort($e->status === 404 || $e->status === 403 ? 404 : 503, $e->getMessage());
|
||||
}
|
||||
|
||||
return Inertia::render('it-service::Ticket', ['ticket' => $ticket]);
|
||||
}
|
||||
|
||||
public function reply(Request $request, int $id): RedirectResponse
|
||||
{
|
||||
$data = $request->validate(['message' => ['required', 'string', 'max:20000']], [], ['message' => 'Antwort']);
|
||||
$this->orFail(fn () => $this->it->reply($request->user(), $id, $data['message']), 'message');
|
||||
|
||||
return back()->with('status', 'Antwort gesendet.');
|
||||
}
|
||||
|
||||
public function attachment(Request $request, int $id): HttpResponse
|
||||
{
|
||||
try {
|
||||
$file = $this->it->attachment($request->user(), $id);
|
||||
} catch (OpenNitException $e) {
|
||||
abort($e->status === 404 || $e->status === 403 ? 404 : 503, $e->getMessage());
|
||||
}
|
||||
|
||||
$name = 'anhang-'.$id;
|
||||
|
||||
if (preg_match('/filename\*?=(?:UTF-8\'\')?"?([^";]+)"?/i', (string) $file->header('Content-Disposition'), $m)) {
|
||||
$name = basename(rawurldecode($m[1]));
|
||||
}
|
||||
|
||||
return response($file->body(), 200, [
|
||||
'Content-Type' => $file->header('Content-Type') ?: 'application/octet-stream',
|
||||
'Content-Disposition' => 'attachment; filename="'.addcslashes($name, '"\\').'"',
|
||||
'X-Content-Type-Options' => 'nosniff',
|
||||
]);
|
||||
}
|
||||
|
||||
public function loanDevices(Request $request): Response
|
||||
{
|
||||
$filters = $request->validate([
|
||||
'typ' => ['nullable', 'string', 'max:100'],
|
||||
'von' => ['nullable', 'date_format:Y-m-d'],
|
||||
'bis' => ['nullable', 'date_format:Y-m-d', 'after_or_equal:von'],
|
||||
]);
|
||||
|
||||
return Inertia::render('it-service::Loans', [
|
||||
'filters' => ['type' => $filters['typ'] ?? null, 'from' => $filters['von'] ?? null, 'to' => $filters['bis'] ?? null],
|
||||
'types' => $this->attempt(fn () => $this->it->deviceTypes()),
|
||||
'devices' => $this->attempt(fn () => $this->it->loanDevices($filters['typ'] ?? null, $filters['von'] ?? null, $filters['bis'] ?? null)),
|
||||
]);
|
||||
}
|
||||
|
||||
public function slots(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
return response()->json(['slots' => $this->it->slots($id)]);
|
||||
} catch (OpenNitException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 503);
|
||||
}
|
||||
}
|
||||
|
||||
public function requestLoan(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'device_id' => ['required', 'integer'],
|
||||
'planned_start' => ['required', 'date_format:Y-m-d', 'after_or_equal:today'],
|
||||
'planned_end' => ['required', 'date_format:Y-m-d', 'after_or_equal:planned_start'],
|
||||
'purpose' => ['nullable', 'string', 'max:500'],
|
||||
], [], ['planned_start' => 'Beginn', 'planned_end' => 'Ende', 'purpose' => 'Zweck']);
|
||||
|
||||
$result = $this->orFail(fn () => $this->it->requestLoan($request->user(), $data), 'planned_start');
|
||||
|
||||
return to_route('it-service.index')->with('status', $result['status'] === 'reserved'
|
||||
? 'Leihgerät reserviert. Die Übergabe organisiert die IT.'
|
||||
: 'Anfrage gesendet – die IT bestätigt die Ausleihe.');
|
||||
}
|
||||
|
||||
public function cancelLoan(Request $request, int $id): RedirectResponse
|
||||
{
|
||||
$this->orFail(fn () => $this->it->cancelLoan($request->user(), $id), 'loan');
|
||||
|
||||
return back()->with('status', 'Ausleihe storniert.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{ok: bool, data: mixed, error: ?string}
|
||||
*/
|
||||
private function attempt(Closure $callback): array
|
||||
{
|
||||
try {
|
||||
return ['ok' => true, 'data' => $callback(), 'error' => null];
|
||||
} catch (OpenNitException $e) {
|
||||
return ['ok' => false, 'data' => null, 'error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
private function orFail(Closure $callback, string $field): mixed
|
||||
{
|
||||
try {
|
||||
return $callback();
|
||||
} catch (OpenNitException $e) {
|
||||
throw ValidationException::withMessages([$field => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
312
plugins-core/it-service/src/ItService.php
Normal file
312
plugins-core/it-service/src/ItService.php
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\ItService;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Client\Response;
|
||||
use Illuminate\Support\Arr;
|
||||
use Inhaus\Plugins\ItService\OpenNit\Client;
|
||||
use Inhaus\Plugins\ItService\OpenNit\Settings;
|
||||
|
||||
/**
|
||||
* IT-Self-Service für eine Person: alle Abfragen laufen mit ihrer E-Mail-Adresse,
|
||||
* OpenNIT liefert damit nur ihre eigenen Geräte, Tickets und Ausleihen.
|
||||
* Antworten werden defensiv aufbereitet – die Oberfläche bekommt feste Felder.
|
||||
*/
|
||||
class ItService
|
||||
{
|
||||
public const OPEN_STATUSES = ['open', 'new', 'pending', 'in_progress', 'waiting', 'reopened', 'offen', 'neu', 'in_bearbeitung', 'wartend'];
|
||||
|
||||
public function __construct(private readonly Client $client, private readonly Settings $settings) {}
|
||||
|
||||
public function configured(): bool
|
||||
{
|
||||
return $this->settings->configured();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function assets(User $user): array
|
||||
{
|
||||
return array_map(fn (array $asset) => [
|
||||
'id' => (int) ($asset['id'] ?? 0),
|
||||
'name' => (string) ($asset['name'] ?? $asset['title'] ?? 'Gerät'),
|
||||
'type' => self::text($asset, ['type', 'category', 'device_type']),
|
||||
'serial' => self::text($asset, ['serial', 'serial_number']),
|
||||
'inventory' => self::text($asset, ['inventory_number', 'asset_tag', 'inventory']),
|
||||
'manufacturer' => self::text($asset, ['manufacturer', 'vendor']),
|
||||
'model' => self::text($asset, ['model']),
|
||||
'location' => self::text($asset, ['location', 'location_name']),
|
||||
'warranty_end' => self::text($asset, ['warranty_end', 'warranty_until']),
|
||||
'maintenance' => self::text($asset, ['next_maintenance', 'maintenance_due', 'maintenance']),
|
||||
], $this->list($this->client->get('/my-assets', ['email' => $user->email]), 'assets'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function tickets(User $user): array
|
||||
{
|
||||
$tickets = array_map(fn (array $ticket) => self::ticketSummary($ticket), $this->list($this->client->get('/my-tickets', ['email' => $user->email]), 'tickets'));
|
||||
|
||||
usort($tickets, fn ($a, $b) => [$b['open'], $b['created_at']] <=> [$a['open'], $a['created_at']]);
|
||||
|
||||
return $tickets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function ticket(User $user, int $id): array
|
||||
{
|
||||
$data = $this->client->get("/tickets/{$id}", ['email' => $user->email]);
|
||||
$ticket = (array) ($data['ticket'] ?? $data);
|
||||
|
||||
return [
|
||||
...self::ticketSummary($ticket),
|
||||
'description' => self::text($ticket, ['description', 'body', 'message', 'text']),
|
||||
'category' => self::text($ticket, ['category', 'category_name']),
|
||||
'location' => self::text($ticket, ['location', 'location_name']),
|
||||
'asset' => self::text($ticket, ['asset', 'asset_name']),
|
||||
'replies' => array_map(fn ($reply) => [
|
||||
'message' => is_array($reply) ? (string) (self::text($reply, ['message', 'body', 'text', 'content']) ?? '') : (string) $reply,
|
||||
'author' => is_array($reply) ? self::text($reply, ['author', 'from_name', 'name', 'user', 'author_name']) : null,
|
||||
'from_staff' => is_array($reply) && (bool) ($reply['is_staff'] ?? $reply['internal_user'] ?? $reply['from_staff'] ?? (isset($reply['from_email']) && mb_strtolower((string) $reply['from_email']) !== mb_strtolower($user->email))),
|
||||
'created_at' => is_array($reply) ? self::text($reply, ['created_at', 'date', 'created']) : null,
|
||||
], array_values(array_filter((array) ($data['replies'] ?? []), fn ($reply) => ! (is_array($reply) && ($reply['internal'] ?? $reply['is_internal'] ?? false))))),
|
||||
'attachments' => array_values(array_filter(array_map(fn ($file) => is_array($file) && isset($file['id']) ? [
|
||||
'id' => (int) $file['id'],
|
||||
'name' => (string) ($file['name'] ?? $file['filename'] ?? $file['original_name'] ?? 'Anhang'),
|
||||
'size' => isset($file['size']) ? (int) $file['size'] : null,
|
||||
] : null, (array) ($data['attachments'] ?? [])))),
|
||||
'assignees' => array_values(array_filter(array_map(fn ($person) => is_array($person) ? self::text($person, ['name', 'display_name', 'username']) : (is_string($person) ? $person : null), (array) ($data['assignees'] ?? [])))),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{subject: string, description?: ?string, category_id?: ?int, location_id?: ?int, asset_id?: ?int} $data
|
||||
*/
|
||||
public function createTicket(User $user, array $data): int
|
||||
{
|
||||
$response = $this->client->post('/tickets', array_filter([
|
||||
'subject' => $data['subject'],
|
||||
'from_email' => $user->email,
|
||||
'from_name' => $user->name,
|
||||
'description' => $data['description'] ?? null,
|
||||
'category_id' => $data['category_id'] ?? null,
|
||||
'location_id' => $data['location_id'] ?? null,
|
||||
'asset_id' => $data['asset_id'] ?? null,
|
||||
], fn ($value) => $value !== null && $value !== ''));
|
||||
|
||||
return (int) ($response['id'] ?? $response['ticket_id'] ?? 0);
|
||||
}
|
||||
|
||||
public function reply(User $user, int $ticketId, string $message): void
|
||||
{
|
||||
$this->client->post("/tickets/{$ticketId}/reply", ['email' => $user->email, 'message' => $message]);
|
||||
}
|
||||
|
||||
public function attachment(User $user, int $id): Response
|
||||
{
|
||||
return $this->client->download("/ticket-attachments/{$id}", ['email' => $user->email]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function loans(User $user): array
|
||||
{
|
||||
return array_map(fn (array $loan) => [
|
||||
'id' => (int) ($loan['id'] ?? 0),
|
||||
'device' => (string) ($loan['device_title'] ?? $loan['device'] ?? 'Leihgerät'),
|
||||
'status' => (string) ($loan['status'] ?? ''),
|
||||
'status_label' => self::loanStatus((string) ($loan['status'] ?? '')),
|
||||
'start' => self::text($loan, ['planned_start', 'start']),
|
||||
'end' => self::text($loan, ['planned_end', 'end']),
|
||||
'cancellable' => in_array($loan['status'] ?? '', ['pending', 'reserved'], true),
|
||||
], $this->list($this->client->get('/my-loans', ['email' => $user->email]), 'loans'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function loanDevices(?string $type, ?string $from, ?string $to): array
|
||||
{
|
||||
return array_map(fn (array $device) => [
|
||||
'id' => (int) ($device['id'] ?? 0),
|
||||
'title' => (string) ($device['title'] ?? $device['name'] ?? 'Leihgerät'),
|
||||
'type' => self::text($device, ['type', 'category']),
|
||||
'available' => (bool) ($device['available'] ?? true),
|
||||
'description' => self::text($device, ['description', 'notes']),
|
||||
], $this->list($this->client->get('/loan-devices', ['type' => $type, 'date_from' => $from, 'date_to' => $to]), 'devices'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{start: string, end: string}>
|
||||
*/
|
||||
public function slots(int $deviceId): array
|
||||
{
|
||||
return array_values(array_filter(array_map(fn ($slot) => is_array($slot) && isset($slot['start']) ? ['start' => (string) $slot['start'], 'end' => (string) ($slot['end'] ?? $slot['start'])] : null, $this->list($this->client->get("/loan-devices/{$deviceId}/slots"), 'slots'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{device_id: int, planned_start: string, planned_end: string, purpose?: ?string} $data
|
||||
* @return array{status: string, message: ?string}
|
||||
*/
|
||||
public function requestLoan(User $user, array $data): array
|
||||
{
|
||||
$body = [
|
||||
'device_id' => $data['device_id'],
|
||||
'planned_start' => $data['planned_start'],
|
||||
'planned_end' => $data['planned_end'],
|
||||
'borrower_name' => $user->name,
|
||||
'borrower_email' => $user->email,
|
||||
'purpose' => $data['purpose'] ?? null,
|
||||
];
|
||||
|
||||
if (($auto = $this->settings->autoReserve()) !== null) {
|
||||
$body['auto_reserve'] = $auto;
|
||||
}
|
||||
|
||||
$response = $this->client->post('/loan-requests', array_filter($body, fn ($value) => $value !== null));
|
||||
|
||||
return ['status' => (string) ($response['status'] ?? 'pending'), 'message' => is_string($response['message'] ?? null) ? $response['message'] : null];
|
||||
}
|
||||
|
||||
public function cancelLoan(User $user, int $id): void
|
||||
{
|
||||
$this->client->post("/loan-requests/{$id}/cancel", ['email' => $user->email]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{categories: list<array<string, mixed>>, locations: list<array<string, mixed>>}
|
||||
*/
|
||||
public function ticketOptions(): array
|
||||
{
|
||||
return [
|
||||
'categories' => self::tree($this->list($this->client->cached('/ticket-categories'), 'categories')),
|
||||
'locations' => self::tree($this->list($this->client->cached('/ticket-locations'), 'locations')),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function deviceTypes(): array
|
||||
{
|
||||
return array_values(array_filter(array_map(fn ($type) => is_string($type) ? $type : (is_array($type) ? ($type['name'] ?? null) : null), $this->list($this->client->cached('/device-types'), 'types'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $ticket
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private static function ticketSummary(array $ticket): array
|
||||
{
|
||||
$status = (string) ($ticket['status'] ?? '');
|
||||
|
||||
return [
|
||||
'id' => (int) ($ticket['id'] ?? 0),
|
||||
'subject' => (string) ($ticket['subject'] ?? $ticket['title'] ?? 'Ticket'),
|
||||
'status' => $status,
|
||||
'status_label' => self::ticketStatus($status),
|
||||
'open' => self::isOpen($status),
|
||||
'created_at' => self::text($ticket, ['created_at', 'created', 'date']) ?? '',
|
||||
'updated_at' => self::text($ticket, ['updated_at', 'last_activity']),
|
||||
'number' => self::text($ticket, ['number', 'ticket_number', 'reference']),
|
||||
];
|
||||
}
|
||||
|
||||
public static function isOpen(string $status): bool
|
||||
{
|
||||
return ! in_array(mb_strtolower($status), ['closed', 'resolved', 'done', 'geschlossen', 'erledigt', 'geloest', 'gelöst', 'cancelled'], true);
|
||||
}
|
||||
|
||||
public static function ticketStatus(string $status): string
|
||||
{
|
||||
return match (mb_strtolower($status)) {
|
||||
'open', 'new', 'offen', 'neu' => 'Offen',
|
||||
'in_progress', 'in_bearbeitung', 'assigned' => 'In Bearbeitung',
|
||||
'pending', 'waiting', 'wartend', 'on_hold' => 'Wartet auf Rückmeldung',
|
||||
'reopened' => 'Wieder geöffnet',
|
||||
'resolved', 'geloest', 'gelöst', 'done', 'erledigt' => 'Gelöst',
|
||||
'closed', 'geschlossen' => 'Geschlossen',
|
||||
'cancelled' => 'Storniert',
|
||||
default => $status !== '' ? ucfirst(str_replace('_', ' ', $status)) : 'Offen',
|
||||
};
|
||||
}
|
||||
|
||||
public static function loanStatus(string $status): string
|
||||
{
|
||||
return match ($status) {
|
||||
'pending' => 'Angefragt',
|
||||
'reserved' => 'Reserviert',
|
||||
'active' => 'Ausgeliehen',
|
||||
'returned' => 'Zurückgegeben',
|
||||
'rejected' => 'Abgelehnt',
|
||||
'cancelled' => 'Storniert',
|
||||
default => $status !== '' ? ucfirst($status) : 'Angefragt',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function list(array $data, string $key): array
|
||||
{
|
||||
$items = $data[$key] ?? (array_is_list($data) ? $data : []);
|
||||
|
||||
return array_values(array_filter((array) $items, fn ($item) => is_array($item) || is_string($item)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hierarchie (parent_id) als eingerückte Liste für Auswahlfelder.
|
||||
*
|
||||
* @param list<array<string, mixed>> $items
|
||||
* @return list<array{value: int, label: string}>
|
||||
*/
|
||||
private static function tree(array $items): array
|
||||
{
|
||||
$children = [];
|
||||
|
||||
foreach ($items as $item) {
|
||||
if (is_array($item) && isset($item['id'])) {
|
||||
$children[$item['parent_id'] ?? 0][] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [];
|
||||
$walk = function ($parent, int $depth) use (&$walk, &$children, &$result) {
|
||||
foreach ($children[$parent] ?? [] as $item) {
|
||||
$result[] = ['value' => (int) $item['id'], 'label' => str_repeat('– ', $depth).($item['name'] ?? '')];
|
||||
$walk($item['id'], $depth + 1);
|
||||
}
|
||||
};
|
||||
$walk(0, 0);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @param list<string> $keys
|
||||
*/
|
||||
private static function text(array $data, array $keys): ?string
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
$value = Arr::get($data, $key);
|
||||
|
||||
if (is_array($value)) {
|
||||
$value = $value['name'] ?? $value['title'] ?? null;
|
||||
}
|
||||
|
||||
if (is_scalar($value) && trim((string) $value) !== '') {
|
||||
return trim((string) $value);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
28
plugins-core/it-service/src/ItServicePlugin.php
Normal file
28
plugins-core/it-service/src/ItServicePlugin.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\ItService;
|
||||
|
||||
use App\Dashboard\Widgets;
|
||||
use App\Plugins\Plugin;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Navigation;
|
||||
use Inhaus\Plugins\ItService\OpenNit\Settings;
|
||||
|
||||
/**
|
||||
* IT-Self-Service über OpenNIT (IT-Dokumentation): eigene Geräte, Tickets und Leihgeräte.
|
||||
*/
|
||||
class ItServicePlugin extends Plugin
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->singleton(Settings::class);
|
||||
$this->app->make(Abilities::class)->define('it-service.manage', 'IT-Service (OpenNIT) einrichten', 'IT-Service');
|
||||
|
||||
$this->app->make(Navigation::class)->add('it-service', 'IT-Service', '/it-service', active: 'it-service.*', sort: 75);
|
||||
|
||||
// Die Kachel lädt ihre Zahlen selbst nach – die Startseite wartet nicht auf OpenNIT.
|
||||
$this->app->make(Widgets::class)->add('it-service.summary', 'it-service::MyIt', 'aside', sort: 25,
|
||||
props: fn () => app(Settings::class)->configured() ? [] : null,
|
||||
label: 'Meine IT (offene Tickets, Ausleihen)', mobileSort: 45);
|
||||
}
|
||||
}
|
||||
158
plugins-core/it-service/src/OpenNit/Client.php
Normal file
158
plugins-core/it-service/src/OpenNit/Client.php
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\ItService\OpenNit;
|
||||
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Http\Client\Response;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Zugriff auf die OpenNIT-API (/api/ex) mit Bearer-Token und HMAC-Signatur v2:
|
||||
*
|
||||
* v2 \n METHODE \n PFAD \n QUERY (sortiert) \n EMAIL (klein) \n sha256(BODY) \n TIMESTAMP \n NONCE
|
||||
*
|
||||
* Die E-Mail-Zeile bindet personenbezogene Abfragen („my-tickets“ …) an das
|
||||
* Signing-Secret – so liefert OpenNIT nur Daten der angemeldeten Person.
|
||||
*/
|
||||
class Client
|
||||
{
|
||||
public function __construct(private readonly Settings $settings) {}
|
||||
|
||||
/**
|
||||
* @param array<string, scalar|null> $query
|
||||
* @param array<string, mixed>|null $body
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function get(string $path, array $query = []): array
|
||||
{
|
||||
return $this->json($this->send('GET', $path, $query));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $body
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function post(string $path, array $body = []): array
|
||||
{
|
||||
return $this->json($this->send('POST', $path, [], $body));
|
||||
}
|
||||
|
||||
/**
|
||||
* Binärantwort (z. B. Ticket-Anhang).
|
||||
*
|
||||
* @param array<string, scalar|null> $query
|
||||
*/
|
||||
public function download(string $path, array $query = []): Response
|
||||
{
|
||||
$response = $this->send('GET', $path, $query);
|
||||
|
||||
if (! $response->successful()) {
|
||||
throw OpenNitException::fromStatus($response->status(), (array) $response->json());
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stammdaten (Kategorien, Standorte, Gerätetypen) – kurz zwischengespeichert.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function cached(string $path, int $seconds = 600): array
|
||||
{
|
||||
return Cache::remember('it-service:'.md5($this->settings->url().$path), $seconds, fn () => $this->get($path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Kanonische Zeichenkette der Signatur (öffentlich für Tests).
|
||||
*
|
||||
* @param array<string, scalar|null> $query
|
||||
*/
|
||||
public static function canonical(string $method, string $path, array $query, string $email, string $body, int $timestamp, string $nonce): string
|
||||
{
|
||||
ksort($query);
|
||||
|
||||
return implode("\n", [
|
||||
'v2',
|
||||
strtoupper($method),
|
||||
$path,
|
||||
http_build_query($query),
|
||||
mb_strtolower($email),
|
||||
hash('sha256', $body),
|
||||
(string) $timestamp,
|
||||
$nonce,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, scalar|null> $query
|
||||
* @param array<string, mixed>|null $body
|
||||
*/
|
||||
private function send(string $method, string $path, array $query = [], ?array $body = null): Response
|
||||
{
|
||||
if (! $this->settings->configured()) {
|
||||
throw new OpenNitException('Der IT-Service ist noch nicht eingerichtet. Bitte die Administration informieren.');
|
||||
}
|
||||
|
||||
$query = array_filter($query, fn ($value) => $value !== null && $value !== '');
|
||||
$base = $this->settings->url();
|
||||
$basePath = rtrim((string) parse_url($base, PHP_URL_PATH), '/');
|
||||
$fullPath = $basePath.'/'.ltrim($path, '/');
|
||||
$raw = $body === null ? '' : json_encode($body, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
$email = (string) ($query['email'] ?? (is_array($body) ? ($body['email'] ?? '') : ''));
|
||||
$timestamp = time();
|
||||
$nonce = bin2hex(random_bytes(16));
|
||||
$signature = hash_hmac('sha256', self::canonical($method, $fullPath, $query, $email, $raw, $timestamp, $nonce), $this->settings->secret());
|
||||
|
||||
$request = Http::withToken($this->settings->token())
|
||||
->withHeaders([
|
||||
'X-OpenNIT-Timestamp' => (string) $timestamp,
|
||||
'X-OpenNIT-Nonce' => $nonce,
|
||||
'X-OpenNIT-Signature' => $signature,
|
||||
'Accept' => 'application/json',
|
||||
])
|
||||
->timeout(15)
|
||||
->connectTimeout(5);
|
||||
|
||||
$url = rtrim((string) preg_replace('#(https?://[^/]+).*#', '$1', $base), '/').$fullPath.($query ? '?'.http_build_query(self::sorted($query)) : '');
|
||||
|
||||
try {
|
||||
return $body === null
|
||||
? $request->send($method, $url)
|
||||
: $request->withBody($raw, 'application/json')->send($method, $url);
|
||||
} catch (ConnectionException $e) {
|
||||
Log::warning('OpenNIT nicht erreichbar: '.$e->getMessage());
|
||||
|
||||
throw new OpenNitException('Der IT-Service ist gerade nicht erreichbar. Bitte später erneut versuchen.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function json(Response $response): array
|
||||
{
|
||||
$data = (array) $response->json();
|
||||
|
||||
if (! $response->successful()) {
|
||||
Log::info("OpenNIT antwortete {$response->status()}", ['body' => mb_substr($response->body(), 0, 500)]);
|
||||
|
||||
throw OpenNitException::fromStatus($response->status(), $data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, scalar|null> $query
|
||||
* @return array<string, scalar|null>
|
||||
*/
|
||||
private static function sorted(array $query): array
|
||||
{
|
||||
ksort($query);
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
32
plugins-core/it-service/src/OpenNit/OpenNitException.php
Normal file
32
plugins-core/it-service/src/OpenNit/OpenNitException.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\ItService\OpenNit;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Fehler von OpenNIT – mit einer Meldung, die man Mitarbeitenden zeigen kann.
|
||||
*/
|
||||
class OpenNitException extends RuntimeException
|
||||
{
|
||||
public function __construct(string $message, public readonly int $status = 0, public readonly array $body = [])
|
||||
{
|
||||
parent::__construct($message, $status);
|
||||
}
|
||||
|
||||
public static function fromStatus(int $status, array $body): self
|
||||
{
|
||||
$detail = is_string($body['message'] ?? null) ? $body['message'] : (is_string($body['error'] ?? null) ? $body['error'] : null);
|
||||
|
||||
$message = match ($status) {
|
||||
400 => 'Die Angaben sind unvollständig oder ungültig.'.($detail ? " ({$detail})" : ''),
|
||||
401 => 'Die Verbindung zum IT-Service ist nicht richtig eingerichtet (Anmeldung abgelehnt). Bitte die Administration informieren.',
|
||||
403 => 'Der IT-Service erlaubt diesen Zugriff nicht.',
|
||||
404 => 'Nicht gefunden – vielleicht gehört der Eintrag zu einer anderen Person.',
|
||||
409 => $detail ?: 'Das Gerät ist in diesem Zeitraum nicht verfügbar.',
|
||||
default => 'Der IT-Service ist gerade nicht erreichbar. Bitte später erneut versuchen.',
|
||||
};
|
||||
|
||||
return new self($message, $status, $body);
|
||||
}
|
||||
}
|
||||
94
plugins-core/it-service/src/OpenNit/Settings.php
Normal file
94
plugins-core/it-service/src/OpenNit/Settings.php
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\ItService\OpenNit;
|
||||
|
||||
use App\Support\Settings as PortalSettings;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Zugangsdaten zu OpenNIT. Token und Signing-Secret liegen verschlüsselt in den Einstellungen.
|
||||
*/
|
||||
class Settings
|
||||
{
|
||||
public const URL = 'it_service.url';
|
||||
|
||||
public const TOKEN = 'it_service.token';
|
||||
|
||||
public const SECRET = 'it_service.secret';
|
||||
|
||||
/** null = Einstellung in OpenNIT, true = sofort reservieren, false = immer Anfrage */
|
||||
public const AUTO_RESERVE = 'it_service.auto_reserve';
|
||||
|
||||
public const INTRO = 'it_service.intro';
|
||||
|
||||
public function __construct(private readonly PortalSettings $settings) {}
|
||||
|
||||
public function url(): string
|
||||
{
|
||||
return rtrim((string) $this->settings->get(self::URL, ''), '/');
|
||||
}
|
||||
|
||||
public function token(): string
|
||||
{
|
||||
return $this->decrypt(self::TOKEN);
|
||||
}
|
||||
|
||||
public function secret(): string
|
||||
{
|
||||
return $this->decrypt(self::SECRET);
|
||||
}
|
||||
|
||||
public function configured(): bool
|
||||
{
|
||||
return $this->url() !== '' && $this->token() !== '' && $this->secret() !== '';
|
||||
}
|
||||
|
||||
public function autoReserve(): ?bool
|
||||
{
|
||||
$value = $this->settings->get(self::AUTO_RESERVE);
|
||||
|
||||
return $value === null ? null : (bool) $value;
|
||||
}
|
||||
|
||||
public function intro(): ?string
|
||||
{
|
||||
return $this->settings->get(self::INTRO) ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{url: string, token?: ?string, secret?: ?string, auto_reserve: ?string, intro: ?string} $data leere Token/Secret = unverändert
|
||||
*/
|
||||
public function save(array $data): void
|
||||
{
|
||||
$this->settings->set(self::URL, rtrim(trim($data['url']), '/'));
|
||||
|
||||
foreach ([self::TOKEN => $data['token'] ?? null, self::SECRET => $data['secret'] ?? null] as $key => $value) {
|
||||
if (filled($value)) {
|
||||
$this->settings->set($key, Crypt::encryptString(trim($value)));
|
||||
}
|
||||
}
|
||||
|
||||
$this->settings->set(self::AUTO_RESERVE, match ($data['auto_reserve'] ?? '') {
|
||||
'yes' => true,
|
||||
'no' => false,
|
||||
default => null,
|
||||
});
|
||||
$this->settings->set(self::INTRO, $data['intro'] ?? null);
|
||||
}
|
||||
|
||||
private function decrypt(string $key): string
|
||||
{
|
||||
$value = $this->settings->get($key);
|
||||
|
||||
if (! is_string($value) || $value === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
return Crypt::decryptString($value);
|
||||
} catch (Throwable) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -43,6 +43,9 @@ async function copyLink() {
|
|||
}
|
||||
}
|
||||
|
||||
// Abteilung zuerst, Funktion dahinter: „Personal | Referentin“
|
||||
const authorLine = (author) => [author?.department, author?.job_title].filter(Boolean).join(' | ');
|
||||
|
||||
const mailLink = () => `mailto:?subject=${encodeURIComponent(props.post.title)}&body=${encodeURIComponent(window.location.href)}`;
|
||||
</script>
|
||||
|
||||
|
|
@ -87,7 +90,7 @@ const mailLink = () => `mailto:?subject=${encodeURIComponent(props.post.title)}&
|
|||
<PersonAvatar :person="post.author" class="size-11" />
|
||||
<div class="min-w-0 text-sm">
|
||||
<Link :href="`/personen/${post.author.id}`" class="font-semibold hover:underline">{{ post.author.name }}</Link>
|
||||
<p v-if="post.author.job_title" class="text-muted-foreground">{{ post.author.job_title }}</p>
|
||||
<p v-if="authorLine(post.author)" class="text-muted-foreground">{{ authorLine(post.author) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -118,7 +121,7 @@ const mailLink = () => `mailto:?subject=${encodeURIComponent(props.post.title)}&
|
|||
<PersonAvatar :person="post.author" class="size-14" />
|
||||
<span class="min-w-0">
|
||||
<span class="block font-semibold">{{ post.author.name }}</span>
|
||||
<span v-if="post.author.job_title" class="block text-[13px] text-muted-foreground">{{ post.author.job_title }}</span>
|
||||
<span v-if="authorLine(post.author)" class="block text-[13px] text-muted-foreground">{{ authorLine(post.author) }}</span>
|
||||
</span>
|
||||
</Link>
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ class NewsController extends Controller
|
|||
'name' => $post->author->name,
|
||||
'initials' => $post->author->initials,
|
||||
'job_title' => $post->author->job_title,
|
||||
'department' => $post->author->department,
|
||||
'avatar_url' => $post->author->avatarUrl(96),
|
||||
] : null,
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue