[Core] [Metadata] Support clone row (close #477) (#526)

This commit is contained in:
Devlive Community 2023-12-02 10:51:00 +08:00 committed by GitHub
commit 65697cfe9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 12 deletions

View File

@ -23,6 +23,7 @@ import io.edurt.datacap.spi.Plugin;
import io.edurt.datacap.spi.model.Configure;
import io.edurt.datacap.spi.model.Pagination;
import io.edurt.datacap.spi.model.Response;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.stereotype.Service;
@ -208,12 +209,31 @@ public class TableServiceImpl
updateConfigure.setFormat(FormatType.NONE);
plugin.connect(updateConfigure);
List<String> allSql = Lists.newArrayList();
// Gets the auto-increment column for the current row
List<String> autoIncrementColumns = table.getColumns()
.stream()
.filter(v -> v.getExtra().toLowerCase().contains("auto_increment"))
.map(v -> v.getName())
.collect(Collectors.toList());
configure.getNewColumns().forEach(v -> {
List<SqlColumn> columns = Lists.newArrayList();
v.entrySet().forEach(entry -> columns.add(SqlColumn.builder()
.column(String.format("`%s`", entry.getKey()))
.value(entry.getValue())
.build()));
v.entrySet().forEach(entry -> {
SqlColumn column = SqlColumn.builder()
.column(String.format("`%s`", entry.getKey()))
.build();
if (entry.getValue() == null) {
column.setValue(null);
}
else {
if (autoIncrementColumns.contains(entry.getKey())) {
column.setValue(null);
}
else {
column.setValue(String.format("'%s'", StringEscapeUtils.escapeSql(entry.getValue())));
}
}
columns.add(column);
});
SqlBody body = SqlBody.builder()
.type(SqlType.INSERT)
.database(table.getDatabase().getName())

View File

@ -12,6 +12,7 @@ import {
faCircle,
faCircleInfo,
faClock,
faClone,
faColumns,
faDatabase,
faDroplet,
@ -40,6 +41,7 @@ import {
*/
const createIcons = (app: any) => {
library.add(faArrowRight,
faClone,
faPlus,
faTablet,
faMinus,

View File

@ -67,7 +67,7 @@
<Button :disabled="currentUserId !== row.user.id" shape="circle" type="error" size="small" icon="md-trash"/>
</Poptip>
</Tooltip>
<Tooltip :content="$t('common.admin') + $t('common.beta')"
<Tooltip :content="$t('common.admin')"
transfer>
<Button :disabled="currentUserId !== row.user.id || !row.available"
shape="circle"

View File

@ -81,10 +81,20 @@
<Button size="small"
shape="circle"
type="text"
@click="handlerAddRow">
@click="handlerAddOrCloneRow(false)">
<FontAwesomeIcon icon="plus"/>
</Button>
</Tooltip>
<Tooltip :content="$t('source.manager.addRows')"
transfer>
<Button size="small"
shape="circle"
type="text"
:disabled="dataSelectedChanged.columns.length === 0"
@click="handlerAddOrCloneRow(true)">
<FontAwesomeIcon icon="clone"/>
</Button>
</Tooltip>
<Tooltip :content="$t('source.manager.deleteRows')"
transfer>
<Button size="small"
@ -450,14 +460,22 @@ export default defineComponent({
{
this.filterConfigure.configure = value;
},
handlerAddRow()
handlerAddOrCloneRow(clone: boolean)
{
const newData = {};
this.originalColumns.forEach((column: { field: string; }) => {
newData[column.field] = null;
});
this.configure.datasets.push(newData);
this.newRows.push(newData);
if (!clone) {
this.originalColumns.forEach((column: { field: string; }) => {
newData[column.field] = null;
});
this.configure.datasets.push(newData);
this.newRows.push(newData);
}
else {
this.dataSelectedChanged.columns.forEach(column => {
this.configure.datasets.push(column);
this.newRows.push(column);
});
}
this.dataCellChanged.type = SqlType.INSERT;
this.dataCellChanged.changed = true;
this.dataCellChanged.columns = this.newRows;