Skip to content

Commit

Permalink
Merge pull request starlight-go#7 from awans/aftdatatypes
Browse files Browse the repository at this point in the history
Add client logic for datatypes
  • Loading branch information
chasehensel authored Jun 6, 2020
2 parents 9891086 + ecde2f1 commit cda6064
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 32 deletions.
14 changes: 12 additions & 2 deletions client/catalog/src/app/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ModelList from './models/ModelList.svelte';
import ModelDetail from './models/ModelDetail.svelte';
import ModelNew from './models/ModelNew.svelte';
import DatatypeNew from './datatypes/DatatypeNew.svelte';
import Breadcrumbs from './Breadcrumbs.svelte';
import LogList from './LogList.svelte';
import {router} from './router.js';
Expand All @@ -14,6 +15,7 @@
"/object/:id": ModelDetail,
"/objects/new": ModelNew,
"/objects": ModelList,
"/datatypes/new": DatatypeNew,
"/log": LogList,
"/": ModelList,
};
Expand Down Expand Up @@ -98,8 +100,16 @@
</style>
<svelte:head>
<title>Aft</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700&display=swap" rel="stylesheet">

<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700&display=swap">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.52.2/codemirror.min.css">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.52.2/theme/material-darker.min.css">
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.52.2/codemirror.min.js"></script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.52.2/mode/python/python.min.js"></script>
</svelte:head>

<div id="grid-root">
Expand Down
2 changes: 1 addition & 1 deletion client/catalog/src/app/Breadcrumbs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
</style>
<script>
import { breadcrumbStore } from './breadcrumbStore.js';
import { breadcrumbStore } from './stores.js';
let breadcrumbs;
breadcrumbStore.subscribe(value => {
breadcrumbs = value;
Expand Down
2 changes: 1 addition & 1 deletion client/catalog/src/app/LogList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import client from '../data/client.js';
import HLTable from '../ui/HLTable.svelte';
import HLRow from '../ui/HLRow.svelte';
import { breadcrumbStore } from './breadcrumbStore.js';
import { breadcrumbStore } from './stores.js';
breadcrumbStore.set(
[{
href: "/log",
Expand Down
2 changes: 1 addition & 1 deletion client/catalog/src/app/Nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import LinkList from '../ui/LinkList.svelte';
let items = [
{name:"Objects", path:'/objects'},
{name:"Functions", path: '/functions'},
{name:"Datatypes", path: '/datatypes/new'},
{name:"Roles", path:"/roles"},
{name:"Users", path:"/users"},
{name:"Log", path:"/log"}
Expand Down
11 changes: 9 additions & 2 deletions client/catalog/src/app/models/Attribute.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script>
export let attribute
import HLRow from '../../ui/HLRow.svelte';
import { AttrType } from '../../data/enums.js';
import client from '../../data/client.js';
let load = client.datatype.findOne({where:{id: attribute.datatypeId}});
</script>
<style>
dl {
Expand Down Expand Up @@ -30,9 +31,15 @@ dd {
<div class="v-space"/>
<dl>
<dt>Type</dt>
{#await load}
&nbsp;
{:then datatype}
<dd>
{AttrType[attribute.attrType]}
{datatype.name}
</dd>
{:catch error}
<div>Error..</div>
{/await}
</dl>
</div>
</HLRow>
Expand Down
32 changes: 27 additions & 5 deletions client/catalog/src/app/models/AttributeForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,28 @@ export let attribute;
import HLRow from '../../ui/HLRow.svelte';
import HLSelect from '../../ui/HLSelect.svelte';
import HLText from '../../ui/HLText.svelte';
import { AttrType } from '../../data/enums.js';
import client from '../../data/client.js';
import {afterUpdate} from 'svelte';
let load = client.datatype.findMany({where:{}});
function restrict(s) {
const newVal = s.replace(/[^a-zA-Z_]/g, '');
return newVal;
}
let cap= (s) => {
if (!s) {
return "";
}
s = s.replace(/[\w]([A-Z])/g, function(m) {
return m[0] + " " + m[1];
});
return s.charAt(0).toUpperCase() + s.slice(1)
};
afterUpdate(() => {
attribute.datatype.connect.id = attribute.datatypeId;
});
</script>
<style>
.hform-row {
Expand All @@ -24,12 +40,18 @@ function restrict(s) {
<div class="hform-row">
<HLText placeholder="Attribute name.." bind:value={attribute.name} restrict={restrict}/>
<div class="spacer"/>
<HLSelect bind:value={attribute.attrType}>
{#each Object.entries(AttrType) as attr, ix}
<option value={ix}>
{attr[1]}
{#await load}
&nbsp;
{:then datatypes}
<HLSelect bind:value={attribute.datatypeId}>
{#each Object.entries(datatypes) as attr}
<option value={attr[1].id}>
{cap(attr[1].name)}
</option>
{/each}
</HLSelect>
{:catch error}
<div>Error..</div>
{/await}
</div>
</HLRow>
2 changes: 1 addition & 1 deletion client/catalog/src/app/models/ModelDetail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export let params;
import client from '../../data/client.js';
import Model from './Model.svelte';
import { breadcrumbStore } from '../breadcrumbStore.js';
import { breadcrumbStore } from '../stores.js';
let id = params.id;
let load = client.model.findOne({where: {id: id}, include: {rightRelationships: true, leftRelationships: true, attributes: true}});
Expand Down
2 changes: 1 addition & 1 deletion client/catalog/src/app/models/ModelList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let cap = (s) => {
return s.charAt(0).toUpperCase() + s.slice(1);
};
import { breadcrumbStore } from '../breadcrumbStore.js';
import { breadcrumbStore } from '../stores.js';
breadcrumbStore.set(
[{
href: "/objects",
Expand Down
6 changes: 4 additions & 2 deletions client/catalog/src/app/models/ModelNew.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import HLRowButton from '../../ui/HLRowButton.svelte';
import HLButton from '../../ui/HLButton.svelte';
import HLTextBig from '../../ui/HLTextBig.svelte';
import HLRow from '../../ui/HLRow.svelte';
import { breadcrumbStore } from '../breadcrumbStore.js';
import { breadcrumbStore } from '../stores.js';
breadcrumbStore.set(
[{
href: "/objects",
Expand All @@ -31,7 +31,8 @@ const newModelOp = {
function addAttribute() {
newModelOp.attributes.create = [...newModelOp.attributes.create, {
name: "",
attrType: 0,
datatypeId: "",
datatype: { connect: {id: ""}},
}];
}
Expand All @@ -48,6 +49,7 @@ function addRelationship() {
},
}];
}
import {router} from '../router.js';
async function saveModel() {
const data = await client.model.create({data: newModelOp});
Expand Down
File renamed without changes.
16 changes: 14 additions & 2 deletions client/catalog/src/data/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ const CoreApi = {
log: {
scan: {},
},
model:
datatype:
{
create: {},
findOne: {},
findMany: {},
}
},
model:
{
create: {},
findOne: {},
findMany: {},
},
code:
{
create: {},
findOne: {},
findMany: {},
},
}

class HttpRpcClient {
Expand Down
18 changes: 8 additions & 10 deletions client/catalog/src/data/enums.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
export const AttrType = {
0:"Int" ,
1:"String",
2:"Text",
3:"Float",
4:"Enum",
5:"UUID",
6:"Email",
}

export const RelType = {
0:"has one" ,
1:"belongs to",
2:"has many",
3:"belongs to many",
}

export const InputType = {
0:"Bool" ,
1:"Int",
2:"String",
3:"Float",
4:"UUID",
}
2 changes: 0 additions & 2 deletions internal/api/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,10 @@ func (s CreateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (err er
if err != nil {
return
}

request = CreateRequest{
Operation: op,
Include: inc,
}

s.bus.Publish(lib.ParseRequest{Request: request})

st, err := request.Operation.Apply(tx)
Expand Down
1 change: 1 addition & 0 deletions internal/api/create_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (op CreateOperation) Apply(tx db.RWTx) (db.Record, error) {
return nil, err
}
}
tx.Commit()
return op.Record, nil
}

Expand Down
1 change: 1 addition & 0 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ func (tx *holdTx) SaveModel(m Model) {
storeAttr := RecordForModel(AttributeModel)
storeAttr.Set("name", aKey)
storeAttr.Set("id", attr.ID)
storeAttr.Set("datatypeId", attr.Datatype.ID)//TODO remove hack
storeAttr.SetFK("model", m.ID)
storeAttr.SetFK("datatype", attr.Datatype.ID)
tx.h = tx.h.Insert(storeAttr)
Expand Down
8 changes: 6 additions & 2 deletions internal/db/metamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ var AttributeModel = Model{
ID: uuid.MustParse("51605ada-5326-4cfd-9f31-f10bc4dfbf03"),
Datatype: String,
},
"datatypeId": Attribute{//todo remove hack
ID: uuid.MustParse("bfeefcbf-b9f7-44e6-9951-134755f7e1cd"),
Datatype: UUID,
},
},
RightRelationships: []Relationship{
ModelAttributes,
Expand Down Expand Up @@ -90,11 +94,11 @@ var CodeModel = Model{
Name: "code",
Attributes: map[string]Attribute{
"name": Attribute{
ID: uuid.MustParse("e38e557c-7b18-4b8c-8be4-04ca7810c2c4"),
ID: uuid.MustParse("c47bcd30-01ea-467f-ad02-114342070241"),
Datatype: String,
},
"function": Attribute{
ID: uuid.MustParse("9ad0482e-92ab-45cd-b66b-24ddb1cc9971"),
ID: uuid.MustParse("32589c03-7690-472d-8082-032a7f315394"),
Datatype: Enum,
},
"runtime": Attribute{
Expand Down

0 comments on commit cda6064

Please sign in to comment.