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

Show tournament submissions in frontend #550

Merged
merged 1 commit into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
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
23 changes: 19 additions & 4 deletions frontend/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ class Api {
);
}

static getTournamentSubmissions(episode, page, callback) {
$.get(
`${URL}/api/compete/${episode}/submission/tournament/?page=${page}`
).done((data, status) => {
data = {
count: data.length,
results: data,
};
const pageLimit = Math.ceil(data.count / PAGE_SIZE);
callback(data, pageLimit);
});
}

//----TEAM STATS---

// clean these calls, fix in #368
Expand Down Expand Up @@ -557,10 +570,12 @@ class Api {
});
}

static getTournaments(callback) {
$.get(`${URL}/api/${LEAGUE}/tournament/`).done((data, status) => {
callback(data.results);
});
static getTournaments(episode, callback) {
return $.get(`${URL}/api/episode/${episode}/tournament/`).done(
(data, status) => {
callback(data.results);
}
);
}

//----AUTHENTICATION----
Expand Down
90 changes: 63 additions & 27 deletions frontend/src/components/submissionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class SubmissionList extends Component {

getPage = (page) => {
this.setState({ submissions: [], page, loading: true });
Api.getSubmissions(this.props.episode, page, (data, pageLimit) => {
const getter = this.props.tournament
? Api.getTournamentSubmissions
: Api.getSubmissions;
getter(this.props.episode, page, (data, pageLimit) => {
// This check handles the case where a new page is requested while a
// previous page was loading.
if (page == this.state.page) {
Expand All @@ -57,34 +60,53 @@ class SubmissionList extends Component {
const created_date_string = created_date_text.local_full_string;
return (
<tr key={submission.id}>
{this.props.tournament ? (
<td>
{
(this.props.tournament_info ?? []).filter((t) => {
return t.name_short == submission.tournament;
})[0]?.name_long
}
</td>
) : (
""
)}
<td>{created_date_string}</td>
<td>
{submission.status == "OK!"
? SUBMISSION_ACCEPTED[submission.accepted]
: SUBMISSION_STATUS[submission.status]}
</td>
{this.props.tournament ? (
""
) : (
<td>
{submission.status == "OK!"
? SUBMISSION_ACCEPTED[submission.accepted]
: SUBMISSION_STATUS[submission.status]}
</td>
)}
<td>{submission.description} </td>
<td>{submission.package}</td>
<td>{submission.username} </td>
<td>
{" "}
<a
style={{ cursor: "pointer" }}
onClick={($event) => {
// Prevent default behavior when clicking a link
$event.preventDefault();
{this.props.tournament ? (
""
) : (
<td>
{" "}
<a
style={{ cursor: "pointer" }}
onClick={($event) => {
// Prevent default behavior when clicking a link
$event.preventDefault();

let fileURL = URL.createObjectURL(
new Blob([submission.logs], { type: "text/plain" })
);
window.open(fileURL);
}}
target="_blank"
rel="noopener noreferrer"
>
View log
</a>{" "}
</td>
let fileURL = URL.createObjectURL(
new Blob([submission.logs], { type: "text/plain" })
);
window.open(fileURL);
}}
target="_blank"
rel="noopener noreferrer"
>
View log
</a>{" "}
</td>
)}
<td>
{" "}
<button
Expand Down Expand Up @@ -112,12 +134,13 @@ class SubmissionList extends Component {
<table className="table table-hover table-striped table-responsive table-full-width">
<thead>
<tr>
{this.props.tournament ? <th>Tournament</th> : ""}
<th>Submitted at</th>
<th>Status</th>
{this.props.tournament ? "" : <th>Status</th>}
<th>Description</th>
<th>Package Name</th>
<th>Submitter</th>
<th></th>
{this.props.tournament ? "" : <th></th>}
<th></th>
</tr>
</thead>
Expand All @@ -137,7 +160,20 @@ class SubmissionList extends Component {
return (
<div className="card">
<div className="header">
<h4 className="title">Submission History</h4>
<h4 className="title">
{this.props.tournament
? "Tournament Submission History"
: "Submission History"}
</h4>
{this.props.tournament && this.props.episode_info.frozen ? (
<p>
Submissions are currently frozen. Your last accepted submission
will be entered into the next tournament. The list of your
tournament submissions will be updated here soon!
</p>
) : (
""
)}
</div>
{this.renderTable()}
</div>
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class App extends Component {
logged_in: null,
episode: episode,
episode_info: null,
tournament_info: null,
user: null,
team: null,
loaded: false,
Expand All @@ -66,7 +67,11 @@ class App extends Component {
};

updateBaseState = (callback = () => {}) => {
let fetched_logged_in, fetched_user, fetched_team, fetched_episode_info;
let fetched_logged_in,
fetched_user,
fetched_team,
fetched_episode_info,
fetched_tournament_info;

const ajax1 = Api.loginCheck((logged_in) => {
fetched_logged_in = logged_in;
Expand All @@ -84,7 +89,11 @@ class App extends Component {
fetched_episode_info = episode_info;
});

const ajax_queries = [ajax1, ajax2, ajax3, ajax4];
const ajax5 = Api.getTournaments(this.state.episode, (tournament_info) => {
fetched_tournament_info = tournament_info;
});

const ajax_queries = [ajax1, ajax2, ajax3, ajax4, ajax5];

// To be run when all AJAX queries are complete.
const all_queries_finished = () => {
Expand All @@ -95,6 +104,7 @@ class App extends Component {
user: fetched_user,
team: fetched_team,
episode_info: fetched_episode_info,
tournament_info: fetched_tournament_info,
},
callback
);
Expand Down Expand Up @@ -304,6 +314,7 @@ class App extends Component {
on_team={on_team}
is_game_released={is_game_released}
episode_info={this.state.episode_info}
tournament_info={this.state.tournament_info}
/>
)}
key="submissions"
Expand Down
23 changes: 14 additions & 9 deletions frontend/src/views/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ class Submissions extends Component {
};

this.submission_list = (
<SubmissionList episode={this.props.episode}> </SubmissionList>
<SubmissionList episode={this.props.episode} tournament={false}>
{" "}
</SubmissionList>
);
this.tournament_submission_list = (
<SubmissionList
episode={this.props.episode}
tournament={true}
episode_info={this.props.episode_info}
tournament_info={this.props.tournament_info}
>
{" "}
</SubmissionList>
);

this.changeHandler = this.changeHandler.bind(this);
Expand Down Expand Up @@ -318,14 +330,7 @@ class Submissions extends Component {
</Countdown>
{this.renderHelperSubmissionForm()}
{this.submission_list}

{/* See #78 for tracking */}
{/* <div className="card">
<div className="header">
<h4 className="title">Tournament Submissions</h4>
</div>
<div className="content">{this.renderHelperTourTable()}</div>
</div> */}
{this.tournament_submission_list}
</div>
</div>
</div>
Expand Down