From: Christos Stathis Date: Thu, 15 Sep 2011 14:49:55 +0000 (+0300) Subject: Correctly display usage statistics upon login X-Git-Tag: v0.1~149 X-Git-Url: https://code.grnet.gr/git/pithos-web-client/commitdiff_plain/bf664298ddfff93b729b12f9d0e39e35727a9802 Correctly display usage statistics upon login --- diff --git a/src/gr/grnet/pithos/web/client/Pithos.java b/src/gr/grnet/pithos/web/client/Pithos.java index efeb5a3..08fe20e 100644 --- a/src/gr/grnet/pithos/web/client/Pithos.java +++ b/src/gr/grnet/pithos/web/client/Pithos.java @@ -268,6 +268,14 @@ public class Pithos implements EntryPoint, ResizeHandler { private List selectionModels = new ArrayList(); 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: ")); + totalFiles = new HTML(); + statistics.add(totalFiles); + statistics.add(new HTML(" | Used: ")); + usedBytes = new HTML(); + statistics.add(usedBytes); + statistics.add(new HTML(" of ")); + totalBytes = new HTML(); + statistics.add(totalBytes); + statistics.add(new HTML(" (")); + 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 diff --git a/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java b/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java index 18d781c..fd28267 100644 --- a/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java +++ b/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java @@ -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 getGroups() { @@ -247,4 +248,8 @@ public class AccountResource extends Resource { } return null; } + + public double getUsedPercentage() { + return 100.0 * bytesUsed / (bytesUsed + bytesRemaining); + } }