Skip to content

Commit

Permalink
feat: dns
Browse files Browse the repository at this point in the history
  • Loading branch information
kunish committed Mar 21, 2024
1 parent b44fb75 commit 87ab9b1
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 217 deletions.
51 changes: 31 additions & 20 deletions components/CodeEditor.client.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<script lang="ts" setup>
import { shikiToMonaco } from '@shikijs/monaco'
import { merge } from 'lodash-es'
import * as Monaco from 'monaco-editor'
import { getHighlighter } from 'shiki/bundle-web.mjs'
const props = defineProps<{
options?: Monaco.editor.IStandaloneEditorConstructionOptions
}>()
const languageRoutingA: Monaco.languages.IMonarchLanguage = {
// set defaultToken as `invalid` to turn on debug mode
// defaultToken: 'invalid',
Expand Down Expand Up @@ -53,27 +58,33 @@ const highlighter = await getHighlighter({
shikiToMonaco(highlighter, Monaco)
const options = ref<Monaco.editor.IStandaloneEditorConstructionOptions>({
theme: 'one-dark-pro',
automaticLayout: true,
fontSize: 14,
fontWeight: 'bold',
fontFamily: 'Source Code Pro',
'semanticHighlighting.enabled': true,
fontLigatures: true,
lineHeight: 1.6,
minimap: { enabled: false },
scrollBeyondLastLine: false,
renderWhitespace: 'selection',
cursorBlinking: 'solid',
formatOnPaste: true,
insertSpaces: true,
tabSize: 2,
lineNumbers: 'off',
padding: { top: 8, bottom: 8 }
})
const mergedOptions =
computed<Monaco.editor.IStandaloneEditorConstructionOptions>(() =>
merge(
{
theme: 'one-dark-pro',
automaticLayout: true,
fontSize: 14,
fontWeight: 'bold',
fontFamily: 'Source Code Pro',
'semanticHighlighting.enabled': true,
fontLigatures: true,
lineHeight: 1.6,
minimap: { enabled: false },
scrollBeyondLastLine: false,
renderWhitespace: 'selection',
cursorBlinking: 'solid',
formatOnPaste: true,
insertSpaces: true,
tabSize: 2,
lineNumbers: 'off',
padding: { top: 8, bottom: 8 }
},
props.options
)
)
</script>

<template>
<MonacoEditor :options="options" />
<MonacoEditor :options="mergedOptions" />
</template>
66 changes: 16 additions & 50 deletions components/ConfigFormModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import type { Form, FormErrorEvent, FormSubmitEvent } from '#ui/types'
import { isEqual } from 'lodash-es'
import { z } from 'zod'
import * as mutations from '~/mutations'
import * as queries from '~/queries'
withDefaults(
defineProps<{
Expand Down Expand Up @@ -120,45 +122,18 @@ const logLevelOptions = [
const { data: lanInterfaceOptions, pending: isLanInterfaceLoading } =
useAsyncData('lanInterface', async () => {
const interfaces = await apiStore.apiClient?.query(
graphql(`
query General($up: Boolean) {
general {
interfaces(up: $up) {
name
ifindex
ip
}
}
}
`),
{ up: true }
)
const interfaces = await apiStore.apiClient?.query(queries.general, {
up: true
})
return interfaces?.data?.general.interfaces.map(({ name }) => name)
})
const { data: wanInterfaceOptions, pending: isWanInterfaceLoading } =
useAsyncData('wanInterface', async () => {
const interfaces = await apiStore.apiClient?.query(
graphql(`
query General($up: Boolean) {
general {
interfaces(up: $up) {
name
ifindex
ip
flag {
default {
gateway
}
}
}
}
}
`),
{ up: true }
)
const interfaces = await apiStore.apiClient?.query(queries.general, {
up: true
})
return [
'auto',
Expand Down Expand Up @@ -243,24 +218,15 @@ const onSubmit = async (event: FormSubmitEvent<Schema>) => {
...global
} = event.data
await apiStore.apiClient?.mutation(
graphql(`
mutation CreateConfig($name: String, $global: globalInput) {
createConfig(name: $name, global: $global) {
id
}
}
`),
{
name,
global: {
checkInterval: `${checkIntervalSeconds}s`,
checkTolerance: `${checkToleranceMS}ms`,
sniffingTimeout: `${sniffingTimeoutMS}ms`,
...global
}
await apiStore.apiClient?.mutation(mutations.createConfig, {
name,
global: {
checkInterval: `${checkIntervalSeconds}s`,
checkTolerance: `${checkToleranceMS}ms`,
sniffingTimeout: `${sniffingTimeoutMS}ms`,
...global
}
)
})
onReset()
Expand Down
File renamed without changes.
76 changes: 76 additions & 0 deletions components/ResourceDNS.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<script setup lang="ts">
import * as mutations from '~/mutations'
import * as queries from '~/queries'
const apiStore = useAPIStore()
const defaults = await apiStore.getDefaults()
const { data: dnss, execute: reloadDNSs } = useAsyncData(
'routings',
async () => {
const data = await apiStore.apiClient?.query(queries.dnss, {})
return data?.data?.dnss
}
)
const isRemovingDNS = ref(false)
const removeDNS = async (id: string | number) => {
isRemovingDNS.value = true
try {
await apiStore.apiClient?.mutation(mutations.removeDNS, { id })
await reloadDNSs()
} finally {
isRemovingDNS.value = false
}
}
const isSelectingDNS = ref(false)
const selectDNS = async (id: string | number) => {
isSelectingDNS.value = true
try {
await apiStore.apiClient?.mutation(mutations.selectDNS, { id })
await reloadDNSs()
} finally {
isSelectingDNS.value = false
}
}
</script>

<template>
<div class="space-y-2">
<UButton block icon="i-heroicons-plus" />

<UCard v-for="dns in dnss" :key="dns.id">
<template #header>
{{ dns.name }}
</template>

<template #footer>
<div class="flex justify-end gap-2">
<UButton
:loading="isRemovingDNS"
:disabled="dns.id === defaults?.defaultDNSID || dns.selected"
size="xs"
icon="i-heroicons-minus"
@click="removeDNS(dns.id)"
/>

<UButton
:loading="isSelectingDNS"
:disabled="dns.selected"
size="xs"
icon="i-heroicons-map-pin"
@click="selectDNS(dns.id)"
/>
</div>
</template>
</UCard>
</div>
</template>
File renamed without changes.
78 changes: 78 additions & 0 deletions components/ResourceRouting.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<script setup lang="ts">
import * as mutations from '~/mutations'
import * as queries from '~/queries'
const apiStore = useAPIStore()
const defaults = await apiStore.getDefaults()
const { data: routings, execute: reloadRoutings } = useAsyncData(
'routings',
async () => {
const data = await apiStore.apiClient?.query(queries.routings, {})
return data?.data?.routings
}
)
const isRemovingRouting = ref(false)
const removeRouting = async (id: string | number) => {
isRemovingRouting.value = true
try {
await apiStore.apiClient?.mutation(mutations.removeRouting, { id })
await reloadRoutings()
} finally {
isRemovingRouting.value = false
}
}
const isSelectingRouting = ref(false)
const selectRouting = async (id: string | number) => {
isSelectingRouting.value = true
try {
await apiStore.apiClient?.mutation(mutations.selectRouting, { id })
await reloadRoutings()
} finally {
isSelectingRouting.value = false
}
}
</script>

<template>
<div class="space-y-2">
<UButton block icon="i-heroicons-plus" />

<UCard v-for="routing in routings" :key="routing.id">
<template #header>
{{ routing.name }}
</template>

<template #footer>
<div class="flex justify-end gap-2">
<UButton
:loading="isRemovingRouting"
:disabled="
routing.id === defaults?.defaultRoutingID || routing.selected
"
size="xs"
icon="i-heroicons-minus"
@click="removeRouting(routing.id)"
/>

<UButton
:loading="isSelectingRouting"
:disabled="routing.selected"
size="xs"
icon="i-heroicons-map-pin"
@click="selectRouting(routing.id)"
/>
</div>
</template>
</UCard>
</div>
</template>
Loading

0 comments on commit 87ab9b1

Please sign in to comment.