Skip to content

Commit

Permalink
Avoid passing the fieldId
Browse files Browse the repository at this point in the history
  • Loading branch information
micsucmed authored and ThiefMaster committed Nov 6, 2024
1 parent 047cada commit 86a327a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 60 deletions.
5 changes: 1 addition & 4 deletions indico_jacow/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

from indico_jacow.controllers import (RHAbstractsExportCSV, RHAbstractsExportExcel, RHAbstractsStats,
RHContributionsExportCSV, RHContributionsExportExcel,
RHDisplayAbstractsStatistics, RHPeerReviewManagersExportCSV,
RHPeerReviewManagersImport)
RHDisplayAbstractsStatistics, RHPeerReviewManagersImport)


blueprint = IndicoPluginBlueprint('jacow', __name__, url_prefix='/event/<int:event_id>')
Expand All @@ -31,5 +30,3 @@
RHContributionsExportExcel, methods=('POST',))
blueprint.add_url_rule('/manage/peer_review/managers/upload', 'peer_review_managers_import',
RHPeerReviewManagersImport, methods=('POST',))
blueprint.add_url_rule('/manage/peer_review/managers/peer_review_managers.csv', 'peer_review_managers_export',
RHPeerReviewManagersExportCSV, methods=('GET',))
76 changes: 48 additions & 28 deletions indico_jacow/client/PeerReviewManagersFileInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// them and/or modify them under the terms of the MIT License; see
// the LICENSE file for more details.

import downloadManagersFileURL from 'indico-url:plugin_jacow.peer_review_managers_export'
import uploadManagersFileURL from 'indico-url:plugin_jacow.peer_review_managers_import'

import PropTypes from 'prop-types';
Expand Down Expand Up @@ -63,7 +62,7 @@ const PeerReviewManagersFileInput = ({
}

const onDropAccepted = useCallback(async ([acceptedFile]) => {
Object.assign(acceptedFile, {filename: acceptedFile.name});
acceptedFile.filename = acceptedFile.name;
const isSuccess = await getUserList(acceptedFile, eventId);
if(isSuccess){
setFile(acceptedFile);
Expand All @@ -86,7 +85,7 @@ const PeerReviewManagersFileInput = ({
};


export default function PeerReviewManagersFileField ({onClose, fieldId, eventId, onChange}) {
export default function PeerReviewManagersFileField ({onClose, eventId, onChange}) {
const [unknownEmails, setUnknownEmails] = useState([])
const [userIdentifiers, setUserIdentifiers] = useState([])
const [loading, setLoading] = useState(false)
Expand All @@ -102,7 +101,7 @@ export default function PeerReviewManagersFileField ({onClose, fieldId, eventId,
size="small"
onClose={onClose}
onSubmit={handleSubmit}
header={`Import ${fieldId.replace('_', ' ')}`}
header={Translate.string('Import from CSV')}
submitLabel={Translate.string('Import')}
>
<Message info icon>
Expand Down Expand Up @@ -161,35 +160,56 @@ export default function PeerReviewManagersFileField ({onClose, fieldId, eventId,
)
}

export function PeerReviewManagersFileButton ({fieldId, eventId, onChange}) {
export function PeerReviewManagersFileButton ({entries, importExport, eventId, onChange}) {
const [fileImportVisible, setFileImportVisible] = useState(false);

if (fieldId !== 'judges' && fieldId !== 'content_reviewers'){
return null
const downloadCSV = () => {
const headers = ['First Name', 'Last Name', 'Email', 'Phone Number'];
const rows = entries.map(e => [
e.firstName,
e.lastName,
e.email,
e.phone || 'N/A'
]);

let csvContent = 'data:text/csv;charset=utf-8,';
csvContent += headers.join(',') + '\n';
rows.forEach(row => {
csvContent += row.join(',') + '\n';
});

const encodedUri = encodeURI(csvContent);
const link = document.createElement('a');
link.setAttribute('href', encodedUri);
link.setAttribute('download', 'peer_review_management.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}

return (
<>
<Button
icon='download'
as='a'
href={downloadManagersFileURL({event_id: eventId, field_id: fieldId})}
title={Translate.string('Export (CSV)')}
/>
<Button
icon='upload'
as='div'
title={Translate.string('Import (CSV)')}
onClick={() => setFileImportVisible(true)}
/>
{fileImportVisible && (
<PeerReviewManagersFileField
onClose={() => setFileImportVisible(false)}
fieldId={fieldId}
eventId={eventId}
onChange={onChange}
importExport && (
<>
<Button
icon='download'
as='div'
onClick={downloadCSV}
title={Translate.string('Export (CSV)')}
/>
)}
</>
<Button
icon='upload'
as='div'
title={Translate.string('Import (CSV)')}
onClick={() => setFileImportVisible(true)}
/>
{fileImportVisible && (
<PeerReviewManagersFileField
onClose={() => setFileImportVisible(false)}
eventId={eventId}
onChange={onChange}
/>
)}
</>
)
);
}
29 changes: 1 addition & 28 deletions indico_jacow/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from indico.util.i18n import _
from indico.util.spreadsheets import send_csv, send_xlsx
from indico.util.string import validate_email
from indico.web.args import use_args, use_kwargs
from indico.web.args import use_kwargs
from indico.web.flask.util import url_for

from indico_jacow.views import WPAbstractsStats, WPDisplayAbstractsStatistics
Expand Down Expand Up @@ -270,30 +270,3 @@ def _process(self, file):
'identifiers': identifiers,
'unknown_emails': list(unknown_emails)
})


class RHPeerReviewManagersExportCSV(RHManagePapersBase):
@use_args({'field_id': fields.Str()}, location='query')
def _process(self, args):
# TODO: Generate CSV with the users in charge of judging or reviewing
cfp = self.event.cfp
users = []

field_id = args.get('field_id')
if field_id == 'content_reviewers':
users = cfp.content_reviewers
if field_id == 'judges':
users = cfp.judges

headers = ['First Name', 'Last Name', 'Affiliation', 'Email', 'Phone Number']
rows = []

for user in users:
user_info = {'First Name': user.first_name,
'Last Name': user.last_name,
'Affiliation': user.affiliation,
'Email': user.email,
'Phone Number': user.phone or 'N/A'}
rows.append(user_info)

return send_csv(f'{field_id}.csv', headers, rows, include_header=True)

0 comments on commit 86a327a

Please sign in to comment.