Get object by key in angularfire2 version 5 - angularfire2

"items": {
"a" : {
"size" : "small",
"text" : "small thing"
},
"b" : {
"size" : "medium",
"text" : "medium sample"
},
"c" : {
"size" : "large",
"text" : "large widget"
}
}
Suppose, I have data as above. I want to get data of key a from items list in component file without iterating over whole list. I tried from the docs. But could not find this kind of requirement. Solutions on this platform are related to previous versions before 5.0. Does anyone know how can we achieve it?

I suppose you are referring to Real Time DB because you mentioned "items list", where in FireStore it is collection.
To get an object, use the AngularFireDatabase.object() function.
Examples:
// Get an object, just the data (valuesChanges function), only once (take(1) function)
import 'rxjs/add/operator/take';
let subscribe = AngularFireDatabase.object('items/a').valueChanges().take(1).subscribe(
data =>{
console.log(data);
}
);
Another way is to call the subscrible.unsubscribe() function inside the subscrible return instead of using the take() function:
let subscribe = AngularFireDatabase.object('items/a').valueChanges().subscribe(
data =>{
console.log(data);
subscribe.unsubscribe();
}
);
The above example get the data at the time of execution, not getting changes that occur with the object after that.
// Get an object, just the data (valuesChanges function), and all subsequent changes
let subscribe = AngularFireDatabase.object('items/a').valueChanges().subscribe(
data =>{
console.log(data);
}
);
The above example get the data every time there are changes in the object.
I have tested both examples.
You can read about AnglarFire2 version 5, here and here.
You can read about retrieve data from objects here.

Related

Adaptive Cards Templating in MS Teams

I can't seem to get this to work. If I send the following adaptive card payload to MS Teams:
{
"$schema" : "http://adaptivecards.io/schemas/adaptive-card.json",
"version" : "1.3",
"type" : "AdaptiveCard",
"body" : [ {
"type" : "Container",
"style" : "emphasis",
"items" : [ {
"type" : "Input.Text",
"value" : "${form.name}",
"id" : "name",
"label" : "Name"
} ]
} ],
"$data" : {
"form" : {
"name" : "geoff hurst"
},
}
}
I get a response in Teams like this:
I would have thought that the template should be expanded on the client-side, but this doesn't seem to happen. Have I misunderstood?
So in simple terms, Teams doesn't have an ability to render templates (basically that would mean taking the card template and the data payload and combining them together) - it can only accept the final version of the card.
As a result, if you're wanting to use templates, then you need to implement the data + template capability your side, to send the final card payload down to Teams. See here for examples on how to do this in js or dotnet. Truth be told, if you're in js (e.g. Node), Templating is not much more than string replacement, and if you're in dotnet (e.g. C#) there's a strongly-typed Adaptive Card library you might want to rather use anyway, in which case you're combining the "template" and the "data" already inside your code.
I think probably the best use of templating would be if you're receiving a template from some kind of "template repository", but I don't think there's really practically any such thing yet for Teams.
The method you are trying to use will not allow you to use dynamic data, I prefer you use data as a separate object and use Templating SDKs.
Please have a look at this sample on how to use template :
var templateJSON = File.ReadAllText(Path.Combine(".", "CardPath"));
AdaptiveCardTemplate template = new AdaptiveCardTemplate(templateJSON);
var memberData = new
{
userName = member.Name,
userUPN = member.UserPrincipalName,
userAAD = member.AadObjectId
};
string cardJSON = template.Expand(memberData);
var adaptiveCardAttachment = new Attachment
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(cardJSON),
};
await turnContext.SendActivityAsync(MessageFactory.Attachment(adaptiveCardAttachment), cancellationToken);
In the above snippet as you can see, we need to create a model having the fields that we are using in the card.
In your case you need to create a object having the property as form -> name
var formData = new
{
form = new
{
name = "Testing"
}
};
after that use the expand method and the rest code would be same.

How to convert json to collection in power apps

I have a power app that using the flow from power automate.
My flow is doing an HTTP get and respond a JSON to power apps like below.
Here is the JSON as text:
{"value": "[{\"dataAreaId\":\"mv\",\"AccountNum\":\"100000\",\"Name\":\"*****L FOOD AB\"},{\"dataAreaId\":\"mv\",\"AccountNum\":\"100001\",\"Name\":\"**** AB\"},{\"dataAreaId\":\"mv\",\"AccountNum\":\"100014\",\"Name\":\"****(SEB)\"},{\"dataAreaId\":\"mv\",\"AccountNum\":\"100021\",\"Name\":\"**** AB\"},{\"dataAreaId\":\"mv\",\"AccountNum\":\"100029\",\"Name\":\"**** AB\"},{\"dataAreaId\":\"mv\",\"AccountNum\":\"500100\",\"Name\":\"**** AB\"},{\"dataAreaId\":\"mv\",\"AccountNum\":\"500210\",\"Name\":\"****\"}]"}
But when I try to convert this JSON to the collection, It doesn't behave like a list.
It just seems like a text. Here is how I try to bind the list.
How can I create a collection from JSON to bind to the gallery view?
I found the solution. I finally create a collection from the response of flow.
The flow's name is GetVendor.
The response of flow is like this :
{"value": "[{\"dataAreaId\":\"mv\",\"AccountNum\":\"100000\",\"Name\":\"*****L FOOD AB\"},{\"dataAreaId\":\"mv\",\"AccountNum\":\"100001\",\"Name\":\"**** AB\"},{\"dataAreaId\":\"mv\",\"AccountNum\":\"100014\",\"Name\":\"****(SEB)\"},{\"dataAreaId\":\"mv\",\"AccountNum\":\"100021\",\"Name\":\"**** AB\"},{\"dataAreaId\":\"mv\",\"AccountNum\":\"100029\",\"Name\":\"**** AB\"},{\"dataAreaId\":\"mv\",\"AccountNum\":\"500100\",\"Name\":\"**** AB\"},{\"dataAreaId\":\"mv\",\"AccountNum\":\"500210\",\"Name\":\"****\"}]"}
Below code creates a list from this response :
ClearCollect(_vendorData, MatchAll(GetVendors.Run(_token.value).value, "\{""dataAreaId"":""(?<dataAreaId>[^""]*)"",""AccountNum"":""(?<AccountNum>[^""]*)"",""Name"":""(?<Name>[^""]*)""\}"));
And I could bind the accountnum and name from _vendorDatra collection to the gallery view
In my case I had the same issue as you, but couldn't manage to get data into _vendorData collection, because MatchAll regex part was not working correctly, even if I had exactly the same scenario and I could not make it work.
My solution was to modify the flow itself, where I returned Response instead of Respond to a Power app or Flow, so basically I could return full request from Http.
This caused me some issues also, because when I generated schema from sample I could not register the flow to the powerapp with the error Failed during http send request.
The solution was to manually review the response schema and change all column types to one of the following three, because other are not supported: string, integer or boolean. Object and array can be set only on top level items, but never on children, so if you have anything else than my mentioned three, replace it to string. And no property can be left with undefined type.
Basically I like this solution even more, because in powerapps itself you do not need to do any conversion or anything - simply use the data as is, because it is already recognized as collection in case of array and you have all the properties already named for you.
Response step schema example is below.
{
"type": "object",
"properties": {
"PropertyOne": {
"type": "string"
},
"PropertyTwo": {
"type": "integer"
},
"PropertyThree": {
"type": "boolean"
},
"PropertyFour": {
"type": "array",
"items": {
"type": "object",
"properties": {
"PropertyArray1": {
"type": "string"
},
"PropertyArray1": {
"type": "integer"
},
"PropertyArray1": {
"type": "boolean"
}
}
}
It is easy now.
Power Apps introduced ParseJSON function which helps converting string to collection easily.
Table(ParseJSON(JSONString));
In gallery, map columns like - ThisItem.Value.ColumnName

GraphQL: Explore API without a wildcard (*)?

I am new to GraphQL and I wonder how I can explore an API without a possible wildcard (*) (https://github.com/graphql/graphql-spec/issues/127).
I am currently setting up a headless Craft CMS with GraphQL and I don't really know how my data is nested.
Event with the REST API I have no chance of just getting all the data, because I have to setup all the endpoints and therefore I have to know all field names as well.
So how could I easily explore my CraftCMS data structure?
Thanks for any hints on this.
Cheers
merc
------ Edit -------
If I use #simonpedro s suggestion:
{
__schema {
types {
name
kind
fields {
name
}
}
}
}
I can see a lot of types (?)/fields (?)...
For example I see:
{
"name": "FlexibleContentTeaser",
"kind": "OBJECT",
"fields": [
{
"name": "id"
},
{
"name": "enabled"
},
{
"name": "teaserTitle"
},
{
"name": "text"
},
{
"name": "teaserLink"
},
{
"name": "teaserLinkConnection"
}
]
But now I would like to know how a teaserLink ist structured.
I somehow found out that the teaserLink (it is a field with the type Entries, where I can link to another page) has the properties url & title.
But how would I set up query to explore the properties available within teaserLink?
I tried all sorts of queries, but I am always confrontend with messages like this:
I would be really glad if somebody could give me another pointer how I can find out which properties I can actually query...
Thank you
As far as I'm concerned currently there is no graphql implementation with that capability. However, if what you want to do is to explore the "data structure", i.e, the schema, you should use schema instrospection, which was thought for that (explore the graphql schema). For example, a simple graphql instrospection query would be like this:
{
__schema {
types {
name
kind
fields {
name
}
}
}
}
References:
- https://graphql.org/learn/introspection/
UPDATE for edit:
What you want to do I think is the following:
Make a query like this
{
__schema {
types {
name
kind
fields {
name
type {
fields {
name
}
}
}
}
}
}
And then find the wished type field to grab more information (the fields) from it. Something like this (I don't know if this works, just an idea):
const typeFlexibleContentTeaser = data.__schema.types.find(t => t === "FlexibleContentTeaser")
const teaserLinkField = typeFlexibleContentTeaser.fields.find(f => f.name === "teaserLink")
const teaserLinkField = teaserLinkField.type.fields;
i.e, you have to transverse recursively through the type field.

Spring Data Elasticseach: How to create Completion object with multiple weights?

I have managed to build a working autocomplete service using Elasticsearch with Spring Boot, but I can't assign different weights for my autocomplete sentences.
While I am building the Completion object (org.springframework.data.elasticsearch.core.completion.Completion) I am using the standard constructor and next, I am assigning the weight to the object, for example (I am using Kotlin)
val completion = Completion(arrayOf("Sentence one", "Second sentence"))
completion.weight = 10
(...)
myEntity.suggest = completion
what produces the following JSON for Elasticsearch
{
"suggest" : {
"input": [ "Sentence one", "Second sentence" ],
"weight" : 10
}
}
But, according to the Elasticsearch documentation (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html) I would like to achieve something like this
{
"suggest" : [
{
"input": "Sentence one",
"weight" : 10
},
{
"input": "Second sentence",
"weight" : 5
}
]
}
Is it possible with spring-data-elasticsearch? If yes, how can I do this?
No, at the moment the second case is currently not supported by Spring Data Elasticsearch.
Both JSON you show are valid, the first one is for multiple inputs that all have the same weight, the second one is for multiple inputs, when ich input has a different weight.
Please file an issue in Spring Data Elasticsearch Jira to add support for the Completion object to support this case.

Why does the first firebase call for real time database take too much time after first response it works much faster

I am using firebase real-time database in my application, but I am facing one weird issue. The first firebase call takes too much time after first response the works much faster.
Database.database().reference().child(FireBaseTable.bpmTable).child(firebaseKey).queryOrdered(byChild: "timestamp").observeSingleEvent(of: .value, with: { (snapshot) in
print("Initial load done2")
})
After first response, same code with diff/same key gives much faster response.
A solution could be to index data in your rules: https://firebase.google.com/docs/database/security/indexing-data
{
"lambeosaurus": {
"height" : 2.1,
"length" : 12.5,
"weight": 5000
},
"stegosaurus": {
"height" : 4,
"length" : 9,
"weight" : 2500
}
}
Index can be set like this:
{
"rules": {
"dinosaurs": {
".indexOn": ["height", "length"]
}
}
}
"Firebase allows you to do ad-hoc queries on your data using an
arbitrary child key. If you know in advance what your indexes will be,
you can define them via the .indexOn rule in your Firebase Realtime
Database Rules to improve query performance."

Resources