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
Loading
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -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) {
        int u = 0;
        for (; bytes > 1024 * 1024; bytes >>= 10) {
            u++;
        if (bytes < 1024) {
            return bytes + " B";
        }
        if (bytes > 1024) {
            u++;
        }
        return String.format("%.1f %cB", bytes / 1024f, " kMGTPE".charAt(u));
        int z = (63 - Long.numberOfLeadingZeros(bytes)) / 10;
        return String.format("%.1f %sB", (double) bytes / (1L << (z * 10)), " KMGTPE".charAt(z));
    }

    public boolean isFolder() {
+16 −13
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ package it.inaf.ia2.vospace.ui.service;
import it.inaf.ia2.aa.data.User;
import it.inaf.ia2.vospace.ui.client.VOSpaceClient;
import it.inaf.ia2.vospace.ui.data.ListNodeData;
import it.inaf.oats.vospace.datamodel.NodeProperties;
import it.inaf.oats.vospace.datamodel.NodeUtils;
import java.io.IOException;
import java.io.StringWriter;
@@ -85,10 +84,11 @@ public class NodesService {
    }

    private String getIcon(NodeInfo nodeInfo) {
        String html = "<span class=\"icon ";
        if (nodeInfo.isFile() && nodeInfo.isBusy()) {
            html += "gear";
        } else {
        String html = "";
        if (nodeInfo.isBusy()) {
            html += "<span class=\"node-busy\"><span role=\"status\" class=\"spinner-border\"><span class=\"sr-only\">Loading...</span></span>";
        }
        html += "<span class=\"icon ";
        if (nodeInfo.isFolder()) {
            html += "folder";
        } else {
@@ -97,8 +97,11 @@ public class NodesService {
        if (nodeInfo.isAsyncTrans()) {
            html += "-x";
        }
        html += "-icon\"></span>";
        if (nodeInfo.isBusy()) {
            html += "</span>";
        }
        html += "-icon\"></span>&nbsp;";
        html += "&nbsp;";
        return html;
    }

+67 −0
Original line number Diff line number Diff line
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);
    }
}
+17 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
<script>
import { mapState } from 'vuex'
import TopMenu from './components/TopMenu.vue'
import client from 'api-client'

export default {
  name: 'App',
@@ -32,6 +33,7 @@ export default {
  mounted() {
    this.$store.dispatch('loadJobs');
    this.$store.dispatch('loadUserInfo');
    setInterval(client.keepalive, 60000);
  }
}
</script>
@@ -78,4 +80,19 @@ export default {
  height: 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>
+3 −0
Original line number Diff line number Diff line
@@ -57,5 +57,8 @@ export default {
  },
  deleteNode() {
    return fetch({});
  },
  keepalive() {
    return fetch({});    
  }
}
Loading