retrieve and display types (basic)
parent
d544e31800
commit
68c808ad5b
|
@ -42,6 +42,33 @@ export function useEntity(address: string | (() => string), condition?: () => Bo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function query(query: string | (() => string), condition?: () => Boolean) {
|
||||||
|
const { data, error, mutate } = useSWRV<ListingResult, unknown>(
|
||||||
|
() => (condition === undefined || condition()) ? `/api/obj?query=${typeof query === "string" ? query : query()}` : null,
|
||||||
|
fetcher
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = computed(() => {
|
||||||
|
if (data?.value) {
|
||||||
|
const entries = Object.entries(data.value) as [string, IEntry][];
|
||||||
|
return entries
|
||||||
|
.sort(([_, a], [__, b]) => String(a.value.c).localeCompare(b.value.c))
|
||||||
|
.sort(([_, a], [__, b]) => String(a.value.t).localeCompare(b.value.t))
|
||||||
|
.sort(([_, a], [__, b]) => a.attribute.localeCompare(b.attribute));
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
result,
|
||||||
|
data,
|
||||||
|
error,
|
||||||
|
mutate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface EntityIdentification {
|
interface EntityIdentification {
|
||||||
type: string;
|
type: string;
|
||||||
value: string;
|
value: string;
|
||||||
|
@ -86,4 +113,4 @@ export function identify(attributes: ComputedRef<[string, IEntry][]>): ComputedR
|
||||||
})
|
})
|
||||||
}).flat();
|
}).flat();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,4 +28,8 @@ export interface IFile {
|
||||||
export interface VaultInfo {
|
export interface VaultInfo {
|
||||||
name: string | null;
|
name: string | null;
|
||||||
location: string;
|
location: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IType {
|
||||||
|
name?: string;
|
||||||
}
|
}
|
|
@ -9,6 +9,14 @@
|
||||||
<blob-preview :address="address" />
|
<blob-preview :address="address" />
|
||||||
<div v-if="!error">
|
<div v-if="!error">
|
||||||
<template v-if="attributes.length">
|
<template v-if="attributes.length">
|
||||||
|
<section class="types">
|
||||||
|
<h3>Types</h3>
|
||||||
|
<ul>
|
||||||
|
<li v-for="type, key in types" :key="key">
|
||||||
|
{{ type.name || "???" }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
<h3>Own attributes ({{ attributes.length }})</h3>
|
<h3>Own attributes ({{ attributes.length }})</h3>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -72,8 +80,9 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Address from "@/components/Address.vue";
|
import Address from "@/components/Address.vue";
|
||||||
import BlobPreview from "@/components/BlobPreview.vue";
|
import BlobPreview from "@/components/BlobPreview.vue";
|
||||||
import { useEntity } from "@/lib/entity";
|
import { query, useEntity } from "@/lib/entity";
|
||||||
import { defineComponent } from "vue";
|
import { IEntry, IType } from "@/types/base";
|
||||||
|
import { computed, defineComponent } from "vue";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "Inspect",
|
name: "Inspect",
|
||||||
|
@ -125,11 +134,50 @@ export default defineComponent({
|
||||||
() => props.address
|
() => props.address
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const allTypeAddresses = computed(() => {
|
||||||
|
return attributes.value
|
||||||
|
.map(([_, attr]) => attr)
|
||||||
|
.filter((attr) => attr.attribute == "IS")
|
||||||
|
.map((attr) => attr.value.c);
|
||||||
|
});
|
||||||
|
|
||||||
|
const { result: allTypeEntries } = query(
|
||||||
|
() =>
|
||||||
|
`(matches (in ${allTypeAddresses.value
|
||||||
|
.map((addr) => `"${addr}"`)
|
||||||
|
.join(" ")}) ? ?)`,
|
||||||
|
() => allTypeAddresses.value.length > 0
|
||||||
|
);
|
||||||
|
|
||||||
|
const allTypes = computed(() => {
|
||||||
|
const result = {} as { [key: string]: IType };
|
||||||
|
allTypeEntries.value.forEach(([_, entry]) => {
|
||||||
|
if (result[entry.entity] === undefined) {
|
||||||
|
result[entry.entity] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (entry.attribute) {
|
||||||
|
case "TYPE":
|
||||||
|
result[entry.entity].name = entry.value.c;
|
||||||
|
break;
|
||||||
|
case "TYPE":
|
||||||
|
result[entry.entity].name = entry.value.c;
|
||||||
|
break;
|
||||||
|
case "TYPE":
|
||||||
|
result[entry.entity].name = entry.value.c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
attributes,
|
attributes,
|
||||||
backlinks,
|
backlinks,
|
||||||
error,
|
error,
|
||||||
mutate,
|
mutate,
|
||||||
|
types: allTypes,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -148,7 +196,6 @@ table {
|
||||||
padding-right: 1em;
|
padding-right: 1em;
|
||||||
line-height: 1em;
|
line-height: 1em;
|
||||||
|
|
||||||
|
|
||||||
&.attr-action {
|
&.attr-action {
|
||||||
max-width: 1em;
|
max-width: 1em;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue