SAPUI 5 - Aggregated control with two data models - sapui5

I have a generic tile control that the tile get created base on number of entity available (e.g.: SCARRSet), which is normal. Then in the nested Tile content i need to show the airline logo where the image path is stored in a JSON file. My idea is to use the key in SCARRSet/Carrid to lookup the JSON file to find the image path. So the right image will be displayed for the airline.
Previously i put the image path in Url field which was fine, but that field was meant for something else. Now i want to do it properly.
<l:HorizontalLayout id="hLayout1" allowWrapping="true" content="{flight>/SCARRSet}">
<GenericTile class="sapUiTinyMarginBegin sapUiTinyMarginTop tileLayout"
header="{flight>Carrname}"
subheader="{flight>Carrid}"
press="onTilePressed"
backgroundImage="">
<TileContent unit="{flight>Currcode}" footer="">
<ImageContent src="{flight>Url}" />
</TileContent>
</GenericTile>
</l:HorizontalLayout>
The JSON file looks like following. Is there a way to iterate through each tile to lookup Key = SCARRSet/Carrid then populate imageContent src=(e.g.:"/image/AA.gif")?
{
"icon": [
{
"Key" : "AA",
"Path" : "/image/AA.gif"
},
...
]
}

I would use a formatter function to do the lookup:
src="{formatter: '.formatter.getIconUrl', path: 'flight>Carrid'}"
In the formatter getIconUrl you get the Carrid as input parameter.
For performance reasons I would also suggest to reformat the JSON once to have a hash access to the url: jsonData[carrid] returns the url.

Related

Creating a custom refinementList component based on two facets - Algolia

Let’s suppose we have these two facets:
“manufacturer.url”: [“/url1”, “/url2”, “/url3”]
AND
“manufacturer.name”: [“manufacturer1”, “manufacturer2”, “manufacturer3”];
I’d like to create a custom refinmentList component which show all available facets for my hits based on manufacturers.
I used connectRefinementList(MyCustomComponent); and I set manufactuer.url to attribute property.
<CustomManufacturerFilterRefinementList
attribute="manufacturer.url"
currentCategory={currentCategory}
limit={10}
locale={locale}
showMore={showMore}
searchable={searchable}
showMoreLimit={showMoreLimit}
translations={translations}
/>
Now users can see available manufacturers and can filter them or click on them to go to the manufacturer page, but since I fetch the manufacturer.url, I could only able to show the URL in the list, but I’d like to show manufacture’s name in the list and having URL to generate links.
Problem: how can I create a custom refinementList component which fetches data from two facets at the same time and combine them to generate a list of links?
PS: I tried to use searchForFacetValues function inside my custom component to retrvie manufacturer’s name with below query but I couldn’t map each url with name because there is no logical relation between them:
{
"requests": [
{
"indexName": "stg_lots",
"params": {
"facetName": [
"manufacturer.name"
],
"filters": "manufacturer.url:\"froemag\" OR manufacturer.url:\"volvo\" OR manufacturer.url:\"fendt\" ",
"maxFacetHits": 100
}
}
]
}
Thanks

Conversion from XML to Json removes 0 in Azure Data Factory

I am converting XML files to Json(gzip compression) using Azure Data Factory.
However , I observe that in the XML file I have the values stored as 0123456789. However , when this is converted to Json it is saved as "value" : 123456789. Without 0.
I would like to keep the Json values as-is from the XML . Please provide suggestions for the same.
I recently found using data flow will solve the problem.
I created a simple test. My xml file is as follows:
<?xml version="1.0"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
<number>0123456789</number>
</note>
Set the xml file as the source data. Please don't import Projection.
By default, all columns will be treated as string types.
The data preview is as follows:
Set the json file as the sink:
Select Output to single file and specify the file name.
The debug result is as follows:
That's all.
I've found that you can change the projection mapping using the "Script Editor"
So you can keep your "projection" by importing, during a debug session, the sample you are using.
Once your projection is done you can edit the "Script" to change the type of your tag
Select the Script Editor button
You should have a script that look like that :
source(output(
note as (to as string, from as string, heading as string, body as string, number as integer)
),
allowSchemaDrift: true,
validateSchema: false,
limit: 100,
ignoreNoFilesFound: false,
rowUrlColumn: 'fileName',
validationMode: 'none',
namespaces: true) ~> XmlFiles
You can change the type of your tag "number" to string type
source(output(
note as (to as string, from as string, heading as string, body as string, number as string)
),
allowSchemaDrift: true,
validateSchema: false,
limit: 100,
ignoreNoFilesFound: false,
rowUrlColumn: 'fileName',
validationMode: 'none',
namespaces: true) ~> XmlFiles

How to parse a PDF in nodejs

I am trying to parse a pdf and categorize information based on text formatting/decoration. How do you suggest I do that?
For example, I have a pdf in which the structure is repeated:
S.No. BOLD+UNDERLINED TITLE para
How do I categorize this data into an array of objects based on text decoration:
[
{ sno: "", title: "", desc: "" },
...
]
I went through the documentation for pdf2json and figured that I might have to use pdfData.formImage.Pages[pageNumber].Texts[wordNumber].R[0] object after parsing the pdf to get hold of values I need.
The property TS of the above object is an array, the value at TS[2] corresponds to whether the text is bold (value = 1) or not (value = 0). I could not find any details on data related to underline text-decoration.
I also needed to initialize the parser as follows:
let pdfParser = new PDFParser(null, 1).
Check this for more details.

GraphQL schema from a single object JSON file in Gatsby

So I'd like to query a single JSON file which is not an array from Gatsby's GraphQL but I don't really know how to do it.
As far as I understand gatsby-transformer-json docs - it only supports loading arrays and have them accessible via allFileNameJson schema.
My gatsby-config plugins (only the necessary ones for this question):
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'data',
path: `${__dirname}/src/data`
}
},
'gatsby-transformer-json'
And then let's say in src/data i have a something.json file, like this:
{
"key": "value"
}
Now I'd like to query the data from something.json file, but there is no somethingJson schema i can query (tried with Gatsby's GraphiQL).
Could someone point out what am I doing wrong or how can I solve this problem?
Ok, so it is possible to query single-object files as long as they have a parent (folder).
Let's take these parameters:
gatsby-source-filesystem configured to src/data
test.json file positioned at src/data/test.json with { "key": "value" } content in it
Now as the test.json file actually has a parent (data folder) - you can query the fields from test.json like this:
{
dataJson {
key
}
}
But putting those directly in your root folder is a bad practice, because when you will store another json file, i.e. secondtest.json with { "key2": "value2" } content, and will query it with the same query as above, you will get data only from a single node (not sure if it takes first, or last encountered node),
So, the perfect solution for this case is to have your single-object json files stored in separate folders with just one json per folder.
For example you have some "About Me" data:
create a about folder in your src/data
create an index.json file with i.e. { "name": "John" }
query your data
Like this:
{
aboutJson {
name
}
}
That's it.

NavigationListItem & Sort

I tried to sort a NavigationListItem on a field which is different from the keyfield within the onInit method of the view controller w/o any success.
Note, there is no orderby implementation on the server side.
My xml view which doesn't implement any sorter since orderby isn't implemented: https://openui5.hana.ondemand.com/#/api/sap.tnt.NavigationListItem
<tnt:NavigationList id="navigationList">
<tnt:NavigationListItem icon="sap-icon://"
expanded="{expanded}"
key="{MY_KEY}"
items="{/MY_PATH}">
<tnt:NavigationListItem text="{MY_CONTENT}" key="{MY_KEY}"></tnt:NavigationListItem>
</tnt:NavigationListItem>
</tnt:NavigationList>
Here is an attempt to add a sorter that presently doesn't work. First, because return items correspond to the first level of NavigationListItem and secondly probably because of a wrong approach.
var oNavigationList = this.getView().byId('navigationList');
var aSorter = [];
aSorter[0] = new sap.ui.model.Sorter('MY_FIELD', true);
var oItems = oNavigationList.getItems();
oItems.sort("items", {path: "/MY_PATH", sorter: aSorter});
Could you please advice on the appropriate approach?
Since your List is bound to ODATA Model, all the sorting will happen at server side. Every time you say, sort, a new request is sent to server. Now, as you said, the server is not supporting orderby, I suggest the following approach :
Do oDataModel.read and store the data in a JSON Model. oData Read API
Apply the sorting in XML using below code:
<tnt:NavigationList id="navigationList">
<tnt:NavigationListItem icon="sap-icon://"
expanded="{expanded}" key="{MY_KEY}"
items="{
path : '/MY_PATH',
sorter: {
path: 'MY_CONTENT',
descending: false,
group: false
},
}">
<tnt:NavigationListItem text="{MY_CONTENT}"
key="{MY_KEY}"></tnt:NavigationListItem>
</tnt:NavigationListItem>
</tnt:NavigationList>
Let me know if you need more information.