mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-06 19:40:08 +02:00
🏗️ SwiftUI and config views
This commit is contained in:
@ -8,19 +8,35 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct PreferenceContainer: View {
|
||||
private var name: String = "Memory Limit"
|
||||
private var description: String = "This is the maximum memory a given PHP script may consume."
|
||||
private var controlView: some View = ByteLimitView()
|
||||
struct PreferenceContainer<ControlView: View>: View {
|
||||
private var name: String
|
||||
private var description: String
|
||||
private var controlView: ControlView
|
||||
|
||||
init(
|
||||
name: String,
|
||||
description: String,
|
||||
@ViewBuilder _ controlView: () -> ControlView
|
||||
) {
|
||||
self.name = name
|
||||
self.description = description
|
||||
self.controlView = controlView()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
HStack(alignment: .top, spacing: 50) {
|
||||
Text(self.name).bold()
|
||||
VStack(alignment: .leading) {
|
||||
Text(self.name)
|
||||
.bold()
|
||||
.multilineTextAlignment(.leading)
|
||||
.frame(minWidth: 150, maxWidth: 150, alignment: .leading)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
controlView
|
||||
Text(self.description).font(.subheadline)
|
||||
}
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
.padding(10)
|
||||
@ -49,10 +65,20 @@ struct ByteLimitView: View {
|
||||
.labelsHidden()
|
||||
.pickerStyle(.menu)
|
||||
}
|
||||
|
||||
func setValue(value: String) {
|
||||
return
|
||||
}
|
||||
|
||||
func getValue() -> String {
|
||||
return "ok"
|
||||
}
|
||||
}
|
||||
|
||||
struct ByteLimitView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
PreferenceContainer()
|
||||
PreferenceContainer(name: "Something\nStupid", description: "Description") {
|
||||
ByteLimitView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,25 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct PhpPreference {
|
||||
let key: String
|
||||
let type: PhpPreferenceType
|
||||
}
|
||||
|
||||
enum PhpPreferenceType {
|
||||
case byteLimit
|
||||
case string
|
||||
case boolean
|
||||
}
|
||||
|
||||
struct ConfigManagerView: View {
|
||||
var preferences: [PhpPreference] = [
|
||||
PhpPreference(key: "memory_limit", type: .byteLimit),
|
||||
PhpPreference(key: "post_max_size", type: .byteLimit),
|
||||
PhpPreference(key: "file_uploads", type: .boolean),
|
||||
PhpPreference(key: "upload_max_filesize", type: .byteLimit)
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
HStack(alignment: .center, spacing: 15) {
|
||||
@ -35,9 +53,21 @@ struct ConfigManagerView: View {
|
||||
Divider()
|
||||
|
||||
VStack(spacing: 5) {
|
||||
PreferenceContainer()
|
||||
// PreferenceContainer()
|
||||
// PreferenceContainer()
|
||||
ForEach(preferences, id: \.key) { preference in
|
||||
PreferenceContainer(
|
||||
name: "php_ini." + preference.key + ".title",
|
||||
description: "php_ini." + preference.key + ".description"
|
||||
) {
|
||||
if preference.type == .byteLimit {
|
||||
ByteLimitView()
|
||||
}
|
||||
if preference.type == .boolean {
|
||||
Text("Boolean value here")
|
||||
// Toggle(isOn: preference.)
|
||||
}
|
||||
}.frame(maxWidth: .infinity)
|
||||
}
|
||||
|
||||
Divider()
|
||||
HStack {
|
||||
Button("Close", action: {
|
||||
|
Reference in New Issue
Block a user