feat(admin): add categories and teams management page
This commit is contained in:
@@ -24,4 +24,5 @@ logs
|
|||||||
!.env.example
|
!.env.example
|
||||||
|
|
||||||
pnpm-*.yaml
|
pnpm-*.yaml
|
||||||
|
.pnpm-store/
|
||||||
AGENTS.md
|
AGENTS.md
|
||||||
@@ -296,6 +296,35 @@ html body .navbar .navbar-collapsable .navbar-nav li.nav-item a.nav-link[data-fo
|
|||||||
line-height: 1;
|
line-height: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.page-shell {
|
||||||
|
padding-block: 3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell-header {
|
||||||
|
align-items: flex-start;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 1rem;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell-title {
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell-subtitle {
|
||||||
|
color: var(--visione-text-soft);
|
||||||
|
margin-bottom: 0;
|
||||||
|
max-width: 48rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.surface-card {
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #dfe4ea;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.it-header-wrapper .header-slim-right-zone .btn .rounded-icon,
|
.it-header-wrapper .header-slim-right-zone .btn .rounded-icon,
|
||||||
.it-header-wrapper .header-slim-right-zone .btn .rounded-icon .icon {
|
.it-header-wrapper .header-slim-right-zone .btn .rounded-icon .icon {
|
||||||
|
|
||||||
@@ -316,6 +345,10 @@ html body .navbar .navbar-collapsable .navbar-nav li.nav-item a.nav-link[data-fo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 767.98px) {
|
@media (max-width: 767.98px) {
|
||||||
|
.page-shell {
|
||||||
|
padding-block: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
.it-hero-wrapper .container {
|
.it-hero-wrapper .container {
|
||||||
min-height: 220px;
|
min-height: 220px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// Presumo tu abbia un useAdmin.ts (come da tuo elenco file) per le statistiche
|
|
||||||
const { getOverviewStats } = useAdmin()
|
const { getOverviewStats } = useAdmin()
|
||||||
|
|
||||||
const { data: statsRes, pending } = useAsyncData('admin-stats', () => getOverviewStats())
|
const { data: statsRes, pending } = useAsyncData('admin-stats', () => getOverviewStats())
|
||||||
@@ -40,6 +39,12 @@ const { data: statsRes, pending } = useAsyncData('admin-stats', () => getOvervie
|
|||||||
|
|
||||||
<h3 class="mb-3">Gestione Sistema</h3>
|
<h3 class="mb-3">Gestione Sistema</h3>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<div class="col-12 col-md-4 mb-3">
|
||||||
|
<NuxtLink to="/admin/catalog" class="btn btn-outline-primary w-100 py-3 d-flex flex-column align-items-center">
|
||||||
|
<BIIcon name="it-list" size="sm" color="primary" class="mb-2" />
|
||||||
|
Categorie e Team
|
||||||
|
</NuxtLink>
|
||||||
|
</div>
|
||||||
<div class="col-12 col-md-4 mb-3">
|
<div class="col-12 col-md-4 mb-3">
|
||||||
<NuxtLink to="/admin/areas" class="btn btn-outline-primary w-100 py-3 d-flex flex-column align-items-center">
|
<NuxtLink to="/admin/areas" class="btn btn-outline-primary w-100 py-3 d-flex flex-column align-items-center">
|
||||||
<BIIcon name="it-map-marker" size="sm" color="primary" class="mb-2" />
|
<BIIcon name="it-map-marker" size="sm" color="primary" class="mb-2" />
|
||||||
@@ -52,12 +57,18 @@ const { data: statsRes, pending } = useAsyncData('admin-stats', () => getOvervie
|
|||||||
Gestione Utenti
|
Gestione Utenti
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 col-md-4 mb-3">
|
<div class="col-12 col-md-6 mb-3">
|
||||||
<NuxtLink to="/admin/moderation" class="btn btn-outline-danger w-100 py-3 d-flex flex-column align-items-center">
|
<NuxtLink to="/admin/moderation" class="btn btn-outline-danger w-100 py-3 d-flex flex-column align-items-center">
|
||||||
<BIIcon name="it-warning" size="sm" color="danger" class="mb-2" />
|
<BIIcon name="it-warning" size="sm" color="danger" class="mb-2" />
|
||||||
Moderazione Abusi
|
Moderazione Abusi
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-12 col-md-6 mb-3">
|
||||||
|
<NuxtLink to="/open-data" class="btn btn-outline-secondary w-100 py-3 d-flex flex-column align-items-center">
|
||||||
|
<BIIcon name="it-chart-line" size="sm" class="mb-2" />
|
||||||
|
Vista Open Data
|
||||||
|
</NuxtLink>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -8,7 +8,6 @@ import type {
|
|||||||
} from "~/types/api";
|
} from "~/types/api";
|
||||||
|
|
||||||
export const useAuth = () => {
|
export const useAuth = () => {
|
||||||
const route = useRoute()
|
|
||||||
const nuxtApp = useNuxtApp()
|
const nuxtApp = useNuxtApp()
|
||||||
|
|
||||||
const token = useCookie<string | null>('auth_token', {
|
const token = useCookie<string | null>('auth_token', {
|
||||||
@@ -33,7 +32,8 @@ export const useAuth = () => {
|
|||||||
tokenState.value = newVal || null
|
tokenState.value = newVal || null
|
||||||
})
|
})
|
||||||
|
|
||||||
const syncUser = async (redirectOnSuccess = false) => {
|
const syncUser = async (options: { redirectOnSuccess?: boolean; currentPath?: string } = {}) => {
|
||||||
|
const { redirectOnSuccess = false, currentPath } = options
|
||||||
const tokenVal = tokenState.value || token.value
|
const tokenVal = tokenState.value || token.value
|
||||||
if (!tokenVal || isSyncingUser.value) return
|
if (!tokenVal || isSyncingUser.value) return
|
||||||
|
|
||||||
@@ -42,10 +42,11 @@ export const useAuth = () => {
|
|||||||
const res = await fetchCurrentUser()
|
const res = await fetchCurrentUser()
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
user.value = res.user
|
user.value = res.user
|
||||||
|
const path = currentPath ?? useNuxtApp().$router.currentRoute.value.path
|
||||||
|
|
||||||
if (res.user.must_change_password && route.path !== '/auth/change-password') {
|
if (res.user.must_change_password && path !== '/auth/change-password') {
|
||||||
await nuxtApp.runWithContext(() => navigateTo('/auth/change-password'))
|
await nuxtApp.runWithContext(() => navigateTo('/auth/change-password'))
|
||||||
} else if (redirectOnSuccess && route.path.startsWith('/auth')) {
|
} else if (redirectOnSuccess && path.startsWith('/auth')) {
|
||||||
await nuxtApp.runWithContext(() => navigateTo('/dashboard'))
|
await nuxtApp.runWithContext(() => navigateTo('/dashboard'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +66,7 @@ export const useAuth = () => {
|
|||||||
const handleLoginSuccess = async (jwtToken: string) => {
|
const handleLoginSuccess = async (jwtToken: string) => {
|
||||||
token.value = jwtToken
|
token.value = jwtToken
|
||||||
tokenState.value = jwtToken
|
tokenState.value = jwtToken
|
||||||
await syncUser(true)
|
await syncUser({ redirectOnSuccess: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type {
|
|||||||
InterventionSummaryResponse,
|
InterventionSummaryResponse,
|
||||||
OkResponse,
|
OkResponse,
|
||||||
PagedReportListResponse,
|
PagedReportListResponse,
|
||||||
|
TeamListResponse,
|
||||||
UpdateStatusRequest
|
UpdateStatusRequest
|
||||||
} from "~/types/api";
|
} from "~/types/api";
|
||||||
|
|
||||||
@@ -16,6 +17,9 @@ export const useOperator = () => {
|
|||||||
const getOtherOperatorReports = (query?: { page?: number; per_page?: number }) =>
|
const getOtherOperatorReports = (query?: { page?: number; per_page?: number }) =>
|
||||||
useApiFetch<PagedReportListResponse>('/api/v1/operator/reports/others', { method: 'GET', query })
|
useApiFetch<PagedReportListResponse>('/api/v1/operator/reports/others', { method: 'GET', query })
|
||||||
|
|
||||||
|
const getTeams = () =>
|
||||||
|
useApiFetch<TeamListResponse>('/api/v1/operator/teams', { method: 'GET' })
|
||||||
|
|
||||||
const takeReport = (id: number) =>
|
const takeReport = (id: number) =>
|
||||||
useApiFetch<OkResponse>(`/api/v1/reports/${id}/take`, { method: 'POST' })
|
useApiFetch<OkResponse>(`/api/v1/reports/${id}/take`, { method: 'POST' })
|
||||||
|
|
||||||
@@ -32,6 +36,7 @@ export const useOperator = () => {
|
|||||||
getOpenReports,
|
getOpenReports,
|
||||||
getAssignedReports,
|
getAssignedReports,
|
||||||
getOtherOperatorReports,
|
getOtherOperatorReports,
|
||||||
|
getTeams,
|
||||||
takeReport,
|
takeReport,
|
||||||
updateReportStatus,
|
updateReportStatus,
|
||||||
assignTeam,
|
assignTeam,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type {
|
import type {
|
||||||
|
CategoryListResponse,
|
||||||
CreateReportRequest,
|
CreateReportRequest,
|
||||||
CreateReportResponse, FeedbackRequest, FlagRequest, FlagResponse,
|
CreateReportResponse, FeedbackRequest, FlagRequest, FlagResponse,
|
||||||
MediaUploadResponse,
|
MediaUploadResponse,
|
||||||
@@ -11,6 +12,9 @@ export const useReports = () => {
|
|||||||
const getReports = (query?: { area_id?: number; category_id?: number; status?: string }) =>
|
const getReports = (query?: { area_id?: number; category_id?: number; status?: string }) =>
|
||||||
useApiFetch<ReportListResponse>('/api/v1/reports', { method: 'GET', query })
|
useApiFetch<ReportListResponse>('/api/v1/reports', { method: 'GET', query })
|
||||||
|
|
||||||
|
const getCategories = () =>
|
||||||
|
useApiFetch<CategoryListResponse>('/api/v1/report-categories', { method: 'GET' })
|
||||||
|
|
||||||
const createReport = (body: CreateReportRequest) =>
|
const createReport = (body: CreateReportRequest) =>
|
||||||
useApiFetch<CreateReportResponse>('/api/v1/reports', { method: 'POST', body })
|
useApiFetch<CreateReportResponse>('/api/v1/reports', { method: 'POST', body })
|
||||||
|
|
||||||
@@ -37,6 +41,7 @@ export const useReports = () => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
getReports,
|
getReports,
|
||||||
|
getCategories,
|
||||||
createReport,
|
createReport,
|
||||||
getReportDetail,
|
getReportDetail,
|
||||||
uploadMedia,
|
uploadMedia,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|||||||
// Se c'è un token ma l'utente non è ancora caricato e non stiamo già sincronizzando, sincronizza
|
// Se c'è un token ma l'utente non è ancora caricato e non stiamo già sincronizzando, sincronizza
|
||||||
if ((auth.token.value || auth.tokenState.value) && !auth.user.value && !auth.isSyncingUser.value) {
|
if ((auth.token.value || auth.tokenState.value) && !auth.user.value && !auth.isSyncingUser.value) {
|
||||||
try {
|
try {
|
||||||
await auth.syncUser()
|
await auth.syncUser({ currentPath: to.path })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[Auth Middleware] Sync failed:', error)
|
console.error('[Auth Middleware] Sync failed:', error)
|
||||||
return navigateTo('/auth/login')
|
return navigateTo('/auth/login')
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
export default defineNuxtRouteMiddleware(async () => {
|
export default defineNuxtRouteMiddleware(async (to) => {
|
||||||
const auth = useAuth()
|
const auth = useAuth()
|
||||||
|
|
||||||
if ((auth.token.value || auth.tokenState.value) && !auth.user.value && !auth.isSyncingUser.value) {
|
if ((auth.token.value || auth.tokenState.value) && !auth.user.value && !auth.isSyncingUser.value) {
|
||||||
try {
|
try {
|
||||||
await auth.syncUser()
|
await auth.syncUser({ currentPath: to.path })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[Guest Middleware] Sync failed:', error)
|
console.error('[Guest Middleware] Sync failed:', error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,236 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
definePageMeta({
|
||||||
|
middleware: 'auth',
|
||||||
|
auth: { role: 'ADMIN' }
|
||||||
|
})
|
||||||
|
|
||||||
|
useHead({ title: 'Categorie e Team - Admin' })
|
||||||
|
|
||||||
|
const { createCategory, getTeams, createTeam, getAreas } = useAdmin()
|
||||||
|
const { getCategories } = useReports()
|
||||||
|
|
||||||
|
const { data: categoriesRes, refresh: refreshCategories } = await useAsyncData('report-categories-admin-view', () => getCategories())
|
||||||
|
const { data: teamsRes, refresh: refreshTeams } = await useAsyncData('admin-teams', () => getTeams())
|
||||||
|
const { data: areasRes } = await useAsyncData('admin-team-areas', () => getAreas())
|
||||||
|
|
||||||
|
const categoryForm = reactive({
|
||||||
|
name: '',
|
||||||
|
description: '',
|
||||||
|
})
|
||||||
|
|
||||||
|
const teamForm = reactive({
|
||||||
|
name: '',
|
||||||
|
description: '',
|
||||||
|
team_category_id: null as number | null,
|
||||||
|
area_id: null as number | null,
|
||||||
|
})
|
||||||
|
|
||||||
|
const isSavingCategory = ref(false)
|
||||||
|
const isSavingTeam = ref(false)
|
||||||
|
const categoryError = ref('')
|
||||||
|
const teamError = ref('')
|
||||||
|
|
||||||
|
const categories = computed(() => categoriesRes.value?.categories || [])
|
||||||
|
const teams = computed(() => teamsRes.value?.teams || [])
|
||||||
|
const areas = computed(() => areasRes.value?.areas || [])
|
||||||
|
|
||||||
|
const submitCategory = async () => {
|
||||||
|
categoryError.value = ''
|
||||||
|
isSavingCategory.value = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
await createCategory({
|
||||||
|
name: categoryForm.name.trim(),
|
||||||
|
description: categoryForm.description.trim() || undefined,
|
||||||
|
})
|
||||||
|
categoryForm.name = ''
|
||||||
|
categoryForm.description = ''
|
||||||
|
await refreshCategories()
|
||||||
|
} catch (error: any) {
|
||||||
|
categoryError.value = error?.data?.message || 'Creazione categoria non riuscita.'
|
||||||
|
} finally {
|
||||||
|
isSavingCategory.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitTeam = async () => {
|
||||||
|
if (!teamForm.team_category_id) return
|
||||||
|
|
||||||
|
teamError.value = ''
|
||||||
|
isSavingTeam.value = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
await createTeam({
|
||||||
|
name: teamForm.name.trim(),
|
||||||
|
description: teamForm.description.trim() || undefined,
|
||||||
|
team_category_id: teamForm.team_category_id,
|
||||||
|
area_id: teamForm.area_id || undefined,
|
||||||
|
})
|
||||||
|
teamForm.name = ''
|
||||||
|
teamForm.description = ''
|
||||||
|
teamForm.team_category_id = null
|
||||||
|
teamForm.area_id = null
|
||||||
|
await refreshTeams()
|
||||||
|
} catch (error: any) {
|
||||||
|
teamError.value = error?.data?.message || 'Creazione team non riuscita.'
|
||||||
|
} finally {
|
||||||
|
isSavingTeam.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="container my-5">
|
||||||
|
<div class="d-flex flex-wrap justify-content-between align-items-center gap-3 mb-4">
|
||||||
|
<div>
|
||||||
|
<h1 class="h3 font-weight-bold mb-1">Categorie e Team</h1>
|
||||||
|
<p class="text-muted mb-0">Gestione dati di riferimento per segnalazioni e interventi.</p>
|
||||||
|
</div>
|
||||||
|
<NuxtLink to="/dashboard" class="btn btn-outline-secondary btn-sm">Torna alla Dashboard</NuxtLink>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row g-4">
|
||||||
|
<div class="col-12 col-xl-5">
|
||||||
|
<div class="card card-bg border-0 shadow-sm h-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex align-items-center justify-content-between mb-3">
|
||||||
|
<h2 class="h5 mb-0">Categorie</h2>
|
||||||
|
<span class="badge bg-light text-dark border">{{ categories.length }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="categoryError" class="alert alert-danger py-2" role="alert">
|
||||||
|
{{ categoryError }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form class="mb-4" @submit.prevent="submitCategory">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Nome categoria</label>
|
||||||
|
<input v-model="categoryForm.name" type="text" class="form-control" required />
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Descrizione</label>
|
||||||
|
<textarea v-model="categoryForm.description" class="form-control" rows="3"></textarea>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary" :disabled="isSavingCategory || !categoryForm.name.trim()">
|
||||||
|
<span v-if="isSavingCategory" class="spinner-border spinner-border-sm me-2"></span>
|
||||||
|
Crea categoria
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="table-responsive report-table-wrapper">
|
||||||
|
<table class="table table-hover report-table mb-0">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Nome</th>
|
||||||
|
<th>Stato</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr v-for="category in categories" :key="category.id">
|
||||||
|
<td class="report-table-id">#{{ category.id }}</td>
|
||||||
|
<td>
|
||||||
|
<strong>{{ category.name }}</strong>
|
||||||
|
<div v-if="category.description" class="small text-muted mt-1">{{ category.description }}</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="badge" :class="category.active === false ? 'bg-secondary' : 'bg-success'">
|
||||||
|
{{ category.active === false ? 'Inattiva' : 'Attiva' }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="categories.length === 0">
|
||||||
|
<td colspan="3" class="text-muted">Nessuna categoria configurata.</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12 col-xl-7">
|
||||||
|
<div class="card card-bg border-0 shadow-sm h-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex align-items-center justify-content-between mb-3">
|
||||||
|
<h2 class="h5 mb-0">Team di intervento</h2>
|
||||||
|
<span class="badge bg-light text-dark border">{{ teams.length }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="teamError" class="alert alert-danger py-2" role="alert">
|
||||||
|
{{ teamError }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form class="row g-3 mb-4" @submit.prevent="submitTeam">
|
||||||
|
<div class="col-12 col-md-6">
|
||||||
|
<label class="form-label">Nome team</label>
|
||||||
|
<input v-model="teamForm.name" type="text" class="form-control" required />
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6">
|
||||||
|
<label class="form-label">Categoria coperta</label>
|
||||||
|
<select v-model.number="teamForm.team_category_id" class="form-select" required>
|
||||||
|
<option :value="null">Seleziona categoria</option>
|
||||||
|
<option v-for="category in categories" :key="category.id" :value="category.id">
|
||||||
|
{{ category.name }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6">
|
||||||
|
<label class="form-label">Area</label>
|
||||||
|
<select v-model.number="teamForm.area_id" class="form-select">
|
||||||
|
<option :value="null">Tutte le aree</option>
|
||||||
|
<option v-for="area in areas" :key="area.id" :value="area.id">
|
||||||
|
{{ area.name }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6">
|
||||||
|
<label class="form-label">Descrizione</label>
|
||||||
|
<input v-model="teamForm.description" type="text" class="form-control" />
|
||||||
|
</div>
|
||||||
|
<div class="col-12">
|
||||||
|
<button type="submit" class="btn btn-primary" :disabled="isSavingTeam || !teamForm.name.trim() || !teamForm.team_category_id">
|
||||||
|
<span v-if="isSavingTeam" class="spinner-border spinner-border-sm me-2"></span>
|
||||||
|
Crea team
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="table-responsive report-table-wrapper">
|
||||||
|
<table class="table table-hover report-table mb-0">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Team</th>
|
||||||
|
<th>Categoria</th>
|
||||||
|
<th>Area</th>
|
||||||
|
<th>Stato</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr v-for="team in teams" :key="team.id">
|
||||||
|
<td class="report-table-id">#{{ team.id }}</td>
|
||||||
|
<td>
|
||||||
|
<strong>{{ team.name }}</strong>
|
||||||
|
<div v-if="team.description" class="small text-muted mt-1">{{ team.description }}</div>
|
||||||
|
</td>
|
||||||
|
<td>{{ team.category_name || '-' }}</td>
|
||||||
|
<td>{{ team.area_name || 'Tutte' }}</td>
|
||||||
|
<td>
|
||||||
|
<span class="badge" :class="team.active === false ? 'bg-secondary' : 'bg-success'">
|
||||||
|
{{ team.active === false ? 'Inattivo' : 'Attivo' }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="teams.length === 0">
|
||||||
|
<td colspan="5" class="text-muted">Nessun team configurato.</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -13,6 +13,7 @@ const { getUsers, updateUserBan, updateUserRoles } = useAdmin()
|
|||||||
const { data: usersRes, pending, refresh } = useAsyncData('admin-users', () => getUsers())
|
const { data: usersRes, pending, refresh } = useAsyncData('admin-users', () => getUsers())
|
||||||
|
|
||||||
const search = ref('')
|
const search = ref('')
|
||||||
|
const parseRoles = (roles?: string) => roles ? roles.split(',').map((r) => r.trim()).filter(Boolean) : []
|
||||||
|
|
||||||
const filteredUsers = computed(() => {
|
const filteredUsers = computed(() => {
|
||||||
if (!usersRes.value?.users) return []
|
if (!usersRes.value?.users) return []
|
||||||
@@ -47,7 +48,7 @@ const availableRoles = ['CITIZEN', 'OPERATOR', 'ADMIN']
|
|||||||
|
|
||||||
const openRoleModal = (user: any) => {
|
const openRoleModal = (user: any) => {
|
||||||
editingUserId.value = user.id
|
editingUserId.value = user.id
|
||||||
selectedRoles.value = user.roles ? user.roles.split(',').map((r: string) => r.trim()) : []
|
selectedRoles.value = parseRoles(user.roles)
|
||||||
}
|
}
|
||||||
|
|
||||||
const closeRoleModal = () => {
|
const closeRoleModal = () => {
|
||||||
@@ -118,8 +119,8 @@ const saveRoles = async () => {
|
|||||||
<small class="text-muted">{{ user.fiscal_code }}</small>
|
<small class="text-muted">{{ user.fiscal_code }}</small>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<span v-for="r in (user.roles ? user.roles.split(',') : [])" :key="r" class="badge bg-primary me-1">
|
<span v-for="r in parseRoles(user.roles)" :key="r" class="badge bg-primary me-1">
|
||||||
{{ r.trim() }}
|
{{ r }}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ user.points || 0 }}</td>
|
<td>{{ user.points || 0 }}</td>
|
||||||
|
|||||||
@@ -17,19 +17,22 @@ if (!reportId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { getReportDetail, getMessages, addMessage, flagMessage } = useReports()
|
const { getReportDetail, getMessages, addMessage, flagMessage } = useReports()
|
||||||
const { getInterventionSummary, updateReportStatus, assignTeam } = useOperator()
|
const { getInterventionSummary, updateReportStatus, assignTeam, getTeams } = useOperator()
|
||||||
const { user } = useAuth()
|
const { user } = useAuth()
|
||||||
|
|
||||||
// Dati principali
|
// Dati principali
|
||||||
const { data: reportData, refresh: refreshReport } = await useAsyncData(`op-report-${reportId}`, () => getReportDetail(reportId))
|
const { data: reportData, refresh: refreshReport } = await useAsyncData(`op-report-${reportId}`, () => getReportDetail(reportId))
|
||||||
const { data: messagesData, refresh: refreshMessages } = await useAsyncData(`op-messages-${reportId}`, () => getMessages(reportId))
|
const { data: messagesData, refresh: refreshMessages } = await useAsyncData(`op-messages-${reportId}`, () => getMessages(reportId))
|
||||||
const { data: summaryData, refresh: refreshSummary } = await useAsyncData(`op-summary-${reportId}`, () => getInterventionSummary(reportId))
|
const { data: summaryData, refresh: refreshSummary } = await useAsyncData(`op-summary-${reportId}`, () => getInterventionSummary(reportId))
|
||||||
|
const { data: teamsData } = await useAsyncData('operator-teams', () => getTeams())
|
||||||
|
|
||||||
const report = computed(() => (reportData.value as any)?.report)
|
const report = computed(() => (reportData.value as any)?.report)
|
||||||
const media = computed(() => (reportData.value as any)?.media || [])
|
const media = computed(() => (reportData.value as any)?.media || [])
|
||||||
const statusHistory = computed(() => (reportData.value as any)?.history || [])
|
const statusHistory = computed(() => (reportData.value as any)?.history || [])
|
||||||
const messages = computed(() => (messagesData.value as any)?.messages || [])
|
const messages = computed(() => (messagesData.value as any)?.messages || [])
|
||||||
const summary = computed(() => (summaryData.value as any)?.summary)
|
const summary = computed(() => (summaryData.value as any)?.summary)
|
||||||
|
const summaryMedia = computed(() => (summaryData.value as any)?.media || [])
|
||||||
|
const teams = computed(() => teamsData.value?.teams || [])
|
||||||
const statusMeta: Record<string, string> = {
|
const statusMeta: Record<string, string> = {
|
||||||
OPEN: 'Aperta',
|
OPEN: 'Aperta',
|
||||||
UNDER_REVIEW: 'In revisione',
|
UNDER_REVIEW: 'In revisione',
|
||||||
@@ -47,9 +50,7 @@ const isUpdatingStatus = ref(false)
|
|||||||
|
|
||||||
// Form Assegna Squadra
|
// Form Assegna Squadra
|
||||||
const isAssignModalOpen = ref(false)
|
const isAssignModalOpen = ref(false)
|
||||||
const teamName = ref('')
|
const selectedTeamId = ref<number | null>(null)
|
||||||
const assignNote = ref('')
|
|
||||||
const estimatedDate = ref('')
|
|
||||||
const isAssigning = ref(false)
|
const isAssigning = ref(false)
|
||||||
|
|
||||||
// Messaggi
|
// Messaggi
|
||||||
@@ -90,19 +91,15 @@ const handleStatusUpdate = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleAssignTeam = async () => {
|
const handleAssignTeam = async () => {
|
||||||
if (!teamName.value) return
|
if (!selectedTeamId.value) return
|
||||||
isAssigning.value = true
|
isAssigning.value = true
|
||||||
try {
|
try {
|
||||||
const res = await assignTeam(reportId, {
|
const res = await assignTeam(reportId, {
|
||||||
assigned_to_team: teamName.value,
|
team_id: selectedTeamId.value
|
||||||
estimated_resolution_date: estimatedDate.value || undefined,
|
|
||||||
internal_notes: assignNote.value || undefined
|
|
||||||
})
|
})
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
isAssignModalOpen.value = false
|
isAssignModalOpen.value = false
|
||||||
teamName.value = ''
|
selectedTeamId.value = null
|
||||||
assignNote.value = ''
|
|
||||||
estimatedDate.value = ''
|
|
||||||
await Promise.all([refreshReport(), refreshSummary()])
|
await Promise.all([refreshReport(), refreshSummary()])
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -152,6 +149,15 @@ const formatDate = (dateString: string) => {
|
|||||||
hour: '2-digit', minute: '2-digit'
|
hour: '2-digit', minute: '2-digit'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const latestCitizenMessage = computed(() => {
|
||||||
|
const reportUserId = report.value?.user_id
|
||||||
|
if (!reportUserId) return null
|
||||||
|
|
||||||
|
return [...messages.value]
|
||||||
|
.reverse()
|
||||||
|
.find((message) => message.user_id === reportUserId) || null
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -257,29 +263,31 @@ const formatDate = (dateString: string) => {
|
|||||||
<div class="report-sidebar">
|
<div class="report-sidebar">
|
||||||
<div class="card card-bg border-0 shadow-sm mb-4" v-if="summary">
|
<div class="card card-bg border-0 shadow-sm mb-4" v-if="summary">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h2 class="h6 mb-3">Riepilogo intervento</h2>
|
<h2 class="h6 mb-3">Quadro operativo</h2>
|
||||||
<ul class="report-summary-list list-unstyled mb-4">
|
<ul class="report-summary-list list-unstyled mb-4">
|
||||||
<li>
|
<li>
|
||||||
<span>Operatore</span>
|
<span>Operatore</span>
|
||||||
<strong>{{ summary.operator_id ? `#${summary.operator_id}` : 'Nessuno' }}</strong>
|
<strong>{{ summary.assigned_operator_id ? `#${summary.assigned_operator_id}` : 'Nessuno' }}</strong>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<span>Squadra</span>
|
<span>Team disponibili</span>
|
||||||
<strong>{{ summary.assigned_to_team || 'Nessuna' }}</strong>
|
<strong>{{ teams.length }}</strong>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<span>Data prevista</span>
|
<span>Allegati</span>
|
||||||
<strong>{{ summary.estimated_resolution_date ? formatDate(summary.estimated_resolution_date) : 'Non impostata' }}</strong>
|
<strong>{{ summaryMedia.length || media.length }}</strong>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="report-description">
|
<div class="report-description">
|
||||||
<h3 class="h6 mb-2">Note interne</h3>
|
<h3 class="h6 mb-2">Ultimo messaggio cittadino</h3>
|
||||||
<p class="small mb-0">{{ summary.internal_notes || 'Nessuna nota interna' }}</p>
|
<p class="small mb-0">
|
||||||
|
{{ latestCitizenMessage?.body || 'Nessun messaggio del cittadino disponibile.' }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body pt-0">
|
<div class="card-body pt-0">
|
||||||
<button class="btn btn-outline-primary w-100" @click="isAssignModalOpen = true">
|
<button class="btn btn-outline-primary w-100" @click="isAssignModalOpen = true" :disabled="teams.length === 0">
|
||||||
Gestisci Squadra e Note
|
Assegna team
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -342,20 +350,21 @@ const formatDate = (dateString: string) => {
|
|||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form @submit.prevent="handleAssignTeam">
|
<form @submit.prevent="handleAssignTeam">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Squadra / Ditta Incaricata</label>
|
<label class="form-label">Team incaricato</label>
|
||||||
<input type="text" class="form-control" v-model="teamName" placeholder="Es. Squadra Verde SPA" required />
|
<select v-model.number="selectedTeamId" class="form-select" required>
|
||||||
</div>
|
<option :value="null">Seleziona team</option>
|
||||||
<div class="mb-3">
|
<option v-for="team in teams" :key="team.id" :value="team.id">
|
||||||
<label class="form-label">Data Prevista Risoluzione (opzionale)</label>
|
{{ team.name }}<template v-if="team.category_name"> · {{ team.category_name }}</template>
|
||||||
<input type="date" class="form-control" v-model="estimatedDate" />
|
<template v-if="team.area_name"> · {{ team.area_name }}</template>
|
||||||
</div>
|
</option>
|
||||||
<div class="mb-3">
|
</select>
|
||||||
<label class="form-label">Note Interne (private)</label>
|
<small v-if="teams.length === 0" class="form-text text-danger">
|
||||||
<textarea class="form-control" v-model="assignNote" rows="3" placeholder="Note ad uso interno, non visibili al cittadino..."></textarea>
|
Nessun team attivo disponibile.
|
||||||
|
</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex justify-content-end gap-2 mt-4">
|
<div class="d-flex justify-content-end gap-2 mt-4">
|
||||||
<button type="button" class="btn btn-outline-secondary" @click="isAssignModalOpen = false">Annulla</button>
|
<button type="button" class="btn btn-outline-secondary" @click="isAssignModalOpen = false">Annulla</button>
|
||||||
<button type="submit" class="btn btn-primary" :disabled="isAssigning || !teamName.trim()">
|
<button type="submit" class="btn btn-primary" :disabled="isAssigning || !selectedTeamId">
|
||||||
<span v-if="isAssigning" class="spinner-border spinner-border-sm me-2"></span>
|
<span v-if="isAssigning" class="spinner-border spinner-border-sm me-2"></span>
|
||||||
Salva Assegnazione
|
Salva Assegnazione
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ definePageMeta({
|
|||||||
useHead({ title: 'Nuova segnalazione - Visione' })
|
useHead({ title: 'Nuova segnalazione - Visione' })
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { createReport, uploadMedia } = useReports()
|
const { createReport, uploadMedia, getCategories } = useReports()
|
||||||
const { getCategories } = useAdmin()
|
|
||||||
const { data: categoriesData } = await useAsyncData('categories', () => getCategories())
|
const { data: categoriesData } = await useAsyncData('categories', () => getCategories())
|
||||||
const categories = computed(() => categoriesData.value?.categories || [])
|
const categories = computed(() => categoriesData.value?.categories || [])
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
export default defineNuxtPlugin(async () => {
|
export default defineNuxtPlugin(async () => {
|
||||||
const auth = useAuth()
|
const auth = useAuth()
|
||||||
|
const currentPath = useNuxtApp().$router.currentRoute.value.path
|
||||||
|
|
||||||
if ((auth.token.value || auth.tokenState.value) && !auth.user.value) {
|
if ((auth.token.value || auth.tokenState.value) && !auth.user.value) {
|
||||||
try {
|
try {
|
||||||
await auth.syncUser()
|
await auth.syncUser({ currentPath })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const status = (error as any)?.statusCode || (error as any)?.status || (error as any)?.response?.status
|
const status = (error as any)?.statusCode || (error as any)?.status || (error as any)?.response?.status
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user