Skip to content

Commit 014f001

Browse files
committed
Support timestamp
1 parent a8bc983 commit 014f001

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed

components/modal/createModelData.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
max: undefined,
2323
min: undefined,
2424
name: sch.name,
25+
range: undefined,
2526
type: sch.type,
2627
option: '',
2728
immutable: sch.name === 'id'
@@ -47,7 +48,7 @@
4748
// float: 'Float',
4849
number: 'Number',
4950
string: 'String',
50-
// timestamp: 'Timestamp',
51+
timestamp: 'Timestamp',
5152
uuid: 'UUID'
5253
};
5354
@@ -103,7 +104,7 @@
103104
/>
104105
</section>
105106
</div>
106-
<div class="flex gap-x-2" v-for="(sch, idx) in fields" :key="idx">
107+
<div class="grid grid-cols-4 gap-x-2" v-for="(sch, idx) in fields" :key="idx">
107108
<section class="form-control mt-2">
108109
<FormInput
109110
:disabled="true"
@@ -158,6 +159,17 @@
158159
/>
159160
</section>
160161
<!-- ================== -->
162+
<!-- ======== TIMESTAMP -->
163+
<!-- ================== -->
164+
<section
165+
v-show="sch.value.type === 'timestamp'"
166+
class="form-control mt-2 col-span-2"
167+
>
168+
<CalendarPicker
169+
:disabled="isDisabled"
170+
:name="`schema[${idx}].range`"
171+
/>
172+
</section>
161173
</div>
162174
<section class="mt-10">
163175
<Button :disabled="isDisabled" size="sm" @click="handleClose">

components/model/table.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
import useModelData from '~~/stores/useModelData';
44
import ModalCreateModelData from '~~/components/modal/createModelData.vue';
55
import ModalConfirm from '~~/components/modal/confirm.vue';
6+
import format from 'date-fns/format';
7+
8+
type Schema = {
9+
name: string;
10+
type: string;
11+
}
612
713
defineProps<{
8-
schema: { name: string; type: string }[];
14+
schema: Schema[];
915
}>();
1016
1117
const modelData = useModelData();
@@ -25,6 +31,15 @@
2531
select.clear();
2632
},
2733
});
34+
35+
const render = (model: { schema: any }, schema: Schema) => {
36+
if (schema.type === 'timestamp') {
37+
const parsedDate = Date.parse(model.schema[schema.name]);
38+
return format(parsedDate, 'MMMM d, yyy');
39+
}
40+
41+
return model.schema[schema.name];
42+
};
2843
</script>
2944

3045
<template>
@@ -72,7 +87,7 @@
7287
</tr>
7388
</thead>
7489
<tbody>
75-
<TableLoader v-if="modelData.isLoading" :colspan="4" />
90+
<TableLoader v-if="modelData.isLoading" :colspan="schema.length + 2" />
7691
<tr v-for="md in modelData.list" v-else :key="md.id">
7792
<td colspan="2">
7893
<input
@@ -86,7 +101,7 @@
86101
v-for="sch in schema"
87102
class="font-normal normal-case text-base"
88103
>
89-
{{ md.schema[sch.name as any] }}
104+
{{ render(md, sch) }}
90105
</td>
91106
</tr>
92107
</tbody>

components/table/Loader.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
<template>
88
<tr>
9-
<td :colspan="colspan">
10-
<div class="flex h-full w-full">
9+
<td rowspan="4" :colspan="colspan">
10+
<figure class="flex mt-32 w-full">
1111
<LoaderSpinner />
12-
</div>
12+
</figure>
1313
</td>
1414
</tr>
1515
</template>

server/routes/models/[id]/model-data.post.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ type FakeSchema = {
77
min?: number;
88
name: string;
99
option: string;
10+
range: {
11+
start: string;
12+
end: string;
13+
};
1014
type: string;
1115
};
1216

server/utils/generateModelData.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ type FakeSchema = {
7979
min?: number;
8080
name: string;
8181
option: string;
82+
range: {
83+
start: string;
84+
end: string;
85+
};
8286
type: string;
8387
};
8488

@@ -94,6 +98,11 @@ function setValue(schema: FakeSchema) {
9498
return uuidv4();
9599
case 'boolean':
96100
return faker.datatype.boolean();
101+
case 'timestamp':
102+
return faker.date.between({
103+
from: schema.range.start,
104+
to: schema.range.end
105+
})
97106
}
98107
}
99108

0 commit comments

Comments
 (0)