mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
implements max holder and validation on UI
This commit is contained in:
parent
af740fd87d
commit
807d3674fc
@ -50,8 +50,12 @@ class HouseholdMemberController extends ApiController
|
|||||||
|
|
||||||
// TODO ACL
|
// TODO ACL
|
||||||
//
|
//
|
||||||
// TODO validation
|
$errors = $editor->validate();
|
||||||
//
|
|
||||||
|
if (count($errors) > 0) {
|
||||||
|
return $this->json($errors, 422);
|
||||||
|
}
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
// if new household, persist it
|
// if new household, persist it
|
||||||
|
@ -19,7 +19,7 @@ use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder;
|
|||||||
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
|
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
|
||||||
* "household"=Household::class
|
* "household"=Household::class
|
||||||
* })
|
* })
|
||||||
* @MasHolder()
|
* @MaxHolder(groups={"memberships"})
|
||||||
*/
|
*/
|
||||||
class Household
|
class Household
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@ class MembersEditor
|
|||||||
|
|
||||||
public function __construct(ValidatorInterface $validator, ?Household $household)
|
public function __construct(ValidatorInterface $validator, ?Household $household)
|
||||||
{
|
{
|
||||||
$this->validation = $validator;
|
$this->validator = $validator;
|
||||||
$this->household = $household;
|
$this->household = $household;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ class MembersEditor
|
|||||||
|
|
||||||
public function validate(): ConstraintViolationListInterface
|
public function validate(): ConstraintViolationListInterface
|
||||||
{
|
{
|
||||||
|
return $this->validator->validate($this->getHousehold(), null, [ "memberships" ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPersistable(): array
|
public function getPersistable(): array
|
||||||
@ -100,6 +100,7 @@ class MembersEditor
|
|||||||
return $this->persistables;
|
return $this->persistables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getHousehold(): ?Household
|
public function getHousehold(): ?Household
|
||||||
{
|
{
|
||||||
return $this->household;
|
return $this->household;
|
||||||
|
@ -16,32 +16,13 @@ const householdMove = (payload) => {
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
throw Error('Error with testing move');
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const householdMoveTest = (payload) => {
|
|
||||||
const url = `/api/1.0/person/household/members/move/test.json`;
|
|
||||||
return fetch(url, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(payload),
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.status === 422) {
|
if (response.status === 422) {
|
||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
if (response.ok) {
|
|
||||||
// return an empty array if ok
|
|
||||||
return new Promise((resolve, reject) => resolve({ violations: [] }) );
|
|
||||||
}
|
|
||||||
throw Error('Error with testing move');
|
throw Error('Error with testing move');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
householdMove,
|
householdMove,
|
||||||
householdMoveTest
|
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
<li v-for="(msg, index) in warnings">
|
<li v-for="(msg, index) in warnings">
|
||||||
{{ $t(msg.m, msg.a) }}
|
{{ $t(msg.m, msg.a) }}
|
||||||
</li>
|
</li>
|
||||||
|
<li v-for="msg in errors">
|
||||||
|
{{ msg }}
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<ul class="record_actions sticky-form-buttons">
|
<ul class="record_actions sticky-form-buttons">
|
||||||
@ -34,8 +37,9 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
warnings: (state) => state.warnings,
|
warnings: (state) => state.warnings,
|
||||||
hasNoWarnings: (state) => state.warnings.length === 0,
|
errors: (state) => state.errors,
|
||||||
hasWarnings: (state) => state.warnings.length > 0,
|
hasNoWarnings: (state) => state.warnings.length === 0 && state.errors.length === 0,
|
||||||
|
hasWarnings: (state) => state.warnings.length > 0 || state.errors.length > 0,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -26,6 +26,7 @@ const store = createStore({
|
|||||||
allowLeaveWithoutHousehold: window.household_members_editor_data.allowLeaveWithoutHousehold,
|
allowLeaveWithoutHousehold: window.household_members_editor_data.allowLeaveWithoutHousehold,
|
||||||
forceLeaveWithoutHousehold: false,
|
forceLeaveWithoutHousehold: false,
|
||||||
warnings: [],
|
warnings: [],
|
||||||
|
errors: []
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
isHouseholdNew(state) {
|
isHouseholdNew(state) {
|
||||||
@ -162,6 +163,9 @@ const store = createStore({
|
|||||||
setWarnings(state, warnings) {
|
setWarnings(state, warnings) {
|
||||||
state.warnings = warnings;
|
state.warnings = warnings;
|
||||||
},
|
},
|
||||||
|
setErrors(state, errors) {
|
||||||
|
state.errors = errors;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
addConcerned({ commit, dispatch }, person) {
|
addConcerned({ commit, dispatch }, person) {
|
||||||
@ -216,19 +220,33 @@ const store = createStore({
|
|||||||
|
|
||||||
commit('setWarnings', warnings);
|
commit('setWarnings', warnings);
|
||||||
},
|
},
|
||||||
confirm({ getters, state }) {
|
confirm({ getters, state, commit }) {
|
||||||
let payload = getters.buildPayload,
|
let payload = getters.buildPayload,
|
||||||
|
errors = [],
|
||||||
person_id,
|
person_id,
|
||||||
household_id;
|
household_id,
|
||||||
householdMove(payload).then(household => {
|
error
|
||||||
if (household === null) {
|
;
|
||||||
person_id = getters.persons[0].id;
|
|
||||||
window.location.replace(`/fr/person/${person_id}/general`);
|
householdMove(payload).then(household => {
|
||||||
} else {
|
if (household === null) {
|
||||||
household_id = household.id;
|
person_id = getters.persons[0].id;
|
||||||
// nothing to do anymore here, bye-bye !
|
window.location.replace(`/fr/person/${person_id}/general`);
|
||||||
window.location.replace(`/fr/person/household/${household_id}/members`);
|
} else {
|
||||||
}
|
if (household.type === 'household') {
|
||||||
|
household_id = household.id;
|
||||||
|
// nothing to do anymore here, bye-bye !
|
||||||
|
window.location.replace(`/fr/person/household/${household_id}/members`);
|
||||||
|
} else {
|
||||||
|
// we assume the answer was 422...
|
||||||
|
error = household;
|
||||||
|
for (let e in error.violations) {
|
||||||
|
errors.push('TODO');
|
||||||
|
}
|
||||||
|
|
||||||
|
commit('setErrors', errors);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ class MaxHolder extends Constraint
|
|||||||
public $message = 'household.max_holder_overflowed';
|
public $message = 'household.max_holder_overflowed';
|
||||||
public $messageInfinity = 'household.max_holder_overflowed_infinity';
|
public $messageInfinity = 'household.max_holder_overflowed_infinity';
|
||||||
|
|
||||||
|
public function getTargets()
|
||||||
|
{
|
||||||
|
return self::CLASS_CONSTRAINT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class MaxHolderValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if ($covers->hasIntersections()) {
|
if ($covers->hasIntersections()) {
|
||||||
foreach ($covers->getIntersections() as list($start, $end, $ids)) {
|
foreach ($covers->getIntersections() as list($start, $end, $ids)) {
|
||||||
$msg = $end === null ? $constraint->messageEndInfinite :
|
$msg = $end === null ? $constraint->messageInfinity :
|
||||||
$constraint->message;
|
$constraint->message;
|
||||||
|
|
||||||
$this->context->buildViolation($msg)
|
$this->context->buildViolation($msg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user