forked from ToonSoftwareCollective/postnl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostnlScreen.qml
320 lines (268 loc) · 7.68 KB
/
PostnlScreen.qml
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
import QtQuick 2.1
import qb.components 1.0
import BasicUIControls 1.0;
import FileIO 1.0
Screen {
id: postnlScreen
screenTitle: "Recente PostNL pakketten"
property string actualModelText : "Pakketpost van de afgelopen maand:"
property string lastupdate
FileIO {
id: postnlInboxFile
source: "file:///tmp/postnl/POSTNL-Inbox.json"
}
FileIO {
id: lastupdateFile
source: "file:///tmp/postnl/lastupdate.log"
}
function formatDeliveryDate(dateString) {
return dateString.substring(0, 10) + " " + dateString.substring(11,16);
}
function formatDelivery(status, deliveryDate) {
if (status == 'Delivered') {
return "Afgeleverd op " + deliveryDate;
} else {
if (status == 'ReturnToSender') {
return " ";
} else {
return "Onderweg, aflevering vanaf " + deliveryDate;
}
}
}
onShown: {
// add settingsscreen button
addCustomTopRightButton("Instellingen");
}
onCustomButtonClicked: {
if (app.postnlConfigurationScreen) app.postnlConfigurationScreen.show();
}
function refreshScreen() {
refreshPostnlModel();
}
function refreshPostnlModel() {
var lastupdateText = lastupdateFile.read();
lastupdate = lastupdateText.substring(0,16) + " ";
// clear Tile
app.tileDate = "";
app.tileTime = "";
app.tileBarcode = "Geen pakketten verwacht";
app.tileSender = "";
// read inbox
var postNLData = JSON.parse(postnlInboxFile.read());
if (postNLData['receiver'].length > 0) {
//format tile when parcel is coming
if (postNLData['receiver'][0]['delivery']['status'] !== 'Delivered') {
if (postNLData['receiver'][0]['delivery']['timeframe']['from']) {
app.tileDate = postNLData['receiver'][0]['delivery']['timeframe']['from'].substring(0,10);
app.tileTime = postNLData['receiver'][0]['delivery']['timeframe']['from'].substring(11,16) + " - " + postNLData['receiver'][0]['delivery']['timeframe']['to'].substring(11,16);
} else {
app.tileDate = " ";
app.tileTime = " ";
}
app.tileBarcode = postNLData['receiver'][0]['barcode'];
if (postNLData['receiver'][0]['sender']['companyName']) {
app.tileSender = postNLData['receiver'][0]['sender']['companyName'];
}
}
}
// fill screen
postnlModel.clear();
var shipmentDate = "";
var shipmentSender = "";
var shipmentTitle = "";
// calculate date 1 month back
var now = new Date();
var thisMonth = now.getMonth();
now.setMonth(thisMonth - 1); // 1 month in the past
var strMon = now.getMonth() + 1;
if (strMon < 10) {
strMon = "0" + strMon;
}
var strDay = now.getDate();
if (strDay < 10) {
strDay = "0" + strDay;
}
var cutoffDate = now.getFullYear() + "-" + strMon + "-" + strDay;
// get incoming shipments
for (var i = 0; i < postNLData['receiver'].length; i++) {
// determine date
if (postNLData['receiver'][i]['delivery']['status'] == 'Delivered') {
shipmentDate = formatDeliveryDate(postNLData['receiver'][i]['delivery']['deliveryDate']);
shipmentTitle = "Ontvangen van ";
} else {
if (postNLData['receiver'][i]['delivery']['timeframe']['from']) {
shipmentDate = formatDeliveryDate(postNLData['receiver'][i]['delivery']['timeframe']['from']);
} else {
shipmentDate = "";
}
if (postNLData['receiver'][i]['delivery']['status'] == 'ReturnToSender') {
shipmentTitle = "Retour afzender ";
} else {
shipmentTitle = "Te ontvangen van ";
}
}
if (cutoffDate < shipmentDate.substring(0,10)) {
// determine sender
if (postNLData['receiver'][i]['sender']) {
if (postNLData['receiver'][i]['sender']['companyName']) {
shipmentSender = postNLData['receiver'][i]['sender']['companyName'] + " (" + postNLData['receiver'][i]['sender']['town'] + ")";
} else {
shipmentSender = postNLData['receiver'][i]['sender']['lastName'] + " (" + postNLData['receiver'][i]['sender']['town'] + ")";
}
} else {
shipmentSender = "onbekende afzender";
}
postnlModel.append({deliveryDate: shipmentDate, deliveryInfo: formatDelivery(postNLData['receiver'][i]['delivery']['status'], shipmentDate), barcode: postNLData['receiver'][i]['barcode'], senderInfo: shipmentTitle + shipmentSender});
}
}
// add outgoing shipments
for (var j = 0; j < postNLData['sender'].length; j++) {
if (postNLData['sender'][j]['delivery']['deliveryDate']) {
shipmentDate = formatDeliveryDate(postNLData['sender'][j]['delivery']['deliveryDate']);
} else {
if (postNLData['sender'][j]['delivery']['timeframe']['from']) {
shipmentDate = formatDeliveryDate(postNLData['sender'][j]['delivery']['timeframe']['from']);
} else {
shipmentDate = "";
}
}
if (cutoffDate < shipmentDate.substring(0,10)) {
postnlModel.append({deliveryDate: shipmentDate, deliveryInfo: formatDelivery(postNLData['sender'][j]['delivery']['status'], shipmentDate), barcode: postNLData['sender'][j]['barcode'], senderInfo: "Verstuurd naar " + postNLData['sender'][j]['originalReceiver']['street'] + " " + postNLData['sender'][j]['originalReceiver']['houseNumber'] + ", " + postNLData['sender'][j]['originalReceiver']['town']});
}
}
// sort on deliverydate
sortPostnlModel();
}
function sortPostnlModel() {
var n;
var i;
for (n=0; n < postnlModel.count; n++) {
for (i=n+1; i < postnlModel.count; i++) {
if (postnlModel.get(n).deliveryDate < postnlModel.get(i).deliveryDate) {
postnlModel.move(n, i, 1);
n=0;
}
}
}
}
Item {
id: header
height: isNxt ? 55 : 45
width: parent.width
Text {
id: headerText
text: actualModelText
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 25 : 20
anchors {
left: parent.left
leftMargin: isNxt ? 25 : 20
bottom: parent.bottom
}
}
Text {
id: updatedText
text: "bijgewerkt op: " + lastupdate
anchors {
bottom: parent.bottom
right: parent.right
}
font {
pixelSize: isNxt ? 18 : 15
family: qfont.italic.name
}
}
}
GridView {
id: postnlGridView
model: postnlModel
delegate: Rectangle
{
width: isNxt ? 975 : 760
height: isNxt ? 60 : 48
Text {
id: txtShippedBy
text: senderInfo
font.pixelSize: isNxt ? 20 : 16
font.family: qfont.bold.name
color: colors.clockTileColor
anchors {
top: parent.top
left: parent.left
leftMargin: 5
}
}
Text {
id: txtDelivery
text: deliveryInfo
font.pixelSize: isNxt ? 20 : 16
font.family: qfont.regular.name
color: colors.clockTileColor
anchors {
top: parent.top
right: parent.right
rightMargin: 5
}
}
Text {
id: txtBarcode
text: barcode
font.pixelSize: isNxt ? 20 : 16
font.family: qfont.regular.name
color: colors.clockTileColor
anchors {
top: txtShippedBy.bottom
left: txtShippedBy.left
}
}
}
flow: GridView.TopToBottom
cellWidth: isNxt ? 975 : 750
cellHeight: isNxt ? 65 : 52
anchors {
top: header.bottom
bottom: parent.bottom
left: parent.left
topMargin: 5
leftMargin: isNxt ? 25 : 20
}
}
ListModel {
id: postnlModel
}
GridView {
id: letterGridView
model: letterModel
delegate: Rectangle
{
width: isNxt ? 250 : 200
height: isNxt ? 30 : 24
Text {
id: txtDelivery
text: deliveryDate
font.pixelSize: isNxt ? 20 : 16
font.family: qfont.regular.name
color: colors.clockTileColor
anchors {
top: parent.top
left: parent.left
leftMargin: 5
}
}
}
flow: GridView.TopToBottom
cellWidth: isNxt ? 250 : 200
cellHeight: isNxt ? 35 : 28
visible: false
anchors {
top: header.bottom
bottom: parent.bottom
left: parent.left
topMargin: 5
leftMargin: isNxt ? 25 : 20
}
}
ListModel {
id: letterModel
}
}