My use case is the following:
I have a page with a quiz on it, the quiz has N sections/questions and M possible answers. Both the questions and answers contain multiple fields though (e.g. an image, title and a color for each answer). I'm using a slice and putting the questions in the repeatable area, but you can't have group fields inside the repeatable area.
Any alternative ways of doing that? Wordpress Advanced Custom Fields solves this easily.
There should be no problem modelling this with slices. You would have your slice like you've described with the question and it's image etc in the non repeatable field and the answers with their images in the repeatable field.
Then in the document writing section you would call a slice for each question and select 'Add a new element to group' for each answer.
This is an example of what you json structure of your content type should look like:
{
"Main" : {
"home_title" : {
"type" : "StructuredText",
"config" : {
"single" : "heading1, heading2, heading3, heading4, heading5, heading6",
"label" : "home title",
"placeholder" : "Home"
}
},
"body" : {
"type" : "Slices",
"fieldset" : "Slice zone",
"config" : {
"labels" : {
"mcq" : [ {
"name" : "...",
"display" : ""
} ]
},
"choices" : {
"Question" : {
"type" : "Slice",
"fieldset" : "Question",
"description" : "Question and answers",
"icon" : "help",
"display" : "list",
"non-repeat" : {
"question" : {
"type" : "StructuredText",
"config" : {
"single" : "heading4",
"label" : "question"
}
},
"code_snippet" : {
"type" : "StructuredText",
"config" : {
"multi" : "preformatted",
"label" : "code snippet"
}
},
"correct_answer" : {
"type" : "Number",
"config" : {
"label" : "Correct answer"
}
},
"answer_explanatrion" : {
"type" : "StructuredText",
"config" : {
"multi" : "paragraph, preformatted, heading3, heading4, heading5, heading6, strong, em, hyperlink, image, embed, list-item, o-list-item, o-list-item",
"label" : "Answer explanation"
}
}
},
"repeat" : {
"answers" : {
"type" : "StructuredText",
"config" : {
"multi" : "paragraph, preformatted, strong, em, embed",
"label" : "Answers"
}
}
}
}
}
}
}
}
}
Related
I am trying to create a workspace add-on with a couple input boxes and a submit button. The servlet simply returns http endpoints in json code for the google add-on to read the code and build the card properly. However, I cannot seem to figure out how to get the text input values. What action do I need to call on button click to return an http endpoint with parsable json to the servlet?
Here is the code for creating the card:
{"renderActions" : {
"action" : {
"navigations" : [ {
"pushCard" : {
"header" : {
"title" : "NDA Form"
},
"sections" : [ {
"widgets" : [ {
"textParagraph" : {
"text" : "Please check for proper input!"
}
}, {
"textInput" : {
"label" : "Name",
"type" : "SINGLE_LINE",
"name" : "signerName"
}
}, {
"textInput" : {
"label" : "Email",
"type" : "SINGLE_LINE",
"name" : "email"
}
}, {
"textInput" : {
"label" : "Company Name",
"type" : "SINGLE_LINE",
"name" : "compName"
}
}, {
"textInput" : {
"label" : "Address",
"type" : "SINGLE_LINE",
"name" : "address"
}
}, {
"textInput" : {
"label" : "Date",
"type" : "SINGLE_LINE",
"name" : "date"
}
}, {
"buttonList" : {
"buttons" : [ {
"text" : "Submit Form",
"color" : {
"red" : 0.38,
"green" : 0.765,
"blue" : 0.762,
"alpha" : 1.0
},
"onClick" : {
"action" : {
"function" : "https://8f74-38-101-235-211.ngrok.io/landing/process/nda",
"parameters" : [ {
"key" : "action",
"value" : "process/nda"
} ]
}
},
"disabled" : false
} ]
}
} ]
} ]
}
} ]
}}}
And here is a picture of the form on the card:
Card Form
I have this:
{
"service" : {
"category" : "managed-object",
"resource" : "attribute",
"action" : "delete",
"options" : {
"uuid" : "#VALUE",
"attributes" : {
"name" : {
"value" : "#VALUE"
},
"contactInfo" : "",
"activationDate" : "",
"deactivationDate" : "",
"protectStopDate" : "",
"processStartDate" : ""
}
}
}
}
I need this:
{
"service" : {
"category" : "managed-object",
"resource" : "attribute",
"action" : "delete",
"options" : {
"uuid" : "#VALUE",
"attributes" : {
"name" : {
"value" : "#VALUE"
}
}
}
}
}
Previously I had a similar problem that was a little bit more complicated, and I received this amazingly simple answer from someone here:
.service.options |= (del(.max, .objectGroupMember) | .attributes|={name})
That jq command works even here, but of course (.max, .objectGroupMember) does not make sense because it does not exist.
How can I achieve my desired result?
A different take on the problem:
walk(if type=="object" then with_entries(select(.value!="")) else . end)
I found it in Weeble's answer to my earlier question:
'.service.options.attributes |= {name}'
I'm currently trying to write multiple QueueConfigurations into my CloudFormation template. Each is an SQS queue that is triggered when an object is created to a specified prefix. Here's what I have so far:
{
"Resources": {
"S3Bucket": {
"Type" : "AWS::S3::Bucket",
"Properties" :
"BucketName" : { "Ref" : "paramBucketName" },
"LoggingConfiguration" : {
"DestinationBucketName" : "test-bucket",
"LogFilePrefix" : { "Fn::Join": [ "", [ { "Ref": "paramBucketName" }, "/" ] ] }
},
"NotificationConfiguration" : {
"QueueConfigurations" : [{
"Id" : "1",
"Event" : "s3:ObjectCreated:*",
"Filter" : {
"S3Key" : {
"Rules" : {
"Name" : "prefix",
"Value" : "folder1/"
}
}
},
"Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-cdc_feeder_prod_hvr_dev"
}],
"QueueConfigurations" : [{
"Id" : "2",
"Event" : "s3:ObjectCreated:*",
"Filter" : {
"S3Key" : {
"Rules" : {
"Name" : "prefix",
"Value" : "folder2/"
}
}
},
"Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-latency_hvr_dev"
}]
}
}
}
}
}
}
I've encountered the error saying Encountered unsupported property Id. I thought that by defining the ID, I would be able to avoid the Duplicate object key error.
Does anyone know how to create multiple triggers in a single CloudFormation template? Thanks for the help in advance.
It should be structured like the below, There should only be one QueueConfigurations attribute
that contains all queue configurations within it. Also the Id parameter is not a valid property.
{
"Resources": {
"S3Bucket": {
"Type" : "AWS::S3::Bucket",
"Properties" :
"BucketName" : { "Ref" : "paramBucketName" },
"LoggingConfiguration" : {
"DestinationBucketName" : "test-bucket",
"LogFilePrefix" : { "Fn::Join": [ "", [ { "Ref": "paramBucketName" }, "/" ] ] }
},
"NotificationConfiguration" : {
"QueueConfigurations" : [{
"Event" : "s3:ObjectCreated:*",
"Filter" : {
"S3Key" : {
"Rules" : {
"Name" : "prefix",
"Value" : "folder1/"
}
}
},
"Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-cdc_feeder_prod_hvr_dev"
},
{
"Event" : "s3:ObjectCreated:*",
"Filter" : {
"S3Key" : {
"Rules" : {
"Name" : "prefix",
"Value" : "folder2/"
}
}
},
"Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-latency_hvr_dev"
}]
}
}
}
}
}
}
There is more information about QueueConfiguration in the documentation.
I'm trying to convert JSON into Avro using the kite-sdk morphline module. After playing around I'm able to convert the JSON into Avro using a simple schema (no complex data types).
Then I took it one step further and modified the Avro schema as displayed below (subrec.avsc). As you can see the schema consist of a subrecord.
As soon as I tried to convert the JSON to Avro using the morphlines.conf and the subrec.avsc it failed.
Somehow the JSON paths "/record_type[]/alert/action" are not translated by the toAvro function.
The morphlines.conf
morphlines : [
{
id : morphline1
importCommands : ["org.kitesdk.**"]
commands : [
# Read the JSON blob
{ readJson: {} }
{ logError { format : "record: {}", args : ["#{}"] } }
# Extract JSON
{ extractJsonPaths { flatten: false, paths: {
"/record_type[]/alert/action" : /alert/action,
"/record_type[]/alert/signature_id" : /alert/signature_id,
"/record_type[]/alert/signature" : /alert/signature,
"/record_type[]/alert/category" : /alert/category,
"/record_type[]/alert/severity" : /alert/severity
} } }
{ logError { format : "EXTRACTED THIS : {}", args : ["#{}"] } }
{ extractJsonPaths { flatten: false, paths: {
timestamp : /timestamp,
event_type : /event_type,
source_ip : /src_ip,
source_port : /src_port,
destination_ip : /dest_ip,
destination_port : /dest_port,
protocol : /proto,
} } }
# Create Avro according to schema
{ logError { format : "WE GO TO AVRO"} }
{ toAvro { schemaFile : /etc/flume/conf/conf.empty/subrec.avsc } }
# Create Avro container
{ logError { format : "WE GO TO BINARY"} }
{ writeAvroToByteArray { format: containerlessBinary } }
{ logError { format : "DONE!!!"} }
]
}
]
And the subrec.avsc
{
"type" : "record",
"name" : "Event",
"fields" : [ {
"name" : "timestamp",
"type" : "string"
}, {
"name" : "event_type",
"type" : "string"
}, {
"name" : "source_ip",
"type" : "string"
}, {
"name" : "source_port",
"type" : "int"
}, {
"name" : "destination_ip",
"type" : "string"
}, {
"name" : "destination_port",
"type" : "int"
}, {
"name" : "protocol",
"type" : "string"
}, {
"name": "record_type",
"type" : ["null", {
"name" : "alert",
"type" : "record",
"fields" : [ {
"name" : "action",
"type" : "string"
}, {
"name" : "signature_id",
"type" : "int"
}, {
"name" : "signature",
"type" : "string"
}, {
"name" : "category",
"type" : "string"
}, {
"name" : "severity",
"type" : "int"
}
] } ]
} ]
}
The output on { logError { format : "EXTRACTED THIS : {}", args : ["#{}"] } } I output the following:
[{
/record_type[]/alert / action = [allowed],
/record_type[]/alert / category = [],
/record_type[]/alert / severity = [3],
/record_type[]/alert / signature = [GeoIP from NL,
Netherlands],
/record_type[]/alert / signature_id = [88006],
_attachment_body = [{
"timestamp": "2015-03-23T07:42:01.303046",
"event_type": "alert",
"src_ip": "1.1.1.1",
"src_port": 18192,
"dest_ip": "46.231.41.166",
"dest_port": 62004,
"proto": "TCP",
"alert": {
"action": "allowed",
"gid": "1",
"signature_id": "88006",
"rev": "1",
"signature" : "GeoIP from NL, Netherlands ",
"category" : ""
"severity" : "3"
}
}],
_attachment_mimetype=[json/java + memory],
basename = [simple_eve.json]
}]
UPDATE 2017-06-22
you MUST populate the data in the structure in order for this to work, by using addValues or setValues
{
addValues {
micDefaultHeader : [
{
eventTimestampString : "2017-06-22 18:18:36"
}
]
}
}
after debugging the sources of morphline toAvro, it appears that the record is the first object to be evaluated, no matter what you put in your mappings structure.
the solution is quite simple, but unfortunately took a little extra time, eclipse, running the flume agent in debug mode, cloning the source code and lots of coffee.
here it goes.
my schema:
{
"type" : "record",
"name" : "co_lowbalance_event",
"namespace" : "co.tigo.billing.cboss.lowBalance",
"fields" : [ {
"name" : "dummyValue",
"type" : "string",
"default" : "dummy"
}, {
"name" : "micDefaultHeader",
"type" : {
"type" : "record",
"name" : "mic_default_header_v_1_0",
"namespace" : "com.millicom.schemas.root.struct",
"doc" : "standard millicom header definition",
"fields" : [ {
"name" : "eventTimestampString",
"type" : "string",
"default" : "12345678910"
} ]
}
} ]
}
morphlines file:
morphlines : [
{
id : convertJsonToAvro
importCommands : ["org.kitesdk.**"]
commands : [
{
readJson {
outputClass : java.util.Map
}
}
{
addValues {
micDefaultHeader : [{}]
}
}
{
logDebug { format : "my record: {}", args : ["#{}"] }
}
{
toAvro {
schemaFile : /home/asarubbi/Development/test/co_lowbalance_event.avsc
mappings : {
"micDefaultHeader" : micDefaultHeader
"micDefaultHeader/eventTimestampString" : eventTimestampString
}
}
}
{
writeAvroToByteArray {
format : containerlessJSON
codec : null
}
}
]
}
]
the magic lies here:
{
addValues {
micDefaultHeader : [{}]
}
}
and in the mappings:
mappings : {
"micDefaultHeader" : micDefaultHeader
"micDefaultHeader/eventTimestampString" : eventTimestampString
}
explanation:
inside the code the first field name that is evaluated is micDefaultHeader of type RECORD. as there's no way to specify a default value for a RECORD (logically correct), the toAvro code evaluates this, does not get any value configured in mappings and therefore it fails at it detects (wrongly) that the record is empty when it shouldn't.
however, taking a look at the code, you may see that it requires a Map object, containing no values to please the parser and continue to the next element.
so we add a map object using the addValues and fill it with an empty map [{}]. notice that this must match the name of the record that is causing you an empty value. in my case "micDefaultHeader"
feel free to comment if you have a better solution, as this looks like a "dirty fix"
Im trying to create a 'jsTree' treeview that gets it's data from a .Net webservice.
Everything is working, except for the a-node's href attribute. Whatever I try, it always renders as '#'.
As I understand from the documentation, all attributes in any data object get copied to the a-node.
Below is an example of my current json object. Can anyway figure out why the href attribute isn't copied to the nodes?
[ { "attributes" : { "id" : "rootnode_2",
"rel" : "root2"
},
"children" : [ { "attributes" : { "id" : "childnode_9",
"rel" : "folder"
},
"children" : [ { "attributes" : { "id" : "childnode_23",
"rel" : "folder"
},
"children" : null,
"data" : { "href" : "http://www.google.com",
"title" : "Test_Below_1"
},
"state" : null
} ],
"data" : { "href" : "http://www.google.com",
"title" : "Test_1"
},
"state" : null
},
{ "attributes" : { "id" : "childnode_10",
"rel" : "folder"
},
"children" : [ { "attributes" : { "id" : "childnode_24",
"rel" : "folder"
},
"children" : null,
"data" : { "href" : "http://www.google.com",
"title" : "Test_Below_2"
},
"state" : null
} ],
"data" : { "href" : "http://www.google.com",
"title" : "Test_2"
},
"state" : null
}
],
"data" : { "href" : "http://www.google.com",
"title" : "Glatt"
},
"state" : "closed"
} ]
This is how I initialize the tree;
$("#jstreejson").jstree({
json_data : {
"data": treeObject
},
themes: {
"theme": "apple",
"dots": true,
"icons": true,
"url": "/Scripts/themes/apple/style.css"
},
plugins: ['core', 'themes', 'json', "json_data"]
});
So... I'm not sure that's entirely correct. You can't control the anchor attributes as far as I know, but what you can do add stuff to the attr hash in the json and then use the select_node.jstree event to open the desired link, i.e:
.bind("select_node.jstree", function (e,data) {
var href_address = data.rslt.obj.attr("whatever");
// open desired link
}