-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # src/main.html # src/renderer/resources/lang/code.json # src/renderer/resources/lang/ebs.json # src/renderer/resources/lang/en.json # src/renderer/resources/lang/jp.json # src/renderer/resources/lang/ko.json # src/renderer/resources/lang/vn.json # yarn.lock
- Loading branch information
Showing
45 changed files
with
1,520 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import path from 'path'; | ||
import { CsvModel, ExcelModel } from './models'; | ||
import CommonUtils from '../commonUtils'; | ||
|
||
const Models = [CsvModel, ExcelModel]; | ||
|
||
type ITableData = { | ||
chart: any[]; | ||
fields: string[]; | ||
rows: number; | ||
data: string[][]; | ||
name: string; | ||
} | ||
|
||
class DataTableManager { | ||
private _tables: { [hash: string]: { name: string, data: ITableData } } = {}; | ||
|
||
async makeTableInfo(file: string): Promise<{ id: string; name: string } | undefined> { | ||
try { | ||
const { name, table } = this._createTable(file); | ||
await table.readFile(file); | ||
const rows = table.getRows(); | ||
const hashId = CommonUtils.createFileId(); | ||
const result: ITableData = { | ||
chart: [], | ||
fields: rows.shift() || [], | ||
rows: rows.length, | ||
data: rows, | ||
name, | ||
}; | ||
|
||
this._tables[hashId] = ({ name, data: result }); | ||
return { id: hashId, name }; | ||
} catch (e) { | ||
console.warn('getTable error', e); | ||
} | ||
} | ||
|
||
getTable(hashId: string): ITableData | undefined { | ||
return this._tables[hashId]?.data; | ||
} | ||
|
||
private _createTable(file: string) { | ||
const ext = path.extname(file); | ||
const Model = Models.find((model) => model.getExtensions().includes(ext.replace('.', ''))); | ||
if (!Model) { | ||
throw new Error(`invalid type: ${ext}`); | ||
} | ||
return { | ||
name: path.basename(file), | ||
table: new Model(), | ||
}; | ||
} | ||
} | ||
|
||
export default new DataTableManager(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ITableModel } from './index'; | ||
import csv from 'async-csv'; | ||
import fs from 'fs-extra'; | ||
|
||
class CsvModel implements ITableModel { | ||
private rows: string[][] = []; | ||
|
||
static getExtensions(): string[] { | ||
return ['csv']; | ||
} | ||
|
||
async readFile(file: string): Promise<void> { | ||
const csvString = await fs.readFile(file, 'utf8'); | ||
this.rows = await csv.parse(csvString); | ||
} | ||
|
||
getRows(): string[][] { | ||
return this.rows; | ||
} | ||
} | ||
|
||
export default CsvModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ITableModel } from './index'; | ||
import xlsx from 'node-xlsx'; | ||
|
||
class ExcelModel implements ITableModel { | ||
private sheets?: {name: string, data: [][]}[] = undefined; | ||
|
||
static getExtensions(): string[] { | ||
return ['xlsx', 'xls']; | ||
} | ||
|
||
async readFile(file: string): Promise<void> { | ||
this.sheets = xlsx.parse(file); | ||
} | ||
|
||
getRows(sheetNum = 0): string[][] { | ||
const sheet = this.sheets && this.sheets[sheetNum]; | ||
if (sheet) { | ||
return sheet.data; | ||
} | ||
return []; | ||
} | ||
} | ||
|
||
export default ExcelModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export { default as CsvModel } from './csvModel'; | ||
export { default as ExcelModel } from './excelModel'; | ||
|
||
export interface ITableModel { | ||
readFile(file: string): Promise<void>; | ||
getRows(): string[][]; | ||
// public abstract async write(): Promise<any>; | ||
} |
Oops, something went wrong.