Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scouter names & super scout notes to CSV data export #273

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion primary/src/routes/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,7 @@ router.get('/exportdata', wrap(async (req, res) => {
}
let pivotDataKeys = pivotDataCols.split(',');
let isFirstRow = true;
const isAuthorized = req._user.role.access_level >= Permissions.ACCESS_SCOUTER;
for (let i in scored) {
if (scored[i].data) {
let thisScored = scored[i];
Expand All @@ -1504,12 +1505,20 @@ router.get('/exportdata', wrap(async (req, res) => {
isFirstRow = false;
// initialize header row with particular columns
let headerRow = pivotDataCols;
// add scouter name if authorized
if (isAuthorized) {
headerRow += ',scouter';
}
// add on metric IDs
for (let thisItem of matchLayout) {
// 2022-04-04 JL: If the user is not logged in as a scouter, then don't include otherNotes in the export
if (matchDataHelper.isMetric(thisItem.type) && !isOtherNotesAndUnauthorized(thisItem))
headerRow += ',' + thisItem.id;
}
// add super notes if authorized
if (isAuthorized) {
headerRow += ',superNotes';
}
//logger.debug("headerRow=" + headerRow);
fullCSVoutput = headerRow;
}
Expand Down Expand Up @@ -1540,6 +1549,18 @@ router.get('/exportdata', wrap(async (req, res) => {
dataRow += thisVal.replace(/(\r\n|\n|\r)/gm,'');
}

// add scouter name if authorized
if (isAuthorized) {
if ('actual_scorer' in thisScored)
dataRow += ',"' + (thisScored.actual_scorer?.name ?? '') + '"';

else if ('actual_scouter' in thisScored)
dataRow += ',"' + (thisScored.actual_scouter?.name ?? '') + '"';

else
dataRow += ',';
}

// cycle through the metrics
for (let thisItem of matchLayout) {
// 2022-04-04 JL: If the user is not logged in as a scouter, then don't include otherNotes in the export
Expand All @@ -1552,14 +1573,17 @@ router.get('/exportdata', wrap(async (req, res) => {
}
}
}
if (isAuthorized) {
dataRow += ',"' + ('' + (thisScored.super_data?.otherNotes ?? '')).replace(/(\r\n|\n|\r)/gm,'') + '"';
}
//logger.debug("dataRow=" + dataRow);
fullCSVoutput += '\n' + dataRow;
}
}

// If the layout item is otherNotes and the user is unauthorized to view it, return false.
function isOtherNotesAndUnauthorized(thisItem: Layout) {
return (thisItem.id === 'otherNotes' && req._user.role.access_level < Permissions.ACCESS_SCOUTER);
return (thisItem.id === 'otherNotes' && !isAuthorized);
}

logger.info('EXIT returning ' + scored.length + ' rows of CSV');
Expand Down