Merge branch 'person_renderbox_thirdparty_onthefly' into post-prototypage

This commit is contained in:
2021-09-02 12:25:33 +02:00
15 changed files with 343 additions and 105 deletions

View File

@@ -8,6 +8,8 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter;
use Symfony\Component\HttpFoundation\Request;
/**
* This is the class that loads and manages your bundle configuration.
@@ -47,11 +49,42 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte
{
//declare routes for 3party bundle
$container->prependExtensionConfig('chill_main', array(
'routing' => array(
'routing' => [
'resources' => array(
'@ChillThirdPartyBundle/config/routes.yaml'
)
)
],
'apis' => [
[
'class' => \Chill\ThirdPartyBundle\Entity\ThirdParty::class,
'name' => 'thirdparty',
'base_path' => '/api/1.0/thirdparty/thirdparty',
'base_role' => \Chill\ThirdPartyBundle\Security\Authorization\ThirdPartyVoter::class,
'controller' => \Chill\ThirdPartyBundle\Controller\ThirdPartyApiController::class,
'actions' => [
'_index' => [
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true,
Request::METHOD_POST => true,
],
],
'_entity' => [
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true,
Request::METHOD_POST=> true,
],
'roles' => [
Request::METHOD_GET => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::SHOW,
Request::METHOD_HEAD => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::SHOW,
Request::METHOD_POST => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::CREATE,
],
]
]
]
],
));
}

View File

@@ -30,6 +30,7 @@ use Chill\MainBundle\Entity\Center;
use Symfony\Component\Validator\Constraints as Assert;
use Chill\MainBundle\Entity\Address;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* ThirdParty is a party recorded in the database.
@@ -59,6 +60,7 @@ class ThirdParty
* @var string
* @ORM\Column(name="name", type="string", length=255)
* @Assert\Length(min="2")
* @Groups({"read"})
*/
private $name;
@@ -128,6 +130,7 @@ class ThirdParty
* @Assert\Regex("/^([\+{1}])([0-9\s*]{4,20})$/",
* message="Invalid phone number: it should begin with the international prefix starting with ""+"", hold only digits and be smaller than 20 characters. Ex: +33123456789"
* )
* @Groups({"read"})
*/
private $telephone;
@@ -135,6 +138,7 @@ class ThirdParty
* @var string|null
* @ORM\Column(name="email", type="string", length=255, nullable=true)
* @Assert\Email(checkMX=false)
* @Groups({"read"})
*/
private $email;
@@ -143,6 +147,7 @@ class ThirdParty
* @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address",
* cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
* @Groups({"read"})
*/
private $address;

View File

@@ -0,0 +1,36 @@
/*
* GET a thirdparty by id
*/
const getThirdparty = (id) => {
const url = `/api/1.0/thirdparty/thirdparty/${id}.json`;
return fetch(url)
.then(response => {
if (response.ok) {
return response.json();
}
throw Error('Error with request resource response');
});
};
/*
* POST a new person
*/
const postThirdparty = (body) => {
const url = `/api/1.0/thirdparty/thirdparty.json`;
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 {
getThirdparty,
postThirdparty
};

View File

@@ -26,7 +26,7 @@
<time v-else-if="thirdparty.deathdate" datetime="{{ thirdparty.deathdate.datetime }}" title="{{ thirdparty.deathdate }}">
{{ birthdate }} - {{ deathdate }}
</time>
<span class="age">{{ thirdparty.age }}</span>
<span v-if="options.addAge == true" class="age">{{ thirdparty.age }}</span>
</p>
</div>
</div>
@@ -37,9 +37,9 @@
<i class="fa fa-li fa-map-marker"></i>
<show-address :address="thirdparty.address" :isMultiline="isMultiline"></show-address>
</li>
<li v-if="thirdparty.telephone">
<li v-if="thirdparty.phonenumber">
<i class="fa fa-li fa-mobile"></i>
<a :href="'tel: ' + thirdparty.telephone">{{ thirdparty.telephone }}</a>
<a :href="'tel: ' + thirdparty.phonenumber">{{ thirdparty.phonenumber }}</a>
</li>
<li v-if="thirdparty.email">
<i class="fa fa-li fa-envelope-o"></i>

View File

@@ -1,22 +1,109 @@
<template>
<div v-if="action === 'show'">
show
thirdparty
{{ id }}
<div v-if="action === 'show'">
<div class="flex-table">
<third-party-render-box
:thirdparty="thirdparty"
:options="{
addInfo: true,
addEntity: false,
addAltNames: true,
addId: true,
addLink: false,
addAge: false,
hLevel: 3,
addCenter: true,
addNoData: true,
isMultiline: true
}"
></third-party-render-box>
</div>
</div>
<div v-else-if="action === 'edit' || action === 'create'">
{{ action }}
thirdparty
{{ id }}
<div class="form-floating mb-3">
<input class="form-control form-control-lg" id="firstname" v-model="thirdparty.firstName" v-bind:placeholder="$t('thirdparty.firstname')" />
<label for="firstname">{{ $t('thirdparty.firstname') }}</label>
</div>
<div class="form-floating mb-3">
<input class="form-control form-control-lg" id="lastname" v-model="thirdparty.lastName" v-bind:placeholder="$t('thirdparty.lastname')" />
<label for="lastname">{{ $t('thirdparty.lastname') }}</label>
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="email"><i class="fa fa-fw fa-envelope"></i></span>
<input class="form-control form-control-lg"
v-model="thirdparty.email"
v-bind:placeholder="$t('thirdparty.email')"
v-bind:aria-label="$t('thirdparty.email')"
aria-describedby="email" />
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="phonenumber"><i class="fa fa-fw fa-phone"></i></span>
<input class="form-control form-control-lg"
v-model="thirdparty.phonenumber"
v-bind:placeholder="$t('thirdparty.phonenumber')"
v-bind:aria-label="$t('thirdparty.phonenumber')"
aria-describedby="phonenumber" />
</div>
</div>
</template>
<script>
import ThirdPartyRenderBox from '../Entity/ThirdPartyRenderBox.vue';
import { getThirdparty, postThirdparty } from '../../_api/OnTheFly';
export default {
name: "OnTheFlyThirdParty",
props: ['id', 'type', 'action']
props: ['id', 'type', 'action'],
components: {
ThirdPartyRenderBox,
},
data: function() {
return {
thirdparty: {
type: 'thirdparty'
}
}
},
methods: {
loadThirdparty(){
getThirdparty(this.id).then(thirdparty => new Promise((resolve, reject) => {
this.thirdparty = thirdparty;
resolve();
}));
},
postData() {
postThirdparty(this.thirdparty).then(thirdparty => new Promise((resolve, reject) => {
this.thirdparty = thirdparty;
resolve();
}))
}
},
mounted() {
if (this.action !== 'create'){
this.loadThirdparty();
}
},
}
</script>
<style lang="css" scoped>
<style lang="scss" scoped>
div.flex-table {
div.item-bloc {
div.item-row {
div.item-col:last-child {
justify-content: flex-start;
}
}
}
}
dl {
dd {
margin-left: 1em;
}
}
</style>

View File

@@ -21,6 +21,8 @@ class ThirdPartyNormalizer implements NormalizerInterface, NormalizerAwareInterf
$data['id'] = $thirdParty->getId();
$data['address'] = $this->normalizer->normalize($thirdParty->getAddress(), $format,
[ 'address_rendering' => 'short' ]);
$data['phonenumber'] = $thirdParty->getTelephone();
$data['email'] = $thirdParty->getEmail();
return $data;
}

View File

@@ -0,0 +1,43 @@
---
openapi: "3.0.0"
info:
version: "1.0.0"
title: "Chill api"
description: "Api documentation for chill. Currently, work in progress"
servers:
- url: "/api"
description: "Your current dev server"
paths:
/1.0/thirdparty/thirdparty.json:
get:
tags:
- thirdparty
summary: Return a list of all thirdparty items
responses:
200:
description: "ok"
401:
description: "Unauthorized"
/1.0/thirdparty/thirdparty/{id}.json:
get:
tags:
- thirdparty
summary: Return a thirdparty item by id
parameters:
- name: id
in: path
required: true
description: The thirdparty id
schema:
type: integer
format: integer
minimum: 1
responses:
200:
description: "ok"
404:
description: "not found"
401:
description: "Unauthorized"