119 lines
5.1 KiB
JavaScript
119 lines
5.1 KiB
JavaScript
const {embeddedSvgFromPath, parsePositionLabel, compilePositionLabel} = require("../lib/utils")
|
|
var hb = require('hbs').create();
|
|
|
|
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.flagsString = (flags) => {
|
|
return flags != null ? Array.from(flags).join(",") : ''
|
|
};
|
|
exports.plus1 = (i) => Number(i)+1;
|
|
exports.positions = () => ["P", "C", "1B", "2B", "3B", "SS", "LF", "CF", "RF", "EH", "DH", "DR"];
|
|
exports.defense_positions = () => ["C", "1B", "2B", "3B", "SS", "LF", "CF", "RF", "P"];
|
|
exports.avail_status_code_class = (status_code) => statusCodeButtonClasses[status_code];
|
|
exports.avail_status_code_icon = (status_code) => statusCodeIcons[status_code];
|
|
exports.positionLabelWithoutFlags = (label) => {
|
|
const {positionLabelWithoutFlags} = parsePositionLabel(label);
|
|
return positionLabelWithoutFlags
|
|
};
|
|
exports.positionLabelWithoutPOFlag = (label) => {
|
|
const {positionLabelWithoutFlags, positionFlags} = parsePositionLabel(label);
|
|
positionFlags.delete('PO')
|
|
return compilePositionLabel(positionLabelWithoutFlags, positionFlags)
|
|
};
|
|
exports.positionFlags = (label)=> {
|
|
const {positionFlags} = parsePositionLabel(label);
|
|
return `[${Array.from(positionFlags).join(",")}]`
|
|
};
|
|
exports.hasPositionFlags = (label) => {
|
|
const {positionLabelWithoutFlags, positionFlags} = parsePositionLabel(label);
|
|
return positionFlags.size > 0;
|
|
};
|
|
exports.comparePositionWithFlags = (labelWithoutFlags, eventLineupEntry, options) => {
|
|
labelWithFlags = eventLineupEntry?.label
|
|
const {positionLabelWithoutFlags} = parsePositionLabel(labelWithFlags);
|
|
return positionLabelWithoutFlags == labelWithoutFlags;
|
|
};
|
|
exports.isStarting = (member) => {
|
|
return (member.benchcoach?.eventLineupEntry != null);
|
|
};
|
|
exports.isInStartingLineup = (member) => {
|
|
if (member.benchcoach.eventLineupEntry == null || member.benchcoach.eventLineupEntry.label == '') return false;
|
|
const {positionFlags} = parsePositionLabel(member.benchcoach.eventLineupEntry?.label);
|
|
return (!positionFlags.has("PO"))
|
|
};
|
|
exports.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"))
|
|
};
|
|
exports.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)
|
|
};
|
|
exports. 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)
|
|
};
|
|
exports.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])
|
|
};
|
|
exports.filterNonPlayers = (members) => {
|
|
return members.filter(m=>!m.isNonPlayer)
|
|
};
|
|
exports.joinMemberEmailAddresses = (members) => {
|
|
return members.map(m=>m.emailAddresses.join(',')).join(',')
|
|
}
|
|
exports.loadSlots = (options) =>{
|
|
var s = ""
|
|
const {members, event_lineup, event_lineup_entries, event, availabilities} = options.data.root
|
|
event_lineup_entries.forEach(eventLineupEntry =>{
|
|
const availability = availabilities.find(a=>a.memberId==eventLineupEntry.memberId)
|
|
const member = members.find(m=>m.id==eventLineupEntry.memberId)
|
|
const {positionFlags} = parsePositionLabel(eventLineupEntry.label)
|
|
const initial_slotset = `lineup-${positionFlags.has('PO') ? 'positiononly' : 'starting'}-${event.id}`
|
|
|
|
s+=options.fn({eventLineupEntry, availability, member, event, initial_slotset})
|
|
})
|
|
const players_without_lineup_entry = members.filter(
|
|
member=>!event_lineup_entries.map(lue=>lue.memberId).includes(member.id) && !member.isNonPlayer
|
|
)
|
|
players_without_lineup_entry.forEach(member =>{
|
|
const availability = availabilities.find(a=>a.memberId==member.id)
|
|
let initial_slotset
|
|
if (availability?.statusCode == 0 || availability?.statusCode == null) {
|
|
initial_slotset =`lineup-out-${event.id}`
|
|
} else {
|
|
initial_slotset =`lineup-bench-${event.id}`
|
|
}
|
|
s+=options.fn({availability, member, event, initial_slotset})
|
|
})
|
|
return s
|
|
} |