Skip to content

Commit

Permalink
Support timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
netervati committed Jun 17, 2024
1 parent a8bc983 commit 014f001
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
16 changes: 14 additions & 2 deletions components/modal/createModelData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
max: undefined,
min: undefined,
name: sch.name,
range: undefined,
type: sch.type,
option: '',
immutable: sch.name === 'id'
Expand All @@ -47,7 +48,7 @@
// float: 'Float',
number: 'Number',
string: 'String',
// timestamp: 'Timestamp',
timestamp: 'Timestamp',
uuid: 'UUID'
};
Expand Down Expand Up @@ -103,7 +104,7 @@
/>
</section>
</div>
<div class="flex gap-x-2" v-for="(sch, idx) in fields" :key="idx">
<div class="grid grid-cols-4 gap-x-2" v-for="(sch, idx) in fields" :key="idx">
<section class="form-control mt-2">
<FormInput
:disabled="true"
Expand Down Expand Up @@ -158,6 +159,17 @@
/>
</section>
<!-- ================== -->
<!-- ======== TIMESTAMP -->
<!-- ================== -->
<section
v-show="sch.value.type === 'timestamp'"
class="form-control mt-2 col-span-2"
>
<CalendarPicker
:disabled="isDisabled"
:name="`schema[${idx}].range`"
/>
</section>
</div>
<section class="mt-10">
<Button :disabled="isDisabled" size="sm" @click="handleClose">
Expand Down
21 changes: 18 additions & 3 deletions components/model/table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
import useModelData from '~~/stores/useModelData';
import ModalCreateModelData from '~~/components/modal/createModelData.vue';
import ModalConfirm from '~~/components/modal/confirm.vue';
import format from 'date-fns/format';
type Schema = {
name: string;
type: string;
}
defineProps<{
schema: { name: string; type: string }[];
schema: Schema[];
}>();
const modelData = useModelData();
Expand All @@ -25,6 +31,15 @@
select.clear();
},
});
const render = (model: { schema: any }, schema: Schema) => {
if (schema.type === 'timestamp') {
const parsedDate = Date.parse(model.schema[schema.name]);
return format(parsedDate, 'MMMM d, yyy');
}
return model.schema[schema.name];
};
</script>

<template>
Expand Down Expand Up @@ -72,7 +87,7 @@
</tr>
</thead>
<tbody>
<TableLoader v-if="modelData.isLoading" :colspan="4" />
<TableLoader v-if="modelData.isLoading" :colspan="schema.length + 2" />
<tr v-for="md in modelData.list" v-else :key="md.id">
<td colspan="2">
<input
Expand All @@ -86,7 +101,7 @@
v-for="sch in schema"
class="font-normal normal-case text-base"
>
{{ md.schema[sch.name as any] }}
{{ render(md, sch) }}
</td>
</tr>
</tbody>
Expand Down
6 changes: 3 additions & 3 deletions components/table/Loader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

<template>
<tr>
<td :colspan="colspan">
<div class="flex h-full w-full">
<td rowspan="4" :colspan="colspan">
<figure class="flex mt-32 w-full">
<LoaderSpinner />
</div>
</figure>
</td>
</tr>
</template>
4 changes: 4 additions & 0 deletions server/routes/models/[id]/model-data.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ type FakeSchema = {
min?: number;
name: string;
option: string;
range: {
start: string;
end: string;
};
type: string;
};

Expand Down
9 changes: 9 additions & 0 deletions server/utils/generateModelData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ type FakeSchema = {
min?: number;
name: string;
option: string;
range: {
start: string;
end: string;
};
type: string;
};

Expand All @@ -94,6 +98,11 @@ function setValue(schema: FakeSchema) {
return uuidv4();
case 'boolean':
return faker.datatype.boolean();
case 'timestamp':
return faker.date.between({
from: schema.range.start,
to: schema.range.end

Check warning on line 104 in server/utils/generateModelData.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Insert `,`
})

Check warning on line 105 in server/utils/generateModelData.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Insert `;`
}
}

Expand Down

0 comments on commit 014f001

Please sign in to comment.