Enable exporting plans as CSV - 2.33 🚀
This is to help migrations across to Flexify. Also is generally useful if someone wants to do some Excel magic on their plans.
This commit is contained in:
parent
52f642c2af
commit
d0e76f574b
|
@ -511,7 +511,7 @@ export default function SettingsPage() {
|
||||||
style={{ alignSelf: "flex-start" }}
|
style={{ alignSelf: "flex-start" }}
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
const result = await DocumentPicker.pickDirectory();
|
const result = await DocumentPicker.pickDirectory();
|
||||||
await NativeModules.BackupModule.exportToCSV(result.uri);
|
await NativeModules.BackupModule.exportSets(result.uri);
|
||||||
toast("Exported sets as CSV.");
|
toast("Exported sets as CSV.");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -519,6 +519,21 @@ export default function SettingsPage() {
|
||||||
</Button>
|
</Button>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Export plans as CSV",
|
||||||
|
renderItem: (name: string) => (
|
||||||
|
<Button
|
||||||
|
style={{ alignSelf: "flex-start" }}
|
||||||
|
onPress={async () => {
|
||||||
|
const result = await DocumentPicker.pickDirectory();
|
||||||
|
await NativeModules.BackupModule.exportPlans(result.uri);
|
||||||
|
toast("Exported plans as CSV.");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{name}
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Import database",
|
name: "Import database",
|
||||||
renderItem: (name: string) => (
|
renderItem: (name: string) => (
|
||||||
|
|
|
@ -87,8 +87,8 @@ android {
|
||||||
applicationId "com.massive"
|
applicationId "com.massive"
|
||||||
minSdkVersion rootProject.ext.minSdkVersion
|
minSdkVersion rootProject.ext.minSdkVersion
|
||||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||||
versionCode 36247
|
versionCode 36248
|
||||||
versionName "2.32"
|
versionName "2.33"
|
||||||
}
|
}
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
release {
|
release {
|
||||||
|
|
|
@ -95,10 +95,22 @@ class BackupModule(context: ReactApplicationContext?) :
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
fun exportToCSV(target: String, promise: Promise) {
|
fun exportPlans(target: String, promise: Promise) {
|
||||||
try {
|
try {
|
||||||
val db = DatabaseHelper(reactApplicationContext)
|
val db = DatabaseHelper(reactApplicationContext)
|
||||||
db.exportToCSV(target, reactApplicationContext)
|
db.exportPlans(target, reactApplicationContext)
|
||||||
|
promise.resolve("Export successful!")
|
||||||
|
}
|
||||||
|
catch (e: Exception) {
|
||||||
|
promise.reject("ERROR", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
fun exportSets(target: String, promise: Promise) {
|
||||||
|
try {
|
||||||
|
val db = DatabaseHelper(reactApplicationContext)
|
||||||
|
db.exportSets(target, reactApplicationContext)
|
||||||
promise.resolve("Export successful!")
|
promise.resolve("Export successful!")
|
||||||
}
|
}
|
||||||
catch (e: Exception) {
|
catch (e: Exception) {
|
||||||
|
|
|
@ -18,8 +18,8 @@ class DatabaseHelper(context: Context) :
|
||||||
private const val DATABASE_VERSION = 1
|
private const val DATABASE_VERSION = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fun exportToCSV(target: String, context: Context) {
|
fun exportSets(target: String, context: Context) {
|
||||||
Log.d("DatabaseHelper", "exportToCSV $target")
|
Log.d("DatabaseHelper", "exportSets $target")
|
||||||
val treeUri: Uri = Uri.parse(target)
|
val treeUri: Uri = Uri.parse(target)
|
||||||
val documentFile = context.let { DocumentFile.fromTreeUri(it, treeUri) }
|
val documentFile = context.let { DocumentFile.fromTreeUri(it, treeUri) }
|
||||||
val file = documentFile?.createFile("application/octet-stream", "sets.csv") ?: return
|
val file = documentFile?.createFile("application/octet-stream", "sets.csv") ?: return
|
||||||
|
@ -43,6 +43,31 @@ class DatabaseHelper(context: Context) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun exportPlans(target: String, context: Context) {
|
||||||
|
Log.d("DatabaseHelper", "exportPlans $target")
|
||||||
|
val treeUri: Uri = Uri.parse(target)
|
||||||
|
val documentFile = context.let { DocumentFile.fromTreeUri(it, treeUri) }
|
||||||
|
val file = documentFile?.createFile("application/octet-stream", "plans.csv") ?: return
|
||||||
|
|
||||||
|
context.contentResolver.openOutputStream(file.uri).use { outputStream ->
|
||||||
|
val csvWrite = CSVWriter(outputStream?.writer())
|
||||||
|
val db = this.readableDatabase
|
||||||
|
val cursor = db.rawQuery("SELECT * FROM plans", null)
|
||||||
|
csvWrite.writeNext(cursor.columnNames)
|
||||||
|
|
||||||
|
while(cursor.moveToNext()) {
|
||||||
|
val arrStr = arrayOfNulls<String>(cursor.columnCount)
|
||||||
|
for(i in 0 until cursor.columnCount) {
|
||||||
|
arrStr[i] = cursor.getString(i)
|
||||||
|
}
|
||||||
|
csvWrite.writeNext(arrStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
csvWrite.close()
|
||||||
|
cursor.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(db: SQLiteDatabase) {
|
override fun onCreate(db: SQLiteDatabase) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "massive",
|
"name": "massive",
|
||||||
"version": "2.32",
|
"version": "2.33",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user