style cell based on cell value in dojo gridx - dojo.gridx

I am using the dojo gridx component, and I want to format each cell based on the cell's value, I can do the styling for each cell by writing the formatter function for each column when defining the layout structure, but is it possible to write a generic formatter function that can be used for all columns
gridStructure: [
{
"field": "americaGeoValue",
"name": "Americas",
formatter: infoFormatter
},
{
"field": "emeaGeoValue",
"name": "EMEA",
formatter: infoFormatter
},
{
"field": "apGeoValue",
"name": "AP",
formatter: infoFormatter
}
]
this is how I am setting the data for the grid
storedata<portlet:namespace/>.push(
{
"siteLabel": site.siteLabel,
"siteCode": site.siteCode,
"americaGeoValue": site.americaGeoValue,
"emeaGeoValue": site.emeaGeoValue,
"apGeoValue": site.apGeoValue
}
);
formatter function:
function infoFormatter(data) {
console.log('formatter item'+JSON.stringify(data));
}
this the log
{"siteLabel":"test","siteCode":"test","americaGeoValue":"1","emeaGeoValue":"2","apGeoValue":"8"}
So, how do i write a generic formatter to check the value (americaGeoValue/emeaGeoValue/apGeoValue) and do something based on the value.

If you are looking to style the cell based on value, instead of 'formatter', try 'class' or 'style' which are functions accepting cell as parameter like,
{
"field": "emeaGeoValue",
"name": "EMEA",
"class": function(cell){
if(cell.rawData()=='ABC'){
return 'customClsForCell';
}
}
}

Related

how to obtain data argument to provide to mustache template in moodle

In moodle (4.0) I have the need to call
$this->output->render_from_template('core_courseformat/local/content/section/cmlist', $sectionData);
From within a renderer. The goal is to render the normal, native, cmlist component in a particular place on the page. But the way that I am currently getting the value of $section does not seem to work. My template renders nothing. I can see from the github source that this template expects data in this format:
Example context (json):
{
"cms": [
{
"cmitem": {
"cmformat": {
"cmname": "<a class=\"aalink\" href=\"#\"><span class=\"instancename\">Forum example</span></a>",
"hasname": "true"
},
"id": 3,
"module": "forum",
"extraclasses": "newmessages"
}
},
{
"cmitem": {
"cmformat": {
"cmname": "<a class=\"aalink\" href=\"#\"><span class=\"instancename\">Assign example</span></a>",
"hasname": "true"
},
"id": 4,
"module": "assign",
"extraclasses": ""
}
}
],
"hascms": true,
"showmovehere": true,
"movingstr": "Moving this activity: folder example",
"cancelcopyurl": "#",
"movetosectionurl": "#",
"strmovefull": "Move 'folder example' to this location"
}
}}
https://github.com/moodle/moodle/blob/1d99ba19a21d57e9f1ed4211a8eeee00e50b7baf/course/format/templates/local/content/section/cmlist.mustache
But here's the challenge. How do I get an object in that format with the data needed to feed the template so it can render the correct CM list items?
Currently I am tring:
$sectionData = get_fast_modinfo($course->id)->get_section_info($section);
But it doesn't seem to return the data structured in the right way.
Any help appreciated.
You can use the function export_for_template of cmlist render class.
Something like this:
$cmlist = new \core_courseformat\output\local\content\section($format, $section);
$data->cmlist = $cmlist->export_for_template($OUTPUT);
and then send the data to the template.
I recommend you imitate the behavior of a moodle as he performs here:
https://github.com/moodle/moodle/blob/7ce003b666a66b465ce9335f430a6e4d3535a7f1/course/format/classes/output/local/content/section.php#L223

Get keys from Json with regex Jmeter

I'm hustling with regex, and trying to get the id's from this body.
But only the id´s in the members list, and not the id in the verified key. :)
To clarify, I'm using Regular Expression Extractor in JMeter
{
"id": "9c40ffca-0f1a-4f93-b068-1f6332707d02", //<--not this
"me": {
"id": "38a2b866-c8a9-424f-a5d4-93b379f080ce", //<--not this
"isMe": true,
"user": {
"verified": {
"id": "257e30f4-d001-47b3-9e7f-5772e591970b" //<--not this
}
}
},
"members": [
{
"id": "88a2b866-c8a9-424f-a5d4-93b379f780ce", //<--this
"isMe": true,
"user": {
"verified": {
"id": "223e30f4-d001-47b3-9e7f-5772e781970b" //<--not this
}
}
},
{
"id": "53cdc218-4784-4e55-a784-72e6a3ffa9bc", //<--this
"isMe": false,
"user": {
"unverified": {
"verification": "XYZ"
}
}
}
]
}
at the moment I have this regex :
("id": )("[\w-]+")
But as you can see here it returns every guid
Any ideas on how to go on?
Thanks in advance.
Since the input data type is JSON, it is recommended to use the JMeter's JSON Path Extractor Plugin.
Once you add it, use the
$.members[*].id
JSON path expression to match all id values of each members in the document that are the top nodes.
If you may have nested memebers, you may get them all using
$..members[*].id
You may test these expressions at https://jsonpath.com/, see a test:

DynamoDB UpdateItem calculation with numbers?

I would like my UpdateItem function to add the new value to the previous one but I can't figure out how to use numbers for the calculation and access the current value to be added to the new one.
Here is my working function, what I want to do is included in comment. How can I do it?
{
"TableName": "Votes",
"Key": {
"votesId": {
"S": "$input.path('$.votesId')"
}
},
"UpdateExpression": "set buy = :val1",
"ExpressionAttributeValues" : {
":val1": {
"N": "$input.path('$.buy')"
//Would like: "N": "buy + $input.path('$.buy')"
}
},
"ReturnValues": "ALL_NEW"
}
Here is how I test it:
{
"votesId":1,
"down":0,
"up":0,
"hold":0,
"buy":0,
"sell":0
}
You can use UpdateExpression to indicate which attributes are to be updated and what actions to perform.
Specifically in your case, UpdateExpression supports the following:
SET myNum = myNum + :val

Accessing list of dictionaries in template by index

I have a list of dictionaries in the django template. I wish to use its values in a form.
[
{
"movie_id": 1950,
"title": "In the Heat of the Night (1967)"
},
{
"movie_id": 3741,
"title": "Badlands (1973)"
},
{
"movie_id": 3959,
"title": "Time Machine, The (1960)"
},
{
"movie_id": 4101,
"title": "Dogs in Space (1987)"
},
{
"movie_id": 8572,
"title": "Littlest Rebel, The (1935)"
},
{
"movie_id": 65230,
"title": "Marley & Me (2008)"
},
{
"movie_id": 105954,
"title": "All Is Lost (2013)"
}
]
In my template, I want to get values of each field by index. ie. for the
list[0]['movieId'], I would like to get the value 1950. Is that possible?
You can access it via dot (.) notation.
From the documentation
Technically, when the template system encounters a dot, it tries the following lookups, in this order:
Dictionary lookup
Attribute or method lookup
Numeric index lookup
So you can use list.0.movieId. The 0 dot attribute will access the list element and movieId will do the dictionary lookup.

"type mismatch error, expected type LIST" for querying a one-to-many relationship in AppSync

The schema:
type User {
id: ID!
createdCurricula: [Curriculum]
}
type Curriculum {
id: ID!
title: String!
creator: User!
}
The resolver to query all curricula of a given user:
{
"version" : "2017-02-28",
"operation" : "Query",
"query" : {
## Provide a query expression. **
"expression": "userId = :userId",
"expressionValues" : {
":userId" : {
"S" : "${context.source.id}"
}
}
},
"index": "userIdIndex",
"limit": #if(${context.arguments.limit}) ${context.arguments.limit} #else 20 #end,
"nextToken": #if(${context.arguments.nextToken}) "${context.arguments.nextToken}" #else null #end
}
The response map:
{
"items": $util.toJson($context.result.items),
"nextToken": #if(${context.result.nextToken}) "${context.result.nextToken}" #else null #end
}
The query:
query {
getUser(id: "0b6af629-6009-4f4d-a52f-67aef7b42f43") {
id
createdCurricula {
title
}
}
}
The error:
{
"data": {
"getUser": {
"id": "0b6af629-6009-4f4d-a52f-67aef7b42f43",
"createdCurricula": null
}
},
"errors": [
{
"path": [
"getUser",
"createdCurricula"
],
"locations": null,
"message": "Can't resolve value (/getUser/createdCurricula) : type mismatch error, expected type LIST"
}
]
}
The CurriculumTable has a global secondary index titled userIdIndex, which has userId as the partition key.
If I change the response map to this:
$util.toJson($context.result.items)
The output is the following:
{
"data": {
"getUser": {
"id": "0b6af629-6009-4f4d-a52f-67aef7b42f43",
"createdCurricula": null
}
},
"errors": [
{
"path": [
"getUser",
"createdCurricula"
],
"errorType": "MappingTemplate",
"locations": [
{
"line": 4,
"column": 5
}
],
"message": "Unable to convert \n{\n [{\"id\":\"87897987\",\"title\":\"Test Curriculum\",\"userId\":\"0b6af629-6009-4f4d-a52f-67aef7b42f43\"}],\n} to class java.lang.Object."
}
]
}
If I take that string and run it through a console.log in my frontend app, I get:
{
[{"id":"2","userId":"0b6af629-6009-4f4d-a52f-67aef7b42f43"},{"id":"1","userId":"0b6af629-6009-4f4d-a52f-67aef7b42f43"}]
}
That's clearly an object. How do I make it... not an object, so that AppSync properly reads it as a list?
SOLUTION
My response map had a set of curly braces around it. I'm pretty sure that was placed there in the generator by Amazon. Removing them fixed it.
I think I'm not seeing the complete view of your schema, I was expecting something like:
schema {
query: Query
}
Where Query is RootQuery, in fact you didn't share us your Query definition. Assuming you have the right Query definition. The main problem is in your response template.
> "items": $util.toJson($context.result.items)
This means that you are passing a collection named: *"items"* to Graphql query engine. And you are referring this collection as "createdCurricula". So solve this issue your response-mapping-template is the right place to fix. How? just replace the above line with the following.
"createdCurricula": $util.toJson($context.result.items),
Please the main thing to note here is, the mapping template is a bridge between your datasources and qraphql, feel free to make any computation, or name mapping but don't forget that object names in that response json are the one should match in schema/query definition.
Thanks.
Musema
change to result type to $util.toJson($ctx.result.data.posts)
The exception msg says that it expected a type list.
Looking at:
{
[{"id":"2","userId":"0b6af629-6009-4f4d-a52f-67aef7b42f43"},{"id":"1","userId":"0b6af629-6009-4f4d-a52f-67aef7b42f43"}]
}
I don't see that createdCurricula is a LIST.
What is currently in DDB is:
"id": "0b6af629-6009-4f4d-a52f-67aef7b42f43",
"createdCurricula": null