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

Consolidate JSON Data from Multiple Queries into a Model

$
0
0

I would like to share how to load and consolidate JSON data (with the same structure) from OData services into one JSON model.

 

Let's assume you need to load the following OData services into one JSON model:

/sap/opu/odata/sap/ZGW_SRV/lpadSet?&$filter=ActivityGroup%20eq%20'" +menu[a]+ "'&$format=json"

 

Where menu[a] is a different source of OData service.

var oBundle = jQuery.sap.resources({url : "res/menu.properties"});
var menu = oBundle.getText("LOCAL_MENU").split(",");

 

Here is a sample of JSON data structure:

{

  "d": {

    "results": [

      {

        "__metadata": {

          "id": "https://sapnetweaver.com:8200/sap/opu/odata/sap/ZGW_SRV/lpadSet('SAP_BW_GLB_FIN_MENU')",

          "uri": "https://sapnetweaver.com:8200/sap/opu/odata/sap/ZGW_SRV/lpadSet('SAP_BW_GLB_FIN_MENU')",

          "type": "ZGW_SRV.lpad"

        },

        "ActivityGroup": "SAP_BW_GLB_FIN_MENU",

        "ParentId": "0000000011",

        "ObjectId": "0000000002",

        "NodeType": "F",

        "Text": "Asset Accounting",

        "PDFUrl": "",

        "Menulevel": "02",

        "Description": "",

        "Url": ""

      },

      {

        "__metadata": {

          "id": "https://sapnetweaver.com:8200/sap/opu/odata/sap/ZGW_SRV/lpadSet('SAP_BW_GLB_SD_MENU')",

          "uri": "https://sapnetweaver.com:8200/sap/opu/odata/sap/ZGW_SRV/lpadSet('SAP_BW_GLB_SD_MENU')",

          "type": "ZGW_SRV.lpad"

        },

        "ActivityGroup": "SAP_BW_GLB_SD_MENU",

        "ParentId": "0000000011",

        "ObjectId": "0000000003",

        "NodeType": "F",

        "Text": "Accounts Payable",

        "PDFUrl": "",

        "Menulevel": "02",

        "Description": "",

        "Url": ""

      }

    ]

  }

}

 

Let's defining the necessary variables. Variable ml is the counter to indicate how many Ajax query we have perform. Variable outputdata is an array to store the result of OData query.

var outputdata = [];  oModel = new sap.ui.model.json.JSONModel();  oModel.setSizeLimit(500);  console.log(menu.length);  var ml = 0;  var rund = true;

 

Create a function timeout() to check if all Ajax queries have been completed. How do we know? by checking if the menu length is the same as the variable ml. Once it has been completed, put the outpdata into a JSON model and exit the loop.

function timeout() {  function run() {         if(menu.length==ml && rund == true){          rund = false;          console.log("Done");          clearInterval(myVar);  oModel.setData({  modelData:outputdata         });  oController.getView().setBusy(false);  console.log(oModel);         }     }  var myVar = setInterval(run, 10);  }

 

Set Busy dialog and run the timeout() function:

oController.getView().setBusy(true);  timeout();

 

Perform a loop based on the total number of query in menu[a].

for (a in menu ) {  $.when(  $.get("/sap/opu/odata/sap/ZGW_SRV/lpadSet?&$filter=ActivityGroup%20eq%20'" + menu[a] + "'&$format=json")      .success(function(data) {      for (z=0; z<data.d.results.length; z++){      outputdata.push({ActivityGroup: data.d.results[z].ActivityGroup, Description: data.d.results[z].Description, Menulevel: data.d.results[z].Menulevel, NodeType: data.d.results[z].NodeType, ObjectId: data.d.results[z].ObjectId, PDFUrl: data.d.results[z].PDFUrl, ParentId: data.d.results[z].ParentId, Text: data.d.results[z].Text, Url: data.d.results[z].Url });      }      ml = ml + 1;      })      .error(function(jqXHR, textStatus, errorThrown) {      })  ).fail(function() {  ml = ml + 1;  }  ).done(function() {  });  }

 

We perform the Ajax "Get" query. If is success, under success function we put the result in outputdata array and increase the counter of variable ml.

.success(function(data) {      for (z=0; z<data.d.results.length; z++){           outputdata.push({ActivityGroup: data.d.results[z].ActivityGroup, Description: data.d.results[z].Description, Menulevel: data.d.results[z].Menulevel, NodeType: data.d.results[z].NodeType, ObjectId: data.d.results[z].ObjectId, PDFUrl: data.d.results[z].PDFUrl, ParentId: data.d.results[z].ParentId, Text: data.d.results[z].Text, Url: data.d.results[z].Url });      }      ml = ml + 1;      })

 

If fail to get the result, we also increase the counter of variable ml.

).fail(function() {       ml = ml + 1;  }

 

Let's test it out.

 

In the below example, the total number of query is 7. I have disabled 6 so only 1 is working. We managed to captured all the information and stored in JSON model: modelData.

blog1.jpg

That's it for now. Thanks for reading my blog and let me know if you have any comments.


How to develop right pane plugin for Web IDE (Part 1)

$
0
0

Hi,

In this blog post i will show how to develop plugin that will be integrated into the right pane of the Web IDE.

 

Prerequisites

 

 

Right Pane Plugin

 

In Web IDE you can create different types of plugins (e.g. editor plugin, menu plugin, right/left pane plugins and more)

in this tutorial i will show how to create plugin that will be integrated into the SAP Web IDE right pane area.

currently under the right pane area you will be able to find the following plugins:

  • Search and replace
  • Git
  • Git history
  • Collaboration
  • API reference
  • Outline

rightpane.png

Let's get started!!

 

Open SAP Web IDE

Create a new plugin project template

  • Click File --> New --> Project From Template to open the template creation wizard
    3 - new project.png
    • Select Empty Plugin Project option --> Click Next

      4 - empty plugin project.png
    • Fill in the project name myfirstrightpaneplugin and click Next
    • Fill in the plugin name and plugin description
      • Plugin name: rpaneplugin
      • Plugin description: my first right pane plugin
      • Leave the include sample implementation code unchecked
      • Click Next

              * Please notice that from here this tutorial will be based on the plugin name that you entered in the Plugin Name text field

 

 

                  5 - plugin name.png

    • Click Finish and Web IDE will generate an empty plugin project under your workspace

 

Review the generated code

  • Under your workspace expand the myfirstrightpaneplugin project, There you should find the following folders:
    • Command - contains various commands which will be used in order to execute various operations (e.g. open, close, execute, delete and so on)
    • service– folder containing service implementations and service interfaces (when the interface does not belong to sap.ide.common.service)
    • lib - folder containing external libraries (e.g. open source, reuse libraries etc)
    • image - folder containing image resources
    • css - folder containing custom style sheet (css) files for styling your plugin
    • i18n - localization
    • control - folder containing SAPUI5 custom controls
    • view - folder containing SAPUI5 views (MVC design pattern - SAPUI5 SDK - Demo Kit)
    • plugin.json - main file which contains all the plugin configurations

      6 - project structure.png

Plugin configurations

  • Double click on the plugin.json to open it for editing via SAP Web IDE editor
  • Review the plugin.json structure:
    • name: plugin name
    • description: plugin short description
    • i18n: localization files path
    • requires: other Web IDE plugin that our plugin depends on
    • provides: services which are provides by our plugin (that can be reused by our/other plugins)
    • configures: service configuration of our plugin (commands, styles etc)
    • subscribes: subscribe for Web IDE events

 

Plugin configuration content - Let's fill in our plugin.json file with some relevant content.

  • copy and paste the the following content and replace it with the content of your plugin.json file.

    {

      "name": "rpaneplugin",

      "description": "my first right pane plugin",

      "i18n" : "rpaneplugin/i18n/i18n",

     

     

      "requires": {

      "services": [

                "usernotification",

      "log",

      "command",

      "commandGroup",

      "perspective",

      "selection",

      "content",

       "resource"

      ]

      },

      "provides": {

      "services" : {

                "player" : {

                    "implements": "rpaneplugin.service.Player",

                    "module": "rpaneplugin/service/Player"

                }

      },

     

      "interfaces": {

          "rpaneplugin.service.Player": "rpaneplugin/service/Player"

      }

      },

      "configures": {

      "services": {

                "player:styles" : [

                    { "uri" : "rpaneplugin/css/style.css"  }

                 ],

      "command:commands" : [

      {

         "id" : "rpaneplugin.open",

      "label": "Toggle Player",

      "service" : "rpaneplugin/command/Open",

      "available" : true

      }

      ],

      "commandGroup:items": [

                    {

                          "parent": "view.otherPanes",

                          "command": "rpaneplugin.open",

                          "prio": "30"

                    }

      ],

                 "perspective:views": [

                       { "id": "player", "service": "@player", "area": "right", "visible": "false", "cssclass": "explorer splitterContainer"}

                 ] 

      }

      },

      "subscribes": {

     

      }

    }



  • From a quick look at the plugin.json content we can learn that our plugin
    • Depends on the following plugins:
      • usernotification
      • log
      • command and commandGroup
      • prespective
      • selection
      • content
      • resource
    • Provide one service - the name of the service is player and the implementation should be done in Player.js file
    • Implement one command - the name of the command is Open and the implementation should be done in Open.js file
    • From perspective:views we figure that the plugin will be shown on the Web IDE right pane ("area:"right")



Let's get our hands dirty with some code!!


Create the Open command

 

  • Select the command folder
  • Right click --> New --> File

    7 - new command.png7 - new command.png

  • Enter Open.js as the file name and click OK

    8 - open.png

 

 

 

  • Copy and paste the following content into the Open.js file
define({  execute : function() {  var that = this;  return this.context.service.player.isVisible().then(function(bVisible) {  return that.context.service.player.setVisible(!bVisible);  });  },  isAvailable : function() {  return true;  },  isEnabled : function() {  return true;  }
});

 

Create the player service (2 files)

 

Create the service interface -

  • Select the service folder
  • Right click --> New --> File
  • Enter Player.json as the file name and click OK

    9 - new service interface.png
  • Copy and paste the following content into the Player.json file

 

{  "name" : "rpaneplugin.service.Player",  "description" : "/Sound Cloud Player",  "extends" : ["sap.watt.common.service.ui.Part"] ,  "methods" : {      "isAvailable" : {             "params" : [              {                  "name" : "oDocument",                  "type" : "object"                 }             ],             "returns" : "object"         },  "isEnabled" : {             "params" : [              {                  "name" : "oDocument",                  "type" : "object"                 }             ],             "returns" : "object"         }  }
}

 

Create the service implementation -

 

  • Select the service folder
  • Right click --> New --> File
  • Enter Player.js as the file name and click OK
  • Copy and paste the following content into the Player.js file

 

define(["sap/watt/common/plugin/platform/service/ui/AbstractPart"], function(AbstractPart) {  "use strict";  var Player = AbstractPart.extend("plugin.soundcloud.service.Player", {  init: function() {  },  configure: function(mConfig) {  this.context.service.resource.includeStyles(mConfig.styles).done();  },  getContent: function() {  var oButton = new sap.ui.commons.Button({  text: "Right Pane Button"  });  var oLayout = new sap.ui.layout.VerticalLayout({     width: "100%",     height: "100%",     content: [oButton]  });  oLayout.addStyleClass("playerLayout");  return oLayout;  },  isEnabled: function(oDocument) {  return true;  },  isAvailable: function(oDocument) {  return true;  }  });  return Player;
});

Currently (For Part 1 of the user guide) our plugin is very basic. It contains only a button and that's it.

In Part 2 (coming soon...) of the guide I will show how we can enhance it with more capabilities...


Last but not least create the css file


  • Select the css folder
  • Right click --> New --> File
  • Enter style.css as the file name and click OK
  • Copy and paste the following content into the style.css file
.playerLayout {    width: 100%;    height: 100%;    background-color: white;    position: relative;
}

Finally!! Run the plugin in Web IDE

  • Select the plugin.json file
  • Right click --> Run --> Run Plugin Project

    10 - run plugin.png
  • a New Web IDE instance will be opened in DEBUG MODE. This instance of Web IDE contains also the plugin that we just created
  • To view the plugin click on View --> Toggle Player
    11 - toggle plugin.png
  • A new pane will appear at the right area of the Web IDE with the plugin UI (a simple button with "Right Pane Button" text)

    12 - right pane result.png

 

That's it! Now that you know how to create plugin to the Web IDE you can extend and customize the Web IDE capabilities according to your needs!

 

Stay tuned! Part 2 will come soon...

Extend a Fiori Application with SAP Web IDE Part 1

$
0
0

In this blog, I will show you how to extend a standard SAP Fiori application (here: Purchase Order Approval)  using a SAP Web IDE. The different possibilities of extending a Fiori app view are shown:

Part 1: hide a control,

Part 2: extend by implementing an extension point & replace a view

Part 3: replace a service

 

 

 

 

 

Start creating a new Extension Project


Start SAP Web IDE from your browser

 

Click on Local folder and start by creating a new extension project (File> New > Extension Project)

01.png

 

From step 1 in the wizard, click Remote..., and select SAPUI5 ABAP Repository to access the remote SAP Gateway system which has the
standard SAP Fiori PO Approval application deployed.

02.png

 

 

In the Select Application from SAPUI5 ABAP Repository dialog, select your SAP Gateway System.

NOTE: Please be aware that the server used in this blog is just an example, thus you may not have granted access to it.

03.png

 

All available applications on you system are shown.

04.png

 

Search for "purchase" to show search and filter capabilities

05.png


Select MM_PO_APV Approve Purchase Orders and click OK.

06.png


You may change the proposed project name to e.g. POApprovalExtended or leave it as proposed by SAP Web IDE ‘MM_PO_APVExtension’ Then click Next.

07.png

 

Click Finish.  An extension project is created in your workspace

08.png

 

If authentication is required, enter User Name and PW for your SAP Gateway system.

 

The application Preview Pane automatically opens in Preview Mode. Once the application is loaded and the data has been fetched from the backend, you can see that the application is fully running.

09.PNG

 

Explore the features of the preview. Display the app in the different screen sizes. When in Small size, change the orientation.

At the end, go back to Large or Medium size.

10.png.


In the application Outline, select the Show property Extensible Elements in the drop down list

11.png


Toggle to Extensibility Mode by clicking Preview Mode down arrow. Notice that the app gets a shadow.
Hover the mouse of the controls in the app. Notice how views are highlighted and the scrolling occurs automatically.

12.png

 

Extend the app by hiding an existing control


In the app, navigate to the view S4 by scrolling down in the detail view until you see the Items table, click on an item.

Note:  You may need to toggle off Extensibility Mode, because in Extensibility Mode you cannot navigate to other views.

13.png


We are going to hide the Pricing Conditions in the view S4.

Make sure you are in Extensibility Mode.

Select the Pricing Condition at the bottom of the view. To highlight the control you need to point the mouse pointer to the right or left side of the table.
Alternatively, you may select in the Outline the PricingCondTable under S4.

14.PNG

 

Select Hide Control in the drop-down of Possible Extensions and click OK to hide it - busy indicator appears, followed by a popup message saying the extension was added successfully.

15.png 


Alternatively, you can right-click on PricingCondTable in the Outline and select Hide Control

16.png


A pop-up window appears to indicate that the control is successfully hidden.  Click Yes to refresh the application.

17.png

 

Navigate to S4 view and show the control was hidden

18.png

 

In Outline section, under Show field, drop down to select Extended Elements.  Now, you can see that under S4 element PricingCondTable is listed as Hidden.

19_1.png

 

Close the Extensibility Pane by clicking on the X on the top right

19.png

 

In the next part I will show you how you can extend an Fiori App by implementing an extension point and how you can replace a view.

 

More Web IDE stuff published by Technology RIG

 

 

See you

Claudi

Extend a Fiori Application with SAP Web IDE Part 2

$
0
0

In this blog, I will show you how to extend a standard SAP Fiori application (here: Purchase Order Approval)  using a SAP Web IDE. The different possibilities of extending a Fiori app view are shown:

Part 1: hide a control,

Part 2: extend by implementing an extension point & replace a view

Part 3: replace a service

 

 

Extend the App by adding a new UI field to an extension point

 

Highlight the application folder and start the Extensibility Pane (Tools> Extensibility Pane or Ctrl-Shift-E) if not done yet.

20.PNG

In the application Outline section, select the Show property Extensible Elements in the drop down list

21.png

 

Expand S2 view in the Outline and select the extension point extListItemInfo

22.png

 

Check that the possible extension at the bottom of the Application Outline shows Extend View and click OK.

23.png

 

Show that the extension point was successfully extended and click Yes to refresh the application

24.png

 

Check to see that the element extListItemInfo displays (Extended). Select it and click Go to Code, Extension Code at the bottom

25.png

 

You are redirected back to the Code Editor and the generated extension fragment file is opened

26.PNG

 

Paste the following code:

<ObjectAttribute text="{i18n>view.PurchaseOrder.purchaseOrderLabel}: {PoNumber}"/>

27.PNG

 

The filename has a prefixed * to indicate that the file has been edited and not saved. Click Save.

28.png

 

Run the app in the Extensibility Pane (Tools > Extensibility Pane)

29.png

 

You can now see the added purchase order number and the label in English. The value of the purchase order has been fetched from the backend. 

Check the detail view to verify the same purchase order number.

30.png

 

In the top bar, click on the down arrow next to the language English. Select another language, e.g. French.

31.png

 

Show that the language of the label has changed according to the language selected

32.png

 

Repeat for other languages. At the end, you may go back to English.

 

 

Extend the App by replacing a view


Select S3 view (detail view) in the Outline.

Notice the icon tab bar and remember the number of icons you can see. In the case of the screenshot, there are 2 icons (information and notes). Other POs may have other icons shown, depending on the PO data.

33.png

 

Select Replace with a copy of the parent view in the drop-down of Possible Extensions.  Click OK.

34.png


On the success message, click OK.

Check the application Outline to validate that the S3 view now has the indication of (Replaced with S3Custom)

35.png

 

 

 

Select S3 view in the Outline (if not already selected) and click Go to Code at the bottom.

You are redirected back to the Code Editor and the copied view file opens.

36.png

 

 

You are redirected back to the Code Editor and the copied view file opens.

37.PNG

 

We will be adding more icon tabs to the tab bar.  The attached file contains the extension we want to apply. Open the file and copy the code.


Paste the code to the S3Custom.view.xml file as follow:  At line 68, you can find multiple <IconTabFilter items.  Paste all the code before the <IconTabFilter items.

38.PNG

Click Save to save the file.

 

Select index.html, click Run to run the app.

40.png

Show the result.
41.png


In this particular PO, we have 2 additional icons that have been added.

At the end, you may close the Application Preview browser tab.

 

In the last part I will show you how you can replace a service and extend the data model using the EDMX editor.

 

More Web IDE stuff published by Technology RIG

 

 

See you

Claudi

Extend a Fiori Application with SAP Web IDE Part 3

$
0
0

In this blog, I will show you how to extend a standard SAP Fiori application (here: Purchase Order Approval)  using a SAP Web IDE. The different possibilities of extending a Fiori app view are shown:

Part 1: hide a control,

Part 2: extend by implementing an extension point & replace a view

Part 3: replace a service

 

 

 

 

Replace the OData Service by an extended Service

 

Select your project folder and start a new wizard to replace the service (File> New> Extension)

43.png

 

 

 

Make sure the right project name is displayed in the text field.  Click Next.

44.png

 

Click on Replace Service to select the OData Service replacing wizard, and then click Next.

45.png

 

At wizard step 3 (Data Connection), click on ServiceCatalog to get all available OData Services on the SAP Gateway system.

  • Click the drop down list and select your Gateway system. The list of OData Services is being fetched.
  • Scroll down the list to display all OData Services available on the Gateway system selected.

NOTE: Please be aware that the server used in this blog is just an example, thus you may not have granted access to it.

46.png

 

Search for "poapproval" to display search and filter capabilities.

  • Expand the OData Service and show defined data collections for the OData Service ZGBAPP_POAPPROVAL_DEMO_SRV is shown here.
  • Select the relevant OData Service, ZGBAPP_POAPPROVAL_DEMO_SRV.

47.png

 

Scroll down to WorkflowTaskCollection and expand it

Scroll down to the end of the WorkflowTaskCollection and show that the new field DemoExtension has been added

48.png

 

Go back up to the list, select ZGBAPP_POAPPROVAL_DEMO_SRV and click Next

49.png

 

At wizard step 4, click Finish to confirm adding the extension

50.png

 

We will now add a text field to the UI to display the extended OData field.
Double-click the file extListInfoCustom.fragment.xml in the view folder.

51.png

 

Paste the following code: <ObjectAttribute text="OData Extension: {DemoExtension}"/>

52.png

 

The filename has a prefixed * indicating the file has been edited and not saved. Save the file.

53.png


Select the index.html file and Run the application.

You can now see the new OData field.

55.png

 

 

Extend the data model using the EDMX editor

 

Navigate to the project > model folder. You may want to close all other tabs

56.png

 

Double-click on the file metadata.xml to open the file in the editor

57.png

 

Locate the EntityType with Name="HeaderDetail" You may use the search with Ctrl-f and enter the workflowtask in the search field.

58.png

 

 

 

Add a new property to this EntityType:

<Property Name="NewField" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="New Field"/>

59.png

 

Save the metadata.xml file.

 

Now, we will be adding a UI text field in the detail view to display the added New Field.

Open the file with the extension fragment in the view folder: S3Custom.view.xml
Search for NewField by pressing Ctrl-f and enter ‘newfield’

61.png


Uncomment the block that contains the New Field definition by selecting the commented block

62.PNG

 

Edit> Comment >Toggle Block Comment

63.png

 

Save the file.


Ensure that the URI is /sap/opu/odata/ZGBAPP_POAPPROVAL_DEMO_SRV and that the JSON files as Mock Data Source is unchecked:

  • Select project name, right mouse click, select Project Settings.
  • Click on Mock Data, verify Mock Data Source.

This will allow the system to generate data for the different data fields.

66.png

67.PNG

 

Now we will run the app with Mockdata to demonstrate that the new field is displayed by using the extended metadata.xml file.
Select the file index.html of the application. Run the app (Run> Run with Mockdata).

65.png

 

Verify that data has been generated

68.png

 

 

More Web IDE stuff published by Technology RIG

 

 

See you

Claudi

UI5 and Webstorm IDE. Get Set Go….

$
0
0

Hi Folks. Eclipse IDE may be a stable and powerful tool to develop UI5 applications. But there are many other powerful tools like Jetbrains Webstorm, aptana, komodo etc. Webstorm is a powerful IDE which understands web technologies and it provides easy to use user interface. It has a powerful prediction feature which accelerates web developments. Also comes in handy when working with nodeJS.

 

I had always been a big fan of webstorm IDE for web development. So I was looking for a way to make webstorm compatible with UI5. I found a blog “Configuring JetBrains WebStorm for UI5 development” by Robin van het hof. He has provided a sequence of steps to integrate UI5 with webstorm. It was very helpful for code completions. Now there is a plugin available for UI5 which can be used to create new ui5 project, ui5 templates and ui5 api search. This means, now you can directly install the plugin and kick start your UI5 development hassle free. Thanks to the author “Sebak” for providing this plugin.


So I thought of sharing this here. I will be providing steps to install this plugin in Webstorm. Also I will be using UI5SplitApp-Boilerplate by 6of5 which is readily available for download in github as initial skeleton. UI5 Boilerplate is a skeleton for building Apps based on OpenUI5. This will also save time in building the skeleton of UI5 mobile applications.

 

Pre Requisites:

 

1) Jetbrains Webstorm 9 IDE

2) UI5 Boilerplate

 

Steps:

 

1) Open webstorm IDE. File->Settings

 

2)  Navigate to Plugins->Browse Repositories

 

1st.JPG

 

3) Search for OpenUI5 and install the plugin.

 

2nd.JPG

 

4) Restart Webstorm for the changes to take effect.

 

3rd.JPG

 

Now that you have successfully added UI5 plugin to webstorm, We can import the boilerplate to Webstorm and kick start with UI5 mobile development.

 

Steps:

 

1) Files->Open->Navigate to the boilerplate extracted folder->Open.

 

Download Links:

 

BoilerPlate: https://github.com/6of5/UI5SplitApp-Boilerplate/archive/master.zip

 

After installing the plugin, you can find these features included in webstorm.

 

111.png

 

123.png

 

1234.png

 

12345.JPG

 

Hope this post was useful.

 

Regards,

Safiyu

SAPUI5 – How to Bind to Individual Rows in a Table

$
0
0

This example will show how to add a combobox inside of a table, and be able to set the binding to each row for individual selections. This is useful if you need to separate the rows to provide different information or selections to the user. The concept is using the key values with the selected item from the combobox to see this work. We will be using 2 models for this example, both json files.  Here is the data from the json files for you to use here:

                    mock.json:

{

                  "table": [{

 

                         "name": "Test1",

                         "selectedKey": 2

            },

            {

                         "name": "Test2",

                         "selectedKey": 1

            }]

           }

 

mock2.json:

{

                  "items": [{

 

                         "name": "Product 1",

                         "key": 1

            },

           {

                         "name": "Product 2",

                         "key": 2

            }]

           }

 

The first step is to create your project. We will be using eclipse for now – just create a new SAPUI5 application and give it a name. Go ahead and have it make a default view, just make a page element and insert your table into the tags. We will go add the binding now for the table and the combobox. The Table uses “{model1>table}” for the items and the combobox uses “{model2>items}” for the binding. Be careful to set the selectedKey to use “{model1>selectedKey}” for the combobox for it to work correctly.

 

view.JPG

 

 

Once the view is setup let us go into the controller for the view and add an onInit function.  I only set the models here – you can use either a json file or go ahead and hard code the data right there if you need. Set both models and give them the designations, “model1” and “model2” for this example.

set models.JPG

 

 

Last for the controller, let us create a function that will fire when the combobox is used. I call it “onSelect” for this example. What we do here is get the binding context of the Event, then the path and parameter of the selected item which is then used to get the text from /name to set as a property.

selection.JPG

 

Now we can look at the output from the view:

 

 

table1.JPG

 

 

As you can see, it gives the “test” items as a place holder before the combobox is selected. Once you choose a selection from the combobox – it will cause the value of “selected Item” to change and match your selection.

 

table2.JPG

Turn Your Handwriting into a Font

$
0
0

I was reading this blog by Christine and I thought it was a good idea to try and share it here. Turn your handwriting into a font and use it in your SAPUI5 application.

 

How-to-turn-your-handwriting-into-a-font-for-free.jpg

IMG_0785.PNG

 

Just follow the instruction from Christine's blog above and download the output TTF file: myfont.ttf.

 

Now is the SAPUI5 part.

 

Declare the font-face and .sapMLabel tag in your CSS:

<style>

  @font-face {

  font-family: 'myfont';

  src: url('fonts/myfont.ttf') format('truetype');

  }

 

  .sapMLabel {

  font-family: 'myfont' !important;

  font-size: 1.5rem;

  font-weight: normal;

  }

    </style>

 

And print out some words:

 

 

<script>  var app = new sap.m.App("IconFontApp", {initialPage:"page"});  var page = new sap.m.Page("page", {  title: "Hello World this is testing of SAPUI5",  content : new sap.m.Label({text:"Hello Mobile World! Welcome to the SAPUI5"})  });  app.addPage(page);  app.placeAt("content");    </script>

 

The complete code can be found in the attachment.


To color the first row of a table in SAP UI5

$
0
0

Each row of the table can be given a separate color according to the requirement. The way it was implemented in our case is as shown below:

Creation of UI:

A table is created with the properties as shown below. fixedRowCount is the important property when you are showing the total of the following values in the table other than the fixed one.

img1.png

Changes in CSS:

Add the below css in either index.html file or by adding the particular css in the customized css file by assigning the same in the index.html as show below in the second image.

img2.png

 

img3.png

 

Result:

As a result of the above implantation, the first row is fixed which indicates the sum of the values in the following rows for each column

 

 

img4.png

SAPUI5 Application Best Practices with CRUD support in SAP Web IDE

$
0
0

When you want to learn how to develop a SAPUI5/OpenUI5 application with the master-detail pattern, then you should read the "Application Best Practices" guide - aka TDG (the definitive guide). The famous Northwind OData service also provides a version with CRUD support, which is used in the best practices application with CREATE and READ.

 

The intention of this blog post is to provide you a quick start solution. I was fiddling around with the example in the SAP Web IDE this weekend - so why not share the project with the necessary setup?

 

To get the application quickly up an running you need the application itself which is on on the openui5 github at src/sap.m/test/sap/m/demokit/tdg and you would need to setup a kind of proxy to access the OData service.

 

So I have prepared everything:

 

To quickly get the best practice application up and running:

  • Grab the zip file from my github repository and import it into the SAP Web IDE
  • Import the "north" file which is contained in the repository into the destination in the HCP account cockpit.

  • optional: adapt the "serviceUrl" in the Component.js to get your own session key: (S(sapuidemotdg))
    (session key described in "preparing" section of the best practice guide at the very end)

 

After this steps you have a fully functional application connected to a real backend!

 

>> To quickly have a look at the application you can access the mocked example hosted by SAPUI5. <<

deployed.png

 

A little bit more help needed?

You need a bit more help with SAP Web IDE? May this quickly tinker around guide by me helps and the SCN space of SAP Web IDE.

Or maybe you need a bit more infos about the destination and where to find it.

 

SAP internally I will work together with Christiane Kurz too keep the best practice application up to date in my github repo.

Due to the latest version of the app from github it could happen that the code in the documentation is not up to date - but the big parts of the app are the same.


Do not try to open the views/fragments with the Layout-Editor. Namespaces, fragments and comments are not supported in the actual trial version of the SAP Web IDE.


Outlook

The best practices application uses only the CREATE and READ operations from the CRUD-able Northwind service. The OData Model has the the two functions: remove for DELETE and update for UPDATE.


UPDATE & DELETE

For updating and deleting you need to send the request to the specific URLs like /Products(1). UPDATE needs a payload like in the create example, but without the Navigation properties for Category and Supplier - you find this in the AddProduct.controller.js. A DELETE doesn't need a payload. A successful update/delete returns 204 with no content!

 

Here you find some payload examples, due to our SAPUI5 OData Model we don't need those odata.metadata or odata.type.


Once I have figured out the best way to handle the UPDATE and DELETE operations including the corresponding views/fragments - I will update the copied app, plan contributing back to OpenUI5 and update this blog post or create a follow up. Or maybe in the meantime a pull request in my repo arrives? ;-)


TOC:

 

 

 

The magic behind the curtain

 

Destination service

The Problem: Same Origin Policy

When you are developing web applications you know that you normally can access only resources from your own server (same origin policy). When testing for yourself you could disable web security for Chrome (--disable-web-security) or in Eclipse deploying a servlet to act as a proxy.

 

But we want to develop in the cloud - so the SAP HANA Cloud platform is here to help us with its "destination service". It behaves like a proxy when you are accessing the resource.

 

Solution: North Destination

The destination looks like this - you can just import the "north" file from my repository. (I did not name it northwind because you may have this connection already set up).

 

north_config.PNG

 

neo-app.json aka "Application Descriptor File"

This file must be located in the root folder of our application in the SAP Web IDE and is also contained in my github repository.

 

To put it in very simple words: with this file you create a connection between the destination "north" and your application. It also adresses the sapui5 resources.

 

You can learn more about this file in the HCP documentation: neo-app.json.

 

Declaration in neo-app.json:

neoappjson.png

 

Usage in Component.js:

componentjs.png

 

HCP HTML5 applications

If the above lines have confused you and you want to learn about this stuff I can recommend you:

 

Two and eight, in a state! (New OpenUI5 preview release 1.28)

$
0
0

A new OpenUI5 version 1.28 was released today.

 

OpenUI5 Blog - New OpenUI5 preview release 1.28

 

It has list of features I personally really like and had a need for those for a long time.

 

The main new features are:

XML templating: allows dynamic XMLView content creation without programming. For more information see the XMLTemplating in OpenUI5 documentation.

 

Great feature, so now instead of doing

 

if(sap.ui.Device.system.desktop) {  resultTable = sap.ui.xmlfragment("ResultTable", "desktop.ResultTable", this);
}
else if (sap.ui.Device.system.tablet){  resultTable = sap.ui.xmlfragment("ResultTable", "tablet.ResultTable", this);
}
else if (sap.ui.Device.system.phone){  resultTable = sap.ui.xmlfragment("ResultTable", "phone.ResultTable", this);
}
this.byId("ResultTablePage").addContent(resultTable);

we can use if instruction in the template itself (of course we would need to create famous deviceModel).

 

Expression Binding: this new feature allows using expressions in bindings. This reduces the need to program formatters for views, especially when using XML Templating. For more information see the Expression Binding documentation.

Baby step toward calculated attributes and supply functions (yes, I am from WD* world too ). Please, we need something more complex/advanced than formatter function and this new baby-formatter (expression binding). Every week or so there is a question on the forum about calculated attributes:

 

Databinding to enabled property on SAPUI5 button

"Move" content of table to a new view

StandartListItem on IconTabFIlter

Binding of different sub-elements from the model

Databinding with element count

 

I bet, on every project that is little bit more complex than hiding a button in standard Fiori component there is a need for those. And a Object.defineProperty trick works only for JsonModel.

 

New control sap.m.MessagePage. This is a new control that is primarily designed to be used when a page is empty because no data is available, but can be used for other full-page messages as well. ,

 

New control sap.m.OverflowToolbar. This new control provides the option to move buttons that do not fit in the visible area to an overflow menu.

 

New control sap.m.MessagePopover. This control is a Popover containing a summarized list with messages that can be consumed by the user through several different features like filtering and drilling down to the details.

The more controls, the better! Freshers will be confused and scared even more (kidding ). The last one sounds like a good alternative for sap.ui.ux3.NotificationBar which acts funny sometime when component is embedded in to Fiori launchpad.

 

Standard Margins & Container Paddings. You can now use predefined CSS classes to manage the margins and container paddings in your application without writing custom CSS.

Thank you for that! Juggling with CSS in pre-"sapUiSizeCompact" era was a pain (not everyone likes gigantic sap.m controls look on a desktop and tablets ).

 

And the last one

The first steps towards client-side filtering/sorting on OData Model Data: the final implementation is planned for a later release, but a first experimental version is available in 1.28: by setting the “OperationMode" on a list binding to "Client", you can force the OData model to loadall data from the server and do sorting and filtering entirely in the browser, with no server roundtrip. Useful only when it is guaranteed that the count of data elements is low.

Yo! Finally! Almost a year ago (we were on 1.16 at that time) a had to create

 

sap.ui.model.odata.ODataListBinding.extend("util.model.CacheableODataListBinding", {  metadata : {    publicMethods : [ "filterCachedData", "resetCachedDataFilter" ]  }
});

to handle filtering of OData on the client. Now we have an "official" (even though experimental) way of doing the same.

 

Please, share your thoughts/ideas/experience.

 

Update from 12:22 PST 3/10/2015

Surfing through code is such a fun - now Model is not EventProvider, it is MessageProcessor. Huge change! Exploring, will keep you posted.

seems like it is that announced :

 

Message Handling: New message manager and message model (documentation pending as of 1.28.1), including the new sap.m.MessagePopover control.

How to embed mock data in a SAPUI5 mobile application

$
0
0

Introduction

You might wonder how to create a mobile app with SAP Web IDE which contains all the data inside of it. This could be useful for example if you need to do a demo and you don't have any connectivity with the backend server or if you simply want to test your mobile application.

Well, this is the right blog for you!

Of course there is nothing in this blog related to offline capabilities of a mobile app: what I'll show here is just a way to create an app which contains all the data inside of it.

 

 

Prerequisites

  • SAP Web IDE 1.7 and later (you can register at SAP HANA Cloud Platform to get your development environment)
  • Hybrid Application Toolkit 1.1.0+ downloadable from here

 

 

Walkthrough

This is the list of all the steps we'll go through:

 

  1. Create a SAPUI5 Kapsel app with SAP Web IDE
  2. Generate random data
  3. Deploy and run the app on the mobile device
  4. (Optional) Save real data to the JSON files

 

Let's get started!

 

Create a SAPUI5 Kapsel app with SAP Web IDE

 

The first thing you need to do is to create your mobile application using one of the Kapsel templates provided out of the box from SAP Web IDE. For this example I'm using the SAPUI5 Master Detail Kapsel Application template.

  • Open SAP Web IDE
  • From the File menu choose New --> Project from Template
  • Select the SAPUI5 Master Detail Kapsel Application template and click on Next

2015-03-11_09-55-06.png

  • Enter a project name and click on Next

2015-03-11_09-55-50.png

  • Provide your data connection details and click on Test. For this example I'm using the service /sap/opu/odata/sap/zgwsample_srv/ located on the public gateway service http://sapes1.sapdevcenter.com:8080

2015-03-11_09-56-49.png

  • You will be requested to enter the credentials for accessing the service on the gateway. Enter the credentials and click on Next
  • Enter the necessary information you want to get from the service and click on Next. This is what I want to display for this exercise:

2015-03-11_09-58-12.png

2015-03-11_09-59-28.png

  • Click on Finish
  • Run the application in the standard way to check if all works fine

2015-03-11_10-00-45.png

 


Generate random data

We need to generate mock data so that this app can work with it.

  • Open the model folder located under the project we have just created in SAP Web IDE
  • Right click on the metadata.xml file and select Edit Mock Data

2015-03-11_10-05-23.png

  • In the new screen, select one by one all the collections displayed in the list and for each one click on the Generate Random Data button

2015-03-11_10-06-33.png

  • For each one of the collections, 10 records will be randomly generated and the grid will be automatically populated with the new data. You can also change some data, if you want, and add new records to the existing list
  • Once you have created the mock data for all the collections click on OK
  • In the model folder you will find as many files as the collections you have

2015-03-11_10-08-16.png


Let's enable now the application to take always mock data. The easiest way to do it is to change the init function in the Component.js file.

  • Open the Component.js file and locate the init function
  • Remove completely the if statement you can find starting at line 81 (just after the declaration of the oModel variable)

2015-03-11_10-02-05.png

 

  • Replace the entire statement with the following code:

 

var sServiceUrl = mConfig.serviceConfig.serviceUrl;  this._startMockServer(sServiceUrl);  oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);        this._setModel(oModel);

2015-03-11_10-43-38.png

This code will force the application to use always the mock server with the JSON files we have just generated

  • Save the Component.js file and run the application again in the desktop to check that it's now taking data from the mock server

2015-03-11_10-10-11.png

 



Deploy and run the app on the mobile device

Now you can mobilise the entire application.

  • Start your Hybrid Application Toolkit and deploy the app to your local machine

2015-03-11_10-11-45.png

  • When the deployment finishes, select the index.html file and run the app on your Android/iOS emulator/device.

2015-03-11_10-15-31.png

  • You should be able to use the app now without any connection to the outside world.

2015-03-11_10-18-54.png




(Optional) Save real data to the JSON files

We are using now random generated data. What about if, for some of the collections, we want to use JSON files populated with real data coming from the service? We can do it using a nice trick.

complete_URL_to_the_service + collection_name + "Collection?$format=json"

For example, let's take the Product.json file, so your final URL will be

http://sapes1.sapdevcenter.com:8080/sap/opu/odata/sap/zgwsample_srv/ProductCollection?$format=json

  • Copy this URL and paste it in a new tab of your browser, you should get the following result

2015-03-11_17-00-17.png

  • Select the entire content of the page, i.e. by pressing CTRL+A on Windows or COMMAND+A on Mac, and copy it in the clipboard
  • Go back on SAP Web IDE
  • Double click on the Product.json file to open it, select the entire content of the file, delete it and paste here the content copied in the clipboard

2015-03-11_18-36-23.png

  • The new file is not yet ready, we need to do some adjustments to it. Remove the first 16 characters form the file, that is all the characters before the first open square bracket "["

2015-03-11_17-16-27.png

  • Go at the end of the file and remove the last two character, that is all the characters after the last closed square bracket "]"
  • Save the file
  • Retest your application.


You have done it!

How to consume a HANA XS service on the HANA Trial landscape

$
0
0

Introduction

With this blog I would like to recap here all the steps to consume, with SAP Web IDE, data coming from a HANA XS instance located on the Trial landscape. There have been a lot of discussions around this topic on SCN, with many pieces spread around: for this reason I would like to show a step-by-step procedure to achieve this goal.

Let's give a look to the current architecture: if we want to connect our SAP Web IDE to an OData source like to the HANA XS instance we need to go through the creation of a destination in the HANA Cloud Cockpit, which connects on its turn to a Cloud Connector installed either on a local workstation or on a centralised server.

2015-03-13_12-36-12.png

The Cloud Connector should be then able to connect to the HANA XS service. Unfortunately this is not possible on HANA Trial because for this landscape the Cloud Connector should be able to go through the SAML2 authentication, but as of now this is not possible.

To overcome this issue we could use a workaround, we could install a proxy in between the two things: HANA XS instance on one side and Cloud Connector on the other. This proxy server will be able to accept requests coming from Cloud Connector and translate them in SAML2 requests to forward to the HANA XS instance.

There is already a proxy, created by a SCN user, Gregor Wolf, that plays this role: it's located here.

The installation of this proxy is pretty simple and we'll see it in the next steps.

 

NOTE: for all SAP Employees, at moment this proxy only works if you are disconnected from the SAP Network. Pay also attention that when you are disconnected from SAP network also the Cloud Connector must be NOT using the SAP proxy.

 

 

Prerequisites

  • A HANA XS OData service to consume on the HANA Trial platform
  • SAP Web IDE 1.7+ (you can register at SAP HANA Cloud Platform to get your development environment)
  • HANA Cloud Connector 2.5.1 downloadable from here
  • Gregor Wolf's proxy downloadable from here
  • NodeJS

 

 

Walkthrough

This is the list of the main steps we'll go through:

  1. Installation of the proxy
  2. Cloud Connector configuration
  3. Destination configuration
  4. Consuming the HANA XS service with SAP Web IDE

 

NOTE: For this exercise we are supposing that you already have a Trial HANA XS service to consume. If you don't have one or if you just want to create a basic one by yourself, you can follow another blog of mine:How to create a new OData service using the Web-Based Workbench

 

Let's get started!

 

 

1. Installation of the proxy

Let's start with the installation of the proxy. This is the piece with the green arrow you see in the architecture picture. It will take care of communicating with the HANA XS instance on the Trial landscape. For this reason we have to provide it with the URL to the HANA XS service.


  • Download or clone the Git repository of the proxy located here


  • If you have downloaded the package, extract it in a suitable folder of your drive


  • Open a terminal window and go in the folder with the proxy. You should see something like this:

2015-03-16_12-24-17.png


  • Open the config.js file with your editor

 

  • Choose the port you want to use for this proxy (by default it's set on 7891)

 

  • Enter the host name taken form the URL string to the HANA XS service

(i.e. from "https://s6hanaxs.hanatrial.ondemand.com/i045523trial/dev/empdemo/services.xsodata" take just "s6hanaxs.hanatrial.ondemand.com")

 

  • Leave the other options untouched and save the file

2015-03-16_12-26-12.png

 

  • Start the proxy with the command node server-basic-auth.js

2015-03-16_12-30-33.png


  • You can test the proxy by navigating to the following URL

http://localhost:7891<path_to_the_service>/$metadata where the <path_to_the_service> string is the part of the service URL after the host name (i.e. /i045523trial/dev/empdemo/services.xsodata)


  • You should get something similar to this

2015-03-16_12-32-03.png


  • If you check the terminal window you can see that the proxy is forwarding the requests the browser issues to the HANA XS instance

2015-03-16_12-33-54.png



2. Cloud Connector configuration

Let's now create a new access control in the Cloud Connector.

  • Open the Cloud Connector administration console

 

  • Click on the Access Control menu item and click on the Add button on the top

2015-03-16_12-37-55.png

 

  • Create a new mapping with the following settings and click on Save
ParameterValue
Virtual Hosthanaxs.virtual
Virtual Port8080
Internal Hostlocalhost
Internal Port7891
ProtocolHTTP
Principal TypeX.509 Certificate
Back-end TypeNon-SAP System

 

2015-03-16_12-38-56.png

 

  • For the added mapping, define also a new resource path

2015-03-16_12-39-19.png

 

2015-03-16_12-39-44.png

 

  • You should get something like this

2015-03-16_12-40-10.png

 

 

3. Destination configuration

Create a new destination for the service URL you configured as the virtual URL in the Cloud Connector.


  • Create a new destination (i.e. "hanaxs") with the following parameters:
ParameterValue
Namehanaxs
TypeHTTP
Descriptionhanaxs
URL<the virtual URL with port defined in the Cloud Connector (i.e. http://hanaxs.virtual:8080/)>
ProxyTypeOnPremise
CloudConnectorVersion2
AuthenticationBasicAuthentication
User<hana_trial_user_for_the_service>
Password<hana_trial_password_for_the_service>

 

  • Add these 3 additional properties as well

 

PropertyValue
WebIDEUsageodata_xs,odata_gen
WebIDEEnabledtrue
WebIDESystem<the same name of the destination> (i.e. hanaxs)

 

  • Save the destination, you should get something like this. It will take up to 5 minutes for the changes being applied

2015-03-16_12-53-39.png

 

  • If you want you can also test the destination by typing in the browser a URL like this:

https://webide-<your_hana_trial_account>.dispatcher.hanatrial.ondemand.com/destinations/hanaxs/<path_to_the_service>/$metadata

where <your_hana_trial_account> is the account you use for SAP Web IDE and <path_to_the_service) is the string just after the host name in your service URL

10.png

 

 

4. Consuming the HANA XS service with SAP Web IDE

The final step is to create a SAP Web IDE project to consume the OData service.

  • Open SAP Web IDE

 

  • Choose File --> New --> Project from Template

 

  • Select one of the templates (i.e. SAP Fiori Master Detail application) and click on Next

 

  • Enter the name of the application and click on Next

 

  • On the Data Connection page, click on Service URL, choose the name of the destination you created in the previous step, enter the path to your OData service (you can omit the protocol and the host name since they are defined in the destination), click on Test and, once you get the details on the right, click on Next

2015-03-16_13-05-43.png

 

  • Define the fields you want to see in the application

2015-03-16_13-09-40.png

 

  • Click on Finish

 

  • Run the application and you will get it perfectly working:

2015-03-16_22-21-38.png

 

 

Congratulations! You have successfully consumed your HANA XS OData service with SAP Web IDE.

To Realize Real Time Search In UI5 Table By Filters

$
0
0

Test Data Structure:

{"Materials":[                                     {                                      "MaterialID":"4231090440",                                      "MaterialDescription":"BRAKE CHAMBER TYPE 27 BC",                                      "ProductCategoryDescription":"Drum Brake",                                      "CreatedBy":"Eddie Smoke",                                      "DateTime":"07/16/2014 5:56AM EST",                                      "MaterialIDhref":"#MaterialIDhref",                                      "MaterialDescriptionhref":"#MaterialDescriptionhref",                                      "CreatedByhref":"#CreatedByhref"                                      },                                      {                                      "MaterialID":"4231060140",                                      "MaterialDescription":"BRAKE CHAMBER TYPE 24 44",                                      "ProductCategoryDescription":"Drum Brake",                                      "CreatedBy":"Eddie Smoke",                                      "DateTime":"07/16/2014 5:57AM EST",                                      "MaterialIDhref":"#MaterialIDhref",                                      "MaterialDescriptionhref":"#MaterialDescriptionhref",                                      "CreatedByhref":"#CreatedByhref"                                      }                         ]
}

 

Step1: Create A Table

var oTable = new sap.ui.table.Table("oTable",{            selectionMode: sap.ui.table.SelectionMode.Single,            visibleRowCount : 6,            firstVisibleRow : 0,            title:"oTable",            toolbar: new sap.ui.commons.Toolbar({items: [                                                          new sap.ui.commons.Label({text : "Find"}),                                                          new sap.ui.commons.TextField("SearchText",{liveChange: oController.Change}),                                                         new sap.ui.commons.Button({text: "Go", press: oController.Search})                                                ]}),           columns:[                    new sap.ui.table.Column({label: "Material ID", template:new sap.ui.commons.Link().bindProperty("text", "MaterialID").bindProperty("href", "MaterialIDhref"), filterProperty:"MaterialID" }),                    new sap.ui.table.Column({label: "Material Description", template:new sap.ui.commons.Link().bindProperty("text", "MaterialDescription").bindProperty("href", "MaterialDescriptionhref"), filterProperty:"MaterialDescription" }),                    new sap.ui.table.Column({label: "Product Category Description", template:"ProductCategoryDescription", filterProperty:"ProductCategoryDescription" }),                    new sap.ui.table.Column({label: "Created By", template:new sap.ui.commons.Link().bindProperty("text", "CreatedBy").bindProperty("href", "CreatedByhref"),filterProperty:"CreatedBy"  }),                    new sap.ui.table.Column({label: "Date/Time", template:"DateTime", filterProperty:"DateTime" })                    ]        });

Key:

1: bind a filterProperty for every column  you want to check as line 12 - 16

2. attach the event liveChange of  sap.ui.commons.TextField by a recall function by yourself( in this I named my function Change) as line 8

 

Step2:Realize The Recall Function

Change: function(oEvent){                        var oTable = sap.ui.getCore().byId("oTable");               var searchText = oEvent.getParameters().liveValue;                var filters=[];                if(searchText.trim()!=''){                        var filter1 = new sap.ui.model.Filter({path:"MaterialID",operator:sap.ui.model.FilterOperator.Contains,value1:searchText});             var filter2 = new sap.ui.model.Filter({path:"MaterialDescription",operator:sap.ui.model.FilterOperator.Contains,value1:searchText});             var filter3 = new sap.ui.model.Filter({path:"ProductCategoryDescription",operator:sap.ui.model.FilterOperator.Contains,value1:searchText});             var filter4 = new sap.ui.model.Filter({path:"CreatedBy",operator:sap.ui.model.FilterOperator.Contains,value1:searchText});             filters = [filter1,filter2,filter3,filter4];            var finalFilter = new sap.ui.model.Filter({filters:filters, and:false});            oTable.getBinding("rows").filter(finalFilter, sap.ui.model.FilterType.Application);        }else{            oTable.getBinding("rows").filter([], sap.ui.model.FilterType.Application);            }                    }

Key:

1. get the live value of text filed real-time(as line 6)

2. logical check of now value in text filed(as line 10)

3. create several "and:false" filters and combine them into a final filter to realize checking several columns at the same time( In default if you combine several filters, their communications are AND, after setting the "and:false", it become OR)



To realize real-time search in a normal UI5 table is a problem in my work, and I haven't found any articles about this, so I post this post.

I hope it can help you!

Thanks for watching!

Few tips for beginners to become a PRO in UI5.

$
0
0


Hey All,

 

    Having been an active user in the UI5 community since a year i have analyzed a bit on where developers go wrong when trying to learn UI5. So i just thought of blogging out my personal views on how to approach it & maybe the way how i learnt it.

 

Me primarily being a front-end dev, i was interested to explore much of what's happening rather than just the bits & pieces of the development. So for anyone looking to be a PRO, i would recommend some of these

 

 

1. Start with a simple text editor. Ex - Notepad++, sublime text.

 

Well, it is know that SAP offers awesome development tools like SAP web ide, Plugins for Eclipse & there are also other third party tools. But as a beginner when we start using these i believe we don't get the underneath basic knowledge on how the complete app works. We start coding directly in the views using the templates offered by SAP. These come handy for development but when you really want to learn i would recommend to use an editor like notepad++/sublime text where you'll have to completely code the entire app from the scratch. I too started my learning as a beginner using the Eclipse plugins but when i switched to Sublime text where i had to code completely i realized how much i actually knew UI5.


texteditorlogocollage.png

 

 

2. Learn to use the API reference & don't copy the code from UI5 demokit

 

  With UI5, there a lot of options where the readymade code is available. You’ll find the code for all the controls in UI5 Demokit. I was blindly doing the same but i had no idea what other options the controls offered apart from the one provided in the sample code. That's when i came to know that you have an API reference in the UI5 demokit which has documented all the properties, aggregations, methods, events of the controls. Since i learnt how to code a single control by following the API reference, i was able to do the same for all the other controls and more importantly i knew what all the controls offered now.


http://img.picturequotes.com/2/2/1378/you-were-born-an-original-dont-die-a-copy-quote-1.jpg

 

 

3. Knowing how to Debug is a must!

 

  More often when we run the code it ends up with some issues. Posting the code in SCN/getting help from colleagues immediately we face an issue is not going to really help in a longer run. Actually browsers say chrome have inbuilt debugging tools which we will have to use it to the best to debug the issue. In fact, it's really simple once you learn how to setup a breakpoint & how to check the requests in the network log to get a pointer on most of the issues. The debugging skills helps us solving the issues by ourselves, but when that doesn't help creating a discussion in SCN/stackoverflow is good to go.


http://www.ibmsystemsmag.com/getattachment/c247b44e-07b3-4ca9-9724-d913fb9dc3c2/

 

4. Start with js views & Learn JavaScript as much as you can

 

  Often there leads to a confusion on which view to use in the development. Though XML views are the one being recommended, for any beginner i would suggest js views. The intention is to make sure that we start writing as much as code in JavaScript as JavaScript is something to be learnt to learn UI5! Being comfortable with JavaScript is indeed required here. Migrating from JS view to XML view is not really a tougher one.

 

  For anyone whose career is into web development JavaScript plays a vital role, be it front-end/back-end. So here learning JavaScript is directly proportional to learning UI5. I would recommend to go through blogs/docs on JavaScript. I got a better insights by reading the design patterns in JavaScript by Addyosmani& also on object oriented JavaScript.


http://www.keepcalmstudio.com/_gallery/300/O2tJXT.png

 

 

6. Try to solve questions in SCN

 

     Trying to solve the questions is SCN has remarkably made me improvise my skills. It's like 'The more you solve, the better you become'! And more than that it gives me a confidence that I’ll be able to tackle most of the issues if i face.


http://www.barbiedecker.com/wp-content/uploads/2014/11/Problems-solving.jpg

   

7. Look out the source code of UI5

 

     The source code of UI5 is something where we get to see the code written by some of the most intellectual guys. It might look a bit mystery out there in the beginning, but going forward you'll be able to take away few good things  from the code & that how one becomes a PRO at it.

 

http://d1lwft0f0qzya1.cloudfront.net/dims4/COKE/43f697d/2147483647/thumbnail/596x334/quality/75/?url=http%3A%2F%2Fassets.coca-colacompany.com%2F5a%2F02%2Febc1d0f842468408be5de9740884%2Fcoding1-604.jpg

 

I would suggest these for the one who wants to have a career with UI5 or front-end technologies in a longer run. It might take a bit of time but it'll prove to be worthy & at least have worked out for me.  I would also like to know the views of UI5 experts out here on how they approached

 

 

- Sakthivel


"The User is Drunk".....the new UX paradigm?

$
0
0

     Perhaps you have heard of "Design Thinking" as much as it has been covered on here and in conferences like SAP TechEd, but I can pretty much bet you have not head of "The User is Drunk" design. (haha)

 

     Part of my morning routine (and sometimes after wrapping up work at whatever time), I like to watch streams of people coding (ie. WatchPeopleCode.com or TWITCH "programming" or "game development" channels). It's fun to see "how the other half lives". (haha) This morning, one of the streamers I often chat with left this video playing while taking a short break, and it really struck home with me in several areas. As provocative as the title may sound "The User is Drunk" is a good way of looking at your UX design.

 

     This is by no means an attempt to rake up clicks/views and/or spam/advertise you. Heck, I don't even know who this company (or this guy) is. But I sure do like their message!

 

 

Key points for me....

  • A lot of the "stuff" on the web are just echos of real life.
  • Great UI isn't there. (it is best when users do not realize they are interacting with a UI)...and to that end, your UI should be as "porous" as possible.
  • Guide users (by and large, they are "attention poor"....lead them....as SAP does well with things like "guided procedures")
  • Say it twice (state key points 2 times always......state key points 2 times always)
  • Respect your users (your user is "drunk not dumb"...do not lie to them or attempt to simplify too much.....a user with 160 IQ that is drunk still has a 160 IQ...but just a lot less patience! hahaha)

 

For a 4 minute or so video, I thought it was put together quite well and made me think about what I build/design for my own work....so now, I am off to drink a few adult beverages and re-test my apps! haha Hope you enjoyed this departure from the usual SAP-centric topics.

XSS Prevention in UI5

$
0
0

Hi,

 

this is my first blog post in the SCN - and I hope it will be helpful.

 

At first I have to say that XSS prevention is part of the UI5 framework. If you bind a model to a view and malicious code is inserted into an UI5 control, the JS-code will be escaped and not executed in the browser.

ui5.png

 

So far so good... But is it possible to write malicious code to your database by an OData-Model? Yes it is!!!

If you don't escape the user-inputs the code will be written into the database:

DB.png

You should prevent this server side (never trust a client), because if a non UI5 client will use your OData Service it will receive the infected JS-Code. And if this client will not esescape them, the JS code will be executed in the clients browser. You can escape strings by using the following ABAP statements in the implementation of your OData Gateway.

escaping_data.png


The result is a clean database:

DB_escaped.png

 

Greetings,

 

Stefan

Custom UI5 themes showcase

$
0
0

leonardo.jpgThis morning I had a discussion with Robin van het Hof and Vladimirs Semikins on Twitter (storify link) about custom UI5 themes. Vladimirs indicated that he created a theme of approximately 3,000 lines of CSS. Although probably quite some of those lines are generated using LESS (I hope), I have the feeling that he made quite an effort into turning his theme into something really custom.

 

Of course I was very interested about what it eventually looked like and asked him if he could share a few screen shots. He will have to go back to ask for permission, but I'm hoping for the best.

 

At the same time, Robin mentioned that he is going to use UI5 for the external marketing site of his company as well, promising another excellent custom UI5 theme to see the light. He explicitly mentioned that he would make an effort to NOT make it look like UI5.

 

I think it would be nice and fun if we could bundle our UI5 theming efforts somehow and create a showcase of screenshots of custom UI5 apps or sites, to form an inspiration or perhaps even boilerplate for others. Because of that, I've set up a Wiki page for this purpose on Custom UI5 themes showcase. I hope many UI5 theme developers will show what they have made there.

 

To kick it off, I have added some screenshots of an OpenUI5 application I have built for Ziggo. It would be great if you could also add your screenshots to the Wiki page. Adding your screenshots is already super-duper, adding a zip with the theme will instantly turn you into a real UI5 theme hero, and will grant you eternal honour and everything

 

Click here to add your theme --> Custom UI5 themes showcase

Rounded Tiles in UI5

$
0
0

I've been working with OpenUI5 for a few months now and I grew tired of the sharp tiles provided by the standard library.

 

If you are not familiar with OpenUI5, go and check the great work they are doing on www.openui5.org

 

Good thing OpenUI5 allows the inheritance between components so that we can create our own based on existing ones... I order to make the launch page of the application I'm working on at the moment more attractive, I decided to create my own tile component based on the standard tile. This is how it looks:

 

roundedTile

 

The design is fully responsive and customisable, when creating the object the following colours parameters can be provided:

  • border of the circles
  • background of the circles
  • icon and text colour

 

In order to achieve that, some JS and CSS are required... I will try to cover it all step by step.

1) The folder structure

 

In order to keep things organised, I created a folder "controls" in my workspace that is the container of my custom controls.

 

When you do something like that, don't forget to register the resource path within your app so that the files can be found using jQuery.sap.registerResourcePath('controls', './controls');.

 

The folder contains 3 files:

  • roundedTile.css containing the CSS rules for the control
  • roundedTile.js containing the metadata of the control
  • roundedTileRenderer.js containing the logic to render the control

 

 

2) The CSS file

 

The CSS file is not very long and contains the rules that will be applied to the different DOM elements that the roundedTileRenderer will create.

 

 

3) roundedTile.js

 

This file defines the extra properties of the object. Keep in mind that this object is inheriting from the StandardTile object and thus has all the properties of the parent object such as icon, title, count,... The properties added are: iconColor, bgColor and borderColor.

 

metadata : {     properties : {          // Icon color property with default value to standard UI5 blue          iconColor : {               type : "string",               defaultValue : "#007cc0"          },          // Background color property with default value to white          bgColor : {               type : "string",               defaultValue : "rgb(255, 255, 255)"          },          // Border color property with default value to standard UI5 blue          borderColor : {               type : "string",               defaultValue : "#007cc0"          }     }
}

4) roundedTileRenderer.js

 

The renderer inherits from the TileRenderer not from the StandardTileRenderer as I need to have access to the div surrounding the tile, not only the content. There's thus a render function as well as a _renderContent.

 

The render method is the one inherited from the TileRenderer and creates the outer div.

The _renderContent is the one in charge of the content of the tile.

 

 

5) Using the control

 

The use of the control is pretty easy, after including the file via

 

jQuery.sap.require("controls.RoundedTile");

 

In the example bellow, I have an Array of JSON objects defining the tiles properties like:

 

var tiles = [{     title: "Tile 1",     icon:"Chart-Tree-Map",     iconColor:"#ffffff",     bgColor:"rgb(57, 123, 110)",     borderColor:"rgb(57, 123, 110)" 
},
...
];

 

Then I loop on that Array and create the roundedTiles as follow:

 

for(var c in tiles){     var tileItem1 = new controls.RoundedTile();     tileItem1.setTitle(tiles[c]["title"]);     tileItem1.setIcon("sap-icon://"+tiles[c]["icon"]);     if(tiles[c]["iconColor"])          tileItem1.setIconColor(tiles[c]["iconColor"]);     if(tiles[c]["bgColor"])          tileItem1.setBgColor(tiles[c]["bgColor"]);     if(tiles[c]["borderColor"])          tileItem1.setBorderColor(tiles[c]["borderColor"]);     this.getView().oTilesContainer.addTile(tileItem1);
}

 

And there you go, your tiles will be rounded.

 

Note that in this first version of the control, I didn't manage the counter yet...

I'll keep the post updated as I will update the control...

 

Any questions/comments are welcome!

 

Jon.

SAPUI5 Controls Cheat Sheet

$
0
0

Introduction

 

While working on new SAPUI5 projects with clients who have been used to seeing jQuery screens or simple HTML pages, in most of the cases they are not aware of what SAPUI5 is capable of doing. The old saying goes here - what you don't see is what you don't get

I created this cheat sheet which contains screen shots of all possible sap.m controls which can serve as a good intro to the technology. It can also serve as a guide to UX designer, just in case you have one in your project.

This was a large high quality PDF file so that it can be zoomed to examine each control image but then I realized that I will not be able to upload it in SCN forums. Hence I exported all the pages as images and pasted it in my blog.


I hope this will be useful for everyone.

Page-01.jpegPage-02.jpegPage-03.jpegPage-04.jpegPage-05.jpegPage-06.jpegPage-07.jpegPage-08.jpegPage-09.jpeg

Viewing all 789 articles
Browse latest View live




Latest Images