Skip to content

Commit

Permalink
feat(config): add clone and manage action, fix #270
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 18, 2023
1 parent 64c5671 commit 3c6a948
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
20 changes: 18 additions & 2 deletions plugins/config/client/components/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<!-- plugin -->
<template v-else>
{{ current.name }}
{{ current.label || current.name }} [{{ current.path }}]
</template>
</template>

Expand Down Expand Up @@ -62,7 +62,7 @@
import { computed, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { clone, message, send, store, useContext, Schema } from '@koishijs/client'
import { Tree, getFullName, addItem, hasCoreDeps, current, plugins, removeItem, dialogSelect } from './utils'
import { Tree, getFullName, addItem, hasCoreDeps, current, plugins, removeItem, dialogSelect, dialogFork } from './utils'
import GlobalSettings from './global.vue'
import GroupSettings from './group.vue'
import TreeView from './tree.vue'
Expand Down Expand Up @@ -117,6 +117,22 @@ ctx.action('config.tree.add-group', {
action: ({ config }) => addItem(config.tree.path, 'reload', 'group'),
})
ctx.action('config.tree.clone', {
disabled: ({ config }) => !config.tree.path || !!config.tree.children,
action: async ({ config }) => {
const ident = Math.random().toString(36).slice(2, 8)
send('manager/unload', config.tree.parent?.path ?? '', `${config.tree.name}:${ident}`, config.tree.config)
router.replace(`/plugins/${ident}`)
},
})
ctx.action('config.tree.manage', {
disabled: ({ config }) => !config.tree.path || !!config.tree.children,
action: async ({ config }) => {
dialogFork.value = config.tree.name
},
})
ctx.action('config.tree.rename', {
disabled: ({ config }) => !config.tree.path,
action: ({ config }) => {
Expand Down
5 changes: 5 additions & 0 deletions plugins/config/client/icons/clone.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<svg class="k-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path fill="currentColor" d="M64 464H288C296.8 464 304 456.8 304 448V384H352V448C352 483.3 323.3 512 288 512H64C28.65 512 0 483.3 0 448V224C0 188.7 28.65 160 64 160H128V208H64C55.16 208 48 215.2 48 224V448C48 456.8 55.16 464 64 464zM160 64C160 28.65 188.7 0 224 0H448C483.3 0 512 28.65 512 64V288C512 323.3 483.3 352 448 352H224C188.7 352 160 323.3 160 288V64zM224 304H448C456.8 304 464 296.8 464 288V64C464 55.16 456.8 48 448 48H224C215.2 48 208 55.16 208 64V288C208 296.8 215.2 304 224 304z"/>
</svg>
</template>
4 changes: 4 additions & 0 deletions plugins/config/client/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import AddGroup from './add-group.vue'
import AddPlugin from './add-plugin.vue'
import TrashCan from './trash-can.vue'
import Check from './check.vue'
import Clone from './clone.vue'
import Manage from './manage.vue'
import Plugin from './plugin.vue'
import Play from './play.vue'
import Stop from './stop.vue'
Expand All @@ -14,6 +16,8 @@ icons.register('add-group', AddGroup)
icons.register('add-plugin', AddPlugin)
icons.register('trash-can', TrashCan)
icons.register('check', Check)
icons.register('clone', Clone)
icons.register('manage', Manage)
icons.register('play', Play)
icons.register('stop', Stop)
icons.register('save', Save)
5 changes: 5 additions & 0 deletions plugins/config/client/icons/manage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<svg class="k-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path fill="currentColor" d="M81.84 152.1C77.43 156.9 71.21 159.8 64.63 159.1C58.05 160.2 51.69 157.6 47.03 152.1L7.029 112.1C-2.343 103.6-2.343 88.4 7.029 79.03C16.4 69.66 31.6 69.66 40.97 79.03L63.08 101.1L118.2 39.94C127 30.09 142.2 29.29 152.1 38.16C161.9 47.03 162.7 62.2 153.8 72.06L81.84 152.1zM81.84 312.1C77.43 316.9 71.21 319.8 64.63 319.1C58.05 320.2 51.69 317.6 47.03 312.1L7.029 272.1C-2.343 263.6-2.343 248.4 7.029 239C16.4 229.7 31.6 229.7 40.97 239L63.08 261.1L118.2 199.9C127 190.1 142.2 189.3 152.1 198.2C161.9 207 162.7 222.2 153.8 232.1L81.84 312.1zM216 120C202.7 120 192 109.3 192 96C192 82.75 202.7 72 216 72H488C501.3 72 512 82.75 512 96C512 109.3 501.3 120 488 120H216zM192 256C192 242.7 202.7 232 216 232H488C501.3 232 512 242.7 512 256C512 269.3 501.3 280 488 280H216C202.7 280 192 269.3 192 256zM160 416C160 402.7 170.7 392 184 392H488C501.3 392 512 402.7 512 416C512 429.3 501.3 440 488 440H184C170.7 440 160 429.3 160 416zM64 448C46.33 448 32 433.7 32 416C32 398.3 46.33 384 64 384C81.67 384 96 398.3 96 416C96 433.7 81.67 448 64 448z"/>
</svg>
</template>
12 changes: 10 additions & 2 deletions plugins/config/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default (ctx: Context) => {
ctx.on('config/dialog-fork', (name) => {
const shortname = name.replace(/(koishi-|^@koishijs\/)plugin-/, '')
const forks = plugins.value.forks[shortname]
if (!forks.length) {
if (!forks?.length) {
const key = Math.random().toString(36).slice(2, 8)
send('manager/unload', '', shortname + ':' + key, {})
router.push('/plugins/' + key)
Expand All @@ -68,7 +68,7 @@ export default (ctx: Context) => {
})

ctx.menu('config.tree', [{
id: '.toggle',
id: '!config.tree.toggle',
type: ({ config }) => config.tree?.disabled ? '' : type.value,
icon: ({ config }) => config.tree?.disabled ? 'play' : 'stop',
label: ({ config }) => (config.tree?.disabled ? '启用' : '停用')
Expand All @@ -90,6 +90,14 @@ export default (ctx: Context) => {
label: ({ config }) => config.tree?.children ? '移除分组' : '移除插件',
}, {
id: '@separator',
}, {
id: '.clone',
icon: 'clone',
label: '克隆配置',
}, {
id: '.manage',
icon: 'manage',
label: '管理多份配置',
}, {
id: '.add-plugin',
icon: 'add-plugin',
Expand Down

0 comments on commit 3c6a948

Please sign in to comment.