@@ -407,10 +407,10 @@ WOQLClient.prototype.insertCSV = function(csv_path, commitMsg, gtype, gid) {
407407 let commit = this . generateCommitInfo ( commitMsg )
408408 const formData = new FormData ( ) ;
409409 csv_path . map ( ( item ) => {
410- if ( typeof ( item . name ) == "string" ) { // file objects
410+ if ( typeof ( item . name ) == "string" ) {
411411 formData . append ( item . name , item )
412412 }
413- else { // string file paths
413+ else {
414414 let name = new String ( item ) . substring ( item . lastIndexOf ( '/' ) + 1 ) ;
415415 var fr = new File ( [ name ] , item , { type : "csv/text" } ) ;
416416 formData . append ( name , fr )
@@ -456,15 +456,53 @@ WOQLClient.prototype.updateCSV = function(csv, commitMsg, gtype, gid) {
456456 *
457457 * @param {string } csvName Name of csv to dump from the specified database to extract
458458 * @param {string } csvDirectory CSV output directory path. (defaults to current directory).
459+ * @param {string } download flag to download csv file
459460 * @param {string } gtype Type of graph (instance|schema|inference)
460461 * @param {string } gid identifier.
461462 * @return {Promise } An API success message
462463 *
463464 */
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
466467 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+ } )
468506}
469507
470508
0 commit comments