move eventlineup helpers to separate file
This commit is contained in:
@@ -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)
|
||||
|
||||
100
src/helpers/eventlineup.js
Normal file
100
src/helpers/eventlineup.js
Normal file
@@ -0,0 +1,100 @@
|
||||
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 = (members, event_lineup, event_lineup_entries, event) =>{
|
||||
var s = ""
|
||||
members.forEach(member => {
|
||||
s+=hb.render("eventlineup/partials/slot", {member, event})
|
||||
});
|
||||
console.log('here')
|
||||
}
|
||||
Reference in New Issue
Block a user