ExtJS4 How to set TreePanels root node from JSON - json

I want to create TreePanel using ExtJS4. So I'm sending JSON to proxy reader which has following format
{
"text": "en",
"children": {
"text": "/",
"children": [{
"text": "/page",
"children": [{
"text": "/page/new",
"children": [],
"leaf": true,
"expanded": false
},
{
"text": "/page/remove",
"children": [],
"leaf": true,
"expanded": false
}
],
"leaf": false,
"expanded": false
},
{
"text": "/home",
"children": [],
"leaf": true,
"expanded": false
}
],
"leaf": false,
"expanded": true
}
}
How do I have to configure my Store if I want en node to be my root node.
Ext.define('Example.store.WebItems', {
extend: 'Ext.data.TreeStore',
model: 'Example.model.Item',
proxy: {
type: 'ajax',
api: {
read: 'some/url',
},
reader: {
type: 'json',
root: 'children' // Is this correct?
}
},
root: // What should I write here?
});
When I define TreeStore's root as root: 'My Root' it will add new root, but I want to use root defined in JSON.
So my questions are:
How to use root node from JSON instead of defining it manualy?
Do I have to define root node in proxy reader and TreeStore as well?

Response has to have root.
For example:
{
MyRoot: {
"text": "en",
"children": {
"text": "/",
"children": [{
"text": "/page",
"children": [{
"text": "/page/new",
"children": [],
"leaf": true,
"expanded": false
}, {
"text": "/page/remove",
"children": [],
"leaf": true,
"expanded": false
}],
"leaf": false,
"expanded": false
}, {
"text": "/home",
"children": [],
"leaf": true,
"expanded": false
}],
"leaf": false,
"expanded": true
}
}
}
In this example root is MyRoot. Now you have to "tell" reader that your root is MyRoot:
// ...
reader: {
type: 'json',
root: 'MyRoot'
}
},
//root: this config is not needed now
});

As per I know, you need to specify root as following:
root: {
text: 'en',
id: 'src',
expanded: true '
}
Try the above code snippet it will help you.

May be late but for others , wrap the JSON inside array [] just like this :
[{
"text": "en",
"children": {
"text": "/",
"children": [{
"text": "/page",
"children": [{
"text": "/page/new",
"children": [],
"leaf": true,
"expanded": false
}, {
"text": "/page/remove",
"children": [],
"leaf": true,
"expanded": false
}],
"leaf": false,
"expanded": false
}, {
"text": "/home",
"children": [],
"leaf": true,
"expanded": false
}],
"leaf": false,
"expanded": true
}
}]
Remove the reader block
reader: {
type: 'json',
root: 'MyRoot'
}
Add root block :
root: {
text: 'en',
id: 'src',
expanded: true '
}
Add rootVisible: false in treepanel.

Related

Failed to get certain files from IPFS cluster

Because public IPFS gateway is too slow, I set up own ipfs cluster using kubernetes on AWS.
However, when I tried to get files from the cluster, I succeeded for some files but failed for others consistently(failed one kept failing).
How do I debug this? Did I make mistake on configuration? Here's the configuration I used.
{
"API": {
"HTTPHeaders": {
"Access-Control-Allow-Methods": [
"PUT",
"POST"
],
"Access-Control-Allow-Origin": [
"http://localhost:3000",
"http://127.0.0.1:5001",
"https://webui.ipfs.io"
]
}
},
"Addresses": {
"API": "/ip4/0.0.0.0/tcp/5001",
"Announce": [],
"AppendAnnounce": [],
"Gateway": "/ip4/0.0.0.0/tcp/8080",
"NoAnnounce": [],
"Swarm": [
"/ip4/0.0.0.0/tcp/4001",
"/ip6/::/tcp/4001",
"/ip4/0.0.0.0/udp/4001/quic",
"/ip6/::/udp/4001/quic"
]
},
"AutoNAT": {},
"Bootstrap": [
"/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/ip4/104.131.131.82/udp/4001/quic/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"
],
"DNS": {
"Resolvers": {}
},
"Datastore": {
"BloomFilterSize": 0,
"GCPeriod": "1h",
"HashOnRead": false,
"Spec": {
"mounts": [
{
"child": {
"path": "blocks",
"shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
"sync": true,
"type": "flatfs"
},
"mountpoint": "/blocks",
"prefix": "flatfs.datastore",
"type": "measure"
},
{
"child": {
"compression": "none",
"path": "datastore",
"type": "levelds"
},
"mountpoint": "/",
"prefix": "leveldb.datastore",
"type": "measure"
}
],
"type": "mount"
},
"StorageGCWatermark": 90,
"StorageMax": "10GB"
},
"Discovery": {
"MDNS": {
"Enabled": true,
"Interval": 10
}
},
"Experimental": {
"AcceleratedDHTClient": false,
"FilestoreEnabled": false,
"GraphsyncEnabled": false,
"Libp2pStreamMounting": false,
"P2pHttpProxy": false,
"StrategicProviding": false,
"UrlstoreEnabled": false
},
"Gateway": {
"APICommands": [],
"HTTPHeaders": {
"Access-Control-Allow-Headers": [
"X-Requested-With",
"Range",
"User-Agent"
],
"Access-Control-Allow-Methods": [
"GET"
],
"Access-Control-Allow-Origin": [
"*"
]
},
"NoDNSLink": false,
"NoFetch": false,
"PathPrefixes": [],
"PublicGateways": null,
"RootRedirect": "",
"Writable": false
},
"Identity": {
"PeerID": "<intentionally hide>"
},
"Internal": {},
"Ipns": {
"RecordLifetime": "",
"RepublishPeriod": "",
"ResolveCacheSize": 128
},
"Migration": {
"DownloadSources": [],
"Keep": ""
},
"Mounts": {
"FuseAllowOther": false,
"IPFS": "/ipfs",
"IPNS": "/ipns"
},
"Peering": {
"Peers": null
},
"Pinning": {
"RemoteServices": {}
},
"Plugins": {
"Plugins": null
},
"Provider": {
"Strategy": ""
},
"Pubsub": {
"DisableSigning": false,
"Router": ""
},
"Reprovider": {
"Interval": "12h",
"Strategy": "all"
},
"Routing": {
"Type": "dht"
},
"Swarm": {
"AddrFilters": null,
"ConnMgr": {
"GracePeriod": "20s",
"HighWater": 900,
"LowWater": 600,
"Type": "basic"
},
"DisableBandwidthMetrics": false,
"DisableNatPortMap": false,
"RelayClient": {
"Enabled": true
},
"RelayService": {
"Enabled": true
},
"Transports": {
"Multiplexers": {},
"Network": {},
"Security": {}
}
}
}

Ethereum / Solidity getting smartcontract events in the geth console

So I tried to retrieve the events generated by my smartcontract
var abi = [{
"constant": false,
"inputs": [{
"name": "_value",
"type": "int32"
}],
"name": "changeLowerTrigger",
"outputs": [],
"payable": false,
"type": "function"
}, {
"constant": true,
"inputs": [],
"name": "metric",
"outputs": [{
"name": "name",
"type": "string",
"value": "place_holder_metric_name_to_be_autogenerated"
}, {
"name": "value",
"type": "int32",
"value": "7"
}],
"payable": false,
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_value",
"type": "int32"
}],
"name": "changeUpperTrigger",
"outputs": [],
"payable": false,
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_value",
"type": "int32"
}],
"name": "update",
"outputs": [],
"payable": false,
"type": "function"
}, {
"anonymous": false,
"inputs": [{
"indexed": false,
"name": "_value",
"type": "int32"
}],
"name": "ValueChanged",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": false,
"name": "_alarm",
"type": "string"
}, {
"indexed": false,
"name": "_value",
"type": "int32"
}],
"name": "Alarm",
"type": "event"
}]
var MyContract = web3.eth.contract(abi);
var myContractInstance = MyContract.at(
'0x3B03c46Dfc878FeF9fAe8de4E32a6718f2E250e9');
var events = myContractInstance.allEvents();
// watch for changes
events.watch(function(error, event) {
if (!error)
console.log(event);
});
// Or pass a callback to start watching immediately
var events = myContractInstance.allEvents(function(error, log) {
console.log(err, log);
});
But it returns only:
> events
{
callbacks: [function(error, log)],
filterId: "0xd6af6f5a7273fe21452f00c4682456",
getLogsCallbacks: [],
implementation: {
getLogs: function(),
newFilter: function(),
poll: function(),
uninstallFilter: function()
},
options: {
address: "0x3B03c46Dfc878FeF9fAe8de4E32a6718f2E250e9",
from: undefined,
fromBlock: undefined,
to: undefined,
toBlock: undefined,
topics: []
},
pollFilters: [],
requestManager: {
polls: {
0xd6af6f5a7273fe21452f00c4682456: {
data: {...},
id: "0xd6af6f5a7273fe21452f00c4682456",
callback: function(error, messages),
uninstall: function()
}
},
provider: {
newAccount: function(),
send: function github.com/ethereum/go-ethereum/console.(*bridge).Send-fm(),
sendAsync: function github.com/ethereum/go-ethereum/console.(*bridge).Send-fm(),
sign: function(),
unlockAccount: function()
},
timeout: {},
poll: function(),
reset: function(keepIsSyncing),
send: function(data),
sendAsync: function(data, callback),
sendBatch: function(data, callback),
setProvider: function(p),
startPolling: function(data, pollId, callback, uninstall),
stopPolling: function(pollId)
},
formatter: function(),
get: function(callback),
stopWatching: function(callback),
watch: function(callback)
}
But what I want, is the events shown in the next image at the very bottom(e.g.Value Changed value:7):
Since the events are displayed in the ETH-Wallet there should be a way. I rly just want a way to get the latest events in the geth console (or sth similare).
Thanks for any help I'm kinda lost and having some of the worst googling of my life.
All you need to do is to call get() on the result object you've got and posted in your answer. Its described in official documentation and can be found here

Json data is not populated in treeview panel

here below is my json formate i need to show in the treeview panel in extjs6
After loading store from server i am not able to see any records in Tree panel.
what should be the Model view and store for this json rendering in to the Tree view panel .
Thanks.
here is my code :
Model :
Ext.define('File', {
extend: 'Ext.data.TreeModel',
fields: [
{number: 'number', type: 'string'},
]
});
Store :
var store = Ext.create('Ext.data.TreeStore', {
model: 'File',
proxy: {
type: 'ajax',
url: 'component-tree.json',
reader: {
type: 'json',
rootProperty: 'components',
leaf: true,
children: 'components',
expanded: true,
},
},
folderSort: true,
});
View :
var tree = Ext.create('Ext.tree.Panel', {
autoLoad: true,
collapsible: true,
useArrows: true,
rootVisible: true,
store: store,
multiSelect: true,
width: 250,
height: 300,
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop',
appendOnly: true
}
},
root: {
text: "Components",
expanded: true,
},
renderTo: document.body
});
component-tree.json :
{
"components": {
"state": "RELEASED",
"nodeType": "Component",
"checked": true,
"name": "PLATE - FOR CABINET - ASSEMBLY",
"level": 0,
"url": "http://example.com/Windchill/servlet/nexiles/tools/api/1.0/epmdocuments/OR:wt.epm.EPMDocument:4474031",
"oid": "OR:wt.epm.EPMDocument:4474031",
"modified": "17.04.2015",
"filename": "21378386.asm",
"num_children": 7,
"number": "21378386.ASM",
"details": "http://example.com/Windchill/app/#ptc1/tcomp/infoPage?oid=OR:wt.epm.EPMDocument:4474031&u8=1",
"components": [
{
"nodeType": "Component",
"leaf": true,
"name": "PLATE - FOR CABINET - DETAIL",
"level": 1,
"url": "http://example.com/Windchill/servlet/nexiles/tools/api/1.0/epmdocuments/OR:wt.epm.EPMDocument:4474018",
"oid": "OR:wt.epm.EPMDocument:4474018",
"modified": "17.04.2011",
"filename": "1234.prt",
"state": "RELEASED",
"number": "21378385.PRT",
"details": "http://example.com/Windchill/app/#ptc1/tcomp/infoPage?oid=OR:wt.epm.EPMDocument:4474018&u8=1",
"version": "A",
"checked": true,
"drawings": [
{
"reftype": "DRAWING",
"nodeType": "Drawing",
"leaf": true,
"name": "PLATE - FOR CABINET - DETAIL",
"url": "http://example.com/Windchill/servlet/nexiles/tools/api/1.0/epmdocuments/OR:wt.epm.EPMDocument:4474013",
"oid": "OR:wt.epm.EPMDocument:4474013",
"modified": "17.04.2015",
"filename": "21378385.drw",
"source": "representation",
"state": "RELEASED",
"number": "21378385.DRW",
"details": "http://example.com/Windchill/app/#ptc1/tcomp/infoPage?oid=OR:wt.epm.EPMDocument:4474013&u8=1",
"version": "A",
"checked": true,
"id": "OR:wt.epm.EPMDocument:4474013-DRAWING",
"icon": "/resources/images/drawing.gif"
},
{
"reftype": "INTERNAL",
"nodeType": "Drawing",
"leaf": true,
"name": "PLATE - FOR CABINET - ASSEMBLY",
"url": "http://example.com/Windchill/servlet/nexiles/tools/api/1.0/epmdocuments/OR:wt.epm.EPMDocument:4474041",
"oid": "OR:wt.epm.EPMDocument:4474041",
"modified": "17.04.2015",
"filename": "21378386.drw",
"source": "representation",
"state": "RELEASED",
"number": "21378386.DRW",
"details": "http://example.com/Windchill/app/#ptc1/tcomp/infoPage?oid=OR:wt.epm.EPMDocument:4474041&u8=1",
"version": "A",
"checked": true,
"id": "OR:wt.epm.EPMDocument:4474041-INTERNAL",
"icon": "/resources/images/drawing.gif"
}
],
"icon": "/resources/images/prt_image.gif"
}
}
Your treeModel just defines number but your store actually contains much more fields...
Take a look at the doc in the chapter 'Heterogeneous node types' for more information.
Try with children instead of components in your json file. By the way I could remark that the case is not respected between the configuration root: { text: "Components", ... } and the json content "components": [ ... ].
C and c

MongoDb query to access array json

EDIT:
INPUT : nodes DB is
db.nodes.insert([
{ "ACTIVE" : 1,
"GEOLOCATION": {
"GEO_CODE": [],
"ACTIVE_GEOLOCATION": false
},
"META": {
"CATEGORY": "levis",
"DESCRIPTION": "dsad",
"PRIVACY": "PUBLIC",
"TEMPLATE_NAME": "B",
"TEMPLATE_GROUP": "Product",
"KEYWORDS": [
"sda"
],
"CREATEDBY": "",
"SUBCATEGORY": "Blue",
"PRODUCT_TEMPLATE_TYPE": "Consumable",
"UOM": "",
"TEMPLATE_SUBGROUP": ""
},
"VARIENTS": [
{
"COMMENT": "Demo",
"INDEX": 0,
"NAME": "Brand",
"IS_PARENT": false,
"DATATYPE": "Text",
"ACCESS": "PUBLIC",
"PARENT_VARIENT": "Parem",
"TYPE": "PERMANENT"
},
{
"COMMENT": "Demo",
"INDEX": 0,
"NAME": "Account",
"IS_PARENT": false,
"DATATYPE": "Text",
"ACCESS": "PUBLIC",
"PARENT_VARIENT": "Parem",
"TYPE": "PERMANENT"
},
{
"COMMENT": "Demo",
"INDEX": 0,
"NAME": "Price",
"IS_PARENT": false,
"DATATYPE": "Text",
"ACCESS": "PUBLIC",
"PARENT_VARIENT": "Parem",
"TYPE": "PERMANENT"
},
]
}
])
Input:
if (Meteor.isServer) {
var nodeDB = new Meteor.Collection('nodes');
Meteor.startup(function () {
// code to run on server at startup
});
var p1=nodeDB.find({"ACTIVE" : 1, "VARIENTS.ACCESS" : "PUBLIC"}, { "VARIENTS.NAME": 1, _id : 0 });
var p2=p1.fetch();
var arr1=[];
var arr2=[];
for (i=0;i <p2.length;i++)
{
//console.log(p2[i].VARIENTS);
arr1[i]=p2[i].VARIENTS;
}
var dict=(arr1[1]);
// console.log(x.length);
console.log(arr1.NAME);
Meteor.startup(function () {
// code to run on server at startup
});
}
Result:
[ [ { COMMENT: 'Demo',
I20150521-15:50:47.855(5.5)? INDEX: 0,
I20150521-15:50:47.856(5.5)? NAME: 'Brand',
I20150521-15:50:47.856(5.5)? IS_PARENT: false,
I20150521-15:50:47.856(5.5)? DATATYPE: 'Text',
I20150521-15:50:47.856(5.5)? ACCESS: 'PUBLIC',
I20150521-15:50:47.856(5.5)? PARENT_VARIENT: 'Parem',
I20150521-15:50:47.856(5.5)? TYPE: 'PERMANENT' },
I20150521-15:50:47.856(5.5)? { COMMENT: 'Demo',
I20150521-15:50:47.857(5.5)? INDEX: 0,
I20150521-15:50:47.857(5.5)? NAME: 'Account',
I20150521-15:50:47.857(5.5)? IS_PARENT: false,
I20150521-15:50:47.857(5.5)? DATATYPE: 'Text',
I20150521-15:50:47.857(5.5)? ACCESS: 'PUBLIC',
I20150521-15:50:47.857(5.5)? PARENT_VARIENT: 'Parem',
I20150521-15:50:47.857(5.5)? TYPE: 'PERMANENT' },
I20150521-15:50:47.857(5.5)? { COMMENT: 'Demo',
I20150521-15:50:47.858(5.5)? INDEX: 0,
I20150521-15:50:47.858(5.5)? NAME: 'Price',
I20150521-15:50:47.858(5.5)? IS_PARENT: false,
I20150521-15:50:47.858(5.5)? DATATYPE: 'Text',
I20150521-15:50:47.858(5.5)? ACCESS: 'PUBLIC',
I20150521-15:50:47.858(5.5)? PARENT_VARIENT: 'Parem',
I20150521-15:50:47.859(5.5)? TYPE: 'PERMANENT' } ] ]
Problem: Result required is only NAME parameters in an array.How the query should be modified?
Mongo Query:-
db.nodes.aggregate([
{"$group": {"_id": "$VARIENTS.NAME"}},
{"$project": {"_id": 0, "TEMPLATE_NAME": "$_id"}}
]);
Mongo Result :-
{
"result" : [
{
"TEMPLATE_NAME" : [
"Brand",
"Account",
"Price"
]
}
],
"ok" : 1
}

ExtJs Store Root

this is my JSON:
[{
"ActionBy": "om",
"ActionDate": "11\/26\/2013 8:50:56 AM",
"ActionDetails": [{
"Field": "St",
"NewValue": "Clo",
"OldValue": "Ch",
"UpdateType": "Tie"
}, {
"Field": "AssignedTo",
"NewValue": "mus",
"OldValue": "n",
"UpdateType": "As"
}]
And this my store:
historyStore = Ext.create('Ext.data.Store', {
fields: ['Field', 'NewValue', 'OldValue'],
autoLoad: true,
proxy: {
type: 'ajax',
url: url,
reader: {
type:'json',
root:''
}
},
listeners:{
load:function(that,records,view){
console.log(records);
}
},
autoLoad: true
});
I want show Field, NewValue and OldValue in grid panel,
But it does not work Store, in my opinion, I am root problem.
Is it true JSON?
What I need to write to Root?
Your json should be like :
{
"ActionBy": "nimet.seyman#beqom.com",
"ActionDate": "11\/26\/2013 8:50:56 AM",
"ActionDetails": [
{
"Field": "State",
"NewValue": "Closed",
"OldValue": "Check",
"UpdateType": "Ticket Update"
},
{
"Field": "AssignedTo",
"NewValue": "mustafa.arikci#beqom.com",
"OldValue": "nimet.seyman#beqom.com",
"UpdateType": "Assignment"
}
]
}
If it is in this way :
data =[{
"ActionBy": "nimet.seyman#beqom.com",
"ActionDate": "11\/26\/2013 8:50:56 AM",
"ActionDetails": [
{
"Field": "State",
"NewValue": "Closed",
"OldValue": "Check",
"UpdateType": "Ticket Update"
},
{
"Field": "AssignedTo",
"NewValue": "mustafa.arikci#beqom.com",
"OldValue": "nimet.seyman#beqom.com",
"UpdateType": "Assignment"
}
]
}]
Your store :
historyStore = Ext.create('Ext.data.Store', {
fields: ['Field', 'NewValue', 'OldValue'],
autoLoad: true,
proxy: {
type: 'ajax',
url: url,
reader: {
type:'json',
root:'ActionDetails'
}
}
});
Your json is not valid,you can use jsonlint.com to validate your json. add '} ]' to your json to complete it.
give root value as ActionDetails so it will take data from that node, like
root:'ActionDetails'