Commit 4e7307c2 authored by Jan Grigat's avatar Jan Grigat
Browse files

finalized project

parent 84fd2772
package de.kompo.common
data class Store(
val name: String,
val items: List<Moebel> = listOf()
public final data class Store(
public val name: String,
public val items: List<Moebel> = listOf()
)
data class Moebel(
val name: String
public final data class Moebel (
public val name: String,
public val anzahl: Int,
public val preis: Float,
public val abmessungen: Abmessungen?,
)
public final data class Abmessungen (
public val breite: Float,
public val hoehe: Float,
public val laenge: Float,
)
\ No newline at end of file
package de.kompo.common
interface StoreRepo {
fun getStores(): List<Store>
suspend fun getStoresAsync(): List<Store>
public interface StoreRepo {
public fun getStores(): List<Store>
public suspend fun getStoresAsync(): List<Store>
fun addStore(store: Store)
public fun addStore(store: Store)
fun addMoebel(store: Store,moebel: Moebel,onComplete: (Store)->Unit,onFail:()->Unit)
public fun addMoebel(store: Store,moebel: Moebel,onComplete: (Store)->Unit,onFail:()->Unit)
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ import org.litote.kmongo.reactivestreams.*
import org.litote.kmongo.setValue
class MongoStoreRepo: StoreRepo {
public final class MongoStoreRepo: StoreRepo {
private val client by lazy { KMongo.createClient("mongodb://root:1gDNlhzMykjYkVjMjV2YlFTZ2IGZiZTM@95.217.104.7:27017").coroutine}
......
......@@ -34,7 +34,7 @@ compose.desktop {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "ComposeWidgetsGallery"
packageName = "KompoMöbelVerwaltung"
packageVersion = "1.0.0"
windows {
......
package de.kompo.ui
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import de.kompo.common.Moebel
@Composable
fun MoebelView(
modifier: Modifier = Modifier,
moebel: Moebel
){
Column(
Modifier.fillMaxSize().composed { modifier }
) {
Text("Name: "+moebel.name)
Text("Anzahl: "+moebel.anzahl)
Text("Preis: "+moebel.preis)
Text("Höhe: "+moebel.abmessungen?.hoehe)
Text("Länge: "+moebel.abmessungen?.laenge)
Text("Breite: "+moebel.abmessungen?.breite)
}
}
\ No newline at end of file
import androidx.compose.desktop.Window
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.*
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusOrder
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import de.kompo.common.Abmessungen
import de.kompo.common.Moebel
import de.kompo.common.Store
import de.kompo.ui.MainApplication
import de.kompo.ui.MoebelView
import de.kompo.ui.StoreDetailView
fun MainWindow(app: MainApplication) = Window {
MaterialTheme(colors = app.style) {
Surface(modifier = Modifier.fillMaxSize()) {
var selected = remember { mutableStateOf<Store?>(null) }
var selected by remember { mutableStateOf<Store?>(null) }
val stores = mutableStateListOf<Store>()
stores.addAll(app.model.getStores())
val showAddStore = remember { mutableStateOf(false) }
if (showAddStore.value){
if (showAddStore.value) {
Dialog({
showAddStore.value = false
}){
MaterialTheme(colors = app.style){
}) {
MaterialTheme(colors = app.style) {
Surface(modifier = Modifier.fillMaxSize()) {
val storeName = remember { mutableStateOf(TextFieldValue()) }
Column {
......@@ -52,31 +62,89 @@ fun MainWindow(app: MainApplication) = Window {
}
val showAddMoebel = remember { mutableStateOf(false) }
if (showAddMoebel.value){
if (showAddMoebel.value) {
Dialog({
showAddMoebel.value = false
}){
MaterialTheme(colors = app.style){
}) {
MaterialTheme(colors = app.style) {
Surface(modifier = Modifier.fillMaxSize()) {
val moebelName = remember { mutableStateOf(TextFieldValue()) }
var moebelName by remember { mutableStateOf(TextFieldValue()) }
var moebelAnzahl by remember { mutableStateOf(TextFieldValue()) }
var moebelPreis by remember { mutableStateOf(TextFieldValue()) }
var moebelHöhe by remember { mutableStateOf(TextFieldValue()) }
var moebelLänge by remember { mutableStateOf(TextFieldValue()) }
var moebelBreite by remember { mutableStateOf(TextFieldValue()) }
Column {
Text("")
TextField(
value = moebelName.value,
onValueChange = { moebelName.value = it },
label = { Text("Label") }
value = moebelName,
onValueChange = { moebelName = it },
label = { Text("Name") }
)
TextField(
value = moebelAnzahl,
onValueChange = { moebelAnzahl = it },
label = { Text("Anzahl") },
)
TextField(
value = moebelPreis,
onValueChange = { moebelPreis = it },
label = { Text("Preis") }
)
TextField(
value = moebelHöhe,
onValueChange = { moebelHöhe = it },
label = { Text("Höhe") }
)
TextField(
value = moebelLänge,
onValueChange = { moebelLänge = it },
label = { Text("Länge") }
)
TextField(
value = moebelBreite,
onValueChange = { moebelBreite = it },
label = { Text("Breite") }
)
Row {
Button({
selected.value?.let { store ->
app.model.addMoebel(store, Moebel(moebelName.value.text),{
selected.value = it
}){
val anzahl = moebelAnzahl.text.toIntOrNull() ?: return@Button
val preis = moebelPreis.text.toFloatOrNull()
?: (moebelPreis.text + ".0").toFloatOrNull() ?: return@Button
val höhe =
moebelHöhe.text.toFloatOrNull() ?: (moebelHöhe.text + ".0").toFloatOrNull()
?: return@Button
val länge = moebelLänge.text.toFloatOrNull()
?: (moebelLänge.text + ".0").toFloatOrNull() ?: return@Button
val breite = moebelBreite.text.toFloatOrNull()
?: (moebelBreite.text + ".0").toFloatOrNull() ?: return@Button
selected?.let { store ->
app.model.addMoebel(store, Moebel(
moebelName.text,
anzahl,
preis,
Abmessungen(
höhe,
länge,
breite
)
), {
selected = it
}) {
}
}
showAddMoebel.value = false
moebelName.value = TextFieldValue()
moebelName = TextFieldValue()
moebelAnzahl = TextFieldValue()
moebelPreis = TextFieldValue()
moebelHöhe = TextFieldValue()
moebelLänge = TextFieldValue()
moebelBreite = TextFieldValue()
stores.clear()
stores.addAll(app.model.getStores())
}) {
......@@ -89,18 +157,23 @@ fun MainWindow(app: MainApplication) = Window {
}
}
Row {
Column {
Row {
Button({
showAddStore.value = true
}) {
Text("New Store")
Column(
Modifier.fillMaxWidth(0.3f)
) {
Box(modifier = Modifier.fillMaxWidth().background(MaterialTheme.colors.primaryVariant)) {
Column(Modifier.padding(5.dp)) {
Text("Lager: \n")
Button({
showAddStore.value = true
}, modifier = Modifier.padding(5.dp)) {
Text("New Store")
}
}
}
Row {
StoreTreeView(app.model, modifier = Modifier.padding(4.dp).wrapContentWidth().fillMaxHeight(),stores) {
selected.value = it
StoreTreeView(app.model, modifier = Modifier.padding(4.dp).fillMaxSize(), stores) {
selected = it
}
}
......@@ -110,15 +183,37 @@ fun MainWindow(app: MainApplication) = Window {
.width(1.dp)
.fillMaxHeight()
)
Card(modifier = Modifier.padding(8.dp), elevation = 4.dp) {
selected.value?.let { store ->
StoreDetailView(store){
showAddMoebel.value = true
var selectedMoebel by remember { mutableStateOf<Moebel?>(null) }
Row(modifier = Modifier.fillMaxWidth(0.5f).fillMaxHeight()) {
Column(Modifier.fillMaxSize()) {
Box(Modifier.fillMaxWidth().background(MaterialTheme.colors.primaryVariant)) {
Column(modifier = Modifier.fillMaxWidth().padding(5.dp)) {
if (selected == null)
Text("Kein Lager Ausgewählt\n")
else {
Text("Möbelstücke in: \n" + selected?.name)
Button({
showAddMoebel.value = true
}, modifier = Modifier.padding(5.dp)) {
Text("Neues Möbelstück")
}
}
}
}
selected?.let { store ->
StoreDetailView(store, onSelected = {
selectedMoebel = it
}, selected = selectedMoebel)
}
} ?: run {
Text("no Store Selected")
}
}
Divider(
Modifier.padding(4.dp)
.width(1.dp)
.fillMaxHeight()
)
selectedMoebel?.let { MoebelView(moebel = it) }
}
}
}
......
package de.kompo.ui
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.selection.selectable
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import de.kompo.common.Moebel
import de.kompo.common.Store
@Composable
fun StoreView(item: Store,modifier: Modifier = Modifier.wrapContentSize()) = Box(modifier) {
Text(item.name,Modifier.padding(4.dp).wrapContentSize())
fun StoreView(item: Store,modifier: Modifier = Modifier.wrapContentSize(),selected:Boolean = false) = Box(modifier) {
Text(item.name,Modifier.padding(4.dp).wrapContentSize(),color = if (selected) MaterialTheme.colors.primary else Color.White)
}
@Composable
fun StoreDetailView(item: Store,modifier: Modifier = Modifier.wrapContentSize(),OnAddMoebel: ()->Unit) = Column (modifier) {
Text(item.name,Modifier.padding(4.dp).wrapContentSize())
Button(OnAddMoebel){
Text("add möbelstück")
}
fun StoreDetailView(item: Store,modifier: Modifier = Modifier.wrapContentSize(),onSelected:(Moebel)->Unit,selected: Moebel?) = Column (modifier) {
LazyColumn {
items(item.items){
Text(it.name,Modifier.padding(4.dp).wrapContentSize())
Box(Modifier.fillMaxWidth().selectable(selected == it){onSelected(it)}){
Text(it.name,Modifier.padding(4.dp),color = if (selected == it) MaterialTheme.colors.primary else Color.White)
}
}
}
}
\ No newline at end of file
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.selection.selectable
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import de.kompo.common.Store
import de.kompo.common.StoreRepo
......@@ -30,10 +37,10 @@ fun StoreTreeView(model: StoreRepo,modifier: Modifier = Modifier.fillMaxSize().w
state = scrollState
) {
items(list){ store ->
StoreView(store,modifier = Modifier.wrapContentSize().selectable(store.name == selectedId.value?.name){
StoreView(store,modifier = Modifier.fillMaxWidth().selectable(store.name == selectedId.value?.name){
selectedId.value = store
onSelect(store)
})
},store.name == selectedId.value?.name)
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment