Skip to content

Commit c834641

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 5c663b4 + 3306b72 commit c834641

File tree

6 files changed

+53
-24
lines changed

6 files changed

+53
-24
lines changed

backend/apps/datasource/api/datasource.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from apps.db.engine import create_table, get_data_engine, insert_data
1010
from common.core.deps import SessionDep, CurrentUser
1111
from ..crud.datasource import get_datasource_list, check_status, create_ds, update_ds, delete_ds, getTables, getFields, \
12-
execSql, update_table_and_fields, getTablesByDs, chooseTables, preview, updateTable, updateField
12+
execSql, update_table_and_fields, getTablesByDs, chooseTables, preview, updateTable, updateField, get_ds
1313
from ..crud.field import get_fields_by_table_id
1414
from ..crud.table import get_tables_by_ds_id
1515
from ..models.datasource import CoreDatasource, CreateDatasource, TableObj, CoreTable, CoreField
@@ -23,6 +23,11 @@ async def datasource_list(session: SessionDep):
2323
return get_datasource_list(session=session)
2424

2525

26+
@router.post("/get/{id}")
27+
async def get_datasource(session: SessionDep, id: int):
28+
return get_ds(session, id)
29+
30+
2631
@router.post("/check")
2732
async def check(session: SessionDep, ds: CoreDatasource):
2833
return check_status(session, ds)

backend/apps/datasource/crud/datasource.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ def get_datasource_list(session: SessionDep):
2424
return datasource_list
2525

2626

27+
def get_ds(session: SessionDep, id: int):
28+
statement = select(CoreDatasource).where(CoreDatasource.id == id)
29+
datasource = session.exec(statement).first()
30+
return datasource
31+
32+
2733
def check_status(session: SessionDep, ds: CoreDatasource):
2834
conn = get_engine(ds)
2935
try:

frontend/src/api/datasource.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ export const datasourceApi = {
1616
edit: (data: any) => request.post('/datasource/editLocalComment', data),
1717
previewData: (id: Number, data: any) => request.post(`/datasource/previewData/${id}`, data),
1818
saveTable: (data: any) => request.post('/datasource/editTable', data),
19-
saveField: (data: any) => request.post('/datasource/editField', data)
19+
saveField: (data: any) => request.post('/datasource/editField', data),
20+
getDs: (id: Number) => request.post(`/datasource/get/${id}`),
2021
}

frontend/src/views/ds/TableList.vue

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
</div>
1010
<div class="container">
1111
<div class="left-side">
12-
Tables
12+
<div style="display: flex;justify-content: space-between;align-items: center;">
13+
<span>Tables</span>
14+
<el-button style="padding: 12px;" text @click="editTables(ds)" :icon="CreditCard"/>
15+
</div>
1316
<el-input
1417
style="margin: 16px 0"
1518
v-model="searchValue"
@@ -134,6 +137,7 @@
134137
</div>
135138
</el-dialog>
136139
</div>
140+
<DsForm ref="dsForm" @refresh="refresh"/>
137141
</template>
138142

139143
<script lang="tsx" setup>
@@ -143,6 +147,8 @@ import { onMounted } from "vue";
143147
import { ArrowLeft } from "@element-plus/icons-vue";
144148
import type { TabsPaneContext } from "element-plus-secondary";
145149
import IconOpeEdit from '@/assets/svg/operate/ope-edit.svg'
150+
import {CreditCard} from '@element-plus/icons-vue'
151+
import DsForm from './form.vue'
146152
147153
const props = defineProps({
148154
dsId: { type: [Number], required: true },
@@ -160,6 +166,8 @@ const previewData = ref<any>({});
160166
const activeName = ref("schema");
161167
const tableDialog = ref<boolean>(false)
162168
const fieldDialog = ref<boolean>(false)
169+
const dsForm = ref()
170+
const ds = ref<any>({})
163171
164172
const buildData = () => {
165173
return { table: currentTable.value, fields: fieldList.value };
@@ -241,12 +249,27 @@ const handleClick = (tab: TabsPaneContext) => {
241249
}
242250
};
243251
244-
onMounted(() => {
252+
const editTables = (item: any) => {
253+
dsForm.value.open(item, true)
254+
}
255+
256+
const refresh = () => {
257+
init()
258+
}
259+
260+
const init = () => {
245261
dsId.value = props.dsId;
246-
fieldList.value = [];
247-
datasourceApi.tableList(props.dsId).then((res) => {
248-
tableList.value = res;
249-
});
262+
datasourceApi.getDs(dsId.value).then((res) => {
263+
ds.value = res
264+
fieldList.value = [];
265+
datasourceApi.tableList(props.dsId).then((res) => {
266+
tableList.value = res;
267+
});
268+
})
269+
}
270+
271+
onMounted(() => {
272+
init()
250273
});
251274
</script>
252275

frontend/src/views/ds/form.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
>Preview</el-button
150150
>
151151
<el-button
152+
:loading="saveLoading"
152153
v-show="active === 1 || !isCreate"
153154
type="primary"
154155
@click="save(dsFormRef)"
@@ -182,6 +183,7 @@ const token = wsCache.get("user.token");
182183
const headers = ref<any>({ "X-SQLBOT-TOKEN": `Bearer ${token}` });
183184
const dialogTitle = ref("");
184185
const getUploadURL = import.meta.env.VITE_API_BASE_URL + '/datasource/uploadExcel'
186+
const saveLoading = ref<boolean>(false)
185187
186188
187189
const rules = reactive<FormRules>({
@@ -236,6 +238,7 @@ const close = () => {
236238
checkList.value = [];
237239
tableList.value = [];
238240
excelUploadSuccess.value = false;
241+
saveLoading.value = false
239242
};
240243
241244
const open = (item: any, editTable: boolean = false) => {
@@ -327,6 +330,7 @@ const save = async (formEl: FormInstance | undefined) => {
327330
if (!formEl) return;
328331
await formEl.validate((valid) => {
329332
if (valid) {
333+
saveLoading.value = true
330334
const list = tableList.value
331335
.filter((ele: any) => {
332336
return checkList.value.includes(ele.tableName);
@@ -348,6 +352,7 @@ const save = async (formEl: FormInstance | undefined) => {
348352
// save table and field
349353
datasourceApi.chooseTables(form.value.id, list).then(() => {
350354
close();
355+
emit("refresh");
351356
});
352357
}
353358
} else {

frontend/src/views/ds/index.vue

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<DatasourceItemCard :ds="ds">
2727
<div class="connection-actions">
2828
<el-button class="action-btn" circle @click="getTables(ds.id, ds.name)" :icon="List"/>
29-
<el-button class="action-btn" circle @click="editTables(ds)" :icon="CreditCard"/>
29+
<!-- <el-button class="action-btn" circle @click="editTables(ds)" :icon="CreditCard"/> -->
3030
<el-button type="primary" class="action-btn" circle @click="editDs(ds)" :icon="IconOpeEdit"/>
3131
<el-button type="danger" class="action-btn" circle @click="deleteDs(ds)" :icon="IconOpeDelete"/>
3232
</div>
@@ -40,7 +40,7 @@
4040
import IconOpeAdd from '@/assets/svg/operate/ope-add.svg'
4141
import IconOpeEdit from '@/assets/svg/operate/ope-edit.svg'
4242
import IconOpeDelete from '@/assets/svg/operate/ope-delete.svg'
43-
import {Search, List, CreditCard} from '@element-plus/icons-vue'
43+
import {Search, List} from '@element-plus/icons-vue'
4444
import {ref, onMounted} from 'vue'
4545
import DsForm from './form.vue'
4646
import {datasourceApi} from '@/api/datasource'
@@ -83,9 +83,9 @@ const editDs = (item: any) => {
8383
dsForm.value.open(item)
8484
}
8585
86-
const editTables = (item: any) => {
87-
dsForm.value.open(item, true)
88-
}
86+
// const editTables = (item: any) => {
87+
// dsForm.value.open(item, true)
88+
// }
8989
9090
const deleteDs = (item: any) => {
9191
ElMessageBox.confirm(
@@ -108,17 +108,6 @@ const deleteDs = (item: any) => {
108108
}
109109
110110
const getTables = (id: number, name: string) => {
111-
// datasourceApi.getTables(id).then((res) => {
112-
// console.log(res)
113-
// })
114-
115-
// datasourceApi.getFields(id,'core_dataset_table').then((res) => {
116-
// console.log(res)
117-
// })
118-
119-
// datasourceApi.execSql(id,'select id,name,table_name from core_dataset_table limit 10').then((res) => {
120-
// console.log(res)
121-
// })
122111
router.push(`/dsTable/${id}/${name}`)
123112
}
124113

0 commit comments

Comments
 (0)