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 Paste code to submit feature #2720

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

as6325400
Copy link
Contributor

Modify PR merge to main

add Paste code to submit feature

@vmcj
Copy link
Member

vmcj commented Sep 25, 2024

Hi,

I think the rebasing still didn't work correctly, for example 92e3ad7 should stay specific for the 8.3 branch.

Can you run:

git remote add upstream https://github.com/DOMjudge/domjudge
git fetch upstream
git rebase -i upstream/main

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.

@as6325400
Copy link
Contributor Author

Hi,

I think the rebasing still didn't work correctly, for example 92e3ad7 should stay specific for the 8.3 branch.

Can you run:

git remote add upstream https://github.com/DOMjudge/domjudge
git fetch upstream
git rebase -i upstream/main

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.

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 {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Contributor Author

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?

Copy link
Member

@vmcj vmcj left a 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) {
Copy link
Member

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.

Copy link
Contributor Author

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?

etc/db-config.yaml Show resolved Hide resolved
}
});
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline.

Copy link
Contributor Author

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 -->
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@as6325400
Copy link
Contributor Author

I have mostly finished the modifications as mentioned above. Is there anything else that needs to be changed? Thank you.

Copy link
Member

@vmcj vmcj left a 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?


.editor-container:hover {
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EOF is missing.

Copy link
Contributor Author

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!

webapp/templates/team/submit_modal.html.twig Outdated Show resolved Hide resolved
<div class="editor-container">
{{ "" | codeEditor(
"_team_submission_code",
"c_cpp",
Copy link
Member

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).

Copy link
Contributor Author

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?

Copy link
Member

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.

@as6325400
Copy link
Contributor Author

I found the issue and successfully passed the unit tests.

@as6325400 as6325400 requested a review from meisterT October 4, 2024 08:13
@vmcj
Copy link
Member

vmcj commented Oct 4, 2024

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
@as6325400
Copy link
Contributor Author

Can you already squash?

ok

Can you already squash?

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
Copy link
Member

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

Copy link
Contributor Author

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"?

Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.)

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Member

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,
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@@ -201,6 +201,14 @@
- category: Display
description: Options related to the DOMjudge user interface.
items:
- name: default_submission_code_mode
type: int
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

@as6325400
Copy link
Contributor Author

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.

type: array_val
default_value: [upload]
public: true
description: Select the default submission method for the team
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is submit client?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@as6325400 as6325400 requested a review from meisterT October 14, 2024 13:12
@as6325400
Copy link
Contributor Author

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.

@vmcj
Copy link
Member

vmcj commented Oct 18, 2024

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.

etc/db-config.yaml Outdated Show resolved Hide resolved
$entryPoint = $formPaste->get('entry_point')->getData() ?: null;
// Check for invalid characters in entry point name
$invalidChars = '/[<>:"\/\\|?*]/';
if(preg_match($invalidChars, $entryPoint)) {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see them:
image

maybe you have to toggle a to see them.


$uploadedFile = new UploadedFile(
$tempFilePath,
$tempFileName,
Copy link
Member

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.

as6325400 and others added 2 commits October 22, 2024 06:57
);
$tempFileName = preg_replace('/[^a-zA-Z0-9_.-]/', '_', $tempFileName);

if ($language->getExtensions()[0] == 'java' || $language->getExtensions()[0] == 'kt') {
Copy link
Member

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.

Copy link
Member

@meisterT meisterT Oct 22, 2024

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

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vmcj
截圖 2024-11-16 晚上8 10 24
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.

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants