@@ -18,9 +18,29 @@ export class CCVizzuPanel {
1818 this . _pageGen = new PageGenerator ( panel , extensionUri ) ;
1919 }
2020
21+ public static export ( folderPath : string ) {
22+ if ( CCVizzuPanel . currentPanel && this . currentPanel ) {
23+ if ( this . currentPanel . _dataTable != undefined )
24+ CCVizzuPanel . currentPanel . _jsonDataExport ( folderPath ) ;
25+ else
26+ window . showErrorMessage ( "No data to export" ) ;
27+ }
28+ }
29+
30+ public static import ( folderPath : string ) {
31+ if ( CCVizzuPanel . currentPanel ) {
32+ CCVizzuPanel . currentPanel . _jsonDataImport ( folderPath ) ;
33+ if ( this . currentPanel != undefined ) {
34+ let panel = this . currentPanel . _panel ;
35+ panel . webview . postMessage ( {
36+ command : 'clear-data-table'
37+ } ) ;
38+ }
39+ }
40+ }
41+
2142 public static refresh ( data : Object , summ : Summary ) {
2243 if ( this . currentPanel != undefined ) {
23- let refreshReq = this . currentPanel . _dataTable != undefined ;
2444 this . currentPanel . _dataTable = data ;
2545 this . currentPanel . _dataSummary = summ ;
2646 let panel = this . currentPanel . _panel ;
@@ -51,7 +71,7 @@ export class CCVizzuPanel {
5171 while ( this . _disposables . length ) {
5272 const disposable = this . _disposables . pop ( ) ;
5373 if ( disposable ) {
54- disposable . dispose ( ) ;
74+ disposable . dispose ( ) ;
5575 }
5676 }
5777 }
@@ -63,7 +83,6 @@ export class CCVizzuPanel {
6383 const text = message . text ;
6484 switch ( command ) {
6585 case "vizzu-ready" :
66- //this._jsonDataExport('/home/...your home directory name comes here.../');
6786 this . _panel . webview . postMessage ( {
6887 command : 'refresh-data-table' ,
6988 dataTable : this . _dataTable ,
@@ -96,16 +115,30 @@ export class CCVizzuPanel {
96115 ) ;
97116 }
98117
118+ private _jsonDataImport ( rootDir : string ) {
119+ if ( rootDir . endsWith ( '/' ) )
120+ rootDir = rootDir . substring ( 0 , rootDir . length - 1 ) ;
121+ this . _dataTable = { } ;
122+ this . _dataSummary = { } ;
123+ const fs = require ( 'fs' ) ;
124+ const text1 = fs . readFileSync ( rootDir + '/data.json' , { encoding :'utf8' , flag :'r' } ) ;
125+ this . _dataTable = JSON . parse ( text1 ) ;
126+ const text2 = fs . readFileSync ( rootDir + '/datasum.json' , { encoding :'utf8' , flag :'r' } ) ;
127+ this . _dataSummary = JSON . parse ( text2 ) ;
128+ }
129+
99130 private _jsonDataExport ( rootDir : string ) {
131+ if ( rootDir . endsWith ( '/' ) )
132+ rootDir = rootDir . substring ( 0 , rootDir . length - 1 ) ;
100133 var fs = require ( 'fs' ) ;
101- fs . writeFile ( rootDir + 'data.json' ,
134+ fs . writeFile ( rootDir + '/ data.json' ,
102135 JSON . stringify ( this . _dataTable ) , function ( err : Object ) {
103136 if ( err )
104137 console . log ( err ) ;
105138 }
106139 ) ;
107140 var fs = require ( 'fs' ) ;
108- fs . writeFile ( rootDir + 'datasum.json' ,
141+ fs . writeFile ( rootDir + '/ datasum.json' ,
109142 JSON . stringify ( this . _dataSummary ) , function ( err : Object ) {
110143 if ( err )
111144 console . log ( err ) ;
0 commit comments