diff --git a/src/store/store.js b/src/store/store.js index 9ad76fc..32e5b75 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -12,6 +12,8 @@ import clients from '@/store/clients'; import invoices from '@/store/invoices'; import teams from '@/store/teams'; import themes from '@/store/themes'; +import localForage from 'localforage'; +import { download } from '../utils/helpers'; Vue.use(Vuex); @@ -35,5 +37,24 @@ export default new Vuex.Store({ }, state: {}, mutations: {}, - actions: {}, + actions: { + async exportJson() { + let results = []; + const keys = await localForage.keys(); + keys.forEach((key) => { + results.push(localForage.getItem(key)); + }); + results = await Promise.all(results); + + const data = {}; + keys.forEach((key, index) => { + data[key] = results[index]; + }); + + download(JSON.stringify(data), 'serverless-invoices.json', 'application/json'); + }, + importJson() { + + }, + }, }); diff --git a/src/utils/helpers.js b/src/utils/helpers.js index 74187c6..e5fe405 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -29,3 +29,21 @@ export function pick(obj, map) { }); return objSubset; } + +export function download(data, filename, type) { + var file = new Blob([data], {type: type}); + if (window.navigator.msSaveOrOpenBlob) // IE10+ + window.navigator.msSaveOrOpenBlob(file, filename); + else { // Others + var a = document.createElement("a"), + url = URL.createObjectURL(file); + a.href = url; + a.download = filename; + document.body.appendChild(a); + a.click(); + setTimeout(function() { + document.body.removeChild(a); + window.URL.revokeObjectURL(url); + }, 0); + } +} diff --git a/src/views/dashboard/Invoices.vue b/src/views/dashboard/Invoices.vue index cbd6d92..da6f387 100644 --- a/src/views/dashboard/Invoices.vue +++ b/src/views/dashboard/Invoices.vue @@ -3,7 +3,16 @@