mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge remote-tracking branch 'origin/master' into features/activity-form
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\AddressReference;
|
||||
|
||||
/**
|
||||
* Class AddressController
|
||||
*
|
||||
* @package Chill\MainBundle\Controller
|
||||
*/
|
||||
class AddressController extends AbstractController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Get API Data for showing endpoint
|
||||
*
|
||||
* @Route(
|
||||
* "/{_locale}/main/api/1.0/address/{address_id}/show.{_format}",
|
||||
* name="chill_main_address_api_show"
|
||||
* )
|
||||
* @ParamConverter("address", options={"id": "address_id"})
|
||||
*/
|
||||
public function showAddress(Address $address, $_format): Response
|
||||
{
|
||||
// TODO check ACL ?
|
||||
switch ($_format) {
|
||||
case 'json':
|
||||
return $this->json($address);
|
||||
default:
|
||||
throw new BadRequestException('Unsupported format');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get API Data for showing endpoint
|
||||
*
|
||||
* @Route(
|
||||
* "/{_locale}/main/api/1.0/address-reference/{address_reference_id}/show.{_format}",
|
||||
* name="chill_main_address_reference_api_show"
|
||||
* )
|
||||
* @ParamConverter("addressReference", options={"id": "address_reference_id"})
|
||||
*/
|
||||
public function showAddressReference(AddressReference $addressReference, $_format): Response
|
||||
{
|
||||
// TODO check ACL ?
|
||||
switch ($_format) {
|
||||
case 'json':
|
||||
return $this->json($addressReference);
|
||||
default:
|
||||
throw new BadRequestException('Unsupported format');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Class AddressReferenceAPIController
|
||||
*
|
||||
* @package Chill\MainBundle\Controller
|
||||
* @author Champs Libres
|
||||
*/
|
||||
class AddressReferenceAPIController extends ApiController
|
||||
{
|
||||
|
||||
protected function customizeQuery(string $action, Request $request, $qb): void
|
||||
{
|
||||
if ($request->query->has('postal_code')) {
|
||||
|
||||
$qb->where('e.postcode = :postal_code')
|
||||
->setParameter('postal_code', $request->query->get('postal_code'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Class PostalCodeAPIController
|
||||
*
|
||||
* @package Chill\MainBundle\Controller
|
||||
* @author Champs Libres
|
||||
*/
|
||||
class PostalCodeAPIController extends ApiController
|
||||
{
|
||||
|
||||
protected function customizeQuery(string $action, Request $request, $qb): void
|
||||
{
|
||||
if ($request->query->has('country')) {
|
||||
|
||||
$qb->where('e.country = :country')
|
||||
->setParameter('country', $request->query->get('country'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Champs-Libres Coopérative <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Chill\MainBundle\Timeline\TimelineBuilder;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
class TimelineCenterController extends AbstractController
|
||||
{
|
||||
|
||||
protected TimelineBuilder $timelineBuilder;
|
||||
|
||||
protected PaginatorFactory $paginatorFactory;
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(
|
||||
TimelineBuilder $timelineBuilder,
|
||||
PaginatorFactory $paginatorFactory,
|
||||
Security $security
|
||||
) {
|
||||
$this->timelineBuilder = $timelineBuilder;
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/center/timeline",
|
||||
* name="chill_center_timeline",
|
||||
* methods={"GET"}
|
||||
* )
|
||||
*/
|
||||
public function centerAction(Request $request)
|
||||
{
|
||||
// collect reachable center for each group
|
||||
$user = $this->security->getUser();
|
||||
$centers = [];
|
||||
foreach ($user->getGroupCenters() as $group) {
|
||||
$centers[] = $group->getCenter();
|
||||
}
|
||||
|
||||
if (0 === count($centers)) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
$nbItems = $this->timelineBuilder->countItems('center',
|
||||
[ 'centers' => $centers ]
|
||||
);
|
||||
|
||||
$paginator = $this->paginatorFactory->create($nbItems);
|
||||
|
||||
return $this->render('@ChillMain/Timeline/index.html.twig', array
|
||||
(
|
||||
'timeline' => $this->timelineBuilder->getTimelineHTML(
|
||||
'center',
|
||||
[ 'centers' => $centers ],
|
||||
$paginator->getCurrentPage()->getFirstItemNumber(),
|
||||
$paginator->getItemsPerPage()
|
||||
),
|
||||
'nb_items' => $nbItems,
|
||||
'paginator' => $paginator
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@@ -284,6 +284,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
]
|
||||
],
|
||||
[
|
||||
'controller' => \Chill\MainBundle\Controller\AddressReferenceAPIController::class,
|
||||
'class' => \Chill\MainBundle\Entity\AddressReference::class,
|
||||
'name' => 'address_reference',
|
||||
'base_path' => '/api/1.0/main/address-reference',
|
||||
@@ -304,6 +305,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
]
|
||||
],
|
||||
[
|
||||
'controller' => \Chill\MainBundle\Controller\PostalCodeAPIController::class,
|
||||
'class' => \Chill\MainBundle\Entity\PostalCode::class,
|
||||
'name' => 'postal_code',
|
||||
'base_path' => '/api/1.0/main/postal-code',
|
||||
|
@@ -9,11 +9,11 @@ use \JsonSerializable;
|
||||
*
|
||||
*/
|
||||
class Point implements JsonSerializable {
|
||||
private float $lat;
|
||||
private float $lon;
|
||||
private ?float $lat = null;
|
||||
private ?float $lon = null;
|
||||
public static string $SRID = '4326';
|
||||
|
||||
private function __construct(float $lon, float $lat)
|
||||
private function __construct(?float $lon, ?float $lat)
|
||||
{
|
||||
$this->lat = $lat;
|
||||
$this->lon = $lon;
|
||||
|
@@ -4,6 +4,7 @@ namespace Chill\MainBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Chill\MainBundle\Doctrine\Model\Point;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
|
||||
@@ -22,6 +23,7 @@ class Address
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $id;
|
||||
|
||||
@@ -29,6 +31,7 @@ class Address
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $street = '';
|
||||
|
||||
@@ -36,6 +39,7 @@ class Address
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $streetNumber = '';
|
||||
|
||||
@@ -43,6 +47,7 @@ class Address
|
||||
* @var PostalCode
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\PostalCode")
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $postcode;
|
||||
|
||||
@@ -50,6 +55,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=16, nullable=true)
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $floor;
|
||||
|
||||
@@ -57,6 +63,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=16, nullable=true)
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $corridor;
|
||||
|
||||
@@ -64,6 +71,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=16, nullable=true)
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $steps;
|
||||
|
||||
@@ -71,6 +79,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $buildingName;
|
||||
|
||||
@@ -78,6 +87,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=16, nullable=true)
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $flat;
|
||||
|
||||
@@ -85,6 +95,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $distribution;
|
||||
|
||||
@@ -92,6 +103,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $extra;
|
||||
|
||||
@@ -102,6 +114,7 @@ class Address
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(type="date")
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $validFrom;
|
||||
|
||||
@@ -112,11 +125,13 @@ class Address
|
||||
* @var \DateTime|null
|
||||
*
|
||||
* @ORM\Column(type="date", nullable=true)
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $validTo;
|
||||
|
||||
/**
|
||||
* True if the address is a "no address", aka homeless person, ...
|
||||
* @groups({"write"})
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
@@ -128,6 +143,7 @@ class Address
|
||||
* @var Point|null
|
||||
*
|
||||
* @ORM\Column(type="point", nullable=true)
|
||||
* @groups({"write"})
|
||||
*/
|
||||
private $point;
|
||||
|
||||
@@ -137,6 +153,7 @@ class Address
|
||||
* @var ThirdParty|null
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty")
|
||||
* @groups({"write"})
|
||||
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
|
||||
*/
|
||||
private $linkedToThirdParty;
|
||||
|
@@ -4,6 +4,7 @@ namespace Chill\MainBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Chill\MainBundle\Doctrine\Model\Point;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
@@ -16,21 +17,25 @@ class AddressReference
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $refId;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $street;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $streetNumber;
|
||||
|
||||
@@ -38,16 +43,19 @@ class AddressReference
|
||||
* @var PostalCode
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\PostalCode")
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $postcode;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $municipalityCode;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $source;
|
||||
|
||||
@@ -57,6 +65,7 @@ class AddressReference
|
||||
* @var Point
|
||||
*
|
||||
* @ORM\Column(type="point")
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $point;
|
||||
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace Chill\MainBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
/**
|
||||
* Country
|
||||
@@ -20,6 +21,7 @@ class Country
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $id;
|
||||
|
||||
@@ -27,13 +29,16 @@ class Country
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="json_array")
|
||||
* @groups({"read"})
|
||||
*
|
||||
*/
|
||||
private $name;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=3)
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $countryCode;
|
||||
|
||||
@@ -41,7 +46,7 @@ class Country
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
@@ -57,20 +62,20 @@ class Country
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -90,12 +95,12 @@ class Country
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $countryCode
|
||||
* @param string $countryCode
|
||||
*/
|
||||
public function setCountryCode($countryCode)
|
||||
{
|
||||
$this->countryCode = $countryCode;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace Chill\MainBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
/**
|
||||
* PostalCode
|
||||
@@ -25,6 +26,7 @@ class PostalCode
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $id;
|
||||
|
||||
@@ -32,6 +34,7 @@ class PostalCode
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=255, name="label")
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $name;
|
||||
|
||||
@@ -39,6 +42,7 @@ class PostalCode
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=100)
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $code;
|
||||
|
||||
@@ -46,6 +50,7 @@ class PostalCode
|
||||
* @var Country
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Country")
|
||||
* @groups({"read"})
|
||||
*/
|
||||
private $country;
|
||||
|
||||
|
@@ -23,7 +23,7 @@
|
||||
// @import "bootstrap/scss/button-group";
|
||||
// @import "bootstrap/scss/input-group";
|
||||
// @import "bootstrap/scss/custom-forms";
|
||||
// @import "bootstrap/scss/nav";
|
||||
@import "bootstrap/scss/nav";
|
||||
// @import "bootstrap/scss/navbar";
|
||||
// @import "bootstrap/scss/card";
|
||||
// @import "bootstrap/scss/breadcrumb";
|
||||
|
@@ -56,7 +56,7 @@ div#header-accompanying_course-name {
|
||||
background: none repeat scroll 0 0 #718596;
|
||||
color: #FFF;
|
||||
h1 {
|
||||
margin: 0.4em 0;
|
||||
margin: 0.4em 0;
|
||||
}
|
||||
span {
|
||||
a {
|
||||
@@ -77,7 +77,7 @@ div#header-accompanying_course-details {
|
||||
/*
|
||||
* FLEX RESPONSIVE TABLE/BLOCK PRESENTATION
|
||||
*/
|
||||
div.flex-bloc,
|
||||
div.flex-bloc,
|
||||
div.flex-table {
|
||||
h2, h3, h4, dl, p {
|
||||
margin: 0;
|
||||
@@ -103,25 +103,35 @@ div.flex-table {
|
||||
* Bloc appearance
|
||||
*/
|
||||
div.flex-bloc {
|
||||
box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-items: stretch;
|
||||
align-content: stretch;
|
||||
|
||||
|
||||
div.item-bloc {
|
||||
flex-grow: 0; flex-shrink: 1; flex-basis: 50%;
|
||||
margin: 0;
|
||||
padding: 1em;
|
||||
border-top: 0;
|
||||
&:nth-child(1), &:nth-child(2) {
|
||||
border-top: 1px solid #000;
|
||||
}
|
||||
border-left: 0;
|
||||
&:nth-child(odd) {
|
||||
border-left: 1px solid #000;
|
||||
}
|
||||
|
||||
//background-color: #e6e6e6;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
|
||||
div.item-row {
|
||||
flex-grow: 1; flex-shrink: 1; flex-basis: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
|
||||
div.item-col {
|
||||
&:first-child {
|
||||
flex-grow: 0; flex-shrink: 0; flex-basis: auto;
|
||||
@@ -129,7 +139,7 @@ div.flex-bloc {
|
||||
&:last-child {
|
||||
flex-grow: 1; flex-shrink: 1; flex-basis: auto;
|
||||
display: flex;
|
||||
|
||||
|
||||
.list-content { // ul, dl, or div
|
||||
}
|
||||
ul.record_actions {
|
||||
@@ -139,7 +149,7 @@ div.flex-bloc {
|
||||
li {
|
||||
margin-right: 5px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,24 +160,30 @@ div.flex-bloc {
|
||||
@media only screen and (max-width: 900px) {
|
||||
flex-direction: column;
|
||||
margin: auto 0;
|
||||
div.item-bloc {
|
||||
border-left: 1px solid #000;
|
||||
&:nth-child(2) {
|
||||
border-top: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Table appearance
|
||||
*/
|
||||
*/
|
||||
div.flex-table {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
align-content: stretch;
|
||||
|
||||
|
||||
div.item-bloc {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 1em;
|
||||
&:nth-child(even) {
|
||||
background-color: #e6e6e6;
|
||||
background-color: #e6e6e6;
|
||||
}
|
||||
|
||||
div.item-row {
|
||||
@@ -179,7 +195,7 @@ div.flex-table {
|
||||
padding-top: 0.5em;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
|
||||
div.item-col {
|
||||
&:first-child {
|
||||
flex-grow: 0; flex-shrink: 0; flex-basis: 33%;
|
||||
@@ -188,7 +204,7 @@ div.flex-table {
|
||||
flex-grow: 1; flex-shrink: 1; flex-basis: auto;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
||||
|
||||
.list-content { // ul, dl, or div
|
||||
}
|
||||
ul.record_actions {
|
||||
@@ -198,7 +214,7 @@ div.flex-table {
|
||||
li {
|
||||
margin-right: 5px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@media only screen and (max-width: 900px) {
|
||||
@@ -211,9 +227,47 @@ div.flex-table {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// neutralize
|
||||
|
||||
// neutralize
|
||||
div.chill_address div.chill_address_address p { text-indent: 0; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Address form
|
||||
*/
|
||||
div.address_form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
div.address_form__header {
|
||||
|
||||
}
|
||||
div.address_form__select {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
|
||||
div.address_form__select__body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
div.address_form__select__map {
|
||||
margin: 0px 20px;
|
||||
div#address_map {
|
||||
height:400px;
|
||||
width:400px;
|
||||
}
|
||||
}
|
||||
}
|
||||
div.address_form__more {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
|
||||
|
||||
<div v-if="address.address">
|
||||
{{ address.address.street }}, {{ address.address.streetNumber }}
|
||||
</div>
|
||||
@@ -9,7 +9,7 @@
|
||||
<div v-if="address.country">
|
||||
{{ address.country.name }}
|
||||
</div>
|
||||
|
||||
|
||||
<add-address
|
||||
@addNewAddress="addNewAddress">
|
||||
</add-address>
|
||||
@@ -33,7 +33,26 @@ export default {
|
||||
methods: {
|
||||
addNewAddress({ address, modal }) {
|
||||
console.log('@@@ CLICK button addNewAdress', address);
|
||||
this.$store.dispatch('addAddress', address.selected);
|
||||
|
||||
let newAddress = {
|
||||
'isNoAddress': address.isNoAddress,
|
||||
'street': address.selected.address.street,
|
||||
'streetNumber': address.selected.address.streetNumber,
|
||||
'postcode': {'id': address.selected.city.id },
|
||||
'floor': address.floor,
|
||||
'corridor': address.corridor,
|
||||
'steps': address.steps,
|
||||
'flat': address.flat,
|
||||
'buildingName': address.buildingName,
|
||||
'distribution': address.distribution,
|
||||
'extra': address.extra
|
||||
};
|
||||
|
||||
if (address.selected.address.point !== undefined){
|
||||
newAddress = Object.assign(newAddress, {'point': address.selected.address.point.coordinates});
|
||||
}
|
||||
|
||||
this.$store.dispatch('addAddress', newAddress);
|
||||
modal.showModal = false;
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,13 @@
|
||||
const addressMessages = {
|
||||
fr: {
|
||||
add_an_address: 'Ajouter une adresse',
|
||||
select_an_address: 'Sélectionner une adresse',
|
||||
add_an_address_title: 'Ajouter une adresse',
|
||||
select_an_address_title: 'Sélectionner une adresse',
|
||||
fill_an_address: 'Compléter l\'adresse',
|
||||
select_country: 'Choisir le pays',
|
||||
select_city: 'Choisir une localité',
|
||||
select_address: 'Choisir une adresse',
|
||||
isNoAddress: 'L\'adresse n\'est pas celle d\'un domicile fixe ?',
|
||||
create_address: 'Appuyer sur "Entrée" pour créer une nouvelle adresse',
|
||||
isNoAddress: 'Pas d\'adresse complète',
|
||||
floor: 'Étage',
|
||||
corridor: 'Couloir',
|
||||
steps: 'Escalier',
|
||||
|
@@ -1,8 +1,7 @@
|
||||
import 'es6-promise/auto';
|
||||
import { createStore } from 'vuex';
|
||||
|
||||
// le fetch POST serait rangé dans la logique du composant qui appelle AddAddress
|
||||
//import { postAddress } from '... api'
|
||||
import { postAddress } from '../../_api/AddAddress'
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
|
||||
@@ -10,11 +9,14 @@ const store = createStore({
|
||||
strict: debug,
|
||||
state: {
|
||||
address: {},
|
||||
errorMsg: {}
|
||||
errorMsg: []
|
||||
},
|
||||
getters: {
|
||||
},
|
||||
mutations: {
|
||||
catchError(state, error) {
|
||||
state.errorMsg.push(error);
|
||||
},
|
||||
addAddress(state, address) {
|
||||
console.log('@M addAddress address', address);
|
||||
state.address = address;
|
||||
@@ -23,19 +25,19 @@ const store = createStore({
|
||||
actions: {
|
||||
addAddress({ commit }, payload) {
|
||||
console.log('@A addAddress payload', payload);
|
||||
commit('addAddress', payload); // à remplacer par
|
||||
|
||||
// fetch POST qui envoie l'adresse, et récupère la confirmation que c'est ok.
|
||||
// La confirmation est l'adresse elle-même.
|
||||
//
|
||||
// postAddress(payload)
|
||||
// .fetch(address => new Promise((resolve, reject) => {
|
||||
// commit('addAddress', address);
|
||||
// resolve();
|
||||
// }))
|
||||
// .catch((error) => {
|
||||
// state.errorMsg.push(error.message);
|
||||
// });
|
||||
//commit('addAddress', payload); // à remplacer par la suite
|
||||
|
||||
//fetch POST qui envoie l'adresse, et récupère la confirmation que c'est ok.
|
||||
//La confirmation est l'adresse elle-même.
|
||||
|
||||
postAddress(payload)
|
||||
.then(address => new Promise((resolve, reject) => {
|
||||
commit('addAddress', address);
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
commit('catchError', error);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@@ -1,37 +1,43 @@
|
||||
/*
|
||||
* Endpoint countries GET
|
||||
* TODO
|
||||
* Endpoint chill_api_single_country__index
|
||||
* method GET, get Country Object
|
||||
* @returns {Promise} a promise containing all Country object
|
||||
*/
|
||||
const fetchCountries = () => {
|
||||
console.log('<<< fetching countries');
|
||||
return [
|
||||
{id: 1, name: 'France', countryCode: 'FR'},
|
||||
{id: 2, name: 'Belgium', countryCode: 'BE'}
|
||||
];
|
||||
|
||||
const url = `/api/1.0/main/country.json?item_per_page=1000`;
|
||||
return fetch(url)
|
||||
.then(response => {
|
||||
if (response.ok) { return response.json(); }
|
||||
throw Error('Error with request resource response');
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* Endpoint cities GET
|
||||
* TODO
|
||||
* Endpoint chill_api_single_postal_code__index
|
||||
* method GET, get Country Object
|
||||
* @returns {Promise} a promise containing all Postal Code objects filtered with country
|
||||
*/
|
||||
const fetchCities = (country) => {
|
||||
const fetchCities = (country) => {
|
||||
console.log('<<< fetching cities for', country);
|
||||
return [
|
||||
{id: 1, name: 'Bruxelles', code: '1000', country: 'BE'},
|
||||
{id: 2, name: 'Aisne', code: '85045', country: 'FR'},
|
||||
{id: 3, name: 'Saint-Gervais', code: '85230', country: 'FR'}
|
||||
];
|
||||
const url = `/api/1.0/main/postal-code.json?item_per_page=1000&country=${country.id}`;
|
||||
return fetch(url)
|
||||
.then(response => {
|
||||
if (response.ok) { return response.json(); }
|
||||
throw Error('Error with request resource response');
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* Endpoint chill_main_address_reference_api_show
|
||||
* Endpoint chill_api_single_address_reference__index
|
||||
* method GET, get AddressReference Object
|
||||
* @returns {Promise} a promise containing all AddressReference object
|
||||
* @returns {Promise} a promise containing all AddressReference objects filtered with postal code
|
||||
*/
|
||||
const fetchReferenceAddresses = (city) => {
|
||||
console.log('<<< fetching references addresses for', city); // city n'est pas utilisé pour le moment
|
||||
|
||||
const url = `/api/1.0/main/address-reference.json`;
|
||||
const fetchReferenceAddresses = (postalCode) => {
|
||||
console.log('<<< fetching references addresses for', postalCode);
|
||||
//TODO deal with huge number of addresses... we should do suggestion...
|
||||
const url = `/api/1.0/main/address-reference.json?item_per_page=1000&postal_code=${postalCode.id}`;
|
||||
return fetch(url)
|
||||
.then(response => {
|
||||
if (response.ok) { return response.json(); }
|
||||
@@ -39,8 +45,31 @@ const fetchReferenceAddresses = (city) => {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* Endpoint chill_api_single_address__entity__create
|
||||
* method POST, post Address Object
|
||||
* @returns {Promise}
|
||||
*/
|
||||
const postAddress = (address) => {
|
||||
console.log(address);
|
||||
const url = `/api/1.0/main/address.json?`;
|
||||
const body = address;
|
||||
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8'
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
}).then(response => {
|
||||
if (response.ok) { return response.json(); }
|
||||
throw Error('Error with request resource response');
|
||||
});
|
||||
};
|
||||
|
||||
export {
|
||||
fetchCountries,
|
||||
fetchCities,
|
||||
fetchReferenceAddresses
|
||||
fetchReferenceAddresses,
|
||||
postAddress
|
||||
};
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<button class="sc-button bt-create centered mt-4" @click="openModal">
|
||||
{{ $t('add_an_address') }}
|
||||
{{ $t('add_an_address_title') }}
|
||||
</button>
|
||||
|
||||
<teleport to="body">
|
||||
@@ -9,76 +9,64 @@
|
||||
@close="modal.showModal = false">
|
||||
|
||||
<template v-slot:header>
|
||||
<h3 class="modal-title">{{ $t('add_an_address') }}</h3>
|
||||
<h3 class="modal-title">{{ $t('add_an_address_title') }}</h3>
|
||||
</template>
|
||||
|
||||
<template v-slot:body>
|
||||
|
||||
<h4>{{ $t('select_an_address') }}</h4>
|
||||
|
||||
<label for="isNoAddress">
|
||||
<input type="checkbox"
|
||||
name="isNoAddress"
|
||||
v-bind:placeholder="$t('isNoAddress')"
|
||||
v-model="isNoAddress"
|
||||
v-bind:value="value"/>
|
||||
{{ $t('isNoAddress') }}
|
||||
</label>
|
||||
<div class="address_form">
|
||||
|
||||
<country-selection
|
||||
v-bind:address="address"
|
||||
v-bind:getCities="getCities">
|
||||
</country-selection>
|
||||
|
||||
<city-selection
|
||||
v-bind:address="address"
|
||||
v-bind:getReferenceAddresses="getReferenceAddresses">
|
||||
</city-selection>
|
||||
|
||||
<address-selection
|
||||
v-bind:address="address"
|
||||
v-bind:updateMapCenter="updateMapCenter">
|
||||
</address-selection>
|
||||
<div class="address_form__header">
|
||||
<h4>{{ $t('select_an_address_title') }}</h4>
|
||||
</div>
|
||||
|
||||
<address-map
|
||||
v-bind:address="address"
|
||||
ref="addressMap">
|
||||
</address-map>
|
||||
|
||||
<address-more
|
||||
v-if="!isNoAddress"
|
||||
v-bind:address="address">
|
||||
</address-more>
|
||||
|
||||
<!--
|
||||
<div class="address_form__fields__isNoAddress"></div>
|
||||
<div class="address_form__select">
|
||||
<div class="address_form__select__header"></div>
|
||||
<div class="address_form__select__left"></div>
|
||||
<div class="address_form__map"></div>
|
||||
<div class="address_form__select">
|
||||
|
||||
<div class="address_form__select__body">
|
||||
<label for="isNoAddress">
|
||||
<input type="checkbox"
|
||||
name="isNoAddress"
|
||||
v-bind:placeholder="$t('isNoAddress')"
|
||||
v-model="isNoAddress"
|
||||
v-bind:value="value"/>
|
||||
{{ $t('isNoAddress') }}
|
||||
</label>
|
||||
|
||||
<country-selection
|
||||
v-bind:address="address"
|
||||
v-bind:getCities="getCities">
|
||||
</country-selection>
|
||||
|
||||
<city-selection
|
||||
v-bind:address="address"
|
||||
v-bind:getReferenceAddresses="getReferenceAddresses">
|
||||
</city-selection>
|
||||
|
||||
<address-selection
|
||||
v-bind:address="address"
|
||||
v-bind:updateMapCenter="updateMapCenter">
|
||||
</address-selection>
|
||||
</div>
|
||||
|
||||
<div class="address_form__select__map">
|
||||
<address-map
|
||||
v-bind:address="address"
|
||||
ref="addressMap">
|
||||
</address-map>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="address_form__more">
|
||||
<address-more
|
||||
v-if="!isNoAddress"
|
||||
v-bind:address="address">
|
||||
</address-more>
|
||||
</div>
|
||||
</div>
|
||||
<div class="address_form__fields">
|
||||
<div class="address_form__fields__header"></div>
|
||||
<div class="address_form__fields__left"></div>
|
||||
<div class="address_form__fields__right"></div>
|
||||
</div>
|
||||
|
||||
à discuter,
|
||||
mais je pense qu'il est préférable de profiter de l'imbriquation des classes css
|
||||
|
||||
div.address_form {
|
||||
div.select {
|
||||
div.header {}
|
||||
div.left {}
|
||||
div.map {}
|
||||
}
|
||||
}
|
||||
|
||||
-->
|
||||
|
||||
</template>
|
||||
|
||||
<template v-slot:footer>
|
||||
<button class="sc-button green"
|
||||
<button class="sc-button green"
|
||||
@click.prevent="$emit('addNewAddress', { address, modal })">
|
||||
<i class="fa fa-plus fa-fw"></i>{{ $t('action.add')}}
|
||||
</button>
|
||||
@@ -155,49 +143,47 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.getCountries();
|
||||
},
|
||||
methods: {
|
||||
openModal() {
|
||||
this.modal.showModal = true;
|
||||
this.resetAll();
|
||||
this.getCountries();
|
||||
|
||||
//this.$nextTick(function() {
|
||||
// this.$refs.search.focus(); // positionner le curseur à l'ouverture de la modale
|
||||
//})
|
||||
},
|
||||
getCountries() {
|
||||
console.log('getCountries');
|
||||
this.address.loaded.countries = fetchCountries(); // à remplacer par
|
||||
// fetchCountries().then(countries => new Promise((resolve, reject) => {
|
||||
// this.address.loaded.countries = countries;
|
||||
// resolve()
|
||||
// }))
|
||||
// .catch((error) => {
|
||||
// this.errorMsg.push(error.message);
|
||||
// });
|
||||
fetchCountries().then(countries => new Promise((resolve, reject) => {
|
||||
this.address.loaded.countries = countries.results;
|
||||
resolve()
|
||||
}))
|
||||
.catch((error) => {
|
||||
this.errorMsg.push(error.message);
|
||||
});
|
||||
},
|
||||
getCities(country) {
|
||||
console.log('getCities for', country.name);
|
||||
this.address.loaded.cities = fetchCities(); // à remplacer par
|
||||
// fetchCities(country).then(cities => new Promise((resolve, reject) => {
|
||||
// this.address.loaded.cities = cities;
|
||||
// resolve()
|
||||
// }))
|
||||
// .catch((error) => {
|
||||
// this.errorMsg.push(error.message);
|
||||
// });
|
||||
fetchCities(country).then(cities => new Promise((resolve, reject) => {
|
||||
this.address.loaded.cities = cities.results;
|
||||
resolve()
|
||||
}))
|
||||
.catch((error) => {
|
||||
this.errorMsg.push(error.message);
|
||||
});
|
||||
},
|
||||
getReferenceAddresses(city) {
|
||||
console.log('getReferenceAddresses for', city.name);
|
||||
fetchReferenceAddresses(city) // il me semble que le paramètre city va limiter le poids des adresses de références reçues
|
||||
.then(addresses => new Promise((resolve, reject) => {
|
||||
fetchReferenceAddresses(city).then(addresses => new Promise((resolve, reject) => {
|
||||
console.log('addresses', addresses);
|
||||
this.address.loaded.addresses = addresses.results;
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
this.errorMsg.push(error.message);
|
||||
});
|
||||
.catch((error) => {
|
||||
this.errorMsg.push(error.message);
|
||||
});
|
||||
},
|
||||
updateMapCenter(point) {
|
||||
console.log('point', point);
|
||||
@@ -208,7 +194,7 @@ export default {
|
||||
resetAll() {
|
||||
console.log('reset all selected');
|
||||
this.address.loaded.addresses = [];
|
||||
this.address.selected.address = {};
|
||||
this.address.selected.address = {};
|
||||
this.address.loaded.cities = [];
|
||||
this.address.selected.city = {};
|
||||
this.address.selected.country = {};
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<div id='address_map' style='height:400px; width:400px;'></div>
|
||||
<div id='address_map'></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -11,6 +11,7 @@ import markerIconPng from 'leaflet/dist/images/marker-icon.png'
|
||||
import 'leaflet/dist/leaflet.css';
|
||||
|
||||
let map;
|
||||
let marker;
|
||||
|
||||
export default {
|
||||
name: 'AddressMap',
|
||||
@@ -30,13 +31,15 @@ export default {
|
||||
|
||||
const markerIcon = L.icon({
|
||||
iconUrl: markerIconPng,
|
||||
iconAnchor: [12, 41],
|
||||
});
|
||||
|
||||
L.marker([48.8589, 2.3469], {icon: markerIcon}).addTo(map);
|
||||
marker = L.marker([48.8589, 2.3469], {icon: markerIcon}).addTo(map);
|
||||
|
||||
},
|
||||
update() {
|
||||
console.log('update map with : ', this.address.addressMap.center)
|
||||
marker.setLatLng(this.address.addressMap.center);
|
||||
map.setView(this.address.addressMap.center, 12);
|
||||
}
|
||||
},
|
||||
|
@@ -1,38 +1,56 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<select
|
||||
v-model="selected">
|
||||
<option :value="{}" disabled selected>{{ $t('select_address') }}</option>
|
||||
<option
|
||||
v-for="item in this.addresses"
|
||||
v-bind:item="item"
|
||||
v-bind:key="item.id"
|
||||
v-bind:value="item">
|
||||
{{ item.street }}, {{ item.streetNumber }}
|
||||
</option>
|
||||
</select>
|
||||
<VueMultiselect
|
||||
v-model="value"
|
||||
@select="selectAddress"
|
||||
name="field"
|
||||
track-by="id"
|
||||
label="value"
|
||||
:custom-label="transName"
|
||||
:taggable="true"
|
||||
:multiple="false"
|
||||
@tag="addAddress"
|
||||
:placeholder="$t('select_address')"
|
||||
:tagPlaceholder="$t('create_address')"
|
||||
:options="addresses">
|
||||
</VueMultiselect>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import VueMultiselect from 'vue-multiselect';
|
||||
|
||||
export default {
|
||||
name: 'AddressSelection',
|
||||
components: { VueMultiselect },
|
||||
props: ['address', 'updateMapCenter'],
|
||||
data() {
|
||||
return {
|
||||
value: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
addresses() {
|
||||
return this.address.loaded.addresses;
|
||||
addresses() {
|
||||
return this.address.loaded.addresses;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
transName(value) {
|
||||
return value.streetNumber === undefined ? value.street : `${value.street}, ${value.streetNumber}`
|
||||
},
|
||||
selected: {
|
||||
set(value) {
|
||||
console.log('selected value', value);
|
||||
this.address.selected.address = value;
|
||||
this.updateMapCenter(value.point);
|
||||
},
|
||||
get() {
|
||||
return this.address.selected.address;
|
||||
}
|
||||
selectAddress(value) {
|
||||
this.address.selected.address = value;
|
||||
this.updateMapCenter(value.point);
|
||||
},
|
||||
addAddress (newAddress) {
|
||||
const address = {
|
||||
street: newAddress
|
||||
};
|
||||
this.value = address;
|
||||
this.address.selected.address = address;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style src="vue-multiselect/dist/vue-multiselect.css"></style>
|
||||
|
@@ -1,38 +1,45 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<select
|
||||
v-model="selected">
|
||||
<option :value="{}" disabled selected>{{ $t('select_city') }}</option>
|
||||
<option
|
||||
v-for="item in this.cities"
|
||||
v-bind:item="item"
|
||||
v-bind:key="item.id"
|
||||
v-bind:value="item">
|
||||
{{ item.code }}-{{ item.name }}
|
||||
</option>
|
||||
</select>
|
||||
<VueMultiselect
|
||||
v-model="value"
|
||||
@select="selectCity"
|
||||
name="field"
|
||||
track-by="id"
|
||||
label="value"
|
||||
:custom-label="transName"
|
||||
:placeholder="$t('select_city')"
|
||||
:options="cities">
|
||||
</VueMultiselect>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import VueMultiselect from 'vue-multiselect';
|
||||
|
||||
export default {
|
||||
name: 'CitySelection',
|
||||
components: { VueMultiselect },
|
||||
props: ['address', 'getReferenceAddresses'],
|
||||
data() {
|
||||
return {
|
||||
value: null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
transName(value) {
|
||||
return `${value.code}-${value.name}`
|
||||
},
|
||||
selectCity(value) {
|
||||
this.address.selected.city = value;
|
||||
this.getReferenceAddresses(value);
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
cities() {
|
||||
return this.address.loaded.cities;
|
||||
},
|
||||
selected: {
|
||||
set(value) {
|
||||
console.log('selected value', value.name);
|
||||
this.address.selected.city = value;
|
||||
this.getReferenceAddresses(value);
|
||||
},
|
||||
get() {
|
||||
return this.address.selected.city;
|
||||
}
|
||||
},
|
||||
cities() {
|
||||
return this.address.loaded.cities;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style src="vue-multiselect/dist/vue-multiselect.css"></style>
|
||||
|
@@ -1,38 +1,59 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<select
|
||||
v-model="selected">
|
||||
<option :value="{}" disabled selected>{{ $t('select_country') }}</option>
|
||||
<option
|
||||
v-for="item in this.countries"
|
||||
v-bind:item="item"
|
||||
v-bind:key="item.id"
|
||||
v-bind:value="item">
|
||||
{{ item.name }}
|
||||
</option>
|
||||
</select>
|
||||
<VueMultiselect
|
||||
v-model="value"
|
||||
name="field"
|
||||
track-by="id"
|
||||
label="name"
|
||||
:custom-label="transName"
|
||||
:placeholder="$t('select_country')"
|
||||
:options="countries"
|
||||
@select="selectCountry">
|
||||
</VueMultiselect>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import VueMultiselect from 'vue-multiselect';
|
||||
|
||||
export default {
|
||||
name: 'CountrySelection',
|
||||
components: { VueMultiselect },
|
||||
props: ['address', 'getCities'],
|
||||
computed: {
|
||||
countries() {
|
||||
return this.address.loaded.countries;
|
||||
},
|
||||
selected: {
|
||||
set(value) {
|
||||
console.log('selected value', value.name);
|
||||
this.address.selected.country = value;
|
||||
this.getCities(value);
|
||||
},
|
||||
get() {
|
||||
return this.address.selected.country;
|
||||
data() {
|
||||
return {
|
||||
value: this.address.loaded.countries.filter(c => c.countryCode === 'FR')[0]
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
init() {
|
||||
if (this.value !== undefined) {
|
||||
this.getCities(this.value);
|
||||
}
|
||||
},
|
||||
transName ({ name }) {
|
||||
return name.fr //TODO multilang
|
||||
},
|
||||
selectCountry(value) {
|
||||
console.log(value);
|
||||
this.address.selected.country = value;
|
||||
this.getCities(value);
|
||||
},
|
||||
},
|
||||
mounted(){
|
||||
this.init()
|
||||
},
|
||||
computed: {
|
||||
countries() {
|
||||
const countries = this.address.loaded.countries;
|
||||
let orderedCountries = [];
|
||||
orderedCountries.push(...countries.filter(c => c.countryCode === 'FR'))
|
||||
orderedCountries.push(...countries.filter(c => c.countryCode === 'BE'))
|
||||
orderedCountries.push(...countries.filter(c => c.countryCode !== 'FR').filter(c => c.countryCode !== 'BE'))
|
||||
return orderedCountries;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style src="vue-multiselect/dist/vue-multiselect.css"></style>
|
||||
|
@@ -0,0 +1,153 @@
|
||||
<template>
|
||||
|
||||
<a class="sc-button" target="_blank"
|
||||
:class="classAction"
|
||||
:title="$t(titleAction)"
|
||||
@click="openModal">
|
||||
{{ buttonText }}
|
||||
</a>
|
||||
|
||||
<teleport to="body">
|
||||
<modal v-if="modal.showModal"
|
||||
:modalDialogClass="modal.modalDialogClass"
|
||||
@close="modal.showModal = false">
|
||||
|
||||
<template v-slot:header>
|
||||
<h3 class="modal-title">{{ $t(titleModal) }}</h3>
|
||||
</template>
|
||||
|
||||
<template v-slot:body v-if="type === 'person'">
|
||||
<on-the-fly-person
|
||||
v-bind:id="id"
|
||||
v-bind:type="type"
|
||||
v-bind:action="action"
|
||||
ref="castPerson">
|
||||
</on-the-fly-person>
|
||||
</template>
|
||||
|
||||
<template v-slot:body v-else-if="type === 'thirdparty'">
|
||||
<on-the-fly-thirdparty
|
||||
v-bind:id="id"
|
||||
v-bind:type="type"
|
||||
v-bind:action="action"
|
||||
ref="castThirdparty">
|
||||
</on-the-fly-thirdparty>
|
||||
</template>
|
||||
|
||||
<template v-slot:body v-else>
|
||||
<on-the-fly-create
|
||||
v-bind:action="action"
|
||||
ref="castNew">
|
||||
</on-the-fly-create>
|
||||
</template>
|
||||
|
||||
<template v-slot:footer>
|
||||
<button v-if="action === 'show'"
|
||||
@click="changeActionTo('edit')"
|
||||
class="sc-button bt-update"> <!-- @click.prevent="$emit('..', ..)" -->
|
||||
</button>
|
||||
<button v-else
|
||||
class="sc-button bt-save"
|
||||
@click="saveAction"
|
||||
> <!--
|
||||
-->
|
||||
{{ $t('action.save')}}
|
||||
</button>
|
||||
</template>
|
||||
|
||||
</modal>
|
||||
</teleport>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Modal from 'ChillMainAssets/vuejs/_components/Modal.vue';
|
||||
import OnTheFlyPerson from 'ChillPersonAssets/vuejs/_components/OnTheFly/Person.vue';
|
||||
import OnTheFlyThirdparty from './OnTheFly/ThirdParty.vue';
|
||||
import OnTheFlyCreate from './OnTheFly/Create.vue';
|
||||
|
||||
export default {
|
||||
name: 'OnTheFly',
|
||||
components: {
|
||||
Modal,
|
||||
OnTheFlyPerson,
|
||||
OnTheFlyThirdparty,
|
||||
OnTheFlyCreate
|
||||
},
|
||||
props: ['type', 'id', 'action', 'buttonText'],
|
||||
data() {
|
||||
return {
|
||||
modal: {
|
||||
showModal: false,
|
||||
modalDialogClass: "modal-dialog-scrollable modal-xl"
|
||||
},
|
||||
action: this.action
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
action() {
|
||||
return this.$data.action;
|
||||
},
|
||||
classAction() {
|
||||
switch (this.action) {
|
||||
case 'show':
|
||||
return 'bt-show';
|
||||
case 'edit':
|
||||
return 'bt-update';
|
||||
case 'create':
|
||||
return 'bt-create';
|
||||
}
|
||||
},
|
||||
titleAction() {
|
||||
switch (this.action) {
|
||||
case 'show':
|
||||
return 'action.show';
|
||||
case 'edit':
|
||||
return 'action.edit';
|
||||
case 'create':
|
||||
return 'action.create';
|
||||
}
|
||||
},
|
||||
titleModal() {
|
||||
switch (this.action) {
|
||||
case 'show':
|
||||
return 'onthefly.show.' + this.type;
|
||||
case 'edit':
|
||||
return 'onthefly.edit.' + this.type;
|
||||
case 'create':
|
||||
return 'onthefly.create.title';
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
openModal() {
|
||||
this.modal.showModal = true;
|
||||
this.$nextTick(function() {
|
||||
//this.$refs.search.focus();
|
||||
})
|
||||
},
|
||||
changeActionTo(action) {
|
||||
// [BUG] clic first on show item button; in modal clic edit button; close modal; clic again on show item button
|
||||
this.$data.action = action;
|
||||
},
|
||||
saveAction() {
|
||||
console.log('saveAction');
|
||||
if (this.type === 'person') {
|
||||
this.$refs.castPerson.postData();
|
||||
} else if (this.type === 'thirdparty') {
|
||||
this.$refs.castThirdparty.postData();
|
||||
} else {
|
||||
// saveAction() ==cast=to==> child.castByType() ==cast=to==> grand-child.postData()
|
||||
this.$refs.castNew.castByType();
|
||||
}
|
||||
this.modal.showModal = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css" scoped>
|
||||
a {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
@@ -0,0 +1,84 @@
|
||||
<template>
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" :class="{ active: isActive('person') }">
|
||||
<label for="person">
|
||||
<input type="radio" name="person" v-model="radioType" value="person">
|
||||
{{ $t('onthefly.create.person') }}
|
||||
</label>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" :class="{ active: isActive('thirdparty') }">
|
||||
<label for="thirdparty">
|
||||
<input type="radio" name="thirdparty" v-model="radioType" value="thirdparty">
|
||||
{{ $t('onthefly.create.thirdparty') }}
|
||||
</label>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="my-4">
|
||||
<on-the-fly-person
|
||||
v-if="type === 'person'"
|
||||
v-bind:action="action"
|
||||
ref="castPerson">
|
||||
</on-the-fly-person>
|
||||
|
||||
<on-the-fly-thirdparty
|
||||
v-if="type === 'thirdparty'"
|
||||
v-bind:action="action"
|
||||
ref="castThirdparty">
|
||||
</on-the-fly-thirdparty>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import OnTheFlyPerson from 'ChillPersonAssets/vuejs/_components/OnTheFly/Person.vue';
|
||||
import OnTheFlyThirdparty from './ThirdParty.vue'; // TODO move in ChillThirdpartyAssets
|
||||
|
||||
export default {
|
||||
name: "OnTheFlyCreate",
|
||||
props: ['action'],
|
||||
components: {
|
||||
OnTheFlyPerson,
|
||||
OnTheFlyThirdparty
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
type: 'person' //by default
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
radioType: {
|
||||
set(type) {
|
||||
this.type = type;
|
||||
},
|
||||
get() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
isActive(tab) {
|
||||
return (this.type === tab) ? true : false;
|
||||
},
|
||||
castByType() {
|
||||
console.log('saveActionByType');
|
||||
if (this.type === 'person') {
|
||||
this.$refs.castPerson.postData();
|
||||
} else if (this.type === 'thirdparty') {
|
||||
this.$refs.castThirdparty.postData();
|
||||
} else {
|
||||
throw Error('Invalid type of entity');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css" scoped>
|
||||
label {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
@@ -0,0 +1,23 @@
|
||||
<template>
|
||||
<div v-if="action === 'show'">
|
||||
show
|
||||
thirdparty
|
||||
{{ id }}
|
||||
</div>
|
||||
<div v-else-if="action === 'edit' || action === 'create'">
|
||||
{{ action }}
|
||||
thirdparty
|
||||
{{ id }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "OnTheFlyThirdParty",
|
||||
props: ['id', 'type', 'action']
|
||||
}
|
||||
// TODO move in ChillThirdpartyAssets
|
||||
</script>
|
||||
|
||||
<style lang="css" scoped>
|
||||
</style>
|
@@ -46,6 +46,22 @@ const messages = {
|
||||
previous: "Précédent",
|
||||
top: "Haut",
|
||||
bottom: "Bas",
|
||||
},
|
||||
onthefly: {
|
||||
show: {
|
||||
person: "Détails de l'usager",
|
||||
thirdparty: "Détails du tiers"
|
||||
},
|
||||
edit: {
|
||||
person: "Modifier un usager",
|
||||
thirdparty: "Modifier un tiers"
|
||||
},
|
||||
create: {
|
||||
button: "Créer \"{q}\"",
|
||||
title: "Créer à la volée…",
|
||||
person: "un nouvel usager",
|
||||
thirdparty: "un nouveau tiers"
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -0,0 +1,7 @@
|
||||
<div class="timeline">
|
||||
{% for result in results %}
|
||||
<div class="timeline-item {% if loop.index0 is even %}even{% else %}odd{% endif %}">
|
||||
{% include result.template with result.template_data %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
@@ -1,7 +1,15 @@
|
||||
<div class="timeline">
|
||||
{% for result in results %}
|
||||
<div class="timeline-item {% if loop.index0 is even %}even{% else %}odd{% endif %}">
|
||||
{% include result.template with result.template_data %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% extends "@ChillMain/layout.html.twig" %}
|
||||
|
||||
{% block content %}
|
||||
<div id="container content">
|
||||
<div class="grid-8 centered">
|
||||
<h1>{{ 'Global timeline'|trans }}</h1>
|
||||
|
||||
{{ timeline|raw }}
|
||||
|
||||
{% if nb_items > paginator.getItemsPerPage %}
|
||||
{{ chill_pagination(paginator) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
@@ -68,6 +68,14 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface
|
||||
'icons' => ['home'],
|
||||
'order' => 0
|
||||
]);
|
||||
|
||||
$menu->addChild($this->translator->trans('Global timeline'), [
|
||||
'route' => 'chill_center_timeline',
|
||||
])
|
||||
->setExtras([
|
||||
'order' => 10
|
||||
]
|
||||
);
|
||||
|
||||
if ($this->authorizationChecker->isGranted(ChillExportVoter::EXPORT)) {
|
||||
$menu->addChild($this->translator->trans('Export Menu'), [
|
||||
|
@@ -110,8 +110,6 @@ class AuthorizationHelper
|
||||
return false;
|
||||
}
|
||||
|
||||
$role = ($attribute instanceof Role) ? $attribute : new Role($attribute);
|
||||
|
||||
foreach ($user->getGroupCenters() as $groupCenter){
|
||||
//filter on center
|
||||
if ($groupCenter->getCenter()->getId() === $entity->getCenter()->getId()) {
|
||||
@@ -119,8 +117,7 @@ class AuthorizationHelper
|
||||
//iterate on roleScopes
|
||||
foreach($permissionGroup->getRoleScopes() as $roleScope) {
|
||||
//check that the role allow to reach the required role
|
||||
if ($this->isRoleReached($role,
|
||||
new Role($roleScope->getRole()))){
|
||||
if ($this->isRoleReached($attribute, $roleScope->getRole())) {
|
||||
//if yes, we have a right on something...
|
||||
// perform check on scope if necessary
|
||||
if ($entity instanceof HasScopeInterface) {
|
||||
@@ -149,12 +146,15 @@ class AuthorizationHelper
|
||||
* and optionnaly Scope
|
||||
*
|
||||
* @param User $user
|
||||
* @param Role $role
|
||||
* @param string|Role $role
|
||||
* @param null|Scope $scope
|
||||
* @return Center[]
|
||||
*/
|
||||
public function getReachableCenters(User $user, Role $role, Scope $scope = null)
|
||||
public function getReachableCenters(User $user, $role, Scope $scope = null)
|
||||
{
|
||||
if ($role instanceof Role) {
|
||||
$role = $role->getRole();
|
||||
}
|
||||
$centers = array();
|
||||
|
||||
foreach ($user->getGroupCenters() as $groupCenter){
|
||||
@@ -162,8 +162,7 @@ class AuthorizationHelper
|
||||
//iterate on roleScopes
|
||||
foreach($permissionGroup->getRoleScopes() as $roleScope) {
|
||||
//check that the role is in the reachable roles
|
||||
if ($this->isRoleReached($role,
|
||||
new Role($roleScope->getRole()))) {
|
||||
if ($this->isRoleReached($role, $roleScope->getRole())) {
|
||||
if ($scope === null) {
|
||||
$centers[] = $groupCenter->getCenter();
|
||||
break 1;
|
||||
@@ -180,6 +179,30 @@ class AuthorizationHelper
|
||||
|
||||
return $centers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter an array of centers, return only center which are reachable
|
||||
*
|
||||
* @param User $user The user
|
||||
* @param array $centers a list of centers which are going to be filtered
|
||||
* @param string|Center $role
|
||||
*/
|
||||
public function filterReachableCenters(User $user, array $centers, $role): array
|
||||
{
|
||||
$results = [];
|
||||
|
||||
if ($role instanceof Role) {
|
||||
$role = $role->getRole();
|
||||
}
|
||||
|
||||
foreach ($centers as $center) {
|
||||
if ($this->userCanReachCenter($user, $center, $role)) {
|
||||
$results[] = $center;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all reachable scope for a given user, center and role
|
||||
@@ -191,8 +214,12 @@ class AuthorizationHelper
|
||||
* @param Center $center
|
||||
* @return Scope[]
|
||||
*/
|
||||
public function getReachableScopes(User $user, Role $role, Center $center)
|
||||
public function getReachableScopes(User $user, $role, Center $center)
|
||||
{
|
||||
if ($role instanceof Role) {
|
||||
$role = $role->getRole();
|
||||
}
|
||||
|
||||
return $this->getReachableCircles($user, $role, $center);
|
||||
}
|
||||
|
||||
@@ -200,12 +227,15 @@ class AuthorizationHelper
|
||||
* Return all reachable circle for a given user, center and role
|
||||
*
|
||||
* @param User $user
|
||||
* @param Role $role
|
||||
* @param string|Role $role
|
||||
* @param Center $center
|
||||
* @return Scope[]
|
||||
*/
|
||||
public function getReachableCircles(User $user, Role $role, Center $center)
|
||||
public function getReachableCircles(User $user, $role, Center $center)
|
||||
{
|
||||
if ($role instanceof Role) {
|
||||
$role = $role->getRole();
|
||||
}
|
||||
$scopes = array();
|
||||
|
||||
foreach ($user->getGroupCenters() as $groupCenter){
|
||||
@@ -215,9 +245,7 @@ class AuthorizationHelper
|
||||
//iterate on roleScopes
|
||||
foreach($permissionGroup->getRoleScopes() as $roleScope) {
|
||||
//check that the role is in the reachable roles
|
||||
if ($this->isRoleReached($role,
|
||||
new Role($roleScope->getRole()))) {
|
||||
|
||||
if ($this->isRoleReached($role, $roleScope->getRole())) {
|
||||
$scopes[] = $roleScope->getScope();
|
||||
}
|
||||
}
|
||||
@@ -269,10 +297,10 @@ class AuthorizationHelper
|
||||
* @param Role $parentRole The role which should give access to $childRole
|
||||
* @return boolean true if the child role is granted by parent role
|
||||
*/
|
||||
protected function isRoleReached(Role $childRole, Role $parentRole)
|
||||
protected function isRoleReached($childRole, $parentRole)
|
||||
{
|
||||
$reachableRoles = $this->roleHierarchy
|
||||
->getReachableRoles([$parentRole]);
|
||||
->getReachableRoleNames([$parentRole]);
|
||||
|
||||
return in_array($childRole, $reachableRoles);
|
||||
}
|
||||
|
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Serializer\Normalizer;
|
||||
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||
|
||||
use Chill\MainBundle\Doctrine\Model\Point;
|
||||
|
||||
|
||||
class PointNormalizer implements DenormalizerInterface
|
||||
{
|
||||
|
||||
public function supportsDenormalization($data, string $type, string $format = null) : bool
|
||||
{
|
||||
return $type === Point::class;
|
||||
}
|
||||
|
||||
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||
{
|
||||
|
||||
if (!is_array($data)) {
|
||||
throw new InvalidArgumentException('point data is not an array. It should be an array of 2 coordinates.');
|
||||
} else {
|
||||
if (count($data) !== 2) {
|
||||
throw new InvalidArgumentException('point data is not an array of 2 elements. It should be an array of 2 coordinates.');
|
||||
} else {
|
||||
return Point::fromLonLat($data[0], $data[1]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -23,11 +23,11 @@ use Doctrine\ORM\Query\ResultSetMapping;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\NativeQuery;
|
||||
|
||||
/**
|
||||
* Build timeline
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class TimelineBuilder implements ContainerAwareInterface
|
||||
{
|
||||
@@ -78,14 +78,14 @@ class TimelineBuilder implements ContainerAwareInterface
|
||||
*/
|
||||
public function getTimelineHTML($context, array $args, $firstItem = 0, $number = 20)
|
||||
{
|
||||
$union = $this->buildUnionQuery($context, $args);
|
||||
list($union, $parameters) = $this->buildUnionQuery($context, $args);
|
||||
|
||||
//add ORDER BY clause and LIMIT
|
||||
$query = $union . sprintf(' ORDER BY date DESC LIMIT %d OFFSET %d',
|
||||
$number, $firstItem);
|
||||
|
||||
// run query and handle results
|
||||
$fetched = $this->runUnionQuery($query);
|
||||
$fetched = $this->runUnionQuery($query, $parameters);
|
||||
$entitiesByKey = $this->getEntities($fetched, $context);
|
||||
|
||||
return $this->render($fetched, $entitiesByKey, $context, $args);
|
||||
@@ -100,16 +100,18 @@ class TimelineBuilder implements ContainerAwareInterface
|
||||
*/
|
||||
public function countItems($context, array $args)
|
||||
{
|
||||
$union = $this->buildUnionQuery($context, $args);
|
||||
|
||||
// embed the union query inside a count query
|
||||
$count = sprintf('SELECT COUNT(sq.id) AS total FROM (%s) as sq', $union);
|
||||
|
||||
$rsm = (new ResultSetMapping())
|
||||
->addScalarResult('total', 'total', Type::INTEGER);
|
||||
|
||||
list($select, $parameters) = $this->buildUnionQuery($context, $args);
|
||||
|
||||
// embed the union query inside a count query
|
||||
$countQuery = sprintf('SELECT COUNT(sq.id) AS total FROM (%s) as sq', $select);
|
||||
|
||||
$nq = $this->em->createNativeQuery($countQuery, $rsm);
|
||||
$nq->setParameters($parameters);
|
||||
|
||||
return $this->em->createNativeQuery($count, $rsm)
|
||||
->getSingleScalarResult();
|
||||
return $nq->getSingleScalarResult();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,40 +156,59 @@ class TimelineBuilder implements ContainerAwareInterface
|
||||
*
|
||||
* @uses self::buildSelectQuery to build individual SELECT queries
|
||||
*
|
||||
* @param string $context
|
||||
* @param mixed $args
|
||||
* @param int $page
|
||||
* @param int $number
|
||||
* @return string
|
||||
* @throws \LogicException if no builder have been defined for this context
|
||||
* @return array, where first element is the query, the second one an array with the parameters
|
||||
*/
|
||||
private function buildUnionQuery($context, array $args)
|
||||
private function buildUnionQuery(string $context, array $args): array
|
||||
{
|
||||
//append SELECT queries with UNION keyword between them
|
||||
$union = '';
|
||||
$parameters = [];
|
||||
|
||||
foreach($this->getProvidersByContext($context) as $provider) {
|
||||
$select = $this->buildSelectQuery($provider, $context, $args);
|
||||
$append = ($union === '') ? $select : ' UNION '.$select;
|
||||
$data = $provider->fetchQuery($context, $args);
|
||||
list($select, $selectParameters) = $this->buildSelectQuery($data);
|
||||
$append = empty($union) ? $select : ' UNION '.$select;
|
||||
$union .= $append;
|
||||
$parameters = array_merge($parameters, $selectParameters);
|
||||
}
|
||||
|
||||
return $union;
|
||||
return [$union, $parameters];
|
||||
}
|
||||
|
||||
/**
|
||||
* Hack to replace the arbitrary "AS" statement in DQL
|
||||
* into proper SQL query
|
||||
* TODO remove
|
||||
private function replaceASInDQL(string $dql): string
|
||||
{
|
||||
$pattern = '/^(SELECT\s+[a-zA-Z0-9\_\.\']{1,}\s+)(AS [a-z0-9\_]{1,})(\s{0,},\s{0,}[a-zA-Z0-9\_\.\']{1,}\s+)(AS [a-z0-9\_]{1,})(\s{0,},\s{0,}[a-zA-Z0-9\_\.\']{1,}\s+)(AS [a-z0-9\_]{1,})(\s+FROM.*)/';
|
||||
$replacements = '${1} AS id ${3} AS type ${5} AS date ${7}';
|
||||
|
||||
$s = \preg_replace($pattern, $replacements, $dql, 1);
|
||||
|
||||
if (NULL === $s) {
|
||||
throw new \RuntimeException('Could not replace the "AS" statement produced by '.
|
||||
'DQL with normal SQL AS: '.$dql);
|
||||
}
|
||||
|
||||
return $s;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* return the SQL SELECT query as a string,
|
||||
*
|
||||
* @uses TimelineProfiderInterface::fetchQuery use the fetchQuery function
|
||||
* @param \Chill\MainBundle\Timeline\TimelineProviderInterface $provider
|
||||
* @param string $context
|
||||
* @param mixed[] $args
|
||||
* @return string
|
||||
* @return array: first parameter is the sql string, second an array with parameters
|
||||
*/
|
||||
private function buildSelectQuery(TimelineProviderInterface $provider, $context, array $args)
|
||||
private function buildSelectQuery($data): array
|
||||
{
|
||||
$data = $provider->fetchQuery($context, $args);
|
||||
|
||||
return sprintf(
|
||||
return [$data->buildSql(), $data->getParameters()];
|
||||
|
||||
// dead code
|
||||
$parameters = [];
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT %s AS id, '
|
||||
. '%s AS "date", '
|
||||
. "'%s' AS type "
|
||||
@@ -197,16 +218,19 @@ class TimelineBuilder implements ContainerAwareInterface
|
||||
$data['date'],
|
||||
$data['type'],
|
||||
$data['FROM'],
|
||||
$data['WHERE']);
|
||||
is_string($data['WHERE']) ? $data['WHERE'] : $data['WHERE'][0]
|
||||
);
|
||||
|
||||
return [$sql, $data['WHERE'][1]];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* run the UNION query and return result as an array
|
||||
*
|
||||
* @param string $query
|
||||
* @return array
|
||||
* @return array an array with the results
|
||||
*/
|
||||
private function runUnionQuery($query)
|
||||
private function runUnionQuery(string $query, array $parameters): array
|
||||
{
|
||||
$resultSetMapping = (new ResultSetMapping())
|
||||
->addScalarResult('id', 'id')
|
||||
@@ -214,7 +238,8 @@ class TimelineBuilder implements ContainerAwareInterface
|
||||
->addScalarResult('date', 'date');
|
||||
|
||||
return $this->em->createNativeQuery($query, $resultSetMapping)
|
||||
->getArrayResult();
|
||||
->setParameters($parameters)
|
||||
->getArrayResult();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,7 +299,7 @@ class TimelineBuilder implements ContainerAwareInterface
|
||||
}
|
||||
|
||||
return $this->container->get('templating')
|
||||
->render('@ChillMain/Timeline/index.html.twig', array(
|
||||
->render('@ChillMain/Timeline/chain_timelines.html.twig', array(
|
||||
'results' => $timelineEntries
|
||||
));
|
||||
|
||||
|
155
src/Bundle/ChillMainBundle/Timeline/TimelineSingleQuery.php
Normal file
155
src/Bundle/ChillMainBundle/Timeline/TimelineSingleQuery.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Timeline;
|
||||
|
||||
|
||||
class TimelineSingleQuery
|
||||
{
|
||||
private ?string $id;
|
||||
|
||||
private ?string $date;
|
||||
|
||||
private ?string $key;
|
||||
|
||||
private ?string $from;
|
||||
|
||||
private ?string $where;
|
||||
|
||||
private array $parameters = [];
|
||||
|
||||
private bool $distinct = false;
|
||||
|
||||
public function __construct(
|
||||
string $id = null,
|
||||
string $date = null,
|
||||
string $key = null,
|
||||
string $from = null,
|
||||
string $where = null,
|
||||
array $parameters = []
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->date = $date;
|
||||
$this->key = $key;
|
||||
$this->from = $from;
|
||||
$this->where = $where;
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
public static function fromArray(array $a)
|
||||
{
|
||||
return new TimelineSingleQuery(
|
||||
$a['id'] ?? null,
|
||||
$a['date'] ?? null,
|
||||
$a['type'] ?? $a['key'] ?? null,
|
||||
$a['FROM'] ?? $a['from'] ?? null,
|
||||
$a['WHERE'] ?? $a['where'] ?? null,
|
||||
$a['parameters'] ?? null);
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(string $id): self
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDate(): string
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function setDate(string $date): self
|
||||
{
|
||||
$this->date = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getKey(): string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
public function setKey(string $key): self
|
||||
{
|
||||
$this->key = $key;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFrom(): string
|
||||
{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
public function setFrom(string $from): self
|
||||
{
|
||||
$this->from = $from;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWhere(): string
|
||||
{
|
||||
return $this->where;
|
||||
}
|
||||
|
||||
public function setWhere(string $where): self
|
||||
{
|
||||
$this->where = $where;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getParameters(): array
|
||||
{
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
public function setParameters(array $parameters): self
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setDistinct(bool $distinct): self
|
||||
{
|
||||
$this->distinct = $distinct;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isDistinct(): bool
|
||||
{
|
||||
return $this->distinct;
|
||||
}
|
||||
|
||||
public function buildSql(): string
|
||||
{
|
||||
$parameters = [];
|
||||
|
||||
$sql = \strtr(
|
||||
'SELECT {distinct} {id} AS id, '
|
||||
. '{date} AS "date", '
|
||||
. "'{key}' AS type "
|
||||
. 'FROM {from} '
|
||||
. 'WHERE {where}',
|
||||
[
|
||||
'{distinct}' => $this->distinct ? 'DISTINCT' : '',
|
||||
'{id}' => $this->getId(),
|
||||
'{date}' => $this->getDate(),
|
||||
'{key}' => $this->getKey(),
|
||||
'{from}' => $this->getFrom(),
|
||||
'{where}' => $this->getWhere(),
|
||||
]
|
||||
);
|
||||
|
||||
return $sql;
|
||||
}
|
||||
}
|
@@ -1,3 +1,7 @@
|
||||
chill_main_controllers:
|
||||
resource: '../Controller/'
|
||||
type: annotation
|
||||
|
||||
chill_main_admin_permissionsgroup:
|
||||
resource: "@ChillMainBundle/config/routes/permissionsgroup.yaml"
|
||||
prefix: "{_locale}/admin/permissionsgroup"
|
||||
|
@@ -31,14 +31,14 @@ services:
|
||||
- [ setContainer, ["@service_container"]]
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
|
||||
|
||||
chill.main.twig.widget:
|
||||
class: Chill\MainBundle\Templating\Widget\WidgetRenderingTwig
|
||||
arguments:
|
||||
- "@event_dispatcher"
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
|
||||
|
||||
chill.main.twig.csv_cell:
|
||||
class: Chill\MainBundle\Templating\CSVCellTwig
|
||||
tags:
|
||||
@@ -65,3 +65,4 @@ services:
|
||||
- "@security.authorization_checker"
|
||||
- "@chill.main.security.authorization.helper"
|
||||
- "@security.token_storage"
|
||||
|
||||
|
@@ -7,7 +7,7 @@ services:
|
||||
$validator: '@Symfony\Component\Validator\Validator\ValidatorInterface'
|
||||
tags:
|
||||
- { name: console.command }
|
||||
|
||||
|
||||
Chill\MainBundle\Command\ChillUserSendRenewPasswordCodeCommand:
|
||||
arguments:
|
||||
$logger: '@Psr\Log\LoggerInterface'
|
||||
|
@@ -1,7 +1,7 @@
|
||||
---
|
||||
services:
|
||||
|
||||
# note: the autowiring for serializers and normalizers is declared
|
||||
|
||||
# note: the autowiring for serializers and normalizers is declared
|
||||
# into ../services.yaml
|
||||
|
||||
Chill\MainBundle\Serializer\Normalizer\DoctrineExistingEntityNormalizer:
|
||||
|
@@ -4,4 +4,7 @@ services:
|
||||
arguments:
|
||||
- "@doctrine.orm.entity_manager"
|
||||
calls:
|
||||
- [ setContainer, ["@service_container"]]
|
||||
- [ setContainer, ["@service_container"]]
|
||||
# alias:
|
||||
Chill\MainBundle\Timeline\TimelineBuilder: '@chill_main.timeline_builder'
|
||||
|
||||
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Add extension btree_gist
|
||||
*/
|
||||
final class Version20210528090000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'add extension btree_gist';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('CREATE EXTENSION IF NOT EXISTS btree_gist');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP EXTENSION btree_gist');
|
||||
}
|
||||
}
|
@@ -46,6 +46,11 @@ Back to the list: Retour à la liste
|
||||
#interval
|
||||
Years: Années
|
||||
|
||||
# misc date
|
||||
Since %date%: Depuis le %date%
|
||||
since %date%: depuis le %date%
|
||||
Until %date%: Jusqu'au %date%
|
||||
until %date%: jusqu'au %date%
|
||||
#elements used in software
|
||||
centers: centres
|
||||
Centers: Centres
|
||||
@@ -81,6 +86,9 @@ Results %start%-%end% of %total%: Résultats %start%-%end% sur %total%
|
||||
See all results: Voir tous les résultats
|
||||
Advanced search: Recherche avancée
|
||||
|
||||
# timeline
|
||||
Global timeline: Historique global
|
||||
|
||||
#admin
|
||||
Create: Créer
|
||||
show: voir
|
||||
|
Reference in New Issue
Block a user