mustache partial not looping through the data passed down to it - json

I am using mustache in conjunction with enter link description herepattern lab to render out a list of items from a json data file. Given this data structure:
{
"states": {
"dropdown": {
"items": [
{
"title": "CA"
},
{
"title": "OR"
},
{
"title": "TX"
}
]
}
},
"roles": {
"dropdown": {
"items": [
{
"title": "Mid-level Office Manager"
},
{
"title": "Facility Manager"
},
{
"title": "Resources Coordinator"
}
]
}
}
}
If I do the following within my partial:
{{#states}}
{{#dropdown.items}}{{title}}{{/dropdown.items}}
{{/states}}
The names render out fine.
But if I do this:
{{#states}}
{{> molecules-dropdown-picker(btnDropdownToggleLabel: "OR")}}
{{/states}}
Where the dropdown picker partial has the following code:
{{#dropdown.items}}{{title}}{{/dropdown.items}}
It won't render. What am I doing wrong?

I figured this out by doing the following:
JSON:
{
"states": {
"inputTextLabel": "State",
"inputTextName": "address_state",
"btnDropdownToggleLabel": "OR",
"dropdownPickerItems": [
{
"dropdownItemTitle": "OR"
},
{
"dropdownItemTitle": "TX"
},
{
"dropdownItemTitle": "UT"
}
]
},
"roles": {
"inputTextLabel": "Company Role",
"inputTextName": "company_role",
"btnDropdownToggleLabel": "Facility Manager",
"dropdownPickerItems": [
{
"dropdownItemTitle": "Facility Manager"
},
{
"dropdownItemTitle": "Resources Manager"
},
{
"dropdownItemTitle": "Mid-level Manager"
}
]
}
}
FORM:
{{#states}}
{{> molecules-dropdown-picker-list}}
{{/states}}
DROPDOWN-PICKER-LIST:
<div class="dropdown-picker js-dropdown">
<ul class="dropdown-picker__list js-dropdown-list">
{{#dropdownPickerItems}}
{{> atoms-dropdown-picker-item}}
{{/dropdownPickerItems}}
</ul>
</div>
DROPDOWN-PICKER-ITEM:
<li class="dropdown-picker__item js-dropdown-item">
{{dropdownItemTitle}}
<span class="dropdown-picker__selected-check">
{{> atoms-icon(icon-type: "check-small") }}
</span>
</li>

Related

Card_V2 display issue in Google Chat

I have the following JSON to display Card_V2 for Google Chat, (note: words with "let_" are variables):
{
"cards_v2": [
{
"card": {
"header": {
"title": "Create campaign",
"subtitle": "Please complete the following information",
"imageType": "CIRCLE",
"imageUrl": "let_avatar"
},
"sections": [
{
"widgets": [
{
"textInput": {
"label": "Campaign name",
"type": "SINGLE_LINE",
"name": "nCampaign",
"value": "let_campaign"
}
},
{
"textInput": {
"label": "Campaign subject",
"type": "SINGLE_LINE",
"name": "subject",
"value": "let_subject"
}
},
{
"textInput": {
"label": "User name",
"type": "SINGLE_LINE",
"name": "userName",
"value": "let_userName"
}
},
{
"buttonList": {
"buttons": [
{
"text": "Create campaign",
"color": {
"red": 0.502,
"green": 1,
"blue": 0.733,
"alpha": 1
},
"onClick": {
"action": {
"function": "create",
"parameters": []
}
}
},
{
"text": "Cancel",
"color": {
"red": 0.502,
"green": 1,
"blue": 0.733,
"alpha": 1
},
"onClick": {
"action": {
"function": "cancel",
"parameters": []
}
}
}
]
},
"horizontalAlignment": "CENTER"
}
]
}
]
}
}
]
}
My problem is that the "textInput" screen does not appear, but last week it did. Does anyone have any idea what's going on?
PS: the Card is the return of the onMessage(event) function in Google Apps Script

My syntax highlighting in vscode is not working

I have a problem with Visual Studio Code custom syntax highlighting.
I have made a extension using yo code, put it in %userprofile%/.vscode/extensions, restarted Visual Studio Code, but it's not highlighting any words, but at the bottom it says it's using my syntax highlighter.
This is my tmLanguage.json:
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Instructions ASM",
"patterns": [
{
"include": "#keywords"
},
{
"include": "#typewords"
},
{
"include": "#strings"
},
{
"include": "#numbers"
},
{
"include": "#variables"
},
{
"include": "#comments"
},
{
"include": "#sections"
}
],
"repository": {
"keywords":{
"patterns": [
{
"name": "keyword",
"match": "(mov|xor|and|or|int|jmp|con)"
}
]
},
"typewords": {
"patterns": [
{
"name": "keyword.control",
"match": "(db|dw|dd|resb|resw|resd|eq|byte|word|doubleword)"
}
]
},
"strings": {
"patterns": [
{
"name": "string",
"match": "(\".*\")|('.')"
}
]
},
"numbers": {
"patterns": [
{
"name": "constant.numeric",
"match": "(0[xX][a-fA-F0-9]{1,8})|(\\d+)|(0[bB][0-1]{1,64})"
}
]
},
"variables": {
"patterns": [
{
"name": "variable",
"match": "$[a-zA-Z0-9_-.]{1,255}"
}
]
},
"comments": {
"patterns": [
{
"name": "comment",
"match": ";.*"
}
]
},
"sections": {
"patterns": [
{
"name": "entity.name.class",
"match": "(\\.DATA|\\.TEXT|\\.BSS)"
}
]
}
},
"scopeName": "source.1"
}
This is my package.json:
{
"name": "instruction-assembly",
"displayName": "Instruction assembly",
"description": "Code only in instructions - Assembly readable version",
"version": "0.0.1",
"engines": {
"vscode": "^1.54.0"
},
"categories": [
"Programming Languages"
],
"contributes": {
"languages": [{
"id": "instructions-asm",
"aliases": ["Instructions ASM", "instructions-asm"],
"extensions": [".1"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "instructions-asm",
"scopeName": "source.1",
"path": "./syntaxes/instructions-asm.tmLanguage.json"
}]
}
}
Thanks!

What is wrong with this code for visual studio code highlighting?

I'm new in visual studio code language creation, and I tried to make my own syntax highlighting for my custom language using yo code. In my tmLanguge.json file, I got this code, but I don't work and it doesn't highlight anything at all. Can someone please tell me what the problem is?
When I tried it only with the "comments" object, it worked well...
Thanks
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "OP-RANDS++",
"patterns": [
{
"include": "#comments"
},
{
"include": "#numbers"
},
{
"include": "#blocks"
},
{
"include": "#basecalls"
},
{
"include": "#outin"
},
{
"include": "#defines"
},
{
"include": "#maths"
},
{
"include": "#others"
}
],
"repository": {
"comments": {
"patterns": [
{
"name":"comment",
"match": "^\u005c?.*"
}
]
},
"numbers": {
"patterns": [
{
"name": "constant.numeric",
"match": "\u005cd|\u005c\u005c\u005cd"
}
]
},
"blocks": {
"patterns": [
{
"name": "emphasis",
"match": "{|}|[|]|(|)"
}
]
},
"basecalls": {
"patterns": [
{
"name": "keyword.control",
"match": "\u005c.|\u005c|"
}
]
},
"outin": {
"patterns": [
{
"name": "entity.name.function",
"match": ";|,"
}
]
},
"defines": {
"patterns": [
{
"name": "variable.name",
"match": "~|`|^"
}
]
},
"maths": {
"patterns": [
{
"name": "keyword.operator",
"match": "+|-|*|/|%"
}
]
},
"others": {
"patterns": [
{
"name": "keyword.other",
"match": "'|$"
}
]
}
},
"scopeName": "source.opp"
}

JOLT - Transform Array of JSON objects containing nested Arrays into their respective Array group

I want to transform a JSON input file into expected JSON output file:
My input file:
[
{
"category": [
{
"id": "id1",
"name": "Connected Home & Housewares1"
},
{
"id": "id2",
"name": "Housewares1"
},
{
"id": "id3",
"name": "Household Batteries1"
},
{
"id": "id4",
"name": "Alkaline Batteries1"
}
]
},
{
"category": [
{
"id": "id1",
"name": "Connected Home & Housewares2"
},
{
"id": "id2",
"name": "Housewares2"
},
{
"id": "id3",
"name": "Household Batteries2"
},
{
"id": "id4",
"name": "Alkaline Batteries2"
}
]
}
]
(Above is just an example of 2 records, but it contains ~50k records)
Expected Output:
[
{
"childSKUs": [
{
"divisionName": "Connected Home & Housewares1",
"deptName": "Housewares1",
"className": "Household Batteries1"
}
]
},
{
"childSKUs": [
{
"divisionName": "Connected Home & Housewares2",
"deptName": "Housewares2",
"className": "Household Batteries2"
}
]
}
]
My current JOLT Spec:
[
{
"operation": "shift",
"spec": {
"*": {
"category": {
"0": {
"name": "[0].childSKUs[&1].divisionName"
},
"1": {
"name": "[0].childSKUs[&1].deptName"
},
"2": {
"name": "[0].childSKUs[&1].className"
}
}
}
}
}
]
But it is only giving following output:
[
{
"childSKUs": [
{
"divisionName": [
"Connected Home & Housewares1",
"Connected Home & Housewares2"
]
},
{
"deptName": [
"Housewares1",
"Housewares2"
]
},
{
"className": [
"Household Batteries1",
"Household Batteries2"
]
}
]
}
]
I tried various options by playing in https://jolt-demo.appspot.com but no luck so far. Any help is appreciated. Would also be great if you explain your SPEC how was it done.
Ok, I figured it out myself.
Thanks to #Pokuri's answer here which gave me the idea to arrive at the solution: https://stackoverflow.com/a/55861132/248847
Correct JOLT SPEC for above question:
[
{
"operation": "shift",
"spec": {
"*": {
"category": {
"0": {
"name": "[&3].childSKUs[&1].divisionName"
},
"1": {
"name": "[&3].childSKUs[0].deptName"
},
"2": {
"name": "[&3].childSKUs[0].className"
}
}
}
}
}
]

How to send carousel through API.AI?

My bot wants to send a carousel to Google Assistant through API.AI. My understanding is, I need to enclose it inside data -> google, such as:
{
"data": {
"google": {
"expectUserResponse": true,
"isSsml": false,
"expectedInputs": [
{
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Hello World"
}
}
]
}
},
"possibleIntents": [
{
"intent": "actions.intent.OPTION",
"inputValueData": {
"#type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
"carouselSelect": {
"items": [
{
"optionInfo": {"key": "FOO", "synonyms": ["foo"]},
"title": "Foo",
"image": {"url": "http://example.com/", "accessibilityText": "Foo"}
},
{
"optionInfo": {"key": "BAR", "synonyms": ["bar"]},
"title": "Bar",
"image": {"url": "http://example.com/", "accessibilityText": "Bar"}
}
]
}
}
}
]
}
]
}
}
}
But it doesn't work. What is the proper format?
If you are testing this through the Simulator, there should have been a validation error that appeared that would give you at least a little guidance about what is missing. If you didn't even get that, there may be a problem with the other parts besides the data.google object such that api.ai had problems with it.
There are a number of things that, at a glance, could be the problem. You can't just stick a conversation webhook response in the api.ai response. See https://developers.google.com/actions/apiai/webhook#response for the documentation, but here are a few things that I see that could be issues
The expectedInputs property shouldn't be there.
Your data.google.expectedInputs.possibleIntents property should be at data.google.systemIntent
You still need to provide the api.ai fields, such as a basic speech property
The data.google.expectedInputs.inputPrompt.richInitialPrompt would be at data.google.richResponse
Here is some JSON that works for me:
{
"speech": "Hello",
"contextOut": [
{
"name": "_actions_on_google_",
"lifespan": 100,
"parameters": {}
}
],
"data": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Hello"
}
}
],
"suggestions": []
},
"systemIntent": {
"intent": "actions.intent.OPTION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
"carouselSelect": {
"items": [
{
"title": "Foo",
"image": {
"url": "http://example.com/foo.jpg",
"accessibilityText": "Foo title"
},
"optionInfo": {
"key": "foo-key",
"synonyms": [
"foo-alt-1",
"foo-alt-2"
]
}
},
{
"title": "Bar",
"image": {
"url": "http://example.com/bar.jpg",
"accessibilityText": "Bar title"
},
"optionInfo": {
"key": "bar-key",
"synonyms": [
"bar-alt-1",
"bar-alt-2"
]
}
}
]
}
}
}
}
}
}