From 679bede3143b446c0be0392bdce0ded71ad98c32 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= <francois.agneray@lam.fr>
Date: Mon, 6 Dec 2021 14:33:12 +0100
Subject: [PATCH] Archive action => done

---
 .../result/datatable-actions.component.html   |  2 +-
 .../result/datatable-actions.component.ts     | 10 ++--
 server/app/dependencies.php                   |  2 +-
 server/src/Action/ArchiveAction.php           |  2 +-
 server/src/Search/Query/SelectFile.php        | 52 -------------------
 5 files changed, 10 insertions(+), 58 deletions(-)
 delete mode 100644 server/src/Search/Query/SelectFile.php

diff --git a/client/src/app/instance/search/components/result/datatable-actions.component.html b/client/src/app/instance/search/components/result/datatable-actions.component.html
index a412b0e0..a1ff010a 100644
--- a/client/src/app/instance/search/components/result/datatable-actions.component.html
+++ b/client/src/app/instance/search/components/result/datatable-actions.component.html
@@ -1,4 +1,4 @@
-<div class="btn-group mb-2" dropdown [isDisabled]="selectedData.length < 1">
+<div *ngIf="getDataset().config.datatable.datatable_selectable_rows" class="btn-group mb-2" dropdown [isDisabled]="selectedData.length < 1">
     <button id="button-basic" dropdownToggle type="button" class="btn btn-primary dropdown-toggle" aria-controls="dropdown-basic">
         Actions <span class="caret"></span>
     </button>
diff --git a/client/src/app/instance/search/components/result/datatable-actions.component.ts b/client/src/app/instance/search/components/result/datatable-actions.component.ts
index fcd508e6..70e64e95 100644
--- a/client/src/app/instance/search/components/result/datatable-actions.component.ts
+++ b/client/src/app/instance/search/components/result/datatable-actions.component.ts
@@ -31,11 +31,15 @@ export class DatatableActionsComponent {
      *
      * @return boolean
      */
-     getConfigDownloadResultFormat(format: string): boolean {
-        const dataset = this.datasetList.find(d => d.name === this.datasetSelected);
+    getConfigDownloadResultFormat(format: string): boolean {
+        const dataset = this.getDataset();
         return dataset.config.download[format];
     }
 
+    getDataset() {
+        return this.datasetList.find(d => d.name === this.datasetSelected);
+    }
+
     /**
      * Returns URL to download file for the given format.
      *
@@ -43,7 +47,7 @@ export class DatatableActionsComponent {
      *
      * @return string
      */
-     getUrl(format: string): string {
+    getUrl(format: string): string {
         let query: string = `${getHost(this.appConfig.apiUrl)}/search/${this.datasetSelected}?a=${this.outputList.join(';')}`;
         if (this.criteriaList.length > 0) {
             query += `&c=${this.criteriaList.map(criterion => criterionToString(criterion)).join(';')};${this.getCriterionSelectedData()}`;
diff --git a/server/app/dependencies.php b/server/app/dependencies.php
index 2ba1d168..9fe363d6 100644
--- a/server/app/dependencies.php
+++ b/server/app/dependencies.php
@@ -203,7 +203,7 @@ $container->set('App\Action\SearchAction', function (ContainerInterface $c) {
 $container->set('App\Action\ArchiveAction', function (ContainerInterface $c) {
     $anisQueryBuilder = (new App\Search\Query\AnisQueryBuilder())
         ->addQueryPart(new App\Search\Query\From())
-        ->addQueryPart(new App\Search\Query\SelectFile())
+        ->addQueryPart(new App\Search\Query\Select())
         ->addQueryPart(new App\Search\Query\ConeSearch())
         ->addQueryPart(new App\Search\Query\Where(new App\Search\Query\Operator\OperatorFactory()))
         ->addQueryPart(new App\Search\Query\Order())
diff --git a/server/src/Action/ArchiveAction.php b/server/src/Action/ArchiveAction.php
index 431a3648..a40045c1 100644
--- a/server/src/Action/ArchiveAction.php
+++ b/server/src/Action/ArchiveAction.php
@@ -150,7 +150,7 @@ final class ArchiveAction extends AbstractAction
         while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
             foreach ($attributesSelected as $attribute) {
                 $attributeLabel = $attribute->getLabel();
-                $filePath = $this->dataPath . $dataset->getDataPath() . DIRECTORY_SEPARATOR . $row[$attributeLabel];
+                $filePath = $this->dataPath . $dataset->getFullDataPath() . DIRECTORY_SEPARATOR . $row[$attributeLabel];
                 if (file_exists($filePath)) {
                     $zip->addFile($filePath, $row[$attributeLabel]);
                 }
diff --git a/server/src/Search/Query/SelectFile.php b/server/src/Search/Query/SelectFile.php
deleted file mode 100644
index 24d71445..00000000
--- a/server/src/Search/Query/SelectFile.php
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-
-/*
- * This file is part of Anis Server.
- *
- * (c) Laboratoire d'Astrophysique de Marseille / CNRS
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-declare(strict_types=1);
-
-namespace App\Search\Query;
-
-use App\Entity\Dataset;
-
-/**
- * Represents the Anis Select File attributes Query Part
- *
- * @author François Agneray <francois.agneray@lam.fr>
- * @package App\Search\Query
- */
-class SelectFile extends AbstractQueryPart
-{
-    /**
-     * Adds the select clause to the request and set only attribute with search_flag = FILE
-     *
-     * @param AnisQueryBuilder $anisQueryBuilder Represents the query being built
-     * @param Dataset          $dataset      Represents the requested dataset
-     * @param string[]         $queryParams  The query params of the url (after ?)
-     */
-    public function __invoke(AnisQueryBuilder $anisQueryBuilder, Dataset $dataset, array $queryParams): void
-    {
-        if ($queryParams['a'] === 'all') {
-            $listOfIds = array_map(fn($attribute) => $attribute->getId(), $dataset->getAttributes());
-        } else {
-            $listOfIds = explode(';', $queryParams['a']);
-        }
-
-        $columns = array();
-        $attributes = array();
-        foreach ($listOfIds as $id) {
-            $attribute = $this->getAttribute($dataset, (int) $id);
-            if ($attribute->getSearchFlag() === 'FILE') {
-                $columns[] = $dataset->getTableRef() . '.' . $attribute->getName() . ' as ' . $attribute->getLabel();
-                $attributes[] = $attribute;
-            }
-        }
-        $anisQueryBuilder->getDoctrineQueryBuilder()->select($columns);
-        $anisQueryBuilder->setAttributesSelected($attributes);
-    }
-}
-- 
GitLab