Commit a1e2dfd9 authored by Johannes Bill's avatar Johannes Bill

modifications for hallo-nachbarn

parent fbfec87c
"use strict"; "use strict";
var Promise = require('bluebird');
var dateArray = require('./lib/dateArray'); var dateArray = require('./lib/dateArray');
var dateView = require('./lib/dateView'); var dateView = require('./lib/dateView');
var splitMidnight = require('./lib/timeUtils').splitMidnight; var splitMidnight = require('./lib/timeUtils').splitMidnight;
function mapEvents(intervals) { function mapEvents(intervals) {
if (intervals) { if (intervals) {
return splitMidnight(intervals).map(function(evt) { // var splitIntervals = splitMidnight(intervals);
var splitIntervals = intervals;
return splitIntervals.map(function(evt) {
return { return {
startDate: evt[0], startDate: evt[0],
endDate: evt[1] endDate: evt[1]
...@@ -26,6 +28,7 @@ function transform(x) { ...@@ -26,6 +28,7 @@ function transform(x) {
return res; return res;
} }
// intervals for elasticsearch index (to allow opening hours filters)
function getOHIndex(info, today, cb) { function getOHIndex(info, today, cb) {
today = new Date(today.getFullYear(), today.getMonth(), today.getDate()); today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
...@@ -59,7 +62,7 @@ function mapCustomIntervals(customIvals) { ...@@ -59,7 +62,7 @@ function mapCustomIntervals(customIvals) {
return res; return res;
} }
// for detail view, events* contain intervals {from, to}
function getFull(info, now, cb) { function getFull(info, now, cb) {
var epocheSpan = dateView.getPropperEpochSpan(now); var epocheSpan = dateView.getPropperEpochSpan(now);
dateArray(epocheSpan).getData(info, function (err, dataObj) { dateArray(epocheSpan).getData(info, function (err, dataObj) {
...@@ -70,7 +73,7 @@ function getFull(info, now, cb) { ...@@ -70,7 +73,7 @@ function getFull(info, now, cb) {
isOpen: short.isOpen, isOpen: short.isOpen,
text: short.text, text: short.text,
status: short.status, status: short.status,
weekView: dateView.weekViewData(dataObj, now), // weekView: dateView.weekViewData(dataObj, now),
events: mapEvents(dataObj.intervals), events: mapEvents(dataObj.intervals),
eventsMaybe: mapEvents(dataObj.maybeIntervals), eventsMaybe: mapEvents(dataObj.maybeIntervals),
customEvents: mapCustomIntervals(dataObj.customIntervals) customEvents: mapCustomIntervals(dataObj.customIntervals)
...@@ -80,6 +83,7 @@ function getFull(info, now, cb) { ...@@ -80,6 +83,7 @@ function getFull(info, now, cb) {
}) })
} }
// for list view
function getShort(info, now, cb) { function getShort(info, now, cb) {
var epocheSpan = dateView.getPropperEpochSpan(now); var epocheSpan = dateView.getPropperEpochSpan(now);
dateArray(epocheSpan).getData(info, function (err, dataObj) { dateArray(epocheSpan).getData(info, function (err, dataObj) {
...@@ -89,10 +93,12 @@ function getShort(info, now, cb) { ...@@ -89,10 +93,12 @@ function getShort(info, now, cb) {
}) })
} }
// info is {state: "Bayern", zip: 1234, religiousHoliday: true, data: {include, exclude, maybe}}
module.exports = { module.exports = {
getOHIndex: getOHIndex, getOHIndex: Promise.promisify(getOHIndex),
getFull: getFull, getFull: Promise.promisify(getFull),
getShort: getShort, getShort: Promise.promisify(getShort)
pretify: require('./lib/pretifyData').pretify
}; };
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"async": "^2.0.1", "async": "^2.0.1",
"bluebird": "^3.4.6",
"moment": "^2.15.0" "moment": "^2.15.0"
}, },
"devDependencies": { "devDependencies": {
......
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