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