Hi Kris,
genau dynamisch mache ich es auch, und das geht auch problemlos, so lange man nichts mehr an bestehenden Einträgen was anpassen will. ( In meinem Fall gehts um geänderte MQTT Topics).
Und daher will ich, dass immer meine Werte aus der „static::$Variables“ in den Tree übernommen werden, dass Änderungen an bestehenden „static::$Variables“-Werten auch berücksichtigt werden.
Den einzigen, durch den User änderbaren Wert in der Liste in der Spalte „Keep“, lese ich deshalb beim befüllen der Values aus der gespeicherten Tree Eigenschaft nach (Referenz ist der IDENT).
Und trotz „loadValuesFromConfiguration“ FALSE wird bei allen „bestehenden“ Zeilen trotzdem der Eigenschaftswert genommen und nicht mein über Value übergebener Wert.
public function GetConfigurationForm()
{
// Read FORM.JSON from directory to adjust Tree Values
$jsonform = json_decode(file_get_contents(__DIR__."/form.json"), true);
// Read actual Tree Property with the stored Data to transfer the Keep Status
$StoredRows = json_decode($this->ReadPropertyString('Variables'), true);
$Variables_Form = [];
// Process the Static ARRAY with the Variable Definitions
foreach (static::$Variables as $Pos => $Variable) {
// Get Keep Status of stored Dataset from selected Datasets by User
$keep = $Variable[10];
if ($this->ReadPropertyString('Variables') != '' ){
foreach ($StoredRows as $Index => $Row) {
if ($Variable[3] == str_replace(' ', '', $Row['Ident'])) {
$keep = $Row['Keep'];
}
}
}
$Variables_Form[] = [
'id' => $Variable[1],
'parent' => $Variable[2],
'Namespace' => $this->Translate($Variable[0]),
'Ident' => str_replace(' ', '', $Variable[3]),
'Name' => $this->Translate($Variable[3]),
'Tag' => $Variable[4],
'MQTT' => $Variable[5],
'VarType' => $Variable[6],
'Profile' => $Variable[7],
'Factor' => $Variable[8],
'Action' => $Variable[9],
'Keep' => $keep,
'rowColor' => $this->set_color($Variable[2]),
'editable' => $this->set_editable($Variable[2])
];
}
// Update Tree Values in the respective Form Array
$jsonform["elements"][0]["values"] = $Variables_Form;
$this->SendDebug('RSCP Form_post', json_encode($jsonform),0);
return json_encode($jsonform);
}
Und hier der Ausschnitt aus der Form:
{
"elements": [
{
"type": "Tree",
"name": "Variables",
"caption": "",
"loadValuesFromConfiguration": false,
"add": false,
"delete": false,
"columns": [
{
"caption": "Index",
"name": "id",
"width": "65px",
"save": true
},
{
"caption": "Parent",
"name": "parent",
"visible": false,
"width": "0px",
"save": true
},
{
"caption": "Namespace",
"name": "Namespace",
"width": "50px",
"visible": false,
"save": true
},
VG
Philipp