From ab2191436a44da79e4ca7ee30149e6b3b1446b1a Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 17:52:43 -0800 Subject: [PATCH 01/20] Show table for latest submission --- frontend/src/views/submissions.js | 76 +++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index 2e8884b8..f9ac89fb 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -13,6 +13,7 @@ class Submissions extends Component { super(props); this.state = { selectedFile: null, + currentSubmission: null, lastSubmissions: null, tourSubmissions: null, numLastSubmissions: 0, @@ -100,6 +101,7 @@ class Submissions extends Component { //---GETTING TEAMS SUBMISSION DATA---- + KEYS_CURRENT = ['compiling'] KEYS_LAST = ['last_1', 'last_2', 'last_3'] KEYS_TOUR = ['tour_final', 'tour_qual', 'tour_seed', 'tour_sprint', 'tour_hs', 'tour_intl_qual', 'tour_newbie'] @@ -113,6 +115,7 @@ class Submissions extends Component { // this will be maps of the label of type of submission to submission id // this function then makes calles to get the specific data for each submission gotSubmissions = (data) => { + this.setState({currentSubmission: new Array(this.submissionHelper(this.KEYS_CURRENT, data)).fill({})}) this.setState({lastSubmissions: new Array(this.submissionHelper(this.KEYS_LAST, data)).fill({})}) this.setState({tourSubmissions: new Array(this.submissionHelper(this.KEYS_TOUR, data)).fill([])}) } @@ -135,7 +138,13 @@ class Submissions extends Component { setSubmissionData = (key, data) => { let index, add_data - if (this.KEYS_LAST.includes(key)) { + if (this.KEYS_CURRENT.includes(key)) { + index = 0 + const arr = this.state["currentSubmission"] + let newArr = arr.slice(0, index) + newArr.push(data) + this.setState({["currentSubmission"]: newArr.concat(arr.slice(index + 1))}) + } else if (this.KEYS_LAST.includes(key)) { switch (key) { case 'last_1': index = 0 @@ -303,7 +312,61 @@ class Submissions extends Component { } } - //reder helper for table containing the team's latest submissions + //reder helper for table containing the team's latest submission + renderHelperCurrentTable() { + if (this.state.currentSubmission === null) { + return ( +

+ Loading submissions...

+

+ ) + } else if (this.state.currentSubmission.length == 0) { + if (this.state.status == 0) { + return ( +

+ Your code is being submitted -- you'll see it here if it finishes successfully. +

+ ) + } else { + return ( +

+ You haven't submitted any code yet! +

+ ) + } + } else { + const submissionRows = this.state.currentSubmission.map((submission, index) => { + if (Object.keys(submission).length === 0) { + return ( +
Loading...
+ ) + } else { + return ( + + { (new Date(submission.submitted_at)).toLocaleString() } + + + ) + } + }) + + return ( + + + + + + + + { submissionRows } + +
Submission at
+ ) + } + + } + + //reder helper for table containing the team's latest successfully compiled submissions renderHelperLastTable() { if (this.state.lastSubmissions === null) { return ( @@ -415,7 +478,14 @@ class Submissions extends Component { { this.renderHelperSubmissionStatus() }
-

Latest Submissions

+

Latest Submission

+
+
+ { this.renderHelperCurrentTable() } +
+ +
+

Latest Successfully Compiled Submissions

{ this.renderHelperLastTable() } From 1999400026bdb69e8034598d41c0fbf9c0c53bea Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 18:01:54 -0800 Subject: [PATCH 02/20] Remove resolved TODOs --- frontend/src/views/submissions.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index f9ac89fb..e27decff 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -49,9 +49,6 @@ class Submissions extends Component { // makes an api call to upload the selected file // TODO clean this method up // TODO add explanation - // TODO submission table should be what exactly? - // Latest submission in progress, and last 3 good submissions? (and then make this clear in frontend) -- think I'm leaning towards this one - // Last 3 submissions, period? (this might need revisions in backend) // TODO update how we display the most recent submission (including its status.) // Also now that we have new statuses, we need to figue out what we should display in the frontend for each of them. // (eg if user navigates away before the upload link is returned / before the upload finishes, or if submission fails to get queued/compiled, From 84a8e9fe0d9934f8d5bfdfd7e279bd9eccf58924 Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 18:08:42 -0800 Subject: [PATCH 03/20] Placeholder for current submission status --- frontend/src/views/submissions.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index e27decff..afb75ac8 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -341,6 +341,7 @@ class Submissions extends Component { return ( { (new Date(submission.submitted_at)).toLocaleString() } + Status ) @@ -352,6 +353,8 @@ class Submissions extends Component { Submission at + Status + Download Btn From 584e1dd6d162a52f6f03a7ed73eda35d20e27378 Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 18:15:57 -0800 Subject: [PATCH 04/20] Add compilation status display for most recent submission --- frontend/src/views/submissions.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index afb75ac8..08ca64af 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -338,10 +338,33 @@ class Submissions extends Component {
Loading...
) } else { + let status_str = "" + switch (submission.status) { + // TODO fill in rest of cases, revise strings + // TODO don't show the download button in some cases + case -1: + status_str = "Waiting to start submission..." + break + case 0: + status_str = "Currently submitting..." + break + case 1: + status_str = "Successfully submitted!" + break + case 2: + status_str = "Submission failed." + break + case 3: + status_str = "Internal server error. Try re-submitting your code." + break + default: + status_str = "A really long other string. TBD, fill in the rest of cases" + break + } return ( { (new Date(submission.submitted_at)).toLocaleString() } - Status + { status_str } ) From 263b9d53c92529ed9ce957cc3f89ef2d9225c51c Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 18:34:18 -0800 Subject: [PATCH 05/20] Fix current submission's comp status messages --- frontend/src/views/submissions.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index 08ca64af..cd49112b 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -339,26 +339,28 @@ class Submissions extends Component { ) } else { let status_str = "" - switch (submission.status) { - // TODO fill in rest of cases, revise strings + switch (submission.compilation_status) { // TODO don't show the download button in some cases - case -1: - status_str = "Waiting to start submission..." - break case 0: - status_str = "Currently submitting..." + status_str = "Submission initialized, but not yet uploaded... If this persists, try re-submitting your code." break case 1: - status_str = "Successfully submitted!" + status_str = "Successfully submitted and compiled!" break case 2: - status_str = "Submission failed." + status_str = "Submitted, but compiler threw a compile error. Fix and re-submit your code." break case 3: status_str = "Internal server error. Try re-submitting your code." break + case 4: + status_str = "Code uploaded, but not yet queued for compilation... If this persists, try re-submitting your code." + break + case 5: + status_str = "Code queued for compilation -- check back for updates." + break default: - status_str = "A really long other string. TBD, fill in the rest of cases" + status_str = "" break } return ( From 9e184187fc72c560b2e452d0ac3f1457b5a22fdc Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 18:54:54 -0800 Subject: [PATCH 06/20] Properly handle the first successful submission --- backend/api/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/api/views.py b/backend/api/views.py index 8bb0cdc3..b659fd0d 100644 --- a/backend/api/views.py +++ b/backend/api/views.py @@ -762,7 +762,7 @@ def compilation_update(self, request, team, league_id, pk=None): # Only if this submission is newer than what's already been processed, # update the submission history. # (to prevent reverting to older submissions that took longer to process) - if submission.id > team_sub.last_1_id: + if team_sub.last_1_id is None or submission.id > team_sub.last_1_id: team_sub.last_3_id = team_sub.last_2_id team_sub.last_2_id = team_sub.last_1_id team_sub.last_1_id = submission From 5132e0a116945f158438d382f418202cc48f90ce Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 18:55:18 -0800 Subject: [PATCH 07/20] Simplify messages shown with no prev submissions --- frontend/src/views/submissions.js | 36 +++++++++---------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index cd49112b..13b35e5a 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -318,19 +318,11 @@ class Submissions extends Component {

) } else if (this.state.currentSubmission.length == 0) { - if (this.state.status == 0) { - return ( -

- Your code is being submitted -- you'll see it here if it finishes successfully. -

- ) - } else { - return ( -

- You haven't submitted any code yet! -

- ) - } + return ( +

+ You haven't submitted any code yet! +

+ ) } else { const submissionRows = this.state.currentSubmission.map((submission, index) => { if (Object.keys(submission).length === 0) { @@ -400,19 +392,11 @@ class Submissions extends Component {

) } else if (this.state.lastSubmissions.length == 0) { - if (this.state.status == 0) { - return ( -

- Your code is being submitted -- you'll see it here if it finishes successfully. -

- ) - } else { - return ( -

- You haven't submitted any code yet! -

- ) - } + return ( +

+ You haven't had any successful submissions yet! (If you have code being submitted, you'll see it here if it finishes successfully.) +

+ ) } else { const submissionRows = this.state.lastSubmissions.map((submission, index) => { if (Object.keys(submission).length === 0) { From 7ba5c74eee168a00145731bc9aa9112709b92ea4 Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 18:55:44 -0800 Subject: [PATCH 08/20] Remove obsolete code --- frontend/src/views/submissions.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index 13b35e5a..33fb39f5 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -31,7 +31,6 @@ class Submissions extends Component { } componentDidMount() { - Api.getCompilationStatus(this.gotStatus); Api.getTeamSubmissions(this.gotSubmissions); Api.getLeague(function (l) { this.setState({ league: l}); @@ -102,12 +101,6 @@ class Submissions extends Component { KEYS_LAST = ['last_1', 'last_2', 'last_3'] KEYS_TOUR = ['tour_final', 'tour_qual', 'tour_seed', 'tour_sprint', 'tour_hs', 'tour_intl_qual', 'tour_newbie'] - // called when status of teams compilation request is received - // 0 = in progress, 1 = succeeded, 2 = failed, 3 = server failed - gotStatus = (data) => { - this.setState(data) - } - // called when submission data is initially received // this will be maps of the label of type of submission to submission id // this function then makes calles to get the specific data for each submission From 81e79a7ebd7a097722374a752f13c369eeca8cb4 Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 19:01:14 -0800 Subject: [PATCH 09/20] Remove a cluttered header --- frontend/src/views/submissions.js | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index 33fb39f5..3fb9500d 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -364,7 +364,6 @@ class Submissions extends Component { Submission at Status - Download Btn From 628a966061778eba1e2f6b1f9239212212008e4f Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 19:22:46 -0800 Subject: [PATCH 10/20] Hide download button if code not downloadable --- frontend/src/views/submissions.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index 3fb9500d..2a08bbfb 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -48,10 +48,6 @@ class Submissions extends Component { // makes an api call to upload the selected file // TODO clean this method up // TODO add explanation - // TODO update how we display the most recent submission (including its status.) - // Also now that we have new statuses, we need to figue out what we should display in the frontend for each of them. - // (eg if user navigates away before the upload link is returned / before the upload finishes, or if submission fails to get queued/compiled, - // what should the user do? what should we tell them?) uploadData = () => { // let status_str = "Submitting..." Cookies.set('submitting', 1) @@ -324,10 +320,11 @@ class Submissions extends Component { ) } else { let status_str = "" + let download_button = switch (submission.compilation_status) { - // TODO don't show the download button in some cases case 0: status_str = "Submission initialized, but not yet uploaded... If this persists, try re-submitting your code." + download_button = "" break case 1: status_str = "Successfully submitted and compiled!" @@ -352,7 +349,7 @@ class Submissions extends Component { { (new Date(submission.submitted_at)).toLocaleString() } { status_str } - + { download_button } ) } From e679b52d624a409c35dd5d9aa0fbd35dd0650fba Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 21:19:02 -0800 Subject: [PATCH 11/20] Track submission upload process; show errors in frontend --- frontend/src/api.js | 5 ++++- frontend/src/views/submissions.js | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/frontend/src/api.js b/frontend/src/api.js index b5719ddd..992d7c2b 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -46,18 +46,21 @@ class Api { .done((data, status) => { console.log("Definitely done!") // console.log(data, status) - Cookies.set('submitting', 0) + Cookies.set('submitting', 1) }) .fail((xhr, status, error) => { console.log("Error in compilation update callback: ", xhr, status, error) + Cookies.set('submitting', 3) }) }) .fail((xhr, status, error) => { console.log("Error in put request of file to bucket: ", xhr, status, error) + Cookies.set('submitting', 3) }) }) .fail((xhr, status, error) => { console.log("Error in post request for upload: ", xhr, status, error) + Cookies.set('submitting', 3) }); } diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index 2a08bbfb..048caa55 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -50,7 +50,8 @@ class Submissions extends Component { // TODO add explanation uploadData = () => { // let status_str = "Submitting..." - Cookies.set('submitting', 1) + // 'submitting' in Cookies is used to communicate between the functions in api.js and those in submissions.js. + Cookies.set('submitting', 0) // console.log("submitting...") this.setState({sub_status: 0}) this.renderHelperSubmissionForm() @@ -59,12 +60,18 @@ class Submissions extends Component { Api.newSubmission(this.state.selectedFile, null) this.interval = setInterval(() => { - if (Cookies.get('submitting') != 1) { + if (Cookies.get('submitting') != 0) { // console.log("out of time loop") - // refresh the submission button and status - this.setState({sub_status: 1}) + // refresh the submission button this.renderHelperSubmissionForm() + // refresh the submission status + if (Cookies.get('submitting') == 1) { + this.setState({sub_status: 1}) + } + if (Cookies.get('submitting') == 3) { + this.setState({sub_status: 3}) + } this.renderHelperSubmissionStatus() // refresh team submission listing @@ -275,13 +282,10 @@ class Submissions extends Component { status_str = "Currently submitting..." break case 1: - status_str = "Successfully submitted!" - break - case 2: - status_str = "Submission failed." + status_str = "Successfully queued for compilation!" break case 3: - status_str = "Internal server error. Try re-submitting your code." + status_str = "Submitting failed. Try re-submitting your code." break default: status_str = "" From e5a1d4f07f8de5a2e3052a14376432b3e9d70c44 Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 21:19:50 -0800 Subject: [PATCH 12/20] Make sure to refresh all tables when necessary --- frontend/src/views/submissions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index 048caa55..20cafe33 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -74,8 +74,9 @@ class Submissions extends Component { } this.renderHelperSubmissionStatus() - // refresh team submission listing + // refresh team submission tables Api.getTeamSubmissions(this.gotSubmissions); + this.renderHelperCurrentTable() this.renderHelperLastTable() clearInterval(this.interval) From 484e1e14e18e9af14731f1fc754a8e49e160f7c3 Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 21:20:31 -0800 Subject: [PATCH 13/20] Manual safeguard for upload process --- frontend/src/views/submissions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index 20cafe33..b1f41dd2 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -328,7 +328,7 @@ class Submissions extends Component { let download_button = switch (submission.compilation_status) { case 0: - status_str = "Submission initialized, but not yet uploaded... If this persists, try re-submitting your code." + status_str = "Submission initialized, but not yet uploaded... If this persists, try re-submitting your code. Also, make sure to stay on this page." download_button = "" break case 1: From 77e5d0dada64ea18f4ab9bdd29153cdd5d1f85b2 Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 21:26:33 -0800 Subject: [PATCH 14/20] Better name / use for upload status code --- frontend/src/api.js | 11 ++++------- frontend/src/views/submissions.js | 9 +++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/frontend/src/api.js b/frontend/src/api.js index 992d7c2b..3b4313f1 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -20,10 +20,7 @@ class Api { // TODO clean up a lot of old comments, print statements // TODO provide more explanatory comments - // TODO there's a better wayy to work with 'submitting' in cookies - // TODO 'submitting' could probably use a better name // TODO review code in the submissions js - // TODO errors in these callbacks should also display messages in frontend //uploads a new submission to the google cloud bucket static newSubmission(submissionfile, callback){ @@ -46,21 +43,21 @@ class Api { .done((data, status) => { console.log("Definitely done!") // console.log(data, status) - Cookies.set('submitting', 1) + Cookies.set('submission_upload_status', 1) }) .fail((xhr, status, error) => { console.log("Error in compilation update callback: ", xhr, status, error) - Cookies.set('submitting', 3) + Cookies.set('submission_upload_status', 3) }) }) .fail((xhr, status, error) => { console.log("Error in put request of file to bucket: ", xhr, status, error) - Cookies.set('submitting', 3) + Cookies.set('submission_upload_status', 3) }) }) .fail((xhr, status, error) => { console.log("Error in post request for upload: ", xhr, status, error) - Cookies.set('submitting', 3) + Cookies.set('submission_upload_status', 3) }); } diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index b1f41dd2..329ca0db 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -51,7 +51,7 @@ class Submissions extends Component { uploadData = () => { // let status_str = "Submitting..." // 'submitting' in Cookies is used to communicate between the functions in api.js and those in submissions.js. - Cookies.set('submitting', 0) + Cookies.set('submission_upload_status', 0) // console.log("submitting...") this.setState({sub_status: 0}) this.renderHelperSubmissionForm() @@ -60,16 +60,17 @@ class Submissions extends Component { Api.newSubmission(this.state.selectedFile, null) this.interval = setInterval(() => { - if (Cookies.get('submitting') != 0) { + let submission_upload_status = Cookies.get('submission_upload_status'); + if (submission_upload_status != 0) { // console.log("out of time loop") // refresh the submission button this.renderHelperSubmissionForm() // refresh the submission status - if (Cookies.get('submitting') == 1) { + if (submission_upload_status == 1) { this.setState({sub_status: 1}) } - if (Cookies.get('submitting') == 3) { + if (submission_upload_status == 3) { this.setState({sub_status: 3}) } this.renderHelperSubmissionStatus() From 22782d0422b6c48c82dab481ae82b15221813288 Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 21:37:57 -0800 Subject: [PATCH 15/20] Remove unused/possibly buggy methods --- backend/api/views.py | 14 -------------- frontend/src/api.js | 6 ------ 2 files changed, 20 deletions(-) diff --git a/backend/api/views.py b/backend/api/views.py index b659fd0d..e56938a4 100644 --- a/backend/api/views.py +++ b/backend/api/views.py @@ -837,20 +837,6 @@ def team_compilation_status(self, request, team, league_id, pk=None): else: return Response({'status': None}, status.HTTP_200_OK) - @action(methods=['get'], detail=True) - def team_compilation_id(self, request, team, league_id, pk=None): - if pk != str(team.id): - return Response({'message': "Not authenticated"}, status.HTTP_401_UNAUTHORIZED) - - team_data = self.get_queryset().get(pk=pk) - comp_id = team_data.compiling_id - if comp_id is not None: - return Response({'compilation_id': comp_id}, status.HTTP_200_OK) - else: - # this is bad, replace with something thats actually None - # ^ TODO should address this - return Response({'compilation_id': -1}, status.HTTP_200_OK) - class ScrimmageViewSet(viewsets.GenericViewSet, mixins.ListModelMixin, diff --git a/frontend/src/api.js b/frontend/src/api.js index 3b4313f1..2b36cc25 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -102,12 +102,6 @@ class Api { }); } - static getCompilationID(callback) { - $.get(`${URL}/api/${LEAGUE}/teamsubmission/${Cookies.get("team_id")}/team_compilation_id/`).done((data, status) => { - return data['compilation_id'] - }); - } - // note that this is a submission, not a teamsubmission, thing static getSubmissionStatus(callback) { $.get(`${URL}/api/${LEAGUE}/submission/${Cookies.get("submission_id")}/get_status/`).done((data, status) => { From 0847452d0e3ee608511caa4ac87e8e46a56ddd0b Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Mon, 28 Dec 2020 21:40:49 -0800 Subject: [PATCH 16/20] Better explanation of having to refresh to see table update --- frontend/src/views/submissions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index 329ca0db..0b7cc5f6 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -345,7 +345,8 @@ class Submissions extends Component { status_str = "Code uploaded, but not yet queued for compilation... If this persists, try re-submitting your code." break case 5: - status_str = "Code queued for compilation -- check back for updates." + // TODO a dedicated refresh button, that refreshes only these tables, would be cool + status_str = "Code queued for compilation -- check back and refresh for updates." break default: status_str = "" From 70be42a4ff85bd0c4055ee9160ab2cf8ecf3f3b2 Mon Sep 17 00:00:00 2001 From: Nathaniel Kim Date: Tue, 29 Dec 2020 11:32:21 -0800 Subject: [PATCH 17/20] Add explanatory notes --- frontend/src/api.js | 7 +++++-- frontend/src/views/submissions.js | 25 +++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/frontend/src/api.js b/frontend/src/api.js index 2b36cc25..bb256a87 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -19,15 +19,16 @@ class Api { //----SUBMISSIONS---- // TODO clean up a lot of old comments, print statements - // TODO provide more explanatory comments // TODO review code in the submissions js //uploads a new submission to the google cloud bucket static newSubmission(submissionfile, callback){ // submissionfile.append('_method', 'PUT'); - // get the url from the real api + // URLs which files are uploaded to are generated by the backend; + // call the backend api to get this link $.post(`${URL}/api/${LEAGUE}/submission/`) .done((data, status) => { + // Upload to the bucket console.log("got URL") Cookies.set('submission_id', data['submission_id']); $.ajax({ @@ -38,6 +39,8 @@ class Api { contentType: false }) .done((data, status) => { + // After upload is done, need to queue for compilation. + // See corresponding method of backend/api/views.py for more explanation. console.log(data, status) $.post(`${URL}/api/${LEAGUE}/submission/` +Cookies.get('submission_id') + `/compilation_pubsub_call/`) .done((data, status) => { diff --git a/frontend/src/views/submissions.js b/frontend/src/views/submissions.js index 0b7cc5f6..15af98d5 100755 --- a/frontend/src/views/submissions.js +++ b/frontend/src/views/submissions.js @@ -47,39 +47,49 @@ class Submissions extends Component { // makes an api call to upload the selected file // TODO clean this method up - // TODO add explanation uploadData = () => { // let status_str = "Submitting..." - // 'submitting' in Cookies is used to communicate between the functions in api.js and those in submissions.js. + // 'submission_upload_status' in Cookies is used to communicate between the functions in api.js and those in submissions.js. + // A value of 0 indicates that the submission is still in progress. + // When a submission finishes, api.js changes this value to something else. Cookies.set('submission_upload_status', 0) // console.log("submitting...") + // The sub_status state is used internally by this component, to keep track of the submission upload process. + // (Currently, it mirrors submission_upload_status, but is part of state.) this.setState({sub_status: 0}) + + // Disable submission (for now), to prevent concurrent submissions. this.renderHelperSubmissionForm() this.renderHelperSubmissionStatus() Api.newSubmission(this.state.selectedFile, null) + // The method in api.js will change Cookies' submission_upload_status during the process of an upload. + // To check changes, we poll every second. this.interval = setInterval(() => { let submission_upload_status = Cookies.get('submission_upload_status'); if (submission_upload_status != 0) { + // Submission process terminated (see api.js). // console.log("out of time loop") - // refresh the submission button - this.renderHelperSubmissionForm() - // refresh the submission status + // refresh the submission status, for use on this component if (submission_upload_status == 1) { this.setState({sub_status: 1}) } if (submission_upload_status == 3) { this.setState({sub_status: 3}) } + + // refresh the submission button, etc, to allow for a new submission + this.renderHelperSubmissionForm() this.renderHelperSubmissionStatus() - // refresh team submission tables + // refresh team submission tables, to display the submission that just occured Api.getTeamSubmissions(this.gotSubmissions); this.renderHelperCurrentTable() this.renderHelperLastTable() + // Done polling, stop this repeated check clearInterval(this.interval) } else { @@ -227,6 +237,7 @@ class Submissions extends Component { button = } } + // Make sure to disable concurrent submission uploads. if (this.state.sub_status != 0) { file_button_sub =
Choose File
file_button =