Disable and enable repo
This commit is contained in:
parent
ec57a1a5a0
commit
71dffdf7ee
4 changed files with 73 additions and 2 deletions
|
|
@ -476,7 +476,18 @@ class PluginManager @Inject constructor(
|
|||
}
|
||||
dataStore.saveScrapers(updatedScrapers)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Toggle all scrapers belonging to a repository
|
||||
*/
|
||||
suspend fun toggleAllScrapersForRepo(repoId: String, enabled: Boolean) {
|
||||
val scraperList = dataStore.scrapers.first()
|
||||
val updatedScrapers = scraperList.map { scraper ->
|
||||
if (scraper.repositoryId == repoId) scraper.copy(enabled = enabled) else scraper
|
||||
}
|
||||
dataStore.saveScrapers(updatedScrapers)
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle plugins globally enabled
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -217,10 +217,15 @@ fun PluginScreenContent(
|
|||
}
|
||||
|
||||
items(uiState.repositories, key = { it.id }) { repo ->
|
||||
val repoScrapers = uiState.scrapers.filter { it.repositoryId == repo.id }
|
||||
RepositoryCard(
|
||||
repository = repo,
|
||||
repoScrapers = repoScrapers,
|
||||
onRefresh = { viewModel.onEvent(PluginUiEvent.RefreshRepository(repo.id)) },
|
||||
onRemove = { viewModel.onEvent(PluginUiEvent.RemoveRepository(repo.id)) },
|
||||
onToggleAll = { enabled ->
|
||||
viewModel.onEvent(PluginUiEvent.ToggleAllScrapersForRepo(repo.id, enabled))
|
||||
},
|
||||
isLoading = uiState.isLoading,
|
||||
isReadOnly = viewModel.isReadOnly
|
||||
)
|
||||
|
|
@ -847,11 +852,17 @@ private fun ConfirmRepoChangesDialog(
|
|||
@Composable
|
||||
private fun RepositoryCard(
|
||||
repository: PluginRepository,
|
||||
repoScrapers: List<ScraperInfo>,
|
||||
onRefresh: () -> Unit,
|
||||
onRemove: () -> Unit,
|
||||
onToggleAll: (Boolean) -> Unit,
|
||||
isLoading: Boolean,
|
||||
isReadOnly: Boolean = false
|
||||
) {
|
||||
val enabledCount = repoScrapers.count { it.enabled }
|
||||
val allEnabled = repoScrapers.isNotEmpty() && enabledCount == repoScrapers.size
|
||||
val anyEnabled = enabledCount > 0
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
|
@ -886,7 +897,48 @@ private fun RepositoryCard(
|
|||
)
|
||||
}
|
||||
|
||||
if (!isReadOnly) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (!isReadOnly) Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
if (repoScrapers.isNotEmpty()) {
|
||||
Surface(
|
||||
onClick = { onToggleAll(!anyEnabled) },
|
||||
colors = ClickableSurfaceDefaults.colors(
|
||||
containerColor = NuvioColors.Surface,
|
||||
focusedContainerColor = NuvioColors.FocusBackground
|
||||
),
|
||||
border = ClickableSurfaceDefaults.border(
|
||||
focusedBorder = Border(
|
||||
border = BorderStroke(2.dp, NuvioColors.FocusRing),
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
)
|
||||
),
|
||||
shape = ClickableSurfaceDefaults.shape(RoundedCornerShape(12.dp)),
|
||||
scale = ClickableSurfaceDefaults.scale(focusedScale = 1f)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "$enabledCount/${repoScrapers.size}",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = if (anyEnabled) NuvioColors.Secondary else NuvioColors.TextSecondary
|
||||
)
|
||||
Switch(
|
||||
checked = anyEnabled,
|
||||
onCheckedChange = null,
|
||||
colors = SwitchDefaults.colors(
|
||||
checkedThumbColor = NuvioColors.Secondary,
|
||||
checkedTrackColor = NuvioColors.Secondary.copy(alpha = 0.3f)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onRefresh,
|
||||
enabled = !isLoading,
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ sealed interface PluginUiEvent {
|
|||
data class RemoveRepository(val repoId: String) : PluginUiEvent
|
||||
data class RefreshRepository(val repoId: String) : PluginUiEvent
|
||||
data class ToggleScraper(val scraperId: String, val enabled: Boolean) : PluginUiEvent
|
||||
data class ToggleAllScrapersForRepo(val repoId: String, val enabled: Boolean) : PluginUiEvent
|
||||
data class TestScraper(val scraperId: String) : PluginUiEvent
|
||||
data class SetPluginsEnabled(val enabled: Boolean) : PluginUiEvent
|
||||
object ClearTestResults : PluginUiEvent
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ class PluginViewModel @Inject constructor(
|
|||
is PluginUiEvent.RemoveRepository -> removeRepository(event.repoId)
|
||||
is PluginUiEvent.RefreshRepository -> refreshRepository(event.repoId)
|
||||
is PluginUiEvent.ToggleScraper -> toggleScraper(event.scraperId, event.enabled)
|
||||
is PluginUiEvent.ToggleAllScrapersForRepo -> toggleAllScrapersForRepo(event.repoId, event.enabled)
|
||||
is PluginUiEvent.TestScraper -> testScraper(event.scraperId)
|
||||
is PluginUiEvent.SetPluginsEnabled -> setPluginsEnabled(event.enabled)
|
||||
PluginUiEvent.ClearTestResults -> _uiState.update { it.copy(testResults = null, testScraperId = null) }
|
||||
|
|
@ -162,6 +163,12 @@ class PluginViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun toggleAllScrapersForRepo(repoId: String, enabled: Boolean) {
|
||||
viewModelScope.launch {
|
||||
pluginManager.toggleAllScrapersForRepo(repoId, enabled)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setPluginsEnabled(enabled: Boolean) {
|
||||
if (isReadOnly) return
|
||||
viewModelScope.launch {
|
||||
|
|
|
|||
Loading…
Reference in a new issue