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

fix: restore demo checklist #123

Merged
merged 1 commit into from
Mar 31, 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
2 changes: 1 addition & 1 deletion assets/app/checklist/demo-checklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class DemoChecklist extends LitElement

for (const group of groups) {
for (const item of group.items) {
item.isCompleted = progressObject[item.id] ?? false;
item.is_completed = progressObject[item.id] ?? false;
}
}

Expand Down
35 changes: 30 additions & 5 deletions src/Controller/Public/DemoChecklistController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,50 @@
namespace App\Controller\Public;

use App\Controller\AbstractController;
use App\Entity\Project;
use App\Util\Checklist\Generator;
use App\Util\ClientMessageSerializer;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Cache\ItemInterface;

class DemoChecklistController extends AbstractController
{
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
#[Route(path: '/free-checklist', name: 'checklist_demo')]
public function checklistDemo(Generator $checklistGenerator, ClientMessageSerializer $serializer): Response
public function checklistDemo(Generator $checklistGenerator, ClientMessageSerializer $serializer, EntityManagerInterface $entityManager): Response
{
// @FIXME: This does not work with the new serializer, since the items/groups don't have IDs
// $checklist = $checklistGenerator->generateChecklist(null);
// $serializedItemGroups = $serializer->serialize($checklist->getItemGroups());
// The serializer does not like resources without IDs.
// To get around this, we'll just create a project & checklist in an
// SQL transaction, serialize the data, and then rollback the transaction.
// To avoid doing this too often, we cache this for a 30-day duration.
$cache = new FilesystemAdapter();
$serializedItemGroups = $cache->get('demo_checklist', function (ItemInterface $item) use ($checklistGenerator, $serializer, $entityManager) {
$item->expiresAfter(3600 * 24 * 30);

$project = (new Project())
->setName("Temporary checklist project")
->setUrl("https://sample.koalati.com");
$checklist = $checklistGenerator->generateChecklist($project);

$entityManager->beginTransaction();
$entityManager->persist($project);
$entityManager->persist($checklist);
$entityManager->flush();

$serializedItemGroups = $serializer->serialize($checklist->getItemGroups(), ['checklist.read']);

$entityManager->rollback();

return $serializedItemGroups;
});

return $this->render('public/checklist_demo.html.twig', [
"serializedItemGroups" => [], // $serializedItemGroups,
"serializedItemGroups" => $serializedItemGroups,
]);
}
}