Skip to content

Commit

Permalink
Replace var with const or let
Browse files Browse the repository at this point in the history
  • Loading branch information
eeroan committed Dec 5, 2016
1 parent 49ddf81 commit e3fdb90
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 78 deletions.
4 changes: 2 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require('newrelic')
var app = require('./src/router')
var port = process.env.PORT || 5000
const app = require('./src/router')
const port = process.env.PORT || 5000
app.listen(port, () => console.log('Server started at localhost:' + port))
20 changes: 10 additions & 10 deletions src/dao/dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const MongoClient = require('mongodb').MongoClient
const mongoUri = process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || 'mongodb://localhost/test';
const rates = require('../../generated/rates')
const format = require('../format')
var db = null
let db = null

module.exports = {
sendFreeCourts,
Expand All @@ -19,7 +19,7 @@ module.exports = {
}

function sendFreeCourts(req, res) {
var forceRefresh = req.query.refresh === 'true' || false
const forceRefresh = req.query.refresh === 'true' || false
freeCourts(req.query.date, Number(req.query.days) || 1, forceRefresh,
data => res.send(data),
err => res.status(500).send(err))
Expand Down Expand Up @@ -106,8 +106,8 @@ function getType({type, field, res}) {
if(type) {
return type
}
var isBubble = /kupla/i.test(field) || /kupla/i.test(res) || /Kaarihalli.*/i.test(field)
var isOutdoor = /ulko/i.test(field) || /ulko/i.test(res)
const isBubble = /kupla/i.test(field) || /kupla/i.test(res) || /Kaarihalli.*/i.test(field)
const isOutdoor = /ulko/i.test(field) || /ulko/i.test(res)
return isBubble ? 'bubble' : (isOutdoor ? 'outdoor' : 'indoor')
}
function fetch(isoDate) {
Expand Down Expand Up @@ -140,16 +140,16 @@ function fetch(isoDate) {
}

function getPrice(dateTime, time, location, type) {
var hm = time.split(':')
var timeKey = format.formatTimeKey(hm)
var weekDay = (dateTime.getDay() + 6) % 7
var priceByType = _.get(rates, [location, type, timeKey, weekDay], 0)
var commonPrice = _.get(rates, [location, timeKey, weekDay], 0)
const hm = time.split(':')
const timeKey = format.formatTimeKey(hm)
const weekDay = (dateTime.getDay() + 6) % 7
const priceByType = _.get(rates, [location, type, timeKey, weekDay], 0)
const commonPrice = _.get(rates, [location, timeKey, weekDay], 0)
return priceByType || commonPrice
}

function withDoubleLessonInfo(freeCourts) {
var timeAndPlace = {}
const timeAndPlace = {}
freeCourts.forEach(court => {
timeAndPlace[court.date + 'T' + court.time + court.location + court.field] = true
})
Expand Down
6 changes: 3 additions & 3 deletions src/dao/webTimmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const date = require('../date')
const _ = require('lodash')

const req = (method, url, cookie, form) => {
var opts = {
const opts = {
url: `https://timmi.talintenniskeskus.fi/WebTimmi/${url}`,
headers: {
Cookie: cookie,
Expand Down Expand Up @@ -72,11 +72,11 @@ const getRoomPartsForCalendarAjax = (cookie, profileId) => json(post('getRoomPar
id: profileId
}))
const updateStructure = (cookie, startTime, endTime, roomPartIds, dateTime) => {
var form = {
const form = {
startTime: startTime,
endTime: endTime
}
var dayName = DateFormat.format(dateTime, 'l', DateLocale.EN).toLocaleLowerCase() + 'Selected'
const dayName = DateFormat.format(dateTime, 'l', DateLocale.EN).toLocaleLowerCase() + 'Selected'
form[dayName] = '1'
return post('weekViewAjaxAction.do', cookie, {
oper: 'updateStructure',
Expand Down
10 changes: 5 additions & 5 deletions src/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ function formatTimeKey(hm) {
}

function parseTime(isoTime) {
var hm = isoTime.split(':')
const hm = isoTime.split(':')
return String(formatTimeKey(hm))
}

function formatTime(val) {
var hour = Math.floor(val / 10)
var min = Math.round(val % 10 * .6)
const hour = Math.floor(val / 10)
const min = Math.round(val % 10 * .6)
return hour + ':' + min + '0'
}

function formatIsoTime(val) {
var hour = Math.floor(val / 10)
var min = Math.round(val % 10 * .6)
const hour = Math.floor(val / 10)
const min = Math.round(val % 10 * .6)
return (hour >= 10 ? hour : '0' + hour) + ':' + min + '0'
}

Expand Down
58 changes: 29 additions & 29 deletions src/front.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var DateTime = require('dateutils').DateTime
var attachFastClick = require('fastclick')
var navigation = require('./navigation')
const DateTime = require('dateutils').DateTime
const attachFastClick = require('fastclick')
const navigation = require('./navigation')
attachFastClick(document.body)
var markupForDateRange = require('./markupForDateRange')
var locations = require('../generated/locations')
const markupForDateRange = require('./markupForDateRange')
const locations = require('../generated/locations')
const format = require('./format')
var didScroll = false
var alreadyLoadingMoreResults = false
var today = DateTime.fromIsoDate(window.serverDate)
var activeDate = today.plusDays(2)
let didScroll = false
let alreadyLoadingMoreResults = false
const today = DateTime.fromIsoDate(window.serverDate)
let activeDate = today.plusDays(2)
const body = document.body
window.addEventListener('scroll', () => {
didScroll = true
Expand All @@ -22,30 +22,30 @@ setInterval(() => {
}
}
}, 250)
var schedule = document.getElementById('schedule')
const schedule = document.getElementById('schedule')
navigation.init(bindEsc)
listAvailabilityForActiveDate(30)
var reservationModal = document.querySelector('.reservationModal')
const reservationModal = document.querySelector('.reservationModal')
reservationModal.addEventListener('click', e => {
var clickArea = e.target
const clickArea = e.target
if(clickArea.classList.contains('close')) {
reservationModal.style.display = 'none'
unbindEsc()
}
})
schedule.addEventListener('click', e => {
var clickArea = e.target
var openAction = clickArea.classList.contains('locationLabel')
const clickArea = e.target
const openAction = clickArea.classList.contains('locationLabel')
if(openAction) {
var locationBoxes = clickArea.parentNode
var obj = JSON.parse(locationBoxes.getAttribute('data-fields'))
var date = obj.date
var time = obj.time
var fields = obj.fields
var location = obj.location
const locationBoxes = clickArea.parentNode
const obj = JSON.parse(locationBoxes.getAttribute('data-fields'))
const date = obj.date
const time = obj.time
const fields = obj.fields
const location = obj.location
reservationModal.innerHTML = reservationModalMarkup(date, time, fields, location)
reservationModal.style.display = 'block'
var distance = today.distanceInDays(DateTime.fromIsoDate(date))
const distance = today.distanceInDays(DateTime.fromIsoDate(date))
ga('send', 'event', 'Reservation', distance)
bindEsc()
}
Expand All @@ -65,12 +65,12 @@ function loadMoreResults(days) {
}

function reservationModalMarkup(date, time, fields, selectedLocation) {
var dateTime = DateTime.fromIsoDate(date)
var locationObject = locations.find(loc => loc.title === selectedLocation)
var address = locationObject.address
var url = locationObject.url
var tel = locationObject.tel
var title = locationObject.title
const dateTime = DateTime.fromIsoDate(date)
const locationObject = locations.find(loc => loc.title === selectedLocation)
const address = locationObject.address
const url = locationObject.url
const tel = locationObject.tel
const title = locationObject.title
return `<h2>${selectedLocation}</h2> <p>${format.formatDate(dateTime)} klo ${time}</p>
<h3>Lisää kalenteriin</h3> <div class="fields">${fields.map(toButtonMarkup).join('')}</div>
<h3>Tiedot</h3>
Expand Down Expand Up @@ -108,7 +108,7 @@ function linksMarkup(address, url, tel, title) {
}

function listAvailabilityForActiveDate(days) {
var requestedDate = activeDate.toISODateString()
const requestedDate = activeDate.toISODateString()
activeDate = activeDate.plusDays(days - 1)
schedule.classList.add('loading')
alreadyLoadingMoreResults = true
Expand All @@ -125,7 +125,7 @@ function listAvailabilityForActiveDate(days) {
}

function getJson(url, cb) {
var request = new XMLHttpRequest()
const request = new XMLHttpRequest()
request.open('GET', url, true)
request.onload = () => {
if(request.status >= 200 && request.status < 400) {
Expand Down
6 changes: 3 additions & 3 deletions src/history/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function historyMarkup(location, historyData) {
const sortedDates = historyDataGrouped.map(x=>x.dateTime)
const firstDate = DateTime.fromIsoDateTime(_.first(sortedDates))
const lastDate = DateTime.fromIsoDateTime(_.last(sortedDates))
var days = firstDate.distanceInDays(lastDate)
var dates = _.range(0, days + 1).map(num=>firstDate.plusDays(num)).map(date=>({
const days = firstDate.distanceInDays(lastDate)
const dates = _.range(0, days + 1).map(num=>firstDate.plusDays(num)).map(date=>({
dateTime: date,
formattedDate: DateFormat.format(date, 'D j.n', DateLocale.FI)
}))
Expand Down Expand Up @@ -74,7 +74,7 @@ function groupByDate(data) {
})).sort((a, b) => a.dateTime > b.dateTime ? 1 : -1)
}

var timesObj = {}
const timesObj = {}
times.forEach(time=>timesObj[time] = 0)

function getWeeklyAvailability(historyData, location) {
Expand Down
2 changes: 1 addition & 1 deletion src/mainPage/mainPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
}

function show(req, res) {
var refresh = req.query.refresh === 'true'
const refresh = req.query.refresh === 'true'
res.write(`<!DOCTYPE html>
<html>`)
res.write(headHtml({locations: locations, _:_}))
Expand Down
2 changes: 1 addition & 1 deletion src/mapView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var locations = require('../generated/locations')
const locations = require('../generated/locations')

module.exports = {
renderMap
Expand Down
24 changes: 12 additions & 12 deletions src/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const defaults = {
end: 235,
collapsed: false
}
var settings = loadFilters() || defaults
const settings = loadFilters() || defaults
const schedule = document.getElementById('schedule')
const body = document.body

module.exports = {
init
}

var mapMissing = true
let mapMissing = true

function reportSettings(settings) {
return `${activeFilters(settings).sort().join(' ')} ${settings.start}-${settings.end} ${settings.collapsed ? 'collapsed' : ''}`
Expand Down Expand Up @@ -73,8 +73,8 @@ function init(bindEsc) {
function initFeedback() {
elem('.feedbackForm').addEventListener('submit', e => {
e.preventDefault()
var feedback = elem('.feedback')
var text = feedback.value
const feedback = elem('.feedback')
const text = feedback.value
window.ga('send', 'event', 'Feedback', text)
feedback.value = ''
const submitFeedback = elem('.submitFeedback')
Expand All @@ -90,16 +90,16 @@ function toggleNavi() {
}

function toggleObj(key, objRoot) {
var obj = (typeToggles.indexOf(key) >= 0) ? objRoot.typeToggles : objRoot.fieldToggles
const obj = (typeToggles.indexOf(key) >= 0) ? objRoot.typeToggles : objRoot.fieldToggles
if (key in obj) delete obj[key]
else obj[key] = true

}

var all = _.range(60, 235, 5)
const all = _.range(60, 235, 5)

function initTimeFilter() {
var slider = document.getElementById('slider')
const slider = document.getElementById('slider')
noUiSlider.create(slider, {
start: [settings.start, settings.end],
step: 5,
Expand All @@ -114,15 +114,15 @@ function initTimeFilter() {
}
})
slider.noUiSlider.on('update', (values, endTime) => {
var isStart = !endTime
const isStart = !endTime
setStartAndEndLabels(isStart, format.parseTime(values[endTime]))
})
slider.noUiSlider.on('change', () => {
setContainerFilterClasses()
saveFilters()
})
}
var $rangeLabel = elem('.rangeLabel')
const $rangeLabel = elem('.rangeLabel')

function setStartAndEndLabels(isStart, val) {
if (isStart) settings.start = Number(val)
Expand All @@ -131,7 +131,7 @@ function setStartAndEndLabels(isStart, val) {
}

function setContainerFilterClasses() {
var hiddenTimes = all.filter(time => time < settings.start || time > settings.end)
const hiddenTimes = all.filter(time => time < settings.start || time > settings.end)
body.className = activeFilters(settings).concat(hiddenTimes.map(time => 'h' + time)).join(' ')
}

Expand All @@ -147,8 +147,8 @@ function saveFilters() {
}

function loadFilters() {
var jsonString = window.localStorage.getItem('filters')
var parsedJson = JSON.parse(jsonString)
const jsonString = window.localStorage.getItem('filters')
const parsedJson = JSON.parse(jsonString)
if (!parsedJson) return null
if (jsonString) window.ga('send', 'event', 'User settings', reportSettings(parsedJson))
return {
Expand Down
8 changes: 4 additions & 4 deletions test/crawler.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var fs = require('fs')
var slSystems = require('../src/dao/slSystemsCrawler')
const fs = require('fs')
const slSystems = require('../src/dao/slSystemsCrawler')

describe('sls systems crawler', () => {
var obj
var expected
let obj
let expected
before(() => {
obj = slSystems.table(fs.readFileSync(__dirname + '/fixture/meilahti.html', 'utf-8'))
expected = JSON.parse(fs.readFileSync(__dirname + '/fixture/meilahti.json', 'utf-8'))
Expand Down
4 changes: 2 additions & 2 deletions test/integration.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Browser = require('zombie')
const browser = new Browser({waitDuration: '15s'})
var app = require('../src/router')
var port = process.env.PORT || 5001
const app = require('../src/router')
const port = process.env.PORT || 5001
global.isTest = true
describe('Loads list of free courts', function () {
this.timeout(19000)
Expand Down
10 changes: 4 additions & 6 deletions worker.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
process.env.NEW_RELIC_ENABLED = true
require('newrelic')
var DateTime = require('dateutils').DateTime
var dao = require('./src/dao/dao')
const DateTime = require('dateutils').DateTime
const dao = require('./src/dao/dao')

updateReservations(2)
setTimeout(() => updateReservations(60), 1000 * 60 * 2)

function updateReservations(days) {
var daysAhead = 0
var maxDaysAhead = days

function updateReservations(maxDaysAhead) {
let daysAhead = 0
doRefresh()
setInterval(() => {
doRefresh()
Expand Down

0 comments on commit e3fdb90

Please sign in to comment.