From 6a2a66e66056baaf0f06a4cacd9438818ee81c76 Mon Sep 17 00:00:00 2001 From: Ryan Priebe Date: Wed, 13 Dec 2023 18:10:38 -0700 Subject: [PATCH 1/6] added divider between unowned and owned projects in outline widget --- DLPrototype/MainMenu.swift | 6 +++--- DLPrototype/Views/Companies/CompanyBlock.swift | 6 ------ .../Views/Companies/CompanyDashboard.swift | 8 +------- .../Widgets/CreateEntitiesWidget.swift | 4 ++-- DLPrototype/Views/Shared/Outline.swift | 17 ++++++++++------- 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/DLPrototype/MainMenu.swift b/DLPrototype/MainMenu.swift index 7452c253..e57961e1 100644 --- a/DLPrototype/MainMenu.swift +++ b/DLPrototype/MainMenu.swift @@ -27,17 +27,17 @@ struct MainMenu: Commands { .keyboardShortcut("n", modifiers: .command) Button("Note") { nav.view = AnyView(NoteCreate()) - nav.parent = .today + nav.parent = .notes } .keyboardShortcut("n", modifiers: [.command, .shift]) Button("Task") { nav.view = AnyView(TaskDashboard()) - nav.parent = .today + nav.parent = .tasks } .keyboardShortcut("t", modifiers: [.command, .shift]) Button("Project") { nav.view = AnyView(ProjectCreate()) - nav.parent = .today + nav.parent = .companies } .keyboardShortcut("p", modifiers: [.command, .shift]) Button("Job") { diff --git a/DLPrototype/Views/Companies/CompanyBlock.swift b/DLPrototype/Views/Companies/CompanyBlock.swift index 25c5fa1c..7a547705 100644 --- a/DLPrototype/Views/Companies/CompanyBlock.swift +++ b/DLPrototype/Views/Companies/CompanyBlock.swift @@ -50,9 +50,3 @@ struct CompanyBlock: View { .buttonStyle(.plain) } } - -//struct CompanyBlock_Previews: PreviewProvider { -// static var previews: some View { -// CompanyBlock() -// } -//} diff --git a/DLPrototype/Views/Companies/CompanyDashboard.swift b/DLPrototype/Views/Companies/CompanyDashboard.swift index ccc0df71..a10dbdcf 100644 --- a/DLPrototype/Views/Companies/CompanyDashboard.swift +++ b/DLPrototype/Views/Companies/CompanyDashboard.swift @@ -88,7 +88,7 @@ extension CompanyDashboard { init(company: Company? = nil) { let request: NSFetchRequest = Company.fetchRequest() request.sortDescriptors = [ - NSSortDescriptor(keyPath: \Company.name?, ascending: false) + NSSortDescriptor(keyPath: \Company.name, ascending: true) ] request.predicate = NSPredicate(format: "alive = true") @@ -120,9 +120,3 @@ extension CompanyDashboard { } } } - -//struct CompanyDashboard_Previews: PreviewProvider { -// static var previews: some View { -// Company() -// } -//} diff --git a/DLPrototype/Views/Shared/AppSidebar/Widgets/CreateEntitiesWidget.swift b/DLPrototype/Views/Shared/AppSidebar/Widgets/CreateEntitiesWidget.swift index a8fb41ba..038b18d6 100644 --- a/DLPrototype/Views/Shared/AppSidebar/Widgets/CreateEntitiesWidget.swift +++ b/DLPrototype/Views/Shared/AppSidebar/Widgets/CreateEntitiesWidget.swift @@ -127,8 +127,8 @@ struct CreateEntitiesWidget: View { size: .small, type: nav.parent == .projects ? .secondary : .standard, redirect: AnyView(ProjectCreate()), - pageType: .projects, - sidebar: AnyView(ProjectsDashboardSidebar()) + pageType: .companies, + sidebar: AnyView(DefaultCompanySidebar()) ) .mask(Circle()) } diff --git a/DLPrototype/Views/Shared/Outline.swift b/DLPrototype/Views/Shared/Outline.swift index 9947a53f..9775961c 100644 --- a/DLPrototype/Views/Shared/Outline.swift +++ b/DLPrototype/Views/Shared/Outline.swift @@ -41,14 +41,17 @@ struct Outline: View { } if unowned.count > 0 { - Text("Unowned Projects") - ForEach(unowned) { project in - HStack { - Image(systemName: "arrow.turn.down.right") - FancyTextLink(text: project.name!.capitalized, destination: AnyView(ProjectView(project: project)), pageType: .companies, sidebar: AnyView(DefaultCompanySidebar())) - .help("Edit project: \(project.name!.capitalized)") + Divider() + VStack(alignment: .leading) { + Text("Unowned Projects") + ForEach(unowned) { project in + HStack { + Image(systemName: "arrow.turn.down.right") + FancyTextLink(text: project.name!.capitalized, destination: AnyView(ProjectView(project: project)), pageType: .companies, sidebar: AnyView(DefaultCompanySidebar())) + .help("Edit project: \(project.name!.capitalized)") + } + .padding([.leading], 10) } - .padding([.leading], 10) } } } From 02faa620dbc8574544e9be6bc426e1c3e30855de Mon Sep 17 00:00:00 2001 From: Ryan Priebe Date: Wed, 13 Dec 2023 20:52:23 -0700 Subject: [PATCH 2/6] data hierarchy widget ux updates --- DLPrototype/Helpers/StringHelper.swift | 9 ++++++++- DLPrototype/Views/Projects/ProjectView.swift | 3 ++- DLPrototype/Views/Shared/Outline.swift | 10 ++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/DLPrototype/Helpers/StringHelper.swift b/DLPrototype/Helpers/StringHelper.swift index 90e58664..3ecfe955 100644 --- a/DLPrototype/Helpers/StringHelper.swift +++ b/DLPrototype/Helpers/StringHelper.swift @@ -10,6 +10,13 @@ import SwiftUI public final class StringHelper { static public func abbreviate(_ data: String) -> String { - return String(data.split(separator: " ").map {$0.first!}).uppercased() + let letters = data.split(separator: " ").map {$0.first!} + + // get the first 3 characters if there's only one word + if letters.count == 1 { + return String(data.prefix(4)).uppercased() + } + + return String(letters).uppercased() } } diff --git a/DLPrototype/Views/Projects/ProjectView.swift b/DLPrototype/Views/Projects/ProjectView.swift index 0b420f02..aebe546c 100644 --- a/DLPrototype/Views/Projects/ProjectView.swift +++ b/DLPrototype/Views/Projects/ProjectView.swift @@ -64,7 +64,7 @@ struct ProjectView: View { } Spacer() - FancyButtonv2(text: "Update project", action: update) + FancyButtonv2(text: "Save & Close", action: update, redirect: AnyView(CompanyDashboard()), pageType: .companies, sidebar: AnyView(DefaultCompanySidebar())) } Spacer() @@ -461,6 +461,7 @@ extension ProjectView { project.alive = alive project.lastUpdate = Date() project.company = CoreDataCompanies(moc: moc).byPid(selectedCompany) + project.abbreviation = StringHelper.abbreviate(name) if colourChanged { project.colour = Color.randomStorable() diff --git a/DLPrototype/Views/Shared/Outline.swift b/DLPrototype/Views/Shared/Outline.swift index 9775961c..d3db93ae 100644 --- a/DLPrototype/Views/Shared/Outline.swift +++ b/DLPrototype/Views/Shared/Outline.swift @@ -19,6 +19,12 @@ struct Outline: View { var body: some View { VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 10) { + HStack { + Image(systemName: "menucard") + Text("Outline view") + } + Divider() + if companies.count > 0 { ForEach(companies) { company in Group { @@ -47,7 +53,7 @@ struct Outline: View { ForEach(unowned) { project in HStack { Image(systemName: "arrow.turn.down.right") - FancyTextLink(text: project.name!.capitalized, destination: AnyView(ProjectView(project: project)), pageType: .companies, sidebar: AnyView(DefaultCompanySidebar())) + FancyTextLink(text: "[\(project.abbreviation != nil ? project.abbreviation!.uppercased() : "NOPE")] \(project.name!.capitalized)", destination: AnyView(ProjectView(project: project)), pageType: .companies, sidebar: AnyView(DefaultCompanySidebar())) .help("Edit project: \(project.name!.capitalized)") } .padding([.leading], 10) @@ -102,7 +108,7 @@ struct ProjectOutline: View { ForEach(projects) { project in HStack { Image(systemName: "arrow.turn.down.right") - FancyTextLink(text: project.name!.capitalized, destination: AnyView(ProjectView(project: project)), pageType: .companies, sidebar: AnyView(DefaultCompanySidebar())) + FancyTextLink(text: "[\(project.abbreviation != nil ? project.abbreviation!.uppercased() : "NOPE")] \(project.name!.capitalized)", destination: AnyView(ProjectView(project: project)), pageType: .companies, sidebar: AnyView(DefaultCompanySidebar())) .help("Edit project: \(project.name!.capitalized)") } .padding([.leading], 10) From 807350e491e39216043130629494238e99c0f078 Mon Sep 17 00:00:00 2001 From: Ryan Priebe Date: Thu, 14 Dec 2023 12:35:26 -0700 Subject: [PATCH 3/6] company blocks on company dashboard are now coloured --- DLPrototype.xcodeproj/project.pbxproj | 4 ++ DLPrototype/Extensions/Color.swift | 14 ++++- .../Views/Companies/CompanyBlock.swift | 4 +- DLPrototype/Views/Companies/CompanyView.swift | 21 ++++--- DLPrototype/Views/Projects/ProjectView.swift | 28 +-------- .../Shared/Fancy/FancyColourPicker.swift | 61 +++++++++++++++++++ 6 files changed, 94 insertions(+), 38 deletions(-) create mode 100644 DLPrototype/Views/Shared/Fancy/FancyColourPicker.swift diff --git a/DLPrototype.xcodeproj/project.pbxproj b/DLPrototype.xcodeproj/project.pbxproj index 34b802a5..64274f19 100644 --- a/DLPrototype.xcodeproj/project.pbxproj +++ b/DLPrototype.xcodeproj/project.pbxproj @@ -47,6 +47,7 @@ 5334F26A2B2A14F90079D2E7 /* ManageOwnedProjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F2692B2A14F90079D2E7 /* ManageOwnedProjects.swift */; }; 5334F26C2B2A5BD60079D2E7 /* FancyToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F26B2B2A5BD60079D2E7 /* FancyToggle.swift */; }; 5334F26E2B2A5CC50079D2E7 /* FancyLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F26D2B2A5CC50079D2E7 /* FancyLabel.swift */; }; + 5334F2702B2B83190079D2E7 /* FancyColourPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F26F2B2B83190079D2E7 /* FancyColourPicker.swift */; }; 5335A5AE296CFF83000051B1 /* FileHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5335A5AD296CFF83000051B1 /* FileHelper.swift */; }; 5335A5B3296D17EB000051B1 /* TaskDashboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5335A5B2296D17EB000051B1 /* TaskDashboard.swift */; }; 5335A5B5296D1FA7000051B1 /* TaskView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5335A5B4296D1FA7000051B1 /* TaskView.swift */; }; @@ -252,6 +253,7 @@ 5334F2692B2A14F90079D2E7 /* ManageOwnedProjects.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManageOwnedProjects.swift; sourceTree = ""; }; 5334F26B2B2A5BD60079D2E7 /* FancyToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FancyToggle.swift; sourceTree = ""; }; 5334F26D2B2A5CC50079D2E7 /* FancyLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FancyLabel.swift; sourceTree = ""; }; + 5334F26F2B2B83190079D2E7 /* FancyColourPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FancyColourPicker.swift; sourceTree = ""; }; 5335A5AD296CFF83000051B1 /* FileHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileHelper.swift; sourceTree = ""; }; 5335A5B2296D17EB000051B1 /* TaskDashboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskDashboard.swift; sourceTree = ""; }; 5335A5B4296D1FA7000051B1 /* TaskView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskView.swift; sourceTree = ""; }; @@ -852,6 +854,7 @@ 53E202752A81F2E100B4DF70 /* FancyStar.swift */, 5334F26B2B2A5BD60079D2E7 /* FancyToggle.swift */, 5334F26D2B2A5CC50079D2E7 /* FancyLabel.swift */, + 5334F26F2B2B83190079D2E7 /* FancyColourPicker.swift */, ); path = Fancy; sourceTree = ""; @@ -1211,6 +1214,7 @@ 53EDDFA22963502A008D34C7 /* LogRowEmpty.swift in Sources */, 5371BA342A7B2B8F00DEEC21 /* JobRowPlain.swift in Sources */, 533AB3F2296CA34600E91A9F /* ManageRecords.swift in Sources */, + 5334F2702B2B83190079D2E7 /* FancyColourPicker.swift in Sources */, 53DFF075296F124E0051DA91 /* ManageTasks.swift in Sources */, 5334F26A2B2A14F90079D2E7 /* ManageOwnedProjects.swift in Sources */, 53790C102A74D54C00D3FFD4 /* JobFormValidator.swift in Sources */, diff --git a/DLPrototype/Extensions/Color.swift b/DLPrototype/Extensions/Color.swift index 1c4da5c2..a9fce9b1 100644 --- a/DLPrototype/Extensions/Color.swift +++ b/DLPrototype/Extensions/Color.swift @@ -29,7 +29,7 @@ extension Color { return colour } - + static func randomStorable() -> [Double] { return [Double.random(in: 0...1), Double.random(in: 0...1), Double.random(in: 0...1)] } @@ -43,4 +43,16 @@ extension Color { let brightness = ((components[0] * 299) + (components[1] * 587) + (components[2] * 114)) / 1000 return (brightness > 0.5) } + + public func toStored() -> [Double] { + if let components = cgColor?.components { + let r = components[0] * 1.0 + let g = components[1] * 1.0 + let b = components[2] * 1.0 + + return [r,g,b] + } + + return [0.0, 0.0, 0.0] + } } diff --git a/DLPrototype/Views/Companies/CompanyBlock.swift b/DLPrototype/Views/Companies/CompanyBlock.swift index 7a547705..7763614c 100644 --- a/DLPrototype/Views/Companies/CompanyBlock.swift +++ b/DLPrototype/Views/Companies/CompanyBlock.swift @@ -24,9 +24,9 @@ struct CompanyBlock: View { } label: { VStack(spacing: 0) { ZStack(alignment: .topLeading) { - (company.alive ? Color.yellow : Color.white) + (company.alive ? Color.fromStored(company.colour!) : Color.white) .shadow(color: .black.opacity(1), radius: 3) - .opacity(highlighted ? 0.2 : 0.1) + .opacity(highlighted ? 0.4 : 0.3) VStack(alignment: .leading, spacing: 10) { HStack { diff --git a/DLPrototype/Views/Companies/CompanyView.swift b/DLPrototype/Views/Companies/CompanyView.swift index 74365b76..ca8534a0 100644 --- a/DLPrototype/Views/Companies/CompanyView.swift +++ b/DLPrototype/Views/Companies/CompanyView.swift @@ -15,6 +15,7 @@ struct CompanyView: View { @State private var abbreviation: String = "" @State private var created: Date? = nil @State private var updated: Date? = nil + @State private var colour: Color = .clear @State private var isDeleteAlertShowing: Bool = false @Environment(\.managedObjectContext) var moc @@ -35,7 +36,8 @@ struct CompanyView: View { FancyTextField(placeholder: "Legal name", lineLimit: 1, onSubmit: {}, showLabel: true, text: $name) FancyTextField(placeholder: "Abbreviation", lineLimit: 1, onSubmit: {}, showLabel: true, text: $abbreviation) - + FancyColourPicker(initialColour: company.colour ?? Theme.rowColourAsDouble, onChange: {colourAsDouble in colour = Color.fromStored(colourAsDouble)}) + if let created = created { HStack { FancyLabel(text: "Created") @@ -83,7 +85,7 @@ struct CompanyView: View { Spacer() FancyButtonv2( - text: "Save", + text: "Save & Close", action: save, size: .medium, redirect: AnyView(CompanyDashboard()), @@ -112,6 +114,13 @@ struct CompanyView: View { abbreviation = newCompany.abbreviation! created = newCompany.createdDate! updated = newCompany.lastUpdate! + + if let c = newCompany.colour { + colour = Color.fromStored(c) + } + } + .onChange(of: colour) { newColour in + self.save() } } } @@ -121,6 +130,7 @@ extension CompanyView { name = company.name! abbreviation = company.abbreviation! created = company.createdDate! + colour = Color.fromStored(company.colour ?? Theme.rowColourAsDouble) if let updatedAt = company.lastUpdate { updated = updatedAt @@ -131,6 +141,7 @@ extension CompanyView { company.name = name company.abbreviation = abbreviation company.lastUpdate = Date() + company.colour = colour.toStored() PersistenceController.shared.save() } @@ -164,9 +175,3 @@ extension CompanyView { nav.setSidebar(AnyView(DefaultCompanySidebar())) } } - -//struct CompanyView_Previews: PreviewProvider { -// static var previews: some View { -// CompanyView() -// } -//} diff --git a/DLPrototype/Views/Projects/ProjectView.swift b/DLPrototype/Views/Projects/ProjectView.swift index aebe546c..5b459e8a 100644 --- a/DLPrototype/Views/Projects/ProjectView.swift +++ b/DLPrototype/Views/Projects/ProjectView.swift @@ -109,38 +109,12 @@ struct ProjectView: View { @ViewBuilder var form: some View { Title(text: "Editing: \($name.wrappedValue)") - FancyTextField(placeholder: "Name", lineLimit: 1, onSubmit: update, showLabel: true, text: $name) FancyTextField(placeholder: "Abbreviation", lineLimit: 1, onSubmit: {}, showLabel: true, text: $abbreviation) CompanyPicker(onChange: {company,_ in selectedCompany = company}, selected: project.company != nil ? Int(project.company!.pid) : 0) FancyToggle(entity: project) + FancyColourPicker(initialColour: project.colour ?? Theme.rowColourAsDouble, onChange: {colourAsDouble in colour = Color.fromStored(colourAsDouble).description}) - HStack(spacing: 0) { - FancyLabel(text: "Colour") - .padding([.trailing], 10) - Rectangle() - .frame(width: 20) - .background(Color.fromStored(project.colour ?? Theme.rowColourAsDouble)) - .foregroundColor(.clear) - - FancyTextField( - placeholder: "Colour", - lineLimit: 1, - onSubmit: {}, - disabled: true, - bgColour: Color.clear, - text: $colour - ) - .border(Color.black.opacity(0.1), width: 2) - .frame(width: 200) - .onAppear(perform: { - colour = Color.fromStored(project.colour ?? Theme.rowColourAsDouble).description.debugDescription - }) - - FancyButtonv2(text: "Regenerate colour", action: regenerateColour, icon: "arrow.counterclockwise", showLabel: false) - .padding(.leading, 5) - }.frame(height: 40) - if let createdAt = created { HStack { FancyLabel(text: "Created") diff --git a/DLPrototype/Views/Shared/Fancy/FancyColourPicker.swift b/DLPrototype/Views/Shared/Fancy/FancyColourPicker.swift new file mode 100644 index 00000000..f0782b0f --- /dev/null +++ b/DLPrototype/Views/Shared/Fancy/FancyColourPicker.swift @@ -0,0 +1,61 @@ +// +// FancyColourPicker.swift +// DLPrototype +// +// Created by Ryan Priebe on 2023-12-14. +// Copyright © 2023 YegCollective. All rights reserved. +// + +import SwiftUI + +struct FancyColourPicker: View { + public let initialColour: [Double] + public let onChange: (([Double]) -> Void) + + @State private var asColor: Color + @State private var asString: String = "" + + var body: some View { + HStack(spacing: 0) { + FancyLabel(text: "Colour") + .padding([.trailing], 10) + Rectangle() + .frame(width: 20) + .background(asColor) + .foregroundColor(.clear) + + FancyTextField( + placeholder: "Colour", + lineLimit: 1, + onSubmit: {}, + disabled: true, + bgColour: Color.clear, + text: $asString + ) + .border(Color.black.opacity(0.1), width: 2) + .frame(width: 200) + .onAppear(perform: { + asString = asColor.description + }) + + FancyButtonv2(text: "Regenerate colour", action: regenerateColour, icon: "arrow.counterclockwise", showLabel: false) + .padding(.leading, 5) + }.frame(height: 40) + } +} + +extension FancyColourPicker { + init(initialColour: [Double], onChange: @escaping (([Double]) -> Void)) { + self.initialColour = initialColour + self.onChange = onChange + asColor = Color.fromStored(initialColour) + } + + private func regenerateColour() -> Void { + let rndColour = Color.randomStorable() + asColor = Color.fromStored(rndColour) + asString = asColor.description + + onChange(rndColour) + } +} From ce31f2df4bc9c87520809fd41679ba4b2f0324fc Mon Sep 17 00:00:00 2001 From: Ryan Priebe Date: Thu, 14 Dec 2023 12:52:47 -0700 Subject: [PATCH 4/6] company/project colour randomizers are now colour pickers --- DLPrototype/Views/Companies/CompanyView.swift | 2 +- DLPrototype/Views/Projects/ProjectView.swift | 22 +++++++------- .../Shared/Fancy/FancyColourPicker.swift | 30 +++++++++---------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/DLPrototype/Views/Companies/CompanyView.swift b/DLPrototype/Views/Companies/CompanyView.swift index ca8534a0..ae8ebd96 100644 --- a/DLPrototype/Views/Companies/CompanyView.swift +++ b/DLPrototype/Views/Companies/CompanyView.swift @@ -36,7 +36,7 @@ struct CompanyView: View { FancyTextField(placeholder: "Legal name", lineLimit: 1, onSubmit: {}, showLabel: true, text: $name) FancyTextField(placeholder: "Abbreviation", lineLimit: 1, onSubmit: {}, showLabel: true, text: $abbreviation) - FancyColourPicker(initialColour: company.colour ?? Theme.rowColourAsDouble, onChange: {colourAsDouble in colour = Color.fromStored(colourAsDouble)}) + FancyColourPicker(initialColour: company.colour ?? Theme.rowColourAsDouble, onChange: {newColour in colour = newColour}) if let created = created { HStack { diff --git a/DLPrototype/Views/Projects/ProjectView.swift b/DLPrototype/Views/Projects/ProjectView.swift index 5b459e8a..8e4a3b82 100644 --- a/DLPrototype/Views/Projects/ProjectView.swift +++ b/DLPrototype/Views/Projects/ProjectView.swift @@ -13,7 +13,7 @@ struct ProjectView: View { public let project: Project @State private var name: String = "" - @State private var colour: String = "" + @State private var colour: Color = .clear @State private var colourChanged: Bool = false @State private var created: Date? @State private var lastUpdate: Date? @@ -113,7 +113,7 @@ struct ProjectView: View { FancyTextField(placeholder: "Abbreviation", lineLimit: 1, onSubmit: {}, showLabel: true, text: $abbreviation) CompanyPicker(onChange: {company,_ in selectedCompany = company}, selected: project.company != nil ? Int(project.company!.pid) : 0) FancyToggle(entity: project) - FancyColourPicker(initialColour: project.colour ?? Theme.rowColourAsDouble, onChange: {colourAsDouble in colour = Color.fromStored(colourAsDouble).description}) + FancyColourPicker(initialColour: project.colour ?? Theme.rowColourAsDouble, onChange: {newColour in colour = newColour}) if let createdAt = created { HStack { @@ -389,15 +389,15 @@ struct ProjectView: View { } extension ProjectView { - private func regenerateColour() -> Void { - let rndColour = Color.randomStorable() - colour = Color.fromStored(rndColour).description.debugDescription - project.colour = rndColour - colourChanged = true - - PersistenceController.shared.save() - updater.update() - } +// private func regenerateColour() -> Void { +// let rndColour = Color.randomStorable() +// colour = Color.fromStored(rndColour).description.debugDescription +// project.colour = rndColour +// colourChanged = true +// +// PersistenceController.shared.save() +// updater.update() +// } private func createToolbar() -> Void { // TODO: apply this pattern to Today view diff --git a/DLPrototype/Views/Shared/Fancy/FancyColourPicker.swift b/DLPrototype/Views/Shared/Fancy/FancyColourPicker.swift index f0782b0f..505e0ea3 100644 --- a/DLPrototype/Views/Shared/Fancy/FancyColourPicker.swift +++ b/DLPrototype/Views/Shared/Fancy/FancyColourPicker.swift @@ -10,7 +10,7 @@ import SwiftUI struct FancyColourPicker: View { public let initialColour: [Double] - public let onChange: (([Double]) -> Void) + public let onChange: ((Color) -> Void) @State private var asColor: Color @State private var asString: String = "" @@ -19,10 +19,10 @@ struct FancyColourPicker: View { HStack(spacing: 0) { FancyLabel(text: "Colour") .padding([.trailing], 10) - Rectangle() - .frame(width: 20) - .background(asColor) - .foregroundColor(.clear) + + ColorPicker("", selection: $asColor) + .rotationEffect(.degrees(90)) + .frame(width: 20, height: 45) FancyTextField( placeholder: "Colour", @@ -34,28 +34,28 @@ struct FancyColourPicker: View { ) .border(Color.black.opacity(0.1), width: 2) .frame(width: 200) - .onAppear(perform: { - asString = asColor.description - }) - FancyButtonv2(text: "Regenerate colour", action: regenerateColour, icon: "arrow.counterclockwise", showLabel: false) - .padding(.leading, 5) }.frame(height: 40) + .onAppear(perform: { + asString = asColor.description + }) + .onChange(of: asColor) { newColour in + colourChanged(newColour) + } } } extension FancyColourPicker { - init(initialColour: [Double], onChange: @escaping (([Double]) -> Void)) { + init(initialColour: [Double], onChange: @escaping ((Color) -> Void)) { self.initialColour = initialColour self.onChange = onChange asColor = Color.fromStored(initialColour) } - private func regenerateColour() -> Void { - let rndColour = Color.randomStorable() - asColor = Color.fromStored(rndColour) + private func colourChanged(_ newColour: Color) -> Void { + asColor = newColour asString = asColor.description - onChange(rndColour) + onChange(newColour) } } From 171ff11b9ee4ad9ebeeedcd8077952326536f21d Mon Sep 17 00:00:00 2001 From: Ryan Priebe Date: Thu, 14 Dec 2023 13:10:35 -0700 Subject: [PATCH 5/6] updated job form UX --- DLPrototype.xcodeproj/project.pbxproj | 16 +++-- DLPrototype/Views/Jobs/JobView.swift | 70 +++++-------------- DLPrototype/Views/Projects/ProjectView.swift | 2 +- .../Shared/Fancy/FancyJobActiveToggle.swift | 41 +++++++++++ .../Shared/Fancy/FancyJobSredToggle.swift | 41 +++++++++++ ...e.swift => FancyProjectActiveToggle.swift} | 2 +- 6 files changed, 113 insertions(+), 59 deletions(-) create mode 100644 DLPrototype/Views/Shared/Fancy/FancyJobActiveToggle.swift create mode 100644 DLPrototype/Views/Shared/Fancy/FancyJobSredToggle.swift rename DLPrototype/Views/Shared/Fancy/{FancyToggle.swift => FancyProjectActiveToggle.swift} (95%) diff --git a/DLPrototype.xcodeproj/project.pbxproj b/DLPrototype.xcodeproj/project.pbxproj index 64274f19..585af616 100644 --- a/DLPrototype.xcodeproj/project.pbxproj +++ b/DLPrototype.xcodeproj/project.pbxproj @@ -45,9 +45,11 @@ 5334F2662B28FA520079D2E7 /* Outline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F2652B28FA520079D2E7 /* Outline.swift */; }; 5334F2682B2963B60079D2E7 /* StringHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F2672B2963B60079D2E7 /* StringHelper.swift */; }; 5334F26A2B2A14F90079D2E7 /* ManageOwnedProjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F2692B2A14F90079D2E7 /* ManageOwnedProjects.swift */; }; - 5334F26C2B2A5BD60079D2E7 /* FancyToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F26B2B2A5BD60079D2E7 /* FancyToggle.swift */; }; + 5334F26C2B2A5BD60079D2E7 /* FancyProjectActiveToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F26B2B2A5BD60079D2E7 /* FancyProjectActiveToggle.swift */; }; 5334F26E2B2A5CC50079D2E7 /* FancyLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F26D2B2A5CC50079D2E7 /* FancyLabel.swift */; }; 5334F2702B2B83190079D2E7 /* FancyColourPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F26F2B2B83190079D2E7 /* FancyColourPicker.swift */; }; + 5334F2722B2B95240079D2E7 /* FancyJobActiveToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F2712B2B95240079D2E7 /* FancyJobActiveToggle.swift */; }; + 5334F2742B2B958D0079D2E7 /* FancyJobSredToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5334F2732B2B958D0079D2E7 /* FancyJobSredToggle.swift */; }; 5335A5AE296CFF83000051B1 /* FileHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5335A5AD296CFF83000051B1 /* FileHelper.swift */; }; 5335A5B3296D17EB000051B1 /* TaskDashboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5335A5B2296D17EB000051B1 /* TaskDashboard.swift */; }; 5335A5B5296D1FA7000051B1 /* TaskView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5335A5B4296D1FA7000051B1 /* TaskView.swift */; }; @@ -251,9 +253,11 @@ 5334F2652B28FA520079D2E7 /* Outline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Outline.swift; sourceTree = ""; }; 5334F2672B2963B60079D2E7 /* StringHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringHelper.swift; sourceTree = ""; }; 5334F2692B2A14F90079D2E7 /* ManageOwnedProjects.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManageOwnedProjects.swift; sourceTree = ""; }; - 5334F26B2B2A5BD60079D2E7 /* FancyToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FancyToggle.swift; sourceTree = ""; }; + 5334F26B2B2A5BD60079D2E7 /* FancyProjectActiveToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FancyProjectActiveToggle.swift; sourceTree = ""; }; 5334F26D2B2A5CC50079D2E7 /* FancyLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FancyLabel.swift; sourceTree = ""; }; 5334F26F2B2B83190079D2E7 /* FancyColourPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FancyColourPicker.swift; sourceTree = ""; }; + 5334F2712B2B95240079D2E7 /* FancyJobActiveToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FancyJobActiveToggle.swift; sourceTree = ""; }; + 5334F2732B2B958D0079D2E7 /* FancyJobSredToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FancyJobSredToggle.swift; sourceTree = ""; }; 5335A5AD296CFF83000051B1 /* FileHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileHelper.swift; sourceTree = ""; }; 5335A5B2296D17EB000051B1 /* TaskDashboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskDashboard.swift; sourceTree = ""; }; 5335A5B4296D1FA7000051B1 /* TaskView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskView.swift; sourceTree = ""; }; @@ -852,9 +856,11 @@ 5372C0292A105AA1008CB120 /* FancyChip.swift */, 53FBCC8D2A61D59B00B88539 /* FancyStaticTextField.swift */, 53E202752A81F2E100B4DF70 /* FancyStar.swift */, - 5334F26B2B2A5BD60079D2E7 /* FancyToggle.swift */, + 5334F26B2B2A5BD60079D2E7 /* FancyProjectActiveToggle.swift */, 5334F26D2B2A5CC50079D2E7 /* FancyLabel.swift */, 5334F26F2B2B83190079D2E7 /* FancyColourPicker.swift */, + 5334F2712B2B95240079D2E7 /* FancyJobActiveToggle.swift */, + 5334F2732B2B958D0079D2E7 /* FancyJobSredToggle.swift */, ); path = Fancy; sourceTree = ""; @@ -1249,6 +1255,7 @@ 537628AC29665B4E00DE8ECF /* NoteView.swift in Sources */, 53B0BE8829726400007CB663 /* GenericToolbar.swift in Sources */, 53E24C412A844BC800EB21FD /* EKEvent.swift in Sources */, + 5334F2722B2B95240079D2E7 /* FancyJobActiveToggle.swift in Sources */, 53D5E29A2A85E38A00FE293A /* WidgetLocation.swift in Sources */, 53999C1F29669C4E00125E65 /* NoteCreate.swift in Sources */, 53E202682A802D0900B4DF70 /* ButtonSize.swift in Sources */, @@ -1293,7 +1300,7 @@ 5371BA2B2A7B279800DEEC21 /* NoteViewSidebar.swift in Sources */, 53B0BE90297333C3007CB663 /* ManageProjects.swift in Sources */, 53B0BE8129725B52007CB663 /* CoreDataProjects.swift in Sources */, - 5334F26C2B2A5BD60079D2E7 /* FancyToggle.swift in Sources */, + 5334F26C2B2A5BD60079D2E7 /* FancyProjectActiveToggle.swift in Sources */, 53D5E2982A85A75C00FE293A /* Planning.swift in Sources */, 53967D8629EC7DEB006616A0 /* ViewModeSelector.swift in Sources */, 53152CCC2969453000A14E43 /* DateHelper.swift in Sources */, @@ -1307,6 +1314,7 @@ 53521E54296FBDAE002E7F21 /* CoreDataNoteVersions.swift in Sources */, 53967D8429EC6D14006616A0 /* TodaySettings.swift in Sources */, 531E2F752A140533009CA230 /* CalendarToday.swift in Sources */, + 5334F2742B2B958D0079D2E7 /* FancyJobSredToggle.swift in Sources */, 5326AE982B27FA02009F1349 /* DefaultCompanySidebar.swift in Sources */, 537AEB9F29627DCC00385787 /* LogTable.swift in Sources */, 5335A5AE296CFF83000051B1 /* FileHelper.swift in Sources */, diff --git a/DLPrototype/Views/Jobs/JobView.swift b/DLPrototype/Views/Jobs/JobView.swift index 095ab96e..70fb6bf4 100644 --- a/DLPrototype/Views/Jobs/JobView.swift +++ b/DLPrototype/Views/Jobs/JobView.swift @@ -16,7 +16,7 @@ struct JobView: View { @State private var pName: String = "" @State private var pId: String = "" @State private var url: String = "" - @State private var colour: String = "" + @State private var colour: Color = .clear @State private var alive: Bool = true @State private var shredable: Bool = false @State private var validJob: Bool = false @@ -33,19 +33,14 @@ struct JobView: View { topSpace fieldProjectLink - fieldIsOn - fieldIsShredable FancyTextField(placeholder: "URL", lineLimit: 1, onSubmit: {}, showLabel: true, text: $url) .background(validUrl ? Color.clear : Color.red) FancyTextField(placeholder: "Job ID", lineLimit: 1, onSubmit: {}, showLabel: true, text: $id) .background(validJob ? Color.clear : Color.red) - - - HStack { - FancyRandomJobColourPicker(job: job, colour: $colour) - Spacer() - } + FancyJobActiveToggle(entity: job) + FancyJobSredToggle(entity: job) + FancyColourPicker(initialColour: job.colour ?? Theme.rowColourAsDouble, onChange: {newColour in colour = newColour}) buttonSubmit } @@ -75,52 +70,21 @@ struct JobView: View { @ViewBuilder private var fieldProjectLink: some View { if let project = job.project { - FancyLink( - icon: "folder", - label: "Project: \(project.name!)", - showLabel: true, - colour: Color.fromStored(job.project!.colour ?? Theme.rowColourAsDouble), - destination: AnyView(ProjectView(project: project)), - pageType: .projects, - sidebar: AnyView(ProjectsDashboardSidebar()) - ) - } - } - - @ViewBuilder private var fieldIsOn: some View { - FancyDivider() - - HStack { - Toggle("Job is active", isOn: $alive) -// .onAppear(perform: { -// if job.alive { -// alive = true -// } else { -// alive = false -// } -// -// update() -// }) - Spacer() - } - } - - @ViewBuilder private var fieldIsShredable: some View { - HStack { - Toggle("Eligible for SR&ED", isOn: $shredable) -// .onAppear(perform: { -// if job.shredable { -// shredable = true -// } else { -// shredable = false -// } -// -// update() -// }) - Spacer() + HStack { + FancyLabel(text: "Project") + FancyLink( + icon: "folder", + label: project.name!, + showLabel: true, + colour: Color.fromStored(job.project!.colour ?? Theme.rowColourAsDouble), + destination: AnyView(ProjectView(project: project)), + pageType: .projects, + sidebar: AnyView(ProjectsDashboardSidebar()) + ) + } } } - + @ViewBuilder private var buttonSubmit: some View { HStack { FancyButtonv2( diff --git a/DLPrototype/Views/Projects/ProjectView.swift b/DLPrototype/Views/Projects/ProjectView.swift index 8e4a3b82..dc8440c8 100644 --- a/DLPrototype/Views/Projects/ProjectView.swift +++ b/DLPrototype/Views/Projects/ProjectView.swift @@ -112,7 +112,7 @@ struct ProjectView: View { FancyTextField(placeholder: "Name", lineLimit: 1, onSubmit: update, showLabel: true, text: $name) FancyTextField(placeholder: "Abbreviation", lineLimit: 1, onSubmit: {}, showLabel: true, text: $abbreviation) CompanyPicker(onChange: {company,_ in selectedCompany = company}, selected: project.company != nil ? Int(project.company!.pid) : 0) - FancyToggle(entity: project) + FancyProjectActiveToggle(entity: project) FancyColourPicker(initialColour: project.colour ?? Theme.rowColourAsDouble, onChange: {newColour in colour = newColour}) if let createdAt = created { diff --git a/DLPrototype/Views/Shared/Fancy/FancyJobActiveToggle.swift b/DLPrototype/Views/Shared/Fancy/FancyJobActiveToggle.swift new file mode 100644 index 00000000..8f54cf78 --- /dev/null +++ b/DLPrototype/Views/Shared/Fancy/FancyJobActiveToggle.swift @@ -0,0 +1,41 @@ +// +// FancyJobActiveToggle.swift +// DLPrototype +// +// Created by Ryan Priebe on 2023-12-14. +// Copyright © 2023 YegCollective. All rights reserved. +// + +import SwiftUI + +struct FancyJobActiveToggle: View { + public let entity: Job // TODO: should either be generic or not require a type + public var label: String = "Active" + + @State private var alive: Bool = true + + var body: some View { + HStack { + VStack { + FancyLabel(text: label) + } + HStack { + Toggle(label, isOn: $alive) + Spacer() + } + .padding() + .background(Theme.textBackground) + } + .onAppear(perform: { + if entity.alive { + alive = true + } else { + alive = false + } + + entity.alive = alive + + PersistenceController.shared.save() + }) + } +} diff --git a/DLPrototype/Views/Shared/Fancy/FancyJobSredToggle.swift b/DLPrototype/Views/Shared/Fancy/FancyJobSredToggle.swift new file mode 100644 index 00000000..f7066c1e --- /dev/null +++ b/DLPrototype/Views/Shared/Fancy/FancyJobSredToggle.swift @@ -0,0 +1,41 @@ +// +// FancyJobSredToggle.swift +// DLPrototype +// +// Created by Ryan Priebe on 2023-12-14. +// Copyright © 2023 YegCollective. All rights reserved. +// + +import SwiftUI + +struct FancyJobSredToggle: View { + public let entity: Job // TODO: should either be generic or not require a type + public var label: String = "SR&ED Eligible" + + @State private var shredable: Bool = true + + var body: some View { + HStack { + VStack { + FancyLabel(text: label) + } + HStack { + Toggle(label, isOn: $shredable) + Spacer() + } + .padding() + .background(Theme.textBackground) + } + .onAppear(perform: { + if entity.shredable { + shredable = true + } else { + shredable = false + } + + entity.shredable = shredable + + PersistenceController.shared.save() + }) + } +} diff --git a/DLPrototype/Views/Shared/Fancy/FancyToggle.swift b/DLPrototype/Views/Shared/Fancy/FancyProjectActiveToggle.swift similarity index 95% rename from DLPrototype/Views/Shared/Fancy/FancyToggle.swift rename to DLPrototype/Views/Shared/Fancy/FancyProjectActiveToggle.swift index c05c2696..9ed17ec5 100644 --- a/DLPrototype/Views/Shared/Fancy/FancyToggle.swift +++ b/DLPrototype/Views/Shared/Fancy/FancyProjectActiveToggle.swift @@ -8,7 +8,7 @@ import SwiftUI -struct FancyToggle: View { +struct FancyProjectActiveToggle: View { public let entity: Project // TODO: should either be generic or not require a type public var label: String = "Active" From 34730b173ab2914d54d58ecfac459f57a6dd4c6a Mon Sep 17 00:00:00 2001 From: Ryan Priebe Date: Thu, 14 Dec 2023 13:11:19 -0700 Subject: [PATCH 6/6] bump --- DLPrototype.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DLPrototype.xcodeproj/project.pbxproj b/DLPrototype.xcodeproj/project.pbxproj index 585af616..bb56b5b0 100644 --- a/DLPrototype.xcodeproj/project.pbxproj +++ b/DLPrototype.xcodeproj/project.pbxproj @@ -1506,7 +1506,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 149; + CURRENT_PROJECT_VERSION = 150; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\""; DEVELOPMENT_TEAM = 6DT7L2N5X6; @@ -1541,7 +1541,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 149; + CURRENT_PROJECT_VERSION = 150; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\""; DEVELOPMENT_TEAM = 6DT7L2N5X6;