Inherit from Master XML View in UI5 - sapui5

Imagine I have two pages which have exactly the same layout except for the data which always comes from a different model.
With a Javascript view I can code something like this using the OO mechanisms provided by UI5:
+---------------------------------------------------+
| CarsView |
+---------------------------------------------------+
| - defines the page structure |
| - contains no concrete model or uses dummy model |
+-----^-----------------------------------^---------+
| |
| |
| |
| |
+-------------+----------------+ +-------------+--------------+
| SportsCarView | | SUVview |
+------------------------------+ +----------------------------+
| - inherits from "CarsView" | | - inherits from "CarsView" |
| - uses "sportscar" model | | - uses "suv" model |
+------------------------------+ +----------------------------+
The SportCarView and the SUVview are actually used and displayed in the application, the CarsView is never used directly. So in fact it is an abstract class.
This is all fine and understood but how can I do the same (or similar thing) with XML views?
The only method of composition I am aware of are XML fragments which would let me reuse snippets for XML views in other XML views. But this is not what I am after.
Any ideas?

When you're applying XMLViews, I think I would get the controller to take care of the model selection. This is also where this kind of logic is supposed to be happening in my opinion (MVC).
E.g.:
this.setModel(
this.getComponent().getModel(
car === "SUV" ? "SUVModel" : "SportsCarModel"
));
On top of that, you could indeed apply different fragments (as you already mentioned) or play with visible and class attributes and binding expressions to make the views appear slightly different, e.g.:
<Text text="{SuvProperty}" visible={viewModel>/IsSuv} />
or:
<Text text="{= ${viewModel>/IsSuv} ? ${SuvProperty} : ${SportcarProperty} }" />
One word of caution esp. when playing with the visible attribute. If you get the app to construct 100 fields and hide 80 of them, you may understand that it'll be quite detrimental for performance.

Related

In Microsoft Dynamics 365, why is my filter not a combo box when I am running start my Visual Studio Project?

I'm currently following the tutorial "Creating a custom filter control" in Dynamics 365 for Finance and Operations Development Cookbook - Fourth Edition
I've created the extension to the MainAccount which includes, under NavigationList(Group) -> Filter (Group)", an instance of Combo Box with the following properties:
| Property | Value |
| Name | FilterType |
| AutoDeclaration | Yes |
| EnumType | DimensionLedgerAccountType |
| Selection | 10 |
In Visual Studio's preview, this displays correctly and offers the expected set of values.
I've set my project to be my startup project.
I've set my form extension to be my startup object.
... and then I click "Start".
After some long wait for the page to render, I find the labels for the fields are displayed with short black lines where the input fields should be, but the input fields hardly allow any interaction. I can click on them to select them, transforming them into blue box shapes, but I can't actually type anything into them and the input which should be a drop-down/combo-box for "type" has no visual or functional distinctions from the input for "name" which should just be text.
Is Visual Studio failing to deploy something?
Is there some additional modification needed in my metadata for this to render as expected?
What do I need to do to fix this?
Because you mention that you click "Apply", I think you are in the wrong area of the form.
Take a look at the screenshot from my implementation of the recipe, you can see there are two filter areas on the form. The first is the standard filter experience and the listed fields are based on the ranges set on the query of the form. Those fields are text fields because they allow you to enter filter values which may be different from one possible value. The second area is the one where the two custom filter controls described by the recipe in the cookbook were added. As you can see in the screenshot, the "Main account type" control provides a combo box behavior with the allowed values. If you change a value in on of these two controls, you don't need to click "Apply". Instead, the filters are applied automatically when the onModified event of the control fires.
With thanks to FH-Inway who spent some time screen sharing, it turns out the problem was not with the solution but with my expectations.
I expected the filter fields to simply be displayed and immediately available for use.
However, in actually -- completely counter-intuitively -- the fields, being created as part of the form, are only editable after one clicks the "Edit" button.
Once in edit mode, the fields display and interact as expected.

Rendering title tag based on a particular condition in sightly AEM

I am trying to render title on a page based on certain conditions.
Here is the pseudo code for what I want to achieve:
if currentPage.pageTitle is set, then render title as <title>${currentPage.pageTitle} | ${'page.title' # i18n}</title>
if currentPage.pageTitle is not set (i.e. is null), then render title as <title>${'page.title' # i18n}</title>
Right now I was trying to do something like this : <title data-sly-set.title="${currentPage.pageTitle || page.title}">${'page.title' # i18n, format=[title]}</title> but I want to modify it based on the conditions mentioned above.
Any suggestions?
You could just add the | conditionally and take advantage that a falsy expression does not render:
<title>${currentPage.pageTitle}${currentPage.pageTitle?' | ':''}${'page.title' # i18n}</title>

Is there a way to edit InfoView settings programmatically?

Is there a way in Enterprise Architect to modify elements displayed in InfoView element display by the means of EA API?
InfoView and its behavior is one of the undocumented features in EA API, so it may change without any notice. Following description is based on EA 13.5 build 1352.
The way it is implemented is somewhat weird (a good reason not to document it).
First, where the InfoView data is stored.
InfoView display mode is switched on by adding OPTIONS_duid=InfoView=value:; into field styleex of the table t_diagram, where duid is the short unique identifier of the diagram element (as in field InstanceId in t_diagramobjects) and value is a number, which bits are (MSB to LSB):
x x x x x x x
| | | | | | |_ ICON
| | | | | |___ TYPE
| | | | |_____ STEREOTYPE
| | | |_______ STATUS
| | |_________ PHASE
| |___________ VERSION
|_____________ AUTHOR
So the information about the element display format is stored in the diagram tables (and API object).
The styleEx field contains more than just this information; the information elements in the field are separated by semicolon (;) and their order is sometimes important, so don't touch the rest of this field, unless you know exactly know, what you're doing.
Let's assume we have diagram with DiagramId=12345, element with ElementId=6789.
So switching the InfoView ON and display the icon for the given element on our diagram shall be done like this (VbScript):
dim diag 'as EA.Diagram
dim el 'as EA.Element
dim dob 'as EA.DiagramObject
dim duid 'as String
set diag=Repository.getDiagramById(12345)
set el=Repository.getElementById(6789)
'find diagram object corresponding to the element in given diagram
for each dob in diag.DiagramObjects
if dob.ElementId=el.ElementId then
duid=dob.InstanceId
end if
next
' switch on the Infoview with an icon
diag.StyleEx=diag.StyleEx & "OPTIONS_" & duid & "=InfoView="1:;"
'save it
diag.Update
Notes:
You need to reload the diagram to see the changes.
Use Repository.SqlQuery() function to find the DiagramObject in production code; the example code is way too slow.
If the InfoView information element already exists in the StyleEx property of the diagram, you need to replace it instead of adding a new one.

Can I modify the text of links within the type declaration inside #property tags in JSDoc?

I am using the following syntax in JSDoc to link to type definitions within property definitions:
#property {module:a/b/c/type[]} propName propDescription
This works, but it uses the entire text within the curly braces as the type name in the generated documentation. For example, the above line results in generated doc that looks something like:
| propName | Array.<module:a/b/c/type> | propDescription |
Is there some way to do this but only have the actual type name displayed in the link? I want it to look like this:
| propName | Array.type | propDescription |
but still have "type" link to the documentation describing that type.
I have been unable to find any documentation related to this type of linking; I only found the current syntax by searching StackOverflow (mainly from this page)

Add a custom filter to search in magento2

I'm new with Magento2, I have a problem trying to add a new filter to the search module.
For example:
I created an attribute that names: "flag" of type "text field", that will be invisible in storefront.
I have 3 products:
name | description | flag
Product1 | Description1 | 1
Product2 | Description2 | 1
Product3 | Description3 | 0
When I type in the search box "product", by default Magento2 returns all the products, because all matches with the
search, what I want is add a filter to the search, that only returns the products with flag = 1, so it will returns only the product 1 and 2.
I don't know what is the exactly block or model that I must override.
Thanks in advance
You can add this attribute under search form as a hidden field with the value you want to filter with. When user click on the search button it would perform the search by adding one more parameter in the query string i.e ?q=product&flag=1 and you will get the expected result. With this way you don't need to overwrite any block or controller. But you need to overwrite the default search form. Below URL can help you overwriting core magento files.
Reference URL: https://magento.stackexchange.com/questions/84550/magento-2-override-base-view-file
Note: This technique will not work with the auto search. In that case you need to overwrite core search blocks.