Dart Angular Components - How to get full path of selected values? - dart

I'm implementing a Single Selection Nested Tree from the Angular Components Example and the example code gets the selected value.
I want to get the full path with the selected value as well as the selected parent groups titles.
Is this possible? I've been searching for an API documentation but haven't found one yet.
Example:
<material-tree
[options]="nestedOptions"
[expandAll]="expandAll"
[selection]="singleSelection">
</material-tree>
-
final SelectionOptions nestedOptions = new _NestedSelectionOptions([
new OptionGroup(
['Animated Feature Films', 'Live-Action Films', 'Documentary Films'])
], {
'Animated Feature Films': [
new OptionGroup([
'Cinderalla',
'Alice In Wonderland',
'Peter Pan',
'Lady and the Tramp',
])
],
'Live-Action Films': [
new OptionGroup(
['Treasure Island', 'The Littlest Outlaw', 'Old Yeller', 'Star Wars'])
],
'Documentary Films': [
new OptionGroup(['Frank and Ollie', 'Sacred Planet'])
],
'Star Wars': [
new OptionGroup(['By George Lucas'])
],
'By George Lucas': [
new OptionGroup(
['A New Hope', 'Empire Strikes Back', 'Return of the Jedi'])
]
});

There isn't a built in way to display the path information. To make that work you would want to create a class for your values that stores the parent information and makes that accessible. Then use an ItemRenderer to ensure it is displayed as a string when used in the Material Tree.

Related

Exclude empty fields from Log4J2 JsonTemplateLayout output

The log4j2 PatternLayout offers a %notEmpty conversion pattern that allows you to skip sections of the pattern that refer to empty variables.
Is there any way to do something similar for JsonTemplateLayout, specifically for thread context data (MDC)? It correctly (IMO) suppresses null fields, but it doesn't do the same with empty ones.
E.g., given the following in my JSON template:
"application": {
"name": { "key": "x-app", "$resolver": "mdc" },
"context": { "key": "x-app-context", "$resolver": "mdc" },
"instance": {
"name": { "key": "x-appinst", "$resolver": "mdc" },
"context": { "key": "x-appinst-context", "$resolver": "mdc" }
}
}
is there a way to prevent blocks like this from being logged, where the only data in the subtree is the empty string values for context?
"application":{"context":"","instance":{"context":""}}
(Yes, ideally I'd prevent those empty strings being put into the context in the first place, but this isn't my app, I'm just configuring it.)
JsonTemplateLayout author speaking here. Currently, JsonTemplateLayout doesn't support blank property exclusion for the following reasons:
The definition of empty/blank is ambiguous. One might have, null, {}, "\s*", [], [[]], [{}], etc. as valid JSON values. Which one of these are empty/blank? Let's assume we have agreed on a certain behavior. Will it apply to the rest of its users?
Checking if a value is empty/blank incurs an extra runtime cost.
Most of the time you don't care. You persist logs in a storage system, e.g., ELK stack, and there blank value elimination is provided out of the box by the storage engine in the most efficient way.
Would you mind sharing your use case, please? Why do you want to prevent the emission of "context": "" properties? If you deliver your logs to Elasticsearch, there you can easily exclude such fields via appropriate index mappings.
Near as I can tell, no. I would suggest you create a Jira issue to get that addressed.

How do I indent a bulleted list with the Google Docs API

Starting with a Google Doc that looks like:
* Item
I'm hoping to make a series of API calls to turn the doc into:
* Item
- Subitem
But, I can't figure out how to do this with the API. A CreateParagraphBulletRequest doesn't have an indent level I can specify. The documentation suggests:
The nesting level of each paragraph will be determined by counting leading tabs in front of each paragraph. To avoid excess space between the bullet and the corresponding paragraph, these leading tabs are removed by this request. This may change the indices of parts of the text.
However, prepending tabs to the beginning of an InsertTextRequest will prepend the tab character, rather than changing the indent:
* Item
* Subitem
Does anyone have any ideas for what I may be doing wrong?
I believe your goal as follows.
You want to create a nested list using Google Docs API.
At first, a list, which has one item as 1st level, is existing in the Google Document. It's as follows.
- item1
Under this situation, you want to insert a nested item to the existing list as 2nd level. It's as follows.
- item1
- item2
Points for achieving your goal:
In this case, in order to insert the item to the existing list as the 2nd level, in my experience, I couldn't directly insert it. In my case, as a workaround, I'm using the following flow.
Insert a text \n\titem2\n for 2nd level using insertText request.
In this case, the 1st level is also inserted. It seems that in order to insert the deep level items, it is required to set from the 1st level and convert to the list with the bullets.
Using createParagraphBullets, it gives the bullets to the list. By this, \t is converted to the nested items.
Remove the bullet of the 1st level.
Remove the line break.
Sample request body:
When above flow is reflected to the request body of the method of batchUpdate in Docs API, it becomes as follows.
{
"requests": [
{
"insertText": {
"text": "\n\titem2\n",
"location": {
"index": 7
}
}
},
{
"createParagraphBullets": {
"range": {
"startIndex": 1,
"endIndex": 15
},
"bulletPreset": "BULLET_DISC_CIRCLE_SQUARE"
}
},
{
"deleteParagraphBullets": {
"range": {
"startIndex": 7,
"endIndex": 8
}
}
},
{
"deleteContentRange": {
"range": {
"startIndex": 7,
"endIndex": 8
}
}
}
]
}
Result:
When above request body is used, the following result is obtained.
Before:
After:
Note:
Although I had looked for other methods for using Docs API without changing the existing list, unfortunately, I cannot still find them. I thought that in order to insert the deep nested items to the existing list, in the current stage, the items might be required to be given from 1st level using \t. Unfortunately, I'm not sure whether this is the specification. So, for example, how about requesting this for the issue tracker as the future request? Ref
References:
Working with lists
documents.batchUpdate

How can I get the FULL list of slack emoji through API?

I am using the slack API to get the full list of emoji, so that when I get a message, I will just replace :squirrel: with the icon.
The method https://slack.com/api/emoji.list works like a charm, but returns 30 icons only. I think this is correct since in the documentation page (https://api.slack.com/methods/emoji.list) they say:
This method lists the custom emoji for a team.
Fair enough, but how can I get the full list of the associations icon-name / icon URL ?
I finally managed to get all the icons and to use them and I post here the solution for anyone that would like to use do similar:
First of all, I got the Slack Custom Emoji through this slack URL
Since at step 1 we get only Custom Emojis, it is useful to know that slack uses standard emoji defined in unicode characters, mapped through custom handles like :smiley: or :horse:. The good thing is that we can find, linked through slack page a link to a JSON object with all the emoji mappings. This file is HUGE, but has everything we need.
In the file you'll find an array of javascript object like the one below:
{
"name":"SMILING FACE WITH OPEN MOUTH",
"unified":"1F603",
"variations":[],
"docomo":"E6F0",
"au":"E471",
"softbank":"E057",
"google":"FE330",
"image":"1f603.png",
"sheet_x":26,
"sheet_y":18,"
short_name":"smiley",
"short_names":["smiley"],
"text":":)",
"texts":["=)","=-)"],
"category":"People",
"sort_order":5,
"has_img_apple":true,
"has_img_google":true,
"has_img_twitter":true,
"has_img_emojione":true
}
I used the following information:
shortnames are the names that are used in slack (you'll need to turn smiley into :smiley: )
unified is the unicode character to use (to use it directly in an HTML page you'll need to add &#x so in this case you'll have to use 😃 which is rendered 😃
Using this information you will be able to create a slack-to-html function to decode emojis and display them wherever you want
Not entirely sure if this is what you are looking for, but if it's just about mapping images to slack-style names, this is a pretty good library:
https://github.com/iamcal/emoji-data
So, building on the example in their README:
The emoji with the Slack style short name point_uphas the hex value 261d, and can thus be found here: https://github.com/iamcal/emoji-data/blob/master/img-apple-160/261d.png
(Apple, because the default slack emoji are the apple emoji)
Just extending on #Luca's awesome solution, I've created a shortnames => html unicode javascript dictionary...
Download: Slack emoticons to unicode html mapping.
Generated - 17th August 2018 from the source https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json
Example:
{
"+1": "👍",
"-1": "👎",
"100": "💯",
"1234": "🔢",
"8ball": "🎱",
"ab": "🆎",
"abc": "🔤",
"abcd": "🔡",
"accept": "🉑",
...
"zebra_face": "🦓",
"zipper_mouth_face": "🤐",
"zombie": "🧟",
"zzz": "💤"
}
Which becomes...
{ "+1": "👍", "-1": "👎", "100": "💯",
"1234": "🔢", "8ball": "🎱", "ab": "🆎",
"abc": "🔤", "abcd": "🔡", "accept": "🉑",
... "zebra_face": "🦓", "zipper_mouth_face": "🤐",
"zombie": "🧟", "zzz": "💤" }
As far as I know, there is no API endpoint or comprehensive list of supported emoji/keywords available. I was able to grab the full set (including custom emoji for the workspace) by inspecting the Slack emoji picker using React Developer Tools (Chrome extension).
Here's an example (JSON):
...
{
"name": "beers",
"unicode": "1f37b",
"id": "E1f37b",
"keywords": ["bar", "beer", "clink", "drink", "mug", "ale", "food"]
},
{
"name": "baby_bottle",
"unicode": "1f37c",
"id": "E1f37c",
"keywords": ["baby", "bottle", "drink", "milk", "infant"]
},
{
"name": "knife_fork_plate",
"unicode": "1f37d-fe0f",
"id": "E1f37d-fe0f",
"keywords": ["cooking", "fork", "knife", "plate"]
},
{
"name": "champagne",
"unicode": "1f37e",
"id": "E1f37e",
"keywords": ["bar", "bottle", "cork", "drink", "popping"]
},
{ "name": "popcorn", "unicode": "1f37f", "id": "E1f37f", "keywords": [] },
...
Full dump (as of 12/20/2020, excluding custom emoji): https://gist.github.com/impressiver/87b5b9682d935efba8936898fbfe1919
Since it seemed impossible to find a complete and up-to-date source for these emoji names I came up with this browser console script. Just let it run in Slack and when it finishes it will download a full emoji.json. At time of writing it contains 2485 entries.
https://gist.github.com/8461e125072c2806301403a4e1eca891
This looks like this:
{
"+1": "https://a.slack-edge.com/production-standard-emoji-assets/13.0/google-medium/1f44d#2x.png",
"+1::skin-tone-2": "https://a.slack-edge.com/production-standard-emoji-assets/13.0/google-medium/1f44d-1f3fb#2x.png",
"+1::skin-tone-3": "https://a.slack-edge.com/production-standard-emoji-assets/13.0/google-medium/1f44d-1f3fc#2x.png",
"+1::skin-tone-4": "https://a.slack-edge.com/production-standard-emoji-assets/13.0/google-medium/1f44d-1f3fd#2x.png",
If you want the actual emoji instead of the image you can parse that out of the image file name, e.g. 1f44d-1f3fd#2x.png is "\u1f44d\u1f3fd".

How to iterate over this Json data in rails?

I'm trying to Iterate over this Json data I want to get the Items out of "data I tried doing
#Response =HTTParty.get(("http://ddragon.leagueoflegends.com/cdn/5.15.1/data/en_US/item.json"))
puts #Response["data"].each do |item|
puts item
end
Also I want to be able to iterate them without having to know the IDS prior for example the first item is "1001" I don't want to have to enter those manually
but this just says that it can't find anything with '[]' for Nil:NilClass
Also before anyone mentions the JSON below doesn't finish because I only took a sample there are a lot more Items and if I were to paste it , it would easily be over 1000 Lines.
"type":"item",
"version":"5.15.1",
"basic":{},
"data":{
"1001":{
"name":"Boots of Speed",
"group":"BootsNormal",
"description":"<groupLimit>Limited to 1.</groupLimit><br><br> <unique>UNIQUE Passive - Enhanced Movement:</unique> +25 Movement Speed<br><br> <i>(Unique Passives with the same name don't stack.)</i>",
"colloq":";",
"plaintext":"Slightly increases Movement Speed",
"into":[
"3006",
"3047",
"3020",
"3158",
"3111",
"3117",
"3009"
],
"image":{
"full":"1001.png",
"sprite":"item0.png",
"group":"item",
"x":0,
"y":0,
"w":48,
"h":48
},
"gold":{
"base":325,
"purchasable":true,
"total":325,
"sell":227
},
"tags":[
"Boots"
],
"stats":{
"FlatMovementSpeedMod":25.0
}
},
"1004":{
"name":"Faerie Charm",
"description":"<stats><mana>+25% Base Mana Regen </mana></stats>",
"colloq":";",
"plaintext":"Slightly increases Mana Regen",
"into":[
"3028",
"3070",
"3073",
"3114"
],
"image":{
"full":"1004.png",
"sprite":"item0.png",
"group":"item",
"x":48,
"y":0,
"w":48,
"h":48
},
"gold":{
"base":180,
"purchasable":true,
"total":180,
"sell":126
},
"tags":[
"ManaRegen"
],
"stats":{
}
},
Four problems:
you are not parsing the response body with JSON.parse
you are using a constant name (starting with capital letter) as a variable name (#Response), you shouldn't.
unnecessary puts on iteration.
The value of data is not an array, but rather another hash. So you should iterate over it as key/value pairs.
Solution:
#response = JSON.parse(HTTParty.get(your_url).body)
#response["data"].each do |key, value|
puts key
puts value
end
I had done something like this before, maybe that can help you here is the link - Reading Json using Ruby

Dust.js - iterate through an iterated anonymous array

I have this data structure in dust:
{ 'items' : [
[ 'apples', "$1.00" , "Delicious" ],
[ 'oranges', "$2.00" , "Juicy" ],
]
}
I'm trying to access the inner items, and can't figure out how.
I can address the entire array of the current loop via {.} , but i can't seem to access the items within it. ( I could do this in Mustache )
I was expecting something like this to work...
{#items}
<b>{.[0]}</b> <em>only {.[1]}!</em>
<p>{.[2]}</p>
{/items}
When I ran your example in the dust playground: http://linkedin.github.io/dustjs/test/test.html
the output I got was:
<b>apples</b> <em>only $1.00!</em><p>Delicious</p><b>oranges</b> <em>only $2.00!</em><p>Juicy</p>
This looks to be what you were expecting. I believe fixes in this area after your post likely made this work. Grab the latest version of dust.

Resources