Introduzione Hooks disponibili in stato dei servizi

This commit is contained in:
Luca 2022-10-06 17:08:18 +02:00
parent 4b9655cf9f
commit dac2537ac0
6 changed files with 274 additions and 7 deletions

View File

@ -267,6 +267,48 @@ switch (filter('op')) {
break; break;
case 'disabilita-hook':
$id = filter('id');
// Abilitazione del widget indicato
$database->table('zz_hooks')
->where('id', '=', $id)
->update(['enabled' => 0]);
// Messaggio informativo
$hook = $database->table('zz_hooks')
->where('id', '=', $id)
->first();
flash()->info(tr('Hook "_NAME_" disabilitato!', [
'_NAME_' => $hook->name,
]));
echo json_encode([]);
break;
case 'abilita-hook':
$id = filter('id');
// Abilitazione del widget indicato
$database->table('zz_hooks')
->where('id', '=', $id)
->update(['enabled' => 1]);
// Messaggio informativo
$hook = $database->table('zz_hooks')
->where('id', '=', $id)
->first();
flash()->info(tr('Hook "_NAME_" abilitato!', [
'_NAME_' => $hook->name,
]));
echo json_encode([]);
break;
case 'sizes': case 'sizes':
$results = []; $results = [];
@ -279,13 +321,16 @@ switch (filter('op')) {
]; ];
foreach ($dirs as $dir => $description) { foreach ($dirs as $dir => $description) {
$size = FileSystem::folderSize($dir, ['htaccess','gitkeep','ini','xml']); $excluded_extensions = ['htaccess','gitkeep'];
$excluded_dir = [DOCROOT.'\files\impianti', DOCROOT.'\files\importFE', DOCROOT.'\files\importFE'];
$size = FileSystem::folderSize($dir, array_merge($excluded_extensions,$excluded_dir));
$results[] = [ $results[] = [
'description' => $description, 'description' => $description,
'size' => $size, 'size' => $size,
'formattedSize' => FileSystem::formatBytes($size), 'formattedSize' => FileSystem::formatBytes($size),
'count' => FileSystem::fileCount($dir, ['htaccess','gitkeep','ini','xml']) ?: 0, 'count' => FileSystem::fileCount($dir, array_merge($excluded_extensions,$excluded_dir)) ?: 0,
'dbSize' => ($description == 'Allegati') ? $dbo->fetchOne('SELECT SUM(`size`) AS dbsize FROM zz_files')['dbsize'] : 0, 'dbSize' => ($description == 'Allegati') ? $dbo->fetchOne('SELECT SUM(`size`) AS dbsize FROM zz_files')['dbsize'] : 0,
'dbCount' => ($description == 'Allegati') ? $dbo->fetchOne('SELECT COUNT(`id`) AS dbcount FROM zz_files')['dbcount'] : 0, 'dbCount' => ($description == 'Allegati') ? $dbo->fetchOne('SELECT COUNT(`id`) AS dbcount FROM zz_files')['dbcount'] : 0,
'dbExtensions' => ($description == 'Allegati') ? $dbo->fetchArray("SELECT SUBSTRING_INDEX(filename, '.', -1) AS extension, COUNT(*) AS num FROM zz_files GROUP BY extension ORDER BY num DESC LIMIT 10") : 0, 'dbExtensions' => ($description == 'Allegati') ? $dbo->fetchArray("SELECT SUBSTRING_INDEX(filename, '.', -1) AS extension, COUNT(*) AS num FROM zz_files GROUP BY extension ORDER BY num DESC LIMIT 10") : 0,

View File

@ -264,7 +264,7 @@ echo '
</div> </div>
</div>'; </div>';
// Widgets // Widgets + Hooks
echo ' echo '
<div class="col-md-12 col-lg-6"> <div class="col-md-12 col-lg-6">
<div class="box box-info"> <div class="box box-info">
@ -277,6 +277,18 @@ echo '
<div class="box-body" id="widget"> <div class="box-body" id="widget">
</div> </div>
</div> </div>
<div class="box box-info">
<div class="box-header">
<h3 class="box-title">
'.tr('Hooks disponibili').'
</h3>
</div>
<div class="box-body" id="hook">
</div>
</div>
</div> </div>
</div> </div>
@ -422,9 +434,23 @@ function caricaElencoWidget() {
}); });
} }
function caricaElencoHooks() {
let container = $("#hook");
localLoading(container, true);
return $.get("'.$structure->fileurl('elenco-hooks.php').'?id_module='.$id_module.'", function(data) {
container.html(data);
localLoading(container, false);
init();
});
}
$(document).ready(function() { $(document).ready(function() {
caricaElencoModuli(); caricaElencoModuli();
caricaElencoWidget(); caricaElencoWidget();
caricaElencoHooks();
init(); init();
}); });

View File

@ -0,0 +1,195 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
echo '
<table class="table table-hover table-condensed">
<thead>
<tr>
<th>'.tr('Nome').'</th>
<th>'.tr('Stato').'</th>
<th>'.tr('Ultima esecuzione').'</th>
</tr>
</thead>';
$hooks = $dbo->fetchArray('SELECT zz_hooks.*, zz_modules.name AS modulo
FROM zz_hooks
INNER JOIN zz_modules ON zz_hooks.id_module = zz_modules.id
ORDER BY `id_module` ASC, `zz_hooks`.`id` ASC');
$gruppi = collect($hooks)->groupBy('modulo');
foreach ($gruppi as $modulo => $hooks) {
echo '
<thead>
<tr>
<th colspan="4">'.$modulo.'</th>
</tr>
</thead>
<tbody>';
foreach ($hooks as $hook) {
$class = $hook['enabled'] ? 'success' : 'warning';
$nome_tipo = 'hook';
echo '
<tr class="'.$class.'" data-id="'.$hook['id'].'" data-nome='.json_encode($hook['name']).'>
<td>
'.$hook['name'].(!empty($hook['help']) ? '
<i class="tip fa fa-question-circle-o" title="'.$hook['help'].'"</i>' : '').'
</td>
<td class="text-center">';
// Possibilità di disabilitare o abilitare il hook
if ($hook['enabled']) {
echo '
<div class="tip" data-toggle="tooltip" title="'.tr('Questo _TYPE_ è abilitato: clicca qui per disabilitarlo', [
'_TYPE_' => $nome_tipo,
]).'">
<button type="button" class="btn btn-warning btn-xs" onclick="disabilitaHook(this)">
<i class="fa fa-power-off" title="'.tr('Disabilita').'"></i>
</button>
</div>';
} else {
echo '
<div class="tip" data-toggle="tooltip" title="'.tr('Questo _TYPE_ è disabilitato: clicca qui per abilitarlo', [
'_TYPE_' => $nome_tipo,
]).'">
<button type="button" class="btn btn-success btn-xs" onclick="abilitaHook(this)">
<i class="fa fa-plug" title="'.tr('Abilita').'"></i>
</button>
</div>';
}
echo '
</td>
<td class="text-center">';
Translator::timestampToLocale($hook['processing_at']);
echo '
</td>
</tr>';
}
echo '
</tbody>';
}
echo '
</table>
<script>
function disabilitaHook(button){
const riga = $(button).closest("tr");
const id = riga.data("id");
const nome = riga.data("nome");
const nome_tipo = "hook";
swal({
title: "'.tr('Disabilitare il _TYPE_?', [
'_TYPE_' => '" + nome_tipo + "',
]).'",
html: "'.tr('Sei sicuro di voler disabilitare il _TYPE_ _NAME_?', [
'_TYPE_' => '" + nome_tipo + "',
'_NAME_' => '" + nome + "',
]).'",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Continua').'"
}).then(function (result) {
let restore = buttonLoading(button);
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
dataType: "JSON",
data: {
id_module: globals.id_module,
op: "disabilita-hook",
id: id,
},
success: function (response) {
caricaElencoHooks();
renderMessages();
},
error: function() {
buttonRestore(button, restore);
swal({
type: "error",
title: globals.translations.ajax.error.title,
text: globals.translations.ajax.error.text,
});
}
});
})
}
function abilitaHook(button) {
const riga = $(button).closest("tr");
const id = riga.data("id");
const nome = riga.data("nome");
const nome_tipo = "hook";
swal({
title: "'.tr('Abilitare il _TYPE_?', [
'_TYPE_' => '" + nome_tipo + "',
]).'",
html: "'.tr('Sei sicuro di voler abilitare il _TYPE_ _NAME_?', [
'_TYPE_' => '" + nome_tipo + "',
'_NAME_' => '" + nome + "',
]).'",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Continua').'"
}).then(function (result) {
let restore = buttonLoading(button);
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
dataType: "JSON",
data: {
id_module: globals.id_module,
op: "abilita-hook",
id: id,
},
success: function (response) {
caricaElencoHooks();
renderMessages();
},
error: function() {
buttonRestore(button, restore);
swal({
type: "error",
title: globals.translations.ajax.error.title,
text: globals.translations.ajax.error.text,
});
}
});
})
}
</script>';

View File

@ -24,7 +24,7 @@ echo '
<thead> <thead>
<tr> <tr>
<th>'.tr('Nome').'</th> <th>'.tr('Nome').'</th>
<th>'.tr('Posizione').'</th> <th>'.tr('Ubicazione').'</th>
<th>'.tr('Stato').'</th> <th>'.tr('Stato').'</th>
<th>'.tr('Posizione').'</th> <th>'.tr('Posizione').'</th>
</tr> </tr>

View File

@ -72,7 +72,7 @@ function crea_grafico(values){
if (element.count<element.dbCount){ if (element.count<element.dbCount){
var diff = (element.dbCount-element.count); var diff = (element.dbCount-element.count);
$("#message").append("<div class=\"label label-warning\" ><i class=\"fa fa-exclamation-triangle\" aria-hidden=\"true\"></i> "+diff+" files non trovati sul disco per allegati.</div><br>"); $("#message").append("<div class=\"label label-warning\" ><i class=\"fa fa-exclamation-triangle\" aria-hidden=\"true\"></i> "+diff+" files non trovati per allegati.</div><br>");
} }
} }

View File

@ -71,7 +71,7 @@ class FileSystem
if ($path !== false && $path != '' && file_exists($path)) { if ($path !== false && $path != '' && file_exists($path)) {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) { foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) {
if (!in_array($object->getExtension(), $exclusions)) { if (!in_array($object->getExtension(), $exclusions) && (!in_array($object->getPath(), $exclusions)) ) {
$total += $object->getSize(); $total += $object->getSize();
} }
} }
@ -94,7 +94,8 @@ class FileSystem
if ($path !== false && $path != '' && file_exists($path)) { if ($path !== false && $path != '' && file_exists($path)) {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) { foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) {
if (!in_array($object->getExtension(), $exclusions)) { if (!in_array($object->getExtension(), $exclusions) && (!in_array($object->getPath(), $exclusions)) ) {
++$total; ++$total;
} }
} }