diff --git a/webapp/src/Controller/Jury/ExecutableController.php b/webapp/src/Controller/Jury/ExecutableController.php index 223f3995c2..df0f100250 100644 --- a/webapp/src/Controller/Jury/ExecutableController.php +++ b/webapp/src/Controller/Jury/ExecutableController.php @@ -12,6 +12,7 @@ use App\Service\EventLogService; use App\Utils\Utils; use Doctrine\ORM\EntityManagerInterface; +use InvalidArgumentException as PHPInvalidArgumentException; use Symfony\Component\HttpKernel\Attribute\MapQueryParameter; use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\Component\Form\Exception\InvalidArgumentException; @@ -42,6 +43,8 @@ public function __construct( #[Route(path: '', name: 'jury_executables')] public function indexAction(Request $request): Response { + $executables_tables_used = []; + $executables_tables_unused = []; $data = []; $form = $this->createForm(ExecutableUploadType::class, $data); $form->handleRequest($request); @@ -64,6 +67,15 @@ public function indexAction(Request $request): Response $propertyAccessor = PropertyAccess::createPropertyAccessor(); $executables_table = []; + $configScripts = []; + foreach (['compare', 'run', 'full_debug'] as $config_script) { + try { + $configScripts[] = (string)$this->config->get('default_' . $config_script); + } catch (PHPInvalidArgumentException $e) { + // If not found this is an older database, as we only use this for visual changes ignore this error; + } + } + foreach ($executables as $e) { $execdata = []; $execactions = []; @@ -115,16 +127,27 @@ public function indexAction(Request $request): Response 'link' => $this->generateUrl('jury_executable_download', ['execId' => $e->getExecid()]) ]; - $executables_table[] = [ - 'data' => $execdata, - 'actions' => $execactions, - 'link' => $this->generateUrl('jury_executable', ['execId' => $e->getExecid()]), - ]; + if ($e->checkUsed($configScripts)) { + $executables_tables_used[] = [ + 'data' => $execdata, + 'actions' => $execactions, + 'link' => $this->generateUrl('jury_executable', ['execId' => $e->getExecid()]), + ]; + } else { + $executables_tables_unused[] = [ + 'data' => $execdata, + 'actions' => $execactions, + 'link' => $this->generateUrl('jury_executable', ['execId' => $e->getExecid()]), + 'cssclass' => 'disabled', + ]; + } } // This is replaced with the icon. unset($table_fields['type']); + return $this->render('jury/executables.html.twig', [ - 'executables' => $executables_table, + 'executables_used' => $executables_tables_used, + 'executables_unused' => $executables_tables_unused, 'table_fields' => $table_fields, 'form' => $form, ]); diff --git a/webapp/src/Entity/Executable.php b/webapp/src/Entity/Executable.php index 30eb1aa422..24e80c6cf4 100644 --- a/webapp/src/Entity/Executable.php +++ b/webapp/src/Entity/Executable.php @@ -181,4 +181,20 @@ public function getZipfileContent(string $tempdir): string unlink($tempzipFile); return $zipFileContents; } + + /** + * @param string[] $configScripts + */ + public function checkUsed(array $configScripts): bool + { + foreach ($configScripts as $config_script) { + if ($this->execid === $config_script) { + return true; + } + } + if (count($this->problems_compare) || count($this->problems_run)) { + return true; + } + return false; + } } diff --git a/webapp/templates/jury/executables.html.twig b/webapp/templates/jury/executables.html.twig index cd5276371e..159492c57d 100644 --- a/webapp/templates/jury/executables.html.twig +++ b/webapp/templates/jury/executables.html.twig @@ -10,9 +10,11 @@ {% block content %} -

Executables

+

Used executables

+ {{ macros.table(executables_used, table_fields, {'ordering': 'false'}) }} - {{ macros.table(executables, table_fields, {'ordering': 'false'}) }} +

Unused executables

+ {{ macros.table(executables_unused, table_fields, {'ordering': 'false'}) }} {% if is_granted('ROLE_ADMIN') %}

diff --git a/webapp/tests/Unit/Controller/Jury/ExecutableControllerTest.php b/webapp/tests/Unit/Controller/Jury/ExecutableControllerTest.php index 86aef76a61..5b45c00ef2 100644 --- a/webapp/tests/Unit/Controller/Jury/ExecutableControllerTest.php +++ b/webapp/tests/Unit/Controller/Jury/ExecutableControllerTest.php @@ -17,7 +17,7 @@ class ExecutableControllerTest extends JuryControllerTestCase protected static string $deleteEntityIdentifier = 'description'; protected static string $getIDFunc = 'getExecid'; protected static string $className = Executable::class; - protected static array $DOM_elements = ['h1' => ['Executables']]; + protected static array $DOM_elements = ['h1' => ['Used executables', 'Unused executables']]; protected static string $addForm = 'executable_upload['; protected static array $addEntitiesShown = ['type']; protected static array $addEntities = [];