VIsual Console Refactor: bugfix
Former-commit-id: f0603f3512dbb224f11d628600857a4b9dbb9f9b
This commit is contained in:
parent
7acee06a00
commit
2952af7f6b
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
global $config;
|
||||
|
||||
if (!is_ajax()) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $config;
|
||||
|
||||
require_once $config['homedir'].'/vendor/autoload.php';
|
||||
|
||||
use Models\VisualConsole\Container as VisualConsole;
|
||||
|
@ -42,7 +42,8 @@ if ($getVisualConsole === true) {
|
|||
|
||||
echo $visualConsole;
|
||||
} else if ($getVisualConsoleItems === true) {
|
||||
echo '['.implode(VisualConsole::getItemsFromDB($visualConsoleId, $aclUserGroups), ',').']';
|
||||
$vcItems = VisualConsole::getItemsFromDB($visualConsoleId, $aclUserGroups);
|
||||
echo '['.implode($vcItems, ',').']';
|
||||
}
|
||||
|
||||
exit;
|
||||
|
|
|
@ -328,37 +328,35 @@ final class Container extends Model
|
|||
*/
|
||||
public static function getItemsFromDB(
|
||||
int $layoutId,
|
||||
array $aclUserGroups=[]
|
||||
array $groupsFilter=[]
|
||||
): array {
|
||||
// If is empty array user view all groups.
|
||||
if (count($aclUserGroups) > 0) {
|
||||
// Filter group for elements groups.
|
||||
$filterCondition = ['id_layout' => $layoutId];
|
||||
$filterCondition['element_group'] = $aclUserGroups;
|
||||
// Format filter mysql.
|
||||
$filter[0] = db_format_array_where_clause_sql(
|
||||
$filterCondition
|
||||
);
|
||||
|
||||
// Filter groups for type groups.
|
||||
// Only true condition if type is GROUP_ITEM.
|
||||
$filterGroup = [];
|
||||
$filterGroup['type'] = GROUP_ITEM;
|
||||
$filterGroup['id_group'] = $aclUserGroups;
|
||||
|
||||
// Format filter mysql.
|
||||
$filter[1] = '('.db_format_array_where_clause_sql(
|
||||
$filterGroup
|
||||
).')';
|
||||
} else {
|
||||
$filter = ['id_layout' => $layoutId];
|
||||
}
|
||||
|
||||
// Default filter.
|
||||
$filter = ['id_layout' => $layoutId];
|
||||
$fields = [
|
||||
'id',
|
||||
'type',
|
||||
];
|
||||
|
||||
// Override the filter if the groups filter is not empty.
|
||||
if (count($groupsFilter) > 0) {
|
||||
// Filter group for elements groups.
|
||||
$filter[] = \db_format_array_where_clause_sql(
|
||||
[
|
||||
'id_layout' => $layoutId,
|
||||
'element_group' => $groupsFilter,
|
||||
]
|
||||
);
|
||||
|
||||
// Filter groups for type groups.
|
||||
// Only true condition if type is GROUP_ITEM.
|
||||
$filter[] = '('.\db_format_array_where_clause_sql(
|
||||
[
|
||||
'type' => GROUP_ITEM,
|
||||
'id_group' => $groupsFilter,
|
||||
]
|
||||
).')';
|
||||
}
|
||||
|
||||
$rows = \db_get_all_rows_filter(
|
||||
'tlayout_data',
|
||||
$filter,
|
||||
|
@ -368,7 +366,6 @@ final class Container extends Model
|
|||
|
||||
if ($rows === false) {
|
||||
$rows = [];
|
||||
// TODO: throw new \Exception('error fetching the data from the DB');.
|
||||
}
|
||||
|
||||
$items = [];
|
||||
|
|
|
@ -28,7 +28,7 @@ interface LineProps extends ItemProps {
|
|||
export function linePropsDecoder(data: UnknownObject): LineProps | never {
|
||||
const lineWidth = parseIntOr(data.lineWidth, 0);
|
||||
|
||||
return {
|
||||
const props: LineProps = {
|
||||
...itemBasePropsDecoder({ ...data, width: 1, height: 1 }), // Object spread. It will merge the properties of the two objects.
|
||||
type: ItemType.LINE_ITEM,
|
||||
label: null,
|
||||
|
@ -52,6 +52,21 @@ export function linePropsDecoder(data: UnknownObject): LineProps | never {
|
|||
lineWidth: lineWidth > 0 ? lineWidth : 1,
|
||||
color: notEmptyStringOr(data.borderColor || data.color, null)
|
||||
};
|
||||
|
||||
/*
|
||||
* We need to enhance the props with the extracted size and position
|
||||
* of the box cause there are missing at the props update. A better
|
||||
* solution would be overriding the props setter to do it there, but
|
||||
* the language doesn't allow it while targetting ES5.
|
||||
* TODO: We need to figure out a more consistent solution.
|
||||
*/
|
||||
|
||||
return {
|
||||
...props,
|
||||
// Enhance the props extracting the box size and position.
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
...Line.extractBoxSizeAndPosition(props)
|
||||
};
|
||||
}
|
||||
|
||||
export default class Line extends Item<LineProps> {
|
||||
|
@ -106,7 +121,7 @@ export default class Line extends Item<LineProps> {
|
|||
* the start and the finish of the line.
|
||||
* @param props Item properties.
|
||||
*/
|
||||
private static extractBoxSizeAndPosition(props: LineProps): Size & Position {
|
||||
public static extractBoxSizeAndPosition(props: LineProps): Size & Position {
|
||||
return {
|
||||
width: Math.abs(props.startPosition.x - props.endPosition.x),
|
||||
height: Math.abs(props.startPosition.y - props.endPosition.y),
|
||||
|
|
Loading…
Reference in New Issue