blob: 477befd3446fc1315cd53cdd14ac87fd01798df6 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
Adrià Vilanova Martínez5af86512023-12-02 20:44:16 +01002/*
3 * hores
4 * Copyright (c) 2023 Adrià Vilanova Martínez
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public
17 * License along with this program.
18 * If not, see http://www.gnu.org/licenses/.
19 */
20
Copybara botbe50d492023-11-30 00:16:42 +010021require_once("core.php");
22security::checkType(security::ADMIN);
23
24incidentsView::handleIncidentShortcuts();
25
26incidentsView::buildSelect();
27
28$numRows = incidents::numRows($select);
29$companies = companies::getAll();
30?>
31<!DOCTYPE html>
32<html>
33<head>
34 <title><?php echo $conf["appName"]; ?></title>
35 <?php visual::includeHead(); ?>
36 <link rel="stylesheet" href="css/dashboard.css">
37 <link rel="stylesheet" href="css/incidents.css">
38
39 <style>
40 .addincident, .addrecurringincident, .filter {
41 z-index: 1000;
42 }
43
44 .addincident {
45 position: fixed;
46 bottom: 16px;
47 right: 16px;
48 }
49
50 .addrecurringincident {
51 position: fixed;
52 bottom: 80px;
53 right: 25px;
54 }
55
56 .filter {
57 position: fixed;
58 bottom: 126px;
59 right: 25px;
60 }
61
62 .helper-bellow-incidents-list {
63 text-align: center;
64 font-size: 13px;
65 }
66
67 @media (max-width: 655px) {
68 .extra {
69 display: none;
70 }
71 }
72 </style>
73</head>
74<?php visual::printBodyTag(); ?>
75 <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer">
76 <?php visual::includeNav(); ?>
77 <button class="addincident mdl-button md-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--accent"><i class="material-icons">add</i><span class="mdl-ripple"></span></button>
78 <button class="addrecurringincident mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-color--grey-200"><i class="material-icons">repeat</i><span class="mdl-ripple"></span></button>
79 <button class="filter mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-color--grey-200"><i class="material-icons">filter_list</i></button>
80 <main class="mdl-layout__content">
81 <div class="page-content">
82 <div class="main mdl-shadow--4dp">
83 <h2>Incidencias</h2>
84
85 <?php
86 if ($select["showPendingQueue"]) {
87 $numRowsPending = incidents::numPending();
88 ?>
89 <h4>Cola de revisión (<?=$numRowsPending?>)<?=($select["isAnyEnabled"] ? ' <i id="tt_filtersarenotapplied" class="material-icons help">info</i>' : '')?></h4>
90 <?php
91 if ($select["isAnyEnabled"]) {
92 visual::addTooltip("tt_filtersarenotapplied", "Los filtros no se han aplicado a la cola de revisión.");
93 }
94
95 $incidentsPending = incidents::getAll(true);
96 if (count($incidentsPending)) {
97 incidentsView::renderIncidents($incidentsPending, $companies);
98 } else {
99 echo "Todas las incidencias ya han sido revisadas.";
100 }
101 }
102
103
104 $page = ($select["showResultsPaginated"] ? (isset($_GET["page"]) ? (int)$_GET["page"] - 1 : null) : 0);
105
106 if ($select["showResultsPaginated"]) {
107 $limit = (int)($_GET["limit"] ?? incidents::PAGINATION_LIMIT);
108 if ($limit <= 0 || $limit > 100) $limit = incidents::PAGINATION_LIMIT;
109 } else $limit = 0;
110
111 $incidents = incidents::getAll(null, $page, $limit, "ALL", null, null, false, $select);
112
113 if (!$select["showResultsPaginated"]) $numRows = count($incidents);
114 ?>
115
116 <h4><?=($select["isAnyEnabled"] ? "Incidencias filtradas" : "Todas las incidencias")?> (<?=(int)$numRows?>)</h4>
117
118 <?php
119 if (count($incidents)) {
120 incidentsView::renderIncidents($incidents, $companies, false, true, false, false, true);
121 /*if (!$select["showResultsPaginated"]) {
122 echo "<p class=\"helper-bellow-incidents-list mdl-color-text--grey-600\">Se está truncando la lista de incidencias a un máximo de resultados, así que es posible que algunas incidencias no se muestren en la lista.<br>Puedes encontrar más incidencias cambiando el selector de fecha final de la sección de filtros a la fecha de la última incidencia de la lista.</p>";
123 }*/
124 } else if ($select["isAnyEnabled"]) {
125 echo "No se ha encontrado ninguna incidencia con los filtros seleccionados.";
126 } else {
127 echo "Todavía no existe ninguna incidencia. Puedes añadir una haciendo clic en el botón de la esquina inferior derecha.";
128 }
129 ?>
130
131 <?php
132 if ($select["showResultsPaginated"]) visual::renderPagination($numRows, $select["pageUrl"], $limit, ($limit == incidents::PAGINATION_LIMIT ? false : true), $select["pageUrlHasParameters"], [
133 "elementName" => "incidencias",
134 "options" => incidentsView::$limitOptions
135 ], incidents::todayPage($limit));
136 if ($select["showPendingQueue"]) visual::printDebug("incidents::getAll(true)", $incidentsPending);
137 visual::printDebug("incidents::getAll(null, ".(int)$page.", ".(int)$limit.", \"ALL\", null, null, false, \$select)", $incidents);
138 visual::printDebug("\$select", $select);
139 ?>
140 </div>
141 </div>
142 </main>
143 </div>
144
145 <?php
146 $workers = people::getAll(false, true);
147 incidentsView::renderIncidentForm($workers, function(&$worker) {
148 return (int)$worker["workerid"];
149 }, function (&$worker, &$companies) {
150 return $worker["name"].' ('.$companies[$worker["companyid"]].')';
151 }, $companies, false, false, "incidents.php");
152
153 incidentsView::renderIncidentForm($workers, function(&$worker) {
154 return (int)$worker["workerid"];
155 }, function (&$worker, &$companies) {
156 return $worker["name"].' ('.$companies[$worker["companyid"]].')';
157 }, $companies, false, true, "incidents.php");
158
159 if (isset($_GET["openRecurringFormWorker"])) {
160 $openWorker = (int)$_GET["openRecurringFormWorker"];
161 ?>
162 <script>
163 document.getElementById("recurringworker").value = "<?=security::htmlsafe($openWorker)?>";
164 document.getElementById("addrecurringincident").showModal();
165 </script>
166 <?php
167 }
168
169 incidentsView::renderFilterDialog($select);
170
171 visual::renderTooltips();
172 ?>
173
174 <div class="mdl-snackbar mdl-js-snackbar">
175 <div class="mdl-snackbar__text"></div>
176 <button type="button" class="mdl-snackbar__action"></button>
177 </div>
178
179 <?php
180 visual::smartSnackbar(incidentsView::$incidentsMsgs, 10000, false);
181 ?>
182
183 <script>
184 var _showResultsPaginated = <?=($select["showResultsPaginated"] ? "true" : "false")?>;
185 var _limit = <?=(int)$limit?>;
186 var _page = <?=(int)$page?>;
187 </script>
188 <script src="js/incidents.js"></script>
189 <script src="js/incidentsgeneric.js"></script>
190</body>
191</html>