Added save in onItemMoved

This commit is contained in:
Daniel Maya 2019-06-18 10:13:56 +02:00
parent e9b4dea6c5
commit 589000fb6c
6 changed files with 42 additions and 17 deletions

View File

@ -144,7 +144,8 @@ function createVisualConsole(
var id = e.item.props.id;
var data = {
x: e.newPosition.x,
y: e.newPosition.y
y: e.newPosition.y,
type: e.item.props.type
};
var taskId = "visual-console-item-move-" + id;

View File

@ -13,6 +13,7 @@ use Models\VisualConsole\Container as VisualConsole;
$visualConsoleId = (int) get_parameter('visualConsoleId');
$getVisualConsole = (bool) get_parameter('getVisualConsole');
$getVisualConsoleItems = (bool) get_parameter('getVisualConsoleItems');
$updateVisualConsoleItem = (bool) get_parameter('updateVisualConsoleItem');
// Check groups can access user.
$aclUserGroups = [];
@ -44,6 +45,21 @@ if ($getVisualConsole === true) {
} else if ($getVisualConsoleItems === true) {
$vcItems = VisualConsole::getItemsFromDB($visualConsoleId, $aclUserGroups);
echo '['.implode($vcItems, ',').']';
} else if ($updateVisualConsoleItem === true) {
$visualConsoleId = (integer) get_parameter('visualConsoleId');
$visualConsoleItemId = (integer) get_parameter('visualConsoleItemId');
$data = get_parameter('data');
$class = VisualConsole::getItemClass($data['type']);
$item_data = [];
$item_data['id'] = $visualConsoleItemId;
$item_data['id_layout'] = $visualConsoleId;
$item_data['type'] = $data['type'];
$item = $class::fromDB($item_data);
$item->save($item->toArray(), $data);
}
exit;

View File

@ -68,7 +68,7 @@ abstract class Model
*
* @abstract
*/
abstract public function save(array $data=[]): bool;
abstract public function save(array $data=[], array $newdata=[]);
/**
@ -93,7 +93,7 @@ abstract class Model
*
* @return self Instance of the model.
*/
public static function fromArray(array $data)
public static function fromArray(array $data): self
{
// The reserved word static refers to the invoked class at runtime.
return new static($data);

View File

@ -117,7 +117,7 @@ final class Container extends Model
*
* @overrides Model::save.
*/
public function save(array $data=[]): bool
public function save(array $data=[], array $newdata=[]): bool
{
return true;
}
@ -396,7 +396,6 @@ final class Container extends Model
try {
array_push($items, $class::fromDB($data));
hd($class::save($data), true);
} catch (\Throwable $e) {
// TODO: Log this?
}

View File

@ -1627,24 +1627,33 @@ class Item extends CachedModel
*
* @overrides Model::save.
*/
public function save(array $data=[]): bool
public function save(array $data=[], array $newdata=[])
{
$save = static::encode($data);
$save = self::encode($data);
$newSave = self::encode($newdata);
if (empty($save['id'])) {
// Insert.
$result = \db_process_sql_insert('tlayout_data', $save);
// static = static::fromDB(['id' => $result]);
} else {
// Update.
$result = \db_process_sql_update('tlayout_data', $save, ['id' => $save['id']]);
// static = static::fromDB(['id' => $save['id']]);
$save = \array_merge($save, $newSave);
if (!empty($save)) {
if (empty($save['id'])) {
// Insert.
$result = \db_process_sql_insert('tlayout_data', $save);
} else {
// Update.
$result = \db_process_sql_update('tlayout_data', $save, ['id' => $save['id']]);
}
}
// Update the model.
if ($result) {
if (empty($save['id'])) {
$item = static::fromDB(['id' => $result]);
} else {
$item = static::fromDB(['id' => $save['id']]);
}
}
return $result;
return $item;
}

View File

@ -231,7 +231,7 @@ final class Line extends Model
*
* @overrides Model::save.
*/
public function save(array $data=[]): bool
public function save(array $data=[], array $newdata=[]): bool
{
return true;
}