implement demo data load

This commit is contained in:
alejandro.campos@artica.es 2023-11-20 16:52:49 +01:00
parent 1fcc263046
commit d6bffbade1
8 changed files with 1185 additions and 337 deletions

View File

@ -507,7 +507,7 @@ if ($access_console_node === true) {
enterprise_hook('skins_submenu'); enterprise_hook('skins_submenu');
$sub['godmode/setup/demo']['text'] = __('Demo'); $sub['godmode/setup/demo']['text'] = __('Demo data');
$sub['godmode/setup/demo']['id'] = 'demo'; $sub['godmode/setup/demo']['id'] = 'demo';
$menu_godmode['gsetup']['sub'] = $sub; $menu_godmode['gsetup']['sub'] = $sub;

View File

@ -38,6 +38,7 @@ config_update_value('demo_data_load_progress', 0);
html_print_input_hidden('demo_items_count', 0); html_print_input_hidden('demo_items_count', 0);
$agents_num = (int) get_parameter('agents_num', 30);
$submit_value = (string) get_parameter('update_button', ''); $submit_value = (string) get_parameter('update_button', '');
$demo_items_count = db_get_value('count(*)', 'tdemo_data'); $demo_items_count = db_get_value('count(*)', 'tdemo_data');
$demo_agents_count = db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente'); $demo_agents_count = db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente');
@ -130,7 +131,7 @@ $table_aux->data['row1'][] = html_print_label_input_block(
'content' => html_print_select( 'content' => html_print_select(
$arraySelectIcon, $arraySelectIcon,
'agents_num', 'agents_num',
$config['gis_default_icon'], $agents_num,
'', '',
'30', '30',
30, 30,
@ -291,10 +292,14 @@ $actionButtons[] = html_print_submit_button(
true true
); );
echo '<div id="btn-set" style="display:none;">';
html_print_action_buttons( html_print_action_buttons(
implode('', $actionButtons) implode('', $actionButtons)
); );
echo '</div>';
echo '</form>'; echo '</form>';
?> ?>
@ -309,8 +314,10 @@ echo '</form>';
var delete_demo_data_str = '<?php echo __('Delete demo data'); ?>'; var delete_demo_data_str = '<?php echo __('Delete demo data'); ?>';
$('#btn-set').show();
if (demo_agents_count > 0) { if (demo_agents_count > 0) {
$('#span-btn-delete-demo-data').text(delete_demo_data_str+' ('+demo_agents_count+')'); $('#span-btn-delete-demo-data').text(delete_demo_data_str+' ('+demo_agents_count+')');
$('#btn-create-demo-data').hide();
$('#btn-delete-demo-data').show(); $('#btn-delete-demo-data').show();
} }
@ -326,7 +333,7 @@ echo '</form>';
var params = {}; var params = {};
params["action"] = "create_demo_data"; params["action"] = "create_demo_data";
params["page"] = "include/ajax/demo_data.ajax"; params["page"] = "include/ajax/demo_data.ajax";
params["agents_num"] = $('#agents_num').val(); params["agents_num"] = <?php echo $agents_num; ?>;
jQuery.ajax({ jQuery.ajax({
data: params, data: params,
@ -335,13 +342,16 @@ echo '</form>';
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
if (data.agents_count > 0) { if (data.agents_count > 0) {
$('#btn-create-demo-data').hide();
$('#span-btn-delete-demo-data').text(delete_demo_data_str+' ('+data.agents_count+')'); $('#span-btn-delete-demo-data').text(delete_demo_data_str+' ('+data.agents_count+')');
$('#agent-count-span').text('('+(data.agents_count ?? 0)+' '+agent_count_span_str+')'); $('#agent-count-span').text('('+(data.agents_count ?? 0)+' '+agent_count_span_str+')');
$('#btn-delete-demo-data').show(); $('#btn-delete-demo-data').show();
} }
}, },
error: function(XMLHttpRequest, textStatus, errorThrown) { error: function(jqXHR, textStatus, errorThrown) {
console.log("ERROR"); // Handle error
console.log('Error: ' + textStatus + ' - ' + errorThrown);
console.log(jqXHR.responseText);
} }
}); });
} }
@ -362,6 +372,7 @@ echo '</form>';
$('#span-btn-delete-demo-data').text(delete_demo_data_str); $('#span-btn-delete-demo-data').text(delete_demo_data_str);
$('#agent-count-span').text('('+(data.agents_count ?? 0)+' '+agent_count_span_str+')'); $('#agent-count-span').text('('+(data.agents_count ?? 0)+' '+agent_count_span_str+')');
$('#btn-delete-demo-data').hide(); $('#btn-delete-demo-data').hide();
$('#btn-create-demo-data').show();
}, },
error: function(XMLHttpRequest, textStatus, errorThrown) { error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("ERROR"); console.log("ERROR");

File diff suppressed because it is too large Load Diff

View File

@ -1158,7 +1158,7 @@ class WelcomeWindow extends Wizard
// Task to do actions. // Task to do actions.
function loadDemoDataPage() { function loadDemoDataPage() {
window.location = '<?php echo ui_get_full_url('index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&show_deploy_agent=1'); ?>'; window.location = '<?php echo ui_get_full_url('index.php?sec=gagente&sec2=godmode/setup/demo'); ?>';
} }
function openCreateModulesDialog() { function openCreateModulesDialog() {

View File

@ -655,7 +655,7 @@ function mysql_encapsule_fields_with_same_name_to_instructions($field)
* *
* @return mixed Value of first column of the first row. False if there were no row. * @return mixed Value of first column of the first row. False if there were no row.
*/ */
function mysql_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false) function mysql_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false, $cache=true)
{ {
if (!is_array($filter) || empty($filter)) { if (!is_array($filter) || empty($filter)) {
return false; return false;
@ -672,7 +672,7 @@ function mysql_db_get_value_filter($field, $table, $filter, $where_join='AND', $
db_format_array_where_clause_sql($filter, $where_join) db_format_array_where_clause_sql($filter, $where_join)
); );
$result = db_get_all_rows_sql($sql, $search_history_db); $result = db_get_all_rows_sql($sql, $search_history_db, $cache);
if ($result === false) { if ($result === false) {
return false; return false;
@ -1022,6 +1022,10 @@ function mysql_db_get_row_filter($table, $filter, $fields=false, $where_join='AN
} }
$sql = sprintf('SELECT %s FROM %s %s', $fields, $table, $filter); $sql = sprintf('SELECT %s FROM %s %s', $fields, $table, $filter);
if ($table==='tagente_modulo') {
hd("QUERYYYYYY", true);
hd($sql, true);
}
return db_get_row_sql($sql, $historydb, $cache); return db_get_row_sql($sql, $historydb, $cache);
} }

View File

@ -574,7 +574,7 @@ function oracle_encapsule_fields_with_same_name_to_instructions($field)
* *
* @return mixed Value of first column of the first row. False if there were no row. * @return mixed Value of first column of the first row. False if there were no row.
*/ */
function oracle_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false) function oracle_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false, $cache=true)
{ {
if (! is_array($filter) || empty($filter)) { if (! is_array($filter) || empty($filter)) {
return false; return false;
@ -590,7 +590,7 @@ function oracle_db_get_value_filter($field, $table, $filter, $where_join='AND',
$table, $table,
db_format_array_where_clause_sql($filter, $where_join) db_format_array_where_clause_sql($filter, $where_join)
); );
$result = db_get_all_rows_sql($sql, $search_history_db); $result = db_get_all_rows_sql($sql, $search_history_db, $cache);
if ($result === false) { if ($result === false) {
return false; return false;

View File

@ -474,7 +474,7 @@ function postgresql_encapsule_fields_with_same_name_to_instructions($field)
* *
* @return mixed Value of first column of the first row. False if there were no row. * @return mixed Value of first column of the first row. False if there were no row.
*/ */
function postgresql_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false) function postgresql_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false, $cache=true)
{ {
if (! is_array($filter) || empty($filter)) { if (! is_array($filter) || empty($filter)) {
return false; return false;
@ -496,7 +496,7 @@ function postgresql_db_get_value_filter($field, $table, $filter, $where_join='AN
db_format_array_where_clause_sql($filter, $where_join) db_format_array_where_clause_sql($filter, $where_join)
); );
$result = db_get_all_rows_sql($sql, $search_history_db); $result = db_get_all_rows_sql($sql, $search_history_db, $cache);
$row = array_shift($result); $row = array_shift($result);
$value = array_shift($row); $value = array_shift($row);

View File

@ -380,21 +380,21 @@ function db_get_value(
* *
* @return mixed Value of first column of the first row. False if there were no row. * @return mixed Value of first column of the first row. False if there were no row.
*/ */
function db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false) function db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false, $cache=true)
{ {
global $config; global $config;
switch ($config['dbtype']) { switch ($config['dbtype']) {
case 'mysql': case 'mysql':
return mysql_db_get_value_filter($field, $table, $filter, $where_join, $search_history_db); return mysql_db_get_value_filter($field, $table, $filter, $where_join, $search_history_db, $cache);
break; break;
case 'postgresql': case 'postgresql':
return postgresql_db_get_value_filter($field, $table, $filter, $where_join, $search_history_db); return postgresql_db_get_value_filter($field, $table, $filter, $where_join, $search_history_db, $cache);
break; break;
case 'oracle': case 'oracle':
return oracle_db_get_value_filter($field, $table, $filter, $where_join, $search_history_db); return oracle_db_get_value_filter($field, $table, $filter, $where_join, $search_history_db, $cache);
break; break;
} }