{
  "meta": {
    "version": "4.000.9103",
    "fileFormatVersion": "0.4",
    "date": "2024-12-02T22:07:33.379Z",
    "name": "csv-read-write-js",
    "description": "CSV read from file then download to file",
    "groupName": "JavaScript",
    "tags": [
      {
        "text": "DataNodes"
      },
      {
        "text": "CSV"
      },
      {
        "text": "File-download"
      },
      {
        "text": "Table"
      },
      {
        "text": "Button"
      }
    ],
    "schedulerLogOff": true
  },
  "data": {
    "datanodes": [
      {
        "name": "convertToCSV",
        "type": "JSON_formula_plugin",
        "settings": {
          "name": "convertToCSV",
          "autoStart": true,
          "explicitTrig": false,
          "json_var_formula": "\nvar keys = Object.keys(dataNodes[\"csvFile\"]);    \nvar values = _.zip(..._.values(dataNodes[\"csvFile\"]));\n    \nvar csv = Papa.unparse({\n\t\"fields\": keys,\n\t\"data\": values\n},\n{\n\tquotes: false, //or array of booleans\n\tquoteChar: '\"',\n\tescapeChar: '\"',\n\tdelimiter: \";\",\n\theader: true,\n\tnewline: \"\\r\\n\",\n\tskipEmptyLines: false, //or 'greedy',\n\tcolumns: null //or array of strings\n});\n\nreturn csv;"
        }
      },
      {
        "name": "csvFile",
        "type": "CSV_file_reader_plugin",
        "settings": {
          "name": "csvFile",
          "data_path": "export.csv",
          "content": {
            "type": "text/csv",
            "size": "136 bytes",
            "name": "export.csv",
            "content": "lat;lng;CH4\r\n48.876684;2.175765;1.94\r\n48.876684;2.175765;1.95\r\n48.876684;2.175765;1.92\r\n48.876705;2.175806;1.93\r\n48.876705;2.175806;1.99",
            "isBinary": false
          },
          "delimiter": "",
          "eol": "",
          "quote_char": "\"",
          "head": true,
          "skip_empty_lines": true,
          "dynamic_typing": true,
          "pluck": true,
          "embedding_object": false,
          "nb_meta_lines": 0,
          "nb_subheader_lines": 0
        }
      },
      {
        "name": "fileName",
        "type": "JSON_var_plugin",
        "settings": {
          "name": "fileName",
          "json_var": "{\"value\":\"export.csv\"}"
        }
      },
      {
        "name": "saveFile",
        "type": "JSON_formula_plugin",
        "settings": {
          "name": "saveFile",
          "autoStart": false,
          "explicitTrig": true,
          "json_var_formula": "var data, filename, link;\n\t\t\nvar csv = dataNodes.convertToCSV;\nif (csv === null) return;\n\nfilename = dataNodes.fileName.value;\n\nif (!csv.match(/^data:text\\/csv/i)) {\n\tcsv = 'data:text/csv;charset=utf-8,' + csv;\n}\ndata = encodeURI(csv);\nlink = document.createElement('a');\nlink.setAttribute('href', data);\nlink.setAttribute('download', filename);\nlink.click();\n\nreturn true;"
        }
      },
      {
        "name": "tableDisplay",
        "type": "JSON_formula_plugin",
        "settings": {
          "name": "tableDisplay",
          "autoStart": true,
          "explicitTrig": false,
          "json_var_formula": "var vals = _.unzip(_.values(dataNodes[\"csvFile\"]));\nvar keys = _.keys(dataNodes[\"csvFile\"]);\nvals.unshift(keys);\nreturn vals;\n"
        }
      }
    ]
  },
  "libraries": {
    "pyodideStandard": [],
    "pyodideMicropip": []
  },
  "dashboard": {
    "flatUiTableA": {
      "layout": {
        "top": 99,
        "left": 2,
        "height": 454,
        "width": 1224,
        "z-index": "5"
      },
      "container": {
        "instanceId": "flatUiTableA",
        "modelJsonId": "flatUiTable"
      },
      "modelParameters": {
        "headerLine": true,
        "indexColumn": false,
        "tableValueFontSize": 0.5,
        "striped": true,
        "valueColor": "var(--widget-table-value-color)",
        "valueFontFamily": "var(--widget-font-family)",
        "valueAlign": "left",
        "bordered": true,
        "noBorder": false,
        "editableCols": "[]",
        "backgroundColor": {
          "primary": "var(--widget-color-0)",
          "secondary": "var(--widget-table-striped-odd)"
        },
        "paginationMinNbr": 10,
        "paginationOptions": "[10, 50, 100, 500]",
        "paginationDefaultValue": 10,
        "showWidget": true,
        "enableWidget": true
      },
      "modelHiddenParams": {
        "value": null
      }
    },
    "flatUiFileInputButtonA": {
      "layout": {
        "top": 4,
        "left": 7,
        "height": 57,
        "width": 148,
        "z-index": "6"
      },
      "container": {
        "instanceId": "flatUiFileInputButtonA",
        "modelJsonId": "flatUiFileInputButton"
      },
      "modelParameters": {
        "text": "Read CSV",
        "numberOfTriggers": 1,
        "fileInput": true,
        "binaryFileInput": false,
        "buttonFontSize": 0.3,
        "displayIcon": false,
        "fontAwesomeIcon": "",
        "buttonFontFamily": "var(--widget-font-family)",
        "buttonTextColor": "var(--widget-button-primary-text)",
        "buttonDefaultColor": "var(--widget-button-primary-color)",
        "buttonActiveColor": "var(--widget-button-active-color)",
        "buttonHoverColor": "var(--widget-button-hover-color)",
        "showWidget": true,
        "enableWidget": true
      },
      "modelHiddenParams": {}
    },
    "flatUiButtonA": {
      "layout": {
        "top": 3,
        "left": 177,
        "height": 57,
        "width": 148,
        "z-index": "7"
      },
      "container": {
        "instanceId": "flatUiButtonA",
        "modelJsonId": "flatUiButton"
      },
      "modelParameters": {
        "text": "Save csv",
        "numberOfTriggers": 1,
        "fileInput": false,
        "binaryFileInput": false,
        "buttonFontSize": 0.3,
        "displayIcon": false,
        "fontAwesomeIcon": "",
        "buttonFontFamily": "var(--widget-font-family)",
        "buttonTextColor": "var(--widget-button-primary-text)",
        "buttonDefaultColor": "var(--widget-button-primary-color)",
        "buttonActiveColor": "var(--widget-button-active-color)",
        "buttonHoverColor": "var(--widget-button-hover-color)",
        "showWidget": true,
        "enableWidget": true
      },
      "modelHiddenParams": {}
    },
    "flatUiValueDisplayA": {
      "layout": {
        "top": 8,
        "left": 391,
        "height": 48,
        "width": 311,
        "z-index": "8"
      },
      "container": {
        "instanceId": "flatUiValueDisplayA",
        "modelJsonId": "flatUiValueDisplay"
      },
      "modelParameters": {
        "label": "file name:",
        "inheritLabelFromData": false,
        "displayLabel": true,
        "labelFontSize": 0.5,
        "labelColor": "var(--widget-label-color)",
        "labelFontFamily": "var(--widget-font-family)",
        "labelTextAlign": "left",
        "valueWidthProportion": "70%",
        "valueFontSize": 0.5,
        "valueColor": "var(--widget-input-text)",
        "valueFontFamily": "var(--widget-font-family)",
        "valueTextAlign": "left",
        "displayBorder": false,
        "borderColor": "var(--widget-border-color)",
        "backgroundColor": "var(--widget-input-color)",
        "unit": "unitText",
        "displayUnit": false,
        "unitFontSize": 0.5,
        "borderWidth": "2px",
        "showWidget": true,
        "enableWidget": true
      },
      "modelHiddenParams": {
        "value": ""
      }
    }
  },
  "connections": {
    "flatUiTableA": {
      "value": {
        "name": "value",
        "dataNode": "tableDisplay",
        "dataFields": []
      }
    },
    "flatUiFileInputButtonA": {
      "trigger1": {
        "name": "trigger1",
        "dataNode": "csvFile",
        "dataFields": []
      }
    },
    "flatUiButtonA": {
      "trigger1": {
        "name": "trigger1",
        "dataNode": "saveFile",
        "dataFields": []
      }
    },
    "flatUiValueDisplayA": {
      "value": {
        "name": "value",
        "dataNode": "fileName",
        "dataFields": [
          "value"
        ]
      }
    }
  },
  "display": {
    "theme": "default",
    "backgroundColor": "var(--widget-color-0)",
    "inheritThemeBackgroundColor": true,
    "marginX": 10,
    "marginY": 10,
    "width": 1294,
    "height": 590,
    "enforceHeightLimit": false
  },
  "navBarNotification": false
}