|
|
@ -60,9 +60,11 @@ backup and database export, with platform-specific download instructions. * * |
|
|
|
|
|
|
|
<script lang="ts"> |
|
|
|
import { Component, Prop, Vue } from "vue-facing-decorator"; |
|
|
|
import * as R from "ramda"; |
|
|
|
|
|
|
|
import { AppString, NotificationIface } from "../constants/app"; |
|
|
|
|
|
|
|
import { Contact } from "../db/tables/contacts"; |
|
|
|
import { Contact, ContactMaybeWithJsonStrings, ContactMethod } from "../db/tables/contacts"; |
|
|
|
import * as databaseUtil from "../db/databaseUtil"; |
|
|
|
|
|
|
|
import { logger } from "../utils/logger"; |
|
|
@ -72,6 +74,7 @@ import { |
|
|
|
PlatformCapabilities, |
|
|
|
} from "../services/PlatformService"; |
|
|
|
import { contactsToExportJson } from "../libs/util"; |
|
|
|
import { parseJsonField } from "../db/databaseUtil"; |
|
|
|
|
|
|
|
/** |
|
|
|
* @vue-component |
|
|
@ -133,13 +136,13 @@ export default class DataExportSection extends Vue { |
|
|
|
*/ |
|
|
|
public async exportDatabase() { |
|
|
|
try { |
|
|
|
let allContacts: Contact[] = []; |
|
|
|
let allDbContacts: ContactMaybeWithJsonStrings[] = []; |
|
|
|
const platformService = PlatformServiceFactory.getInstance(); |
|
|
|
const result = await platformService.dbQuery(`SELECT * FROM contacts`); |
|
|
|
if (result) { |
|
|
|
allContacts = databaseUtil.mapQueryResultToValues( |
|
|
|
allDbContacts = databaseUtil.mapQueryResultToValues( |
|
|
|
result, |
|
|
|
) as unknown as Contact[]; |
|
|
|
) as unknown as ContactMaybeWithJsonStrings[]; |
|
|
|
} |
|
|
|
// if (USE_DEXIE_DB) { |
|
|
|
// await db.open(); |
|
|
@ -147,6 +150,19 @@ export default class DataExportSection extends Vue { |
|
|
|
// } |
|
|
|
|
|
|
|
// Convert contacts to export format |
|
|
|
const allContacts: Contact[] = allDbContacts.map((contact) => { |
|
|
|
// first remove the contactMethods field, mostly to cast to a clear type (that will end up with JSON objects) |
|
|
|
const exContact: Contact = R.omit( |
|
|
|
["contactMethods"], |
|
|
|
contact, |
|
|
|
); |
|
|
|
// now add contactMethods as a true array of ContactMethod objects |
|
|
|
exContact.contactMethods = contact.contactMethods |
|
|
|
? parseJsonField(contact.contactMethods, [] as Array<ContactMethod>) |
|
|
|
: undefined; |
|
|
|
return exContact; |
|
|
|
}); |
|
|
|
|
|
|
|
const exportData = contactsToExportJson(allContacts); |
|
|
|
const jsonStr = JSON.stringify(exportData, null, 2); |
|
|
|
const blob = new Blob([jsonStr], { type: "application/json" }); |
|
|
|