Skip to content

Commit 2da6bea

Browse files
committed
Support for adding columns to a specified location
1 parent 3dcbd5c commit 2da6bea

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/renderer/app/views/object_designer/layout/content/components/create_table/create.table.component.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export class CreateTableComponent {
1717
applyData: DesignerApplyData;
1818

1919
applyTableName: string;
20-
applyColumns: DesignerColumn[] = [];
21-
applyCheckedColumns = new Set<string>;
20+
applyColumns: Array<DesignerColumn> = new Array<DesignerColumn>;
21+
applyCheckedColumns: Set<string> = new Set<string>;
22+
applyLastCheckedColumn: string = null;
2223
dataType = [
2324
'varchar',
2425
'int',
@@ -51,20 +52,37 @@ export class CreateTableComponent {
5152
}
5253
}
5354

54-
handlerPlusColumn() {
55+
handlerGenerateColumn(): DesignerColumn {
5556
const milliseconds = new Date().getTime();
5657
const random = (Math.random() * milliseconds).toFixed(0);
5758
const id = StringUtils.format('{0}_{1}', [milliseconds, random]);
5859
const column = new DesignerColumn();
5960
column.id = id;
60-
this.applyColumns = [...this.applyColumns, column];
61+
return column;
62+
}
63+
64+
handlerPlusColumn() {
65+
this.applyColumns = [...this.applyColumns, this.handlerGenerateColumn()];
66+
}
67+
68+
handlerPlusPreColumn() {
69+
if (this.applyCheckedColumns.size > 0) {
70+
// If contained selected columns are added to the previous row of the column by default
71+
const index = this.applyColumns.findIndex(item => this.applyLastCheckedColumn === item.id);
72+
this.applyColumns.splice(index, 0, this.handlerGenerateColumn());
73+
this.applyColumns = [...this.applyColumns];
74+
} else {
75+
// If not selected, the column is added to the first row by default
76+
this.applyColumns = [this.handlerGenerateColumn(), ...this.applyColumns];
77+
}
6178
}
6279

6380
handlerMinusColumn() {
6481
this.applyColumns = this.applyColumns.filter(column => !this.applyCheckedColumns.has(column.id));
6582
}
6683

6784
handlerColumnChecked(column: string, checked: boolean) {
85+
this.applyLastCheckedColumn = column;
6886
if (checked) {
6987
this.applyCheckedColumns.add(column);
7088
} else {

src/renderer/app/views/object_designer/layout/content/components/create_table/create.table.view.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@
9898
(click)="handlerPlusColumn()">
9999
<i nz-icon nzType="plus-circle" class="action-button-success"></i>
100100
</button>
101+
<button nz-button nzSize="small" nzType="text"
102+
nz-tooltip nzTooltipTitle="{{'common.insert'|translate}}{{'common.column'|translate}}"
103+
(click)="handlerPlusPreColumn()">
104+
<i nz-icon nzType="left-circle" [nzTheme]="'twotone'" [nzTwotoneColor]="'#1890ff'"></i>
105+
</button>
101106
<button nz-button nzSize="small" nzType="text" [disabled]="applyCheckedColumns.size <= 0"
102107
nz-tooltip nzTooltipTitle="{{'common.delete'|translate}}{{'common.column'|translate}}"
103108
(click)="handlerMinusColumn()">

src/renderer/assets/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@
178178
"key": "Key",
179179
"length": "Length",
180180
"beta": "Beta",
181-
"sql": "SQL"
181+
"sql": "SQL",
182+
"insert": "Insert"
182183
},
183184
"language": {
184185
"english": "English",

src/renderer/assets/i18n/zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@
177177
"key": "主键",
178178
"length": "长度",
179179
"beta": "Beta",
180-
"sql": "SQL"
180+
"sql": "SQL",
181+
"insert": "插入"
181182
},
182183
"language": {
183184
"english": "英语",

0 commit comments

Comments
 (0)