Quantcast
Channel: SAPUI5 Developer Center
Viewing all 789 articles
Browse latest View live

Enhance UI5 app with custom icon fonts

$
0
0

What and why

 

Have you ever tried looking for appropriate icon in UI5 and found out that you couldn’t find one? UI5 comes with 546 different icons and a few hundred additional icons are available when using Fiori Launchpad. That is quite a few icons but you will eventually run into a use case where SAP provided icons does not have what you need. Or, it might be that your customer requires that the app uses specific icons.

 

When you have to start styling your app with custom icons, wouldn’t it be great if they worked exactly the same as icons in UI5? You could apply CSS styles, like color, to them or rotate and scale them easily. But it could be that all you have are PNG, JPG raster images or SVG vector images. With PNG and JPG you’re out of luck when it comes to CSS styling. SVGs can be styled but CSS styling may not work well with some UI5 controls like ObjectListItem.

Luckily you can convert your images into icon fonts easily with free tools. All you have to do is:

 

  1. Prepare SVG vector images
  2. Convert vector icons into icon font
  3. Register and use icon font icons in your app

 

With icon fonts you get these benefits over using individual images:

  • Consistent with UI5 icon fonts
  • Can be styled and animated
  • Smaller in size
  • Can be loaded in single HTTP Request

 

Next we will go through all the steps required to get your UI5 app styled with beautiful custom font icons.

 

Prepare vector images

 

Let’s say there is a requirement for an app for controlling kitchen equipment. SAP luckily provides an icon for a dishwasher but unfortunately fridge, oven and microwave oven are missing. Luckily there are many places to find free icons in the Internet and suitable icons are available in Pubzi [http://www.pubzi.com/].

 

source images.png

 

Unfortunately they are raster images so first they need to be converted into vector images. Inkscape is a free tool that can be used for conversion. Conversion is easy. First copy paste the images into Inkscape one at a time. In Inkscape images can then be converted into SVG format with a feature called Trace Bitmap. Then it’s just fitting the converted vector image into the document and possibly changing the document dimensions in Inkscape.

 

tracebitmap.png

 

document properties.png

 

Convert vector icons into icon font

 

Once vector images are ready, you can convert them into an icon font. IcoMoon App is a really good, free tool for that. Vector icons can be imported into IcoMoon App with a few clicks and all the icons can be converted into the font simultaneously. Then all you’ve to do is download the icon font, extract it and integrate it into your UI5 app.

 

fonts generated.png

A few words on icon fonts generated by IcoMoon App. They use Private Use Area (PUA) that is a range of code points in Unicode. Those code points won’t be used by Unicode Consortium but they could be occupied by other custom fonts. So test properly and assign different code point range for your font in IcoMoon App if there are any collisions.

 

Here are the important files that your downloaded icon font contains:

 

font files.png

 

In addition to these font files some lines of CSS are needed for integrating the newly created font icons. Luckily the downloaded package has these also in file style.css.

 

Use icon font in UI5 app

 

Using a custom icon font in your app is almost as simple as using icons that come with UI5. These are the steps required:

 

  1. Register the font and icons with CSS
  2. Add the font into UI5
  3. Use the icons

 

Same steps with example:

 

   1. Register the font and icons with css

 

@font-face {  font-family: 'icomoon';  src:url('icomoon.eot?5qvb9g');  src:url('icomoon.eot?5qvb9g#iefix') format('embedded-opentype'),  url('icomoon.ttf?5qvb9g') format('truetype'),  url('icomoon.woff?5qvb9g') format('woff'),  url('icomoon.svg?5qvb9g#icomoon') format('svg');  font-weight: normal;  font-style: normal;  }  [class^="icon-"], [class*=" icon-"] {  font-family: 'icomoon';  speak: none;  font-style: normal;  font-weight: normal;  font-variant: normal;  text-transform: none;  line-height: 1;  /* Better Font Rendering =========== */  -webkit-font-smoothing: antialiased;  -moz-osx-font-smoothing: grayscale;  }  .icon-microwave:before {  content: "\e900";  }  .icon-oven:before {  content: "\e901";  }  .icon-refridgerator:before {  content: "\e902";  }

   2. Add the font into UI5

 

// first parameter is font name, second parameter is collection name, third parameter is font-family and the last parameter is the code point in Unicode
sap.ui.core.IconPool.addIcon('microwave', 'customfont', 'icomoon', 'e900');
sap.ui.core.IconPool.addIcon('oven', 'customfont', 'icomoon', 'e901');
sap.ui.core.IconPool.addIcon('refridgerator', 'customfont', 'icomoon', 'e902');

 

   3. Use the icons


new sap.ui.core.Icon({      src : "sap-icon://customfont/microwave"
}
//sap-icon://customfont/oven
//sap-icon://customfont/refridgerator


 

And that’s it. Now your app has custom icons that can be styled with CSS. Example:

 

example.png

 

 

 

 

Live example

 

 

 

 

Further reading

 

Good font icon set:

https://fortawesome.github.io/Font-Awesome/

 

Good tutorial on making an icon font:

http://www.webdesignerdepot.com/2012/01/how-to-make-your-own-icon-webfont/


SAPUI5 Walkthrough, And Dive In - Step 3: Controls

$
0
0

Welcome to my SAPUI5 Walkthrough, And Dive In blog series, where I’ll not only walkthrough the tutorial, but dive in, to explore the magic behind SAPUI5. Buckle up and sit tight, it's gonna be a bumpy ride as I’m no expert in any way shape or form, just a humble learner who loves coding and likes to get to the bottom of things =。=

 

This time, we’ll dive in to find out how the control is created, which consists of two parts:

 

- How the sap.m.Text module is requested, loaded and executed.

- How a simple sap.m.Text control is created.

 

Break point, checked, alright, let’s dive in!

01.png

 

First, we’ll need to require the sap.m.Text module.

02.png

 

jQuery.sap.require leads to requireModule.

03.png

 

A sync ajax request loads the content of Text-dbg.js, sets it to module.data, and also, sets module.state to LOADED.

04.png

 

If we switch to the network tab of Chrome developer tool, we’ll find Text-dbg.js had been downloaded.

05.png

 

With module loaded, we’ll then execute the module.

06.png

 

We set module state to EXECUTING first, then, call the _window.eval to have module data executed.

07.png

 

Once done executing the module, its state will be set to READY, and its data will be set to undefined.

08.png

 

With module ready, we’ll continue creating our Text control, first, to create a shell object oInstance, then, call the constructor method on it.

09.png

 

since Control extends from Element, the constructor method of Element will be called next.

10.png

 

And Element’s upper chain, the constructor of ManagedObject will also be called.

11.png

 

In the ManagedObject constructor method, we’ll register the object in the core.

12.png

 

Which leads to registerElement.

13.png

 

Which is essentially add our element to the global this.mElements map.

14.png

 

After registration, we’ll have settings ({text: “Hello World”} in our case) applied.

15.png

 

Which is essentially to call the setText method on “Hello World”.

16.png

17.png

 

With that, the shell object oInstance is now filled with our Text control properties, and returned, the end

18.png

 

 

If you want to dive even deeper on UI5 controls, then you dont wanna miss Mr. Jerry Wang’s A Tutorial how I do self-study on a given Fiori control and UI5 framework code behind series, enjoy, happy coding

SAP Hybrid App Toolkit - Developing Hybrid Mobile Applications

$
0
0

In today's world, mobile devices and smartphones are becoming an intrinsic part of our life and work. Apps offer solutions to all our requirements like getting the latest news updates, shopping, planning holidays, travel, social networking, and so on. More and more enterprises are also supporting their workforce to use mobile devices to access the corporate network and ensure that work is uninterrupted.

 

There are different types of apps available, namely, native apps, mobile web apps, and hybrid mobile apps. Native apps are developed specifically for a mobile platform. They can access all the features of the mobile device like camera, calendar, GPS and so on.

Mobile web apps run across mobile platforms. They appear similar to websites and are viewable on the device's browser. But they cannot access the features of the mobile device. Also, the rendering of mobile web apps does not match the native UI and controls of the mobile device. These apps are developed using SAPUI5 and HTML5.

To bridge the gap between these two types of apps, hybrid mobile apps are developed. These apps run on different operating systems like Android, iOS, and Windows. They can also access the features of the mobile devices.

 

SAP Web IDE is a browser-based toolkit that runs on the SAP HANA Cloud Platform. It enables you to develop SAPUI5 and SAP Fiori apps. SAP Hybrid App Toolkit is a Web IDE plugin that lets you add mobile capabilities to the Fiori apps and develop Apache Cordova hybrid mobile apps.

 

Hybrid App Toolkit provides the following key capabilities:

 

  • Cordova and Kapsel plugin APIs that can be used to add mobile capabilities to the application. Some supported plugins are camera, contacts, calendar, barcode scanner, device information and so on. Auto code completion and code snippets enable you to use the plugins in your apps and develop hybrid mobile apps for Android and iOS platforms.
  • Cordova Facade Preview to preview the hybrid app functionality in a browser, with a single button click.
  • SAP Hybrid APP Toolkit Companion App to test the hybrid mobile app on a mobile device or device emulator.

 

Hybrid App Toolkit includes the following components:

 

  • Hybrid App Toolkit plugin: Provides hybrid app development capabilities to SAP Web IDE
  • Hybrid App Toolkit Connector: A locally installed server process that enables SAP Web IDE to connect to the local system's Cordova development environment
  • Hybrid App Toolkit Companion App: A native mobile application that enables a live preview of the hybrid mobile apps on your personal mobile device or an emulator

 

For more information, see https://help.hana.ondemand.com/webide_hat/frameset.htm.

The Hybrid App Toolkit plugin can be enabled in Web IDE. To download the add-on package that includes the Hybrid App Toolkit Connector and Hybrid App Toolkit Companion App, go to the
SAP Store
.

SAP Web IDE deep dive-openSAP-Developing mobile apps with HCP-Week 2

$
0
0

Week 2 started this Monday, you dont have to download and install any software if you have already done it in Week 1> system preparation guides

 

 

  • To get information about different SAP Web IDE templates, go to Tools>Template Library (you can create your own custom template as well)
  • Easy way to create a project from existing sample apps : Shop, Approve PO, Manage products
  • SAP HANA Cloud connector (HCC) is not the only solution to connect on-premise system to HANA Cloud Platform, but there is also 'Reverse proxy' concept but setting it up is not easy as compared to HCC. + few disadvantages: attacks from Internet, not all protocols can be supported
  • SAP HANA Cloud connector is available as
  • While setting up WebIDEUsage properties, make sure to use lower case.
  • Nice explanation on how an existing Fiori app can be extended.
  • Interesting talk on Fiori Launchpad, how to register to it
    • Before registering to FLP (on HCP), app has to be deployed to HANA Cloud Platform first
    • add mode=admin at the end of the FLP url to look into management cockpit of SAP FLP (of course you should have admin role)
  • Nice tour of SAP HANA Cloud portal
    • How easy it is to assign an deployed app (from HCP) to FLP from 'create app site'

 

You can ask your queries in discussion section of this course.

 

For more info,follow

SMP and HCPms: SMP Developer Center

SAP Web IDE, SAP HAT : SAPUI5 Developer Center

SAP HCP : SAP HANA Cloud Platform Developer Center

SAP HANA Cloud portal: SAP HANA Cloud Portal

 

Looking forward for week 3!!

Analytical Path Framework – Installation

$
0
0

When you want to create cool Analytical Fiori-like Apps then APF is the way to go. I blogged about it here: http://scn.sap.com/community/developer-center/front-end/blog/2015/04/01/analysis-path-framework-a-hidden-gem-for-creating-awesome-analytical-apps. So it is about advanced charting in analytical Fiori Apps. You can use APF when you have SAP UI5 resp. Fiori, you need HANA SPS08 or higher and „SAP HANA Analytics Foundation“ (SHAF)" which is part of SAP Suite-on-HANA.

 

If you don’t know what I mean I recommend to play around with the demo app: https://www.sapfioritrial.com/sap/hana/uis/clients/ushell-app/shells/fiori/FioriLaunchpad.html?helpset=trial&sap-client=001#DaysSalesOutstanding-analyzeDSO or an application in exploratory data analysis which is shown here:


In this blog entry I will describe how to get APF started. And I want to thank everyone at SAP who helped me: you get a free beer when we meet at Markstube in Walldorf

 

Prerequisites

You need the following for APF:

  • AS ABAP – in the blog I describe a scenario for an AS ABAP 7.40 which is a Fiori Frontend Server.
  • HANA – of course with XS Engine running
  • Web Dispatcher

 

This is the easy task – you need following skills:

  • HANA administration: skills of HANA Lifecycle Manager and granting roles and analytical privileges – SSO enablement is necessary if you want to avoid loggin screens which is of course necessary for production
  • Web Dispatcher: an analytical app or the APF configuration modeler are JavaScript apps that also consume XSOData services.
  • ABAP administration: installation of a software component and implementing the Fiori Launchpad and can grant ABAP Roles

 

I also recommend Google Chrome because of the developer tools.

 

The installation is described here: http://help.sap.com/saphelp_uiaddon10/helpdata/en/ec/f70adefd71445586b2fbe264306fdd/content.htm?frameset=/en/ec/699e0817fb46a0817b0fa276a249f8/frameset.htm&node_id=699

 

In the following I will describe some details at the installation process which might be interesting for you. At first check that XS Engine is running. Usually it is on port 80<instance number> of your HANA and you should see something like the following on your browser:

xs.PNG

 

APF on FES and Fiori Lanchpad

After software component UISAFND1 is installed you need two roles on the Frontend Server: SAP_APF_DT_TCR_A (and later you also need  SAP_APF_RT_TCR_A). Then you should see the following tile on your Launchpad:

1_FLP.PNG

 

HANA Content

You need also HANA Content: HANA CONTENT HBA APF CORE 100 (technical name: HCO_HBA_R_APF_CORE). The installation is described in OSS note: 2183947 - Smart Business for SoH (Suite on Hana) delivery. You find a new software component for the frontend server here for Smart Business which is useful in the future. On the HANA system you can find two software packages:

  • HANA CONTENT HBA AF CORE 100 (HCOHBARSBCORE03P_1-20012110.ZIP)
  • HANA CONTENT HBA AF TRANSP 100 (HCOHBARSBTP00_0-70000744.ZIP)

 

I am describing the installation using HANA Application Lifecycle Manager (HALM) which is described here: https://help.sap.com/saphelp_hanaplatform/helpdata/en/bd/b7a459c3144fcab1c5641c72c1158d/frameset.htm. Put the zip file on the database server and execute a command like the following:

/sapmnt/<system>/hdbclient/hdbalm -h sh021 -p 8066 -u <adminuser> install /SAPINST/HANA/HANA_AddOns/SAP_ANALYTICS_FOUNDATION/HCOHBARSBTP00_0-70000744.zip


The administration user need sufficent authorizations which are describes in the following knowledge base articels:


Two roles are important for installation: sap.hana.xs.admin.roles:Administrator and sap.hana.xs.admin.roles:HTTPDestAdministrator.


After that execute SQL-Statements described in OSS note 2118742 - Analyzing HANA Live content package deployment problemsto control the installation.

As developer you should see the following content in HANA studio now:

systems_content.PNG

On older HANA revisions you need the Application Lifecycle Manager but I won't describe the details here.

 

Web Dispatcher

Since APF Configuration Modeler as well as analytical apps consume resources both from the Frontend Server (Gateway Hub) but also from the HANA so you need the web dispatcher to overcome the cross origin policy restrictions.

There are many good documents that explain how a web dispatcher works:

 

It is possible to install more than one web dispatcher. As developer you start the Launchpad and use a different HTTP port. This could be necessary in scenarios when there a more or different systems involved.

 

I describe a typical configuration with (frontend server fes.acme.com), a backend (be.acme.com) and a HANA XS (hana.acme.com).

wdisp/system_0 = MSHOST=https://fes.acme.com, MSPORT=????, SID=COT, NR=??, CLIENT=???, SRCSRV=*:*, SRCURL=/sap/opu;/sap/bc;/sap/public

wdisp/system_1 = MSHOST= https://be.acme.com, MSPORT=????, SID=CCT, NR=??, CLIENT=???, SRCSRV=*:*, SRCURL=/sap/es

wdisp/system_2 = SID=EXT, EXTSRV= https://hana.acme.com:?, SRCSRV=*:*, SRCURL=/sap/hba;/sap/hana

 

Also useful are the following parameters:

wdisp/system_conflict_resolution = 1

wdisp/add_clientprotocol_header = 1

wdisp/handle_webdisp_ap_header = 1

wdisp/add_xforwardedfor_header = true

 

I don’t want to discuss rewriteitign files and integration of Enterprise Search (/sap/es) which is necessary for Fiori factsheets. Please also note that this configuration has to be changed if you develop own XSOData services in own HANA packages.


If the web dispatcher has a wrong configuration then the configuration modeler won’t react if you start to develop a configuration and you will get messages like the one here with Chrome developer tools: “APF message (1): 10005 – Bad HTTP request returned status 404 with text Not found” and “APF message (2): 5101 – Unexpected internal error: No XSRF Tokel availanble. Contact SAP” and “APF message (3): 9000 – Unknown exception Uncaught Type Error: Cannot read property ‘setAndSave’”

3_wrong_disp.PNG


Fight for your Rights!

You need HANA privileges that can be granted by your administrator. Then check them in HANA studio you should see at least the first two here:

system_users.png


You need also analytical privileges which is describe in the installation documentation mentioned above. But in a test scenario you should convince your administration to give you a kind of SAP_ALL for accessing all information views which is reasonable in test systems (only):

sap_all.PNG

 

By the way, you see all your privileges in detail with an SQL statement:

2_grant.PNG

 

If you don’t have enough privileges you will get the following messages in Chrome developer tools:

“APF message (1): 5001  Request /sap/hba/r/apf/core&odata/modeler/AnalyticalConfiguration.xsodata/$batch to server failed with http status code 403…”

 

Smoketest

Now you perform a smoketest. Enter the configuration modeler, and press "+". Now create a new application and after pressing "Save" it will be saved in the HANA database. When there is a problem then "Save" will not work. In this case open Chrome tools and check the error messages. The description of the errors above will help you to indentify the problem.

smoke.PNG

 

Summary

It’s not that difficult to install APF if you know how to do it. But you should have a sixpack of cold beer or some sparkling wine to captivate and win the hearts of your administrators. They deserve it.

Atom text editor for UI5 development

$
0
0

Introduction to Atom

Atom is a free text editor that is published under the MIT license. By installing selected packages you can modify the editor to fits your needs.

 

Useful packages for UI5 development

  • Project Manager
    • simple project manager which can be opened via shortcut CTRL+CMD+p on a Mac
  • Color picker
    • supports color picker via right click with various formats (HEX, RGB, HSL, …)
    • shows actual color as background color in the CSS file
  • linter + linter-eslint
    • With these plugins you can integrate eslint checks directly into the editor. E.g. every time you save a javascript file the eslint checks are run and the result is directly displayed inside the editor. This helps to prevent a lot of small coding mistakes and to enforce common standards when working together with other developers.
    • ESLint can be configured with a .eslintrc file you add to your project. A good starting point is to use the .eslintrc file from the OpenUI5 sources
  • atom-beautify
    • This plugin provides code formatter for HTML, XML, JavaScript, CSS and many more file formats
    • Unfortunately the formatting for XML sucks.
    • JS Beautify can be i configured in a way that it matches your ESLint settings.
  • svg-preview
    • this plugin shows a visual representation of an SVG file
  • Minimap + Plugins
    • Minimap is a plugin that renders a small representation of the file on the right side of the editor window. Minimap can be enhanced with additional plugins.
  • DocBlockr
    • create easily documentation sections in your code
    • press Enter or Tab after /** in Java Script code and a template documentation is created for you
  • merge-conflicts
    • allows you to merge git conflicts directly in atom
    • if you open a file with merge conflicts in Atom, you can then press ALT+m d to open this plugin
    • to do more advanced resolutions like “ours then theirs”, you can right click on the colored chunks

 

 

 

Export / import packages to Atom

 

Export your installed packages into a file in your home directory

apm list --bare --installed --no-dev > ~/atom_packages.txt

 

Import all packages from a file to Atom

apm install --packages-file ~/atom_packages.txt

 

 

This blog post was created in cooperation with Steffen Froehlich

SAPUI5 Application CREATE, CHECK-OUT, CHECK-IN, DEPLOY, VERSION mgt etc...

$
0
0

Below points will be covered in post:

 

  1. Creating new SAPUI5 Project
  2. Deploy Application on SAP HANA Cloud Platform
  3. SAP HANA Cloud Platform Overview
  4. SAP HANA Cloud Platform Version
  5. SAP HANA Cloud Platform Roles
  6. Committing SAPUI5 Application changes to Cloud
  7. Version management of Application in SAP HANA Cloud Platform

 

 

Creating new SAPUI5 Project

 

1.png

 

Select type of Application you want to create.

 

2.png

 

Follow the screen and Application will be created as shown below.

 

3.png

New Application XMLUI5 is created.

Now we will add this SAPUI5 Project to Git. To do this we need to deploy our application to SAP HANA Cloud Platform.

 

Lets checkout the Git settings first.

 

 

4.png

 

5.png

 

Deploy SAPUI5 Application on HANA Cloud Platform.

 

6.png

 

Here you need to provide your SAPID or PID for Authentication and click on Login button.

 

7.png

 

SAP HANA Cloud Platform it automatically maintain Versions, each time you deploy an Application it creates a new Version number to identify the latest changes. It also provides ability to switch to specific version of deployed Application when ever required and Activate that specific Version.

 

In below screen shot we are deploying very first version 1.0.0 of SAPUI5 Application which we are creating.

 

Click on Deploy button.

 

8.png

 

If your Application is deployed successfully you will see below Popup and Green dots in your Application.

 

9.png

 

If you want to see hot your Application works on HANA Cloud, you can click on first link available in popup.

Once you click on first link it looks like below.

 

12.png

 

Three more files (highlighted below) will be added once all things are correctly configured in HANA Cloud Platform

 

11.png

Once your Application (XMLUI5) is configured in SAP HANA Cloud you can see it in Cloud Platform as below.

SAP HANA Cockpit can be accessed using below URL

 

https://account.hanatrial.ondemand.com/cockpit

 

13.png

 

Once you click on your deployed Application you will see below screen which contains below details

 

  1. Application Details
  2. Current Status of your application
  3. Current Active Version URL (you can access your application using this URL)

 

 

Overview:

 

14.png

 

Version:


When you click on Version link on left side below screen will be opened

 

Versioning sections two main parts

 

Commits:

 

  1. This section will contains all of your commits done in Application along with comments and Versions you are allowed here to activate any of the available versions.
  2. Each time you perform a Commit in your SAPUI5 project from WEBIDE Git, the same will be updated here. Currently we are having only one new Commit available with active version 1.0.0.
  3. Git Repository URl can be used to retrieve the repository Application contents or push changes using a Git utility.

 

15.png

 

Versions:

 

Versions tab will show you the current Active as well as all other Inactive Versions available in HANA Cloud. You can change Active version any time as required by using Actions column Activate Button.

 

16.png

Roles:


Roles tab is basically used in scenario when there are multiple developers working on same application (authenticate them) we create Roles and then we assign Developers in that Role. In our example we have created one Role called Developer and add Three developers in that Role.

 

These should be PID or SAPID of the Developers who will work. This mainly used when you try to Deploy or Commit any changes done in Application to SAP HANA Cloud.

 

17.png

Once we are done with creating Roles we are ready to Assign Developers to that Role. PID or SAPID is required to add Developers.

 

18.png

 

Any time you can Un-assign/Assign any User from/to List.

 

19.png

 

Changing files and updating (Committing changes) on SAP HANA Cloud Platform


Let us see how Application looks, go as shown below

 

21.png

 

22.png

 

Now let us make some changes to Title of our Application and make a Commit to SAP HANA Cloud.

 

Once you make changes to file the Green Dot will gets changes to *.  This means you have checked out these files (Files are changed) and are no longer in sync with SAP HANA Cloud repository.

 

23.png

 

Once you are done with all your changes to a file you can again Checked-in the changes to SAP HANA Cloud.

Just Click Git Pane on right hand side. This will provide options to Check-In code as shown below

 

24.png

 

Choose the files which you want to Check-In by clicking on Stag checkbox individually.

It is suggested Click on Pull button before committing any changes.

 

Once you click on Pull button you will be asked for SAP ID/PID for Authentication as below, provide and click on OK button.

 

25.png

 

Now time to Commit the changes, select Stag checkbox put some Commit Description Comments and click on Commit and Push button.

 

26.png

 

 

 

28.png

Once Commit is successful you will see message on top right corner.

 

30.png

 

This means your changes are Committed in SAP HANA Cloud. The * will turn back to Green Dot in Application hierarchy.

You can see your Commits in History in SAP HANA Cloud as below.

 

31.png

 

After this Commit if you see in Versioning tab of SAP HANA Cloud Platform you still find the Old version which is active.

 

New Version can be Activate as shown below.

 

37.png

 

Click on Yes button to Activate.

 

Run Application again and changes will be reflected as below (Title updated)

 

38.png

 

 

Thanks to you for reading this post till end.

I have tried to provide details on each and every step you need to perform if you are working on SAP HANA Cloud platform, please suggest or comment if I missed any.


Please drop a comment or suggestion so I can update the document accordingly.

 

 

Thanks-

Abhishek

Getting ready to contribute to #OpenUI5 - Keeping a fork up to date

$
0
0

Being a Contributer

 

In my recent talk at SAP Teched in Las Vegas on writing SAPUI5 applications I made a comment about contributing to the OpenUI5.

 

There were a couple of reasons for this:

1. Contributing to an open source project will be a cool thing to do

2. You will learn a lot about OpenUI5 in the process even if you don't actually submit anything.

 

With this in mind there are several ways you can contribute and they are outlined here.

 

You can:

 

All of those are great things to do and I drop into the forums here and at stack exchange to see how I can help others and learn myself to see what people are struggling with.

 

 

If though you are going to take the final step and contribute code then we need to have a local fork of OpenUI5.

Firstly you have to make sure your local setup is working and review the contributing guides

 

But before we get to this we have to fork OpenUI5 and clone it to our local machine.

 

Well, that is pretty easy and I have done this a couple of times only to find that UI5 is marching on and every other day the core UI5 team are committing to the master branch.

 

So how to keep our clone up to date.

 

That is what we are going to cover in this blog.

 

Firstly fork OpenUI5 to your own account. This is as simple as going to SAP/openui5 · GitHub and clicking on the fork button.

 

Then you need to clone that fork to your own computer. You can do this step with the UI versions of Github for windows but for the following steps you are going to need the command line as there isn't a UI option to keep a fork up to date.

 

09:18:55 /var/www$ git clone git@njames.github.com:sqrc/openui5.git
Cloning into 'openui5'...
remote: Counting objects: 220479, done.
remote: Compressing objects: 100% (207/207), done.
remote: Total 220479 (delta 113), reused 0 (delta 0), pack-reused 220218
Receiving objects: 100% (220479/220479), 82.91 MiB | 259.00 KiB/s, done.
Resolving deltas: 100% (125255/125255), done.
Checking connectivity... done.

 

Then you need to set your upstream repo - the one that you cloned from

 

09:25:32 /var/www$ cd openui5/
09:25:50 (master) /var/www/openui5$ git fetch upstream
fatal: 'upstream' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

09:25:51 (master) /var/www/openui5$ git remote -v
origin     git@njames.github.com:sqrc/openui5.git (fetch)
origin     git@njames.github.com:sqrc/openui5.git (push)
09:26:18 (master) /var/www/openui5$ git remote add upstream git@github.com:SAP/openui5.git
09:28:14 (master) /var/www/openui5$ git remote -v
origin     git@njames.github.com:sqrc/openui5.git (fetch)
origin     git@njames.github.com:sqrc/openui5.git (push)
upstream     git@github.com:SAP/openui5.git (fetch)
upstream     git@github.com:SAP/openui5.git (push)

 

I first tried to fetch my upstream but none existed. I then checked what the remotes are set to and then added the upstream repo to the OpenUI5 repo.

Now when I check my remotes I have an origin and an upstream.

 

Now when I fetch from upstream I will pull in the new branches I don't have in the clone.

 

09:28:18 (master) /var/www/openui5$ git fetch upstream
From github.com:SAP/openui5
 * [new branch]      gh-pages   -> upstream/gh-pages
 * [new branch]      master     -> upstream/master
 * [new branch]      rel-1.26   -> upstream/rel-1.26
 * [new branch]      rel-1.28   -> upstream/rel-1.28
 * [new branch]      rel-1.30   -> upstream/rel-1.30
 * [new branch]      rel-1.32   -> upstream/rel-1.32
09:28:36 (master) /var/www/openui5$ 

Now you can merge the upstream with master and provided you haven't done anything on master that should be pretty painless fast forward merge

 

12:08:42 (master) /var/www/openui5$ git merge upstream/master
Updating c1f7be6..3180cd8
Fast-forward
 src/sap.m/src/sap/m/ActionSheet.js                                          |  12 +-
 src/sap.m/src/sap/m/NotificationListGroup.js                                |  29 ++-
 src/sap.m/src/sap/m/NotificationListItem.js                                 |   6 +-
 src/sap.m/src/sap/m/NotificationListItemRenderer.js                         |   4 +-
 src/sap.m/src/sap/m/P13nColumnsPanel.js                                     | 185 +++++++++++++++---
 src/sap.m/src/sap/m/ViewSettingsDialog.js                                   | 129 +++++++++----
 src/sap.m/src/sap/m/messagebundle.properties                                |  24 +++
 ...

 

Now all you have to do is regularly pull from upstream with git fetch upstream and merge with git merge upstream/master

 

Your github fork though is behind master.

 

behind-master.png

Note that at the bottom of this image it states that 'This branch is 42 commits behind SAP:master'

 

 

To fix this once your local clone is up to date with the commands above you just need to git push and you are done.

 

even-master.png

Now: 'This branch is even with SAP:master'

 

You could even add these into an alias to make it a single command.

 

Set up a local fork of OpenUI5 and get ready to contribute.

 

Two bonus links from githubs documentation if you are looking for more info on this:

  1. https://help.github.com/articles/configuring-a-remote-for-a-fork/
  2. https://help.github.com/articles/syncing-a-fork/

 

 

(UPDATE: I just realised my title of keeping a clone up to date is not quite strictly correct - it is the fork we are keeping up to date and I have changed it.)


An insight into SAPUI5 through free online resources/links

$
0
0

Summary: Learning SAP UI5 for a beginner seems like a mammoth task, although there are numerous learning resources scattered on SCN and other sites. Its overwhelming to make sense out of the huge spaghetti of scattered links. With this document I have striven hard to arrange the knowledge in a logical order so that it makes sense.

Prerequisites: A strong desire to learn SAP UI5.

Outcome: You will be on your way to becoming a SAPUI5 expert.

Target audience: This document is good for beginners and experts alike.

 

Installing Java and Eclipse

http://www.java.sun.com

http://www.eclipse.org/downloads/

Java is an Oracle product now after acquisition of Sun Microsystems but the old link still works. You need an IDE to code, Eclipse in our case, which in turn needs JDK to run. Please be careful about installing the right version of Java that works with the Eclipse you wish to install. Its not wrong to have multiple versions of JDK but many times it causes issues. You will have to troubleshoot a it to ensure that the system uses the appropriate version of Java.


If you need more clarity on the installation process the following link should be helpful.

How to install a basic development environment for SAPUI5

 

Installing SAPUI5 plugins

https://tools.hana.ondemand.com/

To install some or all of the tools, get an installation compatible with the desired tools and use the respective software site URL in the Help > Install New Software wizard. Based on the version of your eclipse:

 

SAPUI5 Demokit

https://openui5beta.hana.ondemand.com/

 

SAPUI5 Tutorials

https://openui5beta.hana.ondemand.com/#docs/guide/8b49fc198bf04b2d9800fc37fecbb218.html

This link gives you further access to the following Tutorials:

  • Hello World

  • Walkthrough

  • Data Binding

  • Navigation and Routing

  • Testing

Data Binding in SAPUI5 (by Chris Whealy)

Data Binding in SAPUI5

JavaScript for ABAP developers (by Chris Whealy)

JavaScript for ABAP Developers (Updated)

SAPUI5 SplittApp Example (This example was good but I had to troubleshoot a bit to get it working as some concepts were not very clearly specified)

http://www.saplearners.com/sap-m-splitapp-demo-application-in-sapui5/

SAPUI5 sap.m.Table Example

http://www.saplearners.com/table-sap-m-table-in-sapui5/


SAPUI5 Icons Explorer

https://openui5.hana.ondemand.com/iconExplorer.html

 

SAPUI5 UI Elements Explorer

https://sapui5.hana.ondemand.com/explored.html

 

Getting access to SAP WebIDE Trial

SAP Web IDE - Local Trial Version

The above link talks about both SAP WebIDE web based trial as well as local installation.

 

Installing local version of SAP WebIDE for non-productive purposes

SAP Web IDE Dev Guide (Local Installation)

How To Install SAP Web IDE Locally for Trial in Windows

 

SAPUI5 Code Inspector Chrome Extension

https://chrome.google.com/webstore/detail/ui5-inspector/bebecogbafbighhaildooiibipcnbngo

 

OPENUI5 Youtube Channel

https://www.youtube.com/user/openui5videos

 

SAPUI5 Youtube Playlist (by Abhishek Saha)

https://www.youtube.com/playlist?list=PL-xVzXm_I8mDXLVTZtNyz1EboIxqwcQ2I

 

Miscellaneous

Develop your SAPUI5 applications in Ubuntu (Linux)

http://scn.sap.com/community/developer-center/front-end/blog/2015/05/15/make-your-sapui5-applications-in-ubuntu

How to get rid of: "No 'Access-Control-Allow-Origin' header is present on the requested resource." in Chrome browser.

How to get rid of: "No 'Access-Control-Allow-Origin' header is present on the requested resource." in Chrome browser.

OData.org

http://www.odata.org/

Smart Table - Backend and Frontend Example

$
0
0

Hello Fellow SCNers,

 

In this blog, I will demo the usage of Smart Table control including OData Metadata development and Front End application code.

Smart Table uses Vocabulary based annotations in OData.

 

Backend

 

Data Structure and Data preparation


Step 1: Go to SE11 and create a table as shown below.

Table.jpg

Step 2: Populate the data and check.

Data.jpg

Service Creation


Step 3: Import the highlighted vocabulary(ies) in SEGW(Project Builder Transaction). (This is a one time activity)

Vocab.jpg

 

Step 4: Create a Service with Vocabulary Based Annotation as

Serv Det 1.jpg

 

Step 5: Create an Entity - SmartTable and corresponding EntitySet. These are standard steps and I am ignoring them here, though I have attached screenshot of the same.

Serv Det 2.jpg

 

Properties -

Serv Det 3.jpg

Step 6: Import the vocabulary in the Service as -

Import Vocab.jpg

 

Step 7: Create the Line Item Annotation which is the most important one for Smart table as it will help the UI5 framework to create table structure.

Choose the line item column and then click on Create Annotation.

Line Item.jpg

Step 8: Click on 'Append Row/Create'

Line Item 2.jpg

Step 9: Choose the highlighted type for property

Line Item 3.jpg

 

Step 10: One column is created as shown below -

Line Item 4.jpg

Do the above step for all 4 columns.

 

Step 11: Now the service will look like -

 

Proj 1.jpg

 

Step 12: Implement the Getter for Smart Table Entityset too -

Getter.jpg

Now the metadata should look like below

 

<edmx:Edmxxmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"xmlns:sap="http://www.sap.com/Protocols/SAPData"Version="1.0">

 

 

 

 

 

<edmx:DataServicesm:DataServiceVersion="2.0">

 

 

<Schemaxmlns="http://schemas.microsoft.com/ado/2008/09/edm"Namespace="ZSMARTTABLE4"xml:lang="en"sap:schema-version="0000">

 

 

<EntityTypeName="SmartTable"sap:content-version="1">

 

 

<Key>

 

 

<PropertyRefName="Bname"/>

 

</Key>

<PropertyName="Bname"Type="Edm.String"Nullable="false"MaxLength="12"sap:label="User"/>

<PropertyName="Fullname"Type="Edm.String"Nullable="false"MaxLength="80"sap:label="Complete name"/>

<PropertyName="SmtpAddr"Type="Edm.String"Nullable="false"MaxLength="241"sap:label="E-Mail Address"/>

<PropertyName="Location"Type="Edm.String"Nullable="false"MaxLength="40"sap:label="Location"/>

</EntityType>

 

<EntityContainerName="ZSMARTTABLE4_Entities"m:IsDefaultEntityContainer="true">

 

 

<EntitySetName="SmartTableSet"EntityType="ZSMARTTABLE4.SmartTable"sap:content-version="1"/>

 

</EntityContainer>

 

<Annotationsxmlns="http://docs.oasis-open.org/odata/ns/edm"Target="SmartTable">

 

 

<AnnotationTerm="com.sap.vocabularies.UI.v1.LineItem">

 

 

<Collection>

 

 

<RecordType="com.sap.vocabularies.UI.v1.DataFieldForAnnotation">

 

 

<PropertyValueProperty="Label"String="Location"/>

 

<PropertyValueProperty="Target"AnnotationPath="Location"/>

</Record>

<RecordType="com.sap.vocabularies.UI.v1.DataFieldForAnnotation"/>

 

<RecordType="com.sap.vocabularies.UI.v1.DataFieldForAnnotation">

 

 

<PropertyValueProperty="Label"String="Location"/>

 

<PropertyValueProperty="Target"AnnotationPath="Location"/>

</Record>

<RecordType="com.sap.vocabularies.UI.v1.DataFieldForAnnotation"/>

</Collection>

</Annotation>

</Annotations>

<atom:linkxmlns:atom="http://www.w3.org/2005/Atom"rel="self"href="<host:port>/sap/opu/odata/sap/ZSMARTTABLE4/$metadata"/>

<atom:linkxmlns:atom="http://www.w3.org/2005/Atom"rel="latest-version"href="<host:port>/sap/opu/odata/sap/ZSMARTTABLE4/$metadata"/>

</Schema>

</edmx:DataServices>

</edmx:Edmx>


Front End Code


Step 13: For sake of simplicity I have put the Smart Table in Index.html file and run it.


<!DOCTYPE html>

<html><head>

  <meta http-equiv='X-UA-Compatible' content='IE=edge' />

  <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

  <title>Smart Table</title>

 

  <script id='sap-ui-bootstrap' type='text/javascript'

  src='/sapui5/resources/sap-ui-core.js'

  data-sap-ui-theme='sap_bluecrystal'

  data-sap-ui-xx-bindingSyntax="complex"

  data-sap-ui-libs='sap.ui.commons, sap.m'>

  </script>

 

  <script id="view1" type="sapui5/xmlview">

  <core:View xmlns:core="sap.ui.core" xmlns="sap.m" xmlns:smartFilterBar="sap.ui.comp.smartfilterbar" xmlns:smartTable="sap.ui.comp.smarttable" controllerName="smartTable.controller" class="sapUiSizeCompact">

  <Page id="page" title="Customers">

 

  <smartTable:SmartTable entitySet="SmartTableSet"  enableAutoBinding="true"/>

  </Page>

  </core:View>

  </script>

 

  <script>

  //Controller

  sap.ui.controller("smartTable.controller", {

  onInit: function() {

  var sURL, oModel, oView;

 

  sURL = "<host:port>/sap/opu/odata/sap/ZSMARTTABLE4";

  oModel = new sap.ui.model.odata.v2.ODataModel(sURL, {

  json: true

  });

  oView = this.getView();

  oView.setModel(oModel);

  }

  });

 

  jQuery.sap.declare("smartTable.Component");

  sap.ui.core.UIComponent.extend("smartTable.Component", {

  /**

  * Initialize the application

  *

  * @returns {sap.ui.core.Control} the content

  */

  createContent: function() {

  var app = new sap.m.App({

  initialPage: "idView"

  });

  var oView = sap.ui.xmlview("idView", { viewContent: jQuery("#view1").html() });         

  app.addPage(oView);

  return app;

  }

  });

 

  new sap.ui.core.ComponentContainer({

  name : "smartTable"

  }).placeAt("content")

 

  </script>

 

  </head>

  <body class='sapUiBody'>

  <div id='content'></div>

  </body>

</html>

 

 

Final Output -

 

Output.jpg

 

PS: You may get some errors like one shown below but it is dependent on the SAPUI5 Version. I have used 1.33.0-SNAPSHOT version but it works on 1.28 also.

 

Error.jpg

 

 

I would like to thank Santhosh Gowda whose blog gave me inspiration to test this control and Arshdeep Singh for his help.

 

I would request you all to provide feedback and ask questions to enhance everyone's learning.

 

BR,

Ankit Maskara.

How to install Hybrid Application Toolkit (HAT) on Mac

$
0
0

Introduction

Let me complete my previous blog with some considerations regarding the installation of HAT on MAC OS X (El Capitan). I'm going to show here just the main differences between this installation and the one on Windows. The required steps are pretty much the same, but as you might know with Mac platforms you can also deploy your apps to iOS device. This requires the installation of a development tool named XCode. Further to that you need also to install the corresponding Command Line Developer Tools. Of course this is only needed if you want to develop apps for iOS: if you want to stick with Android apps you just need to install the Android SDK as explained later in this document. Here in this guide I'm going to describe how to install all the required tools for both development platforms: iOS and Android.

One could think that the installation of HAT and its prerequisites on MAC is harder than on Windows, but I can show here that it's even easier if we use the Terminal window to issue the installation instructions.

Let's start from the beginning.

 

 

 

Prerequisites

We are assuming here that Xcode is already installed and Command Line Developer Tools as well. You can get the first one from the Apple store or you can access the https://developer.apple.com/downloads/ site and download it from there, together with the Command Line Developer Tools.

33.jpg

If you have downloaded both packages from this developer site you can install them very quickly: for the first one, once mounted the .dmg file, you just need to drag & drop the Xcode app to your application folder.

The second tool can be installed by performing the following steps:

 

1) Double click on the .dmg image file in order to mount it

2) Double click on the installation package

3) At the Introduction screen click on Continue

4) At the License screen click on Continue

5) Click on Agree

6) At the Installation Type screen click on Install

7) Provide your credentials

8) At the Summary screen click on Close

9) Command Line Developers Tool is installed

 

You can continue now with this guide

 

 

 

Let's get started!

This is what we are going to install today:


  • Homebrew (Homebrew — The missing package manager for OS X) - Homebrew is a package manager which helps you to install some components you need direclty from the command line. It also symlinks their files into the /usr/local folder
  • Cask(http://caskroom.io/) - Cask is a tool which extends Homebrew and allows you to install large binaries like big applications on your Mac direclty from the command line
  • Oracle Java JDK - It's installed through Cask
  • Apache Ant - It's a build tool required by Android development
  • Android SDK - Required for Android Development
  • Kapsel - Required for adding Kapsel plugins to your hybrid apps
  • Configuration of some environment variables
  • Bower (http://bower.io/) - It's a package manager specific for the web and it's required by the HAT installation procedure
  • NodeJS (https://nodejs.org/en/) - Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model      that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
  • ios-deploy - Required for deployment on iOS Simulator/Device
  • ios-sim - Required to manage iOS Simulator
  • Cordova (https://cordova.apache.org/) - Apache Cordova is an open-source mobile development framework. It allows you to use standard web technologies such as HTML5, CSS3, and JavaScript for cross-platform development, avoiding each mobile platforms' native development language. Applications execute within wrappers targeted to each platform, and rely on standards-compliant API bindings to access each device's sensors, data, and network status.
  • Kapsel CLI - It's the Command Line Interface for Kapsel
  • HAT - Hybrid Application Toolkit

 

Don't be afraid about the number of the components we are going to install because the entire process will be quite straightforward by using the Terminal window.


1) Open a Terminal window on your Mac



2) The first thing to install is Homebrew: this will allow us to install other components very smoothly. The command to install Homebrew is


     ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

 

 

3) Now let's use Homebrew to install Cask, this will allow us to easily install Java JDK in the next step

 

     brew install cask

 

 

4) Install Oracle Java JDK by using the command

 

     brew cask install java

 

     this will install automatically the latest version

 

 

5)  If you are going to develop and deploy to Android platform you need Apache Ant. You can skip this step and the next one if you don't need to develop for

     Android. This is the command to install Ant

    

     brew install ant

 

     It should be installed under the following path: /usr/local/Cellar/ant/1.9.6

 

 

6) Let's now install the Android SDK through the command

 

     brew install android-sdk

 

     It should be installed under the path /usr/local/Cellar/android-sdk/24.4.1



7) Once installed you need to configure it. Run:

    

     android


     The Android SDK manager starts and you can select here the required components you want to install. Here it's a list of just the ones required to make it      working


  • Click on the Install 10 packages button

     05.jpg

  •      Accept the License

     06.jpg

  •      The installation starts: when it finishes, close the Android SDK manager tool.

 

 

8) Create a virtual device for Android development.

  •      Run the command android avd
  •      Click on the Device Definitions tab
  •      choose the device you want to use as a template for your emulator (i.e. Nexus 4)
  •      click on Create Device on the left side.
  •      Provide the following information and click on OK

     07.jpg

  •      Then close the Android AVD Manager

 

 

9) Another required tool is NodeJS. You can install it by going on the product web site and downloading it from there, but I'm going to show you this quicker way to do it:

 

     brew tap homebrew/boneyard

     brew install homebrew/versions/node012

 

With this command I'm going to install a specific version of Node, in particular I'm going to install the latest build of the version 0.12 which, at the time I'm writing, is 0.12.7. I'm installing this specific version because this is the one supported and required by the HAT installation procedure.

 

 

10) Now it's the time to install the Kapsel plugins. Download the package from the SAP Store. I'm assuming that the package has been downloaded into the folder Desktop/temp of your Mac. From the terminal, run the following commands:

 

     cd ~/Desktop/temp

     tar xvzf SMPSDK30010P_1-21011833.gz

     unzip ebf25343/modules/KapselSDK/KapselSDK.zip -d ~/KapselSDK

 

Now, in your home folder you should find a new subfolder named KapselSDK

 

 

11) Some environment variables must be defined in the system. According to the HAT installation guide, the best place to define these variables is the .bash_profile file that you should find in your Home folder. If this file is not present you need to create it. So

 

  • run "cd" to go back to your home folder
  • run "ls -la" to check if this file is present or not. if It's not present create it by running the command "touch .bash_profile"
  • run "nano .bash_profile" to open the file with the nano editor
  • copy and paste the following lines in the file

 

export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME="/usr/local/Cellar/android-sdk/24.4.1"
export ANT_HOME="/usr/local/Cellar/ant/1.9.6/libexec/"
export KAPSEL_HOME="/Users/virtual/KapselSDK"
export PATH=$PATH:/usr/local/bin/ant

12.jpg


NOTE: please pay attention to the two variables ANDROID_HOME and ANT_HOME where there is hard-coded the version numbers of the two softwares. You must change them according to your installed versions. Pay also attention to the variable KAPSEL_HOME where you have to replace the user named "virtual" with your user.

 

  • press "CTRL-O" to save the file, confirm the name by hitting ENTER and then press "CTRL-X" to exit from the editor
  • run "source .bash_profile" to apply the changes immediately



12) You can check that the changes have been applied by running the command "export".This will print out the complete list of the exported variables where you should be able to find the one you defined

     13.jpg


13) Install ios-deploy, cordova, ios-sim and the Command Line Interface(CLI) for Kapsel with the following commands:

 

     npm install -g ios-deploy@1.8.2

     npm install -g cordova@5.2.0

     npm install -g ios-sim

     npm install -g ~/KapselSDK/cli

 

14) Finally we can start the installation of HAT. I'm always assuming that your HAT .zip package is located as well under he folder Desktop/temp of your Mac. These commands will extract the .zip file under the hat subfolder of your home directory and will make all the .sh files as executables. Then the setup procedure will be launched


     unzip ~/Desktop/temp/SAP_HAT_local_1_9_7.zip -d ~/

     mv ~/SAP_HAT_local-1.9.7/ ~/hat

     cd ~/hat

     chmod +x *.sh

     ./setup.sh

 

15) The installation starts. Some other required components and libraries will be installed. When the web page shows up you can close the splash screen and select both the platforms on the top of the screen. Then click on the Check All button

     17.jpg

 

 

16) From this moment on it continues at the same way I showed in my blog for HAT Installation on Windows platform.

 

Have fun!

OData Server for Node.js

$
0
0

In this blog I want to gain your attention and give an introduction to an OpenSource project I recently started a few weeks ago on GitHub. The aim of the n-odata-server project is to develop an OData server that runs on node.js backend which helps us to develop better SAPUI5 applications in shorter time.

 

Motivation

Why don't you use SAP Gateway?

You would obviously ask: Why do you want to implement your own OData server. There is SAP Gateway that fulfills this perfectly. My answer is "yes" and "no". If you are working in a SAP environment and the backend functionality has already been developed you simply implement your OData service on SAP Gateway and can develop your SAPUI5 frontend against this middleware. But what if the backend is developed at the same time as the frontend and both parts should go live at the same time in near future?

 

Why don't you use Mockserver?

You would say: "There is a very good mockserver" that you can leverage to develop your SAPUI5 frontend absolutely autarkic. Again the answer is "yes" and "no". Of course the mockserver helps very much but there is one point that bothers me.

Mockserver cannot save data to files

The mockserver can read the data you defined in your local JSON files and you can then do most everything with this data in your SAPUI5 application (complete CRUD functionality). But if you refresh the page cause e.g. you changed a little bit in your source code all the data you entered so far is gone. The application / mockserver loads the data from your local JSON files and you have to do enter all your data again to test your code change. This is due to a javascript security policy. Javascript applications are not allowed to save data to the local file system and the mockserver has no chance to save the data to a backend system cause there is no appropriate service for this.

Developing app over a longer time

Or think about a scenario in which you develop your app over several weeks and because you also have other projects you only can spend 1 or 2 day a week on the UI5 project. In this case it would be really great if you could start with the data you entered the week before.

End-User Workshops

Another scenario is delivering of the frontend application for end-user workshops as early as possible even if your backend is still in an early development phase. If such a workshop lasts more than a few hours maybe some days the users expect that they find the data they entered the day before when they restart testing the next morning. With mockserver this is only possible if you tell your users not to shutdown the browser and the computer in the evening and not to refresh the page. But you know as me that this is ofter not possible or the end-users don't listen to you or sometime you need to clear the browser cache.

Non-Gateway Scenarios

Last but not least there are scenarios in which you don't have a SAP backend like R/3, S/4 Hana or HANA. In this case you have to implement your backend on your own. Of course you can simply implement a RESTful JSON api with java, node.js, php, ... But as SAPUI5 developer you already know and appreciate the benefits of OData. As far my research revealed there are no out-of-the-box solutions yet even no lightweight ones that can also quickly be enabled for the above mentioned other scenarios.

 

Why node.js?

Next question you might ask is: "Why do you use node.js and not Java?". I am an experience Java developer. So it would be no problem for me to leverage the Olingo library to implement an OData server with Java. But there are four reasons that lead me to node.js.

SAP commitment to node.js

Some weeks ago SAP officially commited to node.js. They will change the javascript engine of SAP HANA to node.js and they will support node.js on HCP (Hana Cloud Platform) when they roll-out the cloudfoundry support. With the cloudfoundry roll-out you will be able to develop not only Java or HANA backend application on HCP but also node.js applications.

I personally expect that javascript (node.js) will get much much more attention on backend side in the next years and will replace Java in many cases.

Server startup time

In the Java world most of us work with a Tomcat server. Even though it is lightweight compared to SAP Web AS Java or IBM Websphere or whatever, the startup takes some time. This is annoying for every developer. A simple node.js server starts in felt no time (milliseconds).

Node.js library to support several DB-systems

Then there is this great node.js library (called package in node terminology) called loopback that abstracts the db layer. This this library it is easily possible to support several DBs like Oracle, MySQL, Postgres, MongoDB, ... It supports also a flat file database for apps with small data or testing screnerios.

 

State of the n-odata-server project

Cause I started the project a few weeks ago and I cannot work on it every day it currently is in quite early state. Therefore it supports only basic OData scenarios at the moment.

But because I decided to develop it as an OpenSource project I hope that a few other guys also see the potential of it an contribute to it. I'm not only looking for developers. Also testers, documentation writers of even marketing people with a huge business network are welcome.

Currently we are two developers who work on this part-time.

We collaborate via Slack and manage our task with Trello and have online meetings on Google Hangout from time to time. With these tools we are extremely agile and it should be no problem to collaborate even with participants from different continents. 

 

The future of n-odata-server

As I'm at the beginning of the development there is still a lot of work. The first step at the roadmap would be to implement the minimal OData conformance level. Later I would like to implement the intermediate and advanced conformance levels.

Also there is room for new ideas that might come by you.

 

Resources

Following is a list of resources I mentioned in this blog. These may help you to get a deeper insight in what I´m technically talking about.

 

This is the end of my short introduction to this project. I hope I could enthuse one, two or hundred people to contribute to the project.

 

See you on

SAPUI5 walkthrough step 4 - XML views, dive in - how does a xml view get created?

$
0
0

Welcome to my SAPUI5 Walkthrough, And Dive In blog series, where I’ll not only walkthrough the tutorial, but dive in, to explore the magic behind SAPUI5. Buckle up and sit tight, it's gonna be a bumpy ride as I’m no expert in any way shape or form, just a humble learner who loves coding and likes to get to the bottom of things =。=

 

We’ll continue our journey with step 4 of the walkthrough. The XML view introduced is very simple, which makes a good example for us to take a closer look at how the XML view is created behind the scene

 

01.png

 

Here’s our index.html, where we instantiate a XML view with the view configuration object which holds the view name.

02.png

 

Our framework source code treasure hunt starts here.

03.png

 

Which leads us to the factory function of sap.ui.view.

04.png

 

Where it prepares the parameters, moves our configuration object from sId to vView to oView.

05.png

 

It adds a type (XML) to the oView configuration object.

06.png

 

Then, base on the view type, it instantiates a sap.ui.core.mvc.XMLView with the configuration object, and assigns it to our view object.

07.png

 

If we step into it, we’ll be taken to the constructor method of the Control class, you may wonder what XMLView has anything to do with Control, turns out XMLView was extended from Control, well, not exactly, before we dive into the source code, let’s take a high-level look at the inheritance chain of the classes we’ll about to get into:

 

 

sap.ui.core.mvc.XMLView

                    |

               extend

                    |

sap.ui.core.mvc.View

                    |

               extend

                    |

sap.ui.core.Control (base class for Controls, creates and initializes a new control with the given sId and settings)

                    |

               extend

                    |

sap.ui.core.Element (base class for UI elements, constructs and initializes an UI Element with the given sId and settings)

                    |

               extend

                    |

sap.ui.base.ManagedObject (base class that introduces some basic concepts like state management or data binding)

                    |

               extend

                    |

sap.ui.base.EventProvider (provides internal eventing facilities for objects)

                    |

               extend

                    |

sap.ui.base.Object (base class for all SAPUI5 Objects)

 

 

Alright, with this information in mind, let’s continue with our source code debugging, Control’s constructor calls Element’s constructor with the configuration object as the argument. (from this point onwards, you'll probably find a lot of similarity between the following content and second part of my last blog - how does a control get created, well, view and control they are all came from the same chain after all. I do think I explain things better this time around : )

08.png

09.png

 

Element's constructor calls ManagedObject's constructor.

10.png

 

ManagedObject's constructor calls EventProvider's constructor.

11.png

 

EventProvider's constructor calls BaseObject's constructor.

12.png

 

BaseObject’s constructor, end of the chain, it throws error if the view we’re creating is not a instance of the BaseObject, other than that, it does not do anything else.

13.png

 

After that, we get pop back to the EventProvider’s constructor, it creates the mEventRegistry map and sets it to an empty object.

14.png

 

Then, we’re taken another stack back, to the ManagedObject’s constructor, where quite a few things happen. First, it shifts the sId (configuration object) to mSettings, and sets our view’s sId to null since there’s no sId given explicitly.

15.png

 

Then it generates a sId for the view object.

16.png

 

It creates a bunch of properties and sets them with default values, we see a lot of familiar faces here, like the properties map, aggregations map, model object, binding related properties, turns out this is where they were born

17.png

 

Then it registers the object in the Core.

18.png

 

By calling the registerElement method.

19.png

 

Which essentially adds our view object to the global mElements map.

20.png

 

After the registration, it calls InitCompositeSupport, which initializes the view and connects it to the controller.

21.png

 

There’s 4 method / function calls within InitCompositeSupport, we’ll focus on the first 2 calls (the last 2 does not really do anything in our case).

22.png

 

Instead of showing screenshot after screenshot, which will most likely get people confused, I’ll try to explain what the first 2 calls in below format, hopefully the hierarchy layout plus my super expressive argument names plus right amount of comments could make things easier

 

initViewSettings(mSettingsAKAconfigurationObject)     |—> jQuery.sap.loadResource(“App.view.xml”).documentElement // to loads in our xml document then sets its content to xmlContent     |—> fnProcessView          |—> XMLTemplateProcessor.parseViewAttributes(xmlContent, viewObject, mSettings) // to parse only the attributes of the XML root node
fnInitController()     |—> createAndConnectController(viewObject, mSettings) // which does nothings in our case     |—> onControllerConnected(oControllerWhichDoesNotExistInOurCase)          |—> ManagedObject.runWithPreprocessors()               |—> XMLTemplateProcessor.parseTemplate(xmlContent, viewObject) // to parse a complete XML template definition the full node hierarchy, it returns an array containing Controls and/or plain HTML element strings                    |—> parseChildren(xmlNode)                         |—> parseNode(childNode)                              |—> createControlOrExtension(childNode)                                   |—> createRegularControls(childNode) // to create a plain and simple regular UI5 control                                        |—> handleChildren(childNode, oDefaultAggregation, mAllAggregations) // there’s no children to be handled in our case                                             |—> createControls(node)                                                  |—> createControlOrExtension(node) // recursive call, it gets in a loop to have all UI5 controls required for the application created out of children nodes and their aggregations                              |—> oView.addAggregation("content”, oChildControlJustCreatedAndReturned)

Now, we’re back. Then we continue with runPreprocessor (there’s no preprocessor registered in our case).

23.png

 

It calls fireAfterInit, which does not do anything neither in our case, this is the end of InitCompositeSupport.

24.png

 

After InitCompositeSupport, the init method will be called if it exists which is not in our case, then, it applies settings, sets all properties, aggregations, associations and event handlers as given in.

25.png

 

It only does one thing in our case, which is to set the viewName property.

26.png

 

In the end, it returns the view object.

27.png

 

And lastly, it places it at HTML document body.

28.png

 

 

The End

Setting up Jenkins with GitHub

$
0
0

In a typical software development model, there are multiples programmers contributing to the same codebase. This causes many bugs in the codebase, which significantly slows down development.

 

Continuous Integration is a practice that involves developers checking-in their code several times a day to a central code repository. Each time code is checked in, automated builds and tests run. Since this happens several times a day, problems are detected early and they are resolved before development continues further. This practice requires: a Continuous Integration server which runs the automated builds and tests; a version control system that tracks changes in the codebase.

 

In this setup, we will use:

  • Jenkins: an open-source continuous integration server.
  • Git: a Version Control System
  • GitHub: to host the code repository online, so that multiple developers can access it over the internet. GitHub is a web-based Git repository hosting service that can be used free of cost.

 

fig1.jpg

Figure 1: Continuous Integration setup with Jenkins

 

 

In this article, we shall cover the section shown in orange. This focuses on the steps required to enable Jenkins to communicate with GitHub.

 

There are several ways of connecting Jenkins to a remote repository on GitHub (SSH, HTTPS, Subversion). In this tutorial, we use SSH authentication, as this eliminates the need to enter your username and password every time you run a Git command. Also, this eliminates the need for a local issuer certificate (SSL) on Jenkins.


1. Prerequisites

 

    • GitHub (github.wdf.sap.corp) account is set up with a repository.
    • Git for Windows is set up on your computer, using SSH for authentication. (A tutorial on this is available here.)
    • Jenkins is installed on your computer [with Git plugin installed].

 

2. Configuring Jenkins for Git


Open your Jenkins Dashboard.

 

Go to: Manage Jenkins > Configure System

 

Under ‘Git’, add a new Git installation with the ‘Path to Git executable’ set to: C:\Program Files\Git\cmd\git.exe

 

1.GitPath.jpg

NOTE: It is necessary to use this particular git.exe file. There will be multiple git.exe files in other folders. However, pointing Jenkins to any other git.exe file will give you a humongous stack trace of an exception beginning with: ssh executable not found.


3. Running Jenkins as a service of your user account

Open Task Manager > Services > Open Services

 

Select ‘Jenkins’ from the list > Right-click > Properties

 

2.JenkinsProcess.jpg

 

Go to the "Logon" tab

 

Select ‘This account’, and enter your local account name and password (including domain details, if required).

 

3.JenkinsProperties.jpg

 

Restart Jenkins to allow the changes to take effect.

 

4. Setting up Credentials in Jenkins


Open the Jenkins dashboard.

 

Go to: Credentials > Global credentials > Add Credentials

 

4.JenkinsCredentials.jpg

The ‘Kind’ and ‘Scope’ will be as shown above.

 

For the Username, enter your GitHub username.

 

Select ‘From the Jenkins master ~/.ssh’ for the Private Key.

 

Enter the passphrase that you used while setting up SSH. Leave it blank if you didn’t use any passphrase.

 

5. Setting up a project in Jenkins

 

New Item > Free Style project

 

For ‘GitHub project’, enter the URL of the repository on GitHub.

 

Under ‘Source Code Management’, select ‘Git’.

 

Enter the URL of the repository in SSH format.

 

Select credentials that you set up in step 4.

 

Save.

 

 

 

TABLE OF POSSIBLE ERRORS

ERRORPROBABLE CAUSESOLUTION

javax.servlet.ServletException: java.lang.RuntimeException: ssh executable not found. The git plugin only supports official git client http://git-scm.com/download/win

In your Jenkins global configuration, the Path to Git Executable is not pointing to the git.exe provided by the official Git for Windows client.In your Jenkins server, go to Manage Jenkins > Configure System and set ‘Path to Git Executable’ to C:\Program Files\Git\cmd\git.exe
Failed to connect to repository : Command "C:\Program Files\Git\cmd\git.exe -c core.askpass=true ls-remote -h git@github.wdf.sap.corp:I322118/FBA_StandardTiles.git HEAD" returned status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Jenkins is running as a service on the local user account instead of your account.Follow Step 3 to run Jenkins as a service on your user account.

Failed to connect to repository : Command "C:\Program Files\Git\cmd\git.exe -c core.askpass=true ls-remote -h https://github.wdf.sap.corp/I322118/FBA_StandardTiles.git HEAD" returned status code 128:

You are using an HTTPS URL to your GitHub repo instead of an SSH URL.

Go to your GitHub repo, and click on ‘SSH’ and copy that URL. It should be in the following format:

  git@github.wdf.sap.corp:<username>/repo_name.git

 

 

You should now be able to execute a build and see it pass, if Jenkins successfully fetches your code from GitHub. The next step is to set up builds and tests that run on the code that you push to GitHub.

 

In the next article, we will talk about Test-Driven Development in UI5 applications, and the various tools available to this end. This will help us set up ‘Unit tests’ shown in the ‘NodeJS Plugin’ section in Figure 1.

 

 

This article was written with the contribution of :  MOUNIKA GANTA

 

Sharing the #OpenUI5 love

$
0
0

Recently I found a blog that I had written last year and had been sitting idle in draft waiting for some final spit and polish. Well the good news is that that blog was not the only one. This is yet another of the parked-for-way-too-long blogs. I have edited it for tense and timing.

 


 

Last November, in what was a very déjà vu moment for me, I dropped in on a PHP User group meeting. My very first blog on SDN was a promotion of a PHP User group event in London.

 

Wow! That was over 8 years ago and since that very first stammering blog and some encouragement from Craig Cmehil I have blogging ever since. Well, while I sip on some "Chateau de Chasselas" and reminisce, I do have some point.

 

Aside from the great talk on the new features in PHP 5.6 (Ed: this year PHP7 is about to be released) there was an opportunity for Lightning talks.

 

I quickly grabbed some thoughts together and jumped up.

So what do you tell a bunch of web developers in the basement of a pub in Darling Harbour, Sydney about #OpenUI5 in 3 minutes.

 

Well, to be honest not a great deal, but I was able to acknowledge that SAP user interface is historically and generally recognized as sub-par but that SAP is committed to doing something about it point them to the key urls and then show them a quick example of the new controls.

 

With slightly more preparation I could have perhaps had the 3 or 4 top highlights that could impact them. Of course PHP are not solely developers only using PHP but web developers who deploy whatever it takes to get the job done. That means they use a stack of JavaScript and most of them were using react or angular.

 

Of course I hung around afterwards and was able to chat to a couple of guys about different things they were doing which is the most fun part for me.

 

So, if you have any opportunity to tell web developers the exciting things about what is going on with OpenUI5 then grab it.

 

What is your 3 minute OpenUI5 elevator pitch?


Want to use GitHub as your Project Repository with SAP Web IDE?

$
0
0

Introduction

From time to time, I get asked the question “Can I use an external Git with SAP Web IDE?”

When working with SAP Web IDE I recommend using the integrated SAP HCP Git (Look in the Summary section for some of the reasons).

However, SAP Web IDE enables the use of an external Git as well.

 

As Lidor Tal mentions in his excellent blog post How to Use the SAP Web IDE Git Client, the first thing you have to do to work with Git, is to have a Git repository in your SAP Web IDE workspace”. However, in the examples in Lidor’s blog post, he uses the SAP HCP Git server that is well integrated with SAP Web IDE.

 

This blog post describes how to use GitHub as an external Git as the project repository with SAP Web IDE. It is part of a series of blogs that discuss Git and SAP Web IDE.

  • It is NOT intended to teach Git. For this there are plenty of resources on the web, specifically with most Git services, you’ll find an education section.
  • It is NOT intended to educate on SAP Web IDE Git client functionality.

 

I plan a series of related blogs that will describe how to use additional Git services, such as BitBucket, as Git repositories for a SAP Web IDE project as well as relevant tips & tricks.

 

Overview

In this blog I will discuss:

  • Creating the repository
  • Cloning the repository

 

Creating the Git Repository

When working with external Git repositories, and with GitHub specifically, the first step is to create the repository. This step is probably the only thing that is substantially different from working with the SAP HCP Git. The reason for this is that when working with external Git, the Git repository creation is done through the Git service, while with the SAP HCP Git when creating an HTML5 application in the HCP cockpit or when deploying to HCP from the SAP Web IDE, it is automatically created for you.

 

Steps to create the Git repository on GitHub:

  • Login to your GitHub account.
  • Create a new repository.

GitHub-Create Repo-4_.png

 

  • Fill in the repository fields, mainly Repository name, description, public/private, etc.

Important: Don’t forget to check the “Initialize this repository with a README”.

GitHub-Create Repo-5_.png

 

Cloning the Git Repository

Steps to clone the Git repository from GitHub:

  • In your GitHub account, select the repository to clone and copy the repository link.

GitHub-Clone Repo-1_.png

 

  • In SAP Web IDE, choose the “Clone Repository” option.

GitHub-Clone Repo-3_.png

 

  • In the URL field of the popup, paste the GitHub repository link and push <Tab> button.

Note: The “Host” and “Repository Path” fields are filled-in automatically.

GitHub-Clone Repo-5_.png

 

  • Fill-in the authentication fields. You’re welcome to check the “Remember Me” checkbox for next times.


  • After clicking “OK” you’ll get notifications both in the console pane as well as in the “Highlighted Announcement Area” of the SAP Web IDE. You will see them at the beginning of the clone operation as well as at the completion.

GitHub-Clone Repo-6_.png

 

Congrats !!!

 

A new project was generated in SAP Web IDE that was cloned from GitHub. You can see that, as expected, the project only contains the README.md file.

 

Open the Git History pane. You’ll see that it contains one commit, the initial commit. If you click on the commit, you’ll see that it only contains one file, README.md that was added to the repository (Status – A).

GitHub-Clone Repo-8_.png

Summary & Next Steps

Cloning from an external Git repository is simple, specifically with GitHub.

The major difference from the SAP HCP Git is:

  • You need to create the Git repository in GitHub prior to the start of development.
  • You need to check the “Initialize this repository with a README” checkbox during creation of the repository.


OK, now that the project is cloned in SAP Web IDE, what can I do next?

Following are a few options:

  • Import a project.
  • Create a project from template.
  • ...


A few things to note when working with external Git

  • You cannot deploy from SAP Web IDE to HCP.
  • Creation of branches, and possibly additional repostiroy management operations, should be done via the Git service UI / client.

 

-- Raz

SAPUI5 walkthrough step 5 - controllers, dive in - how does a controller get created?

$
0
0

Welcome to my SAPUI5 Walkthrough, And Dive In blog series, where I’ll not only walkthrough the tutorial, but dive in, to explore the magic behind SAPUI5. Buckle up and sit tight, it's gonna be a bumpy ride as I’m no expert in any way shape or form, just a humble learner who loves coding and likes to get to the bottom of things =。=

 

The source code world is waiting. Ready? Go!

 

Questions answered in the following section:

- Where does the framework pick up our custom defined controller name?

- How does the framework load in our controller code and execute it?

 

In order to explain how does a controller get created, we’ll need to get back the the initViewSettings process (please refer to my last post for detail information on how we get to this point), the XML view root nodes will be parsed, that’s what the screenshot below is doing, and also, that’s also where the framework picks up our controller name, this is the starting point of this post.

01.png

 

After that, it moves on to init controller with the fnInitController function, where createAndConnectController will be called with the view object, and the view configuration object (settings) as its arguments.

02.png

 

It calls the factory function.

03.png

 

Within the factory function, it first requires the controller by its name.

04.png

 

It loads in our code (for module loading and executing, please see my first and second post for more detail information).

05.png

 

Then it executes it.

06.png

 

By calling window.eval.

07.png

 

Questions answered in the following section:

- How does sap.ui.define work?

- How does extend method work?

- What does the prototypical inheritance really look like between sap.ui.core.mvc.Controller (parent) and sap.ui.demo.wt.controller.App (child)?

 

With the module executed, it takes us back to App.controller.js

08.png

 

Next, we dive into the sap.ui.define implementation, sap.ui.define defines a Javascript module with its name, its dependencies and a module factory function.

09.png

 

It first shifts parameters, then converts resource path (sap/ui/demo/wt/controller/App.controller.js) to module name, then declares the module and assigns it to variable oModule.

10.png

 

Then it calls requireAll to resolve the dependencies, we only have one here, the sap.ui.core.mvc.Controller

11.png

 

Its invokes the callback function on aModules, which is a array that holds one item, the constructor of sap.ui.core.mvc.Controller

12.png

 

This is what happen at the end of the callback.

13.png

 

 

The vFactory is our controller factory
  
function (Controller) {

 

   "use strict";

   return Controller.extend("sap.ui.demo.wt.controller.App", {

      onShowHello : function () {

         // show a native JavaScript alert

         alert("Hello World");

      }

   });

} 

 

vFactory.apply(window, aModules) is essentially:

 

ControllersConstructor.extend(“sap.ui.demo.wt.controller.App”, { ... });

14.png

 

The extend creates a new subclass of class sap.ui.core.mvc.Controller with name sap.ui.demo.wt.controller.App and enriches it with the information contained in oSCClassInfo, which calls Metadata.createClass method, which returns the fnClass in the end.

15.png

 

Let’s take a look at the prototypical inheritance between the parent “class” sap.ui.core.mvc.Controller and the child “class” sap.ui.demo.wt.controller.App, ( apologise for my bad drawing : )

16.jpg

 

To verify it in the console, looks like that’s what we expect.

17.png

 

That concludes the sap.ui.define method, our module is now successfully defined. (module state will be set to 3 - READY)

18.png

 

Questions answered in the following section:

- How does the factory function sap.ui.controller work?

- How does view connect to controller and controller connect to view?

 

Now we have our controller “class”, we’ll need the controller instance, and here’s how the framework does it. It calls the sap.ui.controller, the factory function, which creates an instance of an already defined controller class.

19.png

 

With oController, the controller instance created, it then bounce back to createAndConnectController (the 3rd screenshot as you may recall) where the view is connected to the controller, and controller is connected to the view.

20.png

 

Once connected, it returns the view and place it on the page. (you can find more detail information from my last post about what exactly happen between createAndConnectController and view is returned).

21.png

22.png

 

The end

How does modules work in SAPUI5

$
0
0

Welcome to my SAPUI5 Walkthrough, And Dive In blog series, where I’ll not only walkthrough the tutorial, but dive in, to explore the magic behind SAPUI5. Buckle up and sit tight, it's gonna be a bumpy ride as I’m no expert in any way shape or form, just a humble learner who loves coding and likes to get to the bottom of things =。=

 

 

"You just do the programming and solve the problem.

And then onto the next problem and solve that problem.

And solve the next problem too.

And if you solve enough problems, you get to go home."

 

— The Martian

 

I just came back watching the martian, this is one of my favourite lines in that movie, I did change the word ‘math’ to ‘programming’ here, I’d like to see a movie in which Matt Damon solves programming problems

 

I got asked by one of my friends the other day, hey, Ji, why are you’re writing these posts, isn’t that something most of the developers already knew? And even they don’t, people can find out about it in the Chrome console during a tea break. Well, that’s true, for one, I don’t know it, I mean I don’t before dive into the source code, and writing about it helps me sort out my thoughts, this is my way of rubber duck debugging. And reading the framework source code is like reading a suspense novel, you’re the one to reveal the mysteries, isn’t that like the best?

 

Alright, clearly I’m having too much tea, let’s take a deep breath and dive in.

 

SAPUI5 uses AMD (Asynchronous Module Definition) format for its module definition and consumption, AMD format is to provide a solution for modular JavaScript that developers can use, you can find a lot of materials out there on this topic, let’s see how does it work in SAPUI5.

 

This is the code introduced in step 6: modules of the walkthrough tutorial. The MessageToast module is the star of today’s show.

01.png

 

First let’s take a quick look at How does a module defined?, I removed all the methods except the show method of our MessageToast module, so that it can be fit into my screenshot below. We define a module, by calling sap.ui.define, the first parameter could be (1) the name of the module, when omitted, the loader determines the name from the request, that’s what we’re doing here. The rest of the parameters are (2) the array of dependencies and (3) the module factory function, and (4) the boolean depending on whether an export to global names is required.

 

In the factory function, we define a javascript object called MessageToast, ’show’ is one of the method / property added, it returns the MessageToast object in the end, that’s it.

 

sap/m/MessageToast.js

02.png

 

Alright, with what’s our MessageToast module looks like in mind, let’s starting debugging, to reveal these mysteries:

 

- How does a module required?

- How does a module loaded?

- How many states a module could have?

- How does a module made available to global name space?

 

In our example code, the MessageToast module is consumed as one of the dependencies of the App.controller.js.

03.png

 

The MessageToast module is required in the requiredAll method which is responsible for resolving the dependencies.

04.png

 

Within requireAll, the requireModule method is called.

(screenshot #5)

05.png

 

requireModule looks for MessageToast in the global mModules map, if it does not exist, the oModule object will be created, with its first property, state, with value INITIAL.

06.png

 

Before we go any further, let’s take a look at how many states a module could have, this would give us a good picture of what’s next to come.

 

            INITIAL = 0, // Module neither has been required nor preloaded not declared, but someone asked for it.            PRELOADED = -1, // Module has been preloaded, but not required or declared            LOADING = 1, // Module has been declared.            LOADED = 2, // Module has been loaded, but not yet executed.            EXECUTING = 3, // Module is currently being executed            READY = 4, // Module has been loaded and executed without errors.            FAILED = 5, // Module either could not be loaded or execution threw an error

Next, we set module state to LOADING, then, a sync ajax request action is performed, MessageToast.js is retrieved and its content is set to the data property of the oModule object, and also, the module state is now set to LOADED.

 

One of the advantages of AMD format is that modules can be loaded asynchronously, but as you can see, modules in SAPUI5 is now loaded synchronously, according to the documentation: sap.ui.define currently loads modules with synchronous XHR calls. This is basically a tribute to the synchronous history of UI5.

07.png

 

With module loaded, the execModule method is called to execute module.

08.png

 

We first set module state to EXECUTING, then calls window.eval on the module data.

09.png

 

By executing our MessageToast module, we’ll go through the sap.ui.define -> requireAll -> requireEachModule -> execEachModule process again as MessageToast depends on another three modules as we saw earlier. Once dependencies resolved, the callback which we saw at screenshot #5 is called with the aModules array, that’s where the dependencies are kept.

10.png

 

In the callback function, the MessageToast factory function is called with the depended modules.

11.png

That results the MessageToast object filled with all its methods returned and assigned to the content property of oModule object.

12.png

 

Next, we’ll be exporting our module to the global name space cause we passed in export true when we (right, not us, but the framework) define the module.

13.png

 

jQuery.sap.setObject method is called to do the exporting.

14.png

 

Which essentially adds the MessageToast object to the sap.m global namespace / object.

15.png

 

Lastly, we set module state to READY, and clear out the data property.

16.png

 

Then, we come back, the MessageToast and all its methods, .show included are made available to us.

17.png

 

Our Hello World is framed with the beautiful MessageToast control.

18.png

 

The end, happy coding

Develop Hybrid Mobile Apps With SAP Web IDE Part 1

$
0
0

In this and following blogs, I will show you how you can create hybrid mobile applications based on Apache Cordova using the SAP Web IDE and the hybrid app toolkit add-on.


We will build an SAP Fiori app from scratch, adding mobile features and deploying the app to a mobile device.


Info: This is one exersice from the TechEd 2015 (MOB160 - Develop Hybrid Mobile Apps With SAP Web IDE, Hybrid App Toolkit Add-On)


part 1

this part

  • Create a new Kapsel App
part 2
  • Add new Functionality
  • Test In Browser with Cordova Facade
part 3
  • Run The App On Your Mobile Device


 

 

 

 

Requirements

 

You have finished the setup of your environment (HCC, HCP, WebIde).

 

Please use the Google Chrome Browser!

 

 

Create A New Kapsel App

 

Before we can create a new application in SAP Web IDE, we have to add the HAT Plugin.


Add the Hybrid Application Toolkit (HAT) Plugin

 

The Hybrid Application Toolkit (HAT) plugin takes your SAP Web IDE project and packages it into a Cordova container in order to run it as a hybrid mobile app.

In this exercise, we will be using the HAT plugin to provide a Cordova Façade.

 

So first, we must activate the HAT plugin in our SAP Web IDE.

 

 

To enable optional plugins to your SAP Web IDE, open the preferences by selecting Preferences on the left side.

01.png

Click Optional Plugins, enable the Hybrid App Toolkit plugin and click Save

02_.png

 

Restart your SAP Web IDE by refreshing the browser page

 

Go back to the preferences.

 

You should now see a Hybrid Application Toolkit option.

 

Make sure that Cordova Facade Preview option is enabled.

 

Click Save

 

Note: There is no need to press the button "Test Connection“, because since we are using the Cordova Façade there is no local Hybrid Application Toolkit server installed, and the test will always fail.

03.png

 

To come back to the development view, click Development on the left side

04.png

 

 

Create a new Kapsel Project

 

Now we can start to create a new application using the Kapsel template.

 

 

Open the SAP Web IDE in the Chrome browser.

Click File - New - Project from Template

05.png

 

Select SAPUI5 Mobile Application in  the drop down box and then choose SAPUI5 Master Detail Kapsel Application and click Next

07.png

 

Enter a project name, e.g. TechEd and click Next

 

From the Service Catalog list, choose your system

Choose your service and click Next.

10.png

At the Template Customization enter the following fields and click Next

 

Project Settings
Project NamespaceTechEd
Master Section
TitleProducts
OData CollectionProductSet
Search FieldProductID
Main Data Fields
Item TitleProductID
Numeric AttributePrice
Units AttributeCurrencyCode
Detail Section
TitleProduct Details
Additional Attribute 1SupplierName
Additional Attribute 2Description
Information Section
OData NavigationsToSupplier
Navigation Attribute 1PhoneNumber
Navigation Attribute 2EmailAddress
Navigation Attribute 3WebAddress

 

11.png

 

Confirm it by clicking Finish

 

This will create a new Kapsel Application.

Open the Project Folder and choose the index.html.

Click the Run Button

12.png

 

And preview the application

The Application is shown in the Fullscreen-Mode, but we need the functionality of the Preview-Mode

13.png

 

Now we need to adapt some preferencens of the project itself

 

Open the Project Folder and choose the index.html. Right click and select Project Settings

14.png

 

In the project Settings choose Run Configurations

Under run configurations select the first entry under Web Application

15.png

 

Scroll down and check the box for Open with Frame

Press Save to save your settings

 

Press Close to close the Preferences

16.png

 

Run the application again.

17.png

 

Now the application is shown in a frame and at the top we have more functionality (like preview-size, language, QR-Code, etc)

18.png

 

 

Select the search bar on the top and enter HT-1052.

Select the magnifying glass to find the product.

19.png

20.png

 

Close the preview tab.

 

 

In the next partI will show, how you can add new functionality to your App and how you can test it in the browser.

 

 

More Web IDE stuff published by Technology RIG

 

 

See you

Claudi

Develop Hybrid Mobile Apps With SAP Web IDE Part 2

$
0
0

part 1

  • Create a new Kapsel App

part 2

this part

  • Add new Functionality
  • Test In Browser with Cordova Facade
part 3
  • Run The App On Your Mobile Device


 

Add New Functionality To The App

 

Now we will add two new features to the app:

  1. A scan button next to the search field at the Master View. When you click the button, the camera app will start and you can scan a bar- or QR-code of a product. It will then search for this product-ID in the product list.
  2. At the detail view we will add a button at the bottom of the view, where you can save the supplier-contactdata to your addressbook of your mobile device.

 

Because of the Facade plugin we can test this also in the WebPreview of the SAP Web IDE.

 


In your project, open the view folder and right click on the Master.view.xml - Open With - Layout Editor

21.png

 

At the left choose the Button

22.png

 

...and drag and drop it onto the right of the Search Bar.

Untitled.png

 

 

Now change the properties of the new Button

24.png

25.png

 

Click Save.

 

We must now add the functionality that is invoked when the button is pressed.

Right-click on the button and choose Go to Code

26.png

 

 

The XML Code Editor opens.

Here you can find the new button.

27.png

 

Now we have to add more properties to the button description:

tooltip="Bar Code Scanner" press="onBarCodeScan"

28.png

 

And do not forget to save!


Double click on the Master.controller.js to open it.

 

30.png

 

Add the following line at the top of the controller file.

 

jQuery.sap.require("sap.m.MessageBox");

31.png

 

Add also the new function onBarCodeScan to the Master.controller.js


onBarCodeScan:function(){
var that = this;
var code = "";
try {

cordova.plugins.barcodeScanner.scan( function (result) {
sap.m.MessageBox.show("Barcode scanning result:\n" + "Result: " + result.text + "\n" + "Format: " + result.format + "\n" + "Cancelled: " + result.cancelled+"\n","");
code = result.text;
                                                               that.getView().byId("searchField").setValue(code);                               that.onSearch();                  
}, function (error) {

sap.m.MessageBox.show("Barcode scanning failed: ", error,"");
} );
}
catch (e) {
 sap.m.MessageBox.show("Cordova plugin is not available.",""); 
}       
},


And do not forget to save!

32.png

This will use the Cordova barcode scanner plugin to scan a QR-Code or a Bar-Code andstores the result.

It creates a MessageBox which will show the text of the QR- or barcode and what code-format was read.

The result-text is added to the Search-Field and the Search function is then started.

It will also catch the errors if the scanning failed or the Cordova plugin isn’t available.

Note: If you want to improve the layout of the source code, right-click in the editor window - Beautify. This will arrange the code.

 

 

Now we will extend the Detail View.

First close the Layout Editor for Master.view.xml tab

 

Right click on the Detail.view.xml - Open With - Layout Editor


On the left choose the Button Control…

33.png

 

..and drag and drop it to the toolbar at the bottom.

02.png

 

Now change the properties of the new Button

Click Save.

34.png

 

We must now add the functionality that is invoked when the button is pressed.

Right-click on the button and choose Go to Code

35.png

 

The Code Editor opens in which you can find the new button.

36.png

 

Now we have to add more properties to the button description:

 

xmlns="sap.m" press="addContact”

 

And do not forget to save!

37.png

 

Open the Detail.controller.js

 

At the top of the controller add the following line

 

jQuery.sap.require("sap.m.MessageBox");


39.png

 

Then add the function addContact


addContact: function(oEvent) {                if (!navigator.contacts) {                               sap.m.MessageBox.show("Contacts API only supported on Devices/Simulators", sap.m.MessageBox.Icon.INFORMATION, "Add Contact");                               return;                }                var oView = this.getView();                var sEntityPath = "/" + oEvent.getSource().getBindingContext().getPath().slice(1) + "/ToSupplier";                var bpData = oView.getModel().getData(sEntityPath);                //Get Contacts data                var name = bpData.CompanyName;                var phone = bpData.PhoneNumber;                var email = bpData.EmailAddress;                var contact = navigator.contacts.create();                contact.name = {                               givenName: name                };                
var phoneNumbers = [];                var emails = [];                phoneNumbers[0] = new ContactField("work", phone, true);                emails[0] = new ContactField("email", email, false);                contact.phoneNumbers = phoneNumbers;                contact.emails = emails;                contact.save();                sap.m.MessageBox.show("Successfully saved into Device Contacts ", sap.m.MessageBox.Icon.SUCCESS, "Add Contact");  },


And do not forget to save!

40.png

This function obtains the ToSupplier-contact data from the selected product and saves it as a new contact.

Note: To improve the layout of the source code, right-click - Beautify. This will arrange the code.   

 

 

Test In Browser with Cordova Facade

 

We can test this new functionality using the Cordova Façade.

 

Remember that by activating the Hybrid Application Toolkit plugin in SAP Web IDE, we are able to test some of the hardware features of a mobile device directly in the desktop browser.

 

Click on index.html and then the Run button

 

41.png

 

You will see now two new buttons.

42.png

Click the barcode button next to the search field.

 

43.png

 

A Chrome pop up will ask you to allow the camera of your laptop.

Click Allow and scan the QR-Code/Barcode with the camera of your laptop.

 

44.png

45.png

A Message Box will show you the result of your code scan.

46.png

47.png

A search will be performed for the Product having this particular code.

48.png

 

To test the Add Contact functionality in the browser press F12 to open the Developer Tools.

49.png

 

Choose one product and click the Add to Contact


Important:Please click on a product in the master list. When resizing the screen, it is important to make sure that you have really selected a product in the master list.

50.png

 

A Message Box shows a success Message. Your saved contact you can find in the Resources tab in the Developer Tools - Resources - Local Storage - contacts

 

If you get an error: be sure that you have marked one product to open the details. If you use the first-load-details you will get an error.

51.png

 

In the next part I will show, how you can test it on your Mobile Device with the companion App.

 

 

More Web IDE stuff published by Technology RIG

 

 

See you

Claudi

Viewing all 789 articles
Browse latest View live


Latest Images