mirror of
https://gitee.com/devlive-community/datacap.git
synced 2024-12-02 20:17:45 +08:00
[Core] Supports batch import of plug-in functions
This commit is contained in:
parent
6575db7a92
commit
d65fdd68c9
@ -0,0 +1,28 @@
|
||||
package io.edurt.datacap.server.body;
|
||||
|
||||
import io.edurt.datacap.server.common.FunctionType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FunctionsImportBody
|
||||
{
|
||||
@NotBlank
|
||||
private String content;
|
||||
|
||||
@NotNull
|
||||
@Size(min = 1)
|
||||
private List<String> plugin;
|
||||
private FunctionType type = FunctionType.KEYWORD;
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package io.edurt.datacap.server.controller.admin;
|
||||
|
||||
import io.edurt.datacap.server.body.FilterBody;
|
||||
import io.edurt.datacap.server.body.FunctionsImportBody;
|
||||
import io.edurt.datacap.server.common.Response;
|
||||
import io.edurt.datacap.server.entity.FunctionsEntity;
|
||||
import io.edurt.datacap.server.entity.PageEntity;
|
||||
@ -50,4 +51,10 @@ public class FunctionsController
|
||||
{
|
||||
return this.functionsService.getById(id);
|
||||
}
|
||||
|
||||
@PutMapping(value = "import")
|
||||
public Response<Object> batchImport(@RequestBody @Validated FunctionsImportBody configure)
|
||||
{
|
||||
return this.functionsService.batchImport(configure);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.edurt.datacap.server.service;
|
||||
|
||||
import io.edurt.datacap.server.body.FilterBody;
|
||||
import io.edurt.datacap.server.body.FunctionsImportBody;
|
||||
import io.edurt.datacap.server.common.Response;
|
||||
import io.edurt.datacap.server.entity.FunctionsEntity;
|
||||
import io.edurt.datacap.server.entity.PageEntity;
|
||||
@ -12,4 +13,6 @@ public interface FunctionsService
|
||||
Response<PageEntity<FunctionsEntity>> getAllByFilter(FilterBody filter);
|
||||
|
||||
Response<FunctionsEntity> getById(Long id);
|
||||
|
||||
Response<Object> batchImport(FunctionsImportBody configure);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.edurt.datacap.server.service.impl;
|
||||
|
||||
import io.edurt.datacap.server.adapter.PageRequestAdapter;
|
||||
import io.edurt.datacap.server.body.FilterBody;
|
||||
import io.edurt.datacap.server.body.FunctionsImportBody;
|
||||
import io.edurt.datacap.server.common.Response;
|
||||
import io.edurt.datacap.server.entity.FunctionsEntity;
|
||||
import io.edurt.datacap.server.entity.PageEntity;
|
||||
@ -10,6 +11,10 @@ import io.edurt.datacap.server.service.FunctionsService;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class FunctionsServiceImpl
|
||||
implements FunctionsService
|
||||
@ -39,4 +44,21 @@ public class FunctionsServiceImpl
|
||||
{
|
||||
return Response.success(this.functionsRepository.findById(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Object> batchImport(FunctionsImportBody configure)
|
||||
{
|
||||
List<FunctionsEntity> functions = new ArrayList<>();
|
||||
Arrays.stream(configure.getContent().split("\n")).forEach(value -> {
|
||||
FunctionsEntity function = new FunctionsEntity();
|
||||
function.setContent(value);
|
||||
function.setName(value);
|
||||
function.setExample(value);
|
||||
function.setPlugin(configure.getPlugin());
|
||||
function.setDescription(value);
|
||||
function.setType(configure.getType());
|
||||
functions.add(function);
|
||||
});
|
||||
return Response.success(this.functionsRepository.saveAll(functions));
|
||||
}
|
||||
}
|
||||
|
@ -62,5 +62,8 @@ export default {
|
||||
type: 'Type',
|
||||
keyword: 'KeyWord',
|
||||
operator: 'Operator',
|
||||
example: 'Example'
|
||||
example: 'Example',
|
||||
more: 'More',
|
||||
batch: 'Batch',
|
||||
import: 'import'
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
export default {
|
||||
elapsedMillisecond: 'The value is expressed in milliseconds',
|
||||
pageShow: 'Open / Close the page'
|
||||
pageShow: 'Open / Close the page',
|
||||
multipleLines: 'One for each line. Multiple lines are represented by newline characters'
|
||||
}
|
||||
|
@ -62,5 +62,8 @@ export default {
|
||||
type: '类型',
|
||||
keyword: '关键字',
|
||||
operator: '操作符',
|
||||
example: '示例'
|
||||
example: '示例',
|
||||
more: '更多',
|
||||
batch: '批量',
|
||||
import: '导入'
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
export default {
|
||||
elapsedMillisecond: '单位为毫秒',
|
||||
pageShow: '开启/关闭分页'
|
||||
pageShow: '开启/关闭分页',
|
||||
multipleLines: '每行一个,多个使用换行符表示'
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
export interface FunctionImport
|
||||
{
|
||||
content: string;
|
||||
plugin: string;
|
||||
type: string;
|
||||
}
|
@ -2,6 +2,7 @@ import {HttpCommon} from "@/common/HttpCommon";
|
||||
import {ResponseModel} from "@/model/ResponseModel";
|
||||
import {Filter} from "@/model/Filter";
|
||||
import {Function} from "@/model/settings/function/Function";
|
||||
import {FunctionImport} from "@/model/settings/function/FunctionImport";
|
||||
|
||||
const baseUrl = "/api/v1/admin/function";
|
||||
|
||||
@ -26,6 +27,11 @@ class FunctionService
|
||||
{
|
||||
return new HttpCommon().get(baseUrl + "/" + id);
|
||||
}
|
||||
|
||||
import(configure: FunctionImport): Promise<ResponseModel>
|
||||
{
|
||||
return new HttpCommon().put(baseUrl + "/import", configure);
|
||||
}
|
||||
}
|
||||
|
||||
export default new FunctionService();
|
||||
|
@ -7,6 +7,17 @@
|
||||
<template #content>{{ $t('common.create') }}</template>
|
||||
<Button type="primary" shape="circle" icon="md-add" size="small" @click="handlerCreateOrUpdate()"/>
|
||||
</Tooltip>
|
||||
<Dropdown>
|
||||
<a href="javascript:void(0)">
|
||||
<Button shape="circle" type="info" size="small" icon="md-more"/>
|
||||
</a>
|
||||
<template #list>
|
||||
<DropdownMenu>
|
||||
<DropdownItem @click="handlerImportController(true)">{{ $t('common.import') }}
|
||||
</DropdownItem>
|
||||
</DropdownMenu>
|
||||
</template>
|
||||
</Dropdown>
|
||||
</Space>
|
||||
</template>
|
||||
<Table :loading="loading" :columns="headers" :data="data.content" @on-sort-change="handlerSort">
|
||||
@ -32,6 +43,7 @@
|
||||
</p>
|
||||
</Card>
|
||||
<FunctionDetails v-if="visibleInfo" :isVisible="visibleInfo" :id="applyId" @close="handlerCloseCreateNew($event)"/>
|
||||
<FunctionImport v-if="visibleImport" :isVisible="visibleImport" @close="handlerImportController($event)"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -44,11 +56,12 @@ import {Order} from "@/model/Order";
|
||||
import {createHeaders} from "@/views/pages/admin/settings/function/FunctionGenerate";
|
||||
import FunctionDetails from "@/views/pages/admin/settings/function/FunctionDetails.vue";
|
||||
import FunctionService from "@/services/settings/function/FunctionService";
|
||||
import FunctionImport from "@/views/pages/admin/settings/function/FunctionImport.vue";
|
||||
|
||||
const filter: Filter = new Filter();
|
||||
export default defineComponent({
|
||||
name: "FunctionAdmin",
|
||||
components: {FunctionDetails},
|
||||
components: {FunctionImport, FunctionDetails},
|
||||
setup()
|
||||
{
|
||||
const i18n = useI18n();
|
||||
@ -65,6 +78,7 @@ export default defineComponent({
|
||||
loading: false,
|
||||
applyId: 0,
|
||||
visibleInfo: false,
|
||||
visibleImport: false,
|
||||
pagination: {
|
||||
total: 0,
|
||||
current: 1,
|
||||
@ -77,6 +91,10 @@ export default defineComponent({
|
||||
this.handlerInitialize(this.filter)
|
||||
},
|
||||
methods: {
|
||||
alert()
|
||||
{
|
||||
return alert
|
||||
},
|
||||
handlerInitialize(filter: Filter)
|
||||
{
|
||||
this.loading = true;
|
||||
@ -141,7 +159,12 @@ export default defineComponent({
|
||||
const plugins = [];
|
||||
elements.forEach(element => plugins.push({tip: element}));
|
||||
return plugins;
|
||||
}
|
||||
},
|
||||
handlerImportController(value: boolean)
|
||||
{
|
||||
this.visibleImport = value;
|
||||
this.handlerInitialize(this.filter);
|
||||
},
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -118,7 +118,7 @@ export default defineComponent({
|
||||
});
|
||||
}
|
||||
},
|
||||
handlerSave()
|
||||
handlerImport()
|
||||
{
|
||||
this.created = true;
|
||||
FunctionService.saveAndUpdate(this.formState, this.isUpdate)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import {Function} from "@/model/settings/function/Function";
|
||||
import {FunctionImport} from "@/model/settings/function/FunctionImport";
|
||||
|
||||
const emptyEntity: Function = {
|
||||
content: '',
|
||||
@ -8,6 +9,9 @@ const emptyEntity: Function = {
|
||||
plugin: '',
|
||||
type: 'KEYWORD'
|
||||
};
|
||||
const emptyImportEntity: FunctionImport = {
|
||||
content: "", plugin: "", type: ""
|
||||
};
|
||||
|
||||
const createHeaders = (i18n: any) => {
|
||||
return [
|
||||
@ -64,7 +68,7 @@ const createHeaders = (i18n: any) => {
|
||||
];
|
||||
};
|
||||
|
||||
const createDefaultType= (i18n: any) => [
|
||||
const createDefaultType = (i18n: any) => [
|
||||
{label: i18n.t('common.keyword'), value: 'KEYWORD'},
|
||||
{label: i18n.t('common.operator'), value: 'OPERATOR'},
|
||||
{label: i18n.t('common.function'), value: 'FUNCTION'}
|
||||
@ -73,5 +77,6 @@ const createDefaultType= (i18n: any) => [
|
||||
export {
|
||||
createHeaders,
|
||||
createDefaultType,
|
||||
emptyEntity
|
||||
emptyEntity,
|
||||
emptyImportEntity
|
||||
}
|
||||
|
@ -0,0 +1,132 @@
|
||||
<template>
|
||||
<div>
|
||||
<Drawer :title="$t('common.import') + $t('common.function')" :width="720" :closable="false"
|
||||
v-model="visible" :maskClosable="false" :z-index="9" :styles="{}">
|
||||
<Form :model="formState">
|
||||
<FormItem :label="$t('common.content')" label-position="top">
|
||||
<Input type="textarea" show-word-limit v-model="formState.content" :placeholder="$t('tooltip.multipleLines')" :rows="12"/>
|
||||
</FormItem>
|
||||
<Row :gutter="32">
|
||||
<Col span="12">
|
||||
<FormItem :label="$t('common.plugin')">
|
||||
<Select v-model="formState.plugin" multiple max-tag-count="3">
|
||||
<OptionGroup v-for="key in Object.keys(plugins)" v-bind:key="key" :label="key">
|
||||
<Option v-for="plugin in plugins[key]" :value="plugin.name" :key="plugin.name">{{ plugin.name }}</Option>
|
||||
</OptionGroup>
|
||||
</Select>
|
||||
</FormItem>
|
||||
</Col>
|
||||
<Col span="12">
|
||||
<FormItem :label="$t('common.type')" name="type" label-position="top">
|
||||
<Select v-model="formState.type">
|
||||
<Option v-for="item in types" :value="item.value" :key="item.value">{{ item.label }}</Option>
|
||||
</Select>
|
||||
</FormItem>
|
||||
</Col>
|
||||
</Row>
|
||||
</Form>
|
||||
<div class="datacap-drawer-footer">
|
||||
<Button :disabled="created" style="margin-right: 8px" @click="handlerCancel()">{{ $t('common.cancel') }}</Button>
|
||||
<Button type="primary" :loading="created" @click="handlerImport()">{{ $t('common.submit') }}</Button>
|
||||
</div>
|
||||
<Spin size="large" fix :show="loading"></Spin>
|
||||
</Drawer>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import {defineComponent, reactive} from 'vue';
|
||||
import {SourceService} from "@/services/SourceService";
|
||||
import {createDefaultType, emptyImportEntity} from "@/views/pages/admin/settings/function/FunctionGenerate";
|
||||
import FunctionService from "@/services/settings/function/FunctionService";
|
||||
import {useI18n} from "vue-i18n";
|
||||
import {FunctionImport} from "@/model/settings/function/FunctionImport";
|
||||
|
||||
export default defineComponent({
|
||||
name: 'FunctionImport',
|
||||
props: {
|
||||
isVisible: {
|
||||
type: Boolean,
|
||||
default: () => false
|
||||
}
|
||||
},
|
||||
setup()
|
||||
{
|
||||
const i18n = useI18n();
|
||||
const types = createDefaultType(i18n);
|
||||
return {
|
||||
types
|
||||
}
|
||||
},
|
||||
data()
|
||||
{
|
||||
return {
|
||||
isUpdate: false,
|
||||
formState: null as unknown as FunctionImport,
|
||||
loading: false,
|
||||
created: false,
|
||||
plugins: []
|
||||
}
|
||||
},
|
||||
created()
|
||||
{
|
||||
this.formState = reactive<FunctionImport>(emptyImportEntity);
|
||||
this.handlerInitialize();
|
||||
},
|
||||
methods: {
|
||||
handlerInitialize()
|
||||
{
|
||||
new SourceService().getPlugins()
|
||||
.then(response => {
|
||||
if (response.status) {
|
||||
this.plugins = response.data;
|
||||
}
|
||||
});
|
||||
},
|
||||
handlerImport()
|
||||
{
|
||||
this.created = true;
|
||||
FunctionService.import(this.formState)
|
||||
.then((response) => {
|
||||
if (response.status) {
|
||||
this.$Message.success("Create successful");
|
||||
this.visible = false;
|
||||
}
|
||||
else {
|
||||
this.$Message.error(response.message);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.created = false;
|
||||
});
|
||||
},
|
||||
handlerCancel()
|
||||
{
|
||||
this.visible = false;
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
visible: {
|
||||
get(): boolean
|
||||
{
|
||||
return this.isVisible
|
||||
},
|
||||
set(value: boolean)
|
||||
{
|
||||
this.$emit('close', value)
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style scoped>
|
||||
.datacap-drawer-footer {
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
border-top: 1px solid #e8e8e8;
|
||||
padding: 10px 16px;
|
||||
text-align: right;
|
||||
background: #fff;
|
||||
}
|
||||
</style>
|
@ -78,7 +78,7 @@ export default defineComponent({
|
||||
this.snippetForm.code = this.codeSnippet;
|
||||
}
|
||||
},
|
||||
handlerSave()
|
||||
handlerImport()
|
||||
{
|
||||
new SnippetService()
|
||||
.saveAndUpdate(this.snippetForm, this.isUpdate)
|
||||
|
@ -249,7 +249,7 @@ export default defineComponent({
|
||||
{
|
||||
this.visible = false;
|
||||
},
|
||||
handlerSave()
|
||||
handlerImport()
|
||||
{
|
||||
this.formState.configures = Arrays.arrayToObject(this.configure);
|
||||
const applyConfigure = clone(this.formState);
|
||||
|
@ -93,7 +93,7 @@ export default defineComponent({
|
||||
});
|
||||
}
|
||||
},
|
||||
handlerSave()
|
||||
handlerImport()
|
||||
{
|
||||
const entity = clone(this.formState);
|
||||
entity.plugin = this.formState.plugin.join(',');
|
||||
|
Loading…
Reference in New Issue
Block a user