Skip to content

Commit db46f1d

Browse files
committed
working on datasets
1 parent c8b78e3 commit db46f1d

File tree

3 files changed

+141
-40
lines changed

3 files changed

+141
-40
lines changed

pages/game/[id]/datasets.vue

+73
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,72 @@
1010
<div class="flex gap-5 flex-column-reverse md:flex-row">
1111
<div class="flex-auto p-fluid">
1212

13+
<InputGroup>
14+
<InputGroupAddon>
15+
<i class="pi pi-search" />
16+
</InputGroupAddon>
17+
<InputText type="text" placeholder="Datasets" class="w-full"
18+
v-model="datasets.query.search" @keydown.enter="datasets.search()" />
19+
<Button label="Search" @click="datasets.search()" />
20+
</InputGroup>
1321

22+
<DataTable :value="datasets.records" stripedRows @sort="(e) => datasets.sortDataTable(e)">
23+
<Column field="props.name" header="Name" sortable>
24+
<template #body="slotProps">
25+
<NuxtLink :to="`/dataset/${slotProps.data.props.id}`" v-ripple>
26+
{{ slotProps.data.props.name }}
27+
</NuxtLink>
28+
</template>
29+
</Column>
30+
<Column field="extra.rowCount" header="Row Count" sortable></Column>
31+
<Column field="extra.totalQuantity" header="Total Quantity" sortable></Column>
32+
<Column header="Manage">
33+
<template #body="slotProps">
34+
<NuxtLink :to="`/dataset/${slotProps.data.props.id}`" class="mr-2 no-underline">
35+
<Button icon="pi pi-eye" title="View" alt="View Dataset" />
36+
</NuxtLink>
37+
<NuxtLink v-if="slotProps.data.meta?.isOwner" :to="`/dataset/${slotProps.data.props.id}/edit`" class="mr-2 no-underline">
38+
<Button icon="pi pi-pencil" severity="success" title="Edit" alt="Edit Dataset" />
39+
</NuxtLink>
40+
<Button v-if="slotProps.data.meta?.isOwner" title="Delete" alt="Delete Dataset" icon="pi pi-trash" severity="danger" @click="slotProps.data.delete()" />
41+
</template>
42+
</Column>
43+
</DataTable>
44+
<Pager :kind="datasets" />
1445

1546

1647
</div>
1748
</div>
49+
50+
</div>
51+
52+
<div class="surface-card mt-5 p-5 border-1 surface-border border-round">
53+
54+
<div class="flex gap-5 flex-column-reverse md:flex-row">
55+
<div class="flex-auto p-fluid">
56+
57+
58+
<h2 class="mt-0">Create Dataset</h2>
59+
60+
<Form :send="() => datasets.create()">
61+
<div class="flex gap-5 flex-column-reverse md:flex-row">
62+
<div class="flex-auto p-fluid">
63+
64+
<div class="mb-4">
65+
<FormInput name="name" type="text" v-model="datasets.new.name" required label="Name" />
66+
</div>
67+
<div>
68+
<Button type="submit" class="w-auto" severity="success">
69+
<i class="pi pi-plus mr-1"></i> Create Dataset
70+
</Button>
71+
</div>
72+
</div>
73+
74+
</div>
75+
</Form>
76+
77+
</div>
78+
</div>
1879
</div>
1980
</div>
2081

@@ -40,6 +101,18 @@ const game = useVingRecord({
40101
await game.fetch();
41102
onBeforeRouteLeave(() => game.dispose());
42103
104+
const datasets = useVingKind({
105+
listApi: `/api/${restVersion()}/dataset`,
106+
createApi: `/api/${restVersion()}/dataset`,
107+
query: { includeMeta: true, sortBy: 'createdAt', sortOrder: 'desc', includeExtra: ['totalQuantity','rowCount'] },
108+
newDefaults: { name: '', gameId: id },
109+
});
110+
await Promise.all([
111+
datasets.search(),
112+
datasets.fetchPropsOptions(),
113+
]);
114+
onBeforeRouteLeave(() => datasets.dispose());
115+
43116
const dt = useDateTime();
44117
45118
</script>

ving/record/records/Dataset.mjs

+52-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { VingRecord, VingKind } from "#ving/record/VingRecord.mjs";
2-
import { eq } from '#ving/drizzle/orm.mjs';
32

43
/** Management of individual Datasets.
54
* @class
@@ -50,10 +49,60 @@ export class DatasetRecord extends VingRecord {
5049
await super.delete();
5150
}
5251

53-
copyWithRows() {
54-
const newDataset = super.copy();
52+
async copyWithRows() {
53+
const newDataset = await super.copy();
54+
this.#skipDefaults = true;
55+
await newDataset.insert();
56+
const rows = await (await this.children('rows')).getMany();
57+
for (const row of rows) {
58+
const newRow = await row.copy();
59+
newRow.datasetId = newDataset.id;
60+
await newRow.insert();
61+
}
62+
}
63+
64+
#skipDefaults = false;
65+
66+
async insert() {
67+
await super.insert();
68+
await this.createDefaults();
69+
}
70+
71+
async createDefaults() {
72+
if (this.#skipDefaults)
73+
return;
74+
const rows = await this.children('rows');
75+
await rows.create({ name: 'Untitiled' });
76+
}
77+
78+
async serialize() {
79+
const rowsOut = [];
80+
const rows = await (await this.children('rows')).findMany();
81+
for (const row in rows) {
82+
rowsOut.push(await row.serialize());
83+
}
84+
return {
85+
rows,
86+
id: this.id,
87+
name: this.name,
88+
enumerateOn: this.enumerateOn,
89+
fields: this.fields,
90+
fieldSchema: this.fieldSchema,
91+
rowFieldOrder: this.rowFieldOrder,
92+
rowSchema: this.rowSchema,
93+
}
5594
}
5695

96+
async deserialize(data) {
97+
this.setAll(data);
98+
const rows = await this.children('rows');
99+
for (const rowData of data.rows) {
100+
const newRow = rows.mint();
101+
await newRow.deserialize(rowData);
102+
}
103+
}
104+
105+
57106
}
58107

59108
/** Management of all Datasets.

ving/record/records/Row.mjs

+16-37
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,30 @@
11
import { VingRecord, VingKind } from "#ving/record/VingRecord.mjs";
2-
import {eq} from '#ving/drizzle/orm.mjs';
32

43
/** Management of individual Rows.
54
* @class
65
*/
76
export class RowRecord extends VingRecord {
87
// add custom Record code here
9-
10-
/**
11-
* Extends `describe()` in `VingRecord` to add `meta` property `bar`
12-
* and the `extra` property `foo`.
13-
*
14-
* Note, these don't do anything, this is just here to explain how to extend
15-
* the describe method.
16-
*
17-
* @see VingRecord.describe()
18-
*/
19-
async describe(params = {}) {
20-
const out = await super.describe(params);
21-
if (params?.include?.meta && out.meta) {
22-
out.meta.bar = 'bar';
23-
}
24-
if (params?.include?.extra.includes('foo')) {
25-
if (out.extra === undefined) {
26-
out.extra = {};
27-
}
28-
out.extra.foo = 'foo';
29-
}
30-
return out;
31-
}
32-
33-
8+
9+
async serialize() {
10+
return {
11+
name: this.name,
12+
quantity: this.quantity,
13+
fields: this.fields,
14+
}
15+
}
16+
17+
async deserialize(data) {
18+
this.setAll(data);
19+
await this.insert();
20+
}
21+
3422
}
3523

3624
/** Management of all Rows.
3725
* @class
3826
*/
39-
export class RowKind extends VingKind {
27+
export class RowKind extends VingKind {
4028
// add custom Kind code here
41-
42-
/**
43-
* An example of a shortcut for a common query you might want to make.
44-
*
45-
* @returns a list of `RowRecord`s that are cool
46-
*/
47-
async findCool() {
48-
return this.select.findMany(eq(this.table.isCool, true));
49-
}
50-
29+
5130
}

0 commit comments

Comments
 (0)