|
1 | 1 | <script setup lang="tsx"> |
2 | | -import type { CustomRenderProps } from '@/components/StdDesign/StdDataDisplay/StdTableTransformer' |
3 | | -import type { Column, JSXElements } from '@/components/StdDesign/types' |
| 2 | +import type { SiteCategory } from '@/api/site_category' |
4 | 3 | import domain from '@/api/domain' |
| 4 | +import site_category from '@/api/site_category' |
5 | 5 | import StdTable from '@/components/StdDesign/StdDataDisplay/StdTable.vue' |
6 | | -import { datetime } from '@/components/StdDesign/StdDataDisplay/StdTableTransformer' |
7 | | -import { input, select } from '@/components/StdDesign/StdDataEntry' |
8 | 6 | import InspectConfig from '@/views/config/InspectConfig.vue' |
9 | 7 | import SiteDuplicate from '@/views/site/components/SiteDuplicate.vue' |
10 | | -import { Badge, message } from 'ant-design-vue' |
11 | | -
|
12 | | -const columns: Column[] = [{ |
13 | | - title: () => $gettext('Name'), |
14 | | - dataIndex: 'name', |
15 | | - sorter: true, |
16 | | - pithy: true, |
17 | | - edit: { |
18 | | - type: input, |
19 | | - }, |
20 | | - search: true, |
21 | | -}, { |
22 | | - title: () => $gettext('Status'), |
23 | | - dataIndex: 'enabled', |
24 | | - customRender: (args: CustomRenderProps) => { |
25 | | - const template: JSXElements = [] |
26 | | - const { text } = args |
27 | | - if (text === true || text > 0) { |
28 | | - template.push(<Badge status="success" />) |
29 | | - template.push($gettext('Enabled')) |
30 | | - } |
31 | | - else { |
32 | | - template.push(<Badge status="warning" />) |
33 | | - template.push($gettext('Disabled')) |
34 | | - } |
| 8 | +import columns from '@/views/site/site_list/columns' |
| 9 | +import { message } from 'ant-design-vue' |
35 | 10 |
|
36 | | - return h('div', template) |
37 | | - }, |
38 | | - search: { |
39 | | - type: select, |
40 | | - mask: { |
41 | | - true: $gettext('Enabled'), |
42 | | - false: $gettext('Disabled'), |
43 | | - }, |
44 | | - }, |
45 | | - sorter: true, |
46 | | - pithy: true, |
47 | | -}, { |
48 | | - title: () => $gettext('Updated at'), |
49 | | - dataIndex: 'modified_at', |
50 | | - customRender: datetime, |
51 | | - sorter: true, |
52 | | - pithy: true, |
53 | | -}, { |
54 | | - title: () => $gettext('Action'), |
55 | | - dataIndex: 'action', |
56 | | -}] |
| 11 | +const route = useRoute() |
| 12 | +const router = useRouter() |
57 | 13 |
|
58 | 14 | const table = ref() |
59 | | -
|
60 | 15 | const inspect_config = ref() |
61 | 16 |
|
| 17 | +const siteCategoryId = ref(Number.parseInt(route.query.site_category_id as string) || 0) |
| 18 | +const siteCategories = ref([]) as Ref<SiteCategory[]> |
| 19 | +
|
| 20 | +watch(route, () => { |
| 21 | + inspect_config.value?.test() |
| 22 | +}) |
| 23 | +
|
| 24 | +onMounted(async () => { |
| 25 | + while (true) { |
| 26 | + try { |
| 27 | + const { data, pagination } = await site_category.get_list() |
| 28 | + if (!data || !pagination) |
| 29 | + return |
| 30 | + siteCategories.value.push(...data) |
| 31 | + if (data.length < pagination?.per_page) { |
| 32 | + return |
| 33 | + } |
| 34 | + } |
| 35 | + catch (e: any) { |
| 36 | + message.error(e?.message ?? $gettext('Server error')) |
| 37 | + return |
| 38 | + } |
| 39 | + } |
| 40 | +}) |
| 41 | +
|
62 | 42 | function enable(name: string) { |
63 | 43 | domain.enable(name).then(() => { |
64 | 44 | message.success($gettext('Enabled successfully')) |
@@ -97,26 +77,28 @@ function handle_click_duplicate(name: string) { |
97 | 77 | show_duplicator.value = true |
98 | 78 | target.value = name |
99 | 79 | } |
100 | | -
|
101 | | -const route = useRoute() |
102 | | -
|
103 | | -watch(route, () => { |
104 | | - inspect_config.value?.test() |
105 | | -}) |
106 | 80 | </script> |
107 | 81 |
|
108 | 82 | <template> |
109 | 83 | <ACard :title="$gettext('Manage Sites')"> |
110 | 84 | <InspectConfig ref="inspect_config" /> |
111 | 85 |
|
| 86 | + <ATabs v-model:active-key="siteCategoryId"> |
| 87 | + <ATabPane :key="0" :tab="$gettext('All')" /> |
| 88 | + <ATabPane v-for="c in siteCategories" :key="c.id" :tab="c.name" /> |
| 89 | + </ATabs> |
| 90 | + |
112 | 91 | <StdTable |
113 | 92 | ref="table" |
114 | 93 | :api="domain" |
115 | 94 | :columns="columns" |
116 | 95 | row-key="name" |
117 | 96 | disable-delete |
118 | 97 | disable-view |
119 | | - @click-edit="r => $router.push({ |
| 98 | + :get-params="{ |
| 99 | + site_category_id: siteCategoryId, |
| 100 | + }" |
| 101 | + @click-edit="(r: string) => router.push({ |
120 | 102 | path: `/sites/${r}`, |
121 | 103 | })" |
122 | 104 | > |
|
0 commit comments