-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwastecollectionProvider_2.js
More file actions
179 lines (150 loc) · 6.41 KB
/
wastecollectionProvider_2.js
File metadata and controls
179 lines (150 loc) · 6.41 KB
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
//<provider>2</provider><version>1.0.0</version><parms>"zipcode,housenr"</parms>
//provider deafvalapp, testdata:5831NG 2
function readCalendar(wasteZipcode, wasteHouseNr, extraDates, enableCreateICS, wasteICSId, wasteStreet, wasteStreetName, wasteCity, wasteFullICSUrl) {
var indexGFT = 0;
var indexPAPIER = 0;
var indexREST = 0;
var indexPLASTIC = 0;
var i = 0;
var j = 0;
wasteDatesString = "";
var wasteType = "";
var fileDate = "";
var lastGFTfileDate = "";
var lastPAPIERfileDate = "";
var lastPLASTICfileDate = "";
var lastRESTfileDate = "";
var deafvalappDates = [];
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var aNode = xmlhttp.responseText;
// read start index of all wastetypes
indexGFT = aNode.indexOf("GFT");
indexPAPIER = aNode.indexOf("PAPIER");
indexPLASTIC = aNode.indexOf("PLASTIC");
if (indexPLASTIC < 0) indexPLASTIC = aNode.indexOf("PMD");
if (indexPLASTIC < 0) indexPLASTIC = aNode.indexOf("PBP");
indexREST = aNode.indexOf("REST");
if (indexREST < 0) indexREST = aNode.indexOf("ZAK_BLAUW");
// find first dates in the future of each type - GFT for 2 years
if (indexGFT > -1) {
i = aNode.indexOf(';', indexGFT);
while (aNode.substring(i+7, i+9) == "20") {
fileDate = aNode.substring(i+7, i + 11) + "-" + aNode.substring(i+4, i+6) + "-" + aNode.substring(i+1, i+3);
deafvalappDates.push(fileDate + "_3")
i = aNode.indexOf(';', i+1);
}
}
indexGFT = aNode.indexOf("GFT", indexGFT + 10); //process second year block if available
if (indexGFT > -1) {
i = aNode.indexOf(';', indexGFT);
while (aNode.substring(i+7, i+9) == "20") {
fileDate = aNode.substring(i+7, i + 11) + "-" + aNode.substring(i+4, i+6) + "-" + aNode.substring(i+1, i+3);
deafvalappDates.push(fileDate + "_3")
i = aNode.indexOf(';', i+1);
}
}
// find first dates in the future of each type - PAPIER
if (indexPAPIER > -1) {
i = aNode.indexOf(';', indexPAPIER);
while (aNode.substring(i+7, i+9) == "20") {
fileDate = aNode.substring(i+7, i + 11) + "-" + aNode.substring(i+4, i+6) + "-" + aNode.substring(i+1, i+3);
deafvalappDates.push(fileDate + "_2")
i = aNode.indexOf(';', i+1);
}
}
indexPAPIER = aNode.indexOf("PAPIER", indexPAPIER + 10);
if (indexPAPIER > -1) {
i = aNode.indexOf(';', indexPAPIER);
while (aNode.substring(i+7, i+9) == "20") {
fileDate = aNode.substring(i+7, i + 11) + "-" + aNode.substring(i+4, i+6) + "-" + aNode.substring(i+1, i+3);
deafvalappDates.push(fileDate + "_2")
i = aNode.indexOf(';', i+1);
}
}
// find first dates in the future of each type - PLASTIC
if (indexPLASTIC > -1) {
i = aNode.indexOf(';', indexPLASTIC);
while (aNode.substring(i+7, i+9) == "20") {
fileDate = aNode.substring(i+7, i + 11) + "-" + aNode.substring(i+4, i+6) + "-" + aNode.substring(i+1, i+3);
deafvalappDates.push(fileDate + "_1")
i = aNode.indexOf(';', i+1);
}
}
var indexPLASTIC2 = aNode.indexOf("PLASTIC", indexPLASTIC + 10);
if (indexPLASTIC2 < 0) indexPLASTIC2 = aNode.indexOf("PMD", indexPLASTIC + 10);
if (indexPLASTIC2 < 0) indexPLASTIC2 = aNode.indexOf("PBP", indexPLASTIC + 10);
if (indexPLASTIC2 > -1) {
i = aNode.indexOf(';', indexPLASTIC2);
while (aNode.substring(i+7, i+9) == "20") {
fileDate = aNode.substring(i+7, i + 11) + "-" + aNode.substring(i+4, i+6) + "-" + aNode.substring(i+1, i+3);
deafvalappDates.push(fileDate + "_1")
i = aNode.indexOf(';', i+1);
}
}
// find first dates in the future of each type - REST
if (indexREST > -1) {
i = aNode.indexOf(';', indexREST);
while (aNode.substring(i+7, i+9) == "20") {
fileDate = aNode.substring(i+7, i + 11) + "-" + aNode.substring(i+4, i+6) + "-" + aNode.substring(i+1, i+3);
deafvalappDates.push(fileDate + "_0")
i = aNode.indexOf(';', i+1);
}
}
var indexREST2 = aNode.indexOf("REST", indexREST + 10);
if (indexREST2 < 0) indexREST2 = aNode.indexOf("ZAK_BLAUW", indexREST + 10);
if (indexREST2 > -1) {
i = aNode.indexOf(';', indexREST2);
while (aNode.substring(i+7, i+9) == "20") {
fileDate = aNode.substring(i+7, i + 11) + "-" + aNode.substring(i+4, i+6) + "-" + aNode.substring(i+1, i+3);
deafvalappDates.push(fileDate + "_0")
i = aNode.indexOf(';', i+1);
}
}
// sort dates
var tmp = sortArray2(deafvalappDates, extraDates);
for (i = 0; i < tmp.length; i++) {
wasteDatesString = wasteDatesString + tmp[i] + "\n";
}
writeWasteDates(wasteDatesString, enableCreateICS);
}
}
}
xmlhttp.open("GET", "http://dataservice.deafvalapp.nl/dataservice/DataServiceServlet?service=OPHAALSCHEMA&land=NL&postcode=" + wasteZipcode + "&huisnr=" + wasteHouseNr + "&huisnrtoev=", true);
xmlhttp.send();
}
function sortArray2(inputarray, extraDates) {
var newArray = inputarray.concat(extraDates);
newArray.sort();
return newArray;
}
function writeWasteDates(wasteDatesString, enableCreateICS) {
var doc2 = new XMLHttpRequest();
doc2.open("PUT", "file:///var/volatile/tmp/wasteDates.txt");
doc2.onreadystatechange=function() {
if (doc2.readyState === 4){
if (doc2.status === 0) {
updateWasteIcon("no");
}
}
}
doc2.send(wasteDatesString);
// create ICS file for use in the calendar app when requested
if (enableCreateICS) {
var outputICS = "";
var tmpICS = wasteDatesString.split("\n");
for (var i = 0; i < tmpICS.length; i++) {
if (tmpICS[i].length > 10) {
outputICS = outputICS + "BEGIN:VEVENT\r\n";
outputICS = outputICS + "DTSTART;VALUE=DATE:" + tmpICS[i].substring(0,4) + tmpICS[i].substring(5,7) + tmpICS[i].substring(8,10) + "\r\n";
outputICS = outputICS + "SUMMARY:" + wasteTypeFriendlyName(tmpICS[i].substring(11,12)) + "\r\n";
outputICS = outputICS + "BEGIN:VEVENT\r\n";
}
}
var doc3 = new XMLHttpRequest();
doc3.open("PUT", "file:///var/volatile/tmp/wasteDates.ics");
doc3.send(outputICS);
}
}