From b42b14eed8f04587ca3ffe54f973fdb27e73a51e Mon Sep 17 00:00:00 2001 From: j Date: Wed, 5 Dec 2018 17:18:57 +0100 Subject: [PATCH] export csv --- static/index.html | 1 + static/js/cccc.js | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/static/index.html b/static/index.html index 3bda12c..8e4b674 100644 --- a/static/index.html +++ b/static/index.html @@ -100,6 +100,7 @@
  • Global Speed:
  • Export:

  • +
  • Import:

  • import sequence
  • diff --git a/static/js/cccc.js b/static/js/cccc.js index cb943d5..e618aa6 100644 --- a/static/js/cccc.js +++ b/static/js/cccc.js @@ -489,6 +489,47 @@ function exportSequence() { }) } +function getPreset(id) { + return presets.filter(function(preset) { + return preset.id == id; + })[0] +} + +function exportSequenceCSV() { + var position = 0; + return data.map(function(row) { + var r = []; + r.push(row.preset) + var preset = getPreset(row.preset) + r.push(preset.name) + if (row.duration) { + position += row.duration + r.push(formatDuration(position)) + r.push(formatDuration(row.duration)) + } else { + r.push('') + r.push('') + } + r.push(row.speed) + r.push(row.sleep) + return r.join(','); + }).join('\n'); +} + +$('button.export_sequence_csv').on({click: function() { + data.forEach(function(seq) { + if (!seq.seqid) { + seq.seqid = uuidv4() + } + }) + var blob = textBlob(JSON.stringify(exportSequenceCSV(), null, ' ')) + var url = window.URL.createObjectURL(blob); + $(this).parent().attr({ + href: url, download: 'sequence.csv' + }); +}}) + + $('button.export_sequence').on({click: function() { data.forEach(function(seq) { if (!seq.seqid) {