Samples / Stack / Smart Controls

SmartChart with NavPopover

an analytical service - you supply the path

Class
z2ui5_cl_smps_app_479
Repository
abap2UI5/samples-stack
UI5 libraries
sap.m, sap.ui.comp, sap.ui.core
Lowest UI5 release
1.71
In the browser
Needs a system - opens in the playground for reading
Controls it builds
sap.m.Page, sap.m.Shell, sap.ui.comp.navpopover.SemanticObjectController, sap.ui.comp.smartchart.SmartChart, sap.ui.core.mvc.View

The class

" @keywords smartchart navpopover semanticobjectcontroller chart semantic object navigation
" @summary an analytical service - you supply the path
CLASS z2ui5_cl_smps_app_479 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

  PROTECTED SECTION.
    " THIS PATH IS A PLACEHOLDER AND MUST BE REPLACED - the app shows an empty
    " chart until it points at a real service.
    " Unlike the other smart control demos, a SmartChart cannot fall back to the
    " Gateway demo service GWSAMPLE_BASIC: it needs an ANALYTICAL OData V2
    " service - properties marked sap:aggregation-role dimension/measure plus the
    " UI.Chart annotation the chart layout comes from. No such service is part of
    " any standard system, so there is no honest default to ship here; enter the
    " analytical service of your system, with an entity set carrying the
    " dimensions and measures the view expects.
    CONSTANTS c_odata_service TYPE string VALUE `/sap/opu/odata/sap/<YOUR_ANALYTICAL_SERVICE>/`.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smps_app_479 IMPLEMENTATION.

  METHOD z2ui5_if_app~main.

    IF client->check_on_navigated( ).

      DATA(view) = z2ui5_cl_ui5_view_builder=>factory(
          )->ele( n = `View` ns = `mvc`
              )->a( n = `displayBlock`     v = `true`
              )->a( n = `height`           v = `100%`
              )->a( n = `xmlns`            v = `sap.m`
              )->a( n = `xmlns:mvc`        v = `sap.ui.core.mvc`
              )->a( n = `xmlns:navpopover` v = `sap.ui.comp.navpopover`
              )->a( n = `xmlns:smartChart` v = `sap.ui.comp.smartchart` ).

      DATA(page) = view->ele( `Shell`
          )->ele( `Page`
              )->a( n = `title`          v = `abap2UI5 - Smart Controls - SmartChart`
              )->a( n = `showNavButton`  b = client->check_app_prev_stack( )
              )->a( n = `navButtonPress` v = client->_event_nav_app_leave( ) ).

      " The chart, its dimensions/measures and the personalization dialog are all
      " metadata-driven; the SemanticObjectController turns the annotated Category
      " dimension into a navigation popover and reports its two events back here.
      page->ele( n = `SmartChart` ns = `smartChart`
          )->a( n = `enableAutoBinding`       b = abap_true
          )->a( n = `entitySet`               v = `Products`
          )->a( n = `useVariantManagement`    b = abap_true
          )->a( n = `persistencyKey`          v = `SmartChart_Explored`
          )->a( n = `useChartPersonalisation` b = abap_true
          )->a( n = `header`                  v = `Products`
          )->ele( n = `semanticObjectController` ns = `smartChart`
              )->ele( n = `SemanticObjectController` ns = `navpopover`
                  )->a( n = `navigationTargetsObtained` v = client->_event( `NAV_TARGETS_OBTAINED` )
                  )->a( n = `navigate`                  v = client->_event( val = `NAVIGATE`
                                                                                          arg = `${$parameters>/text}` ) ).

      client->view_display( val = view->stringify( ) switch_default_model_path = c_odata_service ).

    ELSEIF client->check_on_event( `NAV_TARGETS_OBTAINED` ).
      " The tutorial answers this event by composing the navigation popover
      " imperatively (oParameters.show( ) with LinkData entries and a SimpleForm of
      " Title/Image/Text). That is frontend construction of controls, which a thin
      " frontend does not express - the wire stays, and the popover keeps the
      " content the SemanticObjectController derives from the annotations itself.
      client->message_toast_display( `Navigation targets obtained` ).

    ELSEIF client->check_on_event( `NAVIGATE` ).

      DATA(text) = client->get_event_arg( ).

      IF text <> `Homepage`.
        client->message_box_display( text  = |{ text } has been pressed|
                                     type  = `information`
                                     title = `SmartChart demo` ).
      ENDIF.

    ENDIF.

  ENDMETHOD.

ENDCLASS.