add dr, dh flags
This commit is contained in:
@@ -15,9 +15,11 @@ const statusCodeIcons = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.helpers = {
|
exports.helpers = {
|
||||||
flagsString: (flags) => flags?.join(","),
|
flagsString: (flags) => {
|
||||||
|
return flags != null ? Array.from(flags).join(",") : ''
|
||||||
|
},
|
||||||
plus1: (i) => Number(i)+1,
|
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"],
|
defense_positions: () => ["C", "1B", "2B", "3B", "SS", "LF", "CF", "RF", "P"],
|
||||||
avail_status_code_icon: (status_code) => {
|
avail_status_code_icon: (status_code) => {
|
||||||
const icon_classes = {
|
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>`
|
return `<button class="Button Button--smallSquare ${button_classes[status_code]}" type="button"><span class="">${statusCodeIcons[status_code]}</span></button>`
|
||||||
},
|
},
|
||||||
positionLabelWithoutFlags: (label) => {
|
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) => {
|
comparePositionWithFlags: (labelWithoutFlags, eventLineupEntry, options) => {
|
||||||
labelWithFlags = eventLineupEntry?.label
|
labelWithFlags = eventLineupEntry?.label
|
||||||
@@ -52,12 +68,12 @@ exports.helpers = {
|
|||||||
isInStartingLineup: (member) => {
|
isInStartingLineup: (member) => {
|
||||||
if (member.benchcoach.eventLineupEntry == null || member.benchcoach.eventLineupEntry.label == '') return false;
|
if (member.benchcoach.eventLineupEntry == null || member.benchcoach.eventLineupEntry.label == '') return false;
|
||||||
const {positionFlags} = parsePositionLabel(member.benchcoach.eventLineupEntry?.label);
|
const {positionFlags} = parsePositionLabel(member.benchcoach.eventLineupEntry?.label);
|
||||||
return (positionFlags != "PO")
|
return (!positionFlags.has("PO"))
|
||||||
},
|
},
|
||||||
isInPositionOnly: (member) => {
|
isInPositionOnly: (member) => {
|
||||||
if (!member.benchcoach || member.benchcoach.eventLineupEntry == null) return false;
|
if (!member.benchcoach || member.benchcoach.eventLineupEntry == null) return false;
|
||||||
const {positionFlags} = parsePositionLabel(member.benchcoach.eventLineupEntry?.label);
|
const {positionFlags} = parsePositionLabel(member.benchcoach.eventLineupEntry?.label);
|
||||||
return (member.benchcoach.eventLineupEntry != null && positionFlags == "PO")
|
return (member.benchcoach.eventLineupEntry != null && positionFlags.has("PO"))
|
||||||
},
|
},
|
||||||
isInBench: (member) => {
|
isInBench: (member) => {
|
||||||
if ((member.benchcoach.eventLineupEntry != null && member.benchcoach.eventLineupEntry.label != '') || member.isNonPlayer) return false;
|
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}
|
if (body.memberId == null) {res.status(400).end();return}
|
||||||
await Promise.all(req.promises);
|
await Promise.all(req.promises);
|
||||||
const eventLineupEntries = req.event_lineup.eventLineupEntries
|
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=>{
|
newEventLineupEntries.forEach(e=>{
|
||||||
teamsnap.saveEventLineupEntry(e)
|
teamsnap.saveEventLineupEntry(e)
|
||||||
})
|
})
|
||||||
|
deleteEventLineupEntries.forEach(e=>{
|
||||||
|
teamsnap.deleteEventLineupEntry(e)
|
||||||
|
})
|
||||||
|
|
||||||
eventLineup = await teamsnap.loadEventLineups(req.params.event_id)
|
eventLineup = await teamsnap.loadEventLineups(req.params.event_id)
|
||||||
res.status(201).end()
|
res.status(201).end()
|
||||||
}
|
}
|
||||||
|
|
||||||
const processPostedEventLineupEntries = (body, eventLineupEntries, eventLineup) => {
|
const processPostedEventLineupEntries = (body, eventLineupEntries, eventLineup) => {
|
||||||
const newEventLineupEntries = []
|
const newEventLineupEntries = []
|
||||||
|
const deleteEventLineupEntries = []
|
||||||
|
|
||||||
body.memberId.forEach((memberId, i)=>{
|
body.memberId.forEach((memberId, i)=>{
|
||||||
const lineupEntryId = body.eventLineupEntryId[i]
|
const lineupEntryId = body.eventLineupEntryId[i]
|
||||||
const lineupEntryLabel = body.label[i]
|
const lineupEntryLabel = body.label[i]
|
||||||
const lineupEntrySequence = body.sequence[i]
|
const lineupEntrySequence = body.sequence[i]
|
||||||
const lineupEntryFlags = body.flags[i]
|
const lineupEntryFlags = body.flags[i]
|
||||||
if (lineupEntryId != '') {
|
if (lineupEntryId != '' && lineupEntryLabel != '') {
|
||||||
// Update lineup entry
|
// Update lineup entry
|
||||||
const eventLineupEntry = eventLineupEntries.find((e)=>e.id==Number(lineupEntryId))
|
const eventLineupEntry = eventLineupEntries.find((e)=>e.id==Number(lineupEntryId))
|
||||||
eventLineupEntry.sequence = lineupEntrySequence
|
eventLineupEntry.sequence = lineupEntrySequence
|
||||||
eventLineupEntry.label = compilePositionLabel(lineupEntryLabel, lineupEntryFlags)
|
eventLineupEntry.label = compilePositionLabel(lineupEntryLabel, lineupEntryFlags)
|
||||||
newEventLineupEntries.push(eventLineupEntry)
|
newEventLineupEntries.push(eventLineupEntry)
|
||||||
}
|
}
|
||||||
|
else if (lineupEntryId != '') {
|
||||||
|
// Delete lineup entry
|
||||||
|
const eventLineupEntry = eventLineupEntries.find((e)=>e.id==Number(lineupEntryId))
|
||||||
|
deleteEventLineupEntries.push(eventLineupEntry)
|
||||||
|
}
|
||||||
else if (lineupEntryLabel != '') {
|
else if (lineupEntryLabel != '') {
|
||||||
// Create lineup entry
|
// Create lineup entry
|
||||||
const eventLineupEntry = teamsnap.createEventLineupEntry()
|
const eventLineupEntry = teamsnap.createEventLineupEntry()
|
||||||
@@ -179,5 +205,5 @@ const processPostedEventLineupEntries = (body, eventLineupEntries, eventLineup)
|
|||||||
// Skip lineup entry
|
// Skip lineup entry
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return {newEventLineupEntries, eventLineupEntries}
|
return {newEventLineupEntries, eventLineupEntries, deleteEventLineupEntries}
|
||||||
}
|
}
|
||||||
@@ -157,12 +157,13 @@ exports.parsePositionLabel = (label) => {
|
|||||||
const pattern = /(?<pos>[A-Z0-9]+)(?:\s\[(?<flags>.[A-z,]+)\])?/g
|
const pattern = /(?<pos>[A-Z0-9]+)(?:\s\[(?<flags>.[A-z,]+)\])?/g
|
||||||
const {pos, flags} = pattern.exec(label)?.groups || {}
|
const {pos, flags} = pattern.exec(label)?.groups || {}
|
||||||
const positionLabelWithoutFlags= pos
|
const positionLabelWithoutFlags= pos
|
||||||
const positionFlags = flags?.split(',').map(f=>f.trim()) || []
|
const positionFlags = new Set(flags?.split(',').map(f=>f.trim()) || [])
|
||||||
|
|
||||||
return {positionLabelWithoutFlags, positionFlags}
|
return {positionLabelWithoutFlags, positionFlags}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.compilePositionLabel = (label, flags) => {
|
exports.compilePositionLabel = (label, flags) => {
|
||||||
if (flags == null || flags == '' || flags.lengh == 0) {
|
if (flags == null || flags == '' || flags.size == 0) {
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -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() {
|
function refreshLineup() {
|
||||||
Array.from(document.querySelectorAll("[id^=event-lineup]")).forEach((bcLineup) => {
|
Array.from(document.querySelectorAll("[id^=event-lineup]")).forEach((bcLineup) => {
|
||||||
Array.from(
|
Array.from(
|
||||||
@@ -50,25 +72,36 @@ function refreshLineup() {
|
|||||||
).forEach((slot, i) => {
|
).forEach((slot, i) => {
|
||||||
slot.querySelector("input[name*=sequence]").value = i;
|
slot.querySelector("input[name*=sequence]").value = i;
|
||||||
selected_position = slot.querySelector(".position-select-box option:checked");
|
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 != "--") {
|
if (selected_position && selected_position.text != "--") {
|
||||||
slot.querySelector("input[name*=label]").value = selected_position.text;
|
slot.querySelector("input[name*=label]").value = selected_position.text;
|
||||||
} else {
|
} else {
|
||||||
slot.querySelector("input[name*=label]").value = null;
|
slot.querySelector("input[name*=label]").value = null;
|
||||||
}
|
}
|
||||||
if (slot.closest('.position-only')){
|
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('')
|
flags.add('PO');flags.delete('')
|
||||||
slot.querySelector("input[name*=flags]").value = Array.from(flags).join(",");
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const flags = new Set(slot.querySelector("input[name*=flags]").value.split(',').map(s=>s.trim()))
|
|
||||||
flags.delete('PO');flags.delete('')
|
flags.delete('PO');flags.delete('')
|
||||||
slot.querySelector("input[name*=flags]").value = Array.from(flags).join(",");
|
|
||||||
}
|
}
|
||||||
if (slot.closest('.bench')){
|
if (slot.closest('.bench')){
|
||||||
slot.querySelector("input[name*=sequence]").value = '';
|
slot.querySelector("input[name*=sequence]").value = '';
|
||||||
slot.querySelector("input[name*=label]").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")) {
|
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=>{
|
Array.from(cells).forEach(cell=>{
|
||||||
cell.classList.add('u-hidden')
|
cell.classList.add('u-hidden')
|
||||||
})
|
})
|
||||||
@@ -503,7 +536,7 @@ function toggleChildSlots (element) {
|
|||||||
console.log(element.closest(".slot-set"))
|
console.log(element.closest(".slot-set"))
|
||||||
for (lineup_slot of document.querySelectorAll("[id^=lineup-out] .lineup-slot")) {
|
for (lineup_slot of document.querySelectorAll("[id^=lineup-out] .lineup-slot")) {
|
||||||
console.log(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=>{
|
Array.from(cells).forEach(cell=>{
|
||||||
cell.classList.toggle('u-hidden')
|
cell.classList.toggle('u-hidden')
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -11,10 +11,10 @@
|
|||||||
{{#if (isInStartingLineup this)}}
|
{{#if (isInStartingLineup this)}}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="sequence-cell">
|
<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>
|
||||||
<td class="name-cell">{{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}</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>
|
</tr>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="sequence-cell"></td>
|
<td class="sequence-cell"></td>
|
||||||
<td class="name-cell">{{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}</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>
|
</tr>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|||||||
@@ -15,14 +15,15 @@
|
|||||||
class="Panel-cell Panel-cell--header">
|
class="Panel-cell Panel-cell--header">
|
||||||
<div class="sequence u-textNoWrap u-fontSizeLg"></div>
|
<div class="sequence u-textNoWrap u-fontSizeLg"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="Panel-cell u-padXs u-sizeFill">
|
<div class="Panel-cell u-padXs u-sizeFill u-flex">
|
||||||
<div
|
<div
|
||||||
class="d-flex availability-status-code-{{
|
class="availability-status-code-{{
|
||||||
member.benchcoach.availability?.statusCode
|
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">
|
<span class="lastname">
|
||||||
{{member.lastName}}
|
{{member.lastName}}
|
||||||
</span>
|
</span>
|
||||||
@@ -33,6 +34,16 @@
|
|||||||
#{{member.jerseyNumber}}
|
#{{member.jerseyNumber}}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
<div class="Panel-cell u-padXs u-sizeFit">
|
<div class="Panel-cell u-padXs u-sizeFit">
|
||||||
|
|||||||
Reference in New Issue
Block a user