Skip to content
Snippets Groups Projects
Commit 6ef14f6d authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Fixed file size bug; called keepalive endpoint for refreshing tokens; improved icon for busy nodes

parent 6c44a945
No related branches found
No related tags found
No related merge requests found
Pipeline #997 passed
...@@ -128,17 +128,14 @@ public class NodeInfo { ...@@ -128,17 +128,14 @@ public class NodeInfo {
} }
/** /**
* Credits: https://stackoverflow.com/a/16576773/771431 * Credits: https://stackoverflow.com/a/24805871/771431
*/ */
private String getHumanReadableSize(long bytes) { private String getHumanReadableSize(long bytes) {
int u = 0; if (bytes < 1024) {
for (; bytes > 1024 * 1024; bytes >>= 10) { return bytes + " B";
u++;
} }
if (bytes > 1024) { int z = (63 - Long.numberOfLeadingZeros(bytes)) / 10;
u++; return String.format("%.1f %sB", (double) bytes / (1L << (z * 10)), " KMGTPE".charAt(z));
}
return String.format("%.1f %cB", bytes / 1024f, " kMGTPE".charAt(u));
} }
public boolean isFolder() { public boolean isFolder() {
......
...@@ -3,7 +3,6 @@ package it.inaf.ia2.vospace.ui.service; ...@@ -3,7 +3,6 @@ package it.inaf.ia2.vospace.ui.service;
import it.inaf.ia2.aa.data.User; import it.inaf.ia2.aa.data.User;
import it.inaf.ia2.vospace.ui.client.VOSpaceClient; import it.inaf.ia2.vospace.ui.client.VOSpaceClient;
import it.inaf.ia2.vospace.ui.data.ListNodeData; import it.inaf.ia2.vospace.ui.data.ListNodeData;
import it.inaf.oats.vospace.datamodel.NodeProperties;
import it.inaf.oats.vospace.datamodel.NodeUtils; import it.inaf.oats.vospace.datamodel.NodeUtils;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
...@@ -85,10 +84,11 @@ public class NodesService { ...@@ -85,10 +84,11 @@ public class NodesService {
} }
private String getIcon(NodeInfo nodeInfo) { private String getIcon(NodeInfo nodeInfo) {
String html = "<span class=\"icon "; String html = "";
if (nodeInfo.isFile() && nodeInfo.isBusy()) { if (nodeInfo.isBusy()) {
html += "gear"; html += "<span class=\"node-busy\"><span role=\"status\" class=\"spinner-border\"><span class=\"sr-only\">Loading...</span></span>";
} else { }
html += "<span class=\"icon ";
if (nodeInfo.isFolder()) { if (nodeInfo.isFolder()) {
html += "folder"; html += "folder";
} else { } else {
...@@ -97,8 +97,11 @@ public class NodesService { ...@@ -97,8 +97,11 @@ public class NodesService {
if (nodeInfo.isAsyncTrans()) { if (nodeInfo.isAsyncTrans()) {
html += "-x"; html += "-x";
} }
html += "-icon\"></span>";
if (nodeInfo.isBusy()) {
html += "</span>";
} }
html += "-icon\"></span>&nbsp;"; html += "&nbsp;";
return html; return html;
} }
......
package it.inaf.ia2.vospace.ui.service;
import net.ivoa.xml.vospace.v2.DataNode;
import net.ivoa.xml.vospace.v2.Node;
import net.ivoa.xml.vospace.v2.Property;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class NodeInfoTest {
private static final String AUTHORITY = "example.com!vospace";
@Test
public void testZero() {
testNodeLength(0, "0 B");
}
@Test
public void testSizeBytes() {
testNodeLength(5, "5 B");
}
@Test
public void testSizeKilo() {
testNodeLength(1024, "1.0 KB");
}
@Test
public void testSizeMega() {
testNodeLength(149639144, "142.7 MB");
}
@Test
public void testSizeGiga() {
testNodeLength(483286324544L, "450.1 GB");
}
@Test
public void testSizeTera() {
testNodeLength(6963696737140L, "6.3 TB");
}
@Test
public void testSizePeta() {
testNodeLength(6963696737150000L, "6.2 PB");
}
private void testNodeLength(long bytes, String expectedText) {
DataNode node = getDataNode();
setLength(node, bytes);
NodeInfo nodeInfo = new NodeInfo(node, AUTHORITY);
assertEquals(expectedText, nodeInfo.getSize());
}
private DataNode getDataNode() {
DataNode node = new DataNode();
node.setUri("vos://example.com!vospace/mynode");
return node;
}
private void setLength(Node node, long length) {
Property lengthProperty = new Property();
lengthProperty.setUri("ivo://ivoa.net/vospace/core#length");
lengthProperty.setValue(String.valueOf(length));
node.getProperties().add(lengthProperty);
}
}
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<script> <script>
import { mapState } from 'vuex' import { mapState } from 'vuex'
import TopMenu from './components/TopMenu.vue' import TopMenu from './components/TopMenu.vue'
import client from 'api-client'
export default { export default {
name: 'App', name: 'App',
...@@ -32,6 +33,7 @@ export default { ...@@ -32,6 +33,7 @@ export default {
mounted() { mounted() {
this.$store.dispatch('loadJobs'); this.$store.dispatch('loadJobs');
this.$store.dispatch('loadUserInfo'); this.$store.dispatch('loadUserInfo');
setInterval(client.keepalive, 60000);
} }
} }
</script> </script>
...@@ -78,4 +80,19 @@ export default { ...@@ -78,4 +80,19 @@ export default {
height: 100%; height: 100%;
width: 100%; width: 100%;
} }
.node-busy {
position: relative;
padding-right: 3px;
}
.node-busy .spinner-border {
position: absolute;
left: -5px;
font-size: 7px;
height: 26px;
width: 26px;
top: -7px;
color: #3293f2;
}
</style> </style>
...@@ -57,5 +57,8 @@ export default { ...@@ -57,5 +57,8 @@ export default {
}, },
deleteNode() { deleteNode() {
return fetch({}); return fetch({});
},
keepalive() {
return fetch({});
} }
} }
...@@ -136,5 +136,16 @@ export default { ...@@ -136,5 +136,16 @@ export default {
'Cache-Control': 'no-cache' 'Cache-Control': 'no-cache'
} }
}, true, true); }, true, true);
},
keepalive() {
let url = BASE_API_URL + 'keepalive';
return apiRequest({
method: 'GET',
url: url,
withCredentials: true,
headers: {
'Cache-Control': 'no-cache'
}
}, false, false);
} }
} }
...@@ -32,7 +32,3 @@ ...@@ -32,7 +32,3 @@
.folder-link-icon { .folder-link-icon {
background-image: url("data:image/svg+xml,%3Csvg data-v-41be6633='' viewBox='0 0 16 16' width='1em' height='1em' focusable='false' role='img' aria-label='folder symlink' xmlns='http://www.w3.org/2000/svg' fill='currentColor' class='bi-folder-symlink mx-auto b-icon bi'%3E%3Cg data-v-41be6633=''%3E%3Cpath d='M11.798 8.271l-3.182 1.97c-.27.166-.616-.036-.616-.372V9.1s-2.571-.3-4 2.4c.571-4.8 3.143-4.8 4-4.8v-.769c0-.336.346-.538.616-.371l3.182 1.969c.27.166.27.576 0 .742z'%3E%3C/path%3E%3Cpath d='M.5 3l.04.87a1.99 1.99 0 0 0-.342 1.311l.637 7A2 2 0 0 0 2.826 14h10.348a2 2 0 0 0 1.991-1.819l.637-7A2 2 0 0 0 13.81 3H9.828a2 2 0 0 1-1.414-.586l-.828-.828A2 2 0 0 0 6.172 1H2.5a2 2 0 0 0-2 2zm.694 2.09A1 1 0 0 1 2.19 4h11.62a1 1 0 0 1 .996 1.09l-.636 7a1 1 0 0 1-.996.91H2.826a1 1 0 0 1-.995-.91l-.637-7zM6.172 2a1 1 0 0 1 .707.293L7.586 3H2.19c-.24 0-.47.042-.684.12L1.5 2.98a1 1 0 0 1 1-.98h3.672z'%3E%3C/path%3E%3C/g%3E%3C/svg%3E"); background-image: url("data:image/svg+xml,%3Csvg data-v-41be6633='' viewBox='0 0 16 16' width='1em' height='1em' focusable='false' role='img' aria-label='folder symlink' xmlns='http://www.w3.org/2000/svg' fill='currentColor' class='bi-folder-symlink mx-auto b-icon bi'%3E%3Cg data-v-41be6633=''%3E%3Cpath d='M11.798 8.271l-3.182 1.97c-.27.166-.616-.036-.616-.372V9.1s-2.571-.3-4 2.4c.571-4.8 3.143-4.8 4-4.8v-.769c0-.336.346-.538.616-.371l3.182 1.969c.27.166.27.576 0 .742z'%3E%3C/path%3E%3Cpath d='M.5 3l.04.87a1.99 1.99 0 0 0-.342 1.311l.637 7A2 2 0 0 0 2.826 14h10.348a2 2 0 0 0 1.991-1.819l.637-7A2 2 0 0 0 13.81 3H9.828a2 2 0 0 1-1.414-.586l-.828-.828A2 2 0 0 0 6.172 1H2.5a2 2 0 0 0-2 2zm.694 2.09A1 1 0 0 1 2.19 4h11.62a1 1 0 0 1 .996 1.09l-.636 7a1 1 0 0 1-.996.91H2.826a1 1 0 0 1-.995-.91l-.637-7zM6.172 2a1 1 0 0 1 .707.293L7.586 3H2.19c-.24 0-.47.042-.684.12L1.5 2.98a1 1 0 0 1 1-.98h3.672z'%3E%3C/path%3E%3C/g%3E%3C/svg%3E");
} }
.gear-icon {
background-image: url("data:image/svg+xml,%3Csvg data-v-41be6633='' viewBox='0 0 16 16' width='1em' height='1em' focusable='false' role='img' aria-label='gear' xmlns='http://www.w3.org/2000/svg' fill='currentColor' class='bi-gear mx-auto b-icon bi'%3E%3Cg data-v-41be6633=''%3E%3Cpath d='M8 4.754a3.246 3.246 0 1 0 0 6.492 3.246 3.246 0 0 0 0-6.492zM5.754 8a2.246 2.246 0 1 1 4.492 0 2.246 2.246 0 0 1-4.492 0z'%3E%3C/path%3E%3Cpath d='M9.796 1.343c-.527-1.79-3.065-1.79-3.592 0l-.094.319a.873.873 0 0 1-1.255.52l-.292-.16c-1.64-.892-3.433.902-2.54 2.541l.159.292a.873.873 0 0 1-.52 1.255l-.319.094c-1.79.527-1.79 3.065 0 3.592l.319.094a.873.873 0 0 1 .52 1.255l-.16.292c-.892 1.64.901 3.434 2.541 2.54l.292-.159a.873.873 0 0 1 1.255.52l.094.319c.527 1.79 3.065 1.79 3.592 0l.094-.319a.873.873 0 0 1 1.255-.52l.292.16c1.64.893 3.434-.902 2.54-2.541l-.159-.292a.873.873 0 0 1 .52-1.255l.319-.094c1.79-.527 1.79-3.065 0-3.592l-.319-.094a.873.873 0 0 1-.52-1.255l.16-.292c.893-1.64-.902-3.433-2.541-2.54l-.292.159a.873.873 0 0 1-1.255-.52l-.094-.319zm-2.633.283c.246-.835 1.428-.835 1.674 0l.094.319a1.873 1.873 0 0 0 2.693 1.115l.291-.16c.764-.415 1.6.42 1.184 1.185l-.159.292a1.873 1.873 0 0 0 1.116 2.692l.318.094c.835.246.835 1.428 0 1.674l-.319.094a1.873 1.873 0 0 0-1.115 2.693l.16.291c.415.764-.42 1.6-1.185 1.184l-.291-.159a1.873 1.873 0 0 0-2.693 1.116l-.094.318c-.246.835-1.428.835-1.674 0l-.094-.319a1.873 1.873 0 0 0-2.692-1.115l-.292.16c-.764.415-1.6-.42-1.184-1.185l.159-.291A1.873 1.873 0 0 0 1.945 8.93l-.319-.094c-.835-.246-.835-1.428 0-1.674l.319-.094A1.873 1.873 0 0 0 3.06 4.377l-.16-.292c-.415-.764.42-1.6 1.185-1.184l.292.159a1.873 1.873 0 0 0 2.692-1.115l.094-.319z'%3E%3C/path%3E%3C/g%3E%3C/svg%3E");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment