Commit 78cadac7 authored by Johannes Bill's avatar Johannes Bill

added two week view, one week view now starts on monday

parent 964b2601
...@@ -8,7 +8,9 @@ function createWeekView(dataObj, now) { ...@@ -8,7 +8,9 @@ function createWeekView(dataObj, now) {
var data = dataObj.intervals; var data = dataObj.intervals;
var holidays = dataObj.holidays; var holidays = dataObj.holidays;
var noOfDays = 7; var noOfDays = 7;
var offset = 3; // var offset = 3;
var offset = now.getDay() - 1;
if(offset < 0) offset += 7;
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(data, startDate, endDate); var oHours = transformData(data, startDate, endDate);
...@@ -54,18 +56,27 @@ function createWeekView(dataObj, now) { ...@@ -54,18 +56,27 @@ function createWeekView(dataObj, now) {
return content; return content;
} }
function createWeekViewVertical(dataObj, now) { function createWeekViewVertical(dataObj, now, noOfDays, flexibleLayout, className) {
var data = dataObj.intervals; var data = dataObj.intervals;
var holidays = dataObj.holidays; var holidays = dataObj.holidays;
var noOfDays = 7; noOfDays = noOfDays || 7;
var offset = 3;
var offset;
if(flexibleLayout) {
offset = 3;
}
else {
offset = now.getDay() - 1;
if(offset < 0) offset += 7;
}
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(data, startDate, endDate); var oHours = transformData(data, startDate, endDate);
var maxNumber = getMaxNoOfItemsPerDay(oHours); var maxNumber = getMaxNoOfItemsPerDay(oHours);
var tableWidth = maxNumber; var tableWidth = maxNumber;
var content = '<div class="weekview-v-container"><table class="weekview-v-table">'; var content = '<div class="' + className + '-container"><table class="' + className + '-table">';
content += '<tbody>'; content += '<tbody>';
var columns = []; var columns = [];
...@@ -77,33 +88,33 @@ function createWeekViewVertical(dataObj, now) { ...@@ -77,33 +88,33 @@ function createWeekViewVertical(dataObj, now) {
var cls = ''; var cls = '';
if (dayInHolidays(day.date, holidays)) { if (dayInHolidays(day.date, holidays)) {
cls += " weekview-v-holiday"; cls += " " + className + "-holiday";
} }
if (compareDate(day.date, now) == 0) { if (compareDate(day.date, now) == 0) {
cls += " weekview-v-today"; cls += " " + className + "-today";
} }
if(day.date.getDay() == 0) { if(day.date.getDay() == 0) {
cls += " weekview-v-sunday"; cls += " " + className + "-sunday";
} }
else if(day.date.getDay() == 6) { else if(day.date.getDay() == 6) {
cls += " weekview-v-saturday"; cls += " " + className + "-saturday";
} }
var datString = formatDate(day.date); var datString = formatDate(day.date);
column.push('<td class="weekview-v-td-first' + cls + '">' + datString[0] + '</td>'); column.push('<td class="' + className + '-td-first' + cls + '">' + datString[0] + '</td>');
column.push('<td class="weekview-v-td-date' + cls + '">' + datString[1] + '</td>'); column.push('<td class="' + className + '-td-date' + cls + '">' + datString[1] + '</td>');
for (var j = 0; j < day.oHours.length; j++) { for (var j = 0; j < day.oHours.length; j++) {
var oHour = day.oHours[j]; var oHour = day.oHours[j];
column.push('<td class="weekview-v-td weekview-v-filled' + cls + '">' + formatTime(oHour[0]) + " – " + formatTime(oHour[1]) + '</td>'); column.push('<td class="' + className + '-td ' + className + '-filled' + cls + '">' + formatTime(oHour[0]) + " – " + formatTime(oHour[1]) + '</td>');
} }
for (var j = day.oHours.length; j < tableWidth; j++) { for (var j = day.oHours.length; j < tableWidth; j++) {
column.push('<td class="weekview-v-td weekview-v-empty' + cls + '"></td>'); column.push('<td class="' + className + '-td ' + className + '-empty' + cls + '"></td>');
} }
} }
for (var j = 0; j < tableWidth + 2; j++) { for (var j = 0; j < tableWidth + 2; j++) {
content += '<tr class="weekview-v-tr">'; content += '<tr class="' + className + '-tr">';
for (var i = 0; i < noOfDays; i++) { for (var i = 0; i < noOfDays; i++) {
content += columns[i][j]; content += columns[i][j];
} }
...@@ -206,9 +217,10 @@ function create3MonthView(dataObj, now) { ...@@ -206,9 +217,10 @@ function create3MonthView(dataObj, now) {
function getView(dataObj, now) { function getView(dataObj, now) {
var content = '<div class="view-container">'; var content = '<div class="view-container">';
content += createWeekView(dataObj, now); content += module.exports.weekView(dataObj, now);
content += createWeekViewVertical(dataObj, now); content += module.exports.weekViewV(dataObj, now);
content += create3MonthView(dataObj, now); content += module.exports.twoWeekViewV(dataObj, now);
content += module.exports.monthView(dataObj, now);
content += '</div>'; content += '</div>';
return content; return content;
} }
...@@ -330,7 +342,12 @@ function asString(data, now) { ...@@ -330,7 +342,12 @@ function asString(data, now) {
module.exports.asString = asString; module.exports.asString = asString;
module.exports.weekView = createWeekView; module.exports.weekView = createWeekView;
module.exports.weekViewV = createWeekViewVertical; module.exports.weekViewV = function(dataObj, now) {
return createWeekViewVertical(dataObj, now, 7, false, 'weekview-v');
};
module.exports.twoWeekViewV = function(dataObj, now) {
return createWeekViewVertical(dataObj, now, 14, true, 'two-weekview-v');
};
module.exports.monthView = create3MonthView; module.exports.monthView = create3MonthView;
module.exports.getView = getView; module.exports.getView = getView;
module.exports.getPropperEpochSpan = getPropperEpochSpan; module.exports.getPropperEpochSpan = getPropperEpochSpan;
\ No newline at end of file
...@@ -18,7 +18,7 @@ module.exports.getData = function (now, cb) { ...@@ -18,7 +18,7 @@ module.exports.getData = function (now, cb) {
// console.log(epocheSpan); // console.log(epocheSpan);
// dateArray.setEpocheSpan(epocheSpan); // dateArray.setEpocheSpan(epocheSpan);
connection.query('SELECT name, elements FROM cms_zoo_item WHERE type in ("pos", "company") LIMIT 100', function (err, rows) { connection.query('SELECT name, elements FROM cms_zoo_item WHERE type in ("pos", "company") ORDER BY id LIMIT 100', function (err, rows) {
console.log(rows.length); console.log(rows.length);
var result = []; var result = [];
var cnt = 0; var cnt = 0;
...@@ -27,22 +27,25 @@ module.exports.getData = function (now, cb) { ...@@ -27,22 +27,25 @@ module.exports.getData = function (now, cb) {
var obj = JSON.parse(rows[i].elements); var obj = JSON.parse(rows[i].elements);
(function () { (function () {
var name = rows[i].name; var name = rows[i].name;
var idx = i;
dateArray(epocheSpan).getData(obj, plz, function (err, dataObj) { dateArray(epocheSpan).getData(obj, plz, function (err, dataObj) {
if (err) { if (err) {
console.log(name, err); console.log(name, err);
} }
else if (dataObj && dataObj.intervals.length > 0) {
else if (dataObj) {
var data = dataObj.intervals;
cnt++; cnt++;
var view = dateView.getView(dataObj, now); var view = dateView.getView(dataObj, now);
var asString = dateView.asString(dataObj, now); var asString = dateView.asString(dataObj, now);
asString = asString.asString.join(", "); asString = asString.asString.join(", ");
result.push('<div class="name">' + name + "</div> " + asString + view); // result.push('<div class="name">' + name + "</div> " + asString + view);
result[idx] = ('<div class="name">' + name + "</div> " + asString + view);
} }
if (--iters == 0) { if (--iters == 0) {
console.log("Count: %d", cnt); console.log("Count: %d", cnt);
result = result.filter(function (elem) {
return !!elem;
});
cb(result.join('<br>')); cb(result.join('<br>'));
} }
}); });
......
...@@ -5,11 +5,17 @@ var db = require('../dataBaseQuery'); ...@@ -5,11 +5,17 @@ var db = require('../dataBaseQuery');
router.get('/', function(req, res) { router.get('/', function(req, res) {
var dateString = req.query.date; var dateString = req.query.date;
var now; var now;
if(dateString && dateString.length == 8) { if(dateString && dateString.length >= 8) {
var year = parseInt(dateString.slice(0,4)); var year = parseInt(dateString.slice(0,4));
var month = parseInt(dateString.slice(4,6)); var month = parseInt(dateString.slice(4,6));
var date = parseInt(dateString.slice(6,8)); var date = parseInt(dateString.slice(6,8));
now = new Date(year, month - 1, date); var hours = 0;
var minutes = 0;
if(dateString.length == 12) {
hours = dateString.slice(8, 10);
minutes = dateString.slice(10, 12);
}
now = new Date(year, month - 1, date, hours, minutes);
} }
else { else {
now = new Date(); now = new Date();
......
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