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

weekview

parent fd64692e
......@@ -7,7 +7,6 @@ var andMaybeString = "und nach Absprache geöffnet";
moment.locale("de");
var twoHours = 1000 * 3600 * 2;
function merge(a, b) {
if (a.length === 0)
......@@ -134,7 +133,6 @@ function hoursMaybe(oHours) {
function createWeekViewVerticalRaw(dataObj, now, className, offset, addDayOfWeek) {
var noOfDays = 7;
if (!offset) {
offset = now.getDay() - 1;
if (offset < 0) offset += 7;
......@@ -143,7 +141,6 @@ function createWeekViewVerticalRaw(dataObj, now, className, offset, addDayOfWeek
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);
console.log(require("util").inspect(oHours, {depth: null}));
var hasMaybe = hoursMaybe(oHours);
......@@ -297,7 +294,7 @@ function createMonthView(dataObj, now, monthOffset) {
var startDate = new Date(now.getFullYear(), now.getMonth() + monthOffset, 1);
var monthDate = new Date(startDate);
if(startDate.getDay() === 0) {
if (startDate.getDay() === 0) {
startDate.setDate(-5);
}
else {
......@@ -402,7 +399,7 @@ function getMaxNoOfItemsPerDay(oHours) {
function formatDate(date) {
var mom = moment(date);
return [mom.format("dddd"), mom.format("ll") ];
return [mom.format("dddd"), mom.format("ll")];
}
function formatTime(date) {
......@@ -414,8 +411,42 @@ function formatTime(date) {
// 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) {
var data = dataObj.intervals.map(function (e) {
return e;
return {
0: e[0],
1: e[1],
......@@ -424,6 +455,7 @@ function transformData(dataObj, startDate, endDate) {
});
var dataMaybe = dataObj.maybeIntervals.map(function (e) {
return e;
return {
0: e[0],
1: e[1],
......@@ -447,7 +479,8 @@ function transformData(dataObj, startDate, endDate) {
function dataIterator(data) {
var idx = 0;
var len = data.length;
return {next: function () {
return {
next: function () {
var res = [];
while (idx < len) {
var comp = compareDate(data[idx][0], curDate);
......@@ -461,7 +494,8 @@ function transformData(dataObj, startDate, endDate) {
else break;
}
return res;
}}
}
}
}
var dataIt = dataIterator(data);
......@@ -472,7 +506,7 @@ function transformData(dataObj, startDate, endDate) {
var oHours = dataIt.next();
var oHoursMaybe = dataMaybeIt.next();
var oHoursMerged = dataMergedIt.next();
//var oHoursMerged = dataMergedIt.next();
var isHoliday = false;
while (holidayIdx < holidays.length) {
......@@ -491,7 +525,7 @@ function transformData(dataObj, startDate, endDate) {
date: new Date(curDate),
oHours: oHours,
oHoursMaybe: oHoursMaybe,
oHoursMerged: oHoursMerged,
//oHoursMerged: oHoursMerged,
holiday: isHoliday
});
curDate.setDate(curDate.getDate() + 1);
......@@ -517,6 +551,8 @@ function getPropperEpochSpan(now) {
var tenMinutes = 10 * 60 * 1000;
function asString(dataObj, now) {
const TWO_HOURS = 1000 * 3600 * 2;
var data = dataObj.intervals;
if (data.length == 0) {
......@@ -540,7 +576,7 @@ function asString(dataObj, now) {
}
if (open) {
idx--;
if (data[idx][1].getTime() - nowT <= twoHours)
if (data[idx][1].getTime() - nowT <= TWO_HOURS)
firstText = "Jetzt noch geöffnet";
else firstText = "Jetzt geöffnet";
if (data[idx][1].getTime() - nowT <= tenMinutes)
......@@ -557,7 +593,7 @@ function asString(dataObj, now) {
}
else {
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");
}
//uebermorgen wieder geoeffnet ab blabla im element[2]
......@@ -586,3 +622,4 @@ module.exports.twoWeekV = createTwoWeekViewVertical;
module.exports.threeMonth = create3MonthView;
module.exports.getView = getView;
module.exports.getPropperEpochSpan = getPropperEpochSpan;
module.exports.weekViewData = weekViewData;
\ No newline at end of file
......@@ -10,7 +10,9 @@
"chai": "^1.9.1",
"ejs": "^1.0.0",
"express": "*",
"mysql": "*"
"mysql": "*",
"superagent": "^1.2.0",
"supertest": "^1.0.1"
},
"author": "",
"license": "ISC",
......
......@@ -38,6 +38,9 @@ app.use(function (err, req, res, next) {
app.set('port', process.env.PORT || 3000);
if(!module.parent)
var server = app.listen(app.get('port'), function () {
console.log('Express server listening on port ' + server.address().port);
});
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) {
});
data = data.filter(function (e) {
//return e.name.match(/Imkerei Schachtner/i);
return e.name.match(/Preuschl Alfred/i);
});
console.log(data.length);
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);
async.map(data, function (datum, cb) {
......@@ -27,10 +27,15 @@ var getData = module.exports.getData = function (now, cb) {
console.error(datum.name, err.stack);
return cb(null, "");
}
if(dataObj.intervals.length && dataObj.maybeIntervals.length) {
console.log("name", datum.name);
}
var view = dateView.getView(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;
var res = ('<div class="name">' + datum.name + "</div> " + text + view);
cb(null, res);
......
......@@ -5,24 +5,63 @@
<title></title>
<style>
div.week.container {
background-color: lightgrey;
position: relative;
background-color: #f1f1f1;
width: 500px;
height: 300px;
}
table {
div.week.container table {
border-collapse: collapse;
position: relative;
width: 100%;
height: 100%;
}
td {
border: 1px solid black;
div.week.container td {
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>
</head>
<body>
<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>
</body>
</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