@@ -407,10 +407,10 @@ WOQLClient.prototype.insertCSV = function(csv_path, commitMsg, gtype, gid) {
407
407
let commit = this . generateCommitInfo ( commitMsg )
408
408
const formData = new FormData ( ) ;
409
409
csv_path . map ( ( item ) => {
410
- if ( typeof ( item . name ) == "string" ) { // file objects
410
+ if ( typeof ( item . name ) == "string" ) {
411
411
formData . append ( item . name , item )
412
412
}
413
- else { // string file paths
413
+ else {
414
414
let name = new String ( item ) . substring ( item . lastIndexOf ( '/' ) + 1 ) ;
415
415
var fr = new File ( [ name ] , item , { type : "csv/text" } ) ;
416
416
formData . append ( name , fr )
@@ -456,15 +456,53 @@ WOQLClient.prototype.updateCSV = function(csv, commitMsg, gtype, gid) {
456
456
*
457
457
* @param {string } csvName Name of csv to dump from the specified database to extract
458
458
* @param {string } csvDirectory CSV output directory path. (defaults to current directory).
459
+ * @param {string } download flag to download csv file
459
460
* @param {string } gtype Type of graph (instance|schema|inference)
460
461
* @param {string } gid identifier.
461
462
* @return {Promise } An API success message
462
463
*
463
464
*/
464
- WOQLClient . prototype . getCSV = function ( csvName , csvDirectory , gtype , gid ) {
465
- let options = { }
465
+ WOQLClient . prototype . getCSV = function ( csvName , download , gtype , gid ) {
466
+ let options = { } , filePath
466
467
options . name = csvName ;
467
- return this . dispatch ( CONST . GET_CSV , this . connectionConfig . csvURL ( gtype , gid ) , options )
468
+ return this . dispatch ( CONST . GET_CSV , this . connectionConfig . csvURL ( gtype , gid ) , options ) . then ( results => {
469
+ if ( download ) {
470
+ const url = window . URL . createObjectURL ( new Blob ( [ results ] ) ) ;
471
+ const link = document . createElement ( 'a' ) ;
472
+ link . href = url ;
473
+ link . setAttribute ( 'download' , csvName ) ;
474
+ document . body . appendChild ( link ) ;
475
+ link . click ( ) ;
476
+ }
477
+ return results ;
478
+ } )
479
+ }
480
+
481
+ /**
482
+ * Deletes a csv into the specified path
483
+ *
484
+ * @param {array } csvName is an array of csv file names
485
+ * @param {string } gtype type of graph |instance|schema|inference|
486
+ * @param {string } gid TerminusDB Graph ID to update, main is the default value
487
+ * @return {Promise } An API success message
488
+ */
489
+ WOQLClient . prototype . deleteCSV = function ( csvName , gtype , gid ) {
490
+ let options = { } , filePath
491
+ options . name = csvName ;
492
+ return this . dispatch ( CONST . DELETE_CSV , this . connectionConfig . csvURL ( gtype , gid ) , options ) . then ( results => {
493
+ return results ;
494
+ } )
495
+ }
496
+
497
+ /**
498
+ * sends a message to the server
499
+ * @param {string } msg - textual string
500
+ */
501
+ WOQLClient . prototype . message = function ( message ) {
502
+ const url = this . api ( ) + 'message'
503
+ return this . dispatch ( CONST . MESSAGE , url , message ) . then ( response => {
504
+ return response
505
+ } )
468
506
}
469
507
470
508
0 commit comments