From a33ddf373bc8a83ec7d440b46710642e26171800 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 21 Oct 2015 12:40:09 +0200 Subject: move file storage quota display to upload section. add a warning if remaining space is less than 100MB and fix % calculation --- include/RedDAV/RedBrowser.php | 55 +++++++++++++++++++++-------------------- view/tpl/cloud_actionspanel.tpl | 1 + view/tpl/cloud_header.tpl | 1 - 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/include/RedDAV/RedBrowser.php b/include/RedDAV/RedBrowser.php index d74bba220..c96b98742 100644 --- a/include/RedDAV/RedBrowser.php +++ b/include/RedDAV/RedBrowser.php @@ -217,31 +217,6 @@ class RedBrowser extends DAV\Browser\Plugin { $f[] = $ft; } - // Storage and quota for the account (all channels of the owner of this directory)! - $limit = service_class_fetch($owner, 'attach_upload_limit'); - $r = q("SELECT SUM(filesize) AS total FROM attach WHERE aid = %d", - intval($this->auth->channel_account_id) - ); - $used = $r[0]['total']; - if ($used) { - $quotaDesc = t('%1$s used'); - $quotaDesc = sprintf($quotaDesc, - userReadableSize($used)); - } - if ($limit && $used) { - $quotaDesc = t('%1$s used of %2$s (%3$s%)'); - $quotaDesc = sprintf($quotaDesc, - userReadableSize($used), - userReadableSize($limit), - round($used / $limit, 1)); - } - - // prepare quota for template - $quota = array(); - $quota['used'] = $used; - $quota['limit'] = $limit; - $quota['desc'] = $quotaDesc; - $output = ''; if ($this->enablePost) { $this->server->broadcastEvent('onHTMLActionsPanel', array($parent, &$output)); @@ -249,7 +224,6 @@ class RedBrowser extends DAV\Browser\Plugin { $html .= replace_macros(get_markup_template('cloud.tpl'), array( '$header' => t('Files') . ": " . $this->escapeHTML($path) . "/", - '$quota' => $quota, '$total' => t('Total'), '$actionspanel' => $output, '$shared' => t('Shared'), @@ -298,11 +272,38 @@ class RedBrowser extends DAV\Browser\Plugin { if (get_class($node) === 'Sabre\\DAV\\SimpleCollection') return; + // Storage and quota for the account (all channels of the owner of this directory)! + $limit = service_class_fetch($owner, 'attach_upload_limit'); + $r = q("SELECT SUM(filesize) AS total FROM attach WHERE aid = %d", + intval($this->auth->channel_account_id) + ); + $used = $r[0]['total']; + if ($used) { + $quotaDesc = t('You are using %1$s of your available file storage.'); + $quotaDesc = sprintf($quotaDesc, + userReadableSize($used)); + } + if ($limit && $used) { + $quotaDesc = t('You are using %1$s of %2$s available file storage. (%3$s%)'); + $quotaDesc = sprintf($quotaDesc, + userReadableSize($used), + userReadableSize($limit), + round($used / $limit, 1) * 100); + } + + // prepare quota for template + $quota = array(); + $quota['used'] = $used; + $quota['limit'] = $limit; + $quota['desc'] = $quotaDesc; + $quota['warning'] = (($limit && ($limit - $used) < 104857600) ? true : false); // 10485760 bytes = 100MB + $output .= replace_macros(get_markup_template('cloud_actionspanel.tpl'), array( '$folder_header' => t('Create new folder'), '$folder_submit' => t('Create'), '$upload_header' => t('Upload file'), - '$upload_submit' => t('Upload') + '$upload_submit' => t('Upload'), + '$quota' => $quota )); } diff --git a/view/tpl/cloud_actionspanel.tpl b/view/tpl/cloud_actionspanel.tpl index da708a98c..4d2afa8ef 100644 --- a/view/tpl/cloud_actionspanel.tpl +++ b/view/tpl/cloud_actionspanel.tpl @@ -8,6 +8,7 @@
+ {{if $quota.limit || $quota.used}}{{/if}}
diff --git a/view/tpl/cloud_header.tpl b/view/tpl/cloud_header.tpl index 0786b46ba..076fa16cb 100644 --- a/view/tpl/cloud_header.tpl +++ b/view/tpl/cloud_header.tpl @@ -9,7 +9,6 @@
{{/if}}

{{$header}}

- {{if $quota.limit || $quota.used}}{{$quota.desc}}{{/if}}
{{if $actionspanel}} -- cgit v1.2.3 From 232742a5e6c2912fe53249465d5fe31ef3b9722f Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 21 Oct 2015 12:52:03 +0200 Subject: warn if quota exceeds 90% of storage limit --- include/RedDAV/RedBrowser.php | 2 +- view/tpl/cloud_actionspanel.tpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/RedDAV/RedBrowser.php b/include/RedDAV/RedBrowser.php index c96b98742..efea5d92f 100644 --- a/include/RedDAV/RedBrowser.php +++ b/include/RedDAV/RedBrowser.php @@ -296,7 +296,7 @@ class RedBrowser extends DAV\Browser\Plugin { $quota['used'] = $used; $quota['limit'] = $limit; $quota['desc'] = $quotaDesc; - $quota['warning'] = (($limit && ($limit - $used) < 104857600) ? true : false); // 10485760 bytes = 100MB + $quota['warning'] = ((($limit) && ((round($used / $limit, 1) * 100) >= 90)) ? t('WARNING:') : ''); // 10485760 bytes = 100MB $output .= replace_macros(get_markup_template('cloud_actionspanel.tpl'), array( '$folder_header' => t('Create new folder'), diff --git a/view/tpl/cloud_actionspanel.tpl b/view/tpl/cloud_actionspanel.tpl index 4d2afa8ef..44e4eb54c 100644 --- a/view/tpl/cloud_actionspanel.tpl +++ b/view/tpl/cloud_actionspanel.tpl @@ -8,7 +8,7 @@
- {{if $quota.limit || $quota.used}}{{/if}} + {{if $quota.limit || $quota.used}}{{/if}} -- cgit v1.2.3