diff --git a/client/src/app/instance/search/components/result/datatable.component.html b/client/src/app/instance/search/components/result/datatable.component.html index 4131652d211c37324f2770d1033808cc6fdece22..8946eff496a0d143347a1cbb61095d6ab2e7c935 100644 --- a/client/src/app/instance/search/components/result/datatable.component.html +++ b/client/src/app/instance/search/components/result/datatable.component.html @@ -41,7 +41,7 @@ </button> </td> <td *ngFor="let attribute of getOutputList()" class="align-middle"> - <div *ngIf="datum[attribute.label]" [ngSwitch]="attribute.renderer"> + <div *ngIf="datum[attribute.label] != null" [ngSwitch]="attribute.renderer"> <div *ngSwitchCase="'detail-link'"> <app-detail-link-renderer [value]="datum[attribute.label]" diff --git a/client/src/app/instance/store/effects/archive.effects.ts b/client/src/app/instance/store/effects/archive.effects.ts index 4ce9973e4d576eff539f20f95567d4a6e3e53076..e255fa785b274f23a6b75d0bdc6a1fecb08af68b 100644 --- a/client/src/app/instance/store/effects/archive.effects.ts +++ b/client/src/app/instance/store/effects/archive.effects.ts @@ -107,7 +107,11 @@ export class ArchiveEffects { resetArchive$ = createEffect(() => this.actions$.pipe( ofType(archiveActions.resetArchive), - tap(() => this.kill$.unsubscribe()) + tap(() => { + if (this.kill$) { + this.kill$.unsubscribe(); + } + }) ), { dispatch: false} ); diff --git a/conf-dev/dev-php.ini b/conf-dev/dev-php.ini index df289dd8b59301ac4f8ad6f4147b2a102e3e4a41..86af78a1e09755c5c876bad4b66b43014ac69490 100644 --- a/conf-dev/dev-php.ini +++ b/conf-dev/dev-php.ini @@ -13,7 +13,8 @@ max_input_time = 60 [xdebug] zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20210902/xdebug.so -xdebug.mode=debug +xdebug.default_enable=1 +xdebug.mode=develop,debug xdebug.client_host=127.0.0.1 xdebug.client_port="9003" diff --git a/server/src/Search/Response/JsonResponse.php b/server/src/Search/Response/JsonResponse.php index 0ee5c449473d523b7f9aba02c559d2f8f15dea44..97d8789ce280384657232ec5a2b0b0430dc9ca7e 100644 --- a/server/src/Search/Response/JsonResponse.php +++ b/server/src/Search/Response/JsonResponse.php @@ -32,14 +32,15 @@ class JsonResponse implements IResponse */ public function getResponse(ResponseInterface $response, AnisQueryBuilder $anisQueryBuilder): ResponseInterface { - $stmt = $anisQueryBuilder->getDoctrineQueryBuilder()->execute(); + $stmt = $anisQueryBuilder->getDoctrineQueryBuilder()->executeQuery(); $attributes = $anisQueryBuilder->getAttributesSelected(); - $payload = json_encode($this->decodeNestedJson($stmt, $attributes), JSON_UNESCAPED_SLASHES); + $payload = json_encode($this->processesTypes($stmt, $attributes), JSON_UNESCAPED_SLASHES); $response->getBody()->write($payload); return $response; } /** + * Process types like float * Decode each nsted json result and returns array results * * @param Result $stmt The doctrine statement of the query request @@ -47,34 +48,21 @@ class JsonResponse implements IResponse * * @return array */ - private function decodeNestedJson(Result $stmt, array $attributes): array + private function processesTypes(Result $stmt, array $attributes): array { $rows = array(); - $jsonAttributes = $this->getAttributesOfTypeJson($attributes); - while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { - foreach ($row as $key => $column) { - if (array_search($key, $jsonAttributes) !== false && !is_null($column)) { - $row[$key] = json_decode($column, true); + while ($row = $stmt->fetchAssociative()) { + foreach ($attributes as $attribute) { + $value = $row[$attribute->getLabel()]; + if ($attribute->getType() === 'json' && !is_null($value)) { + $row[$attribute->getLabel()] = json_decode($value, true); + } + if ($attribute->getType() === 'float' && !is_null($value)) { + $row[$attribute->getLabel()] = floatval($value); } } $rows[] = $row; } return $rows; } - - /** - * Returns array of attributes label for the attribute type json - * - * @param Attribute[] $attributes The query attributes selected - * - * @return string[] - */ - private function getAttributesOfTypeJson(array $attributes): array - { - return array_map(function ($attribute) { - return $attribute->getLabel(); - }, array_filter($attributes, function ($attribute) { - return $attribute->getType() === 'json'; - })); - } } diff --git a/server/tests/Search/Response/JsonResponseTest.php b/server/tests/Search/Response/JsonResponseTest.php index 0626afee4b6d89056af12cc61e6948251be748e2..874e21cad75223b21e8d4dddab99439781f8cf0a 100644 --- a/server/tests/Search/Response/JsonResponseTest.php +++ b/server/tests/Search/Response/JsonResponseTest.php @@ -25,7 +25,7 @@ final class JsonResponseTest extends TestCase public function testGetResponse(): void { $stmt = $this->getResultMock(); - $stmt->method('fetch')->willReturnOnConsecutiveCalls(array( + $stmt->method('fetchAssociative')->willReturnOnConsecutiveCalls(array( 'id' => 1, 'ra' => 102.5, 'dec' => 0.1, @@ -34,19 +34,22 @@ final class JsonResponseTest extends TestCase $id = $this->getAttributeMock(); $id->method('getLabel')->willReturn('id'); + $id->method('getType')->willReturn('integer'); $ra = $this->getAttributeMock(); $ra->method('getLabel')->willReturn('ra'); + $ra->method('getType')->willReturn('float'); $dec = $this->getAttributeMock(); $dec->method('getLabel')->willReturn('dec'); - $dec = $this->getAttributeMock(); - $dec->method('getLabel')->willReturn('json'); - $dec->method('getType')->willReturn('json'); + $dec->method('getType')->willReturn('float'); + $json = $this->getAttributeMock(); + $json->method('getLabel')->willReturn('json'); + $json->method('getType')->willReturn('json'); $doctrineQueryBuilder = $this->getDoctrineQueryBuilderMock(); - $doctrineQueryBuilder->method('execute')->willReturn($stmt); + $doctrineQueryBuilder->method('executeQuery')->willReturn($stmt); $anisQueryBuilder = $this->getAnisQueryBuilderMock(); $anisQueryBuilder->method('getDoctrineQueryBuilder')->willReturn($doctrineQueryBuilder); - $anisQueryBuilder->method('getAttributesSelected')->willReturn(array($id, $ra, $dec)); + $anisQueryBuilder->method('getAttributesSelected')->willReturn(array($id, $ra, $dec, $json)); $textResponse = new JsonResponse(); $r = new Response(200, array(