Real initial commit
Set real eMail-Address
This commit is contained in:
86
lib/eventutils.js
Normal file
86
lib/eventutils.js
Normal file
@@ -0,0 +1,86 @@
|
||||
function create_empty_thereafter() {
|
||||
return {
|
||||
name : "",
|
||||
name_secondary : "",
|
||||
visibility : "publ",
|
||||
end : "",
|
||||
end_is_vague : false,
|
||||
locations: [],
|
||||
involved : [],
|
||||
involved_roles : [],
|
||||
description : "",
|
||||
annotations : ""
|
||||
};
|
||||
}
|
||||
|
||||
exports.create_empty_thereafter = create_empty_thereafter;
|
||||
|
||||
function copy_thereafter(dest, source) {
|
||||
dest.uuid = source.uuid;
|
||||
dest.name = source.name;
|
||||
dest.name_secondary = source.name_secondary;
|
||||
dest.visibility = source.visibility;
|
||||
dest.end = source.end;
|
||||
dest.end_is_vague = source.end_is_vague;
|
||||
dest.locations = source.locations;
|
||||
dest.involved = source.involved;
|
||||
dest.involved_roles = source.involved_roles;
|
||||
dest.description = source.description;
|
||||
dest.annotations = source.annotations;
|
||||
}
|
||||
|
||||
exports.copy_thereafter = copy_thereafter;
|
||||
|
||||
function create_empty_event() {
|
||||
var event = create_empty_thereafter();
|
||||
event.punit = { name : "Rödental St. Hedwig", dn : "eb_bamberg/d_coburg/sb_cosl/p_roedental" };
|
||||
event.start = "";
|
||||
return event;
|
||||
}
|
||||
|
||||
exports.create_empty_event = create_empty_event;
|
||||
|
||||
function copy_event_without_thereafter(dest, source) {
|
||||
copy_thereafter(dest, source);
|
||||
dest.punit = source.punit;
|
||||
dest.start = source.start;
|
||||
}
|
||||
|
||||
exports.copy_event_without_thereafter = copy_event_without_thereafter;
|
||||
|
||||
function add_uids_to_event(ev) {
|
||||
for(var idx in ev.involved)
|
||||
{
|
||||
ev.involved[idx].uid = generateUID();
|
||||
console.log(ev.involved[idx]);
|
||||
}
|
||||
for(var idx in ev.involved_roles)
|
||||
{
|
||||
ev.involved_roles[idx].uid = generateUID();
|
||||
|
||||
for(var inv_idx in ev.involved_roles[idx].involved)
|
||||
ev.involved_roles[idx].involved[inv_idx].uid = generateUID();
|
||||
}
|
||||
|
||||
for(var idx in ev.locations)
|
||||
{
|
||||
ev.locations[idx].uid = generateUID();
|
||||
console.log(ev.locations[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
exports.add_uids_to_event = add_uids_to_event;
|
||||
|
||||
function delete_event_if_nothing_is_edited(day, event) {
|
||||
if(event.in_editing)
|
||||
return;
|
||||
|
||||
console.log(Object.keys(event.thereafter).length);
|
||||
|
||||
if(Object.keys(event.thereafter).length === 0) {
|
||||
console.log('DELETING EVENT: ', event.uuid);
|
||||
delete day.events[event.uuid];
|
||||
}
|
||||
}
|
||||
|
||||
exports.delete_event_if_nothing_is_edited = delete_event_if_nothing_is_edited;
|
||||
243
lib/jsonsrv.js
Normal file
243
lib/jsonsrv.js
Normal file
@@ -0,0 +1,243 @@
|
||||
var net = require('net');
|
||||
|
||||
var pfisjsonhost = "127.0.0.1";
|
||||
|
||||
console.log(process.env["NODE_ENV"])
|
||||
if (process.env["NODE_ENV"] === 'production') {
|
||||
//pfisjsonhost = "127.0.0.1";
|
||||
pfisjsonhost = "10.0.0.4";
|
||||
}
|
||||
console.log(pfisjsonhost);
|
||||
|
||||
function byteCount(s) {
|
||||
return encodeURI(s).split(/%(?:u[0-9A-F]{2})?[0-9A-F]{2}|./).length - 1;
|
||||
}
|
||||
|
||||
function format_json_for_send(data) {
|
||||
var str = JSON.stringify(data);
|
||||
//console.log(str);
|
||||
|
||||
var n = str.length;
|
||||
//console.log("str.length: ", n);
|
||||
n = byteCount(str);
|
||||
//console.log("bytes : ", n);
|
||||
/*var n_hex = n.toString(16);
|
||||
var n_str = "" + n_hex;
|
||||
|
||||
var n_msg = ('00000000'+n_str).substring(n_str.length);
|
||||
|
||||
console.log(n_msg + str);
|
||||
|
||||
return n_msg + str;*/
|
||||
|
||||
return str + "__END_OF_JSON__";
|
||||
}
|
||||
|
||||
exports.format_json_for_send = format_json_for_send;
|
||||
|
||||
exports.do_jsonsrv = function(req, res, data, result_func, error_func) {
|
||||
var client = new net.Socket();
|
||||
var input = '';
|
||||
|
||||
client.connect(1337, pfisjsonhost, function() {
|
||||
/*client.setNoDelay(true);*/
|
||||
console.log('Connected');
|
||||
|
||||
client.write(format_json_for_send(data));
|
||||
});
|
||||
|
||||
client.on('data', function(data) {
|
||||
input += data;
|
||||
});
|
||||
|
||||
client.on('end', function() {
|
||||
var result = JSON.parse(input);
|
||||
|
||||
result_func(req, res, result);
|
||||
|
||||
client.destroy(); // kill client after server's response
|
||||
});
|
||||
|
||||
client.on('error', function(err) {
|
||||
console.log(err);
|
||||
error_func(req, res, err);
|
||||
});
|
||||
|
||||
client.on('close', function() {
|
||||
console.log('Connection closed');
|
||||
});
|
||||
}
|
||||
|
||||
function buffer_to_json(input, result_func, error_func) {
|
||||
try {
|
||||
var result = JSON.parse(input);
|
||||
result_func(result);
|
||||
}catch(err) {
|
||||
console.log("--------------------------------------");
|
||||
console.log("--------------------------------------");
|
||||
console.log("ERROR RETRIEVING DATA VOM PFISJSONSRV!");
|
||||
console.log("--------------------------------------");
|
||||
console.log(err);
|
||||
console.log("--------------------------------------");
|
||||
console.log("INPUT --------------------------------");
|
||||
console.log(input);
|
||||
console.log("--------------------------------------");
|
||||
error_func(err);
|
||||
}
|
||||
}
|
||||
|
||||
exports.do_jsonsrv2 = function(data, result_func, error_func) {
|
||||
|
||||
var client = new net.Socket();
|
||||
var input = '';
|
||||
|
||||
client.connect(1337, pfisjsonhost, function() {
|
||||
/*client.setNoDelay(true);*/
|
||||
console.log('Connected');
|
||||
|
||||
client.write(format_json_for_send(data));
|
||||
});
|
||||
|
||||
client.on('data', function(data) {
|
||||
input += data;
|
||||
});
|
||||
|
||||
client.on('end', function() {
|
||||
//console.log("input: ", input);
|
||||
buffer_to_json(input, result_func, error_func);
|
||||
|
||||
client.destroy(); // kill client after server's response
|
||||
});
|
||||
|
||||
client.on('error', function(err) {
|
||||
error_func(err);
|
||||
});
|
||||
|
||||
client.on('close', function() {
|
||||
console.log('Connection closed');
|
||||
});
|
||||
}
|
||||
|
||||
exports.do_jsonsrv_steppedanswer = function(data, step_func, result_func, error_func) {
|
||||
var client = new net.Socket();
|
||||
var input = '';
|
||||
|
||||
client.connect(1337, pfisjsonhost, function() {
|
||||
/*client.setNoDelay(true);*/
|
||||
console.log('Connected');
|
||||
|
||||
client.write(format_json_for_send(data));
|
||||
});
|
||||
|
||||
client.on('data', function(data) {
|
||||
console.log('DATA RECEIVED: ', "" + data);
|
||||
console.log('DATE END');
|
||||
|
||||
var stepidx = data.indexOf("__STEP__");
|
||||
if(stepidx === -1) {
|
||||
input += data;
|
||||
return;
|
||||
}
|
||||
|
||||
input += data.slice(0, stepidx);
|
||||
|
||||
do{
|
||||
console.log("STEP COMPLETE: ", input);
|
||||
console.log("STEP END______");
|
||||
buffer_to_json(input, step_func, error_func);
|
||||
|
||||
// BEGIN NEXT STEP:
|
||||
console.log('BEGINN NEXT STEP');
|
||||
var oldstepindex = stepidx + 8;
|
||||
stepidx = data.indexOf("__STEP__", oldstepindex);
|
||||
if(stepidx === -1)
|
||||
stepidx = data.length;
|
||||
input = data.slice(oldstepindex, stepidx);
|
||||
console.log("NEW STEP START: ", ""+ input);
|
||||
console.log("NEW STEP END");
|
||||
}while(stepidx < data.length)
|
||||
});
|
||||
|
||||
client.on('end', function() {
|
||||
//console.log("input: ", input);
|
||||
buffer_to_json(input, result_func, error_func);
|
||||
|
||||
client.destroy(); // kill client after server's response
|
||||
});
|
||||
|
||||
client.on('error', function(err) {
|
||||
error_func(err);
|
||||
});
|
||||
|
||||
client.on('close', function() {
|
||||
console.log('Connection closed');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
exports.handle_jsonconnectionerror = function(req, res, err) {
|
||||
console.log("-----------------------------");
|
||||
console.log("-----------------------------");
|
||||
console.log("ERROR CONNECTING PFISJSONSRV!");
|
||||
console.log("-----------------------------");
|
||||
console.log(err);
|
||||
console.log("-----------------------------");
|
||||
|
||||
// Connection-Errors are hard errors, so we display an hard error
|
||||
res.status(err.status || 500);
|
||||
res.render('error', {
|
||||
message: err.message,
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
exports.handle_common_jsonsrverrors = function (req, res, result) {
|
||||
if(result.result === "ERROR_invalid_session") {
|
||||
|
||||
req.session.destroy();
|
||||
|
||||
res.render("errorview", { messages : result.messages });
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(result.result == "ERROR_download_file_not_found")
|
||||
{
|
||||
var err = new Error('Not Found');
|
||||
err.status = 404;
|
||||
res.render('error', {
|
||||
message: err.message,
|
||||
error: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
req.session.messages = result.messages.concat(req.session.messages);
|
||||
|
||||
if(req.session.messages.length === 0)
|
||||
req.session.messages.push({type: "danger", title: "Systemfehler", message: "Es wurde ein Fehler in der Verarbeitung festgestellt, aber keine Fehlermeldung erstellt."});
|
||||
|
||||
if(result.result === "ERROR_could_not_create_task")
|
||||
{
|
||||
res.render("errorview", { messages : result.messages });
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(result.result === "ERROR_could_not_init_task")
|
||||
{
|
||||
res.render("errorview", { messages : result.messages });
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
req.session.messages.push({type: "info", title: "Umleitung erfolgt", message: "Aufgrund vorstehender Fehler in der Verarbeitung Ihrer Anfrage wurde Sie auf die Startseite umgeleiet."});
|
||||
|
||||
var date = "";
|
||||
if(req.params.date)
|
||||
date = "/"+req.params.date;
|
||||
else if(req.params.day)
|
||||
date = "/"+req.params.day;
|
||||
|
||||
res.redirect('/day' + date + "?back=false");
|
||||
}
|
||||
99
lib/pcalutils.js
Normal file
99
lib/pcalutils.js
Normal file
@@ -0,0 +1,99 @@
|
||||
exports.do_day_renderparams_from_result = function(result, session) {
|
||||
var d = new Date(result.date.date);
|
||||
d.setHours(10); // neccessary, so that in March the next day after the last sunday is really the next day and not today (Sommerzeit-Umstellung!?)
|
||||
d.setDate(d.getDate()+1);
|
||||
var tomorrow = d.toISOString().slice(0,10);
|
||||
d.setDate(d.getDate()-2);
|
||||
var yesterday = d.toISOString().slice(0,10);
|
||||
d.setDate(d.getDate()+8);
|
||||
var next_week = d.toISOString().slice(0,10);
|
||||
d.setDate(d.getDate()-14);
|
||||
var last_week = d.toISOString().slice(0,10);
|
||||
|
||||
console.log(result.date.date);
|
||||
console.log(tomorrow);
|
||||
console.log(next_week);
|
||||
|
||||
var messages = [];
|
||||
|
||||
if(result.result === "OK_invalid_date") {
|
||||
messages.push({ type: "danger",
|
||||
title: "Eingabefehler:",
|
||||
message: "Das angegeben Datum konnte nicht interpretiert werden! Es wird auf 'heute' ausgewichen!"
|
||||
});
|
||||
}
|
||||
|
||||
messages = messages.concat(session.messages);
|
||||
session.messages = [];
|
||||
|
||||
return { date : result.date,
|
||||
last_week : last_week,
|
||||
yesterday : yesterday,
|
||||
tomorrow : tomorrow,
|
||||
next_week : next_week,
|
||||
litinfo : result.litinfo,
|
||||
parishcal: result.parishcal,
|
||||
messages: messages,
|
||||
sessionuuid : session.sessionuuid
|
||||
};
|
||||
}
|
||||
|
||||
exports.do_week_renderparams_from_result = function(result, session) {
|
||||
var d = new Date(result.basedate);
|
||||
d.setDate(d.getDate()+7);
|
||||
var next_week = d.toISOString().slice(0,10);
|
||||
d.setDate(d.getDate()-14);
|
||||
var last_week = d.toISOString().slice(0,10);
|
||||
|
||||
var messages = [];
|
||||
|
||||
if(result.result === "OK_invalid_date") {
|
||||
messages.push({ type: "danger",
|
||||
title: "Eingabefehler:",
|
||||
message: "Das angegeben Datum konnte nicht interpretiert werden! Es wird auf die aktuelle Woche ausgewichen!"
|
||||
});
|
||||
}
|
||||
|
||||
messages = messages.concat(session.messages);
|
||||
session.messages = [];
|
||||
|
||||
return { interval : result.interval,
|
||||
basedate : result.basedate,
|
||||
days : result.days,
|
||||
last_week : last_week,
|
||||
next_week : next_week,
|
||||
messages: messages
|
||||
};
|
||||
}
|
||||
|
||||
exports.redirect_after_editing = function(req, res) {
|
||||
switch(req.query.pcalview) {
|
||||
case 'timeline': {
|
||||
res.redirect("/timeline/" + req.params.day);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
res.redirect("/day/" + req.params.day + "?back=false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.create_empty_away = function(uuid) {
|
||||
var away = { uuid: uuid, punit : { name : "Rödental St. Hedwig", dn : "eb_bamberg/d_coburg/sb_cosl/p_roedental" }, name: '', involveddb_id: '', reason: ''};
|
||||
return away;
|
||||
}
|
||||
|
||||
exports.create_empty_keep_in_mind = function(uuid) {
|
||||
var keep_in_mind = { uuid: uuid, punit : { name : "Rödental St. Hedwig", dn : "eb_bamberg/d_coburg/sb_cosl/p_roedental" }, name: '', description: ''};
|
||||
return keep_in_mind;
|
||||
}
|
||||
|
||||
exports.create_empty_todo = function(uuid) {
|
||||
var todo = { uuid: uuid, punit : { name : "Rödental St. Hedwig", dn : "eb_bamberg/d_coburg/sb_cosl/p_roedental" }, name: '', description: '', involved: []};
|
||||
return todo;
|
||||
}
|
||||
|
||||
exports.create_empty_vehicle_use = function(uuid) {
|
||||
var todo = { uuid: uuid, punit : { name : "Rödental St. Hedwig", dn : "eb_bamberg/d_coburg/sb_cosl/p_roedental" }, name: '', description: '', involved: [], vehicle_id: "r_pfarrbus"};
|
||||
return todo;
|
||||
}
|
||||
Reference in New Issue
Block a user