Compare commits
No commits in common. "744e48e812ef321c58732b7a7c8571a48be1f5ff" and "98392327693d03be92fee7c619dba89d08dfc964" have entirely different histories.
744e48e812
...
9839232769
@ -1,4 +1,3 @@
|
|||||||
//Array of part names to omit from the BOM
|
|
||||||
export const rejectedParts = [
|
export const rejectedParts = [
|
||||||
'TP1',
|
'TP1',
|
||||||
'TP2',
|
'TP2',
|
||||||
@ -20,14 +19,3 @@ export const rejectedParts = [
|
|||||||
'IN',
|
'IN',
|
||||||
'OUT',
|
'OUT',
|
||||||
];
|
];
|
||||||
|
|
||||||
//Header titles for the table
|
|
||||||
export const headers: string[] = ['Part', 'Value'];
|
|
||||||
|
|
||||||
//Config object for csv library
|
|
||||||
export const csvConfig = {
|
|
||||||
delimiter: `;`,
|
|
||||||
quote: '"',
|
|
||||||
ignoreEmpty: true,
|
|
||||||
includeColumns: /(Part|Value)/,
|
|
||||||
};
|
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
|
import { CSVParseParam } from '../node_modules/csvtojson/v2/Parameters';
|
||||||
import { isJunk } from './utils';
|
import { isJunk } from './utils';
|
||||||
import { csvConfig } from './config';
|
|
||||||
const csv = require('csvtojson');
|
const csv = require('csvtojson');
|
||||||
|
|
||||||
|
//CSV Config for EAGLE BOM
|
||||||
|
const csvConfig = {
|
||||||
|
delimiter: `;`,
|
||||||
|
quote: '"',
|
||||||
|
ignoreEmpty: true,
|
||||||
|
includeColumns: /(Part|Value)/,
|
||||||
|
};
|
||||||
|
|
||||||
export async function getBOM(csvBOM: string) {
|
export async function getBOM(csvBOM: string) {
|
||||||
const rawBOM = await csv(csvConfig).fromString(csvBOM);
|
const rawBOM = await csv(csvConfig).fromString(csvBOM);
|
||||||
const bom = rawBOM.filter((part: part) => !isJunk(part));
|
const bom = rawBOM.filter((part: part) => !isJunk(part));
|
||||||
|
19
src/index.ts
19
src/index.ts
@ -1,13 +1,16 @@
|
|||||||
//Modules
|
//Modules
|
||||||
import { getBOM } from './csvToJSON';
|
import { getBOM } from './csvToJSON';
|
||||||
import { PartsTable } from './table';
|
import {
|
||||||
import { headers } from './config';
|
createTableBody,
|
||||||
|
createTableHeader,
|
||||||
|
htmlTable,
|
||||||
|
clearTable,
|
||||||
|
} from './utils';
|
||||||
|
|
||||||
//DOM elements
|
//DOM elements
|
||||||
const input = document.getElementById('csvInput') as HTMLInputElement;
|
const input = document.getElementById('csvInput') as HTMLInputElement;
|
||||||
const csvTextOutput = document.getElementById('csvText') as HTMLPreElement;
|
const csvTextOutput = document.getElementById('csvText') as HTMLPreElement;
|
||||||
const jsonTextOutput = document.getElementById('partsJSON') as HTMLPreElement;
|
const jsonTextOutput = document.getElementById('partsJSON') as HTMLPreElement;
|
||||||
const htmlTable = document.getElementById('partsTable') as HTMLTableElement;
|
|
||||||
|
|
||||||
let csvBOM: string;
|
let csvBOM: string;
|
||||||
|
|
||||||
@ -34,20 +37,22 @@ function processCSV(fileReader: Event) {
|
|||||||
//JSON Object
|
//JSON Object
|
||||||
printJSONbom(csvString);
|
printJSONbom(csvString);
|
||||||
//Table
|
//Table
|
||||||
|
clearTable();
|
||||||
createTable();
|
createTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Print JSON
|
//TODO
|
||||||
async function printJSONbom(csvString: string) {
|
async function printJSONbom(csvString: string) {
|
||||||
const bomJSON = await getBOM(csvString);
|
const bomJSON = await getBOM(csvString);
|
||||||
|
// console.log(bomJSON);
|
||||||
jsonTextOutput.innerText = JSON.stringify(bomJSON, null, 2);
|
jsonTextOutput.innerText = JSON.stringify(bomJSON, null, 2);
|
||||||
|
return bomJSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Construct table
|
|
||||||
async function createTable() {
|
async function createTable() {
|
||||||
const bomJSON = await getBOM(csvBOM);
|
const bomJSON = await getBOM(csvBOM);
|
||||||
const partsTable = new PartsTable(htmlTable, headers, bomJSON);
|
createTableHeader();
|
||||||
partsTable.createTable();
|
createTableBody(htmlTable, bomJSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add event listener
|
//Add event listener
|
||||||
|
48
src/table.ts
48
src/table.ts
@ -1,48 +0,0 @@
|
|||||||
export class PartsTable {
|
|
||||||
constructor(
|
|
||||||
public htmlTable: HTMLTableElement,
|
|
||||||
public headers: string[],
|
|
||||||
public jsonBOM: part[],
|
|
||||||
) {}
|
|
||||||
|
|
||||||
//Reset table
|
|
||||||
public clearTable(): void {
|
|
||||||
this.htmlTable.innerHTML = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
//Header
|
|
||||||
private createTableHeader(): void {
|
|
||||||
const tHead = this.htmlTable.createTHead();
|
|
||||||
const hRow = tHead.insertRow();
|
|
||||||
//Populate headers with text
|
|
||||||
for (const header of this.headers) {
|
|
||||||
const th = document.createElement('th');
|
|
||||||
const headerText = document.createTextNode(header);
|
|
||||||
th.appendChild(headerText);
|
|
||||||
hRow.appendChild(th);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Body
|
|
||||||
private createTableBody(): void {
|
|
||||||
this.jsonBOM.map((component) => {
|
|
||||||
//Create a row
|
|
||||||
const tRow = this.htmlTable.insertRow();
|
|
||||||
//Insert part name
|
|
||||||
const partName = tRow.insertCell();
|
|
||||||
const partNameText = document.createTextNode(component.Part);
|
|
||||||
partName.appendChild(partNameText);
|
|
||||||
//Insert part value
|
|
||||||
const partValue = tRow.insertCell();
|
|
||||||
const partValText = document.createTextNode(component.Value);
|
|
||||||
partValue.appendChild(partValText);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create full table
|
|
||||||
public createTable(): void {
|
|
||||||
this.clearTable();
|
|
||||||
this.createTableHeader();
|
|
||||||
this.createTableBody();
|
|
||||||
}
|
|
||||||
}
|
|
39
src/utils.ts
39
src/utils.ts
@ -1,10 +1,47 @@
|
|||||||
import { rejectedParts, headers } from './config';
|
import { rejectedParts } from './config';
|
||||||
|
|
||||||
export function isJunk(element: part): boolean {
|
export function isJunk(element: part): boolean {
|
||||||
// Returns true if element is in the rejected list
|
// Returns true if element is in the rejected list
|
||||||
return rejectedParts.includes(element.Part);
|
return rejectedParts.includes(element.Part);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Table functions
|
||||||
|
export function clearTable() {
|
||||||
|
document.querySelector('table')!.innerHTML = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
export const htmlTable = document.getElementById(
|
||||||
|
'partsTable',
|
||||||
|
) as HTMLTableElement;
|
||||||
|
const headers: string[] = ['Part', 'Value'];
|
||||||
|
|
||||||
|
export function createTableHeader(): void {
|
||||||
|
const tHead = htmlTable.createTHead();
|
||||||
|
const hRow = tHead.insertRow();
|
||||||
|
//Populate headers with text
|
||||||
|
for (const header of headers) {
|
||||||
|
const th = document.createElement('th');
|
||||||
|
const headerText = document.createTextNode(header);
|
||||||
|
th.appendChild(headerText);
|
||||||
|
hRow.appendChild(th);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createTableBody(table: HTMLTableElement, parts: part[]) {
|
||||||
|
parts.map((component) => {
|
||||||
|
//Create a row
|
||||||
|
const tRow = table.insertRow();
|
||||||
|
//Insert part name
|
||||||
|
const partName = tRow.insertCell();
|
||||||
|
const partNameText = document.createTextNode(component.Part);
|
||||||
|
partName.appendChild(partNameText);
|
||||||
|
//Insert part value
|
||||||
|
const partValue = tRow.insertCell();
|
||||||
|
const partValText = document.createTextNode(component.Value);
|
||||||
|
partValue.appendChild(partValText);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user