[TASK] Simplify the Clear temp file section in Install Tool 15/54215/4
authorGeorg Ringer <georg.ringer@gmail.com>
Tue, 26 Sep 2017 05:41:52 +0000 (07:41 +0200)
committerBenni Mack <benni@typo3.org>
Wed, 29 Nov 2017 18:05:58 +0000 (19:05 +0100)
Hide the button for cleaning a directory if the directory is
empty.

Resolves: #82561
Releases: master
Change-Id: I06e76f79b1d814aa5a04a68be544a4c102d7392a
Reviewed-on: https://review.typo3.org/54215
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/install/Classes/Controller/MaintenanceController.php
typo3/sysext/install/Resources/Private/Partials/Maintenance/ClearTypo3tempFiles.html
typo3/sysext/install/Resources/Public/JavaScript/Modules/ClearTypo3tempFiles.js

index 5e23bc9..c4ef8d5 100644 (file)
@@ -53,7 +53,6 @@ class MaintenanceController extends AbstractController
         $view->assignMultiple([
             'clearAllCacheOpcodeCaches' => (new OpcodeCacheService())->getAllActive(),
             'clearTablesClearToken' => $formProtection->generateToken('installTool', 'clearTablesClear'),
-            'clearTypo3tempFilesStats' => (new Typo3tempFileService())->getDirectoryStatistics(),
             'clearTypo3tempFilesToken' => $formProtection->generateToken('installTool', 'clearTypo3tempFiles'),
             'createAdminToken' => $formProtection->generateToken('installTool', 'createAdmin'),
             'databaseAnalyzerExecuteToken' => $formProtection->generateToken('installTool', 'databaseAnalyzerExecute'),
@@ -83,6 +82,21 @@ class MaintenanceController extends AbstractController
     }
 
     /**
+     * Clear typo3temp files statistics action
+     *
+     * @return ResponseInterface
+     */
+    public function clearTypo3tempFilesStatsAction(): ResponseInterface
+    {
+        return new JsonResponse(
+            [
+                'success' => true,
+                'stats' => (new Typo3tempFileService())->getDirectoryStatistics(),
+            ]
+        );
+    }
+
+    /**
      * Clear Processed Files
      *
      * @param ServerRequestInterface $request
index c615462..3056c5b 100644 (file)
                you can use this tool to remove the "_processed_" ones.
        </p>
 
+       <div class="t3js-clearTypo3temp-output"></div>
 
-<div id="t3js-clearTypo3temp-delete-token" style="display:none;">{clearTypo3tempFilesToken}</div>
+       <button
+                       class="btn btn-default t3js-clearTypo3temp-stats"
+                       type="button"
+       >
+               Scan again
+       </button>
+       <hr>
+
+<div class="form-group">
+       <div class="t3js-clearTypo3temp-stat-container"></div>
+</div>
 
-<f:for each="{clearTypo3tempFilesStats}" as="folderStats" iteration="iterator">
-       <div class="t3js-clearTypo3temp-container t3js-clearTypo3temp-container-{folderStats.directory}">
-               <div class="t3js-clearTypo3temp-output"></div>
+<div style="display:none;">
+       <div id="t3js-clearTypo3temp-delete-token" style="display:none;">{clearTypo3tempFilesToken}</div>
+       <div class="t3js-clearTypo3temp-stat-template">
                <button
-                       class="btn btn-warning t3js-clearTypo3temp-delete" data-folder="{folderStats.directory}"
-                       type="button"
+                               class="btn btn-warning t3js-clearTypo3temp-delete"
+                               type="button"
                >
-                       Delete {folderStats.numberOfFiles} in typo3temp/assets/{folderStats.directory}
+                       Delete <span class="t3js-clearTypo3temp-stat-numberOfFiles"></span> files in
+                       typo3temp/assets/<span class="t3js-clearTypo3temp-stat-directory"></span>
                </button>
-               <f:if condition="!{iterator.isLast}">
-                       <hr />
-               </f:if>
+               <hr class="t3js-clearTypo3temp-stat-lastRuler">
        </div>
-</f:for>
+</div>
index 8e68474..93386c2 100644 (file)
@@ -25,27 +25,84 @@ define([
        'use strict';
 
        return {
+               selectorGridderOpener: 't3js-clearTypo3temp-open',
                selectorDeleteToken: '#t3js-clearTypo3temp-delete-token',
                selectorDeleteTrigger: '.t3js-clearTypo3temp-delete',
                selectorOutputContainer: '.t3js-clearTypo3temp-output',
+               selectorStatContainer: 't3js-clearTypo3temp-stat-container',
+               selectorStatsTrigger: '.t3js-clearTypo3temp-stats',
+               selectorStatTemplate: '.t3js-clearTypo3temp-stat-template',
+               selectorStatDescription: '.t3js-clearTypo3temp-stat-description',
+               selectorStatNumberOfFiles: '.t3js-clearTypo3temp-stat-numberOfFiles',
+               selectorStatDirectory: '.t3js-clearTypo3temp-stat-directory',
+               selectorStatName: '.t3js-clearTypo3temp-stat-name',
+               selectorStatLastRuler: '.t3js-clearTypo3temp-stat-lastRuler',
+
 
                initialize: function() {
                        var self = this;
-                       $(document).on('click', this.selectorDeleteTrigger, function(e) {
+                       // Load stats on first open
+                       $(document).on('cardlayout:card-opened', function () {
+                               self.getStats();
+                       });
+
+                       $(document).on('click', this.selectorStatsTrigger, function (e) {
+                               e.preventDefault();
+                               $(self.selectorOutputContainer).empty();
+                               self.getStats();
+                       });
+                       $(document).on('click', this.selectorDeleteTrigger, function (e) {
                                var folder = $(e.target).data('folder');
                                e.preventDefault();
                                self.delete(folder);
                        });
                },
 
+               getStats: function () {
+                       var self = this;
+                       var $outputContainer = $(this.selectorOutputContainer);
+                       var $statContainer = $('.' + this.selectorStatContainer);
+                       $statContainer.empty();
+                       var $statTemplate = $(this.selectorStatTemplate);
+                       var message = ProgressBar.render(Severity.loading, 'Loading...', '');
+                       $outputContainer.append(message);
+                       $.ajax({
+                               url: Router.getUrl('clearTypo3tempFilesStats'),
+                               cache: false,
+                               success: function (data) {
+                                       if (data.success === true) {
+                                               $outputContainer.find('.alert-loading').remove();
+                                               if (Array.isArray(data.stats) && data.stats.length > 0) {
+                                                       data.stats.forEach(function (element) {
+                                                               if (element.numberOfFiles > 0) {
+                                                                       var $aStat = $statTemplate.clone();
+                                                                       $aStat.find(self.selectorStatNumberOfFiles).text(element.numberOfFiles);
+                                                                       $aStat.find(self.selectorStatDirectory).text(element.directory);
+                                                                       $aStat.find(self.selectorDeleteTrigger).data('folder', element.directory);
+                                                                       $statContainer.append($aStat);
+                                                               }
+                                                       });
+                                                       $statContainer.find(self.selectorStatLastRuler + ':last').remove();
+                                               }
+                                       } else {
+                                               var message = FlashMessage.render(Severity.error, 'Something went wrong', '');
+                                               $outputContainer.append(message);
+                                       }
+                               },
+                               error: function (xhr) {
+                                       Router.handleAjaxError(xhr);
+                               }
+                       });
+               },
+
                delete: function(folder) {
-                       var $container = $('.t3js-clearTypo3temp-container-' + folder);
-                       var message = ProgressBar.render(Severity.loading, '', '');
-                       var $outputContainer = $container.find(this.selectorOutputContainer);
-                       $outputContainer.empty().html(message);
+                       var $outputContainer = $(this.selectorOutputContainer);
+                       var message = ProgressBar.render(Severity.loading, 'Loading...', '');
+                       $outputContainer.empty().append(message);
                        $.ajax({
                                method: 'POST',
                                url: Router.getUrl(),
+                               context: this,
                                data: {
                                        'install': {
                                                'action': 'clearTypo3tempFiles',
@@ -61,6 +118,7 @@ define([
                                                        var message = InfoBox.render(element.severity, element.title, element.message);
                                                        $outputContainer.html(message);
                                                });
+                                               this.getStats();
                                        } else {
                                                var message = FlashMessage.render(Severity.error, 'Something went wrong', '');
                                                $outputContainer.empty().html(message);