-
Notifications
You must be signed in to change notification settings - Fork 260
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 Paste code to submit feature #2720
base: main
Are you sure you want to change the base?
Conversation
Hi, I think the rebasing still didn't work correctly, for example 92e3ad7 should stay specific for the 8.3 branch. Can you run:
And only use your own commits there? Alternatively you enabled the option that we can do this, if you want I can try it later this week if you're fine with it. |
6dcfb05
to
42e4a26
Compare
I think I've got it right now. Could you please take a look? Thanks! |
@@ -80,4 +123,31 @@ | |||
filesSelected.removeClass('d-none'); | |||
}); | |||
</script> | |||
<style> | |||
.container { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add this to the .ccs
files and not directly in the page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which existing .css file would be the best to add it to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebase seemed to have worked.
return $this->redirectToRoute('team_index'); | ||
} | ||
} elseif ($formPaste->isSubmitted() && $formPaste->isValid()) { | ||
if ($contest === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of those now get duplicated so maybe merge those where possible? Either by a helper function or using something like:
if ($formUpload->isSubmitted() || $formPaste->isSubmitted())
and do the if/elseif
one branch deeper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've made it much clearer. Is this okay now?
} | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
{{ form_start(form) }} | ||
{% set active_tab = defaultSubmissionCodeMode == 0 ? 'paste' : 'upload' %} | ||
|
||
<!-- Bootstrap Nav Tabs for Switching --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this comment is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
I have mostly finished the modifications as mentioned above. Is there anything else that needs to be changed? Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great already, some small remarks.
I'll wait for someone else to also approve (as is the custom) but this looks good already.
Can you verify again that the unit tests do indeed still pass?
webapp/public/style_domjudge.css
Outdated
|
||
.editor-container:hover { | ||
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EOF
is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the EOF. Thanks for pointing that out!
<div class="editor-container"> | ||
{{ "" | codeEditor( | ||
"_team_submission_code", | ||
"c_cpp", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of moving the language selection above the editor? This way you can also use it here to fix syntax highlighting in the editor (as idea).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good idea. When I first implemented it, I wasn't sure how to dynamically adjust the syntax highlighting in the editor by changing the language in the menu. Is that achievable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that depends on the twig template.
Let's leave that for a follow up PR in that case.
I found the issue and successfully passed the unit tests. |
Can you already squash? |
setting paste_code file entry_point add newline and remove comment update paste_code container css site optimize submit logic use cookie to record user submit mode Update webapp/templates/team/submit_modal.html.twig Co-authored-by: MCJ Vasseur <[email protected]> css new line Update webapp/templates/team/submit_modal.html.twig Co-authored-by: MCJ Vasseur <[email protected]> fix Submit page error fix submit page error 2
ok
Ok, I already squashed it |
<div class="modal-footer"> | ||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> | ||
<button type="submit" class="btn btn-primary"> | ||
<i class="fas fa-paste"></i> Submit Paste |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's call the button just Submit
, same with the other button
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If both "Upload" and "Paste" are available at the same time, would it be weird or cause confusion if both buttons are labeled "Submit"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is confusing as in both cases you are submitting what you filled in in the form you are currently seeing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand now, I misunderstood what you meant.
); | ||
|
||
$files = [$uploadedFile]; | ||
$entryPoint = $tempFileName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filename as entry point does not work for Kotlin, nor for Java.
See https://github.com/DOMjudge/domjudge/blob/main/webapp/templates/team/partials/submit_scripts.html.twig#L3 or https://github.com/DOMjudge/domjudge/blob/main/submit/submit#L206
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered ignoring the entry in Paste mode, since only one file can be uploaded with Paste?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One example is Java, where the entry point basically specifies the class. If you would make the name of the file clear in the UI (or even an input that can be changed after selecting the problem) we could do the same auto-detection (with possibility to change it) with the entry point as for the uploaded file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's feasible in terms of implementation, but Paste code is essentially designed for convenience with a single file. If we allow changes to the file name, it somewhat defeats the original purpose of this feature. Alternatively, we could try handling languages where the entry point is not the file name with special treatment? (Actually, this seems similar to the original approach for uploads.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, I'm currently teaching a data structures class where only C language is allowed, and the usage of Paste is significantly higher than that of upload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I followed that approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, I'd like to ask how I can reference code in a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything else to adjust?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, I'd like to ask how I can reference code in a comment.
|
||
$uploadedFile = new UploadedFile( | ||
$tempFilePath, | ||
$tempFileName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use a simpler name here (and then of course use that as base for the entry point calculation). A nice simple naming scheme could be the shortName
of the contestProblem
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still want the pasted submission to have a special identifier in the filename, to differentiate it from uploads. Is it possible to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason the way of submitting is important? You could test with adding fileupload-
to the name? You would need to test yourself if this still works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it "fileupload"? I thought it would be something like "Paste."
However, I now think using "shortName" directly is fine too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think the short name as given by the contest problem is ok, let's use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the short name allows various characters. I will still use preg_replace('/[^a-zA-Z0-9_.-]/', '_', $tempFileName);
to handle file naming using the short name.
etc/db-config.yaml
Outdated
@@ -201,6 +201,14 @@ | |||
- category: Display | |||
description: Options related to the DOMjudge user interface. | |||
items: | |||
- name: default_submission_code_mode | |||
type: int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this an array_val
, then one can select which ones are enabled. By default let's enable upload for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, but in that case, the cookies will also need a major revamp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should prevent the array from being empty here. How should I handle it when someone submits the form with an empty array?
Should I use an alert?
I haven’t seen any other similar menus to refer to for this implementation.
Sorry about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would check that the array doesn't get empty and if it does refuse to save or use a danger
flash with the message. Alternative is to have a message in the config-check
page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think implementing the required restriction in the backend can be done in the next PR, as it's more general. Including it in this commit would make things confusing.
can i do it this way?
I think implementing the required restriction in the backend can be done in the next PR, as it's more general. Including it in this commit would make things confusing. |
etc/db-config.yaml
Outdated
type: array_val | ||
default_value: [upload] | ||
public: true | ||
description: Select the default submission method for the team |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these the default or allowed submission methods? Also, it would be good to clarify that these are submission methods from the web interface, as there's also the submit client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowed submission methods, with the default set to upload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is submit client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is submit client?
This: https://raw.githubusercontent.com/DOMjudge/domjudge/refs/heads/main/submit/submit
Sorry to bother you, but I was wondering if there are any improvements needed for this? Once this is merged, I should be able to work on the issue of replacing it with Monaco. |
I think you should address @eldering his question, and we should address some of your questions still. |
$entryPoint = $formPaste->get('entry_point')->getData() ?: null; | ||
// Check for invalid characters in entry point name | ||
$invalidChars = '/[<>:"\/\\|?*]/'; | ||
if(preg_match($invalidChars, $entryPoint)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some warnings on https://github.com/DOMjudge/domjudge/pull/2720/files which you should still handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
$uploadedFile = new UploadedFile( | ||
$tempFilePath, | ||
$tempFileName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason the way of submitting is important? You could test with adding fileupload-
to the name? You would need to test yourself if this still works.
Co-authored-by: MCJ Vasseur <[email protected]>
); | ||
$tempFileName = preg_replace('/[^a-zA-Z0-9_.-]/', '_', $tempFileName); | ||
|
||
if ($language->getExtensions()[0] == 'java' || $language->getExtensions()[0] == 'kt') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of hardcoding Java and Kotlin here, use the $language->getRequireEntryPoint()
instead.
Similarly, use $language->getEntryPointDescription()
for a description to display.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to use what we built here so that the entry point works the same regardless of the upload method: https://github.com/DOMjudge/domjudge/blob/main/webapp/src/Form/Type/SubmitProblemType.php#L66
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't understand how to use $language->getRequireEntryPoint(). For example, in the case of Java, when using paste_code, the entry_point might still be no. In this case, how can I use this to determine the file name standard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the remark here is that instead of listing the current languages which need an entrypoint, use that function @meisterT linked and use it from there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the remark here is that instead of listing the current languages which need an entrypoint, use that function @meisterT linked and use it from there?
The function should be checking whether the language in the form requires an entrypoint, which seems to be different from my current situation, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would it be different? You check for 2 languages here and determine the entrypoint for those. If there are other languages like this we would also want to pick them up. People can add more languages besides those 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vmcj
I'm not sure if my understanding is correct, but are the methods $language->getRequireEntryPoint() and $language->getEntryPointDescription() linked to the part I highlighted in the image?
If so, there might be an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, in the case of Java, it can be configured to not require an entry point. In this scenario, under the original upload mode, the uploaded file itself becomes the entry point. However, due to the characteristics of the Java language, the file name must match the main class name.
In the case of the paste code mode, regardless of whether an entry point is required or not, the user must be allowed to specify the main class name. Otherwise, I won’t be able to save the file correctly, which will result in a compile error.
Co-authored-by: MCJ Vasseur <[email protected]>
Modify PR merge to main
add Paste code to submit feature