add dr, dh flags

This commit is contained in:
2024-03-15 08:38:15 -05:00
parent b53c8c532e
commit 61b6dc8a35
5 changed files with 94 additions and 23 deletions

View File

@@ -15,9 +15,11 @@ const statusCodeIcons = {
}
exports.helpers = {
flagsString: (flags) => flags?.join(","),
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"],
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_icon: (status_code) => {
const icon_classes = {
@@ -39,7 +41,21 @@ exports.helpers = {
return `<button class="Button Button--smallSquare ${button_classes[status_code]}" type="button"><span class="">${statusCodeIcons[status_code]}</span></button>`
},
positionLabelWithoutFlags: (label) => {
return label.replace(/(.*?)\s\[(.*?)\]/, "$1");
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
@@ -52,12 +68,12 @@ exports.helpers = {
isInStartingLineup: (member) => {
if (member.benchcoach.eventLineupEntry == null || member.benchcoach.eventLineupEntry.label == '') return false;
const {positionFlags} = parsePositionLabel(member.benchcoach.eventLineupEntry?.label);
return (positionFlags != "PO")
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 == "PO")
return (member.benchcoach.eventLineupEntry != null && positionFlags.has("PO"))
},
isInBench: (member) => {
if ((member.benchcoach.eventLineupEntry != null && member.benchcoach.eventLineupEntry.label != '') || member.isNonPlayer) return false;
@@ -143,29 +159,39 @@ exports.postEventLineup = async (req,res) => {
if (body.memberId == null) {res.status(400).end();return}
await Promise.all(req.promises);
const eventLineupEntries = req.event_lineup.eventLineupEntries
const {newEventLineupEntries} = processPostedEventLineupEntries(body, eventLineupEntries, req.event_lineup)
const {newEventLineupEntries, deleteEventLineupEntries} = processPostedEventLineupEntries(body, eventLineupEntries, req.event_lineup)
newEventLineupEntries.forEach(e=>{
teamsnap.saveEventLineupEntry(e)
})
deleteEventLineupEntries.forEach(e=>{
teamsnap.deleteEventLineupEntry(e)
})
eventLineup = await teamsnap.loadEventLineups(req.params.event_id)
res.status(201).end()
}
const processPostedEventLineupEntries = (body, eventLineupEntries, eventLineup) => {
const newEventLineupEntries = []
const deleteEventLineupEntries = []
body.memberId.forEach((memberId, i)=>{
const lineupEntryId = body.eventLineupEntryId[i]
const lineupEntryLabel = body.label[i]
const lineupEntrySequence = body.sequence[i]
const lineupEntryFlags = body.flags[i]
if (lineupEntryId != '') {
if (lineupEntryId != '' && lineupEntryLabel != '') {
// Update lineup entry
const eventLineupEntry = eventLineupEntries.find((e)=>e.id==Number(lineupEntryId))
eventLineupEntry.sequence = lineupEntrySequence
eventLineupEntry.label = compilePositionLabel(lineupEntryLabel, lineupEntryFlags)
newEventLineupEntries.push(eventLineupEntry)
}
else if (lineupEntryId != '') {
// Delete lineup entry
const eventLineupEntry = eventLineupEntries.find((e)=>e.id==Number(lineupEntryId))
deleteEventLineupEntries.push(eventLineupEntry)
}
else if (lineupEntryLabel != '') {
// Create lineup entry
const eventLineupEntry = teamsnap.createEventLineupEntry()
@@ -179,5 +205,5 @@ const processPostedEventLineupEntries = (body, eventLineupEntries, eventLineup)
// Skip lineup entry
}
})
return {newEventLineupEntries, eventLineupEntries}
return {newEventLineupEntries, eventLineupEntries, deleteEventLineupEntries}
}

View File

@@ -157,12 +157,13 @@ exports.parsePositionLabel = (label) => {
const pattern = /(?<pos>[A-Z0-9]+)(?:\s\[(?<flags>.[A-z,]+)\])?/g
const {pos, flags} = pattern.exec(label)?.groups || {}
const positionLabelWithoutFlags= pos
const positionFlags = flags?.split(',').map(f=>f.trim()) || []
const positionFlags = new Set(flags?.split(',').map(f=>f.trim()) || [])
return {positionLabelWithoutFlags, positionFlags}
}
exports.compilePositionLabel = (label, flags) => {
if (flags == null || flags == '' || flags.lengh == 0) {
if (flags == null || flags == '' || flags.size == 0) {
return label
}
else {

View File

@@ -39,6 +39,28 @@ function colorPositions() {
}
}
function initFlagsCheckboxes(){
Array.from(document.querySelectorAll("[id^=event-lineup]")).forEach((bcLineup) => {
Array.from(
bcLineup.querySelectorAll(
".starting .lineup-slot, \
.position-only .lineup-slot, \
.bench .lineup-slot"
)
).forEach((slot, i) => {
const flags = new Set(slot.querySelector("input[name*=flags]")?.value?.split(',')?.map(s=>s.trim())) || new Set()
console.log(slot, flags)
if (flags.has('DHd')) {
slot.querySelector('[name=flag-dhd]').checked = true;
}
if (flags.has('DRd') ) {
slot.querySelector('[name=flag-drd]').checked = true;
}
})}
)
}
function refreshLineup() {
Array.from(document.querySelectorAll("[id^=event-lineup]")).forEach((bcLineup) => {
Array.from(
@@ -50,25 +72,36 @@ function refreshLineup() {
).forEach((slot, i) => {
slot.querySelector("input[name*=sequence]").value = i;
selected_position = slot.querySelector(".position-select-box option:checked");
const flags = new Set(slot.querySelector("input[name*=flags]")?.value?.split(',')?.map(s=>s.trim())) || new Set()
if (slot.querySelector('[name=flag-dhd]').checked) {
flags.add('DHd')
} else {
flags.delete('DHd')
}
if (slot.querySelector('[name=flag-drd]').checked) {
flags.add('DRd')
} else {
flags.delete('DRd')
}
if (selected_position && selected_position.text != "--") {
slot.querySelector("input[name*=label]").value = selected_position.text;
} else {
slot.querySelector("input[name*=label]").value = null;
}
if (slot.closest('.position-only')){
const flags = new Set(slot.querySelector("input[name*=flags]").value.split(',').map(s=>s.trim()))
flags.add('PO');flags.delete('')
slot.querySelector("input[name*=flags]").value = Array.from(flags).join(",");
}
else {
const flags = new Set(slot.querySelector("input[name*=flags]").value.split(',').map(s=>s.trim()))
flags.delete('PO');flags.delete('')
slot.querySelector("input[name*=flags]").value = Array.from(flags).join(",");
}
if (slot.closest('.bench')){
slot.querySelector("input[name*=sequence]").value = '';
slot.querySelector("input[name*=label]").value = '';
}
slot.querySelector("input[name*=flags]").value = Array.from(flags).join(",");
});
});
}
@@ -105,7 +138,7 @@ for (bcLineup of document.querySelectorAll("[id^=event-lineup]")) {
}
for (lineup_slot of document.querySelectorAll("[id^=lineup-out] .lineup-slot")) {
const cells = lineup_slot.querySelectorAll('.Panel-cell:has(.sequence), .Panel-cell:has(.drag-handle), .Panel-cell:has(.position-select-box) ')
const cells = lineup_slot.querySelectorAll('.Panel-cell:has(.sequence), .Panel-cell:has(.drag-handle), .Panel-cell:has(.position-select-box), div.position-label-flags')
Array.from(cells).forEach(cell=>{
cell.classList.add('u-hidden')
})
@@ -503,7 +536,7 @@ function toggleChildSlots (element) {
console.log(element.closest(".slot-set"))
for (lineup_slot of document.querySelectorAll("[id^=lineup-out] .lineup-slot")) {
console.log(lineup_slot)
const cells = lineup_slot.querySelectorAll('.Panel-cell:has(.sequence), .Panel-cell:has(.drag-handle), .Panel-cell:has(.position-select-box) ')
const cells = lineup_slot.querySelectorAll('.Panel-cell:has(.sequence), .Panel-cell:has(.drag-handle), .Panel-cell:has(.position-select-box), div.position-label-flags ')
Array.from(cells).forEach(cell=>{
cell.classList.toggle('u-hidden')
})

View File

@@ -11,10 +11,10 @@
{{#if (isInStartingLineup this)}}
<tr>
<td class="sequence-cell">
{{plus1 this.benchcoach.eventLineupEntry.sequence}}
{{plus1 this.benchcoach.eventLineupEntry.sequence}}{{#if (hasPositionFlags this.benchcoach.eventLineupEntry.label)}} {{positionFlags this.benchcoach.eventLineupEntry.label}}{{/if}}
</td>
<td class="name-cell">{{this.lastName}}, {{this.firstName}} #{{this.jerseyNumber}}</td>
<td class="position-label-cell">{{this.benchcoach.eventLineupEntry.label}}</td>
<td class="position-label-cell">{{positionLabelWithoutFlags this.benchcoach.eventLineupEntry.label}}</td>
</tr>
{{/if}}
{{/each}}
@@ -26,7 +26,7 @@
<tr>
<td class="sequence-cell"></td>
<td class="name-cell">{{this.lastName}}, {{this.firstName}} #{{this.jerseyNumber}}</td>
<td class="position-label-cell">{{this.benchcoach.eventLineupEntry.label}}</td>
<td class="position-label-cell">{{positionLabelWithoutPOFlag this.benchcoach.eventLineupEntry.label}}</td>
</tr>
{{/if}}
{{/each}}

View File

@@ -15,14 +15,15 @@
class="Panel-cell Panel-cell--header">
<div class="sequence u-textNoWrap u-fontSizeLg"></div>
</div>
<div class="Panel-cell u-padXs u-sizeFill">
<div class="Panel-cell u-padXs u-sizeFill u-flex">
<div
class="d-flex availability-status-code-{{
class="availability-status-code-{{
member.benchcoach.availability?.statusCode
}}"
>
<div class="u-flexInline u-fontSizeLg u-textNoWrap">
{{#if member.benchcoach.availability}}{{{avail_status_code_icon member.benchcoach.availability.statusCode}}}{{/if}}
{{#if member.benchcoach.availability}}{{{avail_status_code_icon member.benchcoach.availability.statusCode}}}{{/if}}
</div>
<div class="u-fontSizeLg u-textNoWrap">
<span class="lastname">
{{member.lastName}}
</span>
@@ -32,6 +33,16 @@
<span class="jerseynumber u-hidden u-sm-inline u-fontSizeSm">
#{{member.jerseyNumber}}
</span>
</div>
<div class="u-flexGrow1"></div>
<div class="position-label-flags">
<div class="Checkbox Checkbox--inline">
<input class="Checkbox-input" type="checkbox" name="flag-drd" id="flag-drd-{{member.id}}-{{member.benchcoach.eventLineupEntry.id}}" onclick="refreshLineup()">
<label class="Checkbox-label" for="flag-drd-{{member.id}}-{{member.benchcoach.eventLineupEntry.id}}">DR<small>d</small></label>
</div>
<div class="Checkbox Checkbox--inline">
<input class="Checkbox-input" type="checkbox" name="flag-dhd" id="flag-dhd-{{member.id}}-{{member.benchcoach.eventLineupEntry.id}}" onclick="refreshLineup()">
<label class="Checkbox-label" for="flag-dhd-{{member.id}}-{{member.benchcoach.eventLineupEntry.id}}">DH<small>d</small></label>
</div>
</div>
</div>