Skip to content
Snippets Groups Projects
Verified Commit ff031d11 authored by Kirill Stytsenko's avatar Kirill Stytsenko
Browse files

Controls for selecting column types

parent 61e09305
No related branches found
No related tags found
3 merge requests!23Sprint results,!18Merge Conflicts,!17UI sprint 2
...@@ -100,13 +100,7 @@ export default { ...@@ -100,13 +100,7 @@ export default {
const data = { const data = {
name: this.name, name: this.name,
description: this.description, description: this.description,
columns: this.columns.map((c) => { columns: this.columns
// c.nullAllowed = c.isNullAllowed
// c.primaryKey = c.isPrimaryKey
// delete c.isPrimaryKey
// delete c.isNullAllowed
return c
})
} }
try { try {
const res = await this.$axios.post(`/api/tables/api/database/${this.$route.params.db_id}/table`, data) const res = await this.$axios.post(`/api/tables/api/database/${this.$route.params.db_id}/table`, data)
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
label="CSV File" /> label="CSV File" />
</v-col> </v-col>
<v-col cols="4" class="mt-3"> <v-col cols="4" class="mt-3">
<v-btn :loading="loading" @click="upload">Upload</v-btn> <v-btn :disabled="!file" :loading="loading" @click="upload">Upload</v-btn>
</v-col> </v-col>
</v-row> </v-row>
</v-stepper-content> </v-stepper-content>
...@@ -23,7 +23,28 @@ ...@@ -23,7 +23,28 @@
Choose data type of columns Choose data type of columns
</v-stepper-step> </v-stepper-step>
<v-stepper-content step="2"> <v-stepper-content step="2">
Column select controls <div v-for="(c, idx) in columns" :key="idx">
<v-row dense class="column pa-2 ml-1 mr-1">
<v-col cols="4">
<v-text-field v-model="c.name" required label="Name" />
</v-col>
<v-col cols="3">
<v-select
v-model="c.type"
:items="columnTypes"
item-value="value"
required
label="Data Type" />
</v-col>
<v-col cols="auto" class="pl-2">
<v-checkbox v-model="c.primaryKey" label="Primary Key" />
</v-col>
<v-col cols="auto" class="pl-10">
<v-checkbox v-model="c.nullAllowed" label="Null Allowed" />
</v-col>
</v-row>
</div>
<v-btn color="primary" @click="step = 3"> <v-btn color="primary" @click="step = 3">
Continue Continue
</v-btn> </v-btn>
...@@ -49,7 +70,17 @@ export default { ...@@ -49,7 +70,17 @@ export default {
return { return {
step: 1, step: 1,
loading: false, loading: false,
file: null file: null,
columns: [],
columnTypes: [
{ value: 'ENUM', text: 'ENUM' },
{ value: 'BOOLEAN', text: 'BOOLEAN' },
{ value: 'NUMBER', text: 'NUMBER' },
{ value: 'BLOB', text: 'BLOB' },
{ value: 'DATE', text: 'DATE' },
{ value: 'STRING', text: 'STRING' },
{ value: 'TEXT', text: 'TEXT' }
]
} }
}, },
mounted () { mounted () {
...@@ -57,7 +88,6 @@ export default { ...@@ -57,7 +88,6 @@ export default {
methods: { methods: {
async upload () { async upload () {
this.loading = true this.loading = true
// TODO fix url
const url = '/server-middleware/table_from_csv' const url = '/server-middleware/table_from_csv'
const data = new FormData() const data = new FormData()
data.append('file', this.file) data.append('file', this.file)
...@@ -66,7 +96,8 @@ export default { ...@@ -66,7 +96,8 @@ export default {
headers: { 'Content-Type': 'multipart/form-data' } headers: { 'Content-Type': 'multipart/form-data' }
}) })
if (res.data.success) { if (res.data.success) {
this.$toast.success('Uploaded successfully!') this.columns = res.data.columns
this.step = 2
} else { } else {
this.$toast.error('Could not upload CSV data') this.$toast.error('Could not upload CSV data')
} }
......
...@@ -6,8 +6,12 @@ const fetch = require('node-fetch') ...@@ -6,8 +6,12 @@ const fetch = require('node-fetch')
// TODO extend me // TODO extend me
const colTypeMap = { const colTypeMap = {
Boolean: 'BOOLEAN',
Date: 'DATE',
Integer: 'NUMBER', Integer: 'NUMBER',
String: 'TEXT' Numeric: 'NUMBER',
String: 'TEXT',
Timestamp: 'DATE'
} }
app.post('/table_from_csv', upload.single('file'), async (req, res) => { app.post('/table_from_csv', upload.single('file'), async (req, res) => {
...@@ -22,21 +26,22 @@ app.post('/table_from_csv', upload.single('file'), async (req, res) => { ...@@ -22,21 +26,22 @@ app.post('/table_from_csv', upload.single('file'), async (req, res) => {
} catch (error) { } catch (error) {
res.json({ success: false, error }) res.json({ success: false, error })
} }
console.log('Analysis', analysis)
// map `determine_dt` column types to ours // map messytables / CoMi's `determine_dt` column types to ours
// e.g. "Integer" -> "NUMBER" // e.g. "Integer" -> "NUMBER"
let entries = Object.entries(analysis.columns) let entries = Object.entries(analysis.columns)
console.log(entries)
entries = entries.map(([k, v]) => { entries = entries.map(([k, v]) => {
if (colTypeMap[v]) { if (colTypeMap[v]) {
v = colTypeMap[v] v = colTypeMap[v]
} }
return [k, v] return {
name: k,
type: v,
nullAllowed: true,
primaryKey: false
}
}) })
console.log(entries)
res.json({ success: true, file, columns: entries }) res.json({ success: true, file, columns: entries })
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment