From ec6570b77167316d0825afc8a4f0cb1a8aed89c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= <francois.agneray@lam.fr>
Date: Fri, 30 Sep 2022 21:17:34 +0200
Subject: [PATCH] #81 => done

---
 .../detail-config-form.component.html         |  5 +---
 .../detail-config-form.component.ts           |  6 ++--
 .../components/detail-content.component.html  |  1 +
 .../components/detail-content.component.ts    | 19 ++++++++++--
 .../metamodel/models/detail-config.model.ts   |  2 +-
 conf-dev/create-db.sh                         |  4 +--
 .../__CG__AppEntityDetailConfig.php           | 28 ++++++++---------
 server/src/Action/DetailConfigAction.php      |  8 ++---
 server/src/Entity/DetailConfig.php            | 30 +++++++++----------
 9 files changed, 57 insertions(+), 46 deletions(-)

diff --git a/client/src/app/admin/instance/dataset/components/detail-page/detail-config-form.component.html b/client/src/app/admin/instance/dataset/components/detail-page/detail-config-form.component.html
index f553fd7c..a7ff4270 100644
--- a/client/src/app/admin/instance/dataset/components/detail-page/detail-config-form.component.html
+++ b/client/src/app/admin/instance/dataset/components/detail-page/detail-config-form.component.html
@@ -1,9 +1,6 @@
 <form [formGroup]="form" (ngSubmit)="submit()" novalidate>
-    <div class="custom-control custom-switch">
-        <input class="custom-control-input" type="checkbox" id="enabled" name="enabled" formControlName="enabled">
-        <label class="custom-control-label" for="enabled">Enabled</label>
-    </div>
     <app-webpage-form-content [form]="form" [controlName]="'content'" [controlLabel]="'Content'" [codeType]="'html'"></app-webpage-form-content>
+    <app-webpage-form-content [form]="form" [controlName]="'style_sheet'" [controlLabel]="'Style sheet css'" [codeType]="'css'"></app-webpage-form-content>
     <div class="form-group mt-3">
         <ng-content></ng-content>
     </div>
diff --git a/client/src/app/admin/instance/dataset/components/detail-page/detail-config-form.component.ts b/client/src/app/admin/instance/dataset/components/detail-page/detail-config-form.component.ts
index 38a92d46..b52ba9a4 100644
--- a/client/src/app/admin/instance/dataset/components/detail-page/detail-config-form.component.ts
+++ b/client/src/app/admin/instance/dataset/components/detail-page/detail-config-form.component.ts
@@ -10,7 +10,7 @@
 import { Component, OnInit, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
 import { UntypedFormGroup, UntypedFormControl } from '@angular/forms';
 
-import { Attribute, DetailConfig } from 'src/app/metamodel/models';
+import { DetailConfig } from 'src/app/metamodel/models';
 
 @Component({
     selector: 'app-detail-config-form',
@@ -22,8 +22,8 @@ export class DetailConfigFormComponent implements OnInit {
     @Output() onSubmit: EventEmitter<DetailConfig> = new EventEmitter();
 
     public form = new UntypedFormGroup({
-        enabled: new UntypedFormControl(false),
-        content: new UntypedFormControl()
+        content: new UntypedFormControl(),
+        style_sheet: new UntypedFormControl(null)
     });
 
     ngOnInit() {
diff --git a/client/src/app/instance/search/detail/components/detail-content.component.html b/client/src/app/instance/search/detail/components/detail-content.component.html
index b0961d8f..ab86c2cb 100644
--- a/client/src/app/instance/search/detail/components/detail-content.component.html
+++ b/client/src/app/instance/search/detail/components/detail-content.component.html
@@ -1,4 +1,5 @@
 <ngx-dynamic-hooks 
+    class="detail-{{datasetName}}"
     [content]="detailConfig.content"
     [parsers]="getParsers()"
     [context]="getContext()">
diff --git a/client/src/app/instance/search/detail/components/detail-content.component.ts b/client/src/app/instance/search/detail/components/detail-content.component.ts
index ca7dfd60..3923f1a8 100644
--- a/client/src/app/instance/search/detail/components/detail-content.component.ts
+++ b/client/src/app/instance/search/detail/components/detail-content.component.ts
@@ -7,11 +7,12 @@
  * file that was distributed with this source code.
  */
 
-import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
+import { Component, OnInit, Input, ChangeDetectionStrategy } from '@angular/core';
 
-import { DetailConfig, Dataset, Attribute, OutputFamily, OutputCategory } from 'src/app/metamodel/models';
+import { DetailConfig, Attribute, OutputFamily, OutputCategory } from 'src/app/metamodel/models';
 import { globalParsers } from 'src/app/shared/dynamic-content';
 import { componentParsers } from '../dynamic-content';
+import { StyleService } from 'src/app/shared/services/style.service';
 
 /**
  * @class
@@ -22,7 +23,7 @@ import { componentParsers } from '../dynamic-content';
     templateUrl: 'detail-content.component.html',
     changeDetection: ChangeDetectionStrategy.OnPush
 })
-export class DetailContentComponent {
+export class DetailContentComponent implements OnInit {
     @Input() detailConfig: DetailConfig;
     @Input() object: any;
     @Input() datasetName: string;
@@ -30,6 +31,18 @@ export class DetailContentComponent {
     @Input() outputFamilyList: OutputFamily[];
     @Input() outputCategoryList: OutputCategory[];
 
+    constructor(private style: StyleService) { }
+
+    ngOnInit() {
+        this.style.addCSS(
+            this.detailConfig.style_sheet.replace(
+                /(.+{)/g,
+                (match, $1) => `.detail-${this.datasetName} ${$1}`
+            ),
+            'detail'
+        );
+    }
+
     getParsers() {
         return [
             ...globalParsers,
diff --git a/client/src/app/metamodel/models/detail-config.model.ts b/client/src/app/metamodel/models/detail-config.model.ts
index 52f3e655..a771632a 100644
--- a/client/src/app/metamodel/models/detail-config.model.ts
+++ b/client/src/app/metamodel/models/detail-config.model.ts
@@ -14,6 +14,6 @@
  */
 export interface DetailConfig {
     id: number;
-    enabled: boolean;
     content: string;
+    style_sheet: string;
 }
\ No newline at end of file
diff --git a/conf-dev/create-db.sh b/conf-dev/create-db.sh
index 38e26bcc..5375f265 100644
--- a/conf-dev/create-db.sh
+++ b/conf-dev/create-db.sh
@@ -45,7 +45,7 @@ curl -d '{"id":57,"name":"spec1dnoise","label":"spec1dnoise","form_label":"spec1
 curl -d '{"id":58,"name":"spec1dsky","label":"spec1dsky","form_label":"spec1dsky","description":null,"primary_key":false,"output_display":580,"criteria_display":580,"search_type":null,"type":"text","operator":null,"dynamic_operator":true,"min":null,"max":null,"placeholder_min":null,"placeholder_max":null,"renderer":"download","renderer_config":{"display":"icon-button","text":"DOWNLOAD","icon":"fas fa-download"},"detail_display":580,"selected":true,"order_by":false,"archive":false,"options":null,"vo_utype":null,"vo_ucd":null,"vo_unit":null,"vo_description":null,"vo_datatype":null,"vo_size":null,"id_criteria_family":null,"id_output_category":1,"id_detail_output_category":null}' --header 'Content-Type: application/json' -X POST http://localhost/dataset/vipers_dr2_w1/attribute
 
 # Add vipers_dr2_w1 detail config
-curl -d '{"enabled":true,"content":"<div class=\"row\">\n    <div class=\"col col-md-8 col-sm-12\">\n        <app-display-spectra\n            [object]=\"context.object\"\n            [datasetName]=\"context.datasetName\"\n            [attributeList]=\"context.attributeList\"\n            [attributeSpectraId]=\"56\"\n            [attributeZId]=\"8\">\n        </app-display-spectra>\n    </div>\n    <div class=\"col col-md-4 col-sm-12\">\n        <app-display-ra-dec\n            [object]=\"context.object\"\n            [attributeList]=\"context.attributeList\"\n            [attributeRaId]=\"2\"\n            [attributeDecId]=\"3\">\n        </app-display-ra-dec>\n        <app-display-object \n            [object]=\"context.object\"\n            [attributeList]=\"context.attributeList\"\n            [outputFamilyList]=\"context.outputFamilyList\"\n            [outputCategoryList]=\"context.outputCategoryList\">\n        </app-display-object>\n    </div>\n</div>"}' --header 'Content-Type: application/json' -X POST http://localhost/dataset/vipers_dr2_w1/detail-config
+curl -d '{"content":"<div class=\"row\">\n    <div class=\"col col-md-8 col-sm-12\">\n        <app-display-spectra\n            [object]=\"context.object\"\n            [datasetName]=\"context.datasetName\"\n            [attributeList]=\"context.attributeList\"\n            [attributeSpectraId]=\"56\"\n            [attributeZId]=\"8\">\n        </app-display-spectra>\n    </div>\n    <div class=\"col col-md-4 col-sm-12\">\n        <app-display-ra-dec\n            [object]=\"context.object\"\n            [attributeList]=\"context.attributeList\"\n            [attributeRaId]=\"2\"\n            [attributeDecId]=\"3\">\n        </app-display-ra-dec>\n        <app-display-object \n            [object]=\"context.object\"\n            [attributeList]=\"context.attributeList\"\n            [outputFamilyList]=\"context.outputFamilyList\"\n            [outputCategoryList]=\"context.outputCategoryList\">\n        </app-display-object>\n    </div>\n</div>","style_sheet":""}' --header 'Content-Type: application/json' -X POST http://localhost/dataset/vipers_dr2_w1/detail-config
 
 # Add sp_cards attributes
 curl -d '{"label":"Card","display":10,"opened":true}' --header 'Content-Type: application/json' -X POST http://localhost/dataset/sp_cards/criteria-family
@@ -80,7 +80,7 @@ curl -d '{"id":9,"name":"fits_png","label":"fits_png","form_label":"fits_png","d
 curl -d '{"id":10,"name":"id_obspack","label":"id_obspack","form_label":"id_obspack","description":null,"primary_key":false,"type":"integer","search_type":null,"operator":null,"dynamic_operator":null,"min":null,"max":null,"options":null,"placeholder_min":null,"placeholder_max":null,"criteria_display":100,"output_display":100,"selected":true,"renderer":"link","renderer_config":{"href":"/instance/default/search/result/iris_obspack?s=100&a=1;2;3&c=1::eq::$value","display":"text","text":"$value","icon":"fas fa-link","blank":false},"order_by":true,"archive":false,"detail_display":100,"vo_utype":null,"vo_ucd":null,"vo_unit":null,"vo_description":null,"vo_datatype":null,"vo_size":null,"id_criteria_family":null,"id_output_category":4,"id_detail_output_category":null}' --header 'Content-Type: application/json' -X POST http://localhost/dataset/observations/attribute
 
 # Add observations detail config
-curl -d '{"enabled":true,"content":"<div class=\"row justify-content-center\">\n    <div class=\"col col-lg-10 col-xl-8 mt-4\">\n        <div class=\"row\">\n            <div class=\"col-12\">\n                <app-display-ra-dec\n                    [object]=\"context.object\"\n                    [attributeList]=\"context.attributeList\"\n                    [attributeRaId]=\"2\"\n                    [attributeDecId]=\"3\">\n                </app-display-ra-dec>\n            </div>\n        </div>\n\n        <app-display-object \n            [object]=\"context.object\"\n            [attributeList]=\"context.attributeList\"\n            [outputFamilyList]=\"context.outputFamilyList\"\n            [outputCategoryList]=\"context.outputCategoryList\">\n        </app-display-object>\n    </div>\n</div>"}' --header 'Content-Type: application/json' -X POST http://localhost/dataset/observations/detail-config
+curl -d '{"content":"<div class=\"row justify-content-center\">\n    <div class=\"col col-lg-10 col-xl-8 mt-4\">\n        <div class=\"row\">\n            <div class=\"col-12\">\n                <app-display-ra-dec\n                    [object]=\"context.object\"\n                    [attributeList]=\"context.attributeList\"\n                    [attributeRaId]=\"2\"\n                    [attributeDecId]=\"3\">\n                </app-display-ra-dec>\n            </div>\n        </div>\n\n        <app-display-object \n            [object]=\"context.object\"\n            [attributeList]=\"context.attributeList\"\n            [outputFamilyList]=\"context.outputFamilyList\"\n            [outputCategoryList]=\"context.outputCategoryList\">\n        </app-display-object>\n    </div>\n</div>","style_sheet":""}' --header 'Content-Type: application/json' -X POST http://localhost/dataset/observations/detail-config
 
 # Add vvds_f02_udeep attributes
 curl -d '{"label":"Default","display":10,"opened":true}' --header 'Content-Type: application/json' -X POST http://localhost/dataset/vvds_f02_udeep/criteria-family
diff --git a/server/doctrine-proxy/__CG__AppEntityDetailConfig.php b/server/doctrine-proxy/__CG__AppEntityDetailConfig.php
index 45fb9beb..0b6f8d81 100644
--- a/server/doctrine-proxy/__CG__AppEntityDetailConfig.php
+++ b/server/doctrine-proxy/__CG__AppEntityDetailConfig.php
@@ -67,10 +67,10 @@ class DetailConfig extends \App\Entity\DetailConfig implements \Doctrine\ORM\Pro
     public function __sleep()
     {
         if ($this->__isInitialized__) {
-            return ['__isInitialized__', 'id', 'enabled', 'content'];
+            return ['__isInitialized__', 'id', 'content', 'styleSheet'];
         }
 
-        return ['__isInitialized__', 'id', 'enabled', 'content'];
+        return ['__isInitialized__', 'id', 'content', 'styleSheet'];
     }
 
     /**
@@ -195,45 +195,45 @@ class DetailConfig extends \App\Entity\DetailConfig implements \Doctrine\ORM\Pro
     /**
      * {@inheritDoc}
      */
-    public function getEnabled()
+    public function getContent()
     {
 
-        $this->__initializer__ && $this->__initializer__->__invoke($this, 'getEnabled', []);
+        $this->__initializer__ && $this->__initializer__->__invoke($this, 'getContent', []);
 
-        return parent::getEnabled();
+        return parent::getContent();
     }
 
     /**
      * {@inheritDoc}
      */
-    public function setEnabled($enabled)
+    public function setContent($content)
     {
 
-        $this->__initializer__ && $this->__initializer__->__invoke($this, 'setEnabled', [$enabled]);
+        $this->__initializer__ && $this->__initializer__->__invoke($this, 'setContent', [$content]);
 
-        return parent::setEnabled($enabled);
+        return parent::setContent($content);
     }
 
     /**
      * {@inheritDoc}
      */
-    public function getContent()
+    public function getStyleSheet()
     {
 
-        $this->__initializer__ && $this->__initializer__->__invoke($this, 'getContent', []);
+        $this->__initializer__ && $this->__initializer__->__invoke($this, 'getStyleSheet', []);
 
-        return parent::getContent();
+        return parent::getStyleSheet();
     }
 
     /**
      * {@inheritDoc}
      */
-    public function setContent($content)
+    public function setStyleSheet($styleSheet)
     {
 
-        $this->__initializer__ && $this->__initializer__->__invoke($this, 'setContent', [$content]);
+        $this->__initializer__ && $this->__initializer__->__invoke($this, 'setStyleSheet', [$styleSheet]);
 
-        return parent::setContent($content);
+        return parent::setStyleSheet($styleSheet);
     }
 
     /**
diff --git a/server/src/Action/DetailConfigAction.php b/server/src/Action/DetailConfigAction.php
index 38877b68..051df084 100644
--- a/server/src/Action/DetailConfigAction.php
+++ b/server/src/Action/DetailConfigAction.php
@@ -104,8 +104,8 @@ final class DetailConfigAction extends AbstractAction
     private function checkParsedBody($parsedBody, $request)
     {
         $fields = array(
-            'enabled',
-            'content'
+            'content',
+            'style_sheet'
         );
 
         // To work this actions needs information
@@ -128,8 +128,8 @@ final class DetailConfigAction extends AbstractAction
     private function postDetailConfig(array $parsedBody, Dataset $dataset): DetailConfig
     {
         $detailConfig = new DetailConfig();
-        $detailConfig->setEnabled($parsedBody['enabled']);
         $detailConfig->setContent($parsedBody['content']);
+        $detailConfig->setStyleSheet($parsedBody['style_sheet']);
 
         $dataset->setDetailConfig($detailConfig);
 
@@ -147,8 +147,8 @@ final class DetailConfigAction extends AbstractAction
      */
     private function editDetailConfig(detailConfig $detailConfig, array $parsedBody): void
     {
-        $detailConfig->setEnabled($parsedBody['enabled']);
         $detailConfig->setContent($parsedBody['content']);
+        $detailConfig->setStyleSheet($parsedBody['style_sheet']);
         $this->em->flush();
     }
 }
diff --git a/server/src/Entity/DetailConfig.php b/server/src/Entity/DetailConfig.php
index 768e3ee1..a6ae6d00 100644
--- a/server/src/Entity/DetailConfig.php
+++ b/server/src/Entity/DetailConfig.php
@@ -31,50 +31,50 @@ class DetailConfig implements \JsonSerializable
     protected $id;
 
     /**
-     * @var bool
+     * @var string
      *
-     * @Column(type="boolean", name="enabled", nullable=false)
+     * @Column(type="text", name="content", nullable=false)
      */
-    protected $enabled;
+    protected $content;
 
     /**
      * @var string
      *
-     * @Column(type="text", name="content", nullable=false)
+     * @Column(type="text", name="style_sheet", nullable=true)
      */
-    protected $content;
+    protected $styleSheet;
 
     public function getId()
     {
         return $this->id;
     }
 
-    public function getEnabled()
+    public function getContent()
     {
-        return $this->enabled;
+        return $this->content;
     }
 
-    public function setEnabled($enabled)
+    public function setContent($content)
     {
-        $this->enabled = $enabled;
+        $this->content = $content;
     }
 
-    public function getContent()
+    public function getStyleSheet()
     {
-        return $this->content;
+        return $this->styleSheet;
     }
 
-    public function setContent($content)
+    public function setStyleSheet($styleSheet)
     {
-        $this->content = $content;
+        $this->styleSheet = $styleSheet;
     }
 
     public function jsonSerialize(): array
     {
         return [
             'id' => $this->getId(),
-            'enabled' => $this->getEnabled(),
-            'content' => $this->getContent()
+            'content' => $this->getContent(),
+            'style_sheet' => $this->getStyleSheet()
         ];
     }
 }
-- 
GitLab