Skip to content

Commit 3376c11

Browse files
committed
java, kt entry_point
1 parent 3893628 commit 3376c11

File tree

3 files changed

+88
-3
lines changed

3 files changed

+88
-3
lines changed

webapp/src/Controller/Team/SubmissionController.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ public function createAction(Request $request, ?Problem $problem = null): Respon
112112
$language->getExtensions()[0]
113113
);
114114
$tempFileName = preg_replace('/[^a-zA-Z0-9_.-]/', '_', $tempFileName);
115+
116+
if ($language->getExtensions()[0] == 'java' || $language->getExtensions()[0] == 'kt') {
117+
$entryPoint = $formPaste->get('entry_point')->getData() ?: null;
118+
// Check for invalid characters in entry point name
119+
$invalidChars = '/[<>:"\/\\|?*]/';
120+
if(preg_match($invalidChars, $entryPoint)) {
121+
$this->addFlash('danger', 'Invalid entry point name.');
122+
return $this->redirectToRoute('team_index');
123+
}
124+
$tempFileName = $entryPoint . '.' . $language->getExtensions()[0];
125+
}
126+
else $entryPoint = $tempFileName;
127+
115128
$tempFilePath = $tempDir . DIRECTORY_SEPARATOR . $tempFileName;
116129
file_put_contents($tempFilePath, $codeContent);
117130

@@ -122,9 +135,7 @@ public function createAction(Request $request, ?Problem $problem = null): Respon
122135
null,
123136
true
124137
);
125-
126138
$files = [$uploadedFile];
127-
$entryPoint = $tempFileName;
128139
}
129140

130141
if ($problem && $language && !empty($files)) {

webapp/src/Form/Type/SubmitProblemPasteType.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,36 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
6868
'label' => 'Entry point',
6969
'required' => false,
7070
'help' => 'The entry point for your code.',
71-
'row_attr' => ['data-entry-point' => '']
71+
'row_attr' => ['data-entry-point' => ''],
72+
'constraints' => [
73+
new Callback(function ($value, ExecutionContextInterface $context) {
74+
/** @var Form $form */
75+
$form = $context->getRoot();
76+
/** @var Language $language */
77+
$language = $form->get('language')->getData();
78+
if ($language) {
79+
$langId = strtolower($language->getExtensions()[0]);
80+
if ($language->getRequireEntryPoint() && empty($value)) {
81+
$message = sprintf('%s required, but not specified',
82+
$language->getEntryPointDescription() ?: 'Entry point');
83+
$context
84+
->buildViolation($message)
85+
->atPath('entry_point')
86+
->addViolation();
87+
}
88+
89+
if (in_array($langId, ['java', 'kt']) && empty($value)) {
90+
$message = sprintf('%s is required for %s language, but not specified',
91+
$language->getEntryPointDescription() ?: 'Entry point',
92+
ucfirst($langId));
93+
$context
94+
->buildViolation($message)
95+
->atPath('entry_point')
96+
->addViolation();
97+
}
98+
}
99+
}),
100+
]
72101
]);
73102
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($problemConfig) {
74103
$data = $event->getData();

webapp/templates/team/partials/submit_scripts.html.twig

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,43 @@
5555
}
5656
}
5757
58+
function maybeShowEntryPointByPasteCode() {
59+
var langid = $('#submit_problem_paste_language').val();
60+
console.log($('#submit_problem_paste_problem'));
61+
if (langid === "") {
62+
return;
63+
}
64+
65+
var $entryPoint = $('[data-entry-point]');
66+
var $entryPointLabel = $entryPoint.find('label');
67+
var $entryPointInput = $entryPoint.find('input');
68+
var entryPointDescription = getEntryPoint(langid);
69+
70+
if (langid === 'java' || langid === 'kt') {
71+
$entryPoint.show();
72+
$entryPointInput.attr('required', 'required');
73+
} else if (entryPointDescription) {
74+
$entryPoint.show();
75+
$entryPointInput.attr('required', 'required');
76+
} else {
77+
$entryPoint.hide();
78+
$entryPointInput.attr('required', null);
79+
}
80+
81+
if (entryPointDescription) {
82+
var $labelChildren = $entryPointLabel.children();
83+
$entryPointLabel.text(entryPointDescription).append($labelChildren);
84+
}
85+
86+
if (langid === 'java') {
87+
$entryPointInput.val(entryPointDetectJava('main.java'));
88+
} else if (langid === 'kt') {
89+
$entryPointInput.val(entryPointDetectKt('main.kt'));
90+
} else {
91+
$entryPointInput.val('');
92+
}
93+
}
94+
5895
$(function () {
5996
var $entryPoint = $('[data-entry-point]');
6097
$entryPoint.hide();
@@ -104,6 +141,14 @@
104141
maybeShowEntryPoint();
105142
});
106143
144+
$body.on('change', '#submit_problem_paste_language', function () {
145+
maybeShowEntryPointByPasteCode();
146+
});
147+
148+
$body.on('change', '#submit_problem_paste_problem', function () {
149+
maybeShowEntryPointByPasteCode();
150+
});
151+
107152
$body.on('submit', 'form[name=submit_problem]', function () {
108153
var langelt = document.getElementById("submit_problem_language");
109154
var language = langelt.options[langelt.selectedIndex].value;

0 commit comments

Comments
 (0)