Skip to content

Commit

Permalink
chore: finish fiori.DynamicPage example
Browse files Browse the repository at this point in the history
  • Loading branch information
Thodd committed Aug 16, 2024
1 parent 4ffd6d3 commit 31ad3a2
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 28 deletions.
36 changes: 36 additions & 0 deletions showcases/ui5-tsapp-simple/webapp/control/HTMLElement.gen.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Control from "sap/ui/core/Control";
import { PropertyBindingInfo } from "sap/ui/base/ManagedObject";
import { AggregationBindingInfo } from "sap/ui/base/ManagedObject";
import { $ControlSettings } from "sap/ui/core/Control";

declare module "./HTMLElement" {

/**
* Interface defining the settings object used in constructor calls
*/
interface $HTMLElementSettings extends $ControlSettings {
text?: string | PropertyBindingInfo;
tag?: string | PropertyBindingInfo;
children?: Control[] | Control | AggregationBindingInfo | `{${string}}`;
}

export default interface HTMLElement {

// property: text
getText(): string;
setText(text: string): this;

// property: tag
getTag(): string;
setTag(tag: string): this;

// aggregation: children
getChildren(): Control[];
addChild(children: Control): this;
insertChild(children: Control, index: number): this;
removeChild(children: number | string | Control): this;
removeAllChildren(): Control[];
indexOfChild(children: Control): number;
destroyChildren(): this;
}
}
50 changes: 50 additions & 0 deletions showcases/ui5-tsapp-simple/webapp/control/HTMLElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Control from "sap/ui/core/Control";
import RenderManager from "sap/ui/core/RenderManager";
import type { MetadataOptions } from "sap/ui/core/Element";

/**
* @namespace ui5.ecosystem.demo.simpletsapp.control
*/
export default class HTMLElement extends Control {
static readonly metadata: MetadataOptions = {
properties: {
text: "string",
tag: "string",
},
aggregations: {
children: { type: "sap.ui.core.Control", multiple: true },
},
defaultAggregation: "children",
};

// The following three lines were generated and should remain as-is to make TypeScript aware of the constructor signatures
constructor(idOrSettings?: string | $HTMLElementSettings);
constructor(id?: string, settings?: $HTMLElementSettings);
constructor(id?: string, settings?: $HTMLElementSettings) {
super(id, settings);
}

renderer = {
apiVersion: 2,
render: (rm: RenderManager, control: HTMLElement) => {
rm.openStart(control.getTag(), control);

Object.keys(control.getMetadata().getProperties()).forEach((name) => {
if (name != "tag") {
const value = control.getProperty(name) as string;
if (value) {
rm.attr(name, value);
}
}
});

rm.openEnd();

control.getChildren().forEach((child) => {
rm.renderControl(child);
});

rm.close("div");
},
};
}
1 change: 1 addition & 0 deletions showcases/ui5-tsapp-simple/webapp/control/SimpleControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class SimpleControl extends Control {
rm.style("color", "blue");
rm.style("padding", ".5rem");
rm.style("border", "1px dashed lightblue");
rm.style("margin-bottom", "5px");
rm.attr("title", "${project.version}");
rm.openEnd();
rm.text(control.getText());
Expand Down
110 changes: 104 additions & 6 deletions showcases/ui5-tsapp-simple/webapp/controller/DynamicPage.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,112 @@
/* eslint-disable */
import Controller from "sap/ui/core/mvc/Controller";
import Control from "sap/ui/core/Control";
import VBox from "sap/m/VBox";
import Popup from "sap/ui/core/Popup";
import Event from "sap/ui/base/Event";
//import "@ui5/webcomponents/library";
import JSONModel from "sap/ui/model/json/JSONModel";

function injectStyle() {
const sheet = new CSSStyleSheet();
sheet.replaceSync(`
.text {
display: inline-block;
font-size: var(--sapFontSize);
font-family: var(--sapFontFamily);
color: var(--sapTextColor);
line-height: normal;
white-space: pre-line;
word-wrap: break-word;
cursor: text;
margin: 0;
}
.product-info {
display: flex;
flex-wrap: wrap;
}
.product-info [ui5-avatar],
.product-info .product-info-cell {
margin-right: 2rem;
margin-bottom: 1rem;
}
.product-info-cell {
display: flex;
gap: 5px;
flex-direction: column;
}
.product-description {
display: inline;
max-width: 300px;
}
.availability {
font-size: 1.2rem;
color: var(--sapPositiveTextColor);
}
.price {
font-size: 1.2rem;
color: var(--sapTextColor);
}
.snapped-title-heading {
display: flex;
align-items: center;
}
.snapped-title-heading [ui5-avatar] {
margin-right: 1rem;
}
.snapped-title-heading [ui5-title] {
font-family: var(--sapObjectHeader_Title_FontFamily);
color: var(--sapObjectHeader_Title_TextColor);
padding: 0.3125rem 0 0 0;
font-size: var(--sapObjectHeader_Title_SnappedFontSize);
text-overflow: ellipsis;
min-width: 0;
}
`);
document.adoptedStyleSheets.push(sheet);
}

/**
* @namespace ui5.ecosystem.demo.simpletsapp.controller
*/
export default class DynamicPage extends Controller {
public onInit(): void {}
public onInit(): void {
injectStyle();

// generate some sample data
const sampleDescriptions = [
"10 inch Portable DVD",
"7 inch WidescreenPortable DVD Player w MP3",
"Astro Laptop 1516",
"Astro Phone 6",
"Audio/Video Cable Kit - 4m",
"Beam Breaker B-1",
"Beam Breaker B-2",
"Beam Breaker B-3",
"Beam Breaker B-4",
"Camcorder View",
"Benda Laptop 1408",
"Cepat Tablet 10.5",
];

const images = ["HT-1000.jpg", "HT-1010.jpg", "HT-1022.jpg", "HT-1030.jpg", "HT-2002.jpg", "HT-2026.jpg"];

const items = [];
for (let i = 0; i < 20; i++) {
items.push({
productID: `HT-${i}`,
productName: sampleDescriptions[(Math.random() * sampleDescriptions.length) | 0],
price: `${i.toFixed(2)} EUR`,
imageSrc: `https://sap.github.io/ui5-webcomponents/images/${images[i % images.length]}`,
});
}

const model = new JSONModel({
listTitle: "Products",
items,
});
this.getView().setModel(model, "dpModel");
}
}
5 changes: 3 additions & 2 deletions showcases/ui5-tsapp-simple/webapp/view/Main.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
iconBiometric: '@ui5/webcomponents-icons/dist/biometric-face',
iconBadge: '@ui5/webcomponents-icons/dist/badge',
iconAccept: '@ui5/webcomponents-icons/dist/accept',
iconMessageError: '@ui5/webcomponents-icons/dist/message-error'
iconMessageError: '@ui5/webcomponents-icons/dist/message-error',
iconArrow: '@ui5/webcomponents-icons/dist/slim-arrow-right'
}"
>
<Page id="page" title="{formatter: 'Formatter.formatValue', path: 'i18n>appTitle'}">
Expand All @@ -22,7 +23,7 @@
<content>
<VBox id="contentArea" alignItems="Center" justifyContent="Center" height="100%">
<control:SimpleControl text="Hello World" />
<webc:Button text="nav to DynamicPage" click=".onNavToDynamicPage" />
<webc:Button text="nav to DynamicPage" click=".onNavToDynamicPage" design="Attention" endIcon="slim-arrow-right" />
<Button text="Don't press me!" press="onBoo" />
<webc:Button text="Hello World 123" />
<webc:Input value="Hello World 123" change="onBoo" />
Expand Down
58 changes: 38 additions & 20 deletions showcases/ui5-tsapp-simple/webapp/view/fiori/DynamicPage.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
xmlns:mvc="sap.ui.core.mvc"
xmlns:webc="@ui5/webcomponents"
xmlns:fiori="@ui5/webcomponents-fiori"
xmlns:c="ui5.ecosystem.demo.simpletsapp.control"
core:require="{
Formatter: 'ui5/ecosystem/demo/simpletsapp/model/Formatter',
iconActionSettings: '@ui5/webcomponents-icons/dist/action-settings',
iconShare: '@ui5/webcomponents-icons/dist/share'
iconShare: '@ui5/webcomponents-icons/dist/share',
iconLaptop: '@ui5/webcomponents-icons/dist/laptop',
iconArrow: '@ui5/webcomponents-icons/dist/slim-arrow-right'
}"
>
<fiori:DynamicPage id="page" showFooter="true">
Expand All @@ -27,10 +30,12 @@
<webc:Title text="Special Running Shoe" />
</fiori:heading>

<!-- <div slot="snappedHeading" class="snapped-title-heading">
<webc:Avatar shape="square" icon="laptop" color-scheme="Accent5" size="S"></webc:Avatar>
<webc:Title wrapping-type="None">Special Running Shoe</webc:Title>
</div> -->
<fiori:snappedHeading>
<c:HTMLElement tag="div" class="snapped-title-heading">
<webc:Avatar shape="Square" icon="laptop" colorScheme="Accent5" size="S" />
<webc:Title wrappingType="None" text="Special Running Shoe" />
</c:HTMLElement>
</fiori:snappedHeading>

<fiori:subheading>
<m:Text text="PO-48865" />
Expand Down Expand Up @@ -62,24 +67,37 @@

<fiori:headerArea>
<fiori:DynamicPageHeader>
<!-- <div class="product-info">
<webc:Avatar id="avatar" shape="square" icon="laptop" color-scheme="Accent5" size="L"></webc:Avatar>
<div class="product-info-cell">
<webc:Label>Availability</webc:Label>
<p class="text availability">In Stock</p>
</div>
<div class="product-info-cell">
<webc:Label>Price</webc:Label>
<p class="text price">379.99 USD</p>
</div>
<div class="product-info-cell">
<webc:Label>Product Description</webc:Label>
<p class="text product-description">Super-lightweight cushioning propels you forward from landing to toe-off and has a fast, snappy feel.</p>
</div>
</div> -->
<c:HTMLElement tag="div" class="product-info">
<webc:Avatar id="avatar" shape="Square" icon="laptop" colorScheme="Accent5" size="L" />

<c:HTMLElement tag="div" class="product-info-cell">
<webc:Label text="Availability" />
<m:Text class="text availability" text="In Stock" />
</c:HTMLElement>

<c:HTMLElement tag="div" class="product-info-cell">
<webc:Label text="Price" />
<m:Text class="text price" text="379.99 USD" />
</c:HTMLElement>

<c:HTMLElement tag="div" class="product-info-cell">
<webc:Label text="Product Description" />
<m:Text class="text product-description" text="Super-lightweight cushioning propels you forward from landing to toe-off and has a fast, snappy feel." />
</c:HTMLElement>
</c:HTMLElement>
</fiori:DynamicPageHeader>
</fiori:headerArea>

<webc:List content="{dpModel>/items}" headerText="Products" selectionMode="None">
<webc:ListItemStandard icon="slim-arrow-right" iconEnd="true" description="{dpModel>productID}" additionalText="{dpModel>price}" text="{dpModel>productName}">
<webc:image>
<webc:Avatar size="S" shape="Square" colorScheme="Accent10">
<m:Image src="{dpModel>imageSrc}" />
</webc:Avatar>
</webc:image>
</webc:ListItemStandard>
</webc:List>

<fiori:footerArea>
<webc:Bar design="FloatingFooter">
<webc:endContent>
Expand Down

0 comments on commit 31ad3a2

Please sign in to comment.