Commit bf62679d authored by Johannes Bill's avatar Johannes Bill

refactoring

parent d3a276df
......@@ -24,7 +24,6 @@ var connection = mysql.createPool(config["mysqlConfig"]);
module.exports.getBundesland = function(plz, cb) {
connection.query("SELECT bundesland FROM postleitzahlen WHERE plz = '" + plz + "'", function (err, result) {
if (err) return cb(err);
var blnd;
try {
blnd = result[0]['bundesland'];
......@@ -54,13 +53,4 @@ module.exports.getKatholisch = function(plz, cb) {
return cb(new Error("no entry found in religion table for plz " + plz));
cb(null, !!feiertag);
});
};
/*getBundesland(4600, function (err, result) {
console.log(err);
console.log(result);
});*/
/*getKatholisch(93047, function (err, result) {
console.log(err);
console.log(result);
});*/
};
\ No newline at end of file
var holidayMapping = require('./holidayMapping.json');
var easterSunday = require('./easterSunday');
var restRequest = require('./blndRelDbRequest');
var requestHandler = require('./blndRelDbRequest');
var easterSundays = {};
var fixedHolidays = {
......@@ -26,26 +26,6 @@ var variableOffsets = {
602: 50
};
var inverseHdMap = (function () {
var regionH = holidayMapping["region"];
var hMap = {};
for (var rKey in regionH) {
var rH = regionH[rKey];
for (var cKey in rH) {
var hArray = rH[cKey];
for (var i = 0; i < hArray.length; i++) {
var hd = hArray[i];
if (!hMap[hd])
hMap[hd] = [];
hMap[hd].push({
region: rKey,
category: cKey
});
}
}
}
return hMap;
}());
function Holidays(year) {
......@@ -108,19 +88,24 @@ function Holidays(year) {
if (specialKeys.length == 0) {
return cb(null, initKeys);
}
restRequest.getBundesland(plz, function (err, blnd) {
requestHandler.getBundesland(plz, function (err, blnd) {
if (err) return cb(err);
var keys = holidayMapping["sureHolidays"].filter(function(key) {
return initKeys.indexOf(key) >= 0;
});
var regionMap = holidayMapping["region"][blnd];
var regHD = regionMap['default'];
for (var i = 0; i < regHD.length; i++) {
var key = regHD[i];
if (initKeys.indexOf(key) >= 0) {
keys.push(key);
if(regionMap) {
var regionHolidays = regionMap['default'];
for (var i = 0; i < regionHolidays.length; i++) {
var key = regionHolidays[i];
if (initKeys.indexOf(key) >= 0) {
keys.push(key);
}
}
}
else {
console.error(new Error("No Mapping for Bundesland: " + blnd));
}
if(blnd != "BY") {
cb(null, keys);
}
......@@ -134,7 +119,7 @@ function Holidays(year) {
}
}
if(regionMap["kath"] && regionMap["kath"].length > 0) {
restRequest.getKatholisch(plz, function(err, kath) {
requestHandler.getKatholisch(plz, function(err, kath) {
if(err) return cb(err);
if(kath) {
var kathHDs = regionMap["kath"];
......@@ -185,4 +170,13 @@ function Holidays(year) {
module.exports = Holidays;
/**
* set the object for handling the requests figuring out the bundesland and katholic
* for testing reasons
* @param handler
*/
module.exports.setRequestHandler = function(handler) {
requestHandler = handler;
};
//var hds = new Holidays(2014);
......@@ -9,8 +9,7 @@
"chai": "^1.9.1",
"ejs": "^1.0.0",
"express": "*",
"mysql": "*",
"v8-profiler": "^5.1.0"
"mysql": "*"
},
"author": "",
"license": "ISC",
......
var dateView = require('../lib/dateView');
var dateArray = require('../lib/dateArray');
var ejs = require('ejs');
var fs = require('fs');
var now = new Date(2014, 7, 10);
var holidays = require('../lib/holidays');
var handler = {
getBundesland: function(plz, cb) {
cb(null, "BY");
},
getKatholisch: function (plz, cb) {
cb(null, true);
}
};
holidays.setRequestHandler(handler);
var now = new Date();
dateArray(dateView.getPropperEpochSpan(now)).getData(require('../mochaTests/testData/testHof.json'), 0, function(err, data) {
dateArray(dateView.getPropperEpochSpan(now)).getData(require('../mochaTests/testData/testHof.json'), 93047, function(err, data) {
var view = dateView.getView(data, now, 93047);
var template = fs.readFileSync('./template.ejs', {encoding: 'utf8'});
view = ejs.render(template, {body: view});
fs.writeFile(process.env["HOME"] + '/Desktop/bla.html', view, function (err) {
fs.writeFile('./testView/test.html', view, {encoding: 'utf8'}, function (err) {
if (err) console.log(err);
else console.log("file saved");
});
......
<!DOCTYPE html>
<html>
<head>
<title>Views</title>
<link rel="stylesheet" href="uikit.min.css"/>
<link rel="stylesheet" href="test.css"/>
<script src="jquery.min.js"></script>
<script src="uikit.min.js"></script>
<style>
</style>
</head>
<body>
<div class="uk-grid uk-grid-preserve main-content Direktvermarkter mit Geschäft rk-premium public">
<%- body %>
</div>
</body>
</html>
This diff is collapsed.
.weekview-table {
width: 100%
}
td {
}
.monthview-container {
text-align: center
}
.monthview-month {
font-family: 'rk_bold'
}
.monthview-maindiv {
width: 30%;
display: inline-block;
text-align: left;
margin-top: 15px
}
.monthview-table {
border-spacing: 2px;
border-collapse: separate
}
.monthview-table
td {
padding: 0px 5px
}
.monthview-today {
color: #fff;
background: rgb(160, 130, 70);
font-family: 'rk_bold'
}
.monthview-today.monthview-filled {
background: rgb(70, 120, 0)
}
.monthview-filled {
background: rgb(90, 140, 0);
color: #fff;
text-align: center;
cursor: pointer;
margin: 2px
}
.monthview-holiday {
background: rgba(160, 0, 0, 0.4);
color: #fff;
text-align: center;
margin: 2px
}
.monthview-holiday.monthview-filled {
background: rgb(90, 140, 0)
}
.weekview-table {
width: 100%;
margin-left: -15px
}
.weekview-container {
margin-top: 10px
}
.weekview-table tr td.weekview-today {
background: rgba(255, 255, 255, 0.6)
}
.weekview-table
tr {
border-top: 1px solid rgba(100, 80, 60, 0.5)
}
.weekview-table tr:last-child {
border-bottom: 1px solid rgba(100, 80, 60, 0.5)
}
.weekview-table td.weekview-td:first-child {
font-family: 'rk_bold';
width: 33%;
padding-left: 15px
}
.weekview-3col td.weekview-filled, .weekview-table td.weekview-empty {
width: 33%
}
.weekview-4col td.weekview-td:first-child {
width: 25%
}
.weekview-4col td.weekview-filled, .weekview-table td.weekview-empty {
width: 25%
}
.weekview-5col td.weekview-td:first-child {
width: 20%
}
.weekview-5col td.weekview-filled, .weekview-table td.weekview-empty {
width: 20%
}
.weekview-6col td.weekview-td:first-child {
width: 25%
}
.weekview-6col td.weekview-filled, .weekview-table td.weekview-empty {
width: 15%
}
.weekview-v-container {
margin: 20px 35px 0px 0px
}
.weekview-v-table tr:first-child {
border-top: 1px solid rgba(100, 80, 60, 0.5)
}
.weekview-v-table tr:last-child {
border-bottom: 1px solid rgba(100, 80, 60, 0.5)
}
.weekview-v-sunday, .weekview-sunday {
color: rgba(160, 0, 0, 0.8)
}
.weekview-v-table {
width: 100%;
text-align: center
}
.weekview-v-table td.weekview-v-td-first {
font-family: 'rk_bold'
}
.weekview-v-table td.weekview-v-today {
background: rgba(255, 255, 255, 0.6);
color: rgb(90, 140, 0)
}
.weekview-v-table
td {
width: 14%
}
.weekview-v-table td:first-child {
width: 16%
}
.two-weekview-v-container {
margin: 20px 35px 0px 0px
}
.two-weekview-v-table tr:first-child {
border-top: 1px solid rgba(100, 80, 60, 0.5)
}
.two-weekview-v-table tr:last-child {
border-bottom: 1px solid rgba(100, 80, 60, 0.5)
}
.two-weekview-v-sunday, .two-weekview-sunday {
color: rgba(160, 0, 0, 0.8)
}
.two-weekview-v-table .two-weekview-v-td-date2 {
padding-top: 15px
}
.two-weekview-v-table {
width: 100%;
text-align: center
}
.two-weekview-v-table td.two-weekview-v-td-first {
font-family: 'rk_bold'
}
.two-weekview-v-table td.two-weekview-v-today {
background: rgba(255, 255, 255, 0.6);
color: rgb(90, 140, 0)
}
.two-weekview-v-table
td {
width: 14%
}
.two-weekview-v-table td:first-child {
width: 16%
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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