forked from regio-osm/housenumberfrontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhousenumbers.js
executable file
·241 lines (209 loc) · 8.88 KB
/
housenumbers.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
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
// project specific references
var ApplicationConfiguration = require("./housenumbers/Applicationconfiguration");
var evaluation = require("./housenumbers/evaluation");
var housenumber = require("./housenumbers/housenumber");
var street = require("./housenumbers/street");
/*
var theo_auswertung = require("./housenumbers/theoauswertung");
var grafikanforderung = require("./housenumbers/grafikanforderung");
var historischeentwicklung = require("./housenumbers/historischeentwicklung");
var notexisting_housenumbers_insert = require("./notexisting_housenumbers/insert_new");
var notexisting_housenumbers_get = require("./notexisting_housenumbers/get");
var statistik = require("./housenumbers/statistik");
var missionplaning = require("./housenumbers/missionplaning");
var api_getmissingstreetnumbers = require("./api/getmissingstreetnumbers");
var jobqueue = require("./housenumbers/jobqueue");
var state = require("./housenumbers/state");
*/
// standard node.js addons
var express = require("express");
var swig = require("swig");
var pg = require("pg");
var I18n = require("i18n-2");
var fs = require('fs');
// definition of frontend-urls (up to now in german, sorry)
//TODO either use english urls or multi language urls
// CAUTION: cannot be changed here, because urls are hardcoded in several code functions
var handle = {}
handle["/en/selectmunicipality"] = evaluation.selectmunicipality;
handle["/de/auswertung_auswahlort"] = evaluation.selectmunicipality;
handle["/de/auswertung_auswahldetails"] = evaluation.selectevaluation;
handle["/en/selectevaluation"] = evaluation.selectevaluation;
handle["/en/showevaluation"] = evaluation.show;
handle["/de/gpx_ausgeben"] = evaluation.exportgpx;
handle["/en/exportgpx"] = evaluation.exportgpx;
handle["/offizielle_koordinaten_ausgeben"] = evaluation.exportofficialgeocoordinates;
handle["/en/exportofficialgeocoordinates"] = evaluation.exportofficialgeocoordinates;
handle["/de/hausnummer_details"] = housenumber.details;
handle["/en/housenumber_details"] = housenumber.details;
handle["/de/hausnummer_ignorieren"] = housenumber.ignore;
handle["/en/housenumber_ignore"] = housenumber.ignore;
handle["/de/hausnummer_ignorierteliste"] = housenumber.ignorelist;
handle["/en/housenumber_ignorelist"] = housenumber.ignorelist;
handle["/de/hausnummer_reaktivieren"] = housenumber.reactivate;
handle["/en/housenumber_reactivate"] = housenumber.reactivate;
handle["/de/strasse_details"] = street.details;
handle["/en/street_details"] = street.details;
handle["/de/strasse_ignorieren"] = street.ignore;
handle["/en/street_ignore"] = street.ignore;
handle["/de/strasse_ignorierteliste"] = street.ignorelist;
handle["/en/street_ignorelist"] = street.ignorelist;
handle["/de/strasse/reaktivieren"] = street.reactivate;
handle["/de/strasse_reaktivieren"] = street.reactivate;
handle["/en/street_reactivate"] = street.reactivate;
/*
handle["/offizielle_koordinaten_abgleichen"] = evaluation.offizielle_koordinaten_abgleichen;
handle["/karte_auswahlort"] = grafikanforderung.ort_dialog;
handle["/theoreticalevaluation"] = grafikanforderung.theoevaluation;
handle["/historischeentwicklung/grafik"] = historischeentwicklung.show;
handle["/notexisting_housenumbers/insert_new"] = notexisting_housenumbers_insert.insert_new;
handle["/notexisting_housenumbers/get_around_pos"] = notexisting_housenumbers_get.around_pos;
handle["/strasse/reaktivieren"] = strasse.reaktivieren;
handle["/statistik"] = statistik.show;
handle["/mission_show"] = missionplaning.show;
handle["/mission_route"] = missionplaning.route;
handle["/nextopenjobs"] = jobqueue.nextOpenJobs;
handle["/nextopenjobshierarchy"] = jobqueue.nextOpenJobsHierarchy;
handle["/evaluationinstantrequest"] = jobqueue.requestInstantJob;
handle["/theoretische_auswertung_anzeigen"] = theo_auswertung.show;
handle["/state"] = state.show;
handle["/api/getmissingstreetnumbers"] = api_getmissingstreetnumbers.request;
*/
global.configuration = ApplicationConfiguration();
console.log(" in hausnummern.js nach Konfigurations-setzen ==="+global.configuration.servername+"===");
console.log("in hausnummern.js nach Konfiguration-setzen global.configuration.frontend_serverport ==="+global.configuration.frontend_serverport+"===");
var app = express();
app.configure(function () {
I18n.expressBind(app, {
// setup some locales - other locales default to en silently
locales: ['de', 'en', 'pt-br', 'pt'],
extension: '.json', // setting extension of json files - defaults to '.json' (you might want to set this to '.js' according to webtranslateit)
devMode: true,
updateFiles: true,
request: true,
query: true,
cookieName: 'language',
directory: __dirname + '/locales'
});
});
app.use(express.cookieParser());
// URL-Ausgabe
app.use(function(request, response, next) {
var show_params = false;
var show_cookies = false;
//console.log("Aufruf:", request.path);
if(request.param && show_params) {
console.log("request.param beginn ...");
for(var pari in request.param) {
console.log(" request.params ["+pari+"] ==="+request.param[pari]+"===");
}
console.log("request.param ende!");
}
if(request.cookies && show_cookies) {
console.log("Cookies begin ...");
for(var cooki in request.cookies) {
console.log("cookie ["+cooki+"] ==="+request.cookies[cooki]+"===");
}
console.log("Cookies end!");
}
next();
});
//This is how you'd set a locale from req.cookies.
//Don't forget to set the cookie either on the client or in your Express app.
app.use(function(request, response, next) {
console.log("==========================================================");
console.log("URL-Aufruf:", request.path);
request.i18n.setLocaleFromCookie();
//console.log("actual language in request: " + request.i18n.getLocale());
//console.log("in app.configure danach isPreferredLocale ==="+request.i18n.isPreferredLocale()+"===");
next();
});
// Statische Seiten
app.use(express.static(__dirname + "/public_html"));
// Dynamische Seiten
app.engine("html", swig.renderFile);
app.set("views", __dirname + '/housenumbers/templates');
app.use(app.router);
app.get('/grafikdarstellung/anzeige.html', function(request, response) {
response.redirect('/housenumbers/anzeige_dynamisch.html');
});
app.get('/grafikdarstellung/anzeige_dynamisch.html', function(request, response) {
response.redirect('/housenumbers/anzeige_dynamisch.html');
});
app.get('/theretischeabdeckung.html', function(request, response) {
response.redirect('/housenumbers/theoretischeabdeckung.html');
//TODO redirect prüfen
});
var getClient = function(callback) {
pg.connect(global.configuration.db_application_connection, callback);
};
var getClient_listofstreets = function(callback) {
pg.connect(global.configuration.db_application_listofstreets_connection, callback);
};
var simpleQuery = function(query, callback) {
getClient(function(error, client, done) {
if (error) {
callback(error);
} else {
client.query(query, function(error, result) {
done();
callback(error, result);
});
}
});
};
var simpleQuery_listofstreets = function(query, callback) {
getClient_listofstreets(function(error, client, done) {
if (error) {
callback(error);
} else {
client.query(query, function(error, result) {
done();
callback(error, result);
});
}
});
};
app.use(function(request, response, next) {
var handler = handle["/" + request.i18n.getLocale() + request.path];
if(! handler) {
handler = handle["/en" + request.path];
if(! handler) {
console.log("didn't get default language url (en) for request ===" + request.path + "===, with langprefix ===" + "/en" + request.path + "===");
handler = handle[request.path];
} else {
console.log("ok, found default language url (en) for request ===" + request.path);
}
} else {
console.log("ok, found language-specific url (" + request.i18n.getLocale() + ") for request ===" + request.path);
}
if (handler) {
response.getClient = getClient;
response.simpleQuery = simpleQuery;
response.simpleQuery_listofstreets = simpleQuery_listofstreets;
handler(request, response);
} else {
console.log("Upps, no handler for url ===" + request.path);
next();
}
});
//start
app.use(function(request, response, next) {
var requestfilename = __dirname + "/housenumbers/templates" + request.path;
console.log(request.path + " until now not found, now try to find pseudo static file ===" + requestfilename + "=== ...");
console.log("request.url ===" + request.url + "===");
fs.readFile(requestfilename, function(err,filecontent) {
if(filecontent != undefined) {
var dateiinhalt = filecontent; // filecontent ist offenbar Object, aber Struktur unklar
response.render(requestfilename);
} else {
next();
}
});
});
// end
app.use(function(request, response, next) {
console.log(request.path + " Datei nicht gefunden");
next();
});
app.listen(global.configuration.frontend_serverport);