Browse Source

fixed thematiques display

bach 3 years ago
parent
commit
6485e3e27b

+ 19 - 0
config/sync/search_api.index.database.yml

@@ -15,6 +15,7 @@ dependencies:
     - field.storage.node.field_famille
     - field.storage.node.field_manufacturer
     - field.storage.node.field_reference
+    - field.storage.node.field_short_description
     - field.storage.node.field_tags
     - field.storage.taxonomy_term.field_synonyms
     - field.storage.node.field_thesaurus
@@ -104,6 +105,14 @@ field_settings:
     dependencies:
       config:
         - field.storage.node.field_reference
+  field_short_description:
+    label: 'Short description'
+    datasource_id: 'entity:node'
+    property_path: field_short_description
+    type: string
+    dependencies:
+      config:
+        - field.storage.node.field_short_description
   name:
     label: 'Manufacturer » Terme de taxonomie » Nom'
     datasource_id: 'entity:node'
@@ -234,6 +243,14 @@ field_settings:
     dependencies:
       module:
         - node
+  type:
+    label: 'Type de contenu'
+    datasource_id: 'entity:node'
+    property_path: type
+    type: string
+    dependencies:
+      module:
+        - node
   uid:
     label: uid
     datasource_id: 'entity:node'
@@ -304,6 +321,7 @@ processor_settings:
       - country_code_1
       - field_famille
       - field_reference
+      - field_short_description
       - name
       - name_1
       - processed
@@ -312,6 +330,7 @@ processor_settings:
       - thesaurus_name
       - thesaurus_synonyms
       - title
+      - type
       - uuid
     title: true
     alt: true

+ 48 - 22
web/modules/custom/materio_graphql/graphql/materio_extension.base.graphqls

@@ -2,18 +2,38 @@ scalar Violation
 
 interface NodeInterface {
   id: Int!
+  uuid: String!
+  title: String!
   path: String!
+  author: String
+  bundle: String!
 }
 
-type Materiau implements NodeInterface {
+interface SearchResultInterface {
   id: Int!
   uuid: String!
   title: String!
   path: String!
   author: String
+  bundle: String!
+  #
+  short_description: String
   body: String
+  linked_materials: [Materiau]
+}
+
+type Materiau implements NodeInterface & SearchResultInterface{
+  id: Int!
+  uuid: String!
+  title: String!
+  path: String!
+  author: String
+  bundle: String!
+  #
   short_description: String
+  body: String
   linked_materials: [Materiau]
+  #
   linked_articles: [Article]
   images: [Image]
   videos: [VideoLink]
@@ -23,41 +43,47 @@ type Materiau implements NodeInterface {
   attachments: [Filefield]
   distributor: [Company]
   manufacturer: [Company]
-  # famille: String
-  # index: Int
   reference: String
   samples: [Sample]
   note: Note
+  # famille: String
+  # index: Int
 }
 
-type Article implements NodeInterface {
+type Thematique implements NodeInterface & SearchResultInterface {
   id: Int!
   uuid: String!
   title: String!
   path: String!
   author: String
+  bundle: String!
+  #
+  short_description: String
   body: String
   linked_materials: [Materiau]
+  #
   images: [Image]
-  videos: [VideoLink]
-  source: Link
-  showroom: Showroom
   tags: [Tag]
-  thesaurus: [Thesaurus]
-  date: Date
   memo: String
 }
 
-type Thematique implements NodeInterface {
+type Article implements NodeInterface {
   id: Int!
   uuid: String!
   title: String!
   path: String!
   author: String
+  bundle: String!
+  #
   body: String
   linked_materials: [Materiau]
   images: [Image]
+  videos: [VideoLink]
+  source: Link
+  showroom: Showroom
   tags: [Tag]
+  thesaurus: [Thesaurus]
+  date: Date
   memo: String
 }
 
@@ -67,18 +93,18 @@ type Note {
   target: Int
 }
 
-type SearchResult {
-  id: Int!
-  uuid: String!
-  title: String!
-  bundle: String!
-  path: String!
-  short_description: String
-  images: [Image]
-  visuels: [Image]
-  reference: String
-  samples: [Sample]
-}
+# type SearchResult {
+#   id: Int!
+#   uuid: String!
+#   title: String!
+#   bundle: String!
+#   path: String!
+#   short_description: String
+#   images: [Image]
+#   visuels: [Image]
+#   reference: String
+#   samples: [Sample]
+# }
 
 type Product {
   id: Int!

+ 1 - 1
web/modules/custom/materio_graphql/graphql/materio_extension.extension.graphqls

@@ -11,7 +11,7 @@ extend type Query {
 }
 
 extend type Query {
-  searchresults(ids: [Int], lang: String): [SearchResult]
+  searchresults(ids: [Int], lang: String): [SearchResultInterface]
 }
 
 extend type Query {

+ 50 - 64
web/modules/custom/materio_graphql/src/Plugin/GraphQL/SchemaExtension/MaterioSchemaExtension.php

@@ -101,9 +101,17 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
       $builder->compose(
         $builder->produce('route_load')
           ->map('path', $builder->fromArgument('path')),
+        $builder->callBack(function($parent, $args){
+          $t="t";
+          return $parent;
+        }),
         $builder->produce('route_entity')
           ->map('url', $builder->fromParent())
-          ->map('language', $builder->fromArgument('lang'))
+          ->map('language', $builder->fromArgument('lang')),
+        $builder->callBack(function($parent, $args){
+          $t="t";
+          return $parent;
+        })
     ));
   }
 
@@ -141,6 +149,12 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
         ->map('entity', $builder->fromParent())
       );
 
+    $registry->addFieldResolver('Materiau', 'bundle',
+      $builder->compose(
+        $builder->produce('entity_bundle')
+          ->map('entity', $builder->fromParent())
+      ));
+
     $registry->addFieldResolver('Materiau', 'path',
       $builder->compose(
         $builder->produce('entity_url')
@@ -319,6 +333,12 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
         ->map('path', $builder->fromValue('field_contenu.value'))
     );
 
+    $registry->addFieldResolver('Note', 'bundle',
+      $builder->compose(
+        $builder->produce('entity_bundle')
+          ->map('entity', $builder->fromParent())
+      ));
+
     $registry->addFieldResolver('Note', 'target',
       $builder->produce('property_path')
         ->map('type', $builder->fromValue('entity:node'))
@@ -332,6 +352,14 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
   // \__ \/ -_) _` | '_/ _| ' \|   / -_|_-< || | |  _|
   // |___/\___\__,_|_| \__|_||_|_|_\___/__/\_,_|_|\__|
   protected function addSearchResult(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
+    // Tell GraphQL how to resolve types of a common interface.
+    $registry->addTypeResolver('SearchResultInterface', function ($value) {
+      switch ($value->bundle()) {
+        case 'materiau': return 'Materiau';
+        case 'thematique': return 'Thematique';
+      }
+      throw new Error('Could not resolve content type.');
+    });
 
     $registry->addFieldResolver('Query', 'searchresults',
         $builder->produce('entity_load_multiple')
@@ -339,69 +367,6 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
           ->map('ids', $builder->fromArgument('ids'))
           ->map('language', $builder->fromArgument('lang'))
     );
-
-    $registry->addFieldResolver('SearchResult', 'id',
-      $builder->produce('entity_id')
-        ->map('entity', $builder->fromParent())
-    );
-
-    $registry->addFieldResolver('SearchResult', 'bundle',
-      $builder->produce('entity_bundle')
-        ->map('entity', $builder->fromParent())
-      );
-
-    $registry->addFieldResolver('SearchResult', 'uuid',
-      $builder->produce('entity_uuid')
-        ->map('entity', $builder->fromParent())
-      );
-
-    $registry->addFieldResolver('SearchResult', 'path',
-      $builder->compose(
-        $builder->produce('entity_url')
-          ->map('entity', $builder->fromParent()),
-        $builder->produce('url_path')
-          ->map('url', $builder->fromParent())
-      )
-    );
-
-    $registry->addFieldResolver('SearchResult', 'title',
-      $builder->compose(
-        $builder->produce('entity_label')
-          ->map('entity', $builder->fromParent())
-      ));
-
-    $registry->addFieldResolver('SearchResult', 'short_description',
-      $builder->produce('property_path')
-        ->map('type', $builder->fromValue('entity:node'))
-        ->map('value', $builder->fromParent())
-        ->map('path', $builder->fromValue('field_short_description.value'))
-    );
-
-    $registry->addFieldResolver('SearchResult', 'images',
-      $builder->produce('entity_reference')
-        ->map('entity', $builder->fromParent())
-        ->map('field', $builder->fromValue('field_materiau_images'))
-      );
-
-    $registry->addFieldResolver('SearchResult', 'visuels',
-      $builder->produce('entity_reference')
-        ->map('entity', $builder->fromParent())
-        ->map('field', $builder->fromValue('field_visuel'))
-      );
-
-    $registry->addFieldResolver('SearchResult', 'reference',
-      $builder->produce('property_path')
-        ->map('type', $builder->fromValue('entity:node'))
-        ->map('value', $builder->fromParent())
-        ->map('path', $builder->fromValue('field_reference.value'))
-      );
-
-    $registry->addFieldResolver('SearchResult', 'samples',
-      $builder->produce('property_path')
-        ->map('type', $builder->fromValue('entity:node'))
-        ->map('value', $builder->fromParent())
-        ->map('path', $builder->fromValue('field_samples'))
-      );
   }
 
   //  ___                  _
@@ -454,6 +419,13 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
       )
     );
 
+    $registry->addFieldResolver('Article', 'bundle',
+      $builder->compose(
+        $builder->produce('entity_bundle')
+          ->map('entity', $builder->fromParent())
+      ));
+
+
     $registry->addFieldResolver('Article', 'title',
       $builder->compose(
         $builder->produce('entity_label')
@@ -575,6 +547,7 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
   //   |_| |_||_\___|_|_|_\__,_|\__|_\__, |\_,_\___|
   //                                    |_|
   protected function addThematique(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
+
     $registry->addFieldResolver('Query', 'Thematique',
       $builder->produce('entity_load')
         ->map('type', $builder->fromValue('node'))
@@ -601,6 +574,12 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
       )
     );
 
+    $registry->addFieldResolver('Thematique', 'bundle',
+      $builder->compose(
+        $builder->produce('entity_bundle')
+          ->map('entity', $builder->fromParent())
+      ));
+
     $registry->addFieldResolver('Thematique', 'title',
       $builder->compose(
         $builder->produce('entity_label')
@@ -615,6 +594,13 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
           ->map('entity', $builder->fromParent())
       ));
 
+    $registry->addFieldResolver('Thematique', 'short_description',
+      $builder->produce('property_path')
+        ->map('type', $builder->fromValue('entity:node'))
+        ->map('value', $builder->fromParent())
+        ->map('path', $builder->fromValue('field_short_description.value'))
+      );
+
     $registry->addFieldResolver('Thematique', 'body',
       $builder->produce('property_path')
         ->map('type', $builder->fromValue('entity:node'))

+ 8 - 8
web/modules/custom/materio_sapi/src/Controller/Base.php

@@ -107,7 +107,7 @@ class Base extends ControllerBase {
   private function defaultQuery(){
     $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
     $this->query = $entity_storage->getQuery()
-      ->condition('type', 'materiau')
+      ->condition('type', ['materiau', 'thematique'], 'IN')
       ->condition('status', '1')
       ->range($this->offset, $this->limit)
       ->accessCheck(TRUE)
@@ -116,7 +116,7 @@ class Base extends ControllerBase {
     $this->results = $this->query->execute();
 
     $this->count_query = $entity_storage->getQuery()
-      ->condition('type', 'materiau')
+      ->condition('type', ['materiau', 'thematique'], 'IN')
       ->accessCheck(TRUE)
       ->condition('status', '1')
       ->count();
@@ -191,18 +191,18 @@ class Base extends ControllerBase {
       $nids = [];
       // Using entityTypeManager
       // Get a node storage object.
-      $node_storage = \Drupal::entityTypeManager()->getStorage('node');
+      // $node_storage = \Drupal::entityTypeManager()->getStorage('node');
 
       foreach ($this->results as $result) {
-        $lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
+        // $lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
         // Load a single node.
-        $node = $node_storage->load($result);
+        // $node = $node_storage->load($result);
         // check if has translation
 
-        if ($node->hasTranslation($lang)) {
-          // $uuids[] = $result->getField('uuid')->getValues()[0];
+        // i used to filter like bellow because of a graphql probleme
+        // if ($node->hasTranslation($lang)) {
           $nids[] = $result;
-        }
+        // }
 
       }
       // $resp['uuids'] = $uuids;

File diff suppressed because it is too large
+ 0 - 0
web/themes/custom/materiotheme/assets/dist/main.js


+ 23 - 19
web/themes/custom/materiotheme/vuejs/api/gql/searchresults.fragment.gql

@@ -1,28 +1,32 @@
-fragment SearchResultFields on SearchResult {
+fragment SearchResultFields on SearchResultInterface {
   id
   uuid
   bundle
+  path
   title
   short_description
-  reference
-  path
-  images{
-    url
-    alt
-    style_cardmedium_url
-    style_hd_url
-  }
-  visuels{
-    url
-    alt
-    style_cardmedium_url
-    style_hd_url
+  ... on Materiau{
+    images{
+      url
+      alt
+      style_cardmedium_url
+      style_hd_url
+    }
+    reference
+  	samples{
+      showroom{
+        name
+        id
+      }
+      location
+    }
   }
-	samples{
-    showroom{
-      name
-      id
+  ... on Thematique {
+    images{
+      url
+      alt
+      style_cardmedium_url
+      style_hd_url
     }
-    location
   }
 }

+ 4 - 4
web/themes/custom/materiotheme/vuejs/components/Content/CardThematique.vue

@@ -11,7 +11,7 @@
     </header>
     <section class="images" v-switcher>
       <figure
-        v-for="(img, index) in item.visuels"
+        v-for="(img, index) in item.images"
         :key="img.url"
       >
         <img
@@ -28,7 +28,7 @@
       </figure>
     </section>
     <CoolLightBox
-      :items="item.visuels"
+      :items="item.images"
       :index="lightbox_index"
       srcName="style_hd_url"
       :loop="true"
@@ -54,7 +54,7 @@ export default {
       blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`,
       // loadingFlag: false,
       lightbox_index: null,
-      alias: this.item.path.replace(/^.?\/thematique\//g, '')
+      alias: this.item.path.replace(/^.*\/thematique\//g, '')
     }
   },
   // computed: {
@@ -98,7 +98,7 @@ export default {
     //   }
     // },
     openThematique (e) {
-      console.log('openThematique', e);
+      console.log('openThematique', e, this.alias);
       this.$router.push({
         name:`thematique`,
         params: { alias:this.alias }

Some files were not shown because too many files changed in this diff