123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- <script setup lang="ts">
- import { StdTable } from '@uozi-admin/curd'
- import config from '@/api/config'
- import FooterToolBar from '@/components/FooterToolbar'
- import { useBreadcrumbs } from '@/composables/useBreadcrumbs'
- import { isProtectedPath } from '@/views/config/configUtils'
- import Delete from './components/Delete.vue'
- import Mkdir from './components/Mkdir.vue'
- import Rename from './components/Rename.vue'
- import configColumns from './configColumns'
- import InspectConfig from './InspectConfig.vue'
- const table = useTemplateRef('table')
- const route = useRoute()
- const router = useRouter()
- const basePath = computed(() => {
- let dir = route?.query?.dir ?? ''
- if (dir)
- dir += '/'
- return dir as string
- })
- const getParams = computed(() => {
- return {
- dir: basePath.value,
- }
- })
- const update = ref(1)
- watch(getParams, () => {
- update.value++
- })
- const refInspectConfig = useTemplateRef('refInspectConfig')
- const breadcrumbs = useBreadcrumbs()
- function updateBreadcrumbs() {
- const filteredPath = basePath.value
- .split('/')
- .filter(v => v)
- let accumulatedPath = ''
- const path = filteredPath.map((segment, index) => {
- const decodedSegment = decodeURIComponent(segment)
- if (index === 0) {
- accumulatedPath = segment
- }
- else {
- accumulatedPath = `${accumulatedPath}/${segment}`
- }
- return {
- name: 'Manage Configs',
- translatedName: () => decodedSegment,
- path: '/config',
- query: {
- dir: accumulatedPath,
- },
- hasChildren: false,
- }
- })
- breadcrumbs.value = [{
- name: 'Dashboard',
- translatedName: () => $gettext('Dashboard'),
- path: '/dashboard',
- hasChildren: false,
- }, {
- name: 'Manage Configs',
- translatedName: () => $gettext('Manage Configs'),
- path: '/config',
- hasChildren: false,
- }, ...path]
- }
- onMounted(() => {
- updateBreadcrumbs()
- })
- watch(route, () => {
- refInspectConfig.value?.test()
- updateBreadcrumbs()
- })
- function goBack() {
- const pathSegments = basePath.value.split('/').slice(0, -2)
- const encodedPath = pathSegments.length > 0 ? pathSegments.join('/') : ''
- router.push({
- path: '/config',
- query: {
- dir: encodedPath || undefined,
- },
- })
- }
- const refMkdir = useTemplateRef('refMkdir')
- const refRename = useTemplateRef('refRename')
- const refDelete = useTemplateRef('refDelete')
- // Check if a file/directory is protected
- function isProtected(name: string) {
- return isProtectedPath(name)
- }
- </script>
- <template>
- <ACard :title="$gettext('Configurations')">
- <template #extra>
- <AButton
- v-if="basePath"
- type="link"
- size="small"
- @click="goBack"
- >
- {{ $gettext('Back') }}
- </AButton>
- <AButton
- type="link"
- size="small"
- @click="router.push({
- path: '/config/add',
- query: { basePath: basePath || undefined },
- })"
- >
- {{ $gettext('Create File') }}
- </AButton>
- <AButton
- type="link"
- size="small"
- @click="() => refMkdir?.open(basePath)"
- >
- {{ $gettext('Create Folder') }}
- </AButton>
- </template>
- <InspectConfig ref="refInspectConfig" />
- <StdTable
- :key="update"
- ref="table"
- :get-list-api="config.getList"
- :columns="configColumns"
- disable-delete
- disable-view
- row-key="name"
- :custom-query-params="getParams"
- disable-router-query
- disable-edit
- :scroll-x="880"
- >
- <template #beforeActions="{ record }">
- <AButton
- type="link"
- size="small"
- @click="() => {
- if (!record.is_dir) {
- router.push({
- path: `/config/${encodeURIComponent(record.name)}/edit`,
- query: {
- basePath,
- },
- })
- }
- else {
- let encodedPath = '';
- if (basePath) {
- encodedPath = basePath;
- }
- encodedPath += encodeURIComponent(record.name);
- router.push({
- query: {
- dir: encodedPath,
- },
- })
- }
- }"
- >
- {{ $gettext('Modify') }}
- </AButton>
- <AButton
- v-if="!isProtected(record.name)"
- type="link"
- size="small"
- @click="() => refRename?.open(basePath, record.name, record.is_dir)"
- >
- {{ $gettext('Rename') }}
- </AButton>
- <AButton
- v-if="!isProtected(record.name)"
- type="link"
- size="small"
- danger
- @click="() => refDelete?.open(basePath, record.name, record.is_dir)"
- >
- {{ $gettext('Delete') }}
- </AButton>
- </template>
- </StdTable>
- <Mkdir
- ref="refMkdir"
- @created="() => table?.refresh()"
- />
- <Rename
- ref="refRename"
- @renamed="() => table?.refresh()"
- />
- <Delete
- ref="refDelete"
- @deleted="() => table?.refresh()"
- />
- <FooterToolBar v-if="basePath">
- <AButton @click="goBack">
- {{ $gettext('Back') }}
- </AButton>
- </FooterToolBar>
- </ACard>
- </template>
- <style scoped>
- </style>
|