-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: finish fiori.DynamicPage example
- Loading branch information
Showing
6 changed files
with
232 additions
and
28 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
showcases/ui5-tsapp-simple/webapp/control/HTMLElement.gen.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 104 additions & 6 deletions
110
showcases/ui5-tsapp-simple/webapp/controller/DynamicPage.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters