Angular ng-options using object - object

Can anyone help me, how to show 'name' in ng-options for following structure.
"systems": {
"android": {
"name": "Android"
},
"ios": {
"name": "iOS"
},
"web": {
"name": "Web"
}
},

For structure:
$scope.systems = {
"android": {
"name": "Android"
},
"ios": {
"name": "iOS"
},
"web": {
"name": "Web"
}
};
you can do it like this:
<select ng-model='system' ng-options='key.name as value.name for (key, value) in systems'></select>
Selected Value = {{system}}
If you have to have this structure:
$scope.systems =
{
"systems": {
"android": {
"name": "Android"
},
"ios": {
"name": "iOS"
},
"web": {
"name": "Web"
}
};
then I would do it with ng-repeat (I don't see the other way):
<select ng-model='system' ng-repeat='(key, values) in systems'>
<option ng-repeat='(k,v) in values' ng-bind='v.name'></option>
</select>
Selected Value = {{system}}
I hope it helps :)

Related

Elasticsearch NodeJs putIndexTemplate API

I'm using elasticsearch 7.13.3 and I want to call the put index template API from my typescript app. I'm using the package "#elastic/elasticsearch": "7.13.0" but I get error for the composition of the call.
From kibana I can execute without any error:
PUT _component_template/template-xxx2
{
"template": {
"mappings": {
"properties": {
"#timestamp": {
"type": "date"
},
"id": {
"type": "keyword"
},
"value": {
"type": "double",
"coerce": false
}
}
}
}
}
PUT _index_template/index-template-xxx2
{
"index_patterns": ["template-xxx2*"],
"template": {
"settings": {
"number_of_shards": 2
},
"mappings": {
"_source": {
"enabled": true
},
"properties": {
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z yyyy"
}
}
},
"aliases": {
"mydata": { }
}
},
"priority": 600,
"composed_of": ["template-xxx2"],
"version": 3,
"_meta": {
"description": "template-xxx2 description"
}
}
and I want do the same from my node app.
The template creation it's ok:
void this.db.clientDb.indices.putTemplate({
name: `template_${this.index}`,
body: {
mappings: {
properties: {
'#timestamp': {
type: 'date'
},
id: {
type: 'keyword'
},
value: {
type: 'double',
coerce: false
}
}
}
}
});
But I can't find the correct overload for the this.db.clientDb.indices.putIndexTemplate({ API.
This gave me errors: (no overloads match this call)
void this.db.clientDb.indices.putIndexTemplate({
name: '',
index_patterns: ["template-xxx2*"], // --> where should I put this property?
body: {
settings: {
number_of_shards: 2
},
mappings: {
_source: {
enabled: true
}
},
aliases: {
mydata: {}
}
},
priority: 500,
composed_of: ['template-xxx2'], // --> where should I put this property?
version: 3,
_meta: {
description: 'template-xxx2 description'
}
});
I want to do this latest script.
Index templates have been overhauled in 7.8. The previous legacy endpoint was called _template and the new one is called _index_template.
You're mixing calls to the old and the new endpoint, i.e. putTemplate calls the old legacy endpoint and putIndexTemplate calls the new one.
Moreover, the whole template definition needs to go inside body, not at the top level of the call parameters.
So here is what you need to do. First, make this call to store the component template:
void this.db.clientDb.cluster.putComponentTemplate({
"name": "template-xxx2",
"body": {
"template": {
"mappings": {
"properties": {
"#timestamp": {
"type": "date"
},
"id": {
"type": "keyword"
},
"value": {
"type": "double",
"coerce": false
}
}
}
}
}
})
Then store the index template with the following call:
void this.db.clientDb.indices.putIndexTemplate({
"name": "index-template-xxx2",
"body": {
"index_patterns": ["template-xxx2*"],
"template": {
"settings": {
"number_of_shards": 2
},
"mappings": {
"_source": {
"enabled": true
},
"properties": {
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z yyyy"
}
}
},
"aliases": {
"mydata": { }
}
},
"priority": 600,
"composed_of": ["template-xxx2"],
"version": 3,
"_meta": {
"description": "template-xxx2 description"
}
}
})

Replace JSON node values with one of their specific child node value - node JS [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have this JSON object, and I would like to replace all 'title' and 'description' objects with
title.es and description.es child values, somehow like this: item.title = item.title.es
Could you help me to find the correct recursive algorithm?
I tried to use recursive functions, but didn't worked.
[
{
"name": "aaa",
"title": {
"es": "dfghfdghgfhgfh",
"en": "hjklhjkljkhljkhlklj"
},
"services": [
{
"name": "aaa-1",
"title": {
"es": "dfgdfgsdfg",
"en": "dfghfgdhgfhgfhgf"
},
"services": [
{
"name": "aaa-1-1",
"title": {
"es": "dfghgfhfghgfdh",
"en": "dfghfgdhfgdhgfdh"
}
"description": {
"es": "sdfgfdsgfdg",
"en": "sertztrezrteztre"
}
}
]
},
{
"name": "aaa-2",
"title": {
"es": "ertzrtez",
"en": "ertuztzutzuztuzt"
}
},
]
},
{
"name": "bbb",
"title": {
"es": "sdfsdfdsf",
"en": "sdfsdfdsfdsfdsf"
},
"services": [
{
"name": "bbb-1",
"title": {
"es": "sdfsdfdsfdsf",
"en": "sdfdsfdsfds"
},
"services": [
{
"name": "bbb-1-1",
"title": {
"es": "werwerewrewr",
"en": "werwerwerwerew"
}
},
{
"name": "bbb-1-2",
"title": {
"es": "werewrewrwerewr",
"en": "werewrewrewrwerwerwerwerewr"
}
}
]
}
]
}
]
This should do the trick for recursive function:
function iter(o) {
Object.keys(o).forEach((k) => {
console.log(k);
if (k === 'title' || k === 'description') {
console.log(o[k]);
o[k] = o[k].en;
return;
}
if (o[k] !== null && typeof o[k] === 'object') {
iter(o[k]);
}
});
}
iter(obj);
This is a modified version of: another SO answer :)

TypeScript: Parsing XML to JSON in node loses the order of same name-tags

I have tried using xml2js and fast-xml-parser and get pretty same result from both (although in different formats, but that is not the point here)
This example is from fast-xml-parser
I have this XML:
<test version="1">
<case tm-reference="reference-to-test-management-test id">
<description>Test description ..</description>
<steps>
<platform type="appium" navigate-to="x in list-of-values">
<expect fan="AUTO"/>
</platform>
<tstat id="">
<set mode="HEAT" fan="AUTO" RT="70F" SP="70F"/>
</tstat>
<!-- value in milliseconds -->
<wait for="500"/>
<platform type="appium">
<expect fan="AUTO"/>
</platform>
<!-- value in milliseconds -->
<wait for="500"/>
<tstat>
<set mode="HEAT" fan="AUTO" RT="70F" SP="70F"/>
<wait for="500"/>
<expect led-g="ON" led-y="ON"/>
<wait for="500"/>
<expect led-g="ON" led-y="ON"/>
</tstat>
</steps>
</case>
</test>
parsing it like this:
import parser from "fast-xml-parser"
const result = parser.parse(this.xml, { parseAttributeValue: true, ignoreAttributes: false, allowBooleanAttributes: true, attributeNamePrefix: "" })
console.log(JSON.stringify(result, null, 2));
doing this result in this:
{
"test": {
"version": 1,
"case": {
"tm-reference": "some reference ID",
"description": "Test description ..",
"steps": {
"platform": [
{
"type": "appium",
"navigate-to": "x in list-of-values",
"expect": {
"fan": "AUTO"
}
},
{
"type": "appium",
"expect": {
"fan": "AUTO"
}
}
],
"tstat": [
{
"id": "",
"set": {
"mode": "HEAT",
"fan": "AUTO",
"RT": "70F",
"SP": "70F"
}
},
{
"set": {
"mode": "HEAT",
"fan": "AUTO",
"RT": "70F",
"SP": "70F"
},
"wait": [
{
"for": 500
},
{
"for": 500
}
],
"expect": [
{
"led-g": "ON",
"led-y": "ON"
},
{
"led-g": "ON",
"led-y": "ON"
}
]
}
],
"wait": [
{
"for": 500
},
{
"for": 500
}
]
}
}
}
}
Notice how the repeated tags for example platform, tstat and wait have been combined together into an array and lost the order of actual their placements in xml file. I am looking for a way to actually preserve the order and repetition of tags.
somehow I get the array of steps(objects) with each tag's information in the same order as in xml file
EDIT: Adding expected output
I'm expecting if not exactly but something similar where order is preserved for each tag
{
"test": {
"version": 1,
"children": [
{
"case": {
"tm-reference": "some reference ID",
"description": "Test description ..",
"steps": {
"children": [
{
"platform": {
"type": "appium",
"navigate-to": "x in list-of-values",
"children": [
{
"expect": {
"fan": "AUTO"
}
}
]
}
},
{
"tstat": {
"id": "",
"children": [
{
"set": {
"mode": "HEAT",
"fan": "AUTO",
"RT": "70F",
"SP": "70F"
}
}
]
}
},
{
"wait": {
"for": 500,
"children": []
}
},
{
"platform": {
"type": "appium",
"children": [
{
"expect": {
"fan": "AUTO"
}
}
]
}
},
{
"wait": {
"for": 500,
"children": []
}
},
{
"tstat": {
"children": [
{
"set": {
"mode": "HEAT",
"fan": "AUTO",
"RT": "70F",
"SP": "70F"
}
},
{
"wait": {
"for": 500
}
},
{
"expect": {
"led-g": "ON",
"led-y": "ON"
}
},
{
"wait": {
"for": 500
}
},
{
"expect": {
"led-g": "ON",
"led-y": "ON"
}
}
]
}
}
]
}
}
}
]
}
}
EDIT 2:
Created an issue on GitHub repo, follow here
You want your steps element's content to be represented in JSON as an array, not an object, because JavaScript object properties are unordered and may not repeat names.
In fast-xml-parser, you may be able to achieve this via the arrayMode option:
arrayMode : When false, a tag with single occurrence is parsed as an object but as an array in case of multiple occurences. When
true, a tag will be parsed as an array always excluding leaf nodes.
When strict, all the tags will be parsed as array only. When
instance of RegEx, only tags will be parsed as array that match the
regex. When function a tag name is passed to the callback that can
be checked.

"commands" (shortcuts): is it possible to sort them for `chrome://extensions/shortcuts`?

In my manifest.json I have:
"commands": {
"add": {
"suggested_key": {
"default": "MacCtrl+Shift+A"
},
"description": "__MSG_addToFeed__"
},
"playPause": {
"suggested_key": {
"default": "Alt+P"
},
"description": "__MSG_playPause__"
},
"nextArticle": {
"description": "__MSG_nextArticle__"
},
"nextChunk": {
"suggested_key": {
"default": "Alt+N"
},
"description": "__MSG_nextChunk__"
},
"prevArticle": {
"suggested_key": {
"default": "Alt+B"
},
"description": "__MSG_prevArticle__"
}
}
This is what I get on chrome://extensions/shortcuts
I do not understand how they are sorted - neither by title nor by shortcut. And looks like no way to change that order.
Documentation links:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands
https://developer.chrome.com/extensions/commands
Related source code of Chromium: https://github.com/chromium/chromium/blob/2ca8c5037021c9d2ecc00b787d58a31ed8fc8bcb/chrome/browser/resources/md_extensions/keyboard_shortcuts.js
Add numbers to your commands object as they are sorted by their keys.
"commands": {
"1_add": { ... },
"2_playPause": { ... },
"3_nextArticle": { ... },
"4_nextChunk": { ... },
"5_prevArticle": { ... }
}

Symfony2 composer adding own bundle requirement

How can I install a specific Bundle (for example SonataGoutteBundle) to my Symfony2 project via composer?
I tried this, but it doesn't work for me. Any ideas what's wrong?
"repositories": [
{
"type": "package",
"package": {
"name": "sonata-project/sonatagouttebundle",
"version": "dev-master",
"dist": {
"url": "https://github.com/sonata-project/SonataGoutteBundle.git",
"type": "git"
}
}
}
],
"require": {
"php": ">=5.3.3",
[...],
"sonata-project/sonatagouttebundle": "dev-master"
}
Try something like
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/sonata-project/SonataGoutteBundle.git"
}
],
"require": {
"php": ">=5.3.3",
"vendor/bundle": "dev-master"
}
}
The SonataGoutteBundle must have a composer.json
In this particular case, this would work:
"repositories": [
{
"type": "package",
"package": {
"name": "sonata-project/goutte",
"version": "dev-master",
"source": {
"url": "https://github.com/sonata-project/SonataGoutteBundle.git",
"type": "git",
"reference": "master"
}
}
}
],
"require": {
"php": ">=5.3.3",
"sonata-project/goutte": "dev-master"
}
For all options see the documentation
You should provide a link to an archive (like zip) in "dist" section. If you want to use git you should define "source" section instead:
{
"repositories": [
{
"type": "package",
"package": {
"name": "sonata-project/sonatagouttebundle",
"version": "dev-master",
"source": {
"url": "https://github.com/sonata-project/SonataGoutteBundle.git",
"type": "git",
"reference": "master"
}
}
}
],
"require": {
"php": ">=5.3.3",
"sonata-project/sonatagouttebundle": "dev-master"
}
}
More about defining custom repositories: http://getcomposer.org/doc/04-schema.md#repositories

Resources