Skip to content

Commit

Permalink
add project colour codes to all data lists. added job row colour to
Browse files Browse the repository at this point in the history
notes dashboard
  • Loading branch information
aapis committed Feb 7, 2023
1 parent 213a841 commit 33bc40f
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 68 deletions.
4 changes: 2 additions & 2 deletions DLPrototype.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 72;
CURRENT_PROJECT_VERSION = 73;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\"";
DEVELOPMENT_TEAM = 6DT7L2N5X6;
Expand Down Expand Up @@ -936,7 +936,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 72;
CURRENT_PROJECT_VERSION = 73;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\"";
DEVELOPMENT_TEAM = 6DT7L2N5X6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
</entity>
<entity name="Project" representedClassName="Project" syncable="YES" codeGenerationType="class">
<attribute name="alive" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES"/>
<attribute name="colour" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" customClassName="[Double]"/>
<attribute name="created" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="lastUpdate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
Expand Down
115 changes: 80 additions & 35 deletions DLPrototype/Views/Notes/NoteDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,47 +105,18 @@ struct NoteDashboard: View {
.frame(width: 100)
}
}
.frame(height: 40)
.frame(height: 46)

ScrollView {
VStack(alignment: .leading, spacing: 1) {
ForEach(filter(notes)) { note in
GridRow {
HStack(spacing: 1) {
Group {
ZStack(alignment: .leading) {
Theme.rowColour
FancyTextLink(text: note.title!, destination: AnyView(NoteView(note: note)))
}
}

Group {
ZStack {
Theme.rowColour

if note.starred {
Image(systemName: "star.fill")
.padding()
}
}
}
.frame(width: 100)

Group {
ZStack {
Theme.rowColour
Text("\(note.versions!.count)")
.padding()
}
}
.frame(width: 100)

Group {
ZStack {
(note.alive ? Theme.rowStatusGreen : Color.red.opacity(0.2))
}
}
.frame(width: 100)
nProject(note)
nNote(note)
nStar(note)
nVersions(note)
nAlive(note)
}
}
}
Expand All @@ -156,6 +127,80 @@ struct NoteDashboard: View {
}
}

@ViewBuilder private func nProject(_ note: Note) -> some View {
Group {
HStack(spacing: 0) {
ZStack(alignment: .leading) {
if note.job != nil {
Color.fromStored(note.job!.project!.colour ?? Theme.rowColourAsDouble)
} else {
Theme.rowColour
}
}
}
}
.frame(width: 5)
}

@ViewBuilder private func nNote(_ note: Note) -> some View {
Group {
ZStack(alignment: .leading) {
if note.job != nil {
Color.fromStored(note.job!.colour ?? Theme.rowColourAsDouble)
} else {
Theme.rowColour
}

FancyTextLink(text: note.title!, destination: AnyView(NoteView(note: note)), fgColour: (note.job != nil ? (Color.fromStored(note.job!.colour ?? Theme.rowColourAsDouble).isBright() ? Color.black : Color.white) : Color.white))
}
}
}

@ViewBuilder private func nStar(_ note: Note) -> some View {
Group {
ZStack {
if note.job != nil {
Color.fromStored(note.job!.colour ?? Theme.rowColourAsDouble)
} else {
Theme.rowColour
}

if note.starred {
Image(systemName: "star.fill")
.padding()
.foregroundColor(note.job != nil ? (Color.fromStored(note.job!.colour ?? Theme.rowColourAsDouble).isBright() ? Color.black : Color.white) : Color.white)
}
}
}
.frame(width: 100)
}

@ViewBuilder private func nVersions(_ note: Note) -> some View {
Group {
ZStack {
if note.job != nil {
Color.fromStored(note.job!.colour ?? Theme.rowColourAsDouble)
} else {
Theme.rowColour
}

Text("\(note.versions!.count)")
.padding()
.foregroundColor(note.job != nil ? (Color.fromStored(note.job!.colour ?? Theme.rowColourAsDouble).isBright() ? Color.black : Color.white) : Color.white)
}
}
.frame(width: 100)
}

@ViewBuilder private func nAlive(_ note: Note) -> some View {
Group {
ZStack {
(note.alive ? Theme.rowStatusGreen : Color.red.opacity(0.2))
}
}
.frame(width: 5)
}

private func filter(_ notes: FetchedResults<Note>) -> [Note] {
return SearchHelper(bucket: notes).findInNotes($searchText)
}
Expand Down
42 changes: 42 additions & 0 deletions DLPrototype/Views/Projects/ProjectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct ProjectView: View {
public var project: Project

@State private var name: String = ""
@State private var colour: String = ""
@State private var created: Date?
@State private var lastUpdate: Date?
@State private var alive: Bool = true
Expand Down Expand Up @@ -61,6 +62,10 @@ struct ProjectView: View {
} else {
alive = false
}

project.alive = alive

PersistenceController.shared.save()
})
}

Expand Down Expand Up @@ -100,6 +105,32 @@ struct ProjectView: View {
FancyTextField(placeholder: "Project name", lineLimit: 1, onSubmit: update, text: $name)
FancyDivider()

HStack(spacing: 0) {
Rectangle()
.frame(width: 15)
.background(Color.fromStored(project.colour!))
.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!).description.debugDescription
})

FancyButton(text: "Regenerate colour", action: regenerateColour, icon: "arrow.counterclockwise", showLabel: false)
.padding(.leading)
}.frame(height: 40)

FancyDivider()

toolbar
}

Expand Down Expand Up @@ -304,6 +335,15 @@ struct ProjectView: View {
}
}

private func regenerateColour() -> Void {
let rndColour = Color.randomStorable()
colour = Color.fromStored(rndColour).description.debugDescription
project.colour = rndColour

PersistenceController.shared.save()
updater.update()
}

private func createToolbar() -> Void {
// TODO: apply this pattern to Today view
buttons = [
Expand All @@ -327,6 +367,7 @@ struct ProjectView: View {
project.jobs = []
project.alive = alive
project.lastUpdate = Date()
project.colour = Color.randomStorable()
lastUpdate = project.lastUpdate!

saveSelectedJobs()
Expand Down Expand Up @@ -450,6 +491,7 @@ struct ProjectView: View {
for job in existingJobs {
project.removeFromJobs(job)
}
lastUpdate = project.lastUpdate ?? Date()

for job in selectedJobs {
project.addToJobs(job)
Expand Down
92 changes: 62 additions & 30 deletions DLPrototype/Views/Projects/ProjectsDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ struct ProjectsDashboard: View {
Group {
ZStack(alignment: .leading) {
Theme.headerColour
Text("Owned Jobs")
Text("# Jobs")
.padding()
}
}
.frame(width: 100)

Group {
ZStack(alignment: .leading) {
Expand All @@ -84,45 +85,76 @@ struct ProjectsDashboard: View {
.padding()
}
}
.frame(width: 100)
}
}
.frame(height: 40)
.frame(height: 46)

ScrollView {
VStack(alignment: .leading, spacing: 1) {
ForEach(filter(projects)) { project in
GridRow {
HStack(spacing: 1) {
Group {
ZStack(alignment: .leading) {
Theme.rowColour
FancyTextLink(text: project.name!, destination: AnyView(ProjectView(project: project).environmentObject(jobModel)))
}
}

Group {
ZStack(alignment: .leading) {
Theme.rowColour
Text("\(project.jobs!.count)")
.padding()
}
}

Group {
ZStack(alignment: .leading) {
(project.alive ? Theme.rowStatusGreen : Color.red.opacity(0.2))
}
}
}
}
projectsView
}
.font(Theme.font)
}
}

@ViewBuilder
var projectsView: some View {
ScrollView {
VStack(alignment: .leading, spacing: 1) {
ForEach(filter(projects)) { project in
GridRow {
HStack(spacing: 1) {
pColour(project)
pLink(project)
pJob(project)
pAlive(project)
}
}
}
}
.font(Theme.font)
}
}

// swift compiler is fucking dogshit and "can't typecheck this expression",
// so here are some columns defined as functions because you can't pass args to a property
@ViewBuilder private func pColour(_ project: Project) -> some View {
Group {
ZStack(alignment: .leading) {
Color.fromStored(project.colour ?? Theme.rowColourAsDouble)
}
}
.frame(width: 5)
}

@ViewBuilder private func pLink(_ project: Project) -> some View {
Group {
ZStack(alignment: .leading) {
Theme.rowColour
FancyTextLink(text: project.name!, destination: AnyView(ProjectView(project: project).environmentObject(jobModel)))
}
}
}

@ViewBuilder private func pJob(_ project: Project) -> some View {
Group {
ZStack {
Theme.rowColour
Text("\(project.jobs!.count)")
.padding()
}
}
.frame(width: 100)
}

@ViewBuilder private func pAlive(_ project: Project) -> some View {
Group {
ZStack(alignment: .leading) {
(project.alive ? Theme.rowStatusGreen : Color.red.opacity(0.2))
}
}
.frame(width: 100)
}


private func filter(_ projects: FetchedResults<Project>) -> [Project] {
return SearchHelper(bucket: projects).findInProjects($searchText)
}
Expand Down
18 changes: 18 additions & 0 deletions DLPrototype/Views/Tasks/TaskView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct TaskView: View {

var body: some View {
HStack(spacing: 0) {
tProject()
GridRow {
Group {
ZStack {
Expand Down Expand Up @@ -111,6 +112,23 @@ struct TaskView: View {
}
}

@ViewBuilder private func tProject() -> some View {
Group {
HStack(spacing: 0) {
ZStack(alignment: .leading) {
if task.owner != nil {
Color.fromStored(task.owner!.project!.colour ?? Theme.rowColourAsDouble)
} else {
Theme.rowColour
}
}
Divider()
.foregroundColor(Theme.toolbarColour)
}
}
.frame(width: 5)
}

private func colourize() -> Color {
if colourizeRow == false {
return (task.completedDate == nil ? Theme.rowColour : Theme.rowStatusGreen)
Expand Down
Loading

0 comments on commit 33bc40f

Please sign in to comment.