Skip to content

Commit

Permalink
java, kt entry_point
Browse files Browse the repository at this point in the history
  • Loading branch information
as6325400 committed Oct 9, 2024
1 parent 3893628 commit 3376c11
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
15 changes: 13 additions & 2 deletions webapp/src/Controller/Team/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ public function createAction(Request $request, ?Problem $problem = null): Respon
$language->getExtensions()[0]
);
$tempFileName = preg_replace('/[^a-zA-Z0-9_.-]/', '_', $tempFileName);

if ($language->getExtensions()[0] == 'java' || $language->getExtensions()[0] == 'kt') {
$entryPoint = $formPaste->get('entry_point')->getData() ?: null;
// Check for invalid characters in entry point name
$invalidChars = '/[<>:"\/\\|?*]/';
if(preg_match($invalidChars, $entryPoint)) {

Check failure on line 120 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
$this->addFlash('danger', 'Invalid entry point name.');
return $this->redirectToRoute('team_index');
}
$tempFileName = $entryPoint . '.' . $language->getExtensions()[0];
}

Check failure on line 125 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 $entryPoint = $tempFileName;

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

View workflow job for this annotation

GitHub Actions / phpcs

Inline control structures are not allowed

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

Expand All @@ -122,9 +135,7 @@ public function createAction(Request $request, ?Problem $problem = null): Respon
null,
true
);

$files = [$uploadedFile];
$entryPoint = $tempFileName;
}

if ($problem && $language && !empty($files)) {
Expand Down
31 changes: 30 additions & 1 deletion webapp/src/Form/Type/SubmitProblemPasteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,36 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'Entry point',
'required' => false,
'help' => 'The entry point for your code.',
'row_attr' => ['data-entry-point' => '']
'row_attr' => ['data-entry-point' => ''],
'constraints' => [
new Callback(function ($value, ExecutionContextInterface $context) {
/** @var Form $form */
$form = $context->getRoot();
/** @var Language $language */
$language = $form->get('language')->getData();
if ($language) {

Check failure on line 78 in webapp/src/Form/Type/SubmitProblemPasteType.php

View workflow job for this annotation

GitHub Actions / phpstan

If condition is always true.
$langId = strtolower($language->getExtensions()[0]);

Check failure on line 79 in webapp/src/Form/Type/SubmitProblemPasteType.php

View workflow job for this annotation

GitHub Actions / phpcs

Whitespace found at end of line
if ($language->getRequireEntryPoint() && empty($value)) {
$message = sprintf('%s required, but not specified',
$language->getEntryPointDescription() ?: 'Entry point');
$context
->buildViolation($message)
->atPath('entry_point')
->addViolation();
}

if (in_array($langId, ['java', 'kt']) && empty($value)) {
$message = sprintf('%s is required for %s language, but not specified',
$language->getEntryPointDescription() ?: 'Entry point',
ucfirst($langId));
$context
->buildViolation($message)
->atPath('entry_point')
->addViolation();
}
}
}),
]
]);
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($problemConfig) {
$data = $event->getData();
Expand Down
45 changes: 45 additions & 0 deletions webapp/templates/team/partials/submit_scripts.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,43 @@
}
}
function maybeShowEntryPointByPasteCode() {
var langid = $('#submit_problem_paste_language').val();
console.log($('#submit_problem_paste_problem'));
if (langid === "") {
return;
}
var $entryPoint = $('[data-entry-point]');
var $entryPointLabel = $entryPoint.find('label');
var $entryPointInput = $entryPoint.find('input');
var entryPointDescription = getEntryPoint(langid);
if (langid === 'java' || langid === 'kt') {
$entryPoint.show();
$entryPointInput.attr('required', 'required');
} else if (entryPointDescription) {
$entryPoint.show();
$entryPointInput.attr('required', 'required');
} else {
$entryPoint.hide();
$entryPointInput.attr('required', null);
}
if (entryPointDescription) {
var $labelChildren = $entryPointLabel.children();
$entryPointLabel.text(entryPointDescription).append($labelChildren);
}
if (langid === 'java') {
$entryPointInput.val(entryPointDetectJava('main.java'));
} else if (langid === 'kt') {
$entryPointInput.val(entryPointDetectKt('main.kt'));
} else {
$entryPointInput.val('');
}
}
$(function () {
var $entryPoint = $('[data-entry-point]');
$entryPoint.hide();
Expand Down Expand Up @@ -104,6 +141,14 @@
maybeShowEntryPoint();
});
$body.on('change', '#submit_problem_paste_language', function () {
maybeShowEntryPointByPasteCode();
});
$body.on('change', '#submit_problem_paste_problem', function () {
maybeShowEntryPointByPasteCode();
});
$body.on('submit', 'form[name=submit_problem]', function () {
var langelt = document.getElementById("submit_problem_language");
var language = langelt.options[langelt.selectedIndex].value;
Expand Down

0 comments on commit 3376c11

Please sign in to comment.