How to store Multiple Pieces of Data in jsTree nodes using a Single Attribute? - jstree

In order to store arbitrary data in jsTree nodes, I'm passing a custom attribute (say node-data) to the create_node method. But I need to store more than one piece of data in the single attribute. (For example name,age etc.) What format would be best suited for the value of the node-data attribute? What I'm looking for is a format that will allow easy retrieval of data.
For example we can have a format like "name:John,age:26". But I will have to split the string by using the comma as the delimiter and split at the colon to separate the name and value. Is there a better way to do this?

Any reason you're not using data- attributes? Supported by jquery and every current browser (HTML5). So instead of obj.attr("myattrib", true); You can assign arbitrary data to any object. You could easily do things like:
node.data("name", "John");
node.data("age", 26);
and later you retrieve them when needed:
var name = node.data("name");
on the server end, presuming you're sending your data back as Json data, you simply define (in the simplest form, you can get fancier) a Dictionary metadata in the json object in the server, then you retrieve "name" from the dictionary, cast the object to the appropriate type and away you go!

You can pass html attributes to node, using li_attr and a_attr in json data array.
$list[] = array(
'id' => "year_" . $year->Year,
'text' => $year->Year,
'children' => TRUE,
'folder' => 'folder',
'li_attr' => array('year' => $year->Year),
'a_attr' => array('month' => $year->month)
);

Related

Ag-grid setFilter in server side filtering

I just want to check if it's possible to give setFilter values in callback, in form of complex objects instead of array of strings. Reason why we need setFilter to have complex objects is because we are using server side filtering and we would like to show labels in filter, but send back keys to server to perform filtering.
If we have for example objects like {name: 'some name', id: 1} we would like to show 'some name' in filter UI but when that filter is selected we need associated id (in this case 1).
By looking into source code of setFilter and corresponding model, it seems like this is not possible.
Is there a way maybe I am missing that this could work?
ag-Grid version 23.2.0
I have exactly the same problem, from the interface it seems impossible indeed because of expected string[] values
interface SetFilterValuesFuncParams {
// The function to call with the values to load into the filter once they are ready
success: (values: string[]) => void;
// The column definition object from which the set filter is invoked
colDef: ColDef;
}

RDF4J not filtering TreeModel in expected way

I have a TTL with something like
ex:isDataProperty rdf:type owl:DatatypeProperty .
ex:Article a owl:Class ;
owl:hasKey ( ex:isDataProperty ) .
And when I load the model with RDF4J (as a TreeModel) then try to filter to extract the properties annotated with haskey fails (just returns empty list result)
Some samples that return data:
val dataProperties = model.filter(null, RDF.TYPE, OWL.DATATYPEPROPERTY).subjects().asScala
val classes = model.filter(null, RDF.TYPE, OWL.CLASS).subjects().asScala
The sample I want, that doesn't return data:
val propertiesWithKeys = model.filter(null, RDF.PROPERTY, OWL.HASKEY).subjects().asScala
I have tried a few variations of the previous one using RDF.TYPE or RDF.Value. (instead of RDF.PROPERTY)
The thing you're after is any subject that has a owl:hasKey property, regardless of value. So both the subject and the object are wildcards, you just want to filter by property name. The way to do that is like this:
model.filter(null, OWL.HASKEY, null)
Now, furthermore you say that you want to know the properties that have been used as annotation using this owl:hasKey property. In your example, that would be ex:isDataProperty. Note that in your model, this is not the subject of the owl:hasKey relation - it's in the object values:
model.filter(null, OWL.HASKEY, null).objects()
To further complicate matters, the object values in your example are not simply single values. Instead, each class is annotated using a list of properties, so the object value is a list object (a.k.a. an RDF Collection). To process this list, there are some utility methods provided by the Models and RDFCollections classes.
For each of the objects you can do this to get the actual list of values:
RDFCollections.asValues(model, objectNode, new ArrayList<Value>())
(where objectNode is one of the values that .objects() returned)
Edit since objects() returns objects of type Value and RDFCollections expects a Resource, you'll either have to do a cast, or if you want to do all of this in a fluent way, you can use Models.objectResources instead. The whole thing then becomes:
Models.objectResources(model.filter(null, OWL.HASKEY, null))
.asScala.map(o => RDFCollections.asValues(model, o, new ArrayList[Value]()));
(I may have the Scala-specific bits of this wrong, but you get the gist hopefully)
For more information on how to work with the rdf4j Model API and with RDF Collections, see the rdf4j documentation.

Fluid Query Result object to JSON

I have a result object in my view and want do put this in JSON format.
The Object looks like
TYPO3\CMS\Extbase\Persistence\Generic\QueryResultprototypeobject (32 items)
0 => KN\Operations\Domain\Model\Operationprototypepersistent entity (uid=853,
pid=90)
1 => KN\Operations\Domain\Model\Operationprototypepersistent entity (uid=852,
pid=90)
....
I tried to use format
{myObject-> f:format.json()}
but this doesn't work. Result is
{}
I want to give that informations to my JS. For me it is not possible to change the Controller because I don't want to change an existing extension.
the format.json viewhelper expects an array as the value. To get the right result you need to convert your result into an array.
If you set the first param of the execute function in your repository to true you will get an array instead of an Queryresult Object.
return $query->execute(true);
You can find additional information on the documentation page of the viewhelper: https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/Format/Json.html
Happy Coding!

Mirth channel XML : how to read value from inside of an element

How to read a list of values from Mirth Channel XML's <mapping> element? I can use msg to read one value. But what if there are list of values? Example:
<patient>
<name>names</name>
<patient>
If there is one value fornames defined, then simply performing <mapping>msg['patient']['name']</mapping> will return the value. But how to get only values if the names return more than one name? How to iterate and display in the same XML? I am doing Mirth for the first time and any help is appreciated.
I understand your question in this way.. so you mean if you receive the XML in this fashion
<patient>
<name>names</name>
<name>name1</name>
</patient>
then how to iterate and fetch only 'name' tags value. If my understanding is correct then place the below code in your source transformer.
var nameLen = msg['name'].length();
for(i=0;i<nameLen;i++){
// Your Mapping Logic
logger.debug(msg['name'][i].toString());
}

Given a Symfony 2.7 formType object with an added choice field, how can I access the choice strings?

I have created a form object in symfony, which is meant to process an api request. It is created in a controller via:
$myForm = new MyFormType($foo, $bar);
$form = $this->createForm($myForm, $entity, array('method' => 'POST', 'csrf_protection' => false));
Once these objects are created, I pass them into an external service which converts api data into data that's meant to be consumed by the form, like the following:
//I pass this in, so that, our api users don't have to pass in
//{uglyAPIVariable45: 721}, but rather {pretty_variable: "go left"}
$goodData = $this->convertOldData($form->getBuilderDataCopy(), $oldData);
One of the things this service does, is if the form has a choice, like a select tag, it attempts to convert any string passed to the api into the value in select tag. This way, if the user can pass over "East" if the select field has the options "North", "West", "South" and "East" associated with the values 0, 4, 5 and 10 and the converter should return 10. The user doesn't have to pass over one of those random values, they can just pass over the string. And if they passed over "Foo", it would return an error along with a description of what good choices they could pass over.
My problem is that, in production, I'm not able to get ahold of those values.
In development, I found that I could get my options using,
foreach($formBuilderDataCopy as $formElement){
$options = $formElement->getAttributes()['data_collector/passed_options']['choices'];
}
But when we moved to production, this code broke. The method, getAttributes, returned null suddenly. Admittedly, it seemed kind of janky to begin with, so I wanted to find a more valid approach to getting these choices, possibly even allowing me to bypass a different approach for 'choice', 'entity', 'timezone' et. al.
Unfortunately, looking through the source code and exploring it with get_class_methods and friends hasn't provided me with a solution this issue. Even when I get choices, the most I can get are values, but not the string options in the select box.
What's the appropriate approach to acquiring such information from my symphony forms?
As a side note, I have also tried:
$form->get('elementName')->getConfig()->getOption('choices');
But it also just returns a list of the ids to single numbers and not the strings that replace those numbers. e.g.
{3: 0, 5: 1, 10: 2, 11: 3...}
Create an entity Object for the form type. Then you can use the data as object. It must not been a doctrine entity.