continue VC
This commit is contained in:
parent
034bbff2cf
commit
fc024898ef
|
@ -494,6 +494,57 @@ function createVisualConsole(
|
|||
})
|
||||
.init();
|
||||
break;
|
||||
case "service-list":
|
||||
asyncTaskManager
|
||||
.add(identifier + "-" + params.id, function(doneAsyncTask) {
|
||||
var abortable = serviceListVisualConsole(
|
||||
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;
|
||||
|
||||
default:
|
||||
done(new Error("identifier not found"));
|
||||
|
@ -1162,6 +1213,73 @@ function autocompleteModuleVisualConsole(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 serviceListVisualConsole(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",
|
||||
serviceListVisualConsole: 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.
|
||||
|
|
|
@ -34,6 +34,10 @@ $getCustomGraphVisualConsoleItem = (bool) get_parameter(
|
|||
'getCustomGraphVisualConsoleItem'
|
||||
);
|
||||
|
||||
$serviceListVisualConsole = (bool) get_parameter(
|
||||
'serviceListVisualConsole'
|
||||
);
|
||||
|
||||
ob_clean();
|
||||
|
||||
// Retrieve the visual console.
|
||||
|
@ -473,7 +477,7 @@ if ($getVisualConsole === true) {
|
|||
enterprise_include_once('include/functions_metaconsole.php');
|
||||
$data = [];
|
||||
if (is_metaconsole()) {
|
||||
$data = metaconsole_get_custom_graphs();
|
||||
$data = metaconsole_get_custom_graphs(true);
|
||||
} else {
|
||||
$data = custom_graphs_get_user(
|
||||
$config['id_user'],
|
||||
|
@ -495,6 +499,29 @@ if ($getVisualConsole === true) {
|
|||
|
||||
echo json_encode($result);
|
||||
return;
|
||||
} else if ($serviceListVisualConsole) {
|
||||
// Services_get_services_no_ancestors_meta.
|
||||
if (!enterprise_installed()) {
|
||||
echo json_encode(false);
|
||||
return;
|
||||
}
|
||||
|
||||
enterprise_include_once('include/functions_services.php');
|
||||
// Services list.
|
||||
$services = [];
|
||||
$services = enterprise_hook(
|
||||
'services_get_services',
|
||||
[
|
||||
false,
|
||||
[
|
||||
'id',
|
||||
'name',
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
echo io_safe_output(json_encode($services));
|
||||
return;
|
||||
}
|
||||
|
||||
exit;
|
||||
|
|
|
@ -139,11 +139,11 @@ form.visual-console-item-edition > input[type="submit"] {
|
|||
}
|
||||
|
||||
.show-elements {
|
||||
visibility: visible;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.hide-elements {
|
||||
visibility: hidden;
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Styles for the solid icons */
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -32,6 +32,7 @@ export type ModuleGraphProps = {
|
|||
backgroundType: "white" | "black" | "transparent";
|
||||
graphType: "line" | "area";
|
||||
period: number | null;
|
||||
customGraphId: number | null;
|
||||
} & ItemProps &
|
||||
WithModuleProps &
|
||||
LinkedVisualConsoleProps;
|
||||
|
@ -92,6 +93,7 @@ export function moduleGraphPropsDecoder(
|
|||
backgroundType: parseBackgroundType(data.backgroundType),
|
||||
period: parseIntOr(data.period, null),
|
||||
graphType: parseGraphType(data.graphType),
|
||||
customGraphId: parseIntOr(data.customGraphId, null),
|
||||
...modulePropsDecoder(data), // Object spread. It will merge the properties of the two objects.
|
||||
...linkedVCPropsDecoder(data) // Object spread. It will merge the properties of the two objects.
|
||||
};
|
||||
|
@ -162,17 +164,17 @@ class ChooseTypeInputGroup extends InputGroup<Partial<ModuleGraphProps>> {
|
|||
radioButtonModule.name = "type-graph";
|
||||
radioButtonModule.value = "module";
|
||||
radioButtonModule.required = true;
|
||||
radioButtonModule.checked = this.initialData.customGraphId ? false : true;
|
||||
|
||||
divContainer.appendChild(radioButtonModule);
|
||||
|
||||
radioButtonModule.addEventListener("change", event => {
|
||||
const show = document.getElementsByClassName(
|
||||
radioButtonModule.addEventListener("change", e => {
|
||||
this.updateRadioButton(
|
||||
"input-group-custom-graph-list",
|
||||
"input-group-agent-autocomplete"
|
||||
);
|
||||
for (let i = 0; i < show.length; i++) {
|
||||
show[i].classList.add("show-elements");
|
||||
show[i].classList.remove("hide-elements");
|
||||
}
|
||||
//Remove Id graph custom.
|
||||
this.updateData({ customGraphId: 0 });
|
||||
});
|
||||
|
||||
const radioButtonCustomLabel = document.createElement("label");
|
||||
|
@ -183,38 +185,34 @@ class ChooseTypeInputGroup extends InputGroup<Partial<ModuleGraphProps>> {
|
|||
const radioButtonCustom = document.createElement("input");
|
||||
radioButtonCustom.type = "radio";
|
||||
radioButtonCustom.name = "type-graph";
|
||||
radioButtonCustom.value = "module";
|
||||
radioButtonCustom.value = "custom";
|
||||
radioButtonCustom.required = true;
|
||||
radioButtonCustom.checked = this.initialData.customGraphId ? true : false;
|
||||
|
||||
divContainer.appendChild(radioButtonCustom);
|
||||
|
||||
radioButtonCustom.addEventListener("change", event => {
|
||||
const show = document.getElementsByClassName(
|
||||
"input-group-agent-autocomplete"
|
||||
this.updateRadioButton(
|
||||
"input-group-agent-autocomplete",
|
||||
"input-group-custom-graph-list"
|
||||
);
|
||||
for (let i = 0; i < show.length; i++) {
|
||||
show[i].classList.add("hide-elements");
|
||||
show[i].classList.remove("show-elements");
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
backgroundTypeSelect.value =
|
||||
this.currentData.backgroundType ||
|
||||
this.initialData.backgroundType ||
|
||||
"default";
|
||||
|
||||
backgroundTypeSelect.addEventListener("change", event => {
|
||||
this.updateData({
|
||||
backgroundType: parseBackgroundType(
|
||||
(event.target as HTMLSelectElement).value
|
||||
)
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
return divContainer;
|
||||
}
|
||||
|
||||
private updateRadioButton = (id: string, id2: string): void => {
|
||||
const itemAgentAutocomplete = document.getElementsByClassName(id);
|
||||
for (let i = 0; i < itemAgentAutocomplete.length; i++) {
|
||||
itemAgentAutocomplete[i].classList.add("hide-elements");
|
||||
itemAgentAutocomplete[i].classList.remove("show-elements");
|
||||
}
|
||||
const itemCustomGraphList = document.getElementsByClassName(id2);
|
||||
for (let i = 0; i < itemCustomGraphList.length; i++) {
|
||||
itemCustomGraphList[i].classList.add("show-elements");
|
||||
itemCustomGraphList[i].classList.remove("hide-elements");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -222,7 +220,7 @@ class ChooseTypeInputGroup extends InputGroup<Partial<ModuleGraphProps>> {
|
|||
* This item consists of a label and a Acl Group type select.
|
||||
* Acl is stored in the aclGroupId property
|
||||
*/
|
||||
class CustomGraphInputGroup extends InputGroup<Partial<ItemProps>> {
|
||||
class CustomGraphInputGroup extends InputGroup<Partial<ModuleGraphProps>> {
|
||||
protected createContent(): HTMLElement | HTMLElement[] {
|
||||
const customGraphLabel = document.createElement("label");
|
||||
customGraphLabel.textContent = t("Custom graph");
|
||||
|
@ -257,17 +255,29 @@ class CustomGraphInputGroup extends InputGroup<Partial<ItemProps>> {
|
|||
customGraphSelect.appendChild(optionElement);
|
||||
});
|
||||
|
||||
/*
|
||||
customGraphSelect.addEventListener("change", event => {
|
||||
this.updateData({
|
||||
aclGroupId: parseIntOr((event.target as HTMLSelectElement).value, 0)
|
||||
});
|
||||
});
|
||||
|
||||
customGraphSelect.value = `${this.currentData.aclGroupId ||
|
||||
this.initialData.aclGroupId ||
|
||||
customGraphSelect.value = `${this.currentData.customGraphId ||
|
||||
this.initialData.customGraphId ||
|
||||
0}`;
|
||||
*/
|
||||
|
||||
customGraphSelect.addEventListener("change", event => {
|
||||
if (typeof (event.target as HTMLSelectElement).value === "string") {
|
||||
const id = (event.target as HTMLSelectElement).value.split("|")[0];
|
||||
const metaconsoleId = (event.target as HTMLSelectElement).value.split(
|
||||
"|"
|
||||
)[1];
|
||||
this.updateData({
|
||||
customGraphId: parseIntOr(id, 0),
|
||||
metaconsoleId: parseIntOr(metaconsoleId, 0)
|
||||
});
|
||||
} else {
|
||||
this.updateData({
|
||||
customGraphId: parseIntOr(
|
||||
(event.target as HTMLSelectElement).value,
|
||||
0
|
||||
)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
customGraphLabel.appendChild(customGraphSelect);
|
||||
}
|
||||
|
@ -416,6 +426,9 @@ export default class ModuleGraph extends Item<ModuleGraphProps> {
|
|||
* PeriodInputGroup
|
||||
* GraphTypeInputGroup
|
||||
* BackgroundTypeInputGroup
|
||||
* ChooseTypeInputGroup
|
||||
* AgentModuleInputGroup
|
||||
* CustomGraphInputGroup
|
||||
*/
|
||||
public getFormContainer(): FormContainer {
|
||||
const formContainer = super.getFormContainer();
|
||||
|
@ -434,11 +447,25 @@ export default class ModuleGraph extends Item<ModuleGraphProps> {
|
|||
formContainer.addInputGroup(
|
||||
new ChooseTypeInputGroup("show-type-graph", this.props)
|
||||
);
|
||||
|
||||
const displayAgent = this.props.customGraphId
|
||||
? "hide-elements"
|
||||
: "show-elements";
|
||||
const displayCustom = this.props.customGraphId
|
||||
? "show-elements"
|
||||
: "hide-elements ";
|
||||
|
||||
formContainer.addInputGroup(
|
||||
new AgentModuleInputGroup("agent-autocomplete", this.props)
|
||||
new AgentModuleInputGroup(
|
||||
`agent-autocomplete ${displayAgent}`,
|
||||
this.props
|
||||
)
|
||||
);
|
||||
formContainer.addInputGroup(
|
||||
new CustomGraphInputGroup("custom-graph-list", this.props)
|
||||
new CustomGraphInputGroup(
|
||||
`custom-graph-list ${displayCustom}`,
|
||||
this.props
|
||||
)
|
||||
);
|
||||
return formContainer;
|
||||
}
|
||||
|
|
|
@ -3,9 +3,21 @@ import {
|
|||
stringIsEmpty,
|
||||
notEmptyStringOr,
|
||||
decodeBase64,
|
||||
parseIntOr
|
||||
parseIntOr,
|
||||
t
|
||||
} from "../lib";
|
||||
import Item, { ItemType, ItemProps, itemBasePropsDecoder } from "../Item";
|
||||
import Item, {
|
||||
ItemType,
|
||||
ItemProps,
|
||||
itemBasePropsDecoder,
|
||||
ImageInputGroup
|
||||
} from "../Item";
|
||||
import { FormContainer, InputGroup } from "../Form";
|
||||
import fontAwesomeIcon from "../lib/FontAwesomeIcon";
|
||||
import {
|
||||
faCircleNotch,
|
||||
faExclamationCircle
|
||||
} from "@fortawesome/free-solid-svg-icons";
|
||||
|
||||
export type ServiceProps = {
|
||||
type: ItemType.SERVICE;
|
||||
|
@ -52,6 +64,79 @@ export function servicePropsDecoder(data: AnyObject): ServiceProps | never {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to add item to the general items form
|
||||
* This item consists of a label and a Service List type select.
|
||||
*/
|
||||
class ServiceListInputGroup extends InputGroup<Partial<ServiceProps>> {
|
||||
protected createContent(): HTMLElement | HTMLElement[] {
|
||||
const serviceListLabel = document.createElement("label");
|
||||
serviceListLabel.textContent = t("Service");
|
||||
|
||||
const spinner = fontAwesomeIcon(faCircleNotch, t("Spinner"), {
|
||||
size: "small",
|
||||
spin: true
|
||||
});
|
||||
serviceListLabel.appendChild(spinner);
|
||||
|
||||
this.requestData("service-list", {}, (error, data) => {
|
||||
// Remove Spinner.
|
||||
spinner.remove();
|
||||
|
||||
if (error) {
|
||||
serviceListLabel.appendChild(
|
||||
fontAwesomeIcon(faExclamationCircle, t("Error"), {
|
||||
size: "small",
|
||||
color: "#e63c52"
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (data instanceof Array) {
|
||||
const serviceListSelect = document.createElement("select");
|
||||
serviceListSelect.required = true;
|
||||
|
||||
data.forEach(option => {
|
||||
const optionElement = document.createElement("option");
|
||||
optionElement.value = option.id;
|
||||
optionElement.textContent = option.name;
|
||||
serviceListSelect.appendChild(optionElement);
|
||||
});
|
||||
|
||||
serviceListSelect.value = `${this.currentData.serviceId ||
|
||||
this.initialData.serviceId ||
|
||||
0}`;
|
||||
|
||||
serviceListSelect.addEventListener("change", event => {
|
||||
if (typeof (event.target as HTMLSelectElement).value === "string") {
|
||||
const id = (event.target as HTMLSelectElement).value.split("|")[0];
|
||||
/*
|
||||
const metaconsoleId = (event.target as HTMLSelectElement).value.split(
|
||||
"|"
|
||||
)[1];
|
||||
*/
|
||||
this.updateData({
|
||||
serviceId: parseIntOr(id, 0)
|
||||
//metaconsoleId: parseIntOr(metaconsoleId, 0)
|
||||
});
|
||||
} else {
|
||||
this.updateData({
|
||||
serviceId: parseIntOr(
|
||||
(event.target as HTMLSelectElement).value,
|
||||
0
|
||||
)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
serviceListLabel.appendChild(serviceListSelect);
|
||||
}
|
||||
});
|
||||
|
||||
return serviceListLabel;
|
||||
}
|
||||
}
|
||||
|
||||
export default class Service extends Item<ServiceProps> {
|
||||
public createDomElement(): HTMLElement {
|
||||
const element = document.createElement("div");
|
||||
|
@ -67,4 +152,26 @@ export default class Service extends Item<ServiceProps> {
|
|||
|
||||
return element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @override function to add or remove inputsGroups those that are not necessary.
|
||||
* Add to:
|
||||
* ImageInputGroup
|
||||
* ServiceListInputGroup
|
||||
*/
|
||||
public getFormContainer(): FormContainer {
|
||||
const formContainer = super.getFormContainer();
|
||||
formContainer.addInputGroup(
|
||||
new ImageInputGroup("image-console", {
|
||||
...this.props,
|
||||
imageKey: "imageSrc",
|
||||
showStatusImg: false
|
||||
})
|
||||
);
|
||||
formContainer.addInputGroup(
|
||||
new ServiceListInputGroup("service-list", this.props)
|
||||
);
|
||||
|
||||
return formContainer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,9 +103,9 @@ form.visual-console-item-edition > input[type="submit"] {
|
|||
}
|
||||
|
||||
.show-elements {
|
||||
visibility: visible;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.hide-elements {
|
||||
visibility: hidden;
|
||||
display: none;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue