1- import { GridFileSchema } from " ./GridFileSchema" ;
2- import { qdb } from " ../../gridDB/db" ;
3- import { UpdateCellsDB } from " ../../gridDB/Cells/UpdateCellsDB" ;
4- import { UpdateDGraphDB } from " ../../gridDB/DGraph/UpdateDGraphDB" ;
5- import QuadraticDependencyGraph from " ../../dgraph/QuadraticDependencyGraph" ;
1+ import { GridFileSchema } from ' ./GridFileSchema' ;
2+ import { qdb } from ' ../../gridDB/db' ;
3+ import { UpdateCellsDB } from ' ../../gridDB/Cells/UpdateCellsDB' ;
4+ import { UpdateDGraphDB } from ' ../../gridDB/DGraph/UpdateDGraphDB' ;
5+ import QuadraticDependencyGraph from ' ../../dgraph/QuadraticDependencyGraph' ;
66
77const readFileAsync = async ( file : File ) => {
88 // takes a File object and returns it as a string
99 return new Promise < string > ( ( resolve , reject ) => {
1010 let reader = new FileReader ( ) ;
1111
1212 reader . onload = ( ) => {
13- resolve ( reader . result ?. toString ( ) || "" ) ;
13+ resolve ( reader . result ?. toString ( ) || '' ) ;
1414 } ;
1515
1616 reader . onerror = reject ;
1717
18- reader . readAsText ( file , " UTF-8" ) ;
18+ reader . readAsText ( file , ' UTF-8' ) ;
1919 } ) ;
2020} ;
2121
2222const openFileMenuAsync = async ( ) => {
2323 // opens a input file menu for a single .grid file
2424 // once a file is selected, the File object is returned
2525 return new Promise < File > ( ( resolve , reject ) => {
26- const elem = window . document . createElement ( " input" ) ;
27- elem . type = " file" ;
28- elem . accept = " .grid" ;
26+ const elem = window . document . createElement ( ' input' ) ;
27+ elem . type = ' file' ;
28+ elem . accept = ' .grid' ;
2929 document . body . appendChild ( elem ) ;
3030 elem . click ( ) ;
3131 document . body . removeChild ( elem ) ;
@@ -41,21 +41,25 @@ const openFileMenuAsync = async () => {
4141 } ) ;
4242} ;
4343
44- export const OpenGridFile = async ( ) => {
45- // take file input selection from user
46- const fileToLoad = await openFileMenuAsync ( ) ;
47- const result = await readFileAsync ( fileToLoad ) ;
48-
49- // parse file
50- const gridFile = JSON . parse ( result ) as GridFileSchema ;
51-
44+ export const LoadGridFromJSON = async ( gridFileJSON : GridFileSchema ) => {
5245 // clear current grid
5346 await qdb . cells . clear ( ) ;
5447 await qdb . qgrid . clear ( ) ;
5548
5649 // Open file cells and dgraph
57- await UpdateCellsDB ( gridFile . cells ) ;
50+ await UpdateCellsDB ( gridFileJSON . cells ) ;
5851 let qdg = new QuadraticDependencyGraph ( ) ;
59- qdg . load_from_json ( gridFile . dgraph ) ;
52+ qdg . load_from_json ( gridFileJSON . dgraph ) ;
6053 await UpdateDGraphDB ( qdg ) ;
6154} ;
55+
56+ export const OpenGridFile = async ( ) => {
57+ // take file input selection from user
58+ const fileToLoad = await openFileMenuAsync ( ) ;
59+ const result = await readFileAsync ( fileToLoad ) ;
60+
61+ // parse file
62+ const gridFileJSON = JSON . parse ( result ) as GridFileSchema ;
63+
64+ await LoadGridFromJSON ( gridFileJSON ) ;
65+ } ;
0 commit comments