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

Show unused executables as disabled #2148

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 29 additions & 6 deletions webapp/src/Controller/Jury/ExecutableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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,
]);
Expand Down
16 changes: 16 additions & 0 deletions webapp/src/Entity/Executable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 4 additions & 2 deletions webapp/templates/jury/executables.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

{% block content %}

<h1>Executables</h1>
<h1>Used executables</h1>
{{ macros.table(executables_used, table_fields, {'ordering': 'false'}) }}

{{ macros.table(executables, table_fields, {'ordering': 'false'}) }}
<h1>Unused executables</h1>
{{ macros.table(executables_unused, table_fields, {'ordering': 'false'}) }}

{% if is_granted('ROLE_ADMIN') %}
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
Loading