mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 21:10:35 +07:00
feat: search, sort
This commit is contained in:
@@ -6,6 +6,8 @@ import Service from './{{.LowerName}}.service.ts'
|
||||
import type { Scheme } from '../types/scheme.type'
|
||||
import { {{.StructName}} } from '{{.GolangServicesPath}}'
|
||||
import { ref } from 'vue'
|
||||
import type { Validate } from "../types/validate.type";
|
||||
import { getDefaultSortOptions } from "../utils/structs/default-sort-options.util.ts";
|
||||
import type { Validate } from '../types/validate.type'
|
||||
{{range .Dependencies}}
|
||||
import {{.ImportName}} from '../{{.LowerName}}/{{.LowerName}}.service.ts'
|
||||
@@ -20,11 +22,11 @@ const load = async () => {
|
||||
{{range .Dependencies}}
|
||||
(scheme as any).{{.FieldName}}.type!.nested!.values = await {{.ServiceName}}.readAll();
|
||||
{{end}}
|
||||
items.value = await service.readAll();
|
||||
items.value = await service.sort(sortOptions.value) ;
|
||||
return items.value;
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
onMounted(() => {
|
||||
load()
|
||||
})
|
||||
|
||||
@@ -37,14 +39,22 @@ const scheme: Scheme<{{.StructName}}> = reactive({
|
||||
|
||||
const getDefaults = () => getDefaultValues(scheme)
|
||||
|
||||
const validate: Validate<{{.StructName}}> = (entity) => {
|
||||
const validate: Validate<{{.StructName}}> = entity => {
|
||||
return {
|
||||
status: 'success'
|
||||
}
|
||||
};
|
||||
|
||||
const search = async (input: string) => {
|
||||
items.value = await service.search(input)
|
||||
}
|
||||
|
||||
const sortOptions = ref(getDefaultSortOptions(scheme))
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Table :scheme :service :get-defaults :load :items :validate></Table>
|
||||
<main class="w-screen h-screen">
|
||||
<Table :scheme :service :get-defaults :load :items :validate @on-search="search" v-model:sort-options="sortOptions"></Table>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { GetAll, Create, Delete, GetById, Update, Count } from "../../bindings/app/internal/services/{{.LowerModelName}}service.ts"
|
||||
import { GetAll, Create, Delete, GetById, Update, Count, SortedByOrder, SearchByAllTextFields } from "../../bindings/app/internal/services/{{.LowerModelName}}service.ts"
|
||||
import type { {{.ModelName}} } from "{{.ServicesPath}}"
|
||||
import type { IService } from "../types/service.type.ts"
|
||||
import type { SortOptions } from "../types/sort-options.type.ts";
|
||||
|
||||
|
||||
export default class {{.ModelName}}Service implements IService<{{.ModelName}}> {
|
||||
async read(id: number) {
|
||||
@@ -26,4 +28,12 @@ export default class {{.ModelName}}Service implements IService<{{.ModelName}}> {
|
||||
async count() {
|
||||
return await Count()
|
||||
}
|
||||
|
||||
async search(input: string) {
|
||||
return await SearchByAllTextFields(input) as {{ .ModelName }}[]
|
||||
}
|
||||
|
||||
async sort(options: SortOptions<{{ .ModelName }}>) {
|
||||
return await SortedByOrder(Object.entries(options).map(item => ({Name: item[0], Order: item[1]}))) as {{ .ModelName }}[]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user