From b207e6a921f3035790393bd6ae2a352c9a9de572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= <francois.agneray@lam.fr> Date: Tue, 24 Aug 2021 10:42:06 +0200 Subject: [PATCH] Add data_path property for instance entity --- .../instance/instance-form.component.html | 8 ++++-- .../instance/instance-form.component.ts | 3 ++- conf-dev/create-db.sh | 2 +- .../__CG__AppEntityInstance.php | 26 +++++++++++++++++-- server/src/Action/InstanceAction.php | 3 ++- server/src/Action/InstanceListAction.php | 3 ++- server/src/Entity/Instance.php | 18 +++++++++++++ 7 files changed, 55 insertions(+), 8 deletions(-) diff --git a/client/src/app/admin/components/instance/instance-form.component.html b/client/src/app/admin/components/instance/instance-form.component.html index d0a7d762..f03ff1bb 100644 --- a/client/src/app/admin/components/instance/instance-form.component.html +++ b/client/src/app/admin/components/instance/instance-form.component.html @@ -3,11 +3,15 @@ <accordion-group heading="General information" [isOpen]="true"> <div class="form-group"> <label for="name">Name</label> - <input id="name" type="text" class="form-control" id="name" name="name" formControlName="name"> + <input type="text" class="form-control" id="name" name="name" formControlName="name"> </div> <div class="form-group"> <label for="label">Label</label> - <input id="label" type="text" class="form-control" id="label" name="label" formControlName="label"> + <input type="text" class="form-control" id="label" name="label" formControlName="label"> + </div> + <div class="form-group"> + <label for="label">Data path</label> + <input type="text" class="form-control" id="data_path" name="data_path" formControlName="data_path"> </div> </accordion-group> <app-design-form-group [form]="designFormGroup"></app-design-form-group> diff --git a/client/src/app/admin/components/instance/instance-form.component.ts b/client/src/app/admin/components/instance/instance-form.component.ts index 04be669d..f6185d62 100644 --- a/client/src/app/admin/components/instance/instance-form.component.ts +++ b/client/src/app/admin/components/instance/instance-form.component.ts @@ -21,7 +21,7 @@ export class InstanceFormComponent implements OnInit { @Output() onSubmit: EventEmitter<Instance> = new EventEmitter(); public designFormGroup = new FormGroup({ - design_color: new FormControl('', [Validators.required]) + design_color: new FormControl('#7AC29A', [Validators.required]) }); public searchFormGroup = new FormGroup({ @@ -37,6 +37,7 @@ export class InstanceFormComponent implements OnInit { public form = new FormGroup({ name: new FormControl('', [Validators.required]), label: new FormControl('', [Validators.required]), + data_path: new FormControl(''), config: new FormGroup({ design: this.designFormGroup, search: this.searchFormGroup, diff --git a/conf-dev/create-db.sh b/conf-dev/create-db.sh index e9dd7ad6..31d6ed97 100644 --- a/conf-dev/create-db.sh +++ b/conf-dev/create-db.sh @@ -59,7 +59,7 @@ curl -d '{"label":"Spectra graph","value":"spectra_graph","display":20,"select_n curl -d '{"label":"Test","dbname":"anis_test","dbtype":"pdo_pgsql","dbhost":"db","dbport":5432,"dblogin":"anis","dbpassword":"anis"}' --header 'Content-Type: application/json' -X POST http://localhost/database # Add default instance -curl -d '{"name":"default","label":"Default instance","config":{"design":{"design_color":"#7AC29A"},"search":{"search_by_criteria_allowed":true,"search_multiple_allowed":false,"search_multiple_all_datasets_selected":false},"documentation":{"documentation_allowed":false}}}' --header 'Content-Type: application/json' -X POST http://localhost/instance +curl -d '{"name":"default","label":"Default instance","data_path":"\/DEFAULT","config":{"design":{"design_color":"#7AC29A"},"search":{"search_by_criteria_allowed":true,"search_multiple_allowed":false,"search_multiple_all_datasets_selected":false},"documentation":{"documentation_allowed":false}}}' --header 'Content-Type: application/json' -X POST http://localhost/instance # Add ANIS, SVOM and IRIS surveys curl -d '{"name":"anis_survey","label":"ANIS survey","description":"Survey used for testing","link":"https://anis.lam.fr","manager":"F. Agneray","id_database":1}' --header 'Content-Type: application/json' -X POST http://localhost/survey diff --git a/server/doctrine-proxy/__CG__AppEntityInstance.php b/server/doctrine-proxy/__CG__AppEntityInstance.php index 9ca9b1eb..b971ab68 100644 --- a/server/doctrine-proxy/__CG__AppEntityInstance.php +++ b/server/doctrine-proxy/__CG__AppEntityInstance.php @@ -66,10 +66,10 @@ class Instance extends \App\Entity\Instance implements \Doctrine\ORM\Proxy\Proxy public function __sleep() { if ($this->__isInitialized__) { - return ['__isInitialized__', 'name', 'label', 'config', 'datasetFamilies']; + return ['__isInitialized__', 'name', 'label', 'dataPath', 'config', 'datasetFamilies']; } - return ['__isInitialized__', 'name', 'label', 'config', 'datasetFamilies']; + return ['__isInitialized__', 'name', 'label', 'dataPath', 'config', 'datasetFamilies']; } /** @@ -213,6 +213,28 @@ class Instance extends \App\Entity\Instance implements \Doctrine\ORM\Proxy\Proxy return parent::setLabel($label); } + /** + * {@inheritDoc} + */ + public function getDataPath() + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'getDataPath', []); + + return parent::getDataPath(); + } + + /** + * {@inheritDoc} + */ + public function setDataPath($dataPath) + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'setDataPath', [$dataPath]); + + return parent::setDataPath($dataPath); + } + /** * {@inheritDoc} */ diff --git a/server/src/Action/InstanceAction.php b/server/src/Action/InstanceAction.php index 6fa73a66..82442eb8 100644 --- a/server/src/Action/InstanceAction.php +++ b/server/src/Action/InstanceAction.php @@ -60,7 +60,7 @@ final class InstanceAction extends AbstractAction $parsedBody = $request->getParsedBody(); // If mandatories empty fields 400 - foreach (array('label') as $a) { + foreach (array('label', 'data_path') as $a) { if ($this->isEmptyField($a, $parsedBody)) { throw new HttpBadRequestException( $request, @@ -94,6 +94,7 @@ final class InstanceAction extends AbstractAction { $instance->setLabel($parsedBody['label']); $instance->setConfig($parsedBody['config']); + $instance->setDataPath($parsedBody['data_path']); $this->em->flush(); } } diff --git a/server/src/Action/InstanceListAction.php b/server/src/Action/InstanceListAction.php index a2439270..9e226441 100644 --- a/server/src/Action/InstanceListAction.php +++ b/server/src/Action/InstanceListAction.php @@ -48,7 +48,7 @@ final class InstanceListAction extends AbstractAction $parsedBody = $request->getParsedBody(); // To work this action needs user information to update - foreach (array('name', 'label') as $a) { + foreach (array('name', 'label', 'data_path') as $a) { if ($this->isEmptyField($a, $parsedBody)) { throw new HttpBadRequestException( $request, @@ -77,6 +77,7 @@ final class InstanceListAction extends AbstractAction { $instance = new Instance($parsedBody['name'], $parsedBody['label']); $instance->setConfig($parsedBody['config']); + $instance->setDataPath($parsedBody['data_path']); $this->em->persist($instance); $this->em->flush(); diff --git a/server/src/Entity/Instance.php b/server/src/Entity/Instance.php index 7280ef51..d95670e1 100644 --- a/server/src/Entity/Instance.php +++ b/server/src/Entity/Instance.php @@ -38,6 +38,13 @@ class Instance implements \JsonSerializable */ protected $label; + /** + * @var string + * + * @Column(type="string", name="data_path", nullable=true) + */ + protected $dataPath; + /** * @var string * @@ -74,6 +81,16 @@ class Instance implements \JsonSerializable $this->label = $label; } + public function getDataPath() + { + return $this->dataPath; + } + + public function setDataPath($dataPath) + { + $this->dataPath = $dataPath; + } + public function getConfig() { return $this->config; @@ -103,6 +120,7 @@ class Instance implements \JsonSerializable return [ 'name' => $this->getName(), 'label' => $this->getLabel(), + 'data_path' => $this->getDataPath(), 'config' => $this->getConfig(), 'nb_dataset_families' => count($this->getDatasetFamilies()), 'nb_datasets' => $this->getNbDatasets() -- GitLab