]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fixed storage stats to be based on current directory
authorVincent Petry <pvince81@owncloud.com>
Wed, 6 Nov 2013 09:55:19 +0000 (10:55 +0100)
committerVincent Petry <pvince81@owncloud.com>
Wed, 6 Nov 2013 09:55:19 +0000 (10:55 +0100)
Previously, the storage statistics were always for the root dir.
This means that the upload button would always show the limit for the
root dir, even when uploading to a shared dir or external storage.

This fix adds a "dir" argument to getstoragestats.php.

apps/files/ajax/getstoragestats.php
apps/files/js/filelist.js
apps/files/js/files.js

index 32a77bff6c3054961a364ce1561b5c5e82f04f85..dd7c7dc5571c09c2ecac5442f27ce2495f8e641b 100644 (file)
@@ -3,7 +3,13 @@
 // only need filesystem apps
 $RUNTIME_APPTYPES = array('filesystem');
 
+$dir = '/';
+
+if (isset($_GET['dir'])) {
+       $dir = $_GET['dir'];
+}
+
 OCP\JSON::checkLoggedIn();
 
 // send back json
-OCP\JSON::success(array('data' => \OCA\Files\Helper::buildFileStorageStatistics('/')));
+OCP\JSON::success(array('data' => \OCA\Files\Helper::buildFileStorageStatistics($dir)));
index 66b4a006f8869fc308af6fcb692b88e278863227..006bd1f4966e0789837a33ec1de2786a623480c0 100644 (file)
@@ -152,6 +152,9 @@ var FileList={
                FileActions.display(tr.find('td.filename'), true);
                return tr;
        },
+       getCurrentDirectory: function(){
+               return $('#dir').val() || '/';
+       },
        /**
         * @brief Changes the current directory and reload the file list.
         * @param targetDir target directory (non URL encoded)
@@ -224,6 +227,10 @@ var FileList={
                        return;
                }
 
+               // TODO: should rather return upload file size through
+               // the files list ajax call
+               Files.updateStorageStatistics(true);
+
                if (result.data.permissions) {
                        FileList.setDirectoryPermissions(result.data.permissions);
                }
index a7aea0957bdc7870c84e30fa09721f1bc32dc656..2947512ece5b9bdc6fe8404c295df09c5fbe202b 100644 (file)
@@ -2,16 +2,23 @@ Files={
        // file space size sync
        _updateStorageStatistics: function() {
                Files._updateStorageStatisticsTimeout = null;
-               if (Files.updateStorageStatistics.running){
-                       return;
+               var currentDir = FileList.getCurrentDirectory(),
+                       state = Files.updateStorageStatistics;
+               if (state.dir){
+                       if (state.dir === currentDir) {
+                               return;
+                       }
+                       // cancel previous call, as it was for another dir
+                       state.call.abort();
                }
-               Files.updateStorageStatistics.running = true;
-               $.getJSON(OC.filePath('files','ajax','getstoragestats.php'),function(response) {
-                       Files.updateStorageStatistics.running = false;
+               state.dir = currentDir;
+               state.call = $.getJSON(OC.filePath('files','ajax','getstoragestats.php') + '?dir=' + encodeURIComponent(currentDir),function(response) {
+                       state.dir = null;
+                       state.call = null;
                        Files.updateMaxUploadFilesize(response);
                });
        },
-       updateStorageStatistics: function() {
+       updateStorageStatistics: function(force) {
                if (!OC.currentUser) {
                        return;
                }
@@ -20,7 +27,12 @@ Files={
                if (Files._updateStorageStatisticsTimeout) {
                        clearTimeout(Files._updateStorageStatisticsTimeout);
                }
-               Files._updateStorageStatisticsTimeout = setTimeout(Files._updateStorageStatistics, 1000);
+               if (force) {
+                       Files._updateStorageStatistics();
+               }
+               else {
+                       Files._updateStorageStatisticsTimeout = setTimeout(Files._updateStorageStatistics, 250);
+               }
        },
 
        updateMaxUploadFilesize:function(response) {