diff --git a/composer.json b/composer.json index 4181af68a..95074c18f 100644 --- a/composer.json +++ b/composer.json @@ -73,7 +73,8 @@ "symfony/web-profiler-bundle": "^5.0", "symfony/var-dumper": "4.*", "symfony/debug-bundle": "^5.1", - "symfony/phpunit-bridge": "^5.2" + "symfony/phpunit-bridge": "^5.2", + "nelmio/alice": "^3.8" }, "scripts": { "auto-scripts": { diff --git a/docs/source/development/api.rst b/docs/source/development/api.rst index 86eb6ff65..d6f63eea3 100644 --- a/docs/source/development/api.rst +++ b/docs/source/development/api.rst @@ -450,4 +450,39 @@ Full configuration example single-collection: single base_role: null +Maintaining an OpenApi +====================== + +.. note:: + + This is experimental and may change. Keep reading this part. + +Accessing swagger +----------------- + +The swagger UI is accessible through ``_ + +This is possible only in development mode. + +You must be authenticated with a valid user to access it. + +Maintaining specs +----------------- + +Each bundle should have an `open api 3.0 spec file `_ at the bundle's root, and name :code:`chill.api.specs.yaml`. + +.. warning:: + + Update the command :code:`specs-build` into `package.json` when adding a new api file. + +The specs may be compiled from the different bundles filed, and validated using docker node: + +.. code-block:: bash + + ./docker-node.sh + # build the openapi + yarn specs-build + # validate + yarn specs-validate + diff --git a/docs/source/installation/index.rst b/docs/source/installation/index.rst index 6aee5c526..1312480e3 100644 --- a/docs/source/installation/index.rst +++ b/docs/source/installation/index.rst @@ -82,7 +82,7 @@ Chill will be available at ``http://localhost:8001.`` Currently, there isn't any .. code-block:: bash - docker-compose exec --user $(id -u) php bin/console doctrine:fixtures:load + docker-compose exec --user $(id -u) php bin/console doctrine:fixtures:load --purge-with-truncate There are several users available: diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php index 5cc055f26..b5c935c76 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php @@ -25,12 +25,19 @@ class AbstractCRUDController extends AbstractController * * @param string $id * @return object + * @throw Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the object is not found */ - protected function getEntity($action, $id, Request $request): ?object + protected function getEntity($action, $id, Request $request): object { - return $this->getDoctrine() + $e = $this->getDoctrine() ->getRepository($this->getEntityClass()) ->find($id); + + if (NULL === $e) { + throw $this->createNotFoundException(sprintf("The object %s for id %s is not found", $this->getEntityClass(), $id)); + } + + return $e; } /** diff --git a/src/Bundle/ChillMainBundle/Controller/SearchController.php b/src/Bundle/ChillMainBundle/Controller/SearchController.php index a44af8e7b..45390ceca 100644 --- a/src/Bundle/ChillMainBundle/Controller/SearchController.php +++ b/src/Bundle/ChillMainBundle/Controller/SearchController.php @@ -22,6 +22,7 @@ namespace Chill\MainBundle\Controller; +use Chill\MainBundle\Serializer\Model\Collection; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Chill\MainBundle\Search\UnknowSearchDomainException; @@ -34,6 +35,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Chill\MainBundle\Search\SearchProvider; use Symfony\Contracts\Translation\TranslatorInterface; use Chill\MainBundle\Pagination\PaginatorFactory; +use Chill\MainBundle\Search\SearchApi; /** * Class SearchController @@ -42,32 +44,24 @@ use Chill\MainBundle\Pagination\PaginatorFactory; */ class SearchController extends AbstractController { - /** - * - * @var SearchProvider - */ - protected $searchProvider; + protected SearchProvider $searchProvider; - /** - * - * @var TranslatorInterface - */ - protected $translator; + protected TranslatorInterface $translator; - /** - * - * @var PaginatorFactory - */ - protected $paginatorFactory; + protected PaginatorFactory $paginatorFactory; + + protected SearchApi $searchApi; function __construct( SearchProvider $searchProvider, TranslatorInterface $translator, - PaginatorFactory $paginatorFactory + PaginatorFactory $paginatorFactory, + SearchApi $searchApi ) { $this->searchProvider = $searchProvider; $this->translator = $translator; $this->paginatorFactory = $paginatorFactory; + $this->searchApi = $searchApi; } @@ -152,6 +146,19 @@ class SearchController extends AbstractController array('results' => $results, 'pattern' => $pattern) ); } + + public function searchApi(Request $request, $_format): JsonResponse + { + //TODO this is an incomplete implementation + $query = $request->query->get('q', ''); + + $results = $this->searchApi->getResults($query, 0, 150); + $paginator = $this->paginatorFactory->create(count($results)); + + $collection = new Collection($results, $paginator); + + return $this->json($collection); + } public function advancedSearchListAction(Request $request) { diff --git a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadCenters.php b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadCenters.php index 1da1af2f3..a3c01fdf6 100644 --- a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadCenters.php +++ b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadCenters.php @@ -55,11 +55,11 @@ class LoadCenters extends AbstractFixture implements OrderedFixtureInterface public function load(ObjectManager $manager) { foreach (static::$centers as $new) { - $centerA = new Center(); - $centerA->setName($new['name']); + $center = new Center(); + $center->setName($new['name']); - $manager->persist($centerA); - $this->addReference($new['ref'], $centerA); + $manager->persist($center); + $this->addReference($new['ref'], $center); static::$refs[] = $new['ref']; } diff --git a/src/Bundle/ChillMainBundle/Resources/public/scss/chillmain.scss b/src/Bundle/ChillMainBundle/Resources/public/scss/chillmain.scss index a27dcdc42..ed6d535e5 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/scss/chillmain.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/scss/chillmain.scss @@ -39,8 +39,17 @@ div.subheader { height: 130px; } -//// VUEJS //// +//// SCRATCH BUTTONS +.sc-button { + &.disabled { + cursor: default; + &.bt-remove { + background-color: #d9d9d9; + } + } +} +//// VUEJS //// div.vue-component { padding: 1.5em; margin: 2em 0; @@ -95,33 +104,47 @@ div.vue-component { } //// AddPersons modal -div.modal-body.up { - margin: auto 4em; - div.search { - position: relative; - input { - padding: 1.2em 1.5em 1.2em 2.5em; - margin: 1em 0; +div.body-head { + overflow-y: unset; + div.modal-body:first-child { + margin: auto 4em; + div.search { + position: relative; + input { + padding: 1.2em 1.5em 1.2em 2.5em; + margin: 1em 0; + } + i { + position: absolute; + opacity: 0.5; + padding: 0.65em 0; + top: 50%; + } + i.fa-search { + left: 0.5em; + } + i.fa-times { + right: 1em; + padding: 0.75em 0; + cursor: pointer; + } } - i { - position: absolute; - top: 50%; - left: 0.5em; - padding: 0.65em 0; - opacity: 0.5; - } - + } + div.modal-body:last-child { + padding-bottom: 0; } } -div.results { - div.count { - margin: -0.5em 0 0.7em; - display: flex; - justify-content: space-between; +div.count { + margin: -0.5em 0 0.7em; + display: flex; + justify-content: space-between; + a { + cursor: pointer; } +} +div.results { div.list-item { - line-height: 26pt; - padding: 0.3em 0.8em; + padding: 0.4em 0.8em; display: flex; flex-direction: row; &.checked { @@ -132,11 +155,20 @@ div.results { & > input { margin-right: 0.8em; } + span:not(.name) { + margin-left: 0.5em; + opacity: 0.5; + font-size: 90%; + font-style: italic; + } } div.right_actions { margin: 0 0 0 auto; + display: flex; + align-items: flex-end; & > * { margin-left: 0.5em; + align-self: baseline; } a.sc-button { border: 1px solid lightgrey; @@ -146,7 +178,6 @@ div.results { } } } - .discret { color: grey; margin-right: 1em; diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/Modal.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/Modal.vue index cbd2d0738..e6c1475e2 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/Modal.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/Modal.vue @@ -9,8 +9,8 @@ -