forked from radiantearth/stac-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZarrMetadataTab.vue
68 lines (66 loc) · 1.88 KB
/
ZarrMetadataTab.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<template>
<div>
<div v-if="loading" class="mt-2"></div>
<div v-else-if="errored" class="mt-2">
<p>An error has occurred while loading while loading Zarr metadata.</p>
<p>Check the console.</p>
</div>
<ZarrGroup v-else :group="group" :group-name="root"></ZarrGroup>
</div>
</template>
<script>
import ZarrGroup from "./ZarrGroup.vue";
import fetch from "node-fetch";
export default {
name: "ZarrMetadataTab",
components: { ZarrGroup },
props: ["zarrMetadataUrl"],
data() {
return {
loading: true,
errored: false,
error: null,
group: {}
};
},
mounted() {
fetch(this.zarrMetadataUrl)
.then(rsp => rsp.json())
.then(data => (this.group = this.parseMeta(data.metadata)))
.catch(err => {
console.error(err);
this.errored = true;
})
.finally(() => (this.loading = false));
},
methods: {
parseMeta: function(meta) {
const group = { groups: {}, arrays: {}, attrs: meta[".zattrs"] || {} };
for (const prop in meta)
if (!prop.endsWith(".zattrs")) {
prop
.split("/")
.slice(0, -1)
.reduce((pre, cur, idx, arr) => {
if (idx == arr.length - 1) {
if (prop.endsWith(".zgroup"))
return (pre.groups[cur] = {
groups: {},
arrays: {},
attrs: meta[prop.replace(".zgroup", ".zattrs")] || {}
});
else
return (pre.arrays[cur] = {
dtype: meta[prop].dtype,
shape: meta[prop].shape,
chunks: meta[prop].chunks,
attrs: meta[prop.replace(".zarray", ".zattrs")] || {}
});
} else return pre.groups[cur];
}, group);
}
return group;
}
}
};
</script>