UNPKG

ui5_easy_use

Version:

CLI tool for SAP ui5 and SAPUI5 projects to initialize apps, generate pages, insert form and table components, manage routing, and automate i18n bindings

53 lines (44 loc) 1.72 kB
sap.ui.define([ "sap/ui/core/UIComponent", "sap/ui/model/json/JSONModel" ], function (UIComponent, JSONModel) { "use strict"; return class Tile { constructor(controller) { this._controllerJS = controller; } setTile(jsonName, jsonKey, callbackFilter = (item) => item.title !== "Home") { this.modelName = `${jsonName}_tiles`; const modelData = this._controllerJS.getOwnerComponent().getModel(jsonName).getData(); const tiles = this._resolveTileData(modelData, jsonKey); const tileModelData = tiles .filter(callbackFilter) .map(this._toGenericTileData); this._controllerJS.getOwnerComponent().setModel(new JSONModel(tileModelData), this.modelName); } press(evt) { const tile = evt.getSource(); const bindingContext = tile.getBindingContext(this.modelName); const route = bindingContext.getProperty("route"); UIComponent.getRouterFor(this._controllerJS).navTo(route); } _resolveTileData(modelData, jsonKey) { const tiles = (jsonKey && jsonKey.trim()) ? modelData[jsonKey] : modelData; return Array.isArray(tiles) ? tiles : []; } _toGenericTileData(item) { return { title: item.title, subtitle: "Focus Area Tracking", footer: "Focus Area Tracking", unit: "EUR", kpivalue: 12, scale: "k", color: "Good", trend: "Up", route: item.key, icon: item.icon }; } }; });