Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

dashboards-manutenzioni.js 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /**
  2. * Dashboard Manutenzioni
  3. */
  4. 'use strict';
  5. document.addEventListener('DOMContentLoaded', function (e) {
  6. let cardColor, headingColor, legendColor, labelColor, shadeColor, borderColor, fontFamily;
  7. cardColor = config.colors.cardColor;
  8. headingColor = config.colors.headingColor;
  9. legendColor = config.colors.bodyColor;
  10. labelColor = config.colors.textMuted;
  11. borderColor = config.colors.borderColor;
  12. fontFamily = config.fontFamily;
  13. // Verifica se i dati della dashboard sono disponibili
  14. let dashboardData;
  15. if (typeof window.dashboardData !== 'undefined') {
  16. dashboardData = window.dashboardData;
  17. } else if (typeof dashboardData !== 'undefined') {
  18. dashboardData = dashboardData;
  19. } else {
  20. console.warn('Dashboard data non disponibile');
  21. return;
  22. }
  23. // Debug: mostra i dati nella console
  24. console.log('Dashboard Data:', dashboardData);
  25. // Grafico Segnalazioni nel Tempo
  26. const segnalazioniTempoChartEl = document.querySelector('#segnalazioniTempoChart');
  27. const hasValidTempoData =
  28. dashboardData.labelsTempo &&
  29. dashboardData.datiTempo &&
  30. Array.isArray(dashboardData.labelsTempo) &&
  31. Array.isArray(dashboardData.datiTempo) &&
  32. dashboardData.labelsTempo.length > 0 &&
  33. dashboardData.datiTempo.length > 0 &&
  34. !dashboardData.labelsTempo.includes('Nessun dato') &&
  35. dashboardData.datiTempo.some(val => val > 0);
  36. if (segnalazioniTempoChartEl && hasValidTempoData) {
  37. const segnalazioniTempoChartConfig = {
  38. chart: {
  39. height: 350,
  40. type: 'line',
  41. toolbar: { show: false },
  42. zoom: { enabled: false }
  43. },
  44. colors: [config.colors.primary],
  45. stroke: {
  46. curve: 'smooth',
  47. width: 3
  48. },
  49. series: [
  50. {
  51. name: 'Segnalazioni',
  52. data: dashboardData.datiTempo
  53. }
  54. ],
  55. xaxis: {
  56. categories: dashboardData.labelsTempo,
  57. labels: {
  58. style: {
  59. fontSize: '13px',
  60. fontFamily: fontFamily,
  61. colors: labelColor
  62. }
  63. },
  64. axisTicks: {
  65. show: false
  66. },
  67. axisBorder: {
  68. show: false
  69. }
  70. },
  71. yaxis: {
  72. labels: {
  73. style: {
  74. fontSize: '13px',
  75. fontFamily: fontFamily,
  76. colors: labelColor
  77. }
  78. }
  79. },
  80. grid: {
  81. borderColor: borderColor,
  82. strokeDashArray: 4,
  83. padding: {
  84. top: -20,
  85. bottom: -10,
  86. left: 0
  87. }
  88. },
  89. tooltip: {
  90. theme: 'dark'
  91. },
  92. states: {
  93. hover: {
  94. filter: {
  95. type: 'none'
  96. }
  97. },
  98. active: {
  99. filter: {
  100. type: 'none'
  101. }
  102. }
  103. }
  104. };
  105. const segnalazioniTempoChart = new ApexCharts(segnalazioniTempoChartEl, segnalazioniTempoChartConfig);
  106. segnalazioniTempoChart.render();
  107. } else if (segnalazioniTempoChartEl) {
  108. segnalazioniTempoChartEl.innerHTML =
  109. '<div class="text-center p-4 text-muted"><i class="bx bx-info-circle me-2"></i>Nessun dato disponibile per questo periodo</div>';
  110. console.log('Segnalazioni nel Tempo: dati non validi', dashboardData.labelsTempo, dashboardData.datiTempo);
  111. }
  112. // Grafico Distribuzione per Stato (Torta)
  113. const distribuzioneStatoChartEl = document.querySelector('#distribuzioneStatoChart');
  114. if (
  115. distribuzioneStatoChartEl &&
  116. dashboardData.labelsStato &&
  117. dashboardData.datiStato &&
  118. Array.isArray(dashboardData.labelsStato) &&
  119. Array.isArray(dashboardData.datiStato) &&
  120. dashboardData.labelsStato.length > 0 &&
  121. dashboardData.datiStato.length > 0 &&
  122. !dashboardData.labelsStato.includes('Nessun dato')
  123. ) {
  124. const distribuzioneStatoChartConfig = {
  125. chart: {
  126. height: 350,
  127. type: 'donut'
  128. },
  129. labels: dashboardData.labelsStato,
  130. series: dashboardData.datiStato,
  131. colors: [config.colors.primary, config.colors.warning, config.colors.info, config.colors.success],
  132. legend: {
  133. position: 'bottom',
  134. labels: {
  135. colors: headingColor,
  136. useSeriesColors: false,
  137. fontSize: '13px',
  138. fontFamily: fontFamily
  139. }
  140. },
  141. plotOptions: {
  142. pie: {
  143. donut: {
  144. size: '75%'
  145. }
  146. }
  147. }
  148. };
  149. const distribuzioneStatoChart = new ApexCharts(distribuzioneStatoChartEl, distribuzioneStatoChartConfig);
  150. distribuzioneStatoChart.render();
  151. } else if (distribuzioneStatoChartEl) {
  152. distribuzioneStatoChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
  153. }
  154. // Grafico Distribuzione per Priorità (Barre)
  155. const distribuzionePrioritaChartEl = document.querySelector('#distribuzionePrioritaChart');
  156. if (
  157. distribuzionePrioritaChartEl &&
  158. dashboardData.labelsPriorita &&
  159. dashboardData.datiPriorita &&
  160. Array.isArray(dashboardData.labelsPriorita) &&
  161. Array.isArray(dashboardData.datiPriorita) &&
  162. dashboardData.labelsPriorita.length > 0 &&
  163. dashboardData.datiPriorita.length > 0 &&
  164. !dashboardData.labelsPriorita.includes('Nessun dato')
  165. ) {
  166. const distribuzionePrioritaChartConfig = {
  167. chart: {
  168. height: 300,
  169. type: 'bar',
  170. toolbar: { show: false }
  171. },
  172. colors: [config.colors.danger, config.colors.warning, config.colors.info, config.colors.success],
  173. plotOptions: {
  174. bar: {
  175. horizontal: false,
  176. columnWidth: '55%',
  177. borderRadius: 8,
  178. startingShape: 'rounded',
  179. endingShape: 'rounded',
  180. borderRadiusApplication: 'around'
  181. }
  182. },
  183. dataLabels: {
  184. enabled: false
  185. },
  186. series: [
  187. {
  188. name: 'Segnalazioni',
  189. data: dashboardData.datiPriorita
  190. }
  191. ],
  192. xaxis: {
  193. categories: dashboardData.labelsPriorita,
  194. labels: {
  195. style: {
  196. fontSize: '13px',
  197. fontFamily: fontFamily,
  198. colors: labelColor
  199. }
  200. },
  201. axisTicks: {
  202. show: false
  203. },
  204. axisBorder: {
  205. show: false
  206. }
  207. },
  208. yaxis: {
  209. labels: {
  210. style: {
  211. fontSize: '13px',
  212. fontFamily: fontFamily,
  213. colors: labelColor
  214. }
  215. }
  216. },
  217. grid: {
  218. borderColor: borderColor,
  219. strokeDashArray: 4,
  220. padding: {
  221. top: -20,
  222. bottom: -10,
  223. left: 0
  224. }
  225. },
  226. states: {
  227. hover: {
  228. filter: {
  229. type: 'none'
  230. }
  231. },
  232. active: {
  233. filter: {
  234. type: 'none'
  235. }
  236. }
  237. }
  238. };
  239. const distribuzionePrioritaChart = new ApexCharts(distribuzionePrioritaChartEl, distribuzionePrioritaChartConfig);
  240. distribuzionePrioritaChart.render();
  241. } else if (distribuzionePrioritaChartEl) {
  242. distribuzionePrioritaChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
  243. }
  244. // Grafico Segnalazioni per Reparto (Barre)
  245. const segnalazioniRepartoChartEl = document.querySelector('#segnalazioniRepartoChart');
  246. if (
  247. segnalazioniRepartoChartEl &&
  248. dashboardData.labelsReparto &&
  249. dashboardData.datiReparto &&
  250. Array.isArray(dashboardData.labelsReparto) &&
  251. Array.isArray(dashboardData.datiReparto) &&
  252. dashboardData.labelsReparto.length > 0 &&
  253. dashboardData.datiReparto.length > 0 &&
  254. !dashboardData.labelsReparto.includes('Nessun dato')
  255. ) {
  256. const segnalazioniRepartoChartConfig = {
  257. chart: {
  258. height: 300,
  259. type: 'bar',
  260. toolbar: { show: false }
  261. },
  262. colors: [config.colors.primary],
  263. plotOptions: {
  264. bar: {
  265. horizontal: false,
  266. columnWidth: '55%',
  267. borderRadius: 8,
  268. startingShape: 'rounded',
  269. endingShape: 'rounded',
  270. borderRadiusApplication: 'around'
  271. }
  272. },
  273. dataLabels: {
  274. enabled: false
  275. },
  276. series: [
  277. {
  278. name: 'Segnalazioni',
  279. data: dashboardData.datiReparto
  280. }
  281. ],
  282. xaxis: {
  283. categories: dashboardData.labelsReparto,
  284. labels: {
  285. style: {
  286. fontSize: '13px',
  287. fontFamily: fontFamily,
  288. colors: labelColor
  289. },
  290. rotate: -45,
  291. rotateAlways: true
  292. },
  293. axisTicks: {
  294. show: false
  295. },
  296. axisBorder: {
  297. show: false
  298. }
  299. },
  300. yaxis: {
  301. labels: {
  302. style: {
  303. fontSize: '13px',
  304. fontFamily: fontFamily,
  305. colors: labelColor
  306. }
  307. }
  308. },
  309. grid: {
  310. borderColor: borderColor,
  311. strokeDashArray: 4,
  312. padding: {
  313. top: -20,
  314. bottom: -10,
  315. left: 0
  316. }
  317. },
  318. states: {
  319. hover: {
  320. filter: {
  321. type: 'none'
  322. }
  323. },
  324. active: {
  325. filter: {
  326. type: 'none'
  327. }
  328. }
  329. }
  330. };
  331. const segnalazioniRepartoChart = new ApexCharts(segnalazioniRepartoChartEl, segnalazioniRepartoChartConfig);
  332. segnalazioniRepartoChart.render();
  333. } else if (segnalazioniRepartoChartEl) {
  334. segnalazioniRepartoChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
  335. }
  336. // Grafico Top Manutentori (Barre Orizzontali)
  337. const topManutentoriChartEl = document.querySelector('#topManutentoriChart');
  338. if (
  339. topManutentoriChartEl &&
  340. dashboardData.labelsManutentori &&
  341. dashboardData.datiManutentori &&
  342. Array.isArray(dashboardData.labelsManutentori) &&
  343. Array.isArray(dashboardData.datiManutentori) &&
  344. dashboardData.labelsManutentori.length > 0 &&
  345. dashboardData.datiManutentori.length > 0 &&
  346. !dashboardData.labelsManutentori.includes('Nessun dato')
  347. ) {
  348. const topManutentoriChartConfig = {
  349. chart: {
  350. height: 300,
  351. type: 'bar',
  352. toolbar: { show: false }
  353. },
  354. colors: [config.colors.success],
  355. plotOptions: {
  356. bar: {
  357. horizontal: true,
  358. barHeight: '70%',
  359. borderRadius: 8,
  360. startingShape: 'rounded',
  361. endingShape: 'rounded',
  362. borderRadiusApplication: 'around'
  363. }
  364. },
  365. dataLabels: {
  366. enabled: true
  367. },
  368. series: [
  369. {
  370. name: 'Segnalazioni Risolte',
  371. data: dashboardData.datiManutentori
  372. }
  373. ],
  374. xaxis: {
  375. categories: dashboardData.labelsManutentori,
  376. labels: {
  377. style: {
  378. fontSize: '13px',
  379. fontFamily: fontFamily,
  380. colors: labelColor
  381. }
  382. },
  383. axisTicks: {
  384. show: false
  385. },
  386. axisBorder: {
  387. show: false
  388. }
  389. },
  390. yaxis: {
  391. labels: {
  392. style: {
  393. fontSize: '13px',
  394. fontFamily: fontFamily,
  395. colors: labelColor
  396. }
  397. }
  398. },
  399. grid: {
  400. borderColor: borderColor,
  401. strokeDashArray: 4,
  402. padding: {
  403. top: -20,
  404. bottom: -10,
  405. left: 0
  406. }
  407. },
  408. states: {
  409. hover: {
  410. filter: {
  411. type: 'none'
  412. }
  413. },
  414. active: {
  415. filter: {
  416. type: 'none'
  417. }
  418. }
  419. }
  420. };
  421. const topManutentoriChart = new ApexCharts(topManutentoriChartEl, topManutentoriChartConfig);
  422. topManutentoriChart.render();
  423. } else if (topManutentoriChartEl) {
  424. topManutentoriChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
  425. }
  426. // Grafico Costi per Reparto (Barre)
  427. const costiRepartoChartEl = document.querySelector('#costiRepartoChart');
  428. if (
  429. costiRepartoChartEl &&
  430. dashboardData.labelsCostiReparto &&
  431. dashboardData.datiCostiReparto &&
  432. Array.isArray(dashboardData.labelsCostiReparto) &&
  433. Array.isArray(dashboardData.datiCostiReparto) &&
  434. dashboardData.labelsCostiReparto.length > 0 &&
  435. dashboardData.datiCostiReparto.length > 0 &&
  436. !dashboardData.labelsCostiReparto.includes('Nessun dato')
  437. ) {
  438. const costiRepartoChartConfig = {
  439. chart: {
  440. height: 350,
  441. type: 'bar',
  442. toolbar: { show: false }
  443. },
  444. colors: [config.colors.warning],
  445. plotOptions: {
  446. bar: {
  447. horizontal: false,
  448. columnWidth: '55%',
  449. borderRadius: 8,
  450. startingShape: 'rounded',
  451. endingShape: 'rounded',
  452. borderRadiusApplication: 'around'
  453. }
  454. },
  455. dataLabels: {
  456. enabled: false
  457. },
  458. series: [
  459. {
  460. name: 'Costi (€)',
  461. data: dashboardData.datiCostiReparto
  462. }
  463. ],
  464. xaxis: {
  465. categories: dashboardData.labelsCostiReparto,
  466. labels: {
  467. style: {
  468. fontSize: '13px',
  469. fontFamily: fontFamily,
  470. colors: labelColor
  471. },
  472. rotate: -45,
  473. rotateAlways: true
  474. },
  475. axisTicks: {
  476. show: false
  477. },
  478. axisBorder: {
  479. show: false
  480. }
  481. },
  482. yaxis: {
  483. labels: {
  484. style: {
  485. fontSize: '13px',
  486. fontFamily: fontFamily,
  487. colors: labelColor
  488. },
  489. formatter: function (val) {
  490. return '€' + val.toFixed(2);
  491. }
  492. }
  493. },
  494. grid: {
  495. borderColor: borderColor,
  496. strokeDashArray: 4,
  497. padding: {
  498. top: -20,
  499. bottom: -10,
  500. left: 0
  501. }
  502. },
  503. states: {
  504. hover: {
  505. filter: {
  506. type: 'none'
  507. }
  508. },
  509. active: {
  510. filter: {
  511. type: 'none'
  512. }
  513. }
  514. },
  515. tooltip: {
  516. y: {
  517. formatter: function (val) {
  518. return '€' + val.toFixed(2);
  519. }
  520. }
  521. }
  522. };
  523. const costiRepartoChart = new ApexCharts(costiRepartoChartEl, costiRepartoChartConfig);
  524. costiRepartoChart.render();
  525. } else if (costiRepartoChartEl) {
  526. costiRepartoChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
  527. }
  528. // Grafico Distribuzione per Tipo (Torta)
  529. const distribuzioneTipoChartEl = document.querySelector('#distribuzioneTipoChart');
  530. if (
  531. distribuzioneTipoChartEl &&
  532. dashboardData.labelsTipo &&
  533. dashboardData.datiTipo &&
  534. Array.isArray(dashboardData.labelsTipo) &&
  535. Array.isArray(dashboardData.datiTipo) &&
  536. dashboardData.labelsTipo.length > 0 &&
  537. dashboardData.datiTipo.length > 0 &&
  538. !dashboardData.labelsTipo.includes('Nessun dato')
  539. ) {
  540. const distribuzioneTipoChartConfig = {
  541. chart: {
  542. height: 300,
  543. type: 'donut'
  544. },
  545. labels: dashboardData.labelsTipo,
  546. series: dashboardData.datiTipo,
  547. colors: [
  548. config.colors.primary,
  549. config.colors.success,
  550. config.colors.warning,
  551. config.colors.info,
  552. config.colors.danger
  553. ],
  554. legend: {
  555. position: 'bottom',
  556. labels: {
  557. colors: headingColor,
  558. useSeriesColors: false,
  559. fontSize: '13px',
  560. fontFamily: fontFamily
  561. }
  562. },
  563. plotOptions: {
  564. pie: {
  565. donut: {
  566. size: '75%'
  567. }
  568. }
  569. }
  570. };
  571. const distribuzioneTipoChart = new ApexCharts(distribuzioneTipoChartEl, distribuzioneTipoChartConfig);
  572. distribuzioneTipoChart.render();
  573. } else if (distribuzioneTipoChartEl) {
  574. distribuzioneTipoChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
  575. }
  576. // Grafico Costi per Tipo (Barre)
  577. const costiTipoChartEl = document.querySelector('#costiTipoChart');
  578. if (
  579. costiTipoChartEl &&
  580. dashboardData.labelsCostiTipo &&
  581. dashboardData.datiCostiTipo &&
  582. Array.isArray(dashboardData.labelsCostiTipo) &&
  583. Array.isArray(dashboardData.datiCostiTipo) &&
  584. dashboardData.labelsCostiTipo.length > 0 &&
  585. dashboardData.datiCostiTipo.length > 0 &&
  586. !dashboardData.labelsCostiTipo.includes('Nessun dato')
  587. ) {
  588. const costiTipoChartConfig = {
  589. chart: {
  590. height: 350,
  591. type: 'bar',
  592. toolbar: { show: false }
  593. },
  594. colors: [config.colors.success],
  595. plotOptions: {
  596. bar: {
  597. horizontal: false,
  598. columnWidth: '55%',
  599. borderRadius: 8,
  600. startingShape: 'rounded',
  601. endingShape: 'rounded',
  602. borderRadiusApplication: 'around'
  603. }
  604. },
  605. dataLabels: {
  606. enabled: false
  607. },
  608. series: [
  609. {
  610. name: 'Costi (€)',
  611. data: dashboardData.datiCostiTipo
  612. }
  613. ],
  614. xaxis: {
  615. categories: dashboardData.labelsCostiTipo,
  616. labels: {
  617. style: {
  618. fontSize: '13px',
  619. fontFamily: fontFamily,
  620. colors: labelColor
  621. },
  622. rotate: -45,
  623. rotateAlways: true
  624. },
  625. axisTicks: {
  626. show: false
  627. },
  628. axisBorder: {
  629. show: false
  630. }
  631. },
  632. yaxis: {
  633. labels: {
  634. style: {
  635. fontSize: '13px',
  636. fontFamily: fontFamily,
  637. colors: labelColor
  638. },
  639. formatter: function (val) {
  640. return '€' + val.toFixed(2);
  641. }
  642. }
  643. },
  644. grid: {
  645. borderColor: borderColor,
  646. strokeDashArray: 4,
  647. padding: {
  648. top: -20,
  649. bottom: -10,
  650. left: 0
  651. }
  652. },
  653. states: {
  654. hover: {
  655. filter: {
  656. type: 'none'
  657. }
  658. },
  659. active: {
  660. filter: {
  661. type: 'none'
  662. }
  663. }
  664. },
  665. tooltip: {
  666. y: {
  667. formatter: function (val) {
  668. return '€' + val.toFixed(2);
  669. }
  670. }
  671. }
  672. };
  673. const costiTipoChart = new ApexCharts(costiTipoChartEl, costiTipoChartConfig);
  674. costiTipoChart.render();
  675. } else if (costiTipoChartEl) {
  676. costiTipoChartEl.innerHTML = '<div class="text-center p-4 text-muted">Nessun dato disponibile</div>';
  677. }
  678. });