Hello. There was a problem with saving data in xml.
Created all the necessary files.
usr/share/openmediavault/datamodels/conf.mydev.devinputs.json
Code: conf.mydev.devinputs.json
{
"type": "config",
"id": "conf.mydev.devinputs",
"title": "DEV inputs",
"queryinfo": {
"xpath": "//mydev/devinputs/devinput",
"iterable": true,
"idproperty": "iddev"
},
"properties": {
"iddev": {
"type": "integer"
},
"number": {
"type": "string"
},
"name": {
"type": "string"
},
"enable": {
"type": "boolean",
"default": false
}
}
}
Alles anzeigen
usr/share/openmediavault/engined/rpc/devinputs.inc
PHP: devinputs.inc
<?php
namespace Engined\Rpc;
class DevInputs extends \OMV\Rpc\ServiceAbstract {
public function getName() {
return "DevInputs";
}
public function initialize() {
$this->registerMethod("getDev");
$this->registerMethod("setDev");
}
function getDev($params, $context) {
$this->validateMethodContext($context, [
"role" => OMV_ROLE_ADMINISTRATOR
]);
//$this->validateMethodParams($params, "rpc.mydev.devinputs");
$db = \OMV\Config\Database::getInstance();
return $db->getAssoc("conf.mydev.devinputs");
}
function setDev($params, $context) {
$this->validateMethodContext($context, [
"role" => OMV_ROLE_ADMINISTRATOR
]);
$object = new \OMV\Config\ConfigObject(
"conf.mydev.devinputs");
$object->setAssoc($params);
$db = \OMV\Config\Database::getInstance();
$db->set($object);
\OMV\Rpc\Rpc::call("Config", "applyChanges", [
"modules" => [ "apt" ],
"force" => TRUE
], $context);
}
}
Alles anzeigen
var/www/openmediavault/js/omv/module/admin/mydev/mydev.js
JavaScript: mydev.js
OMV.WorkspaceManager.registerNode({
id: "mydev",
path: "/",
text: _("DEV"),
position: 11
});
var/www/openmediavault/js/omv/module/admin/mydev/dev_inputs/Dev_inputs.js
JavaScript: Dev_inputs.js
Ext.define("OMV.module.admin.mydev.Dev_inputs", {
extend: "OMV.workspace.grid.Panel",
requires: [
"OMV.data.Store",
"OMV.data.Model",
"OMV.data.proxy.Rpc"
],
hideAddButton: true,
hideEditButton: true,
hideDeleteButton: true,
hideApplyButton: false,
hideRefreshButton: false,
autoReload: false,
stateful: true,
stateId: "dev-inputs",
plugins:[{
ptype:'cellediting',
clicksToEdit: 1
}],
columns: [{
text: _("Number"),
sortable: false,
dataIndex: "number",
stateId: "number",
flex: 1
},{
xtype: "textcolumn",
text: _("Name"),
sortable: true,
dataIndex: "name",
stateId: "name",
flex: 1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},{
xtype: "enabledcolumn",
text: _("Status"),
dataIndex: "enable",
stateId: "status"
},{
xtype: "checkcolumn",
text: _("Enable"),
dataIndex: "enable",
stateId: "enable",
flex: 1
}],
onCheckButton: function() {
this.onApplyButton();
},
onApplyButton: function() {
var me = this;
var params = me.getValues();
OMV.Rpc.request({
scope: me,
relayErrors: false,
rpcData: {
service: "DevInputs",
method: "setDev",
params: params
}
});
},
initComponent: function() {
var me = this;
me.store = Ext.create("OMV.data.Store", {
autoLoad: true,
model: OMV.data.Model.createImplicit({
idProperty: "iddev",
fields: [
{ name: "iddev", type: "int" },
{ name: "number", type: "string" },
{ name: "name", type: "string" },
{ name: "enable", type: "boolean" }
]
}),
proxy: {
type: "rpc",
appendSortParams: false,
rpcData: {
service: "DevInputs",
method: "getDev"
}
},
sorters: [{
direction: "ASC",
property: "iddev"
}]
});
me.callParent(arguments);
}
});
OMV.WorkspaceManager.registerNode({
id: "dev_inputs",
path: "/mydev",
text: _("DEV inputs"),
iconCls: "mdi mdi-star"
});
OMV.WorkspaceManager.registerPanel({
id: "dev_inputs",
path: "/mydev/dev_inputs",
text: _("DEV inputs"),
position: 10,
className: "OMV.module.admin.mydev.Dev_inputs"
});
Alles anzeigen
config.xml
XML: config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<!-- Configuration version -->
<version>0.1</version>
<mydev>
<devinputs>
<devinput>
<iddev>1</iddev>
<number>1.1</number>
<name>DEV 1.1</name>
<enable>0</enable>
</devinput>
<devinput>
<iddev>2</iddev>
<number>1.2</number>
<name>DEV 1.2</name>
<enable>0</enable>
</devinput>
</devinputs>
</mydev>
<!-- System configuration - Do not add any configuration here -->
<system>
...............................
Alles anzeigen
Console command:
source /usr/share/openmediavault/scripts/helper-functions && omv_purge_internal_cache
service openmediavault-engined restart
I get a list, but when saving the change to xml, the entry of idved > 1 elements is duplicated
Only iddev 1 is overwritten.
Please tell me how to fix my error.
Thanks.