add mode maintenance VC pandora_enterprise#4822
This commit is contained in:
parent
b98b0f3ab3
commit
9c93a99fb2
|
@ -1,5 +1,7 @@
|
|||
START TRANSACTION;
|
||||
|
||||
ALTER TABLE `tlayout` ADD COLUMN `maintenance_mode` TEXT NULL;
|
||||
|
||||
ALTER TABLE `tmodule_inventory` ADD COLUMN `script_mode` INT NOT NULL DEFAULT 2;
|
||||
ALTER TABLE `tmodule_inventory` ADD COLUMN `script_path` VARCHAR(1000) DEFAULT '';
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ $ajax = true;
|
|||
$render_map = (bool) get_parameter('render_map', false);
|
||||
$graph_javascript = (bool) get_parameter('graph_javascript', false);
|
||||
$force_remote_check = (bool) get_parameter('force_remote_check', false);
|
||||
$update_maintanance_mode = (bool) get_parameter('update_maintanance_mode', false);
|
||||
$load_css_cv = (bool) get_parameter('load_css_cv', false);
|
||||
|
||||
if ($render_map) {
|
||||
|
@ -99,3 +100,29 @@ if ($load_css_cv === true) {
|
|||
echo $output;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($update_maintanance_mode === true) {
|
||||
$idVisualConsole = (int) get_parameter('idVisualConsole', 0);
|
||||
$mode = (bool) get_parameter('mode', false);
|
||||
|
||||
$values = [];
|
||||
if ($mode === true) {
|
||||
$values['maintenance_mode'] = json_encode(
|
||||
[
|
||||
'user' => $config['id_user'],
|
||||
'timestamp' => time(),
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$values['maintenance_mode'] = null;
|
||||
}
|
||||
|
||||
$result = db_process_sql_update(
|
||||
'tlayout',
|
||||
$values,
|
||||
['id' => $idVisualConsole]
|
||||
);
|
||||
|
||||
echo json_encode(['result' => $result]);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -117,6 +117,17 @@ function createVisualConsole(
|
|||
visualConsole.updateElements(items);
|
||||
}
|
||||
|
||||
console.log(visualConsole.props);
|
||||
console.log(id_user);
|
||||
if (
|
||||
visualConsole.props.maintenanceMode != null &&
|
||||
visualConsole.props.maintenanceMode.user !== id_user
|
||||
) {
|
||||
visualConsole.enableMaintenanceMode();
|
||||
} else {
|
||||
visualConsole.disableMaintenanceMode();
|
||||
}
|
||||
|
||||
// Emit the VC update event.
|
||||
if (onUpdate) onUpdate(prevProps, visualConsole.props);
|
||||
} catch (ignored) {} // eslint-disable-line no-empty
|
||||
|
@ -151,6 +162,7 @@ function createVisualConsole(
|
|||
// Wait to start the fetch interval.
|
||||
asyncTaskManager.init("visual-console-start");
|
||||
} else {
|
||||
console.log("vendria aki");
|
||||
// Start the fetch interval immediately.
|
||||
asyncTaskManager.init("visual-console");
|
||||
}
|
||||
|
@ -159,6 +171,7 @@ function createVisualConsole(
|
|||
// Initialize the Visual Console.
|
||||
try {
|
||||
visualConsole = new VisualConsole(container, props, items);
|
||||
|
||||
// VC Item clicked.
|
||||
visualConsole.onItemClick(function(e) {
|
||||
var data = e.item.props || {};
|
||||
|
@ -357,7 +370,6 @@ function createVisualConsole(
|
|||
})
|
||||
.init();
|
||||
});
|
||||
|
||||
// VC Item resized.
|
||||
visualConsole.onItemResized(function(e) {
|
||||
var item = e.item;
|
||||
|
@ -473,6 +485,13 @@ function createVisualConsole(
|
|||
updateVisualConsole(visualConsole.props.id, interval, null, dimensions);
|
||||
}
|
||||
},
|
||||
forceUpdateVisualConsole: function() {
|
||||
console.log(visualConsole);
|
||||
console.log("Entrando desde el force");
|
||||
asyncTaskManager.cancel("visual-console");
|
||||
asyncTaskManager.cancel("visual-console-start");
|
||||
updateVisualConsole(visualConsole.props.id);
|
||||
},
|
||||
createItem: function(typeString) {
|
||||
var type;
|
||||
switch (typeString) {
|
||||
|
|
|
@ -90,6 +90,7 @@ final class Container extends Model
|
|||
'backgroundURL' => static::extractBackgroundUrl($data),
|
||||
'relationLineWidth' => (int) $data['relationLineWidth'],
|
||||
'hash' => static::extractHash($data),
|
||||
'maintenanceMode' => static::extractMaintenanceMode($data),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -238,6 +239,30 @@ final class Container extends Model
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a background color value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the color (not empty) or null.
|
||||
*/
|
||||
private static function extractMaintenanceMode(array $data)
|
||||
{
|
||||
$maintenance_mode = static::notEmptyStringOr(
|
||||
static::issetInArray(
|
||||
$data,
|
||||
[
|
||||
'maintenanceMode',
|
||||
'maintenance_mode',
|
||||
]
|
||||
),
|
||||
null
|
||||
);
|
||||
|
||||
return ($maintenance_mode !== null) ? json_decode($maintenance_mode, true) : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the "is favorite" switch value.
|
||||
*
|
||||
|
@ -299,6 +324,9 @@ final class Container extends Model
|
|||
// Clean HTML entities.
|
||||
$row = \io_safe_output($row);
|
||||
|
||||
hd('?????????????????????', true);
|
||||
hd($row, true);
|
||||
|
||||
$row['relationLineWidth'] = (int) $config['vc_line_thickness'];
|
||||
|
||||
$backgroundUrl = static::extractBackgroundUrl($row);
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 92 KiB |
|
@ -7,6 +7,16 @@
|
|||
margin-top: 5px;
|
||||
}
|
||||
|
||||
#visual-console-container.is-maintenance {
|
||||
border: 2px solid green;
|
||||
|
||||
background-image: url(maintenanceMode.png) !important;
|
||||
}
|
||||
|
||||
#visual-console-container.is-maintenance :nth-child(1) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.visual-console-item {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
|
|
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
|
@ -33,7 +33,6 @@ global $config;
|
|||
check_login();
|
||||
|
||||
require_once $config['homedir'].'/vendor/autoload.php';
|
||||
// TODO: include file functions.
|
||||
require_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
|
||||
|
||||
|
@ -103,6 +102,9 @@ $aclRead = (bool) check_acl_restricted_all($config['id_user'], $groupId, 'VR')
|
|||
$aclWrite = (bool) check_acl_restricted_all($config['id_user'], $groupId, 'VW');
|
||||
$aclManage = (bool) check_acl_restricted_all($config['id_user'], $groupId, 'VM');
|
||||
|
||||
// Maintenance Mode.
|
||||
$maintenanceMode = $visualConsoleData['maintenanceMode'];
|
||||
|
||||
if ($aclRead === false && $aclWrite === false && $aclManage === false) {
|
||||
db_pandora_audit(
|
||||
AUDIT_LOG_ACL_VIOLATION,
|
||||
|
@ -398,18 +400,56 @@ if ($pure === false) {
|
|||
echo '</div>';
|
||||
|
||||
if ($aclWrite === true || $aclManage === true) {
|
||||
if (!is_metaconsole()) {
|
||||
echo '<a id ="force_check" href="" style="margin-right: 25px;">'.html_print_image(
|
||||
echo '<div class="flex-row" style="width:220px;">';
|
||||
if (is_metaconsole() === false) {
|
||||
echo '<div id="force_check_control" class="flex-column">';
|
||||
echo html_print_label(__('Force'), 'force-mode', true);
|
||||
echo '<a id ="force_check" href="">';
|
||||
echo html_print_image(
|
||||
'images/target.png',
|
||||
true,
|
||||
[
|
||||
'title' => __('Force remote checks'),
|
||||
'class' => 'invert_filter',
|
||||
]
|
||||
).'</a>';
|
||||
);
|
||||
echo '</a>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
$style_edit_mode = '';
|
||||
if ($aclManage === true) {
|
||||
$style = '';
|
||||
$value_maintenance_mode = true;
|
||||
if ($maintenanceMode === null) {
|
||||
$style = ' style="visibility:hidden"';
|
||||
$value_maintenance_mode = false;
|
||||
} else {
|
||||
if ($maintenanceMode['user'] !== $config['id_user']) {
|
||||
$style_edit_mode = ' style="visibility:hidden"';
|
||||
}
|
||||
}
|
||||
|
||||
echo '<div id="maintenance-mode-control" class="flex-column" '.$style.'>';
|
||||
echo html_print_label(
|
||||
__('Maintenance Mode'),
|
||||
'maintenance-mode',
|
||||
true
|
||||
);
|
||||
echo html_print_checkbox_switch(
|
||||
'maintenance-mode',
|
||||
1,
|
||||
$value_maintenance_mode,
|
||||
true
|
||||
);
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '<div id="edit-mode-control" class="flex-column" '.$style_edit_mode.'>';
|
||||
echo html_print_label(__('Edit Mode'), 'edit-mode', true);
|
||||
echo html_print_checkbox_switch('edit-mode', 1, false, true);
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
@ -676,27 +716,83 @@ ui_require_css_file('form');
|
|||
items,
|
||||
baseUrl,
|
||||
<?php echo ($refr * 1000); ?>,
|
||||
handleUpdate
|
||||
handleUpdate,
|
||||
false,
|
||||
undefined,
|
||||
'<?php echo $config['id_user']; ?>',
|
||||
);
|
||||
|
||||
console.log(props);
|
||||
if(props.maintenanceMode != null) {
|
||||
if(props.maintenanceMode.user !== '<?php echo $config['id_user']; ?>') {
|
||||
visualConsoleManager.visualConsole.enableMaintenanceMode();
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
if ($edit_capable === true) {
|
||||
?>
|
||||
// Enable/disable the edition mode.
|
||||
$('input[name=edit-mode]').change(function(event) {
|
||||
const maintenanceMode = '<?php echo json_encode($maintenanceMode); ?>';
|
||||
if ($(this).prop('checked')) {
|
||||
visualConsoleManager.visualConsole.enableEditMode();
|
||||
visualConsoleManager.changeUpdateInterval(0);
|
||||
$('#force_check').hide();
|
||||
$('#force_check_control').hide();
|
||||
$('#edit-controls').css('visibility', '');
|
||||
if (maintenanceMode == 'null') {
|
||||
$('#maintenance-mode-control').css('visibility', '');
|
||||
}
|
||||
} else {
|
||||
visualConsoleManager.visualConsole.disableEditMode();
|
||||
visualConsoleManager.visualConsole.unSelectItems();
|
||||
visualConsoleManager.changeUpdateInterval(<?php echo ($refr * 1000); ?>); // To ms.
|
||||
$('#force_check_control').show();
|
||||
$('#edit-controls').css('visibility', 'hidden');
|
||||
$('#force_check').show();
|
||||
if(maintenanceMode == 'null') {
|
||||
$('#maintenance-mode-control').css('visibility', 'hidden');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Enable/disable the maintenance mode.
|
||||
$('input[name=maintenance-mode]').click(function(event) {
|
||||
event.preventDefault();
|
||||
const idVisualConsole = '<?php echo $visualConsoleId; ?>';
|
||||
const mode = ($(this).prop('checked') === true) ? 1 : 0;
|
||||
|
||||
confirmDialog({
|
||||
title: '<?php echo __('Maintenance mode'); ?>',
|
||||
message: '<?php echo __('XXXXXXXXXXXXXXXXXXX'); ?>',
|
||||
onAccept: function() {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "ajax.php",
|
||||
dataType: "json",
|
||||
data: {
|
||||
page: "include/ajax/visual_console.ajax",
|
||||
update_maintanance_mode: true,
|
||||
idVisualConsole: idVisualConsole,
|
||||
mode: mode
|
||||
},
|
||||
success: function (data) {
|
||||
if(data.result) {
|
||||
console.log('----------------');
|
||||
$('input[name=maintenance-mode]').prop('checked', mode);
|
||||
$('input[name=maintenance-mode]').trigger('change');
|
||||
|
||||
//if ($('input[name=edit-mode]').prop('checked') === false) {
|
||||
// $('#maintenance-mode-control').css('visibility', 'hidden');
|
||||
//}
|
||||
}
|
||||
},
|
||||
error: function (err) {
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
@ -797,6 +893,7 @@ if ($edit_capable === true) {
|
|||
|
||||
function resetInterval() {
|
||||
visualConsoleManager.changeUpdateInterval(<?php echo ($refr * 1000); ?>);
|
||||
visualConsoleManager.forceUpdateVisualConsole();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1676,6 +1676,7 @@ CREATE TABLE IF NOT EXISTS `tlayout` (
|
|||
`background_color` VARCHAR(50) NOT NULL DEFAULT '#FFF',
|
||||
`is_favourite` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`auto_adjust` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`maintenance_mode` TEXT NULL,
|
||||
PRIMARY KEY(`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
|
|
|
@ -591,6 +591,9 @@ abstract class VisualConsoleItem<Props extends ItemProps> {
|
|||
});
|
||||
|
||||
// Metadata state.
|
||||
if (this.meta.maintenanceMode) {
|
||||
box.classList.add("is-maintenance");
|
||||
}
|
||||
if (this.meta.editMode) {
|
||||
box.classList.add("is-editing");
|
||||
}
|
||||
|
@ -877,8 +880,12 @@ abstract class VisualConsoleItem<Props extends ItemProps> {
|
|||
}
|
||||
|
||||
// Change metadata related things.
|
||||
if (!prevMeta || prevMeta.editMode !== this.meta.editMode) {
|
||||
if (this.meta.editMode) {
|
||||
if (
|
||||
!prevMeta ||
|
||||
prevMeta.editMode !== this.meta.editMode ||
|
||||
prevMeta.maintenanceMode !== this.meta.maintenanceMode
|
||||
) {
|
||||
if (this.meta.editMode && this.meta.maintenanceMode === false) {
|
||||
this.elementRef.classList.add("is-editing");
|
||||
} else {
|
||||
this.elementRef.classList.remove("is-editing");
|
||||
|
|
|
@ -159,6 +159,12 @@ export interface VisualConsoleProps extends Size {
|
|||
backgroundColor: string | null;
|
||||
isFavorite: boolean;
|
||||
relationLineWidth: number;
|
||||
maintenanceMode: maintenanceModeInterface | null;
|
||||
}
|
||||
|
||||
export interface maintenanceModeInterface {
|
||||
user: string;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -181,7 +187,8 @@ export function visualConsolePropsDecoder(
|
|||
backgroundURL,
|
||||
backgroundColor,
|
||||
isFavorite,
|
||||
relationLineWidth
|
||||
relationLineWidth,
|
||||
maintenanceMode
|
||||
} = data;
|
||||
|
||||
if (id == null || isNaN(parseInt(id))) {
|
||||
|
@ -202,6 +209,7 @@ export function visualConsolePropsDecoder(
|
|||
backgroundColor: notEmptyStringOr(backgroundColor, null),
|
||||
isFavorite: parseBoolean(isFavorite),
|
||||
relationLineWidth: parseIntOr(relationLineWidth, 0),
|
||||
maintenanceMode: maintenanceMode,
|
||||
...sizePropsDecoder(data)
|
||||
};
|
||||
}
|
||||
|
@ -1222,6 +1230,28 @@ export default class VisualConsole {
|
|||
this.containerRef.classList.remove("is-editing");
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the maintenance mode.
|
||||
*/
|
||||
public enableMaintenanceMode(): void {
|
||||
this.elements.forEach(item => {
|
||||
item.meta = { ...item.meta, maintenanceMode: true };
|
||||
});
|
||||
this.containerRef.classList.add("is-maintenance");
|
||||
this.containerRef.classList.remove("is-editing");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the maintenance mode.
|
||||
*/
|
||||
public disableMaintenanceMode(): void {
|
||||
this.elements.forEach(item => {
|
||||
item.meta = { ...item.meta, maintenanceMode: false };
|
||||
});
|
||||
this.containerRef.classList.remove("is-maintenance");
|
||||
this.containerRef.classList.add("is-editing");
|
||||
}
|
||||
|
||||
/**
|
||||
* Select an item.
|
||||
* @param itemId Item Id.
|
||||
|
|
|
@ -275,6 +275,7 @@ export function itemMetaDecoder(data: UnknownObject): ItemMeta | never {
|
|||
receivedAt,
|
||||
error,
|
||||
editMode: parseBoolean(data.editMode),
|
||||
maintenanceMode: parseBoolean(data.maintenanceMode),
|
||||
isFromCache: parseBoolean(data.isFromCache),
|
||||
isFetching: false,
|
||||
isUpdating: false,
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 92 KiB |
|
@ -133,6 +133,7 @@ describe("itemMetaDecoder function", () => {
|
|||
isFetching: false,
|
||||
isUpdating: false,
|
||||
editMode: false,
|
||||
maintenanceMode: false,
|
||||
isBeingMoved: false,
|
||||
isBeingResized: false,
|
||||
isSelected: false,
|
||||
|
@ -154,6 +155,7 @@ describe("itemMetaDecoder function", () => {
|
|||
isFetching: false,
|
||||
isUpdating: false,
|
||||
editMode: true,
|
||||
maintenanceMode: false,
|
||||
isBeingMoved: false,
|
||||
isBeingResized: false,
|
||||
isSelected: false,
|
||||
|
|
|
@ -61,5 +61,6 @@ export interface ItemMeta {
|
|||
isBeingMoved: boolean;
|
||||
isBeingResized: boolean;
|
||||
editMode: boolean;
|
||||
maintenanceMode: boolean;
|
||||
lineMode: boolean;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,16 @@
|
|||
margin-top: 5px;
|
||||
}
|
||||
|
||||
#visual-console-container.is-maintenance {
|
||||
border: 2px solid green;
|
||||
|
||||
background-image: url(./lib/maintenanceMode.png) !important;
|
||||
}
|
||||
|
||||
#visual-console-container.is-maintenance :nth-child(1) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.visual-console-item {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
|
|
Loading…
Reference in New Issue