Commit 3645a344 authored by Johannes Bill's avatar Johannes Bill

weekview

parent fd64692e
...@@ -7,7 +7,6 @@ var andMaybeString = "und nach Absprache geöffnet"; ...@@ -7,7 +7,6 @@ var andMaybeString = "und nach Absprache geöffnet";
moment.locale("de"); moment.locale("de");
var twoHours = 1000 * 3600 * 2;
function merge(a, b) { function merge(a, b) {
if (a.length === 0) if (a.length === 0)
...@@ -108,7 +107,7 @@ function createWeekView(dataObj, now) { ...@@ -108,7 +107,7 @@ function createWeekView(dataObj, now) {
} }
content += ('<td class="' + className + '-td ' content += ('<td class="' + className + '-td '
+ className + '-maybe' + cls + '" ' + tooltip + '>' + displString + '</td>'); + className + '-maybe' + cls + '" ' + tooltip + '>' + displString + '</td>');
} }
else { else {
content += ('<td class="' + className + '-td ' + className + '-empty' + cls + '"></td>'); content += ('<td class="' + className + '-td ' + className + '-empty' + cls + '"></td>');
...@@ -134,7 +133,6 @@ function hoursMaybe(oHours) { ...@@ -134,7 +133,6 @@ function hoursMaybe(oHours) {
function createWeekViewVerticalRaw(dataObj, now, className, offset, addDayOfWeek) { function createWeekViewVerticalRaw(dataObj, now, className, offset, addDayOfWeek) {
var noOfDays = 7; var noOfDays = 7;
if (!offset) { if (!offset) {
offset = now.getDay() - 1; offset = now.getDay() - 1;
if (offset < 0) offset += 7; if (offset < 0) offset += 7;
...@@ -143,7 +141,6 @@ function createWeekViewVerticalRaw(dataObj, now, className, offset, addDayOfWeek ...@@ -143,7 +141,6 @@ function createWeekViewVerticalRaw(dataObj, now, className, offset, addDayOfWeek
var startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - offset); var startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - offset);
var endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + noOfDays - offset); var endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + noOfDays - offset);
var oHours = transformData(dataObj, startDate, endDate); var oHours = transformData(dataObj, startDate, endDate);
console.log(require("util").inspect(oHours, {depth: null}));
var hasMaybe = hoursMaybe(oHours); var hasMaybe = hoursMaybe(oHours);
...@@ -297,7 +294,7 @@ function createMonthView(dataObj, now, monthOffset) { ...@@ -297,7 +294,7 @@ function createMonthView(dataObj, now, monthOffset) {
var startDate = new Date(now.getFullYear(), now.getMonth() + monthOffset, 1); var startDate = new Date(now.getFullYear(), now.getMonth() + monthOffset, 1);
var monthDate = new Date(startDate); var monthDate = new Date(startDate);
if(startDate.getDay() === 0) { if (startDate.getDay() === 0) {
startDate.setDate(-5); startDate.setDate(-5);
} }
else { else {
...@@ -402,7 +399,7 @@ function getMaxNoOfItemsPerDay(oHours) { ...@@ -402,7 +399,7 @@ function getMaxNoOfItemsPerDay(oHours) {
function formatDate(date) { function formatDate(date) {
var mom = moment(date); var mom = moment(date);
return [mom.format("dddd"), mom.format("ll") ]; return [mom.format("dddd"), mom.format("ll")];
} }
function formatTime(date) { function formatTime(date) {
...@@ -414,8 +411,42 @@ function formatTime(date) { ...@@ -414,8 +411,42 @@ function formatTime(date) {
// return moment(date).format("HH:mm"); // return moment(date).format("HH:mm");
} }
function weekViewData(dataObj, now) {
var noOfDays = 7;
var offset = now.getDay() - 1;
var startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - offset);
var endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + noOfDays - offset);
var oHours = transformData(dataObj, startDate, endDate);
function getHourSpan(oHours) {
var hourMin = 24;
var hourMax = 0;
for (var i = 0; i < oHours.length; i++) {
var dElem = oHours[i].oHours;
for (var j = 0; j < dElem.length; j++) {
var dElem0 = dElem[j][0].getHours();
if(dElem0 < hourMin) hourMin = dElem0;
var dElem1 = dElem[j][1].getHours();
if(dElem1 > hourMax) hourMax = dElem1 + (dElem[j][1].getMinutes() > 0 ? 1 : 0)
}
}
return [hourMin, hourMax];
}
var hourSpan = getHourSpan(oHours);
return oHours;
}
function transformData(dataObj, startDate, endDate) { function transformData(dataObj, startDate, endDate) {
var data = dataObj.intervals.map(function (e) { var data = dataObj.intervals.map(function (e) {
return e;
return { return {
0: e[0], 0: e[0],
1: e[1], 1: e[1],
...@@ -424,6 +455,7 @@ function transformData(dataObj, startDate, endDate) { ...@@ -424,6 +455,7 @@ function transformData(dataObj, startDate, endDate) {
}); });
var dataMaybe = dataObj.maybeIntervals.map(function (e) { var dataMaybe = dataObj.maybeIntervals.map(function (e) {
return e;
return { return {
0: e[0], 0: e[0],
1: e[1], 1: e[1],
...@@ -447,21 +479,23 @@ function transformData(dataObj, startDate, endDate) { ...@@ -447,21 +479,23 @@ function transformData(dataObj, startDate, endDate) {
function dataIterator(data) { function dataIterator(data) {
var idx = 0; var idx = 0;
var len = data.length; var len = data.length;
return {next: function () { return {
var res = []; next: function () {
while (idx < len) { var res = [];
var comp = compareDate(data[idx][0], curDate); while (idx < len) {
//TODO: split midnight var comp = compareDate(data[idx][0], curDate);
if (comp < 0) //TODO: split midnight
idx++; if (comp < 0)
else if (comp == 0) { idx++;
res.push(data[idx]); else if (comp == 0) {
idx++; res.push(data[idx]);
idx++;
}
else break;
} }
else break; return res;
} }
return res; }
}}
} }
var dataIt = dataIterator(data); var dataIt = dataIterator(data);
...@@ -472,7 +506,7 @@ function transformData(dataObj, startDate, endDate) { ...@@ -472,7 +506,7 @@ function transformData(dataObj, startDate, endDate) {
var oHours = dataIt.next(); var oHours = dataIt.next();
var oHoursMaybe = dataMaybeIt.next(); var oHoursMaybe = dataMaybeIt.next();
var oHoursMerged = dataMergedIt.next(); //var oHoursMerged = dataMergedIt.next();
var isHoliday = false; var isHoliday = false;
while (holidayIdx < holidays.length) { while (holidayIdx < holidays.length) {
...@@ -491,7 +525,7 @@ function transformData(dataObj, startDate, endDate) { ...@@ -491,7 +525,7 @@ function transformData(dataObj, startDate, endDate) {
date: new Date(curDate), date: new Date(curDate),
oHours: oHours, oHours: oHours,
oHoursMaybe: oHoursMaybe, oHoursMaybe: oHoursMaybe,
oHoursMerged: oHoursMerged, //oHoursMerged: oHoursMerged,
holiday: isHoliday holiday: isHoliday
}); });
curDate.setDate(curDate.getDate() + 1); curDate.setDate(curDate.getDate() + 1);
...@@ -517,6 +551,8 @@ function getPropperEpochSpan(now) { ...@@ -517,6 +551,8 @@ function getPropperEpochSpan(now) {
var tenMinutes = 10 * 60 * 1000; var tenMinutes = 10 * 60 * 1000;
function asString(dataObj, now) { function asString(dataObj, now) {
const TWO_HOURS = 1000 * 3600 * 2;
var data = dataObj.intervals; var data = dataObj.intervals;
if (data.length == 0) { if (data.length == 0) {
...@@ -540,7 +576,7 @@ function asString(dataObj, now) { ...@@ -540,7 +576,7 @@ function asString(dataObj, now) {
} }
if (open) { if (open) {
idx--; idx--;
if (data[idx][1].getTime() - nowT <= twoHours) if (data[idx][1].getTime() - nowT <= TWO_HOURS)
firstText = "Jetzt noch geöffnet"; firstText = "Jetzt noch geöffnet";
else firstText = "Jetzt geöffnet"; else firstText = "Jetzt geöffnet";
if (data[idx][1].getTime() - nowT <= tenMinutes) if (data[idx][1].getTime() - nowT <= tenMinutes)
...@@ -557,7 +593,7 @@ function asString(dataObj, now) { ...@@ -557,7 +593,7 @@ function asString(dataObj, now) {
} }
else { else {
var nextM = moment(data[idx][0]); var nextM = moment(data[idx][0]);
if (data[idx][0].getTime() - nowT <= twoHours) { if (data[idx][0].getTime() - nowT <= TWO_HOURS) {
secondText = "bald wieder geöffnet ab " + nextM.format("LT"); secondText = "bald wieder geöffnet ab " + nextM.format("LT");
} }
//uebermorgen wieder geoeffnet ab blabla im element[2] //uebermorgen wieder geoeffnet ab blabla im element[2]
...@@ -585,4 +621,5 @@ module.exports.weekV = createWeekViewVertical; ...@@ -585,4 +621,5 @@ module.exports.weekV = createWeekViewVertical;
module.exports.twoWeekV = createTwoWeekViewVertical; module.exports.twoWeekV = createTwoWeekViewVertical;
module.exports.threeMonth = create3MonthView; module.exports.threeMonth = create3MonthView;
module.exports.getView = getView; module.exports.getView = getView;
module.exports.getPropperEpochSpan = getPropperEpochSpan; module.exports.getPropperEpochSpan = getPropperEpochSpan;
\ No newline at end of file module.exports.weekViewData = weekViewData;
\ No newline at end of file
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
"chai": "^1.9.1", "chai": "^1.9.1",
"ejs": "^1.0.0", "ejs": "^1.0.0",
"express": "*", "express": "*",
"mysql": "*" "mysql": "*",
"superagent": "^1.2.0",
"supertest": "^1.0.1"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
......
...@@ -38,6 +38,9 @@ app.use(function (err, req, res, next) { ...@@ -38,6 +38,9 @@ app.use(function (err, req, res, next) {
app.set('port', process.env.PORT || 3000); app.set('port', process.env.PORT || 3000);
if(!module.parent)
var server = app.listen(app.get('port'), function () { var server = app.listen(app.get('port'), function () {
console.log('Express server listening on port ' + server.address().port); console.log('Express server listening on port ' + server.address().port);
}); });
\ No newline at end of file
module.exports = app;
\ No newline at end of file
var mysql = require('mysql');
var dateArray = require('../lib/dateArray');
var dateView = require('../lib/dateView');
var mapping = require('../mapping.json');
var util = require('util');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'bla',
database: 'dev_regionalkauf_cms'
});
connection.connect();
module.exports.getData = function (now, cb) {
var epocheSpan = dateView.getPropperEpochSpan(now);
// console.log(now);
// console.log(epocheSpan);
// dateArray.setEpocheSpan(epocheSpan);
// connection.query('SELECT name, elements FROM cms_zoo_item WHERE type in ("pos", "company") ORDER BY id', function (err, rows) {
connection.query('SELECT name, type, elements FROM cms_zoo_item WHERE id in (1793)', function (err, rows) {
console.error(err);
console.log(rows.length);
var result = [];
var cnt = 0;
var iters = rows.length;
for (var i = 0; i < rows.length; i++) {
var obj = JSON.parse(rows[i].elements);
var type = rows[i].type;
var typeM = mapping[type];
var hours = [obj[typeM['oHoursIncl']], obj[typeM['oHoursExcl']], obj[typeM['oHoursMaybe']]];
//console.log(util.inspect(hours, {depth: null}));
var plz = obj[typeM['C_ZIP']][0]['value'];
(function () {
var name = rows[i].name;
var idx = i;
dateArray(epocheSpan).getData(hours, plz, function (err, dataObj) {
console.log(dataObj);
if (err) {
console.error(name, err.stack);
}
if (dataObj && (dataObj.intervals.length > 0 || dataObj.maybeIntervals.length > 0)) {
cnt++;
var view = dateView.getView(dataObj, now);
var asString = dateView.asString(dataObj, now);
asString = asString.asString.join(", ");
// result.push('<div class="name">' + name + "</div> " + asString + view);
result[idx] = ('<div class="name">' + name + "</div> " + asString + view);
}
if (--iters == 0) {
console.log("Count: %d", cnt);
result = result.filter(function (elem) {
return !!elem;
});
cb(result.join('<br>'));
}
});
})();
}
});
};
...@@ -13,12 +13,12 @@ var data = Object.keys(ohoursMap).map(function (key) { ...@@ -13,12 +13,12 @@ var data = Object.keys(ohoursMap).map(function (key) {
}); });
data = data.filter(function (e) { data = data.filter(function (e) {
//return e.name.match(/Imkerei Schachtner/i);
return e.name.match(/Preuschl Alfred/i); return e.name.match(/Preuschl Alfred/i);
}); });
console.log(data.length);
var getData = module.exports.getData = function (now, cb) { var getData = module.exports.getData = function (now, cb) {
now = new Date("Tue Jun 02 2015 17:55:56 GMT+0200 (CEST)"); //now = new Date("Tue Jun 02 2015 17:55:56 GMT+0200 (CEST)");
var epocheSpan = dateView.getPropperEpochSpan(now); var epocheSpan = dateView.getPropperEpochSpan(now);
async.map(data, function (datum, cb) { async.map(data, function (datum, cb) {
...@@ -27,10 +27,15 @@ var getData = module.exports.getData = function (now, cb) { ...@@ -27,10 +27,15 @@ var getData = module.exports.getData = function (now, cb) {
console.error(datum.name, err.stack); console.error(datum.name, err.stack);
return cb(null, ""); return cb(null, "");
} }
if(dataObj.intervals.length && dataObj.maybeIntervals.length) {
console.log("name", datum.name);
}
var view = dateView.getView(dataObj, now); var view = dateView.getView(dataObj, now);
var asString = dateView.asString(dataObj, now); var asString = dateView.asString(dataObj, now);
var text = asString.text.join(", "); var weekViewData = dateView.weekViewData(dataObj, now);
console.log(require("util").inspect(weekViewData, {depth: null}));
var text = asString.text;
text = asString.status + " " + text; text = asString.status + " " + text;
var res = ('<div class="name">' + datum.name + "</div> " + text + view); var res = ('<div class="name">' + datum.name + "</div> " + text + view);
cb(null, res); cb(null, res);
......
...@@ -5,24 +5,63 @@ ...@@ -5,24 +5,63 @@
<title></title> <title></title>
<style> <style>
div.week.container { div.week.container {
background-color: lightgrey; position: relative;
background-color: #f1f1f1;
width: 500px; width: 500px;
height: 300px; height: 300px;
} }
table { div.week.container table {
border-collapse: collapse; border-collapse: collapse;
position: relative; position: relative;
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
td { div.week.container td {
border: 1px solid black; position: relative;
padding: 0;
border: 1px solid grey;
}
div.week.container table.inner {
position: absolute;
}
div.week.container div#item {
position: absolute;
background-color: green;
width: 14.28%;
top: 10%;
left: 0%;
height: 40%;
} }
</style> </style>
</head> </head>
<body> <body>
<div class="week container"> <div class="week container">
<table class="inner hori-lines">
<tr> <td></td> </tr>
<tr> <td></td> </tr>
<tr> <td></td> </tr>
<tr> <td></td> </tr>
<tr> <td></td> </tr>
<tr> <td></td> </tr>
<tr> <td></td> </tr>
<tr> <td></td> </tr>
<tr> <td></td> </tr>
<tr> <td></td> </tr>
<tr> <td></td> </tr>
<tr> <td></td> </tr>
</table>
<table class="inner vert-lines">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<div id="item">asd</div>
</div> </div>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment