Commit 1c42bc23 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #14753 TIME 2:45 show sector name after selecting address + cannot set...

FEAT #14753 TIME 2:45 show sector name after selecting address + cannot set sector mandatory in parameters
parent aec3fc81
......@@ -148,6 +148,7 @@ $app->put('/watermark/configuration', \Configuration\controllers\ConfigurationCo
//Contacts
$app->get('/contacts', \Contact\controllers\ContactController::class . ':get');
$app->post('/contacts', \Contact\controllers\ContactController::class . ':create');
$app->get('/contacts/sector', \Contact\controllers\ContactController::class . ':getSectorFromAddress');
$app->get('/contacts/{id}', \Contact\controllers\ContactController::class . ':getById');
$app->put('/contacts/export', \Contact\controllers\ContactController::class . ':exportContacts');
$app->put('/contacts/import', \Contact\controllers\ContactController::class . ':importContacts');
......
......@@ -1398,6 +1398,27 @@ class ContactController
return $response->withJson($return);
}
public function getSectorFromAddress(Request $request, Response $response)
{
$queryParams = $request->getQueryParams();
if (empty($queryParams)) {
return $response->withStatus(400)->withJson(['errors' => 'Query is not set or empty']);
} elseif (!empty($queryParams['addressNumber']) && !Validator::stringType()->validate($queryParams['addressNumber'])) {
return $response->withStatus(400)->withJson(['errors' => 'Query addressNumber is not a string']);
} elseif (!empty($queryParams['addressStreet']) && !Validator::stringType()->notEmpty()->validate($queryParams['addressStreet'])) {
return $response->withStatus(400)->withJson(['errors' => 'Query addressStreet is not a string']);
} elseif (!empty($queryParams['addressPostcode']) && !Validator::stringType()->notEmpty()->validate($queryParams['addressPostcode'])) {
return $response->withStatus(400)->withJson(['errors' => 'Query addressPostcode is not a string']);
} elseif (!empty($queryParams['addressTown']) && !Validator::stringType()->notEmpty()->validate($queryParams['addressTown'])) {
return $response->withStatus(400)->withJson(['errors' => 'Query addressTown is not a string']);
}
$sector = ContactController::getAddressSector($queryParams);
return $response->withJson(['sector' => $sector]);
}
public static function getParsedContacts(array $args)
{
ValidatorModel::notEmpty($args, ['resId', 'mode']);
......@@ -1455,7 +1476,8 @@ class ContactController
'creationDate' => $contactRaw['creation_date'],
'modificationDate' => $contactRaw['modification_date'],
'customFields' => !empty($contactRaw['custom_fields']) ? json_decode($contactRaw['custom_fields'], true) : null,
'externalId' => json_decode($contactRaw['external_id'], true)
'externalId' => json_decode($contactRaw['external_id'], true),
'sector' => $contactRaw['sector']
];
if (!empty($contactRaw['communication_means'])) {
......
......@@ -812,6 +812,15 @@ export class ContactsFormComponent implements OnInit {
}
});
this.checkFilling();
this.http.get('../rest/contacts/sector', {params: {'addressNumber': contact['addressNumber'], 'addressStreet': contact['addressStreet'], 'addressPostcode': contact['addressPostcode'], 'addressTown': contact['addressTown']}}).pipe(
tap((data: any) => {
if (data.sector !== null) {
const sectorIndex = this.contactForm.findIndex(element => element.id === 'sector');
this.contactForm[sectorIndex].control.setValue(data.sector.label);
this.contactForm[sectorIndex].display = true;
}
}),
).subscribe();
this.addressBANMode = disableBan ? false : true;
}
......
......@@ -136,7 +136,7 @@
</mat-header-cell>
<mat-cell *matCellDef="let element">
<mat-slide-toggle style="margin-left:11px" color="primary"
[disabled]="element.identifier == 'lastname' || element.identifier == 'company'"
[disabled]="element.identifier == 'lastname' || element.identifier == 'company' || element.identifier == 'sector'"
title="{{'lang.mandatory' | translate}}"
(change)="addCriteria($event, element, 'mandatory')" [checked]="element.mandatory">
</mat-slide-toggle>
......@@ -186,4 +186,4 @@
</div>
</div>
</mat-sidenav-content>
</mat-sidenav-container>
\ No newline at end of file
</mat-sidenav-container>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment