remove unused code

This commit is contained in:
Pig Fang 2020-01-21 11:08:52 +08:00
parent 4c066ac38a
commit be0f74ad64
4 changed files with 0 additions and 400 deletions

View File

@ -1,163 +0,0 @@
<template>
<div class="container-fluid d-flex flex-wrap">
<div v-for="(plugin, index) in plugins" :key="plugin.name" class="info-box mr-3">
<span class="info-box-icon" :class="`bg-${plugin.icon.bg}`">
<i :class="`${plugin.icon.faType} fa-${plugin.icon.fa}`" />
</span>
<div class="info-box-content">
<div class="d-flex justify-content-between">
<div>
<input :checked="plugin.enabled" type="checkbox" @click.prevent="switchPlugin(plugin, $event)">&nbsp;
<strong>{{ plugin.title }}</strong>&nbsp;
<span class="text-gray">v{{ plugin.version }}</span>
</div>
<div class="plugin-actions">
<a
v-if="plugin.readme"
:href="`${baseUrl}/admin/plugins/readme/${plugin.name}`"
>
<i class="fas fa-question" />
</a>
<a
v-if="plugin.enabled && plugin.config"
:href="`${baseUrl}/admin/plugins/config/${plugin.name}`"
>
<i class="fas fa-cog" />
</a>
<a href="#" @click="deletePlugin(plugin, index)">
<i class="fas fa-trash" />
</a>
</div>
</div>
<div class="mt-2 plugin-desc" :title="plugin.description">
{{ plugin.description }}
</div>
</div>
</div>
</div>
</template>
<script>
import alertUnresolvedPlugins from '../../components/mixins/alertUnresolvedPlugins'
import emitMounted from '../../components/mixins/emitMounted'
import { showModal, toast } from '../../scripts/notify'
export default {
name: 'Plugins',
mixins: [
emitMounted,
],
props: {
baseUrl: {
type: String,
default: blessing.base_url,
},
},
data() {
return {
plugins: [],
}
},
beforeMount() {
this.fetchData()
},
methods: {
async fetchData() {
this.plugins = await this.$http.get('/admin/plugins/data')
},
async switchPlugin(plugin, { target }) {
if (target.checked) {
if (await this.enablePlugin(plugin.name)) {
plugin.enabled = true
}
} else if (await this.disablePlugin(plugin.name)) {
plugin.enabled = false
}
},
async enablePlugin(name) {
const {
code, message, data: { reason } = { reason: [] },
} = await this.$http.post(
'/admin/plugins/manage',
{ action: 'enable', name },
)
if (code === 0) {
toast.success(message)
} else {
alertUnresolvedPlugins(message, reason)
}
return code === 0
},
async disablePlugin(name) {
const { code, message } = await this.$http.post(
'/admin/plugins/manage',
{ action: 'disable', name },
)
if (code === 0) {
toast.success(message)
} else {
toast.error(message)
}
return code === 0
},
async deletePlugin(plugin, index) {
try {
await showModal({
title: plugin.title,
text: this.$t('admin.confirmDeletion'),
okButtonType: 'danger',
})
} catch {
return
}
const { code, message } = await this.$http.post(
'/admin/plugins/manage',
{ action: 'delete', name: plugin.name },
)
if (code === 0) {
this.$delete(this.plugins, index)
toast.success(message)
} else {
toast.error(message)
}
},
},
}
</script>
<style lang="stylus">
.info-box
cursor default
transition-property box-shadow
transition-duration 0.3s
width 32%
@media (max-width: 1280px)
width 47%
@media (max-width: 768px)
width 100%
&:hover
box-shadow 0 .5rem 1rem rgba(0,0,0,.15)
.info-box-content
max-width 85%
.plugin-actions
margin-top -7px
a
transition-property color
transition-duration 0.3s
color #000
&:hover
color #999
&:not(:last-child)
margin-right 7px
.plugin-desc
font-size 14px
white-space nowrap
overflow hidden
text-overflow ellipsis
</style>

View File

@ -1,82 +0,0 @@
<template>
<div class="container-fluid">
<vue-good-table
:rows="reports"
:columns="columns"
:search-options="tableOptions.search"
:pagination-options="tableOptions.pagination"
style-class="vgt-table striped"
>
<template #table-row="props">
<span v-if="props.column.field === 'tid'">
{{ props.formattedRow[props.column.field] }}
<a :href="`${baseUrl}/skinlib/show/${props.row.tid}`">
<i class="fa fa-share" />
</a>
</span>
<span v-else-if="props.column.field === 'status'">
{{ $t(`report.status.${props.row.status}`) }}
</span>
<span v-else>
{{ props.formattedRow[props.column.field] }}
</span>
</template>
</vue-good-table>
</div>
</template>
<script>
import { VueGoodTable } from 'vue-good-table'
import 'vue-good-table/dist/vue-good-table.min.css'
import tableOptions from '../../components/mixins/tableOptions'
import emitMounted from '../../components/mixins/emitMounted'
export default {
name: 'MyReports',
components: {
VueGoodTable,
},
mixins: [
emitMounted,
tableOptions,
],
props: {
baseUrl: {
type: String,
default: blessing.base_url,
},
},
data() {
return {
reports: [],
columns: [
{
field: 'id', label: 'ID', type: 'number',
},
{
field: 'tid', label: this.$t('report.tid'), type: 'number',
},
{
field: 'reason',
label: this.$t('report.reason'),
sortable: false,
},
{ field: 'status', label: this.$t('report.status-title') },
{
field: 'report_at',
label: this.$t('report.time'),
globalSearchDisabled: true,
},
],
}
},
mounted() {
this.fetchData()
},
methods: {
async fetchData() {
this.reports = await this.$http.get('/user/reports/list')
},
},
}
</script>

View File

@ -1,138 +0,0 @@
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { flushPromises } from '../../utils'
import { showModal, toast } from '@/scripts/notify'
import Plugins from '@/views/admin/Plugins.vue'
jest.mock('@/scripts/notify')
test('render config button', async () => {
Vue.prototype.$http.get.mockResolvedValue([
{
name: 'a', icon: {}, enabled: true, config: true,
},
{
name: 'b', icon: {}, enabled: false, config: true,
},
{
name: 'c', icon: {}, enabled: false, config: false,
},
])
const wrapper = mount(Plugins)
await flushPromises()
expect(wrapper.find('.info-box:nth-child(1) .fa-cog').exists()).toBeTrue()
expect(wrapper.find('.info-box:nth-child(2) .fa-cog').exists()).toBeFalse()
expect(wrapper.find('.info-box:nth-child(3) .fa-cog').exists()).toBeFalse()
})
test('enable plugin', async () => {
Vue.prototype.$http.get.mockResolvedValue([
{
name: 'a', icon: {}, enabled: false,
},
])
Vue.prototype.$http.post
.mockResolvedValueOnce({
code: 1, message: '1', data: { reason: ['abc'] },
})
.mockResolvedValue({ code: 0, message: '0' })
const wrapper = mount(Plugins)
await flushPromises()
const checkbox = wrapper.find('input[type=checkbox]')
checkbox.trigger('click')
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/plugins/manage',
{ action: 'enable', name: 'a' },
)
expect(showModal).toBeCalledWith({
mode: 'alert',
dangerousHTML: expect.stringContaining('<li>abc</li>'),
})
checkbox.trigger('click')
await flushPromises()
expect(toast.success).toBeCalled()
})
test('disable plugin', async () => {
Vue.prototype.$http.get.mockResolvedValue([
{
name: 'a', icon: {}, enabled: true,
},
])
Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' })
const wrapper = mount(Plugins)
await flushPromises()
const checkbox = wrapper.find('input[type="checkbox"]')
checkbox.trigger('click')
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/plugins/manage',
{ action: 'disable', name: 'a' },
)
checkbox.trigger('click')
await flushPromises()
expect(toast.success).toBeCalledWith('0')
expect(checkbox.attributes('checked')).toBeFalsy()
})
test('delete plugin', async () => {
Vue.prototype.$http.get.mockResolvedValue([
{
name: 'a',
title: 'My Plugin',
icon: {},
},
])
Vue.prototype.$http.post
.mockResolvedValueOnce({ code: 1, message: '1' })
.mockResolvedValue({ code: 0, message: '0' })
showModal
.mockRejectedValueOnce(null)
.mockResolvedValue({ value: '' })
const wrapper = mount(Plugins)
await flushPromises()
const button = wrapper.find('.plugin-actions a')
button.trigger('click')
await flushPromises()
expect(showModal).toBeCalledWith({
title: 'My Plugin',
text: 'admin.confirmDeletion',
okButtonType: 'danger',
})
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/plugins/manage',
{ action: 'delete', name: 'a' },
)
expect(toast.error).toBeCalledWith('1')
button.trigger('click')
await flushPromises()
expect(wrapper.text()).not.toContain('My Plugin')
})
test('readme link', async () => {
Vue.prototype.$http.get.mockResolvedValue([
{
name: 'a',
readme: true,
icon: {},
},
])
const wrapper = mount(Plugins)
await flushPromises()
const link = wrapper.find('.plugin-actions > a:nth-child(1)')
expect(link.attributes('href')).toBe('/admin/plugins/readme/a')
})

View File

@ -1,17 +0,0 @@
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { flushPromises } from '../../utils'
import Report from '@/views/user/Report.vue'
test('basic render', async () => {
Vue.prototype.$http.get.mockResolvedValue([
{
id: 1, tid: 1, reason: 'abc', status: 1,
},
])
const wrapper = mount(Report)
await flushPromises()
expect(wrapper.find('a').attributes('href')).toBe('/skinlib/show/1')
expect(wrapper.text()).toContain('report.status.1')
})