| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691 |
- /**
- * Dashboard Manutenzioni
- */
-
- 'use strict';
-
- document.addEventListener('DOMContentLoaded', function (e) {
- let cardColor, headingColor, legendColor, labelColor, shadeColor, borderColor, fontFamily;
- cardColor = config.colors.cardColor;
- headingColor = config.colors.headingColor;
- legendColor = config.colors.bodyColor;
- labelColor = config.colors.textMuted;
- borderColor = config.colors.borderColor;
- fontFamily = config.fontFamily;
-
- // Verifica se i dati della dashboard sono disponibili
- let dashboardData;
- if (typeof window.dashboardData !== 'undefined') {
- dashboardData = window.dashboardData;
- } else if (typeof dashboardData !== 'undefined') {
- dashboardData = dashboardData;
- } else {
- console.warn('Dashboard data non disponibile');
- return;
- }
-
- // Debug: mostra i dati nella console
- console.log('Dashboard Data:', dashboardData);
-
- // Grafico Segnalazioni nel Tempo
- const segnalazioniTempoChartEl = document.querySelector('#segnalazioniTempoChart');
- const hasValidTempoData =
- dashboardData.labelsTempo &&
- dashboardData.datiTempo &&
- Array.isArray(dashboardData.labelsTempo) &&
- Array.isArray(dashboardData.datiTempo) &&
- dashboardData.labelsTempo.length > 0 &&
- dashboardData.datiTempo.length > 0 &&
- !dashboardData.labelsTempo.includes('Nessun dato') &&
- dashboardData.datiTempo.some(val => val > 0);
-
- if (segnalazioniTempoChartEl && hasValidTempoData) {
- const segnalazioniTempoChartConfig = {
- chart: {
- height: 350,
- type: 'line',
- toolbar: { show: false },
- zoom: { enabled: false }
- },
- colors: [config.colors.primary],
- stroke: {
- curve: 'smooth',
- width: 3
- },
- series: [
- {
- name: 'Segnalazioni',
- data: dashboardData.datiTempo
- }
- ],
- xaxis: {
- categories: dashboardData.labelsTempo,
- labels: {
- style: {
- fontSize: '13px',
- fontFamily: fontFamily,
- colors: labelColor
- }
- },
- axisTicks: {
- show: false
- },
- axisBorder: {
- show: false
- }
- },
- yaxis: {
- labels: {
- style: {
- fontSize: '13px',
- fontFamily: fontFamily,
- colors: labelColor
- }
- }
- },
- grid: {
- borderColor: borderColor,
- strokeDashArray: 4,
- padding: {
- top: -20,
- bottom: -10,
- left: 0
- }
- },
- tooltip: {
- theme: 'dark'
- },
- states: {
- hover: {
- filter: {
- type: 'none'
- }
- },
- active: {
- filter: {
- type: 'none'
- }
- }
- }
- };
- const segnalazioniTempoChart = new ApexCharts(segnalazioniTempoChartEl, segnalazioniTempoChartConfig);
- segnalazioniTempoChart.render();
- } else if (segnalazioniTempoChartEl) {
- segnalazioniTempoChartEl.innerHTML =
- '<div class="text-center p-4 text-muted"><i class="bx bx-info-circle me-2"></i>Nessun dato disponibile per questo periodo</div>';
- console.log('Segnalazioni nel Tempo: dati non validi', dashboardData.labelsTempo, dashboardData.datiTempo);
- }
-
- // Grafico Distribuzione per Stato (Torta)
- const distribuzioneStatoChartEl = document.querySelector('#distribuzioneStatoChart');
- if (
- distribuzioneStatoChartEl &&
- dashboardData.labelsStato &&
- dashboardData.datiStato &&
- Array.isArray(dashboardData.labelsStato) &&
- Array.isArray(dashboardData.datiStato) &&
- dashboardData.labelsStato.length > 0 &&
- dashboardData.datiStato.length > 0 &&
- !dashboardData.labelsStato.includes('Nessun dato')
- ) {
- const distribuzioneStatoChartConfig = {
- chart: {
- height: 350,
- type: 'donut'
- },
- labels: dashboardData.labelsStato,
- series: dashboardData.datiStato,
- colors: [config.colors.primary, config.colors.warning, config.colors.info, config.colors.success],
- legend: {
- position: 'bottom',
- labels: {
- colors: headingColor,
- useSeriesColors: false,
- fontSize: '13px',
- fontFamily: fontFamily
- }
- },
- plotOptions: {
- pie: {
- donut: {
- size: '75%'
- }
- }
- }
- };
- const distribuzioneStatoChart = new ApexCharts(distribuzioneStatoChartEl, distribuzioneStatoChartConfig);
- distribuzioneStatoChart.render();
- } else if (distribuzioneStatoChartEl) {
- distribuzioneStatoChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
- }
-
- // Grafico Distribuzione per Priorità (Barre)
- const distribuzionePrioritaChartEl = document.querySelector('#distribuzionePrioritaChart');
- if (
- distribuzionePrioritaChartEl &&
- dashboardData.labelsPriorita &&
- dashboardData.datiPriorita &&
- Array.isArray(dashboardData.labelsPriorita) &&
- Array.isArray(dashboardData.datiPriorita) &&
- dashboardData.labelsPriorita.length > 0 &&
- dashboardData.datiPriorita.length > 0 &&
- !dashboardData.labelsPriorita.includes('Nessun dato')
- ) {
- const distribuzionePrioritaChartConfig = {
- chart: {
- height: 300,
- type: 'bar',
- toolbar: { show: false }
- },
- colors: [config.colors.danger, config.colors.warning, config.colors.info, config.colors.success],
- plotOptions: {
- bar: {
- horizontal: false,
- columnWidth: '55%',
- borderRadius: 8,
- startingShape: 'rounded',
- endingShape: 'rounded',
- borderRadiusApplication: 'around'
- }
- },
- dataLabels: {
- enabled: false
- },
- series: [
- {
- name: 'Segnalazioni',
- data: dashboardData.datiPriorita
- }
- ],
- xaxis: {
- categories: dashboardData.labelsPriorita,
- labels: {
- style: {
- fontSize: '13px',
- fontFamily: fontFamily,
- colors: labelColor
- }
- },
- axisTicks: {
- show: false
- },
- axisBorder: {
- show: false
- }
- },
- yaxis: {
- labels: {
- style: {
- fontSize: '13px',
- fontFamily: fontFamily,
- colors: labelColor
- }
- }
- },
- grid: {
- borderColor: borderColor,
- strokeDashArray: 4,
- padding: {
- top: -20,
- bottom: -10,
- left: 0
- }
- },
- states: {
- hover: {
- filter: {
- type: 'none'
- }
- },
- active: {
- filter: {
- type: 'none'
- }
- }
- }
- };
- const distribuzionePrioritaChart = new ApexCharts(distribuzionePrioritaChartEl, distribuzionePrioritaChartConfig);
- distribuzionePrioritaChart.render();
- } else if (distribuzionePrioritaChartEl) {
- distribuzionePrioritaChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
- }
-
- // Grafico Segnalazioni per Reparto (Barre)
- const segnalazioniRepartoChartEl = document.querySelector('#segnalazioniRepartoChart');
- if (
- segnalazioniRepartoChartEl &&
- dashboardData.labelsReparto &&
- dashboardData.datiReparto &&
- Array.isArray(dashboardData.labelsReparto) &&
- Array.isArray(dashboardData.datiReparto) &&
- dashboardData.labelsReparto.length > 0 &&
- dashboardData.datiReparto.length > 0 &&
- !dashboardData.labelsReparto.includes('Nessun dato')
- ) {
- const segnalazioniRepartoChartConfig = {
- chart: {
- height: 300,
- type: 'bar',
- toolbar: { show: false }
- },
- colors: [config.colors.primary],
- plotOptions: {
- bar: {
- horizontal: false,
- columnWidth: '55%',
- borderRadius: 8,
- startingShape: 'rounded',
- endingShape: 'rounded',
- borderRadiusApplication: 'around'
- }
- },
- dataLabels: {
- enabled: false
- },
- series: [
- {
- name: 'Segnalazioni',
- data: dashboardData.datiReparto
- }
- ],
- xaxis: {
- categories: dashboardData.labelsReparto,
- labels: {
- style: {
- fontSize: '13px',
- fontFamily: fontFamily,
- colors: labelColor
- },
- rotate: -45,
- rotateAlways: true
- },
- axisTicks: {
- show: false
- },
- axisBorder: {
- show: false
- }
- },
- yaxis: {
- labels: {
- style: {
- fontSize: '13px',
- fontFamily: fontFamily,
- colors: labelColor
- }
- }
- },
- grid: {
- borderColor: borderColor,
- strokeDashArray: 4,
- padding: {
- top: -20,
- bottom: -10,
- left: 0
- }
- },
- states: {
- hover: {
- filter: {
- type: 'none'
- }
- },
- active: {
- filter: {
- type: 'none'
- }
- }
- }
- };
- const segnalazioniRepartoChart = new ApexCharts(segnalazioniRepartoChartEl, segnalazioniRepartoChartConfig);
- segnalazioniRepartoChart.render();
- } else if (segnalazioniRepartoChartEl) {
- segnalazioniRepartoChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
- }
-
- // Grafico Top Manutentori (Barre Orizzontali)
- const topManutentoriChartEl = document.querySelector('#topManutentoriChart');
- if (
- topManutentoriChartEl &&
- dashboardData.labelsManutentori &&
- dashboardData.datiManutentori &&
- Array.isArray(dashboardData.labelsManutentori) &&
- Array.isArray(dashboardData.datiManutentori) &&
- dashboardData.labelsManutentori.length > 0 &&
- dashboardData.datiManutentori.length > 0 &&
- !dashboardData.labelsManutentori.includes('Nessun dato')
- ) {
- const topManutentoriChartConfig = {
- chart: {
- height: 300,
- type: 'bar',
- toolbar: { show: false }
- },
- colors: [config.colors.success],
- plotOptions: {
- bar: {
- horizontal: true,
- barHeight: '70%',
- borderRadius: 8,
- startingShape: 'rounded',
- endingShape: 'rounded',
- borderRadiusApplication: 'around'
- }
- },
- dataLabels: {
- enabled: true
- },
- series: [
- {
- name: 'Segnalazioni Risolte',
- data: dashboardData.datiManutentori
- }
- ],
- xaxis: {
- categories: dashboardData.labelsManutentori,
- labels: {
- style: {
- fontSize: '13px',
- fontFamily: fontFamily,
- colors: labelColor
- }
- },
- axisTicks: {
- show: false
- },
- axisBorder: {
- show: false
- }
- },
- yaxis: {
- labels: {
- style: {
- fontSize: '13px',
- fontFamily: fontFamily,
- colors: labelColor
- }
- }
- },
- grid: {
- borderColor: borderColor,
- strokeDashArray: 4,
- padding: {
- top: -20,
- bottom: -10,
- left: 0
- }
- },
- states: {
- hover: {
- filter: {
- type: 'none'
- }
- },
- active: {
- filter: {
- type: 'none'
- }
- }
- }
- };
- const topManutentoriChart = new ApexCharts(topManutentoriChartEl, topManutentoriChartConfig);
- topManutentoriChart.render();
- } else if (topManutentoriChartEl) {
- topManutentoriChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
- }
-
- // Grafico Costi per Reparto (Barre)
- const costiRepartoChartEl = document.querySelector('#costiRepartoChart');
- if (
- costiRepartoChartEl &&
- dashboardData.labelsCostiReparto &&
- dashboardData.datiCostiReparto &&
- Array.isArray(dashboardData.labelsCostiReparto) &&
- Array.isArray(dashboardData.datiCostiReparto) &&
- dashboardData.labelsCostiReparto.length > 0 &&
- dashboardData.datiCostiReparto.length > 0 &&
- !dashboardData.labelsCostiReparto.includes('Nessun dato')
- ) {
- const costiRepartoChartConfig = {
- chart: {
- height: 350,
- type: 'bar',
- toolbar: { show: false }
- },
- colors: [config.colors.warning],
- plotOptions: {
- bar: {
- horizontal: false,
- columnWidth: '55%',
- borderRadius: 8,
- startingShape: 'rounded',
- endingShape: 'rounded',
- borderRadiusApplication: 'around'
- }
- },
- dataLabels: {
- enabled: false
- },
- series: [
- {
- name: 'Costi (€)',
- data: dashboardData.datiCostiReparto
- }
- ],
- xaxis: {
- categories: dashboardData.labelsCostiReparto,
- labels: {
- style: {
- fontSize: '13px',
- fontFamily: fontFamily,
- colors: labelColor
- },
- rotate: -45,
- rotateAlways: true
- },
- axisTicks: {
- show: false
- },
- axisBorder: {
- show: false
- }
- },
- yaxis: {
- labels: {
- style: {
- fontSize: '13px',
- fontFamily: fontFamily,
- colors: labelColor
- },
- formatter: function (val) {
- return '€' + val.toFixed(2);
- }
- }
- },
- grid: {
- borderColor: borderColor,
- strokeDashArray: 4,
- padding: {
- top: -20,
- bottom: -10,
- left: 0
- }
- },
- states: {
- hover: {
- filter: {
- type: 'none'
- }
- },
- active: {
- filter: {
- type: 'none'
- }
- }
- },
- tooltip: {
- y: {
- formatter: function (val) {
- return '€' + val.toFixed(2);
- }
- }
- }
- };
- const costiRepartoChart = new ApexCharts(costiRepartoChartEl, costiRepartoChartConfig);
- costiRepartoChart.render();
- } else if (costiRepartoChartEl) {
- costiRepartoChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
- }
-
- // Grafico Distribuzione per Tipo (Torta)
- const distribuzioneTipoChartEl = document.querySelector('#distribuzioneTipoChart');
- if (
- distribuzioneTipoChartEl &&
- dashboardData.labelsTipo &&
- dashboardData.datiTipo &&
- Array.isArray(dashboardData.labelsTipo) &&
- Array.isArray(dashboardData.datiTipo) &&
- dashboardData.labelsTipo.length > 0 &&
- dashboardData.datiTipo.length > 0 &&
- !dashboardData.labelsTipo.includes('Nessun dato')
- ) {
- const distribuzioneTipoChartConfig = {
- chart: {
- height: 300,
- type: 'donut'
- },
- labels: dashboardData.labelsTipo,
- series: dashboardData.datiTipo,
- colors: [
- config.colors.primary,
- config.colors.success,
- config.colors.warning,
- config.colors.info,
- config.colors.danger
- ],
- legend: {
- position: 'bottom',
- labels: {
- colors: headingColor,
- useSeriesColors: false,
- fontSize: '13px',
- fontFamily: fontFamily
- }
- },
- plotOptions: {
- pie: {
- donut: {
- size: '75%'
- }
- }
- }
- };
- const distribuzioneTipoChart = new ApexCharts(distribuzioneTipoChartEl, distribuzioneTipoChartConfig);
- distribuzioneTipoChart.render();
- } else if (distribuzioneTipoChartEl) {
- distribuzioneTipoChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
- }
-
- // Grafico Costi per Tipo (Barre)
- const costiTipoChartEl = document.querySelector('#costiTipoChart');
- if (
- costiTipoChartEl &&
- dashboardData.labelsCostiTipo &&
- dashboardData.datiCostiTipo &&
- Array.isArray(dashboardData.labelsCostiTipo) &&
- Array.isArray(dashboardData.datiCostiTipo) &&
- dashboardData.labelsCostiTipo.length > 0 &&
- dashboardData.datiCostiTipo.length > 0 &&
- !dashboardData.labelsCostiTipo.includes('Nessun dato')
- ) {
- const costiTipoChartConfig = {
- chart: {
- height: 350,
- type: 'bar',
- toolbar: { show: false }
- },
- colors: [config.colors.success],
- plotOptions: {
- bar: {
- horizontal: false,
- columnWidth: '55%',
- borderRadius: 8,
- startingShape: 'rounded',
- endingShape: 'rounded',
- borderRadiusApplication: 'around'
- }
- },
- dataLabels: {
- enabled: false
- },
- series: [
- {
- name: 'Costi (€)',
- data: dashboardData.datiCostiTipo
- }
- ],
- xaxis: {
- categories: dashboardData.labelsCostiTipo,
- labels: {
- style: {
- fontSize: '13px',
- fontFamily: fontFamily,
- colors: labelColor
- },
- rotate: -45,
- rotateAlways: true
- },
- axisTicks: {
- show: false
- },
- axisBorder: {
- show: false
- }
- },
- yaxis: {
- labels: {
- style: {
- fontSize: '13px',
- fontFamily: fontFamily,
- colors: labelColor
- },
- formatter: function (val) {
- return '€' + val.toFixed(2);
- }
- }
- },
- grid: {
- borderColor: borderColor,
- strokeDashArray: 4,
- padding: {
- top: -20,
- bottom: -10,
- left: 0
- }
- },
- states: {
- hover: {
- filter: {
- type: 'none'
- }
- },
- active: {
- filter: {
- type: 'none'
- }
- }
- },
- tooltip: {
- y: {
- formatter: function (val) {
- return '€' + val.toFixed(2);
- }
- }
- }
- };
- const costiTipoChart = new ApexCharts(costiTipoChartEl, costiTipoChartConfig);
- costiTipoChart.render();
- } else if (costiTipoChartEl) {
- costiTipoChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
- }
- });
|