Refer separately deployed components for reuse in an ui5 app - sapui5

i'm developing some apps, for which everyone needs to show a document in the same way. For this i created a new component which handles my documents in a separate component. I then just want to reuse this component from my different apps.
To embed my reuse component i used something like this in my view.xml:
<core:ComponentContainer
name="de.mycomp.base.DocViewer"
component="de.mycomp.base.DocViewer"
settings='\{"param1":"value1"\}'/>
To access it during runtime i have to declare the namespace of the reuse component and associate it with an resource-url. To achive this, i used the following coding in the init-method of my Component.js which uses my reuse-component DocViewer.
jQuery.sap.registerModulePath("de.mycomp.base.DocViewer", "/sap/bc/ui5_ui5/sap/zdocviewer");
zdocviewer in this case is the name of the bsp-application to which the reuse-component was deployed on premise. To have this also work in webide and on SAP-Cloud-Plattform i needed to add an entry to neo-app.json
like this:
{
"path": "/sap/bc/ui5_ui5/sap/zdocviewer",
"target": {
"type": "application",
"name": "docviewer"
},
"description": "my base document viewer"
},
where docviewer is the name of the deployed app with the reuse component on SCP.
The type application implies that this destination is an app.
This works so far on premise and on sap cloud.
but my problem is that i dont want to have the registerModulePath in my Component.js. Nearly every configuration of components takes place in the manifest.json file. So i tried to move this coding line to configuration in manifest.json, but i failed so far.
Here's what i did:
i added a dependency in section sap.ui5 and there in the dependency-entry like this:
"components": {
"de.dvelop.base.DvelopBaseDocViewer": {
"lazy": true
}
}
i added the following entry to sap.ui5 part
"resourceRoots": {
"de.dvelop.base.DvelopBaseDocViewer": "/sap/bc/ui5_ui5/sap/zdocviewer"
},
The problem here is, that its not allowed to use absolute paths in the value-part of the resource-root entries. So this is invalid:
- /sap/bc/ui5_ui5/sap/zdocviewer
- ../sap/bc/ui5_ui5/sap/zdocviewer
Only this is valid:
- sap/bc/ui5_ui5/sap/zdocviewer
- ./sap/bc/ui5_ui5/sap/zdocviewer
So this annotation is only usable for embedded components, where the reuse-component is in the same deployed project. But this is not my understanding of a reuseable component. So changing something in that component would make it neccessary to copy the files to all the app-projects using the component. And they all have to be deployed again.
So for now i made a fallback to the jquery.sap.registerModulePath because this works with deployed components to refer them from other independent components.
Or does anybody have an idea how to handle this better or more proper within manifest.json?
kind regards
Matthias

see here: ui5 reuse components: https://github.com/Yelcho/UI5-Comp-Routing
you mixed up here old and new approches, wrinting all steps in this answer would be very long. Here brief step to step approche:
define your componentUsages
"componentUsages": {
"myDoc": {
"name": "com.company.myDoc",
"settings": {},
"componentData": {},
"lazy": true
}}
define path mapping, in resourceRoots
"resourceRoots": {
"com.company.myDoc": "/sap/bc/ui5_ui5/sap/zdocviewer"
},
define a targed type component
"targets": {
"myDocTarget": {
"type": "Component",
"usage": "myDoc"
}
use nested routing
.getRouter()
.navTo("myDocRoute", {
id: oBindingContext.getProperty("CategoryID")
}, {
products: {
route: "list",
parameters: {
}
}
});

Related

Enable users of github program to configure their own DCMake prefix path

Consider a situation where people work together on the same code base; c++ with cmake. Code base depends on a library, that must be installed separately.
Each user may have the library in a different location. A user may invoke cmake like this:
cmake -DCMAKE_PREFIX_PATH=/path/for/that/user .
However, this is not very easy in all circumstances (e.g. windows and visual studio), and requires retyping. So instead, we have
list(APPEND CMAKE_PREFIX_PATH "/path/for/user")
In the CMakeLists.txt. This works, but requires people to constantly change that path after pulling a branch, which is annoying and easily forgotten. Is it possible to configure in a way that pulling new branches does not override this path, once set on a specific machine?
You can have each of your users create their own CMakeUserPresets.json file, and set it in the cacheVariables field of a configurePresets entry.
// CmakeUserPresets.json
{
"version": , // pick one
"cmakeMinimumRequired": {
"major": , // pick one
"minor": , // pick one
"patch": // pick one
},
"configurePresets": [
{
"name": "starball",
"displayName": "Starball's config",
"description": "Starball's private configuration preset",
"generator": "...",
"binaryDir": "...",
"cacheVariables": {
"CMAKE_PREFIX_PATH": "..."
},
"environment": {}
}
],
// ...
}
Make sure to put CMakeUserPresets.json in your .gitignore file (or whatever else you have to do for your specific VCS so that the user preset file isn't tracked in the VCS).

What happens if a library preload file / library dependencies is not updated in the UI5-manifest?

In the best practices for app developers, the Load Only What You Really Need section is written:
Keep Your Library Dependencies Up To Date
A library preload file, the library styles and text translations are loaded for every library you define in the application descriptor or the OpenUI5 bootstrap. Always define libraries in the manifest and remove all libraries that you do not intend to use in your code.
For instance:
"sap.ui5": {
"dependencies": {
"minUI5Version": "1.85.0",
"libs": {
"sap.ui.core": {},
"sap.m": {},
"sap.ui.layout": {}
}
}
...
}
My questions:
Do I understand it correctly, that in the libs I have to add all the libraries which appear in sap.ui.define([…]) of any controller of the UI5-app?
What happens if I forget to add a library here? Is it just excluded from the Component-preload.js and loaded in a non-optimized way or there are more serious disadvantages?
Yes, in order to benefit from performance optimizations, you have to keep the manifest.json section /sap.ui5/dependencies/libs always in sync with the UI5 libraries* (incl. custom ones) that can be identified from the application code and visible in API Reference if the lib is from the framework. I.e. not only "sap.ui.core" and "sap.m" but also, for example, "sap.ui.table" if one of the views contains sap.ui.table.Table.
If you have libraries which don't need to be preloaded immediately on app start but are supposed to be loaded on-demand, you can assign "lazy": true to those libraries, e.g.:
"libs": {
"sap.ui.core": {},
"sap.m": {},
"sap.ui.comp": {
"lazy": true
}
}
But that "lazy": true is purely informational. In the app, such libs should be loaded explicitly before they're in use:
// Core required from "sap/ui/core/Core"
await Core.loadLibrary("sap.ui.comp", /*async:*/ true);
Further info regarding loadLibrary: https://sdk.openui5.org/api/sap.ui.core.Core#methods/loadLibrary
* In the context of UI5, a "library" is a named bundle of controls, elements, types, interfaces, etc.
List of such libraries can be found at:
SAPUI5: https://ui5.sap.com/resources/sap-ui-version.json
OpenUI5: https://sdk.openui5.org/resources/sap-ui-version.json
Adding a single module (e.g. sap/ui/Device) to the /sap.ui5/dependencies/libs section won't work. To see which library the module belongs to, check the "Library" information from the corresponding API reference page:
The same applies when working with UI5 tooling.
All libraries required by your project must be listed in the libraries section of the framework configuration:
framework:
name: OpenUI5
version: 1.108.0
libraries:
- name: sap.ui.core
- name: sap.m
- name: sap.ui.table
- name: ...
The component-preload.js only contains elements of your app, never any UI5 code.
To answer your question, take a look at this small ui5 demo app.
When loading it with:
"sap.ui5": {
"dependencies": {
"minUI5Version": "1.108.0",
"libs": {
"sap.ui.core": {},
"sap.m": {}
}
}
}
Open the DevTools and take a look at the Network Tab. Because of the references of the libs in the manifest.json, both library-preload.js are loaded before your Component.js.
When you remove:
"sap.ui.core": {},
"sap.m": {}
from the manifest.json and run the app again, then you can see that all UI5 elements are loaded one-by-one after your component.js. This just slows down your app.

Set Database Properties when creating it with SqlDatabase.createAsync()

This is the question about the Azure Management Libraries for Java.
First, some background:
The Azure Management REST API mentions at the createorupdate definition the ability to create the database and set different database properties like this (example from the page):
{
"location": "southeastasia",
"sku": {
"name": "S0",
"tier": "Standard"
},
"properties": {
"createMode": "Default",
"collation": "SQL_Latin1_General_CP1_CI_AS",
"maxSizeBytes": 1073741824
}
}
I'm looking how to do the similar request from the Azure Management Libraries for Java.
So far I have found how to set the "sku" part. This is done by using the appropriate ServiceObjectiveName object:
final SqlServer sqlServer = ...get SQL server object ...;
final Creatable<SqlDatabase> myDb = sqlServer.databases()
.define(targetDBName)
.withServiceObjective(ServiceObjectiveName.fromString("S0"));
...
myDb.createAsync(...); // create the db with sku S0
But I can't figure out how to set the properties. For my purpose I need to set a bit different properties than in the sample. Namely, the specific properties.maxSizeBytes and properties.autoPauseDelay.
I even found the .withMaxSizeBytes() method here but it's marked deprecated without any explanation.
I haven't found any way to set the autoPauseDelay.
By digging in the azure-sdk-for-java, I am sorry that I did not find any methods for setting these properties.
The complicated workaround I think of is to use resource deployment. It is supported in java sdk:
azure.deployments().define(deploymentName)
.withExistingResourceGroup(rgName)
.withTemplate(templateJson)
.withParameters("{}")
.withMode(DeploymentMode.INCREMENTAL)
.create();
And here is a sample which can give you some guidance: DeployUsingARMTemplate
By the way, you can try to create a database on Azure portal, and then you can download the template at the last step of the creation:

What are the rules for class names in IBM Watson Visual Recognition service?

I'm exploring IBM Watson Visual Recognition service and when I create a classifier using classnames like 'black-dog' (i.e. black-dog_positive_example), this classname is later returned as 'black_dog' (with underscore replacing dash) when I classify an image using the /v3/classify endpoint.
But when I retrieve the classifier details with the /v3/classifiers/{classifier_id} the class is correctly listed as 'black-dog'.
So, my result for GET /v3/classifiers/{classifier_id} is like:
{
"classifier_id": "dog_561932172",
"name": "dog",
"owner": "xxxxxxxx-xxx-xxx-xxx-xxxxxxxxxxxx",
"status": "ready",
"created": "2016-07-30T22:06:39.327Z",
"classes": [
{"class": "black-dog"}
]
}
While my result for GET /v3/classify is
{
"custom_classes": 1,
"images": [
{
"classifiers": [
{
"classes": [
{
"class": "black_dog",
"score": 0.546941
}
],
"classifier_id": "dog_561932172",
"name": "dog"
}
],
"image": "20160620_142113.jpg"
}
],
"images_processed": 1
}
So is this expected or a defect? Should I avoid using "-" in class names? Are there any other rules for the value of a classname?
Update:
Updated via Matt's answer.
Talked with the support team, and it is indeed a bug. Here was their response:
Thanks for pointing this out. I reproduced and confirmed with dev team, and we do consider this inconsistency between the listed class name and the class name in results is a bug.
And this is because the class name been altered in result from what is submitted.
I have raised a ticket for tracking on this. According to developer, currently the output can be either a document to list the substitutions or find a way to remove them.
...so they are currently working on it.
Are there any other rules for the value of a classname?
We made an update, and the service should no longer modify any class names like replacing a dash with an underscore. Instead, it will not accept class names with any of these characters for custom learning: \,|,*,{,},$,-,/,',`,"
(You'll see the dash is included in there.) Spaces are acceptable. The update is not retroactive, so existing class names that were modified during training are not affected.

Uploading files to Plunker

Is there any way to upload multiple files to http://plnkr.co, instead of copy-pasting the code all the time? Would be great if a plunker could be connected to a github repository, or if a set of files could be dragged in.
There is no built-in way to upload multiple files to Plunker.
Users have built tools to facilitate this. Please see: https://www.npmjs.org/package/plunk which is a command-line utility that will let you create plunks from the contents of a directory.
You can also bootstrap plunks by making POST requests to http://plnkr.co/edit/ where the payload has the following format:
{
"description": "Plunk description", // Optional
"tags": ["tag1", "tag2", ..., "tagN"], // Optional
"files": {
"filename1.ext": "contents of filename1.ext",
"filename2.ext": "and so on.."
}
}
Code for this handler: https://github.com/filearts/plunker_www/blob/0c608ae80ef30d59bfdfeaf3c2a28563f7b730e4/app.coffee#L105-L121