Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

add Paste code to submit feature #2720

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

Open
as6325400 wants to merge 10 commits into DOMjudge:main
base: main
Choose a base branch
Loading
from as6325400:paste_code
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
change css site and use shortname to name file
  • Loading branch information
as6325400 committed Oct 23, 2024
commit dbe2363f393c16836e8e7d141f28190bef4c3ad2
5 changes: 5 additions & 0 deletions webapp/public/style_domjudge.css
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -721,3 +721,8 @@ blockquote {
.editor-container:hover {
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.single-tab {
width: 100%;
display: inline-block;
}
27 changes: 13 additions & 14 deletions webapp/src/Controller/Team/SubmissionController.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,20 @@
$problem = $formPaste->get('problem')->getData();
$language = $formPaste->get('language')->getData();
$codeContent = $formPaste->get('code_content')->getData();

$problemShortName = $problem->getContestProblems()->first()->getShortName();

if ($codeContent == null || empty(trim($codeContent))) {
$this->addFlash('danger', 'No code content provided.');
return $this->redirectToRoute('team_index');
}

$tempDir = sys_get_temp_dir();
$tempFileName = sprintf(
'submission_%s_%s_%s.%s',
$user->getUsername(),
$problem->getName(),
date('Y-m-d_H-i-s'),
$saveFileDir = sys_get_temp_dir();
$saveFileName = sprintf(
'%s.%s',
$problemShortName,
$language->getExtensions()[0]
);
$tempFileName = preg_replace('/[^a-zA-Z0-9_.-]/', '_', $tempFileName);
$saveFileName = preg_replace('/[^a-zA-Z0-9_.-]/', '_', $saveFileName);

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
edited
Loading

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

@as6325400 as6325400 Oct 23, 2024

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

@as6325400 as6325400 Oct 24, 2024

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

@as6325400 as6325400 Nov 16, 2024

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

@as6325400 as6325400 Nov 16, 2024

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.

$entryPoint = $formPaste->get('entry_point')->getData() ?: null;
Expand All @@ -121,17 +120,17 @@
$this->addFlash('danger', 'Invalid entry point name.');
return $this->redirectToRoute('team_index');
}
$tempFileName = $entryPoint . '.' . $language->getExtensions()[0];
$saveFileName = $entryPoint . '.' . $language->getExtensions()[0];
} else {
$entryPoint = $tempFileName;
$entryPoint = $saveFileName;
}

$tempFilePath = $tempDir . DIRECTORY_SEPARATOR . $tempFileName;
file_put_contents($tempFilePath, $codeContent);
$saveFilePath = $saveFileDir . DIRECTORY_SEPARATOR . $saveFileName;
file_put_contents($saveFilePath, $codeContent);

$uploadedFile = new UploadedFile(
$tempFilePath,
$tempFileName,
$saveFilePath,
$saveFileName,
'application/octet-stream',
null,
true
Expand Down Expand Up @@ -172,12 +171,12 @@
if (count($active_tab_array) == 1) {
$active_tab = reset($active_tab_array);
$this->dj->setCookie('active_tab', $active_tab);
}

Check failure on line 174 in webapp/src/Controller/Team/SubmissionController.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 space after closing brace; newline found
else if ($this->dj->getCookie('active_tab') != null) {

Check warning on line 175 in webapp/src/Controller/Team/SubmissionController.php

View workflow job for this annotation

GitHub Actions / phpcs

Usage of ELSE IF is discouraged; use ELSEIF instead
$cookie_active_tab = $this->dj->getCookie('active_tab');
if(in_array($cookie_active_tab, $active_tab_array)) {

Check failure on line 177 in webapp/src/Controller/Team/SubmissionController.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 space(s) after IF keyword; 0 found
$active_tab = $cookie_active_tab;
}

Check failure on line 179 in webapp/src/Controller/Team/SubmissionController.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 space after closing brace; newline found
else {
$active_tab = reset($active_tab_array);
$this->dj->setCookie('active_tab', $active_tab);
Expand Down
7 changes: 0 additions & 7 deletions webapp/templates/team/submit_modal.html.twig
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@
</div>
</div>

<style>
.single-tab {
width: 100%;
display: inline-block;
}
</style>

<script>
const fileInput = document.getElementById('submit_problem_code');
fileInput.addEventListener('change', (event) => {
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /