Merge branch 'ent-6332-aadcm-anadir-buscador-de-modulos-en-vista-de-agente-consola-movil' into 'develop'

Added a searchbox for module list in mobile/agent

See merge request artica/pandorafms!3962
This commit is contained in:
Daniel Rodriguez 2021-04-06 17:14:49 +00:00
commit dc692dbf2c
3 changed files with 101 additions and 0 deletions

View File

@ -1094,6 +1094,11 @@ li.ui-btn {
border-radius: 0px; border-radius: 0px;
} }
.center {
margin: 0 auto;
text-align: center;
}
/* For mobiles */ /* For mobiles */
@media screen and (max-width: 750px) { @media screen and (max-width: 750px) {
.ui-content > .ui-btn { .ui-content > .ui-btn {

View File

@ -286,9 +286,28 @@ class Agent
]; ];
} }
// Module searchbox.
$ui->beginForm('javascript:agent_filter_modules();');
$ui->formAddInput(
[
'id' => 'filter-modules',
'name' => 'filter-modules',
]
);
$ui->formAddInput(
[
'id' => 'filter-modules',
'name' => 'filter-modules',
'type' => 'submit',
'value' => __('Search'),
]
);
$filtering = $ui->getEndForm();
$modules->setFilters($filters); $modules->setFilters($filters);
$modules->disabledColumns(['agent']); $modules->disabledColumns(['agent']);
$ui->contentBeginCollapsible(__('Modules')); $ui->contentBeginCollapsible(__('Modules'));
$ui->contentCollapsibleAddItem($filtering);
$ui->contentCollapsibleAddItem($modules->listModulesHtml(0, true)); $ui->contentCollapsibleAddItem($modules->listModulesHtml(0, true));
$ui->contentEndCollapsible(); $ui->contentEndCollapsible();
@ -389,6 +408,33 @@ class Agent
set_same_heigth(); set_same_heigth();
} }
}); });
function agent_filter_modules() {
$.mobile.showPageLoadingMsg();
$.ajax ({
type: 'POST',
url: 'index.php',
dataType: 'text',
data: {
'action': 'ajax',
'parameter1': 'agent',
'id': ".$this->id.",
'parameter2': 'filter-modules',
'filter': $('#filter-modules').val()
},
success: function(r) {
$.mobile.hidePageLoadingMsg();
var className = $('#list_agent_Modules').attr('class');
$('#list_agent_Modules').parent().html(r);
$('#list_agent_Modules').addClass(className);
},
error: function(r, t, e) {
$.mobile.hidePageLoadingMsg();
console.error(e);
}
});
}
</script>" </script>"
); );
@ -397,4 +443,40 @@ class Agent
} }
/**
* Bob do something!
*
* @return void
*/
public function ajax($parameter2=null)
{
$system = System::getInstance();
if ($parameter2 === 'filter-modules') {
$name_filter = $system->getRequest('filter', '');
$modules = new Modules();
if ($system->getConfig('metaconsole')) {
$filters = [
'id_agent' => $this->agent['id_tagente'],
'all_modules' => true,
'status' => -1,
'name' => $name_filter,
];
} else {
$filters = [
'id_agent' => $this->id,
'all_modules' => true,
'status' => -1,
'name' => $name_filter,
];
}
$modules->setFilters($filters);
$modules->disabledColumns(['agent']);
echo $modules->listModulesHtml(0, true);
}
}
} }

View File

@ -27,6 +27,8 @@ class Modules
private $free_search = ''; private $free_search = '';
private $name = '';
private $module_group = -1; private $module_group = -1;
private $tag = ''; private $tag = '';
@ -106,6 +108,10 @@ class Modules
if (isset($filters['status'])) { if (isset($filters['status'])) {
$this->status = $filters['status']; $this->status = $filters['status'];
} }
if (isset($filters['name'])) {
$this->name = $filters['name'];
}
} }
@ -374,6 +380,14 @@ class Modules
); );
} }
// Search by module name.
if ($this->name != '') {
$sql_conditions .= sprintf(
" AND lower(tagente_modulo.nombre) LIKE lower('%%%s%%') ",
$this->name
);
}
// Part SQL fro Status // Part SQL fro Status
if ($this->status == AGENT_MODULE_STATUS_NORMAL) { if ($this->status == AGENT_MODULE_STATUS_NORMAL) {
// Normal // Normal