From c6b1289f5af6147e0823fb7e41705ed9515823ac Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 16 Nov 2022 17:54:16 +0600 Subject: [PATCH] complete --- .../core/models/MavenConfig.kt | 26 ++++-- .../kmppscriptbuilder/core/ui/BuilderView.kt | 4 +- .../core/ui/DevelopersView.kt | 1 - .../core/ui/RepositoriesView.kt | 87 +++++++++++++------ .../kmppscriptbuilder/core/ui/VerticalView.kt | 4 +- .../core/ui/utils/UIElements.kt | 2 +- .../core/ui/ListViewDrawer.kt | 6 +- .../core/ui/utils/ActualUIElements.kt | 2 +- .../core/ui/ListViewDrawer.kt | 5 +- .../core/ui/utils/ActualUIElements.kt | 2 +- 10 files changed, 90 insertions(+), 49 deletions(-) diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/MavenConfig.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/MavenConfig.kt index fe274fc..555b1e2 100644 --- a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/MavenConfig.kt +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/MavenConfig.kt @@ -33,13 +33,10 @@ data class MavenPublishingRepository( val name: String, val url: String, val credsType: CredentialsType = CredentialsType.UsernameAndPassword( - "${name.uppercase()}_USER", - "${name.uppercase()}_PASSWORD" + CredentialsType.UsernameAndPassword.defaultUsernameProperty(name), + CredentialsType.UsernameAndPassword.defaultPasswordProperty(name), ) ) { - val defaultUsernameProperty = "${name.uppercase()}_USER" - val defaultPasswordProperty = "${name.uppercase()}_PASSWORD" - val defaultHeaderValueProperty = "${name.uppercase()}_TOKEN" @Serializable sealed interface CredentialsType { @@ -54,8 +51,8 @@ data class MavenPublishingRepository( val passwordProperty: String ): CredentialsType { constructor(baseParameter: String) : this( - "${baseParameter.uppercase()}_USER", - "${baseParameter.uppercase()}_PASSWORD", + defaultUsernameProperty(baseParameter), + defaultPasswordProperty(baseParameter) ) override fun buildCheckPart(): String = "(project.hasProperty('${usernameProperty}') || System.getenv('${usernameProperty}') != null) && (project.hasProperty('${passwordProperty}') || System.getenv('${passwordProperty}') != null)" @@ -67,6 +64,15 @@ return """ } """ } + + companion object { + fun defaultUsernameProperty(name: String): String { + return "${name.uppercase()}_USER" + } + fun defaultPasswordProperty(name: String): String { + return "${name.uppercase()}_PASSWORD" + } + } } @Serializable data class HttpHeaderCredentials( @@ -82,6 +88,12 @@ return """ } """ } + + companion object { + fun defaultValueProperty(name: String): String { + return "${name.uppercase()}_TOKEN" + } + } } fun buildCheckPart(): String diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/BuilderView.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/BuilderView.kt index af5aa64..6b1a87c 100644 --- a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/BuilderView.kt +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/BuilderView.kt @@ -5,7 +5,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import dev.inmo.kmppscriptbuilder.core.models.Config -import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultBox +import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultContentColumn import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultDivider @Composable @@ -45,7 +45,7 @@ class BuilderView : View() { config = it } - DefaultBox { + DefaultContentColumn { projectTypeView.build() DefaultDivider() licensesView.build() diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/DevelopersView.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/DevelopersView.kt index 2ed27d3..4fa883c 100644 --- a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/DevelopersView.kt +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/DevelopersView.kt @@ -7,7 +7,6 @@ import androidx.compose.runtime.setValue import dev.inmo.kmppscriptbuilder.core.models.Developer import dev.inmo.kmppscriptbuilder.core.ui.utils.CommonText import dev.inmo.kmppscriptbuilder.core.ui.utils.CommonTextField -import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultBox import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultSmallVerticalMargin class DeveloperState( diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/RepositoriesView.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/RepositoriesView.kt index e53db8b..0f433ea 100644 --- a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/RepositoriesView.kt +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/RepositoriesView.kt @@ -9,6 +9,7 @@ import dev.inmo.kmppscriptbuilder.core.models.MavenPublishingRepository import dev.inmo.kmppscriptbuilder.core.ui.utils.ButtonsPanel import dev.inmo.kmppscriptbuilder.core.ui.utils.CommonText import dev.inmo.kmppscriptbuilder.core.ui.utils.CommonTextField +import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultContentColumn import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultSmallVerticalMargin import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer @@ -21,10 +22,10 @@ class RepositoryState( var url: String by mutableStateOf(url) var credsType by mutableStateOf(credsType) - fun toRepository() = MavenPublishingRepository(name, url) + fun toRepository() = MavenPublishingRepository(name, url, credsType) } -private fun MavenPublishingRepository.toRepositoryState() = RepositoryState(name, url) +private fun MavenPublishingRepository.toRepositoryState() = RepositoryState(name, url, credsType) expect class RepositoryCredentialTypeDrawer : Drawer expect fun RepositoryCredentialTypeDrawerWithState(repositoryState: RepositoryState): RepositoryCredentialTypeDrawer @@ -54,7 +55,34 @@ class RepositoriesView : ListView("Repositories info") { CommonTextField( item.name, "This name will be used to identify repository in gradle" - ) { item.name = it } + ) { + val previous = item.name + item.name = it + when (val currentCredsType = item.credsType) { + is MavenPublishingRepository.CredentialsType.HttpHeaderCredentials -> { + if (MavenPublishingRepository.CredentialsType.HttpHeaderCredentials.defaultValueProperty(previous) == currentCredsType.headerValueProperty) { + item.credsType = currentCredsType.copy( + headerValueProperty = MavenPublishingRepository.CredentialsType.HttpHeaderCredentials.defaultValueProperty(it) + ) + } + } + MavenPublishingRepository.CredentialsType.Nothing -> {} + is MavenPublishingRepository.CredentialsType.UsernameAndPassword -> { + var current: MavenPublishingRepository.CredentialsType.UsernameAndPassword = currentCredsType + if (MavenPublishingRepository.CredentialsType.UsernameAndPassword.defaultUsernameProperty(previous) == currentCredsType.usernameProperty) { + current = current.copy( + usernameProperty = MavenPublishingRepository.CredentialsType.UsernameAndPassword.defaultUsernameProperty(it) + ) + } + if (MavenPublishingRepository.CredentialsType.UsernameAndPassword.defaultPasswordProperty(previous) == currentCredsType.passwordProperty) { + current = current.copy( + passwordProperty = MavenPublishingRepository.CredentialsType.UsernameAndPassword.defaultPasswordProperty(it) + ) + } + item.credsType = current + } + } + } DefaultSmallVerticalMargin() CommonText("Repository url") CommonTextField( @@ -66,41 +94,46 @@ class RepositoriesView : ListView("Repositories info") { "Credentials type", MavenPublishingRepository.CredentialsType.Nothing.takeIf { item.credsType != it } ?: item.credsType, MavenPublishingRepository.CredentialsType.UsernameAndPassword(item.name).takeIf { item.credsType !is MavenPublishingRepository.CredentialsType.UsernameAndPassword } ?: item.credsType, - MavenPublishingRepository.CredentialsType.HttpHeaderCredentials("Authorization", "${item.name.uppercase()}_TOKEN").takeIf { item.credsType !is MavenPublishingRepository.CredentialsType.HttpHeaderCredentials } ?: item.credsType, + MavenPublishingRepository.CredentialsType.HttpHeaderCredentials( + "Authorization", + MavenPublishingRepository.CredentialsType.HttpHeaderCredentials.defaultValueProperty(item.name) + ).takeIf { item.credsType !is MavenPublishingRepository.CredentialsType.HttpHeaderCredentials } ?: item.credsType, ) { with(credsTypesDrawer) { - with(item.credsType) { + with(it) { draw() } } } - when (val credsType = item.credsType) { - is MavenPublishingRepository.CredentialsType.HttpHeaderCredentials -> { - CommonText("Header name") - CommonTextField(credsType.headerName) { - item.credsType = credsType.copy(headerName = it) - } - DefaultSmallVerticalMargin() + DefaultContentColumn { + when (val credsType = item.credsType) { + is MavenPublishingRepository.CredentialsType.HttpHeaderCredentials -> { + CommonText("Header name") + CommonTextField(credsType.headerName) { + item.credsType = credsType.copy(headerName = it) + } + DefaultSmallVerticalMargin() - CommonText("Property name") - CommonTextField(credsType.headerValueProperty) { - item.credsType = credsType.copy(headerValueProperty = it) + CommonText("Property name") + CommonTextField(credsType.headerValueProperty) { + item.credsType = credsType.copy(headerValueProperty = it) + } } - } - MavenPublishingRepository.CredentialsType.Nothing -> { - CommonText("No parameters for absence of credentials") - } - is MavenPublishingRepository.CredentialsType.UsernameAndPassword -> { - CommonText("Username property name") - CommonTextField(credsType.usernameProperty) { - item.credsType = credsType.copy(usernameProperty = it) + MavenPublishingRepository.CredentialsType.Nothing -> { + CommonText("No parameters for absence of credentials") } - DefaultSmallVerticalMargin() + is MavenPublishingRepository.CredentialsType.UsernameAndPassword -> { + CommonText("Username property name") + CommonTextField(credsType.usernameProperty) { + item.credsType = credsType.copy(usernameProperty = it) + } + DefaultSmallVerticalMargin() - CommonText("Password property name") - CommonTextField(credsType.passwordProperty) { - item.credsType = credsType.copy(passwordProperty = it) + CommonText("Password property name") + CommonTextField(credsType.passwordProperty) { + item.credsType = credsType.copy(passwordProperty = it) + } } } } diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/VerticalView.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/VerticalView.kt index e387507..0e3263b 100644 --- a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/VerticalView.kt +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/VerticalView.kt @@ -1,13 +1,13 @@ package dev.inmo.kmppscriptbuilder.core.ui import androidx.compose.runtime.Composable -import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultBox +import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultContentColumn abstract class VerticalView(protected val title: String) : View() { abstract val content: @Composable () -> Unit @Composable override fun build() { - DefaultBox { + DefaultContentColumn { DrawVertically(title, content) } } diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/utils/UIElements.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/utils/UIElements.kt index 746af8a..5cb57ca 100644 --- a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/utils/UIElements.kt +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/utils/UIElements.kt @@ -46,4 +46,4 @@ expect fun DefaultDivider() expect fun DefaultSmallVerticalMargin() @Composable -expect fun DefaultBox(block: @Composable () -> Unit) +expect fun DefaultContentColumn(block: @Composable () -> Unit) diff --git a/core/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/ListViewDrawer.kt b/core/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/ListViewDrawer.kt index f6e4934..e0e11c1 100644 --- a/core/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/ListViewDrawer.kt +++ b/core/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/ListViewDrawer.kt @@ -5,17 +5,15 @@ import dev.inmo.jsuikit.elements.DefaultButton import dev.inmo.jsuikit.modifiers.UIKitButton import dev.inmo.jsuikit.modifiers.UIKitMargin import dev.inmo.jsuikit.modifiers.UIKitUtility -import dev.inmo.jsuikit.modifiers.builder -import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultBox +import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultContentColumn import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer import dev.inmo.kmppscriptbuilder.core.ui.utils.NoTransform -import org.jetbrains.compose.web.dom.Div actual class ListViewDrawer : Drawer> { @Composable override fun ListView.draw() { itemsList.forEach { item -> - DefaultBox { + DefaultContentColumn { buildView(item) DefaultButton(removeItemText, UIKitButton.Type.Default, UIKitMargin.Small, UIKitUtility.NoTransform, UIKitUtility.Border.Rounded) { itemsList.remove(item) diff --git a/core/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/utils/ActualUIElements.kt b/core/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/utils/ActualUIElements.kt index 680e6e6..75be36b 100644 --- a/core/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/utils/ActualUIElements.kt +++ b/core/src/jsMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/utils/ActualUIElements.kt @@ -121,7 +121,7 @@ actual fun DefaultSmallVerticalMargin() { } @Composable -actual fun DefaultBox(block: @Composable () -> Unit) { +actual fun DefaultContentColumn(block: @Composable () -> Unit) { Div(attrsBuilder(UIKitMargin.Small.Horizontal, UIKitMargin.Small.Vertical)) { block() } diff --git a/core/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/ListViewDrawer.kt b/core/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/ListViewDrawer.kt index d2a3b08..b31da7a 100644 --- a/core/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/ListViewDrawer.kt +++ b/core/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/ListViewDrawer.kt @@ -1,6 +1,5 @@ package dev.inmo.kmppscriptbuilder.core.ui -import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding import androidx.compose.material.Button import androidx.compose.material.OutlinedButton @@ -8,14 +7,14 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import dev.inmo.kmppscriptbuilder.core.ui.utils.CommonText -import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultBox +import dev.inmo.kmppscriptbuilder.core.ui.utils.DefaultContentColumn import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer actual class ListViewDrawer : Drawer> { @Composable override fun ListView.draw() { itemsList.forEach { item -> - DefaultBox { + DefaultContentColumn { buildView(item) OutlinedButton({ itemsList.remove(item) }, Modifier.padding(8.dp)) { CommonText(removeItemText,) diff --git a/core/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/utils/ActualUIElements.kt b/core/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/utils/ActualUIElements.kt index 7e5d66d..7788a2d 100644 --- a/core/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/utils/ActualUIElements.kt +++ b/core/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/core/ui/utils/ActualUIElements.kt @@ -106,7 +106,7 @@ actual fun DefaultSmallVerticalMargin() { } @Composable -actual fun DefaultBox(block: @Composable () -> Unit) { +actual fun DefaultContentColumn(block: @Composable () -> Unit) { Column(Modifier.padding(8.dp)) { block() }