Column Name | Column Technical name |
Notification | QMNUM |
Notification Type | QMART |
Notification Date | QMDAT |
Priority Text | PRIOKX |
Priority | PRIOK |
Description | QMTXT |
Equipment | EQUNR |
Malfunction Start | AUSVN |
{
"NotificationCollection": [{
"QMNUM": "<String: Notification #1 ID value>",
"QMART": "<String: Notification #1 Type value>",
"QMDAT": "<String: Notification #1 Date value>",
"PRIOKX": "<String: Notification #1 Priority text value>",
"PRIOK": "<String: Notification #1 Priority value>",
"QMTXT": "<String: Notification #1 Description value>",
"EQUNR": "<String: Notification #1 Equipment ID value>",
"AUSVN": "<String: Notification #1 Malfunction Start Date value>"
}, {
"QMNUM": "<String: Notification #n ID value>",
"QMART": "<String: Notification #n Type value>",
"QMDAT": "<String: Notification #n Date value>",
"PRIOKX": "<String: Notification #n Priority text value>",
"PRIOK": "<String: Notification #n Priority value>",
"QMTXT": "<String: Notification #n Description value>",
"EQUNR": "<String: Notification #n Equipment ID value>",
"AUSVN": "<String: Notification #n Malfunction Start Date value>"
}]
}
iw29-mobile-table/uimodule/webapp/
{
"_version": "1.0.0",
"sap.app": {
"id": "iw29mobiletable",
"type": "application",
"applicationVersion": {
"version": "1.0.0"
},
"title": "{{appTitle}}",
"description": "{{appDescription}}"
},
"sap.ui": {
"technology": "UI5",
"icons": {
"icon": "",
"favIcon": "",
"phone": "",
"phone@2": "",
"tablet": "",
"tablet@2": ""
},
"deviceTypes": {
"desktop": true,
"tablet": true,
"phone": true
}
},
"sap.ui5": {
"flexEnabled": false,
"rootView": {
"viewName": "iw29mobiletable.view.Table",
"type": "XML",
"async": true,
"id": "Table"
},
"dependencies": {
"minUI5Version": "1.65.6",
"libs": {
"sap.ui.layout": {},
"sap.ui.core": {},
"sap.m": {},
"sap.ndc": {}
}
},
"contentDensities": {
"compact": true,
"cozy": true
},
"models": {
"DATA": {
"type": "sap.ui.model.json.JSONModel",
"dataSource": "test_model"
}
},
"services": {
"SelectionService": {
"factoryName": "iw29mobiletable.SelectionService"
}
}
}
}
sap.ui.define([
"sap/ui/core/UIComponent",
"iw29mobiletable/SelectionService"
], function (UIComponent, SelectionService) {
"use strict";
return UIComponent.extend("iw29mobiletable.Component", {
metadata: {
manifest: "json"
},
/**
* The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
* @public
* @override
*/
init: function () {
// call the base component's init function
UIComponent.prototype.init.apply(this, arguments);
},
/*
* @override
* Returns new Service instance that an implements external API inteface
*/
getService : function(sServiceName) {
if(sServiceName === "SelectionService"){
return new SelectionService({
scopeObject: this,
scopeType: "component"
});
}
return null;
}
});
});
sap.ui.define([
"sap/ui/core/service/Service",
"sap/ui/core/service/ServiceFactory",
"sap/ui/core/service/ServiceFactoryRegistry"
], function (Service, ServiceFactory, ServiceFactoryRegistry) {
"use strict";
var oSelectionService = Service.extend("iw29mobiletable.SelectionService", {
_oEventProvider : null,
_oEventBus : null,
init: function () {
ServiceFactoryRegistry.register("iw29mobiletable.SelectionService", new ServiceFactory(this.getInterface()));
this._oEventProvider = new sap.ui.base.EventProvider();
this._oEventBus = sap.ui.getCore().getEventBus();
//The "select" event is published by the iw29mobiletable.controller.Table controller instance once a table row has been selected
this._oEventBus.subscribe("iw29mobiletable", "select", this._onSelect, this);
},
/*
* @private
* @param {String} sChannel
* @param {String} sId
* @param {Object} oData
* The method propogates the "select" event fired by the iw29mobiletable.controller.Table instance
*/
_onSelect : function(sChannel, sId, oData) {
this._oEventProvider.fireEvent("select", {"id" : oData.id});
},
/*
* @param {Function} fnFuntion
* @param {Object} oListener
* Attach external handler function to the table row selection event
*/
attachSelect : function(fnFuntion, oListener){
this._oEventProvider.attachEvent("select", null, fnFuntion, oListener);
},
/*
* @param {Function} fnFuntion
* @param {Object} oListener
* Detach external handler function from the table row selection event
*/
detachSelect : function(fnFuntion, oListener){
this._oEventProvider.detachEvent("select", fnFuntion, oListener);
},
/*
* @param {String} sNotificationId
* Selects table row by notification id
*/
setSelectedRowById : function(sNotificationId){
this._oEventBus.publish("iw29mobiletable", "selectRow", {
"id": sNotificationId
});
}
});
return oSelectionService;
});
<mvc:View controllerName="iw29mobiletable.controller.Table" xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core" xmlns="sap.m">
<Table id="idNotificationsTable" inset="false" mode="SingleSelectMaster" selectionChange="onSelect"
items="{ path: 'DATA>/NotificationCollection', sorter: { path: 'Name' } }">
<headerToolbar>
<OverflowToolbar>
<content>
<Title text="Notifications" level="H2"/>
<ToolbarSpacer/>
<SearchField id="searchField" search="onSearch" placeholder="Search by Equipment" width="auto"></SearchField>
<Button tooltip="Group" icon="sap-icon://sort" press="onSort"/>
<Button tooltip="Filter" icon="sap-icon://filter" press="onFilter"/>
</content>
</OverflowToolbar>
</headerToolbar>
<columns>
<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Center">
<Text text="Notification"/>
</Column>
<Column minScreenWidth="Tablet" hAlign="Center">
<Text text="Notification Date"/>
</Column>
<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Center">
<Text text="Description"/>
</Column>
<Column minScreenWidth="Tablet" demandPopin="true" hAlign="Center">
<Text text="Equipment"/>
</Column>
<Column demandPopin="true" hAlign="Center">
<Text text="Malfunction Start Date"/>
</Column>
<Column demandPopin="true" hAlign="Center">
<Text text="Priority"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<ObjectIdentifier title="{DATA>QMNUM}" text="{DATA>QMART}"/>
<Text
text="{ path: 'DATA>QMDAT', type: 'sap.ui.model.type.Date', formatOptions : { pattern : 'MM/dd/yyyy', source : { pattern : 'MM/dd/yyyy' } } }"/>
<Text text="{DATA>QMTXT}"/>
<Text text="{DATA>EQUNR}"/>
<Text
text="{ path: 'DATA>AUSVN', type: 'sap.ui.model.type.Date', formatOptions : { pattern : 'MM/dd/yyyy', source : { pattern : 'MM/dd/yyyy' } } }"/>
<ObjectStatus text="{DATA>PRIOKX}" state="{path : 'DATA>PRIOK', formatter : 'iw29mobiletable.Formatter.priority'}"/>
</cells>
</ColumnListItem>
</items>
</Table>
</mvc:View>
sap.ui.define(function() {
"use strict";
var Formatter = {
priority : function (sPriority) {
switch(sPriority){
case "3":
return "Warning";
case "2":
case "1":
return "Error";
default:
return "None";
}
}
};
return Formatter;
}, true);
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
<ViewSettingsDialog confirm="onFilterConfirmed">
<filterItems>
<ViewSettingsFilterItem text="Type" key="QMART" multiSelect="true">
<items>
<ViewSettingsItem text="M2 - Malfunction report" key="QMART___EQ___M2"/>
<ViewSettingsItem text="S2 - Service request" key="QMART___EQ___S2"/>
<ViewSettingsItem text="S3 - Activity report" key="QMART___EQ___S3"/>
</items>
</ViewSettingsFilterItem>
<ViewSettingsFilterItem text="Priority" key="PRIOK" multiSelect="true">
<items>
<ViewSettingsItem text="1-Very high" key="PRIOK___EQ___1"/>
<ViewSettingsItem text="2-High" key="PRIOK___EQ___2"/>
<ViewSettingsItem text="3-Medium" key="PRIOK___EQ___3"/>
<ViewSettingsItem text="4-Low" key="PRIOK___EQ___4"/>
</items>
</ViewSettingsFilterItem>
<ViewSettingsFilterItem text="Notification Date" key="QMDAT" multiSelect="false">
<items>
<ViewSettingsItem text="Today" key="QMDAT___EQ___TODAY"/>
<ViewSettingsItem text="Within a month" key="QMDAT___BT___TODAY___MONTH"/>
<ViewSettingsItem text="Older than a month" key="QMDAT___LT___MONTH"/>
</items>
</ViewSettingsFilterItem>
<ViewSettingsFilterItem text="Malfunction Date" key="AUSVN" multiSelect="false">
<items>
<ViewSettingsItem text="Today" key="AUSVN___EQ___TODAY"/>
<ViewSettingsItem text="Within a month" key="AUSVN___BT___TODAY___MONTH"/>
<ViewSettingsItem text="Older than a month" key="AUSVN___LT___MONTH"/>
</items>
</ViewSettingsFilterItem>
</filterItems>
</ViewSettingsDialog>
</core:FragmentDefinition>
<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core">
<ViewSettingsDialog
confirm="onSortConfirm">
<sortItems>
<ViewSettingsItem text="Notification Date" key="QMDAT" selected="true" />
<ViewSettingsItem text="Equipment" key="EQUNR" />
<ViewSettingsItem text="Malfunction Start Date" key="AUSVN" />
<ViewSettingsItem text="Priority" key="PRIOKX" />
</sortItems>
</ViewSettingsDialog>
</core:FragmentDefinition>
sap.ui.define([
"/../Formatter",
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel",
"sap/ui/model/Filter",
"sap/ui/model/FilterOperator",
"sap/ui/model/Sorter"
], function (Formatter, Controller, JSONModel, Filter, FilterOperator, Sorter, BarcodeScanner) {
"use strict";
var TableController = Controller.extend("iw29mobiletable.controller.Table", {
_oEventBus: null,
_oFilterDialog : null,
_oSortDialog : null,
_oTable : null,
onInit: function () {
this._oEventBus = sap.ui.getCore().getEventBus();
this._oEventBus.subscribe("iw29mobiletable", "selectRow", this.onNotificationSelect, this);
this._oTable = this.byId("idNotificationsTable");
},
/*
* Table row selection handler
* @param {Object} oEvent
*/
onSelect: function (oEvent) {
var oSelectedListItem = oEvent.getParameter("listItem"),
oNotificationCell = oSelectedListItem.getCells()[0],
sNotificationId = oNotificationCell.getTitle();
this._oEventBus.publish("iw29mobiletable", "select", {
"id": sNotificationId
});
},
/*
* @param {String} sChannel
* @param {String} sId
* @param {Object} oData
* Handles Row selection request
*/
onNotificationSelect: function (sChannel, sId, oData) {
var sNotificationId = oData.id;
var sTitle;
var oItem;
var aTableItems = this._oTable.getItems();
var i;
for(i = 0; i < aTableItems.length; i++){
oItem = aTableItems[i];
sTitle = oItem.getCells()[0].getTitle();
if(sTitle === sNotificationId){
this._oTable.setSelectedItem(oItem);
oItem.focus();
return;
}
}
this._oTable.removeSelections(true);
},
/*
* Table search handler
* @param {Object} oEvent
*/
onSearch: function (oEvent) {
var sQuery,
oBindings = this._oTable.getBinding("items");
if (oEvent.getParameters().clearButtonPressed) {
oBindings.filter("");
} else {
sQuery = oEvent.getParameter("query");
if (sQuery && sQuery.length > 0) {
oBindings.filter([new Filter("EQUNR", FilterOperator.Contains, sQuery)]);
}
}
},
/*
* Sort button press handler
*/
onSort: function(){
if (!this._oSortDialog) {
this._oSortDialog = sap.ui.xmlfragment("iw29mobiletable.fragments.Sort", this);
}
this._oSortDialog.open();
},
/*
* Filter button press handler
*/
onFilter: function(){
if (!this._oFilterDialog) {
this._oFilterDialog = sap.ui.xmlfragment("iw29mobiletable.fragments.Filter", this);
}
this._oFilterDialog.open();
},
/*
* Handles table sorting
* @param {Object} oEvent
*/
onSortConfirm : function(oEvent){
var mParams = oEvent.getParameters(),
bDescending = mParams.sortDescending,
sPath = mParams.sortItem.getKey(),
oSorter;
//A custom sorter is required for dates
if(sPath === "QMDAT" || sPath === "AUSVN"){
oSorter = new Sorter(sPath, bDescending, undefined, this._compareDates);
}else{
oSorter = new Sorter(sPath, bDescending);
}
this._oTable.getBinding("items").sort([oSorter]);
},
/**
* Compares two date strings
* @param {String} sDateX
* @param {String} sDateY
* @return {Integer} [-1;1]
*/
_compareDates : function(sDateX, sDateY){
var oDateX = new Date(sDateX),
oDateY = new Date(sDateY);
if(oDateX < oDateY || !oDateY){
return -1;
}
if(oDateX > oDateY || !oDateX){
return 1;
}
return 0;
},
/**
* Converts date constants into dynamic date strings
* @param {String} sValue
* @return {String}
*/
_convertDate : function(sValue){
var oDate = new Date();
switch(sValue){
case "TODAY" :
return oDate.toDateString();
case "MONTH" :
oDate.setMonth(oDate.getMonth() - 1);
return oDate.toDateString();
default :
return sValue;
}
},
/*
* Handles table filtering
* @param {Object} oEvent
*/
onFilterConfirmed : function(oEvent){
var mParams = oEvent.getParameters(),
oBinding = this._oTable.getBinding("items"),
aFilters = [];
mParams.filterItems.forEach(function(oItem) {
var aSplit = oItem.getKey().split("___"),
sPath = aSplit[0],
sOperator = aSplit[1],
sValue1 = aSplit[2],
sValue2 = aSplit[3],
oFilter = new Filter(sPath, sOperator, sValue1, sValue2);
//Custom filter settings for dates
if(sPath === "AUSVN" || sPath === "QMDAT"){
oFilter.oValue1 = this._convertDate(sValue1);
oFilter.sValue2 = this._convertDate(sValue2);
oFilter.fnCompare = this._compareDates;
}
aFilters.push(oFilter);
}.bind(this));
// apply filter settings
oBinding.filter(aFilters);
}
});
return TableController;
});
// Load table data from screen
var fnReadModelData = function (){
var oSelectedTable = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell");
var aColumns = oSelectedTable.columns;
var aContents = [];
var sSAPColumnName;
var iTopRow, iRowIdx, oRow, i;
if (oSelectedTable.rowCount > 0) {
oSelectedTable.firstVisibleRow = 0;
iTopRow = oSelectedTable.visibleRowCount - 1;
for (iRowIdx = 0; iRowIdx < oSelectedTable.rowCount; iRowIdx++) {
oRow = {};
if (iRowIdx > iTopRow) {
if (iTopRow + oSelectedTable.visibleRowCount > oSelectedTable.rowCount) {
oSelectedTable.firstVisibleRow = oSelectedTable.rowCount - oSelectedTable.visibleRowCount;
} else {
oSelectedTable.firstVisibleRow = iTopRow + 1;
}
iTopRow += oSelectedTable.visibleRowCount;
}
for (i = 0; i < aColumns.length; i++) {
sSAPColumnName = aColumns.elementAt(i).name;
oRow[sSAPColumnName] = oSelectedTable.getCellValue(iRowIdx, sSAPColumnName);
}
aContents.push(oRow);
}
}
return aContents;
};
var oComponent = session.findById("<PLACE YOUR APPLET ID HERE>").getComponent();
oComponent.getService("SelectionService").attachSelect(function(oEvent){
session.utils.put("SELECTED_NOTIFICATION", oEvent.getParameter("id"));
}.bind(this));
//Set the SAPUI5 Applet view model data
oViewModel = oComponent.getModel("DATA");
oViewModel.setData({"NotificationCollection" : fnReadModelData()});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
20 | |
13 | |
12 | |
10 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 |