0013062: Allow document preview by selecting any file and pressing space
authorMichael Spahn <m.spahn@metaways.de>
Thu, 11 May 2017 08:43:13 +0000 (10:43 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 12 May 2017 13:09:41 +0000 (15:09 +0200)
https://forge.tine20.org/view.php?id=13062

Change-Id: Iacd2d88dd36f4315171c3153ffa0a9b1380b86a3
Reviewed-on: http://gerrit.tine20.com/customers/4652
Tested-by: Philipp Schüle <p.schuele@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Filemanager/Filemanager.jsb2
tine20/Filemanager/js/DocumentPreview.js [new file with mode: 0644]
tine20/Filemanager/js/Filemanager.js
tine20/Filemanager/js/NodeGridPanel.js
tine20/Tinebase/Frontend/Http/Abstract.php
tine20/Tinebase/js/Models.js

index 0451345..319bf7e 100644 (file)
         {
           "text": "GrantsPanel.js",
           "path": "js/"
+        },
+        {
+          "text": "DocumentPreview.js",
+          "path": "js/"
         }
       ]
     },
@@ -89,4 +93,4 @@
       ]
     }
   ]
-}
\ No newline at end of file
+}
diff --git a/tine20/Filemanager/js/DocumentPreview.js b/tine20/Filemanager/js/DocumentPreview.js
new file mode 100644 (file)
index 0000000..b96823d
--- /dev/null
@@ -0,0 +1,112 @@
+Ext.ns('Tine.Filemanager');
+
+Tine.Filemanager.DocumentPreview = Ext.extend(Ext.Panel, {
+    /**
+     * Node record to preview
+     */
+    record: null,
+
+    /**
+     * filemanager
+     */
+    app: null,
+
+    /**
+     * Required for overflow auto
+     */
+    autoScroll: true,
+
+    /**
+     * Overflow auto to enable scrollbar automatically
+     */
+    overflow: 'auto',
+
+    /**
+     * Layout
+     */
+    layout: 'hfit',
+
+    /**
+     * Enable scrollbar
+      */
+    containsScrollbar: true,
+
+    initComponent: function () {
+        this.addEvents(
+            /**
+             * Fires if no preview is available. Later it should be used to be fired if the browser is not able to load images.
+             */
+            'noPreviewAvailable'
+        );
+
+        Tine.Filemanager.DocumentPreview.superclass.initComponent.apply(this, arguments);
+
+        this.on('noPreviewAvailable', this.onNoPreviewAvailable.createDelegate(this));
+
+        if (!this.app) {
+            this.app = Tine.Tinebase.appMgr.get('Filemanager');
+        }
+
+        if (!this.record) {
+            this.fireEvent('noPreviewAvailable');
+            return;
+        }
+
+        this.loadPreview();
+    },
+
+    loadPreview: function () {
+        var me = this;
+
+        if ('0' === this.record.get('preview_count')) {
+            this.fireEvent('noPreviewAvailable');
+            return;
+        }
+
+        lodash.range(this.record.get('preview_count')).forEach(function (previewNumber) {
+            var path = this.record.get('path'),
+                revision = this.record.get('revision');
+
+            var url = Ext.urlEncode({
+                method: 'Filemanager.downloadPreview',
+                frontend: 'http',
+                _path: path,
+                _type: 'previews',
+                _num: previewNumber,
+                _revision: revision
+            }, Tine.Tinebase.tineInit.requestUrl + '?');
+
+            var height = this.window.height - 20,
+                width = this.window.height - 20;
+
+            me.add({
+                html: '<img style="width: 100%; height: 100%" src="' + url + '" />',
+                xtype: 'panel',
+                frame: true,
+                border: true,
+                height: height,
+                width: width
+            });
+        }, this);
+    },
+
+    /**
+     * Fires if no previews are available
+     */
+    onNoPreviewAvailable: function () {
+        this.html = '<b>' + this.app.i18n._('No preview available.') + '</b>';
+    }
+});
+
+Tine.Filemanager.DocumentPreview.openWindow = function (config) {
+    var id = (config.record && config.record.id) ? config.record.id : 0;
+    return Tine.WindowFactory.getWindow({
+        width: (screen.height * 0.8) / Math.sqrt(2), // DIN A4 and so on
+        height: screen.height * 0.8,
+        name: Tine.Filemanager.DocumentPreview.prototype.windowNamePrefix + id,
+        contentPanelConstructor: 'Tine.Filemanager.DocumentPreview',
+        contentPanelConstructorConfig: config,
+        modal: false,
+        windowType: 'Browser'
+    });
+};
index 27a17e8..a32db04 100644 (file)
@@ -99,7 +99,7 @@ Tine.Filemanager.MainScreen = Ext.extend(Tine.widgets.MainScreen, {
 Tine.Filemanager.downloadFile = function(path, revision) {
     path = lodash.get(path, 'data.path') || lodash.get(path, 'path') || path;
 
-    return downloader = new Ext.ux.file.Download({
+    return new Ext.ux.file.Download({
         params: {
             method: 'Filemanager.downloadFile',
             requestType: 'HTTP',
index 352f8cf..5759783 100644 (file)
@@ -318,6 +318,23 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
     },
 
     /**
+     * Capture space to toggle document preview
+     */
+    onKeyDown: function(e) {
+        Tine.Filemanager.NodeGridPanel.superclass.onKeyDown.apply(this, arguments);
+
+        var sm = this.selectionModel,
+            node = sm.getSelected();
+
+        // Open preview on space if a node is selected and the node type equals file
+        if (e.getKey() === 32 && node && node.get('type') === 'file') {
+            Tine.Filemanager.DocumentPreview.openWindow({
+                record: node
+            });
+        }
+    },
+
+    /**
      * init ext grid panel
      * @private
      */
index 5d36237..68b8385 100644 (file)
@@ -123,14 +123,19 @@ abstract class Tinebase_Frontend_Http_Abstract extends Tinebase_Frontend_Abstrac
     {
         $fileSystem = Tinebase_FileSystem::getInstance();
 
-        $this->_prepareHeader($_node->name, $_node->contenttype, 'inline');
-
         $previewNode = Tinebase_FileSystem_Previews::getInstance()->getPreviewForNode($_node, $_type, $_num);
+
+        $this->_prepareHeader($previewNode->name, $previewNode->contenttype, 'inline');
+
+
         $handle = fopen($fileSystem->getRealPathForHash($previewNode->hash), 'r');
+
         if (false === $handle) {
             throw new Tinebase_Exception_NotFound('could not open preview by real path for hash');
         }
+
         fpassthru($handle);
+
         fclose($handle);
     }
 
index 0a07903..a01a2a4 100644 (file)
@@ -499,6 +499,7 @@ Tine.Tinebase.Model.Tree_NodeArray = Tine.Tinebase.Model.modlogFields.concat([
     { name: 'acl_node' },
     { name: 'object_id'},
     { name: 'revision_size', label: 'Revision Size' }, // _('Revision Size')
+    { name: 'preview_count', label: 'Preview Count' }, // _('Preview Count')
 
     { name: 'relations' },
     { name: 'customfields' },