mirror of
https://github.com/openflocon/Flocon.git
synced 2026-05-15 02:33:32 +00:00
Dashboards - Form support (#190)
* [dashboard-form] Android plugin form dsl&config. Moved from SectionConfig to abstract ContainerConfig * [dashboard-form] Implemented models and entities for section -> container and containerConfig * [dashboard-form] reverted back to original elementconfig callback * [dashboard-form] Removed serialization from domain module, cleaned up classes as suggested * [dashboard-form] Updated modifier position
This commit is contained in:
parent
4640f3f026
commit
35b3943f30
66 changed files with 3595 additions and 333 deletions
|
|
@ -2,7 +2,7 @@ package io.github.openflocon.flocon.plugins.dashboard
|
|||
|
||||
import io.github.openflocon.flocon.FloconApp
|
||||
import io.github.openflocon.flocon.core.FloconPlugin
|
||||
import io.github.openflocon.flocon.plugins.dashboard.dsl.DashboardBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.builder.DashboardBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.dsl.dashboardConfig
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.DashboardConfig
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.builder
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.ContainerConfig
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.ElementConfig
|
||||
|
||||
abstract class ContainerBuilder {
|
||||
open val elements = mutableListOf<ElementConfig>()
|
||||
|
||||
open fun add(element: ElementConfig) {
|
||||
elements.add(element)
|
||||
}
|
||||
|
||||
abstract fun build(): ContainerConfig
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.builder
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.dsl.DashboardDsl
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.DashboardConfig
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.ContainerConfig
|
||||
|
||||
@DashboardDsl
|
||||
class DashboardBuilder(private val id: String) {
|
||||
private val containers = mutableListOf<ContainerConfig>()
|
||||
|
||||
fun add(container: ContainerConfig) {
|
||||
containers.add(container)
|
||||
}
|
||||
|
||||
fun build(): DashboardConfig {
|
||||
return DashboardConfig(
|
||||
id = id,
|
||||
containers = containers
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.builder
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.FormConfig
|
||||
|
||||
class FormBuilder(
|
||||
val name: String,
|
||||
val submitText: String,
|
||||
val onSubmitted: (Map<String, String>) -> Unit,
|
||||
) : ContainerBuilder() {
|
||||
|
||||
override fun build(): FormConfig {
|
||||
return FormConfig(
|
||||
id = "form_$name",
|
||||
name = name,
|
||||
submitText = submitText,
|
||||
elements = elements,
|
||||
onSubmitted = onSubmitted
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.builder
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.SectionConfig
|
||||
|
||||
class SectionBuilder(val name: String) : ContainerBuilder() {
|
||||
|
||||
override fun build(): SectionConfig {
|
||||
return SectionConfig(name, elements)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.dsl
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.builder.ContainerBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.ButtonConfig
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.SectionBuilder
|
||||
|
||||
@DashboardDsl
|
||||
fun SectionBuilder.button(
|
||||
fun ContainerBuilder.button(
|
||||
text: String,
|
||||
id : String,
|
||||
onClick: () -> Unit,
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.dsl
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.builder.ContainerBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.CheckBoxConfig
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.SectionBuilder
|
||||
|
||||
@DashboardDsl
|
||||
fun SectionBuilder.checkBox(
|
||||
fun ContainerBuilder.checkBox(
|
||||
id: String,
|
||||
label: String,
|
||||
value: Boolean,
|
||||
onUpdated: (Boolean) -> Unit,
|
||||
onUpdated: (Boolean) -> Unit = {},
|
||||
) {
|
||||
add(
|
||||
CheckBoxConfig(
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.dsl
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.DashboardConfig
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.SectionConfig
|
||||
|
||||
@DashboardDsl
|
||||
class DashboardBuilder(private val id: String) {
|
||||
private val sections = mutableListOf<SectionConfig>()
|
||||
|
||||
fun add(section: SectionConfig) {
|
||||
sections.add(section)
|
||||
}
|
||||
|
||||
fun build(): DashboardConfig {
|
||||
return DashboardConfig(
|
||||
id = id,
|
||||
sections = sections
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.dsl
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.builder.DashboardBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.DashboardConfig
|
||||
|
||||
@DslMarker
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.dsl
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.builder.DashboardBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.builder.FormBuilder
|
||||
|
||||
@DashboardDsl
|
||||
fun DashboardBuilder.form(
|
||||
name: String,
|
||||
submitText: String,
|
||||
onSubmitted: (Map<String, String>) -> Unit,
|
||||
block: FormBuilder.() -> Unit
|
||||
) {
|
||||
val builder = FormBuilder(
|
||||
name = name,
|
||||
submitText = submitText,
|
||||
onSubmitted = onSubmitted
|
||||
).apply {
|
||||
block()
|
||||
}
|
||||
|
||||
add(builder.build())
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.dsl
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.builder.ContainerBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.PlainTextConfig
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.SectionBuilder
|
||||
|
||||
@DashboardDsl
|
||||
fun SectionBuilder.plainText(label: String, value: String) {
|
||||
fun ContainerBuilder.plainText(label: String, value: String) {
|
||||
add(
|
||||
PlainTextConfig(
|
||||
label = label,
|
||||
|
|
@ -15,7 +15,7 @@ fun SectionBuilder.plainText(label: String, value: String) {
|
|||
}
|
||||
|
||||
@DashboardDsl
|
||||
fun SectionBuilder.json(label: String, value: String) {
|
||||
fun ContainerBuilder.json(label: String, value: String) {
|
||||
add(PlainTextConfig(
|
||||
label = label,
|
||||
value = value,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.dsl
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.SectionBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.builder.DashboardBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.builder.SectionBuilder
|
||||
|
||||
@DashboardDsl
|
||||
fun DashboardBuilder.section(name: String, block: SectionBuilder.() -> Unit) {
|
||||
val builder = SectionBuilder(name).apply {
|
||||
block()
|
||||
}
|
||||
|
||||
add(builder.build())
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.dsl
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.SectionBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.builder.ContainerBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.TextConfig
|
||||
|
||||
@DashboardDsl
|
||||
fun SectionBuilder.text(label: String, value: String, color: Int? = null) {
|
||||
fun ContainerBuilder.text(label: String, value: String, color: Int? = null) {
|
||||
add(TextConfig(label = label, value = value, color = color))
|
||||
}
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.dsl
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.SectionBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.builder.ContainerBuilder
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.TextFieldConfig
|
||||
|
||||
@DashboardDsl
|
||||
fun SectionBuilder.textField(
|
||||
fun ContainerBuilder.textField(
|
||||
id: String,
|
||||
label: String,
|
||||
placeHolder: String?,
|
||||
value: String,
|
||||
onSubmitted: (String) -> Unit,
|
||||
onSubmitted: (String) -> Unit = {},
|
||||
) {
|
||||
add(
|
||||
TextFieldConfig(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.model
|
||||
|
||||
enum class ContainerType {
|
||||
FORM,
|
||||
SECTION
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.model
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.SectionConfig
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.config.ContainerConfig
|
||||
|
||||
data class DashboardConfig(
|
||||
val id: String,
|
||||
val sections: List<SectionConfig>
|
||||
val containers: List<ContainerConfig>
|
||||
)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.model.config
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.ContainerType
|
||||
|
||||
sealed interface ContainerConfig {
|
||||
val name: String
|
||||
val elements: List<ElementConfig>
|
||||
val containerType: ContainerType
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.model.config
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.ContainerType
|
||||
|
||||
data class FormConfig(
|
||||
override val name: String,
|
||||
override val elements: List<ElementConfig>,
|
||||
val id: String,
|
||||
val submitText: String,
|
||||
val onSubmitted: (Map<String, String>) -> Unit,
|
||||
) : ContainerConfig {
|
||||
override val containerType: ContainerType = ContainerType.FORM
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.model.config
|
||||
|
||||
class SectionBuilder(val name: String) {
|
||||
private val elements = mutableListOf<ElementConfig>()
|
||||
|
||||
fun add(element: ElementConfig) {
|
||||
elements.add(element)
|
||||
}
|
||||
|
||||
fun build(): SectionConfig {
|
||||
return SectionConfig(name, elements)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
package io.github.openflocon.flocon.plugins.dashboard.model.config
|
||||
|
||||
import io.github.openflocon.flocon.plugins.dashboard.model.ContainerType
|
||||
|
||||
data class SectionConfig(
|
||||
val name: String,
|
||||
val elements: List<ElementConfig>
|
||||
)
|
||||
override val name: String,
|
||||
override val elements: List<ElementConfig>,
|
||||
) : ContainerConfig {
|
||||
override val containerType: ContainerType = ContainerType.SECTION
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue