-
Notifications
You must be signed in to change notification settings - Fork 623
Draft: report migrate to cmp #2392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kapmaurya
wants to merge
25
commits into
openMF:kmp-impl
Choose a base branch
from
kapmaurya:cmp-report
base: kmp-impl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+494
−447
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e9f836e
cmp-report migration
kapmaurya 99d0b1b
cmp-report migration
kapmaurya 7c4a6e5
Merge branch 'kmp-impl' into cmp-report
kapmaurya dceaf10
Merge branch 'kmp-impl' into cmp-report
kapmaurya 99ef9f9
cmp-search migration
kapmaurya a9eda6c
cmp-report migration
kapmaurya f789624
cmp-search migration
kapmaurya bc256eb
Merge branch 'kmp-impl' into cmp-report
kapmaurya 1561ce5
Merge branch 'refs/heads/kmp-impl' into cmp-report
kapmaurya d08f280
Merge remote-tracking branch 'origin/cmp-report' into cmp-report
kapmaurya a60dae5
cmp-search migration
kapmaurya 4762fb3
Merge branch 'kmp-impl' into cmp-report
kapmaurya 38c150d
cmp-search migration
kapmaurya 05f2790
Merge branch 'kmp-impl' into cmp-report
revanthkumarJ b3025bf
updated
revanthkumarJ 3f932fe
updated
revanthkumarJ 79d3a97
revert koinModules
revanthkumarJ 605f374
clean up
revanthkumarJ 5343b06
previews clean up
revanthkumarJ d14bcd1
updated
revanthkumarJ cf1a204
revert back labels
revanthkumarJ b3049a0
revert back labels
revanthkumarJ 6a53f99
Added Serialname
revanthkumarJ 0943808
updated
revanthkumarJ 12f6e40
Merge branch 'kmp-impl' into cmp-report
revanthkumarJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,4 +91,4 @@ fun MifosTextFieldDropdown( | |
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
feature/report/src/commonMain/kotlin/com/mifos/feature/report/report/ReportViewModel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
///* | ||
// * Copyright 2024 Mifos Initiative | ||
// * | ||
// * This Source Code Form is subject to the terms of the Mozilla Public | ||
// * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// * file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// * | ||
// * See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
// */ | ||
package com.mifos.feature.report.report | ||
|
||
|
||
import androidclient.feature.report.generated.resources.Res | ||
import androidclient.feature.report.generated.resources.feature_report_export_started | ||
import androidclient.feature.report.generated.resources.feature_report_exported_successfully | ||
import androidclient.feature.report.generated.resources.feature_report_unable_to_export | ||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.mifos.core.common.utils.Constants | ||
import com.mifos.core.model.objects.runreport.FullParameterListResponse | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import kotlinx.datetime.Clock | ||
import kotlinx.serialization.json.Json | ||
import okio.FileSystem | ||
import okio.Path.Companion.toPath | ||
import okio.SYSTEM | ||
import okio.buffer | ||
import okio.use | ||
|
||
class ReportViewModel( | ||
savedStateHandle: SavedStateHandle, | ||
) : ViewModel() { | ||
|
||
private val reportParameterString = | ||
savedStateHandle.getStateFlow(key = Constants.REPORT_PARAMETER_RESPONSE, initialValue = "") | ||
|
||
val report: FullParameterListResponse = | ||
Json.decodeFromString(reportParameterString.value) | ||
|
||
private val _reportUiState = MutableStateFlow<ReportUiState>(ReportUiState.Initial) | ||
val reportUiState = _reportUiState.asStateFlow() | ||
|
||
fun exportCsv(report: FullParameterListResponse, reportDirectoryPath: String) { | ||
viewModelScope.launch { | ||
_reportUiState.value = ReportUiState.Message(Res.string.feature_report_export_started) | ||
|
||
val timestamp = Clock.System.now().toEpochMilliseconds().toString() | ||
val fileName = "$reportDirectoryPath/$timestamp.csv" | ||
val path = fileName.toPath() | ||
|
||
try { | ||
FileSystem.SYSTEM.sink(path).buffer().use { sink -> | ||
val headers = report.columnHeaders.joinToString(",") { it.columnName } | ||
sink.writeUtf8(headers + "\n") | ||
|
||
for (row in report.data) { | ||
val line = row.row.joinToString(",") | ||
sink.writeUtf8(line + "\n") | ||
} | ||
} | ||
|
||
_reportUiState.value = | ||
ReportUiState.Message(Res.string.feature_report_exported_successfully) | ||
} catch (e: Exception) { | ||
_reportUiState.value = | ||
ReportUiState.Message(Res.string.feature_report_unable_to_export) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.