Skip to content

Commit

Permalink
Set current date as event date when entering event in `SchedulingDial…
Browse files Browse the repository at this point in the history
…og` (#3810)

* Set current date as event date when entering event in `SchedulingDialog`

* Remove unused variable
  • Loading branch information
msasikanth authored Oct 7, 2024
1 parent 4fada06 commit 3a0096e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package org.dhis2.usescases.teiDashboard.dialogs.scheduling

import dagger.Module
import dagger.Provides
import org.dhis2.commons.date.DateUtils

@Module
class SchedulingModule
class SchedulingModule {

@Provides
fun providesDateUtils(): DateUtils = DateUtils.getInstance()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.dhis2.commons.bindings.event
import org.dhis2.commons.date.DateUtils
import org.dhis2.commons.date.toOverdueOrScheduledUiText
import org.dhis2.commons.resources.DhisPeriodUtils
import org.dhis2.commons.resources.EventResourcesProvider
Expand Down Expand Up @@ -38,6 +39,7 @@ class SchedulingViewModel(
private val periodUtils: DhisPeriodUtils,
private val dispatchersProvider: DispatcherProvider,
private val launchMode: LaunchMode,
private val dateUtils: DateUtils,
) : ViewModel() {

lateinit var repository: EventDetailsRepository
Expand Down Expand Up @@ -265,14 +267,13 @@ class SchedulingViewModel(

fun enterEvent(launchMode: LaunchMode.EnterEvent) {
viewModelScope.launch {
val eventDate = eventDate.value.currentDate ?: return@launch
val event = withContext(dispatchersProvider.io()) {
d2.event(launchMode.eventUid)
} ?: return@launch
val programUid = event.program() ?: return@launch

d2.eventModule().events().uid(launchMode.eventUid).run {
setEventDate(eventDate)
setEventDate(dateUtils.today)
setStatus(EventStatus.ACTIVE)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModelProvider
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import org.dhis2.commons.date.DateUtils
import org.dhis2.commons.resources.DhisPeriodUtils
import org.dhis2.commons.resources.EventResourcesProvider
import org.dhis2.commons.resources.ResourceManager
Expand All @@ -17,6 +18,7 @@ class SchedulingViewModelFactory @AssistedInject constructor(
private val resourceManager: ResourceManager,
private val eventResourcesProvider: EventResourcesProvider,
private val periodUtils: DhisPeriodUtils,
private val dateUtils: DateUtils,
private val dispatcherProvider: DispatcherProvider,
@Assisted private val launchMode: SchedulingDialog.LaunchMode,
) : ViewModelProvider.Factory {
Expand All @@ -32,6 +34,7 @@ class SchedulingViewModelFactory @AssistedInject constructor(
resourceManager = resourceManager,
eventResourcesProvider = eventResourcesProvider,
periodUtils = periodUtils,
dateUtils = dateUtils,
dispatchersProvider = dispatcherProvider,
launchMode = launchMode,
) as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SchedulingViewModelTest {
resourceManager = mock(),
eventResourcesProvider = mock(),
periodUtils = mock(),
dateUtils = mock(),
dispatchersProvider = object : DispatcherProvider {
override fun io(): CoroutineDispatcher {
return testingDispatcher
Expand Down

0 comments on commit 3a0096e

Please sign in to comment.