Fixed errors VC

This commit is contained in:
Daniel Barbero Martin 2020-01-21 17:43:41 +01:00
parent a557c25c31
commit ac4c091c9e
8 changed files with 437 additions and 996 deletions

View File

@ -814,140 +814,6 @@ function createVisualConsoleItem(baseUrl, vcId, data, callback) {
}; };
} }
/**
* Fetch a Visual Console's structure and its items.
* @param {string} baseUrl Base URL to build the API path.
* @param {number} vcId Identifier of the Visual Console.
* @param {number} vcItemId Identifier of the Visual Console's item.
* @param {Object} data Data we want to save.
* @param {function} callback Function to be executed on request success or fail.
* @return {Object} Cancellable. Object which include and .abort([statusText]) function.
*/
// eslint-disable-next-line no-unused-vars
function autocompleteAgentsVisualConsole(baseUrl, vcId, data, callback) {
// var apiPath = baseUrl + "/include/rest-api";
var apiPath = baseUrl + "/ajax.php";
var jqXHR = null;
// Cancel the ajax requests.
var abort = function(textStatus) {
if (textStatus == null) textStatus = "abort";
// -- XMLHttpRequest.readyState --
// Value State Description
// 0 UNSENT Client has been created. open() not called yet.
// 4 DONE The operation is complete.
if (jqXHR.readyState !== 0 && jqXHR.readyState !== 4)
jqXHR.abort(textStatus);
};
// Failed request handler.
var handleFail = function(jqXHR, textStatus, errorThrown) {
abort();
// Manually aborted or not.
if (textStatus === "abort") {
callback();
} else {
var error = new Error(errorThrown);
error.request = jqXHR;
callback(error);
}
};
// Function which handle success case.
var handleSuccess = function(data) {
callback(null, data);
};
// Visual Console container request.
jqXHR = jQuery
.post(
apiPath,
{
page: "include/rest-api/index",
autocompleteAgentsVisualConsole: 1,
visualConsoleId: vcId,
data: data
},
"json"
)
.done(handleSuccess)
.fail(handleFail);
// Abortable.
return {
abort: abort
};
}
/**
* Fetch a Visual Console's structure and its items.
* @param {string} baseUrl Base URL to build the API path.
* @param {number} vcId Identifier of the Visual Console.
* @param {number} vcItemId Identifier of the Visual Console's item.
* @param {Object} data Data we want to save.
* @param {function} callback Function to be executed on request success or fail.
* @return {Object} Cancellable. Object which include and .abort([statusText]) function.
*/
// eslint-disable-next-line no-unused-vars
function autocompleteModuleVisualConsole(baseUrl, vcId, data, callback) {
// var apiPath = baseUrl + "/include/rest-api";
var apiPath = baseUrl + "/ajax.php";
var jqXHR = null;
// Cancel the ajax requests.
var abort = function(textStatus) {
if (textStatus == null) textStatus = "abort";
// -- XMLHttpRequest.readyState --
// Value State Description
// 0 UNSENT Client has been created. open() not called yet.
// 4 DONE The operation is complete.
if (jqXHR.readyState !== 0 && jqXHR.readyState !== 4)
jqXHR.abort(textStatus);
};
// Failed request handler.
var handleFail = function(jqXHR, textStatus, errorThrown) {
abort();
// Manually aborted or not.
if (textStatus === "abort") {
callback();
} else {
var error = new Error(errorThrown);
error.request = jqXHR;
callback(error);
}
};
// Function which handle success case.
var handleSuccess = function(data) {
callback(null, data);
};
// Visual Console container request.
jqXHR = jQuery
.post(
apiPath,
{
page: "include/rest-api/index",
autocompleteModuleVisualConsole: 1,
visualConsoleId: vcId,
data: data
},
"json"
)
.done(handleSuccess)
.fail(handleFail);
// Abortable.
return {
abort: abort
};
}
/** /**
* Fetch a Visual Console's structure and its items. * Fetch a Visual Console's structure and its items.
* @param {string} baseUrl Base URL to build the API path. * @param {string} baseUrl Base URL to build the API path.
@ -1148,195 +1014,6 @@ function removeVisualConsoleItem(baseUrl, vcId, vcItemId, callback) {
}; };
} }
/**
* Fetch groups access user.
* @param {string} baseUrl Base URL to build the API path.
* @param {number} vcId Identifier of the Visual Console.
* @param {function} callback Function to be executed on request success or fail.
* @return {Object} Cancellable. Object which include and .abort([statusText]) function.
*/
// eslint-disable-next-line no-unused-vars
function getGroupsVisualConsoleItem(baseUrl, vcId, callback) {
var apiPath = baseUrl + "/ajax.php";
var jqXHR = null;
// Cancel the ajax requests.
var abort = function(textStatus) {
if (textStatus == null) textStatus = "abort";
// -- XMLHttpRequest.readyState --
// Value State Description
// 0 UNSENT Client has been created. open() not called yet.
// 4 DONE The operation is complete.
if (jqXHR.readyState !== 0 && jqXHR.readyState !== 4)
jqXHR.abort(textStatus);
};
// Failed request handler.
var handleFail = function(jqXHR, textStatus, errorThrown) {
abort();
// Manually aborted or not.
if (textStatus === "abort") {
callback();
} else {
var error = new Error(errorThrown);
error.request = jqXHR;
callback(error);
}
};
// Function which handle success case.
var handleSuccess = function(data) {
callback(null, data);
};
// Visual Console container request.
jqXHR = jQuery
.get(
apiPath,
{
page: "include/rest-api/index",
getGroupsVisualConsoleItem: 1,
visualConsoleId: vcId
},
"json"
)
.done(handleSuccess)
.fail(handleFail);
// Abortable.
return {
abort: abort
};
}
/**
* Fetch groups access user.
* @param {string} baseUrl Base URL to build the API path.
* @param {number} vcId Identifier of the Visual Console.
* @param {function} callback Function to be executed on request success or fail.
* @return {Object} Cancellable. Object which include and .abort([statusText]) function.
*/
// eslint-disable-next-line no-unused-vars
function getCustomGraphVisualConsoleItem(baseUrl, vcId, callback) {
var apiPath = baseUrl + "/ajax.php";
var jqXHR = null;
// Cancel the ajax requests.
var abort = function(textStatus) {
if (textStatus == null) textStatus = "abort";
// -- XMLHttpRequest.readyState --
// Value State Description
// 0 UNSENT Client has been created. open() not called yet.
// 4 DONE The operation is complete.
if (jqXHR.readyState !== 0 && jqXHR.readyState !== 4)
jqXHR.abort(textStatus);
};
// Failed request handler.
var handleFail = function(jqXHR, textStatus, errorThrown) {
abort();
// Manually aborted or not.
if (textStatus === "abort") {
callback();
} else {
var error = new Error(errorThrown);
error.request = jqXHR;
callback(error);
}
};
// Function which handle success case.
var handleSuccess = function(data) {
callback(null, data);
};
// Visual Console container request.
jqXHR = jQuery
.get(
apiPath,
{
page: "include/rest-api/index",
getCustomGraphVisualConsoleItem: 1,
visualConsoleId: vcId
},
"json"
)
.done(handleSuccess)
.fail(handleFail);
// Abortable.
return {
abort: abort
};
}
/**
* Fetch groups access user.
* @param {string} baseUrl Base URL to build the API path.
* @param {number} vcId Identifier of the Visual Console.
* @param {function} callback Function to be executed on request success or fail.
* @return {Object} Cancellable. Object which include and .abort([statusText]) function.
*/
// eslint-disable-next-line no-unused-vars
function getAllVisualConsole(baseUrl, vcId, callback) {
var apiPath = baseUrl + "/ajax.php";
var jqXHR = null;
// Cancel the ajax requests.
var abort = function(textStatus) {
if (textStatus == null) textStatus = "abort";
// -- XMLHttpRequest.readyState --
// Value State Description
// 0 UNSENT Client has been created. open() not called yet.
// 4 DONE The operation is complete.
if (jqXHR.readyState !== 0 && jqXHR.readyState !== 4)
jqXHR.abort(textStatus);
};
// Failed request handler.
var handleFail = function(jqXHR, textStatus, errorThrown) {
abort();
// Manually aborted or not.
if (textStatus === "abort") {
callback();
} else {
var error = new Error(errorThrown);
error.request = jqXHR;
callback(error);
}
};
// Function which handle success case.
var handleSuccess = function(data) {
callback(null, data);
};
// Visual Console container request.
jqXHR = jQuery
.get(
apiPath,
{
page: "include/rest-api/index",
getAllVisualConsole: 1,
visualConsoleId: vcId
},
"json"
)
.done(handleSuccess)
.fail(handleFail);
// Abortable.
return {
abort: abort
};
}
/** /**
* Copy an item. * Copy an item.
* @param {string} baseUrl Base URL to build the API path. * @param {string} baseUrl Base URL to build the API path.
@ -1580,326 +1257,6 @@ function createOrUpdateVisualConsoleItem(
var done = e.done; var done = e.done;
switch (identifier) { switch (identifier) {
case "parent":
var data = visualConsole.elements
.filter(function(item) {
return item.props.id !== params.id;
})
.map(function(item) {
return {
value: item.props.id,
text: VisualConsole.itemDescriptiveName(item)
};
});
done(null, data);
break;
case "acl-group":
asyncTaskManager
.add(identifier + "-" + params.id, function(doneAsyncTask) {
var abortable = getGroupsVisualConsoleItem(
baseUrl,
visualConsole.props.id,
function(error, data) {
if (error || !data) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
done(error);
doneAsyncTask();
return;
}
if (typeof data === "string") {
try {
data = JSON.parse(data);
} catch (error) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
done(error);
doneAsyncTask();
return; // Stop task execution.
}
}
done(null, data);
doneAsyncTask();
}
);
return {
cancel: function() {
abortable.abort();
}
};
})
.init();
break;
case "custom-graph-list":
asyncTaskManager
.add(identifier + "-" + params.id, function(doneAsyncTask) {
var abortable = getCustomGraphVisualConsoleItem(
baseUrl,
visualConsole.props.id,
function(error, data) {
if (error || !data) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
done(error);
doneAsyncTask();
return;
}
if (typeof data === "string") {
try {
data = JSON.parse(data);
} catch (error) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
done(error);
doneAsyncTask();
return; // Stop task execution.
}
}
done(null, data);
doneAsyncTask();
}
);
return {
cancel: function() {
abortable.abort();
}
};
})
.init();
break;
case "link-console":
asyncTaskManager
.add(identifier + "-" + params.id, function(doneAsyncTask) {
var abortable = getAllVisualConsole(
baseUrl,
visualConsole.props.id,
function(error, data) {
if (error || !data) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
done(error);
doneAsyncTask();
return;
}
if (typeof data === "string") {
try {
data = JSON.parse(data);
} catch (error) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
done(error);
doneAsyncTask();
return; // Stop task execution.
}
}
done(null, data);
doneAsyncTask();
}
);
return {
cancel: function() {
abortable.abort();
}
};
})
.init();
break;
case "image-console":
asyncTaskManager
.add(identifier + "-" + params.id, function(doneAsyncTask) {
var abortable = getImagesVisualConsole(
baseUrl,
visualConsole.props.id,
function(error, data) {
if (error || !data) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
done(error);
doneAsyncTask();
return;
}
if (typeof data === "string") {
try {
data = JSON.parse(data);
} catch (error) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
done(error);
doneAsyncTask();
return; // Stop task execution.
}
}
done(null, data);
doneAsyncTask();
}
);
return {
cancel: function() {
abortable.abort();
}
};
})
.init();
break;
case "autocomplete-agent":
asyncTaskManager
.add(identifier + "-" + params.id, function(doneAsyncTask) {
var dataObject = {
value: params.value,
type: params.type
};
var abortable = autocompleteAgentsVisualConsole(
baseUrl,
visualConsole.props.id,
dataObject,
function(error, data) {
if (error || !data) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
done(error);
doneAsyncTask();
return;
}
if (typeof data === "string") {
try {
data = JSON.parse(data);
} catch (error) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
done(error);
doneAsyncTask();
return; // Stop task execution.
}
}
done(null, data);
doneAsyncTask();
}
);
return {
cancel: function() {
abortable.abort();
}
};
})
.init();
break;
case "autocomplete-module":
asyncTaskManager
.add(identifier + "-" + params.id, function(doneAsyncTask) {
var abortable = autocompleteModuleVisualConsole(
baseUrl,
visualConsole.props.id,
params,
function(error, data) {
if (error || !data) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
done(error);
doneAsyncTask();
return;
}
if (typeof data === "string") {
try {
data = JSON.parse(data);
} catch (error) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
done(error);
doneAsyncTask();
return; // Stop task execution.
}
}
done(null, data);
doneAsyncTask();
}
);
return {
cancel: function() {
abortable.abort();
}
};
})
.init();
break;
case "service-list": case "service-list":
asyncTaskManager asyncTaskManager
.add(identifier + "-" + params.id, function(doneAsyncTask) { .add(identifier + "-" + params.id, function(doneAsyncTask) {
@ -2098,139 +1455,6 @@ function createOrUpdateVisualConsoleItem(
console.log("Form submit", e.data); console.log("Form submit", e.data);
$formElement.dialog("close"); $formElement.dialog("close");
}); });
$formElement.dialog({
title: formContainer.title,
modal: true,
resizable: false,
draggable: true,
height: 600,
width: 700,
open: function() {
tinymce.init({
selector: "#tinyMCE_editor",
theme: "advanced",
content_css: baseUrl + "include/styles/pandora.css",
theme_advanced_font_sizes:
"4pt=.visual_font_size_4pt, " +
"6pt=.visual_font_size_6pt, " +
"8pt=.visual_font_size_8pt, " +
"10pt=.visual_font_size_10pt, " +
"12pt=.visual_font_size_12pt, " +
"14pt=.visual_font_size_14pt, " +
"18pt=.visual_font_size_18pt, " +
"24pt=.visual_font_size_24pt, " +
"28pt=.visual_font_size_28pt, " +
"36pt=.visual_font_size_36pt, " +
"48pt=.visual_font_size_48pt, " +
"60pt=.visual_font_size_60pt, " +
"72pt=.visual_font_size_72pt, " +
"84pt=.visual_font_size_84pt, " +
"96pt=.visual_font_size_96pt, " +
"116pt=.visual_font_size_116pt, " +
"128pt=.visual_font_size_128pt, " +
"140pt=.visual_font_size_140pt, " +
"154pt=.visual_font_size_154pt, " +
"196pt=.visual_font_size_196pt",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_buttons1:
"bold,italic, |, justifyleft, justifycenter, justifyright, |, undo, redo, |, image, link, |, fontselect, forecolor, fontsizeselect, |,code",
theme_advanced_buttons2: "",
theme_advanced_buttons3: "",
theme_advanced_statusbar_location: "none"
});
},
beforeClose: function() {
//Remove tinyMCE.
tinymce.remove("#tinyMCE_editor");
//Danguerous empty form if necessary for cleaned IDs.
$formElement.empty();
},
buttons: [
{
text: "Cancel",
class:
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel",
click: function() {
$formElement.dialog("close");
}
},
{
text: "Reset",
class:
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel",
click: function() {
console.log("entra");
formContainer.reset();
}
},
{
text: props.id ? "Update" : "Create",
class:
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
click: function() {
// Remove input class error.
var errorInputValidate = this.getElementsByClassName(
"error-input-validate"
);
if (errorInputValidate.length) {
for (var i = 0; i < errorInputValidate.length; i++) {
errorInputValidate
.item(i)
.classList.remove("error-input-validate");
}
}
// Remove element P error in form.
var errorPValidate = this.getElementsByClassName("error-p-validate");
if (errorPValidate.length) {
for (var index = 0; index < errorPValidate.length; index++) {
errorPValidate.item(index).remove();
}
}
// Check validate form.
if (this.checkValidity()) {
// Trigered simulate button submit.
this.dispatchEvent(new Event("submit"));
} else {
// First Element form invalid.
var elementFormInvalid = this.querySelectorAll(":invalid")[0];
// Focus invalid element.
elementFormInvalid.focus();
// Add class list error invalid element.
elementFormInvalid.classList.add("error-input-validate");
// Create Element message error.
var pErrorValidate = document.createElement("p");
pErrorValidate.classList.add("error-p-validate");
// Message error element invalid.
pErrorValidate.textContent = elementFormInvalid.validationMessage;
// Append parent element.
if (
elementFormInvalid.parentElement.classList.contains(
"div-input-group"
)
) {
elementFormInvalid.parentElement.appendChild(pErrorValidate);
} else {
// TODO: Very ugly
elementFormInvalid.parentNode.parentNode.parentNode.parentNode.appendChild(
pErrorValidate
);
}
}
}
}
]
});
// TODO: Add submit and reset button.
*/ */
} }
@ -2425,6 +1649,117 @@ function getImagesVisualConsole(baseUrl, vcId, nameImg, only, callback) {
}; };
} }
/**
* Create Color range.
* @param {string} baseUrl Base URL to build the API path.
* @param {int} vcId Identifier of the Visual Console.
* @return {Void}
*/
// eslint-disable-next-line no-unused-vars
function createColorRange(baseUrl, vcId) {
var from = document.getElementById("rangeDefaultFrom").value;
var to = document.getElementById("rangeDefaultTo").value;
var color = document.getElementById("color-rangeDefaultColor").value;
if (from == 0 && to == 0) {
return;
}
var fncallback = function(error, data) {
if (error || !data) {
console.log(
"[ERROR]",
"[VISUAL-CONSOLE-CLIENT]",
"[API]",
error ? error.message : "Invalid response"
);
return;
}
$("#itemForm-specific ul.wizard:first").append(data);
return;
};
createColorRangeVisualConsole(baseUrl, vcId, from, to, color, fncallback);
}
/**
* Add color ranges.
* @param {string} baseUrl Base URL to build the API path.
* @param {int} vcId Identifier of the Visual Console.
* @param {int} from From range.
* @param {int} to To range.
* @param {string} color Color range.
* @param {function} callback Function to be executed on request success or fail.
* @return {Object} Cancellable. Object which include and .abort([statusText]) function.
*/
// eslint-disable-next-line no-unused-vars
function createColorRangeVisualConsole(
baseUrl,
vcId,
from,
to,
color,
callback
) {
var apiPath = baseUrl + "/ajax.php";
var jqXHR = null;
// Cancel the ajax requests.
var abort = function(textStatus) {
if (textStatus == null) textStatus = "abort";
// -- XMLHttpRequest.readyState --
// Value State Description
// 0 UNSENT Client has been created. open() not called yet.
// 4 DONE The operation is complete.
if (jqXHR.readyState !== 0 && jqXHR.readyState !== 4)
jqXHR.abort(textStatus);
};
// Failed request handler.
var handleFail = function(jqXHR, textStatus, errorThrown) {
abort();
// Manually aborted or not.
if (textStatus === "abort") {
callback();
} else {
var error = new Error(errorThrown);
error.request = jqXHR;
callback(error);
}
};
// Function which handle success case.
var handleSuccess = function(data) {
callback(null, data);
};
// Visual Console container request.
jqXHR = jQuery
.get(
apiPath,
{
page: "include/rest-api/index",
createColorRangeVisualConsole: 1,
visualConsoleId: vcId,
from: from,
to: to,
color: color
},
"html"
)
.done(handleSuccess)
.fail(handleFail);
// Abortable.
return {
abort: abort
};
}
/** /**
* Onchange time-zone. * Onchange time-zone.
* @return {void} * @return {void}

View File

@ -36,23 +36,11 @@ $createVisualConsoleItem = (bool) get_parameter('createVisualConsoleItem');
$getVisualConsoleItem = (bool) get_parameter('getVisualConsoleItem'); $getVisualConsoleItem = (bool) get_parameter('getVisualConsoleItem');
$removeVisualConsoleItem = (bool) get_parameter('removeVisualConsoleItem'); $removeVisualConsoleItem = (bool) get_parameter('removeVisualConsoleItem');
$copyVisualConsoleItem = (bool) get_parameter('copyVisualConsoleItem'); $copyVisualConsoleItem = (bool) get_parameter('copyVisualConsoleItem');
$getGroupsVisualConsoleItem = (bool) get_parameter(
'getGroupsVisualConsoleItem'
);
$getAllVisualConsole = (bool) get_parameter('getAllVisualConsole');
$getImagesVisualConsole = (bool) get_parameter('getImagesVisualConsole'); $getImagesVisualConsole = (bool) get_parameter('getImagesVisualConsole');
$createColorRangeVisualConsole = (bool) get_parameter(
'createColorRangeVisualConsole'
);
$getTimeZoneVisualConsole = (bool) get_parameter('getTimeZoneVisualConsole'); $getTimeZoneVisualConsole = (bool) get_parameter('getTimeZoneVisualConsole');
$autocompleteAgentsVisualConsole = (bool) get_parameter(
'autocompleteAgentsVisualConsole'
);
$autocompleteModuleVisualConsole = (bool) get_parameter(
'autocompleteModuleVisualConsole'
);
$getCustomGraphVisualConsoleItem = (bool) get_parameter(
'getCustomGraphVisualConsoleItem'
);
$serviceListVisualConsole = (bool) get_parameter( $serviceListVisualConsole = (bool) get_parameter(
'serviceListVisualConsole' 'serviceListVisualConsole'
); );
@ -253,209 +241,69 @@ if ($getVisualConsole === true) {
echo $result; echo $result;
return; return;
} else if ($getGroupsVisualConsoleItem === true) {
$data = users_get_groups_for_select(
$config['id_user'],
'AR',
true,
true
);
$result = array_map(
function ($id) use ($data) {
return [
'value' => $id,
'text' => $data[$id],
];
},
array_keys($data)
);
echo json_encode($result);
return;
} else if ($getAllVisualConsole === true) {
// TODO: Remove.
} else if ($getImagesVisualConsole) { } else if ($getImagesVisualConsole) {
$img = get_parameter('nameImg', 'appliance'); $img = get_parameter('nameImg', 'appliance');
$only = (bool) get_parameter('only', 0); $only = (bool) get_parameter('only', 0);
$count = Item::imagesElementsVC($img, $only); $count = Item::imagesElementsVC($img, $only);
echo json_encode($count); echo json_encode($count);
return; return;
} else if ($createColorRangeVisualConsole) {
$baseUrl = ui_get_full_url('/', false, false, false);
$from = get_parameter('from', 0);
$to = get_parameter('to', 0);
$color = get_parameter('color', 0);
$rangeFrom = [
'name' => 'rangeFrom[]',
'type' => 'number',
'value' => $from,
'return' => true,
];
$rangeTo = [
'name' => 'rangeTo[]',
'type' => 'number',
'value' => $to,
'return' => true,
];
$rangeColor = [
'wrapper' => 'div',
'name' => 'rangeColor[]',
'type' => 'color',
'value' => $color,
'return' => true,
];
$removeBtn = [
'name' => 'Remove',
'label' => '',
'type' => 'button',
'attributes' => 'class="remove-item-img"',
'return' => true,
'script' => 'removeColorRange(\''.$baseUrl.'\',\''.$visualConsoleId.'\')',
];
$liRangeColor = '<li class="interval-color-ranges flex-row flex-start w100p">';
$liRangeColor .= '<label>'.__('From').'</label>';
$liRangeColor .= html_print_input($rangeFrom);
$liRangeColor .= '<label>'.__('To').'</label>';
$liRangeColor .= html_print_input($rangeTo);
$liRangeColor .= '<label>'.__('Color').'</label>';
$liRangeColor .= '<div>';
$liRangeColor .= html_print_input($rangeColor);
$liRangeColor .= '</div>';
$liRangeColor .= '<label></label>';
$liRangeColor .= html_print_input($removeBtn);
$liRangeColor .= '<li>';
echo $liRangeColor;
return;
} else if ($getTimeZoneVisualConsole) { } else if ($getTimeZoneVisualConsole) {
$zone = get_parameter('zone', 'Europe'); $zone = get_parameter('zone', 'Europe');
$zones = Item::zonesVC($zone); $zones = Item::zonesVC($zone);
echo json_encode($zones); echo json_encode($zones);
return; return;
} else if ($autocompleteAgentsVisualConsole) {
$params = (array) get_parameter('data', []);
$string = $params['value'];
// TODO: ACL.
$id_group = (int) get_parameter('id_group', -1);
if ($id_group != -1) {
if ($id_group == 0) {
$user_groups = users_get_groups(
$config['id_user'],
'AR',
true
);
$filter['id_grupo'] = array_keys($user_groups);
} else {
$filter['id_grupo'] = $id_group;
}
}
$filter = [];
$filter['disabled'] = 0;
$filter[] = sprintf(
'(alias LIKE "%%%s%%")
OR (alias NOT LIKE "%%%s%%"
AND nombre COLLATE utf8_general_ci LIKE "%%%s%%")
OR (alias NOT LIKE "%%%s%%"
AND nombre COLLATE utf8_general_ci NOT LIKE "%%%s%%"
AND direccion LIKE "%%%s%%")
OR (alias NOT LIKE "%%%s%%"
AND nombre COLLATE utf8_general_ci NOT LIKE "%%%s%%"
AND direccion NOT LIKE "%%%s%%"
AND comentarios LIKE "%%%s%%"
)',
$string,
$string,
$string,
$string,
$string,
$string,
$string,
$string,
$string,
$string
);
$data = [];
if (is_metaconsole() === true) {
enterprise_include_once('include/functions_metaconsole.php');
$metaconsole_connections = metaconsole_get_connection_names();
// For all nodes.
if (isset($metaconsole_connections) === true
&& is_array($metaconsole_connections) === true
) {
foreach ($metaconsole_connections as $metaconsole) {
// Get server connection data.
$server_data = metaconsole_get_connection($metaconsole);
// Establishes connection.
if (metaconsole_load_external_db($server_data) !== NOERR) {
continue;
}
$agents = agents_get_agents(
$filter,
[
'id_agente',
'nombre',
'direccion',
'alias',
]
);
if (isset($agents) === true && is_array($agents) === true) {
foreach ($agents as $agent) {
$data[] = [
'id' => $agent['id_agente'],
'name' => io_safe_output(
$agent['nombre']
),
'alias' => io_safe_output(
$agent['alias']
),
'ip' => io_safe_output(
$agent['direccion']
),
'filter' => 'alias',
'metaconsoleId' => $server_data['id'],
'metaconsoleName' => $metaconsole,
];
}
}
metaconsole_restore_db();
}
}
} else {
$agents = agents_get_agents(
$filter,
[
'id_agente',
'nombre',
'direccion',
'alias',
]
);
if (isset($agents) === true && is_array($agents) === true) {
foreach ($agents as $agent) {
$data[] = [
'id' => $agent['id_agente'],
'name' => io_safe_output($agent['nombre']),
'alias' => io_safe_output($agent['alias']),
'ip' => io_safe_output($agent['direccion']),
'filter' => 'alias',
];
}
}
}
echo json_encode($data);
return;
} else if ($autocompleteModuleVisualConsole) {
$data = (array) get_parameter('data', []);
$result = [];
if (is_metaconsole()) {
enterprise_include_once('include/functions_metaconsole.php');
$connection = metaconsole_get_connection_by_id($data['metaconsoleId']);
if (metaconsole_connect($connection) !== NOERR) {
echo json_encode($result);
return;
}
}
if ($data['type'] == DONUT_GRAPH) {
// Only type sting.
$filter = sprintf(
'id_tipo_modulo IN (17,23,3,10,33)'
);
}
$agent_modules = agents_get_modules(
$data['agentId'],
false,
$filter
);
if (is_metaconsole()) {
// Restore db connection.
metaconsole_restore_db();
}
if (isset($agent_modules) === true && is_array($agent_modules) === true) {
$result = array_map(
function ($id) use ($agent_modules) {
return [
'moduleId' => $id,
'moduleName' => io_safe_output($agent_modules[$id]),
];
},
array_keys($agent_modules)
);
}
echo json_encode($result);
return;
} else if ($getCustomGraphVisualConsoleItem) {
// Remove.
} else if ($serviceListVisualConsole) { } else if ($serviceListVisualConsole) {
if (!enterprise_installed()) { if (!enterprise_installed()) {
echo json_encode(false); echo json_encode(false);

View File

@ -73,6 +73,7 @@ final class ColorCloud extends Item
protected function encode(array $data): array protected function encode(array $data): array
{ {
$return = parent::encode($data); $return = parent::encode($data);
$colorRanges = null; $colorRanges = null;
$defaultColor = null; $defaultColor = null;
@ -228,10 +229,6 @@ final class ColorCloud extends Item
{ {
$dynamicDataEncoded = static::notEmptyStringOr($data['label'], null); $dynamicDataEncoded = static::notEmptyStringOr($data['label'], null);
if ($dynamicDataEncoded === null) {
throw new \InvalidArgumentException('dynamic data not found');
}
$result = []; $result = [];
try { try {
@ -297,10 +294,6 @@ final class ColorCloud extends Item
$moduleId = $linkedModule['moduleId']; $moduleId = $linkedModule['moduleId'];
$metaconsoleId = $linkedModule['metaconsoleId']; $metaconsoleId = $linkedModule['metaconsoleId'];
if ($moduleId === null) {
throw new \InvalidArgumentException('missing module Id');
}
$dynamicData = static::extractDynamicData($data); $dynamicData = static::extractDynamicData($data);
// Set the initial color. // Set the initial color.
$data['color'] = $dynamicData['defaultColor']; $data['color'] = $dynamicData['defaultColor'];
@ -363,4 +356,216 @@ final class ColorCloud extends Item
} }
/**
* Generates inputs for form (specific).
*
* @param array $values Default values.
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public static function getFormInputs(array $values): array
{
// Default values.
$values = static::getDefaultGeneralValues($values);
// Retrieve global - common inputs.
$inputs = Item::getFormInputs($values);
if (is_array($inputs) !== true) {
throw new Exception(
'[ColorCloud]::getFormInputs parent class return is not an array'
);
}
if ($values['tabSelected'] === 'specific') {
// Autocomplete agents.
$inputs[] = [
'label' => __('Agent'),
'arguments' => [
'type' => 'autocomplete_agent',
'name' => 'agentAlias',
'id_agent_hidden' => $values['agentId'],
'name_agent_hidden' => 'agentId',
'server_id_hidden' => $values['metaconsoleId'],
'name_server_hidden' => 'metaconsoleId',
'return' => true,
'module_input' => true,
'module_name' => 'moduleId',
'module_none' => 'false',
],
];
// Autocomplete module.
$inputs[] = [
'label' => __('Module'),
'arguments' => [
'type' => 'autocomplete_module',
'fields' => $fields,
'name' => 'moduleId',
'selected' => $values['moduleId'],
'return' => true,
'sort' => false,
'agent_id' => $values['agentId'],
'metaconsole_id' => $values['metaconsoleId'],
],
];
// Default color.
$inputs[] = [
'label' => __('Default color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'defaultColor',
'type' => 'color',
'value' => $values['defaultColor'],
'return' => true,
],
];
// Label.
$inputs[] = [
'label' => __('Default').':',
];
$baseUrl = ui_get_full_url('/', false, false, false);
// Default ranges.
$inputs[] = [
'block_id' => 'default-ranges',
'class' => 'flex-row flex-start w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('From'),
'arguments' => [
'id' => 'rangeDefaultFrom',
'name' => 'rangeDefaultFrom',
'type' => 'number',
'value' => 0,
'return' => true,
],
],
[
'label' => __('To'),
'arguments' => [
'id' => 'rangeDefaultTo',
'name' => 'rangeDefaultTo',
'type' => 'number',
'value' => 0,
'return' => true,
],
],
[
'label' => __('Color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'rangeDefaultColor',
'type' => 'color',
'value' => '#000000',
'return' => true,
],
],
[
'arguments' => [
'name' => 'add',
'label' => '',
'type' => 'button',
'attributes' => 'class="add-item-img"',
'return' => true,
'script' => 'createColorRange(\''.$baseUrl.'\',\''.$values['vCId'].'\')',
],
],
],
];
// Label.
$inputs[] = [
'label' => __('Ranges').':',
];
if (isset($values['colorRanges']) === true
&& is_array($values['colorRanges']) === true
&& empty($values['colorRanges']) === false
) {
foreach ($values['colorRanges'] as $k => $v) {
$inputs[] = [
'class' => 'interval-color-ranges flex-row flex-start w100p',
'direct' => 1,
'block_content' => [
[
'label' => __('From'),
'arguments' => [
'name' => 'rangeFrom[]',
'type' => 'number',
'value' => $v['fromValue'],
'return' => true,
],
],
[
'label' => __('To'),
'arguments' => [
'name' => 'rangeTo[]',
'type' => 'number',
'value' => $v['toValue'],
'return' => true,
],
],
[
'label' => __('Color'),
'arguments' => [
'wrapper' => 'div',
'name' => 'rangeColor[]',
'type' => 'color',
'value' => $v['color'],
'return' => true,
],
],
[
'arguments' => [
'name' => 'Remove',
'label' => '',
'type' => 'button',
'attributes' => 'class="remove-item-img"',
'return' => true,
'script' => 'removeColorRange(\''.$baseUrl.'\',\''.$values['vCId'].'\')',
],
],
],
];
}
}
}
return $inputs;
}
/**
* Default values.
*
* @param array $values Array values.
*
* @return array Array with default values.
*
* @overrides Item->getDefaultGeneralValues.
*/
public function getDefaultGeneralValues(array $values): array
{
// Retrieve global - common inputs.
$values = parent::getDefaultGeneralValues($values);
// Default values.
if (isset($values['width']) === false) {
$values['width'] = 300;
}
if (isset($values['height']) === false) {
$values['height'] = 180;
}
return $values;
}
} }

View File

@ -467,7 +467,25 @@ class View extends \HTML
break; break;
case COLOR_CLOUD: case COLOR_CLOUD:
// TODO:XXX. $data['agentId'] = \get_parameter('agentId');
$data['metaconsoleId'] = \get_parameter('metaconsoleId');
$data['moduleId'] = \get_parameter('moduleId');
$data['defaultColor'] = \get_parameter('defaultColor');
$rangeFrom = \get_parameter('rangeFrom');
$rangeTo = \get_parameter('rangeTo');
$rangeColor = \get_parameter('rangeColor');
$arrayRangeColor = [];
foreach ($rangeFrom as $key => $value) {
$arrayRangeColor[$key] = [
'color' => $rangeColor[$key],
'fromValue' => $value,
'toValue' => $rangeTo[$key],
];
}
$data['colorRanges'] = $arrayRangeColor;
break; break;
case SERVICE: case SERVICE:

View File

@ -1761,9 +1761,20 @@ button.deploy,
input.deploy { input.deploy {
background-image: url(../../images/input_deploy.png); background-image: url(../../images/input_deploy.png);
} }
/*#table-add-item select, #table-add-sla select {
width: 180px; button.add-item-img,
}*/ input.add-item-img {
background-image: url(../../images/add.png);
background-repeat: no-repeat;
background-position: center;
}
button.remove-item-img,
input.remove-item-img {
background-image: url(../../images/delete.png);
background-repeat: no-repeat;
background-position: center;
}
/* end of classes for event priorities */ /* end of classes for event priorities */
div#main_pure { div#main_pure {

View File

@ -505,6 +505,18 @@ label span.p-slider {
width: 30px; width: 30px;
} }
li.interval-color-ranges > label,
li#li-default-ranges > label {
margin-right: 15px;
}
li.interval-color-ranges > input[type="number"],
li#li-default-ranges > input[type="number"] {
width: 80px;
}
li.interval-color-ranges > label:not(:first-child),
li#li-default-ranges > label:not(:first-child),
li#li-size-item > label:not(:first-child), li#li-size-item > label:not(:first-child),
li#li-position-item > label:not(:first-child) { li#li-position-item > label:not(:first-child) {
width: initial; width: initial;

File diff suppressed because one or more lines are too long

View File

@ -393,6 +393,18 @@ label span.p-slider {
width: 30px; width: 30px;
} }
li.interval-color-ranges > label,
li#li-default-ranges > label {
margin-right: 15px;
}
li.interval-color-ranges > input[type="number"],
li#li-default-ranges > input[type="number"] {
width: 80px;
}
li.interval-color-ranges > label:not(:first-child),
li#li-default-ranges > label:not(:first-child),
li#li-size-item > label:not(:first-child), li#li-size-item > label:not(:first-child),
li#li-position-item > label:not(:first-child) { li#li-position-item > label:not(:first-child) {
width: initial; width: initial;