mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
779 B
43 lines
779 B
2 years ago
|
import Papaparse from 'papaparse'
|
||
|
import TemplateGenerator from './TemplateGenerator'
|
||
|
|
||
|
export default class CSVTemplateAdapter extends TemplateGenerator {
|
||
|
fileName: string
|
||
|
project: object
|
||
|
data: object
|
||
|
csv: any
|
||
|
csvData: any
|
||
|
columns: object
|
||
|
|
||
|
constructor(name: string, data: object) {
|
||
|
super()
|
||
|
this.fileName = name
|
||
|
this.csvData = data
|
||
|
this.project = {
|
||
|
title: this.fileName,
|
||
|
tables: [],
|
||
|
}
|
||
|
this.data = {}
|
||
|
this.csv = {}
|
||
|
this.columns = {}
|
||
|
this.csvData = {}
|
||
|
}
|
||
|
|
||
|
async init() {
|
||
|
this.csv = Papaparse.parse(this.csvData, { header: true })
|
||
|
}
|
||
|
|
||
|
parseData() {
|
||
|
this.columns = this.csv.meta.fields
|
||
|
this.data = this.csv.data
|
||
|
}
|
||
|
|
||
|
getColumns() {
|
||
|
return this.columns
|
||
|
}
|
||
|
|
||
|
getData() {
|
||
|
return this.data
|
||
|
}
|
||
|
}
|