Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise 7 - Guided Development: Adding Building Block Chart #8

Draft
wants to merge 1 commit into
base: ex6
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions app/managetravels/annotations.cds
Original file line number Diff line number Diff line change
@@ -231,3 +231,37 @@ annotate service.Booking with @(
],
}
);
annotate service.BookedFlights with @(
UI.Chart #BookedFlights : {
$Type : 'UI.ChartDefinitionType',
Title : 'Bookings per Airline',
ChartType : #Column,
Dimensions : [
to_Customer_CustomerID,
AirlineID,
],
DimensionAttributes : [
{
$Type : 'UI.ChartDimensionAttributeType',
Dimension : to_Customer_CustomerID,
Role : #Category,
},
{
$Type : 'UI.ChartDimensionAttributeType',
Dimension : AirlineID,
Role : #Series,
},
],
MeasureAttributes : [
{
$Type : 'UI.ChartMeasureAttributeType',
Measure : BookingUUID,
Role : #Axis1,
},
],
Measures : [
BookingUUID,
],
}
);

33 changes: 14 additions & 19 deletions app/managetravels/webapp/ext/fragment/CustomSection.fragment.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<core:FragmentDefinition
xmlns:core='sap.ui.core'
xmlns='sap.m'
xmlns:l='sap.ui.layout'
xmlns:macros='sap.fe.macros'
>
<VBox core:require="{handler: 'sap/fe/cap/managetravels/ext/fragment/CustomSection'}">
<MessageStrip
text='All bookings for travel {TravelID} got confirmed by the agency.'
showIcon='true'
class='sapUiSmallMarginBottom'>
</MessageStrip>
<l:Grid hSpacing='1' containerQuery='true'
defaultSpan='L12 M12 S12'>
<l:content>
<macros:Table metaPath="to_Booking/@com.sap.vocabularies.UI.v1.LineItem" id="bookingTable"></macros:Table>
</l:content>
</l:Grid>
</VBox>
<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:macros="sap.fe.macros">
<VBox core:require="{handler: 'sap/fe/cap/managetravels/ext/fragment/CustomSection'}">
<MessageStrip text="All bookings for travel {TravelID} got confirmed by the agency." showIcon="true" class="sapUiSmallMarginBottom">
</MessageStrip>
<l:Grid hSpacing="1" containerQuery="true" defaultSpan="L6 M6 S12">
<l:dependents>
<core:Fragment fragmentName="sap.fe.cap.managetravels.ext.fragment.Popover" type="XML"/>
</l:dependents>
<l:content>
<macros:Chart id="myChart" metaPath="@com.sap.vocabularies.UI.v1.Chart#BookedFlights" contextPath="/Travel/to_BookedFlights" personalization="Type,Item" selectionMode="Single" selectionChange="handler.onChartSelectionChanged"/>
<macros:Table metaPath="to_Booking/@com.sap.vocabularies.UI.v1.LineItem" id="bookingTable"/>
</l:content>
</l:Grid>
</VBox>
</core:FragmentDefinition>
34 changes: 29 additions & 5 deletions app/managetravels/webapp/ext/fragment/CustomSection.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
import ExtensionAPI from 'sap/fe/core/ExtensionAPI';
import UI5Event from 'sap/ui/base/Event';
import MessageToast from 'sap/m/MessageToast';
import Popover from 'sap/m/Popover';
import JSONModel from 'sap/ui/model/json/JSONModel';

interface paramType {
data: object;
target: object;
}

/**
* Generated event handler.
*
* @param this reference to the 'this' that the event handler is bound to.
* @param this reference to the Fiori elements ExtensionAPI.
* @param event the event object provided by the event provider
*/
export function onPress(this: ExtensionAPI, event: UI5Event) {
MessageToast.show("Custom handler invoked.");
export function onChartSelectionChanged(this: ExtensionAPI, event: UI5Event<Record<string, any>>) {
if (event.getParameter("selected")) {
//get element in the context of the custom section fragment
//access popover control via stable id
const element = this.byId("sap.fe.cap.managetravels::TravelObjectPage--fe::CustomSubSection::CustomSection--myPopover");
if (element instanceof Popover) {
let popupModel = element.getModel("popup") as JSONModel;

if (!popupModel) {
popupModel = new JSONModel();
element.setModel(popupModel, "popup");
}
//Direct parameter access possible as chart is set to single selection mode
const param = (event.getParameter("data") as [paramType])[0];
popupModel.setData(param.data, true);
// open popover at selected chart segment
element.openBy(
param.target as HTMLElement, true
);
}
}
}