From dc41fd7ba98d0de5e1979dd29c87ad25b1d9fc6d Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 5 Mar 2019 19:56:42 +0100 Subject: [PATCH] Tidying up a little bit and implementing file (.fsm) import --- js/export/export.js | 18 ++++++++++-------- js/menu.js | 14 ++++++++------ js/simulate.js | 4 +--- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/js/export/export.js b/js/export/export.js index baafd62..caad25b 100644 --- a/js/export/export.js +++ b/js/export/export.js @@ -1,4 +1,4 @@ -function prepareForExport(doc, _settings = settings) { +function prepareForExport(doc, settings = settings) { let states = JSON.parse(JSON.stringify(doc.states)); states.forEach(state => { @@ -37,9 +37,13 @@ function prepareForExport(doc, _settings = settings) { delete _doc.lastSavedHash; delete _doc.element; + const _settings = JSON.parse(JSON.stringify(settings)); + + delete _settings.colors.getColor; + return { document: _doc, - _settings, + settings: _settings, }; } @@ -91,8 +95,8 @@ function parseFromJson(json) { function importFromJson(json) { const doc = parseFromJson(json); - addDocument(doc); - switchDocument(doc); + addDocument(doc.document); + switchDocument(doc.document); } function exportToFile() { @@ -109,9 +113,7 @@ function exportToFile() { function downloadFile(name, content, type) { const element = document.createElement('a'); - console.log(content); - - element.setAttribute('href', `data:${type},charset=utf-8,${content}`); + element.setAttribute('href', `data:${type};base64,${btoa(content)}`); element.setAttribute('download', name); element.style.display = 'none'; @@ -157,4 +159,4 @@ function openFromLocalStorage(id) { const entry = getLocalStorageEntries().find(entry => entry.document.id === id); addDocument(entry.document); switchDocument(entry.document); -} \ No newline at end of file +} diff --git a/js/menu.js b/js/menu.js index c8bdcd7..eb6b559 100644 --- a/js/menu.js +++ b/js/menu.js @@ -23,10 +23,8 @@ modalSave.addFooterBtn('Speichern', 'btn', () => { const modalOpen = new tingle.modal({ beforeOpen: () => { const entries = getLocalStorageEntries().sort((a, b) => { - console.log(a, b); return b.document.createdAt - a.document.createdAt }); - console.log(entries); let html = '

Gespeicherte Dokumente

'; @@ -70,16 +68,20 @@ modalImport.setContent('

Dokument importieren