show collections
This commit is contained in:
51
src/components/collections.tsx
Normal file
51
src/components/collections.tsx
Normal file
@ -0,0 +1,51 @@
|
||||
import {createSignal, onMount} from "solid-js";
|
||||
import { customElement } from "solid-element";
|
||||
import {awService} from "../services/aw-service";
|
||||
import {Attribute, Collection, CollectionsList} from "./types";
|
||||
|
||||
const style = ``;
|
||||
|
||||
const defaultProps = {
|
||||
awEndpoint: "localhost:80/v1",
|
||||
awProject: "",
|
||||
styles: "",
|
||||
};
|
||||
|
||||
customElement("collections-list", defaultProps, (props) => {
|
||||
const [collections, setCollections] = createSignal<CollectionsList>();
|
||||
awService.init(props.awEndpoint, props.awProject);
|
||||
|
||||
let customStyles;
|
||||
try {
|
||||
customStyles = props.styles;
|
||||
} catch(e) {
|
||||
customStyles = '';
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
awService.getCollections().subscribe((collection: CollectionsList) => {
|
||||
setCollections(collection);
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
<div class={'collections-frame'}>
|
||||
<style>{style}</style>
|
||||
<style>{customStyles}</style>
|
||||
{/*<span>{JSON.stringify(collections(), null, " ")}</span>*/}
|
||||
{collections()?.collections.map((col: Collection) => {
|
||||
return <div>
|
||||
<h3>{col.name}</h3>
|
||||
<span>{col.$id}</span><br></br>
|
||||
{
|
||||
col.attributes.map((attr: Attribute) => {
|
||||
return <div>
|
||||
<span>{attr.key + ", " + attr.type}</span>
|
||||
</div>;
|
||||
})
|
||||
}
|
||||
</div>;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
});
|
28
src/components/types.ts
Normal file
28
src/components/types.ts
Normal file
@ -0,0 +1,28 @@
|
||||
export interface CollectionsList {
|
||||
collections: Collection[]
|
||||
total: number
|
||||
}
|
||||
|
||||
export interface Collection {
|
||||
$id: string
|
||||
$createdAt: number
|
||||
$updatedAt: number
|
||||
$read: string[]
|
||||
$write: string[]
|
||||
databaseId: string
|
||||
name: string
|
||||
enabled: boolean
|
||||
permission: string
|
||||
attributes: Attribute[]
|
||||
}
|
||||
|
||||
export interface Attribute {
|
||||
key: string
|
||||
type: string
|
||||
status: string
|
||||
required: boolean
|
||||
array: boolean
|
||||
size: number
|
||||
default: any
|
||||
}
|
||||
|
Reference in New Issue
Block a user