I'm using a .json file to hold font/text information for an application. Now that I'm adding different languages I need to be able to specify different sizes for certain fonts due to the varying sizes of the words in that language for example German words tend to be longer than English, so I might want a smaller font.
My problem is that there will be a ton of duplicate data in my .json file, as most fonts will remain the same for each language. Here's an example of the duplicate data that I want to reduce somehow, I just don't know how to format my .json file to do so (note that I've stripped out a lot of details so this will read easier):
"styles":
{
"en":
{
"main_title" :
{
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 18,
},
},
"de":
{
"main_title" :
{
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 16,
},
},
"fr":
{
"main_title" :
{
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 18,
},
}
}
Notice that in the above example that I have three languages, and all use identical font information with the exception of deutsche using a smaller "heading" font. What I'd like to do is something like this:
"styles":
{
"en", "de", "fr":
{
"main_title" :
{
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 18,
},
},
"de":
{
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 16,
},
},
}
In this example I have all three languages use the same information, but am able to define one change in the deutsche language font. Obviously my second example won't read properly because it's not correct syntax, but hopefully this gets across what I'm trying to achieve. Is there any syntax in JSON that will allow me to do something like this?
I don't believe that JSON will do this, but you could have a 'default' object which consumers of this data can look at for any values missing from other language objects:
"styles": {
"default": {
"main_title" : {
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" : {
"font" : "font://verdana-bold.ttf",
"size" : 18,
},
},
"de": {
"heading" : {
"size" : 16,
}
}
}
If you need to specify which languages are permissible, just add that as another attribute on the object:
"styles": {
"languages": ["en", "de", "fr"],
...
}
Related
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"
}
}
}
}
}
}
}
}
}
I am trying to load in a TSV in druid using this ingestion speck:
MOST UPDATED SPEC BELOW:
{
"type" : "index",
"spec" : {
"ioConfig" : {
"type" : "index",
"inputSpec" : {
"type": "local",
"baseDir": "quickstart",
"filter": "test_data.json"
}
},
"dataSchema" : {
"dataSource" : "local",
"granularitySpec" : {
"type" : "uniform",
"segmentGranularity" : "hour",
"queryGranularity" : "none",
"intervals" : ["2016-07-18/2016-07-22"]
},
"parser" : {
"type" : "string",
"parseSpec" : {
"format" : "json",
"dimensionsSpec" : {
"dimensions" : ["name", "email", "age"]
},
"timestampSpec" : {
"format" : "yyyy-MM-dd HH:mm:ss",
"column" : "date"
}
}
},
"metricsSpec" : [
{
"name" : "count",
"type" : "count"
},
{
"type" : "doubleSum",
"name" : "age",
"fieldName" : "age"
}
]
}
}
}
If my schema looks like this:
Schema: name email age
And actual dataset looks like this:
name email age Bob Jones 23 Billy Jones 45
Is this how the columns should be formatted^^ in the above dataset for a TSV? Like name email age should be first (the columns) and then the actual data. I am confused how Druid will know how to map the columns to the actual dataset in TSV format.
TSV stands for tab separated format, so it looks the same as csv but you will use tabs instead of commas e.g.
Name<TAB>Age<TAB>Address
Paul<TAB>23<TAB>1115 W Franklin
Bessy the Cow<TAB>5<TAB>Big Farm Way
Zeke<TAB>45<TAB>W Main St
you will use frist line as header to define your column names - so you can use "name", "age" or "email" in dimensions in your spec file
as for the gmt and utc, they are basically the same
There is no time difference between Greenwich Mean Time and
Coordinated Universal Time
first one is time zone, the other one is a time standard
btw don`t forget to include a column with some time value in your tsv file!!
so e.g. if you will have tsv file that looks like:
"name" "position" "office" "age" "start_date" "salary"
"Airi Satou" "Accountant" "Tokyo" "33" "2016-07-16T19:20:30+01:00" "162700"
"Angelica Ramos" "Chief Executive Officer (CEO)" "London" "47" "2016-07-16T19:20:30+01:00" "1200000"
your spec file should look like this:
{
"spec" : {
"ioConfig" : {
"inputSpec" : {
"type": "local",
"baseDir": "path_to_folder",
"filter": "name_of_the_file(s)"
}
},
"dataSchema" : {
"dataSource" : "local",
"granularitySpec" : {
"type" : "uniform",
"segmentGranularity" : "hour",
"queryGranularity" : "none",
"intervals" : ["2016-07-01/2016-07-28"]
},
"parser" : {
"type" : "string",
"parseSpec" : {
"format" : "tsv",
"dimensionsSpec" : {
"dimensions" : [
"position",
"age",
"office"
]
},
"timestampSpec" : {
"format" : "auto",
"column" : "start_date"
}
}
},
"metricsSpec" : [
{
"name" : "count",
"type" : "count"
},
{
"name" : "sum_sallary",
"type" : "longSum",
"fieldName" : "salary"
}
]
}
}
}
I have a JSON schema that looks like this:
{
"_id" : ObjectId("5692a3e124de1e0ce2dfda22"),
"title" : "A Decade of Decadence, Pt. 2: Legacy of Dreams",
"year" : 2013,
"rated" : "PG-13",
"released" : ISODate("2013-09-13T04:00:00Z"),
"runtime" : 65,
"countries" : [
"USA"
],
"genres" : [
"Documentary"
],
"director" : "Drew Glick",
"writers" : [
"Drew Glick"
],
"actors" : [
"Gordon Auld",
"Howie Boulware Jr.",
"Tod Boulware",
"Chen Drachman"
],
"plot" : "A behind the scenes look at the making of A Tiger in the Dark: The Decadence Saga.",
"poster" : null,
"imdb" : {
"id" : "tt2199902",
"rating" : 8,
"votes" : 50
},
"awards" : {
"wins" : 0,
"nominations" : 0,
"text" : ""
},
"type" : "movie"
}
I am trying to find a movie released in 2013, that is rated PG-13 and has won no awards. I tried the following query in my Mongo Shell but no luck:
db.movieDetails.find({rated: "PG-13", year:2013, awards: { wins : 0}})
Any ideas?
From the documentation:
When the field holds an embedded document, a query can either specify an exact match on the embedded document or specify a match by individual fields in the embedded document using the dot notation
db.movieDetails.find( { "rated": "PG-13", "year": 2013, "awards.wins" : 0 } )
if this PG-13 rating query would work for you:
db.movieDetails.find({"rated": "PG-13"})
then i would try something like this:
db.movieDetails.find({$and: [{"rated": "PG-13"}, {"year": 2013}, {"awards": { "wins" : 0}}]} )
[
{
"id" : 1,
"name" : "clevin",
"description" : "Version 1 : some desc",
"info" : [{
"id" : 2,
"name" : "abc",
"size" : "5 GB",
"used" : "25%"
},
{
"id" : 3,
"name" : "def",
"size" : "10 GB",
"used" : "15%"
},
{
"id" : 4,
"name" : "ghi",
"size" : "20 GB",
"used" : "5%"
}],
}]
This is my json file. When ever i mouse over "info.name"[abc, def, ghi] popover will display "name", "size" and "used".
but my issue is "abc" is the first value , when ever i mouseover it display value as expected. but when i mouseover "def" and "ghi" nothing is happened :(.
<ul type="none">
<li>
<label id="vol-label" class="muted">Info :</label>
{{#info}}
<span id="value"><a><u>{{name}}</u></a></span>
<span id="info-popover-title" class="hide">{{name}}</span>
<div id="info-popover-content" class="hide">
<p>Size : {{size}}</p> <p> Used : {{used}}</p><p> Status : {{status}}</p>
</div>
{{/info}}
</li>
</ul>
This is my template(mustache).
following is my view part(backbone.js)
events: {
"mouseenter #value" : "showDetails",
"mouseleave #value" : "hideDetails" ,
},
showDetails : function() {
this.$("#value").popover({
html : true,
title: function() {
return $("#info-popover-title").html();
},
content: function() {
return $("#info-popover-content").html();
}
});
this.$("#value").popover('show');
},
hideDetails : function() {
this.$("#value").popover('hide');
},
Please see my both screen shot to understand the issue. In fist screens hot see am getting all json info values "abc" "def" and "ghi" . in 2nd screen shot if i mouse over am getting "abc" values. but "def" and "ghi" value is not at all displaying. am not figure it out what is the issue :(.
I need to popove "def" and "ghi" values also. But i think something is wrong in my logic. Thanks in advance. This is really a rare issue for me might be others also.
If i use class insted of id following is the screen shot :(
2 things that you need to change here. First, is to use class to define for popovers instead of id. And the second is to abstract each <li> into its own view. Currently, you have one view that loops through the entire collection. All your events are currently tied to this one view. Doing those things I mentioned should fix this issue.
You can do something like this to have the become its own view which carries it's own sub-element. Just wrote this quickly and haven't tested but the idea is something like this. I'm not really sure which popover library you're using but the idea is generally the same.
Edit: Didn't realized you were using Mustache/Handlebars, so here's the JS Fiddle. Code
Now if you try to call each object it should work.
var abc =
{
"id" : 1,
"name" : "clevin",
"description" : "Version 1 : some desc",
"info" : {
"id" : 2,
"name" : "abc",
"size" : "5 GB",
"used" : "25%"
}
};
var def =
{
"id" : 3,
"name" : "def",
"size" : "10 GB",
"used" : "15%"
};
var ghi = {
"id" : 4,
"name" : "ghi",
"size" : "20 GB",
"used" : "5%"
};
var output =
{
show : function()
{
return abc["info"];
}
};
console.log(output.show());
Can I somehow insert a table inside <li> when using
jsTree (1.0) and
json?
let's say in this code where I want to insert table for
both node and
leaf.
Why? To display more things than only a name and using nice formatting.
"data" : [
{
"data" : "A node",
"children" : [ "Child 1", "Child 2" ]
},
{
"attr" : { "id" : "li.node.id" },
"data" : {
"title" : "Long format demo",
"attr" : { "href" : "#" }
}
}
]
update:
it seems to me that I can use html_titles. But could somebody give me an example how to insert whole table and get cell data from variables?
Update2:
whether I use
"data" : "<table><tr><td>Site name</td><td>variable 1</td><td>variable 2</td></tr></table>",
or
"title" : "<table><tr><td>Site name</td><td>variable 1</td><td>variable 2</td></tr></table",
the table is placed on a new line. Not next to the tree icon. Can I fix that somehow?
Expanding on the original post to help others trying to do the same:
$(function () {
$("#demo1").jstree({
"json_data" : {
"data" : [
{
"data" : "<table style='display: inline-block'><tr><td>Site name</td><td>variable 1</td><td>variable 2</td></tr></table>",
"children" : [ "Child 1", "Child 2" ]
},
{
"attr" : { "id" : "li.node.id" },
"data" : {
"title" : "Long format demo",
"attr" : { "href" : "#" }
}
}
]
},
"core" : {"html_titles" : true},
"plugins" : [ "themes", "json_data" ]
});
});
The key is to allow html in the titles which is set in the core options as well as the table style
I thought it needs to be solved on javascript level but <table style='display: inline-block'> does the trick
Addon: The "text" you supply is actually treated as html by default.
core: {
data: [{
id: "ID",
parent: "#",
text: "<span>Individual</span>",
icon: 'fa fa-star text-warning'
},}]}