feat: add overdue analytics by sector with swipeable UI in AnalyticsScreen
This commit is contained in:
@@ -9,5 +9,6 @@ data class AnalyticsState(
|
||||
val timelineDates: List<Date> = emptyList(),
|
||||
val plannedProgressPoints: List<Float> = emptyList(),
|
||||
val realizedProgressPoints: List<Float> = emptyList(),
|
||||
val overdueByTag: List<Pair<String, Int>> = emptyList()
|
||||
val overdueByTag: List<Pair<String, Int>> = emptyList(),
|
||||
val overdueBySector: List<Pair<String, Int>> = emptyList()
|
||||
)
|
||||
|
||||
@@ -4,9 +4,13 @@ import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import kotlinx.coroutines.launch
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.*
|
||||
@@ -119,8 +123,8 @@ fun AnalyticsScreen(
|
||||
// Card 2: Progresso do Projeto: Planejado vs. Realizado
|
||||
SCurveCard(analyticsState)
|
||||
|
||||
// Card 3: Atrasados por TAG
|
||||
OverdueByTagCard(analyticsState.overdueByTag)
|
||||
// Card 3: OSs Atrasadas (TAG / Setor alternáveis por swipe)
|
||||
OverdueAnalyticsCard(analyticsState)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -361,11 +365,14 @@ fun SCurveCard(analyticsState: AnalyticsState) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gráfico 3: OSs Atrasadas por TAG (Ativo)
|
||||
* Lista as TAGs com maior volume de OSs pendentes e com prazo vencido
|
||||
* Gráfico 3: OSs Atrasadas por TAG e por Setor
|
||||
* Permite alternar horizontalmente (swipe) entre as duas visualizações.
|
||||
*/
|
||||
@Composable
|
||||
fun OverdueByTagCard(overdueByTag: List<Pair<String, Int>>) {
|
||||
fun OverdueAnalyticsCard(analyticsState: AnalyticsState) {
|
||||
val pagerState = rememberPagerState(pageCount = { 2 })
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||
@@ -377,18 +384,70 @@ fun OverdueByTagCard(overdueByTag: List<Pair<String, Int>>) {
|
||||
.padding(16.dp)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
text = "Atrasados por TAG",
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = BrandBlack,
|
||||
textAlign = TextAlign.Center,
|
||||
// Header with Dynamic Title & Page Indicator Dots
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 16.dp)
|
||||
.padding(bottom = 16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = if (pagerState.currentPage == 0) "Atrasados por TAG" else "Atrasados por Setor",
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = BrandBlack
|
||||
)
|
||||
|
||||
if (overdueByTag.isEmpty()) {
|
||||
// Page Indicator Dots
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
repeat(2) { index ->
|
||||
val isSelected = pagerState.currentPage == index
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(if (isSelected) 10.dp else 8.dp)
|
||||
.background(
|
||||
color = if (isSelected) BrandGreen else Color.LightGray,
|
||||
shape = CircleShape
|
||||
)
|
||||
.clickable {
|
||||
coroutineScope.launch {
|
||||
pagerState.animateScrollToPage(index)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) { page ->
|
||||
val (items, emptyMsg) = if (page == 0) {
|
||||
analyticsState.overdueByTag to "Parabéns! Nenhuma OS atrasada por TAG no momento."
|
||||
} else {
|
||||
analyticsState.overdueBySector to "Parabéns! Nenhuma OS atrasada por Setor no momento."
|
||||
}
|
||||
|
||||
OverdueBarChartContent(
|
||||
displayList = items,
|
||||
emptyMessage = emptyMsg
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun OverdueBarChartContent(
|
||||
displayList: List<Pair<String, Int>>,
|
||||
emptyMessage: String
|
||||
) {
|
||||
if (displayList.isEmpty()) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -396,21 +455,21 @@ fun OverdueByTagCard(overdueByTag: List<Pair<String, Int>>) {
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = "Parabéns! Nenhuma OS atrasada no momento.",
|
||||
text = emptyMessage,
|
||||
color = Color(0xFF2E7D32),
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = 13.sp
|
||||
fontSize = 13.sp,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val displayList = overdueByTag
|
||||
val maxCount = displayList.maxOfOrNull { it.second } ?: 1
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
displayList.forEachIndexed { index, (tag, count) ->
|
||||
displayList.forEachIndexed { index, (label, count) ->
|
||||
val barColor = when (index) {
|
||||
0 -> Color(0xFF4CAF50) // Green
|
||||
1 -> Color(0xFF2196F3) // Blue
|
||||
@@ -423,9 +482,9 @@ fun OverdueByTagCard(overdueByTag: List<Pair<String, Int>>) {
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
// TAG Name
|
||||
// Label (TAG Name or Sector Name)
|
||||
Text(
|
||||
text = tag,
|
||||
text = label,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = BrandBlack,
|
||||
@@ -463,6 +522,4 @@ fun OverdueByTagCard(overdueByTag: List<Pair<String, Int>>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,7 +557,7 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Overdue tags
|
||||
// 3. Overdue tags and sectors
|
||||
val referenceDate = if (Date().before(projectEnd)) projectEnd else Date()
|
||||
|
||||
val overdueActivities = activities.filter { act ->
|
||||
@@ -581,6 +581,31 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
||||
top + listOf("Outros" to othersCount)
|
||||
}
|
||||
|
||||
val overdueBySectorMap = overdueActivities
|
||||
.groupBy { if (it.setor.isBlank()) "Sem Setor" else it.setor }
|
||||
.mapValues { it.value.size }
|
||||
|
||||
val finalOverdueBySector = if (overdueActivities.isEmpty()) {
|
||||
emptyList()
|
||||
} else {
|
||||
val plantSectors = activities
|
||||
.map { if (it.setor.isBlank()) "Sem Setor" else it.setor }
|
||||
.distinct()
|
||||
|
||||
val fullOverdueBySector = plantSectors
|
||||
.map { sector -> sector to (overdueBySectorMap[sector] ?: 0) }
|
||||
.sortedWith(compareByDescending<Pair<String, Int>> { it.second }.thenBy { it.first })
|
||||
|
||||
val displayLimit = 4
|
||||
if (fullOverdueBySector.size <= displayLimit) {
|
||||
fullOverdueBySector
|
||||
} else {
|
||||
val top = fullOverdueBySector.take(displayLimit - 1)
|
||||
val othersCount = fullOverdueBySector.drop(displayLimit - 1).sumOf { it.second }
|
||||
top + listOf("Outros" to othersCount)
|
||||
}
|
||||
}
|
||||
|
||||
return AnalyticsState(
|
||||
teamMetrics = teamMetrics,
|
||||
projectStart = projectStart,
|
||||
@@ -588,7 +613,8 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
||||
timelineDates = timelineDates,
|
||||
plannedProgressPoints = plannedProgressPoints,
|
||||
realizedProgressPoints = realizedProgressPoints,
|
||||
overdueByTag = finalOverdueByTag
|
||||
overdueByTag = finalOverdueByTag,
|
||||
overdueBySector = finalOverdueBySector
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import androidx.test.core.app.ApplicationProvider
|
||||
import com.example.data.local.AppDatabase
|
||||
import com.example.data.remote.GoogleSheetsSyncService
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
@@ -252,6 +253,9 @@ class ExampleRobolectricTest {
|
||||
// 4. Verify realized progress points has correct count
|
||||
assertEquals(5, state.realizedProgressPoints.size)
|
||||
|
||||
// 5. Verify overdueBySector is present
|
||||
assertNotNull(state.overdueBySector)
|
||||
|
||||
collectionJob.cancel()
|
||||
}
|
||||
db.close()
|
||||
|
||||
Reference in New Issue
Block a user