Last active
November 14, 2019 18:23
-
-
Save tomexx/01373723549ab815594b4932f6d69f4b to your computer and use it in GitHub Desktop.
Hurrier McDonald's pickup alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $container = $('.container.well').eq(0) | |
const $tableLines = $container.find('.active_deliveries > tbody > tr') | |
const colorSuccess = '#009e45' | |
const colorError = 'red' | |
const overloadLimit = 3 | |
const courierMap = new Map() | |
let overloadedCouriers = [] | |
// create mapping | |
$tableLines.each((key, el) => { | |
const $courierCell = $(el).find('td').eq(0) | |
const courier = $courierCell.text().trim() | |
const link = $courierCell.find('a').clone().css({ display: 'block' }) | |
const pickup = $(el).find('td').eq(5).find('div').eq(0).text().trim() | |
if (pickup.startsWith('McDonald')) { | |
if (courierMap.get(courier)) { | |
courierMap.set(courier, courierMap.get(courier) + 1) | |
if (courierMap.get(courier) === overloadLimit) { | |
overloadedCouriers.push(link) | |
} | |
} else { | |
courierMap.set(courier, 1) | |
} | |
} | |
}) | |
// draw counts | |
$tableLines.each((key, el) => { | |
const $courierTd = $(el).find('td').eq(0) | |
const courier = $courierTd.text().trim() | |
const count = courierMap.get(courier) | |
if (count) { | |
const $count = $('<span>', { | |
'class': 'dj-count', | |
'css': { | |
'font-size': '13px', | |
'margin-top': '-1px', | |
'margin-left': '2px', | |
'background': (count >= overloadLimit) ? colorError : colorSuccess, | |
'color': 'white', | |
'border-radius': '4px', | |
'padding': '2px 6px', | |
} | |
}) | |
$count.appendTo($courierTd).text(courierMap.get(courier)) | |
} | |
}) | |
const hasOverload = Array.from(courierMap.values()).filter(item => item >= overloadLimit).length | |
const $djInfo = $('<div>', { | |
'class': 'dj-info', | |
'css': { | |
'border': '2px solid #ddd', | |
'border-color': hasOverload ? colorError : colorSuccess, | |
'color': 'white', | |
'border-radius': '5px', | |
} | |
}) | |
const $djInfoHeadline = $('<div>', { | |
'class': 'dj-info-headline', | |
'css': { | |
'padding': '5px 10px', | |
'color': 'white', | |
'background-color': hasOverload ? colorError : colorSuccess, | |
}, | |
}) | |
$container.prepend($djInfo) | |
$djInfoHeadline.appendTo($djInfo).text(hasOverload ? `There are couriers with ${overloadLimit}+ McDonald's pickups:` : `There are no couriers with ${overloadLimit}+ McDonald\'s pickups`) | |
const $djInfoCouriers = $('<div>', { | |
'class': 'dj-info-couriers', | |
'css': { | |
'padding': '5px 10px', | |
}, | |
}) | |
if (hasOverload) { | |
$djInfoCouriers.appendTo($djInfo) | |
$djInfoCouriers.append(overloadedCouriers) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment