VIsual Console Refactor: bugfix
Former-commit-id: f0603f3512dbb224f11d628600857a4b9dbb9f9b
This commit is contained in:
parent
7acee06a00
commit
2952af7f6b
|
@ -1,11 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
if (!is_ajax()) {
|
if (!is_ajax()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
global $config;
|
|
||||||
|
|
||||||
require_once $config['homedir'].'/vendor/autoload.php';
|
require_once $config['homedir'].'/vendor/autoload.php';
|
||||||
|
|
||||||
use Models\VisualConsole\Container as VisualConsole;
|
use Models\VisualConsole\Container as VisualConsole;
|
||||||
|
@ -42,7 +42,8 @@ if ($getVisualConsole === true) {
|
||||||
|
|
||||||
echo $visualConsole;
|
echo $visualConsole;
|
||||||
} else if ($getVisualConsoleItems === true) {
|
} else if ($getVisualConsoleItems === true) {
|
||||||
echo '['.implode(VisualConsole::getItemsFromDB($visualConsoleId, $aclUserGroups), ',').']';
|
$vcItems = VisualConsole::getItemsFromDB($visualConsoleId, $aclUserGroups);
|
||||||
|
echo '['.implode($vcItems, ',').']';
|
||||||
}
|
}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
|
@ -328,37 +328,35 @@ final class Container extends Model
|
||||||
*/
|
*/
|
||||||
public static function getItemsFromDB(
|
public static function getItemsFromDB(
|
||||||
int $layoutId,
|
int $layoutId,
|
||||||
array $aclUserGroups=[]
|
array $groupsFilter=[]
|
||||||
): array {
|
): array {
|
||||||
// If is empty array user view all groups.
|
// Default filter.
|
||||||
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];
|
$filter = ['id_layout' => $layoutId];
|
||||||
}
|
|
||||||
|
|
||||||
$fields = [
|
$fields = [
|
||||||
'id',
|
'id',
|
||||||
'type',
|
'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(
|
$rows = \db_get_all_rows_filter(
|
||||||
'tlayout_data',
|
'tlayout_data',
|
||||||
$filter,
|
$filter,
|
||||||
|
@ -368,7 +366,6 @@ final class Container extends Model
|
||||||
|
|
||||||
if ($rows === false) {
|
if ($rows === false) {
|
||||||
$rows = [];
|
$rows = [];
|
||||||
// TODO: throw new \Exception('error fetching the data from the DB');.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$items = [];
|
$items = [];
|
||||||
|
|
|
@ -28,7 +28,7 @@ interface LineProps extends ItemProps {
|
||||||
export function linePropsDecoder(data: UnknownObject): LineProps | never {
|
export function linePropsDecoder(data: UnknownObject): LineProps | never {
|
||||||
const lineWidth = parseIntOr(data.lineWidth, 0);
|
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.
|
...itemBasePropsDecoder({ ...data, width: 1, height: 1 }), // Object spread. It will merge the properties of the two objects.
|
||||||
type: ItemType.LINE_ITEM,
|
type: ItemType.LINE_ITEM,
|
||||||
label: null,
|
label: null,
|
||||||
|
@ -52,6 +52,21 @@ export function linePropsDecoder(data: UnknownObject): LineProps | never {
|
||||||
lineWidth: lineWidth > 0 ? lineWidth : 1,
|
lineWidth: lineWidth > 0 ? lineWidth : 1,
|
||||||
color: notEmptyStringOr(data.borderColor || data.color, null)
|
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> {
|
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.
|
* the start and the finish of the line.
|
||||||
* @param props Item properties.
|
* @param props Item properties.
|
||||||
*/
|
*/
|
||||||
private static extractBoxSizeAndPosition(props: LineProps): Size & Position {
|
public static extractBoxSizeAndPosition(props: LineProps): Size & Position {
|
||||||
return {
|
return {
|
||||||
width: Math.abs(props.startPosition.x - props.endPosition.x),
|
width: Math.abs(props.startPosition.x - props.endPosition.x),
|
||||||
height: Math.abs(props.startPosition.y - props.endPosition.y),
|
height: Math.abs(props.startPosition.y - props.endPosition.y),
|
||||||
|
|
Loading…
Reference in New Issue