This repository has been archived by the owner on Apr 11, 2021. It is now read-only.
forked from SAP-archive/cloud-platform-iot-starterkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.view.js
189 lines (167 loc) · 4.11 KB
/
main.view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
sap.ui.jsview("odataconsumption.view.main", {
/** Specifies the Controller belonging to this View.
* In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
* @memberOf controller.main
*/
getControllerName: function() {
return "odataconsumption.controller.main";
},
/** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed.
* Since the Controller is given to this method, its event handlers can be attached right away.
* @memberOf controller.main
*/
createContent: function(oController) {
var oToolbar = new sap.m.Toolbar({
content: [
new sap.m.Title({
text: "{i18n>TEXT_OUTBOUND_BEG}"
}),
this.createDeviceSelect(oController),
this.createMessageTypeSelect(oController),
new sap.m.Title({
text: "{i18n>TEXT_OUTBOUND_END}"
})
]
});
var oPanel = new sap.m.Panel({
headerToolbar: oToolbar,
content: this.createVizFrame()
});
var oPage = new sap.m.Page({
title: "{i18n>TITLE}",
content: [oPanel]
});
var app = new sap.m.App("myApp", {
initialPage: oPage
});
app.addPage(oPage);
return app;
},
createDeviceSelect: function(oController) {
var oItem = new sap.ui.core.Item({
key: "{devices>id}",
text: "{devices>name}"
});
var oSelect = new sap.m.Select({
tooltip: "{i18n>TOOLTIP_DEVICES}",
width: "150px",
enabled: {
path: "devices>/",
formatter: oController.formatSelectEnablement
},
selectedKey: "{viewModel>/selectedDeviceId}",
change: [oController.onDeviceChange, oController]
});
oSelect.bindItems("devices>/", oItem);
return oSelect;
},
createMessageTypeSelect: function(oController) {
var oItem = new sap.ui.core.Item({
key: "{viewModel>id}",
text: "{viewModel>name}"
});
var oSelect = new sap.m.Select({
tooltip: "{i18n>TOOLTIP_MESSAGE_TYPES}",
width: "150px",
enabled: {
path: "viewModel>/messageTypes",
formatter: oController.formatSelectEnablement
},
selectedKey: "{viewModel>/selectedMessageTypeId}",
change: [oController.onMessageTypeChange, oController]
});
oSelect.bindItems("viewModel>/messageTypes", oItem);
return oSelect;
},
createDimensionFeed: function() {
return new sap.viz.ui5.controls.common.feeds.FeedItem({
"uid": "timeAxis",
"type": "Dimension",
"values": ["timestamp"]
});
},
createMeasureFeed: function() {
return new sap.viz.ui5.controls.common.feeds.FeedItem({
"uid": "primaryValues",
"type": "Measure",
"values": ["value"]
});
},
createDataSet: function(oController) {
var oDataset = new sap.viz.ui5.data.FlattenedDataset({
dimensions: [{
name: "timestamp",
value: {
path: "odata>C_TIMESTAMP",
formatter: function(oValue) {
return oController.formatDate(oValue);
}
},
dataType: "date"
}],
measures: [{
name: "value",
value: "{odata>C_VALUE}"
}]
});
oController.oDataset = oDataset;
return oDataset;
},
createVizFrame: function() {
var oController = this.getController();
var oVizFrame = new sap.viz.ui5.controls.VizFrame({
width: "100%",
height: oController.calculateChartHeight(),
vizType: "timeseries_line",
vizProperties: {
plotArea: {
dataLabel: {
visible: false
}
},
legend: {
visible: false
},
title: {
visible: false
},
timeAxis: {
title: {
visible: true
},
levels: ["day", "month", "year"],
levelConfig: {
month: {
formatString: "MM"
},
year: {
formatString: "yyyy"
}
},
interval: {
unit: ''
}
}
},
timeAxis: {
title: {
visible: false
}
},
yAxis: new sap.viz.ui5.types.Axis({
scale: new sap.viz.ui5.types.Axis_scale({
fixedRange: true,
minValue: 0,
maxValue: 100
})
}),
dataset: this.createDataSet(oController)
});
oVizFrame.addFeed(this.createDimensionFeed());
oVizFrame.addFeed(this.createMeasureFeed());
$(window).resize(function() {
oVizFrame.setHeight(oController.calculateChartHeight());
});
return oVizFrame;
}
});