move eventlineup helpers to separate file

This commit is contained in:
2024-05-06 10:41:44 -05:00
parent 3695cd8975
commit c4c0d0fb7d
2 changed files with 101 additions and 94 deletions

View File

@@ -5,100 +5,7 @@ const tsUtils = require('../lib/utils')
const { loadEventLineupEntries } = require('teamsnap.js')
exports.partials = path.join(__dirname, "../views/eventlineup/partials")
const statusCodeIcons = {
1: embeddedSvgFromPath("/teamsnap-ui/assets/icons/check.svg"),
0: embeddedSvgFromPath("/teamsnap-ui/assets/icons/dismiss.svg"),
2: embeddedSvgFromPath("/bootstrap-icons/question-lg.svg"),
null: embeddedSvgFromPath("/bootstrap-icons/question.svg"),
undefined: embeddedSvgFromPath("/bootstrap-icons/question-lg.svg")
}
const statusCodeClasses = {
1: "u-colorPositive",
0: "u-colorNegative",
2: "u-colorPrimary",
null: "u-colorGrey",
undefined: "u-colorGrey"
}
const statusCodeButtonClasses = {
1: "Button--yes",
0: "Button--no",
2: "Button--maybe",
null: "",
undefined: ""
}
exports.helpers = {
flagsString: (flags) => {
return flags != null ? Array.from(flags).join(",") : ''
},
plus1: (i) => Number(i)+1,
positions: () => ["P", "C", "1B", "2B", "3B", "SS", "LF", "CF", "RF", "EH", "DH", "DR"],
defense_positions: () => ["C", "1B", "2B", "3B", "SS", "LF", "CF", "RF", "P"],
avail_status_code_class: (status_code) => statusCodeButtonClasses[status_code],
avail_status_code_icon: (status_code) => statusCodeIcons[status_code],
positionLabelWithoutFlags: (label) => {
const {positionLabelWithoutFlags} = parsePositionLabel(label);
return positionLabelWithoutFlags
},
positionLabelWithoutPOFlag: (label) => {
const {positionLabelWithoutFlags, positionFlags} = parsePositionLabel(label);
positionFlags.delete('PO')
return compilePositionLabel(positionLabelWithoutFlags, positionFlags)
},
positionFlags: (label)=> {
const {positionFlags} = parsePositionLabel(label);
return `[${Array.from(positionFlags).join(",")}]`
},
hasPositionFlags: (label) => {
const {positionLabelWithoutFlags, positionFlags} = parsePositionLabel(label);
return positionFlags.size > 0;
},
comparePositionWithFlags: (labelWithoutFlags, eventLineupEntry, options) => {
labelWithFlags = eventLineupEntry?.label
const {positionLabelWithoutFlags} = parsePositionLabel(labelWithFlags);
return positionLabelWithoutFlags == labelWithoutFlags;
},
isStarting: (member) => {
return (member.benchcoach?.eventLineupEntry != null);
},
isInStartingLineup: (member) => {
if (member.benchcoach.eventLineupEntry == null || member.benchcoach.eventLineupEntry.label == '') return false;
const {positionFlags} = parsePositionLabel(member.benchcoach.eventLineupEntry?.label);
return (!positionFlags.has("PO"))
},
isInPositionOnly: (member) => {
if (!member.benchcoach || member.benchcoach.eventLineupEntry == null) return false;
const {positionFlags} = parsePositionLabel(member.benchcoach.eventLineupEntry?.label);
return (member.benchcoach.eventLineupEntry != null && positionFlags.has("PO"))
},
isInBench: (member) => {
if ((member.benchcoach.eventLineupEntry != null && member.benchcoach.eventLineupEntry.label != '') || member.isNonPlayer) return false;
return (member.benchcoach.availability?.statusCode != 0 && member.benchcoach.availability?.statusCode != null)
},
isInOut: (member) => {
if ((member.benchcoach.eventLineupEntry != null && member.benchcoach.eventLineupEntry.label != '') || member.isNonPlayer) return false;
return (member.benchcoach.availability?.statusCode == 0 || member.benchcoach.availability?.statusCode == null)
},
availabilityStatusShort: (availability) => {
const {YES, MAYBE, NO, NONE} = teamsnap.AVAILABILITIES
const statusShortLookup = {}
statusShortLookup[YES] = "YES"
statusShortLookup[MAYBE] = "MAY"
statusShortLookup[NO] = "NO"
statusShortLookup[NONE] = "UNK"
statusShortLookup[undefined] = "UNK"
return (statusShortLookup[availability?.statusCode])
},
filterNonPlayers: (members) => {
return members.filter(m=>!m.isNonPlayer)
},
joinMemberEmailAddresses: (members) => {
return members.map(m=>m.emailAddresses.join(',')).join(',')
}
}
exports.helpers = require('../helpers/eventlineup.js')
exports.getEventLineup = async (req, res)=>{
await Promise.all(req.promises)