Correctly display usage statistics upon login
authorChristos Stathis <chstath@ebs.gr>
Thu, 15 Sep 2011 14:49:55 +0000 (17:49 +0300)
committerChristos Stathis <chstath@ebs.gr>
Thu, 15 Sep 2011 14:49:55 +0000 (17:49 +0300)
src/gr/grnet/pithos/web/client/Pithos.java
src/gr/grnet/pithos/web/client/foldertree/AccountResource.java

index efeb5a3..08fe20e 100644 (file)
@@ -268,6 +268,14 @@ public class Pithos implements EntryPoint, ResizeHandler {
        private List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>();
     
     Button upload;
+    
+    private HTML totalFiles;
+    
+    private HTML usedBytes;
+    
+    private HTML totalBytes;
+    
+    private HTML usedPercent;
 
        @Override
        public void onModuleLoad() {
@@ -371,7 +379,21 @@ public class Pithos implements EntryPoint, ResizeHandler {
         
         HorizontalPanel treeHeader = new HorizontalPanel();
         treeHeader.addStyleName("pithos-treeHeader");
-        treeHeader.add(new HTML("Total Files: 6 | Used: 2.1 of 50 GB (4.2%)"));
+        HorizontalPanel statistics = new HorizontalPanel();
+        statistics.add(new HTML("Total Files:&nbsp;"));
+        totalFiles = new HTML();
+        statistics.add(totalFiles);
+        statistics.add(new HTML("&nbsp;|&nbsp;Used:&nbsp;"));
+        usedBytes = new HTML();
+        statistics.add(usedBytes);
+        statistics.add(new HTML("&nbsp;of&nbsp;"));
+        totalBytes = new HTML();
+        statistics.add(totalBytes);
+        statistics.add(new HTML("&nbsp;("));
+        usedPercent = new HTML();
+        statistics.add(usedPercent);
+        statistics.add(new HTML("%)"));
+        treeHeader.add(statistics);
         trees.add(treeHeader);
 
         trees.add(folderTreeView);
@@ -534,6 +556,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                                }
                     folderTreeViewModel.initialize(account);
                     groupTreeViewModel.initialize();
+                    updateStatistics();
                 }
             }
 
@@ -550,7 +573,14 @@ public class Pithos implements EntryPoint, ResizeHandler {
         Scheduler.get().scheduleDeferred(getAccount);
     }
 
-    protected void createHomeContainer(final AccountResource account) {
+    protected void updateStatistics() {
+       totalFiles.setHTML(String.valueOf(account.getNumberOfObjects()));
+       usedBytes.setHTML(String.valueOf(account.getFileSizeAsString()));
+       totalBytes.setHTML(String.valueOf(account.getQuotaAsString()));
+       usedPercent.setHTML(String.valueOf(account.getUsedPercentage()));
+       }
+
+       protected void createHomeContainer(final AccountResource account) {
         String path = "/" + Pithos.HOME_CONTAINER;
         PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
             @Override
index 18d781c..fd28267 100644 (file)
@@ -204,14 +204,15 @@ public class AccountResource extends Resource {
         return getSize(bytesUsed , (1024D*1024D*1024D)) + " GB";
     }
 
-    public String getQuotaLeftAsString() {
-        if (bytesRemaining < 1024)
-            return String.valueOf(bytesRemaining) + " B";
-        else if (bytesRemaining < 1024 * 1024)
-            return getSize(bytesRemaining, 1024D) + " KB";
-        else if (bytesRemaining < 1024 * 1024 * 1024)
-            return getSize(bytesRemaining,(1024D * 1024D)) + " MB";
-        return getSize(bytesRemaining , (1024D * 1024D * 1024D)) + " GB";
+    public String getQuotaAsString() {
+       long quota = bytesUsed + bytesRemaining;
+        if (quota < 1024)
+            return String.valueOf(quota) + " B";
+        else if (quota < 1024 * 1024)
+            return getSize(quota, 1024D) + " KB";
+        else if (quota < 1024 * 1024 * 1024)
+            return getSize(quota,(1024D * 1024D)) + " MB";
+        return getSize(quota , (1024D * 1024D * 1024D)) + " GB";
     }
 
     public List<Group> getGroups() {
@@ -247,4 +248,8 @@ public class AccountResource extends Resource {
                }
                return null;
        }
+
+       public double getUsedPercentage() {
+               return 100.0 * bytesUsed / (bytesUsed + bytesRemaining);
+       }
 }