Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated table/row UI on Today view #268

Merged
merged 11 commits into from
Oct 5, 2024
8 changes: 7 additions & 1 deletion DLPrototype/Utils/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import SwiftUI

public enum Page {
case dashboard, today, notes, tasks, projects, jobs, companies, planning, terms, definitionDetail, taskDetail, noteDetail, people, peopleDetail
case dashboard, today, notes, tasks, projects, projectDetail, jobs, companies, planning,
terms, definitionDetail, taskDetail, noteDetail, people, peopleDetail


var colour: Color {
switch self {
Expand All @@ -31,6 +33,7 @@ public enum Page {
case .tasks: return "Tasks"
case .notes: return "Notes"
case .projects: return "Projects"
case .projectDetail: return "Project"
case .jobs: return "Jobs"
case .companies: return "Companies"
case .planning: return "Planning"
Expand All @@ -50,6 +53,7 @@ public enum Page {
case .tasks: return nil
case .notes: return nil
case .projects: return nil
case .projectDetail: return .projects
case .jobs: return nil
case .companies: return nil
case .planning: return nil
Expand Down Expand Up @@ -552,6 +556,8 @@ extension Navigation {
HistoryPage(page: .noteDetail, view: AnyView(NoteView()), sidebar: AnyView(NoteCreateSidebar()), title: "Note detail"),
HistoryPage(page: .people, view: AnyView(PeopleDashboard()), sidebar: AnyView(PeopleDashboardSidebar()), title: "People"),
HistoryPage(page: .peopleDetail, view: AnyView(PeopleDetail()), sidebar: AnyView(PeopleDashboardSidebar()), title: "Person"),
HistoryPage(page: .projectDetail, view: AnyView(EmptyView()), sidebar: AnyView(ProjectsDashboardSidebar()), title: "Project"),
HistoryPage(page: .projects, view: AnyView(CompanyDashboard()), sidebar: AnyView(DefaultCompanySidebar()), title: "Projects"),
]

/// A single page representing a page the user navigated to
Expand Down
8 changes: 6 additions & 2 deletions DLPrototype/Views/Entities/Projects/ProjectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import Foundation
import SwiftUI

struct ProjectView: View {
public let project: Project

@State public var project: Project
@State private var name: String = ""
@State private var colour: Color = .clear
@State private var colourChanged: Bool = false
Expand Down Expand Up @@ -521,6 +520,11 @@ extension ProjectView {
}

public func onAppear() -> Void {
if let stored = self.nav.session.project {
self.project = stored
self.nav.session.project = nil
}

allUnOwned = jm.unowned()
name = project.name!
created = project.created!
Expand Down
11 changes: 3 additions & 8 deletions DLPrototype/Views/Entities/Tasks/Column.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,11 @@ struct Column: View {
} label: {
Text(text.replacingOccurrences(of: ".0", with: ""))
.foregroundColor(colour.isBright() ? Color.black : Color.white)
.onHover { inside in
if inside {
NSCursor.pointingHand.push()
} else {
NSCursor.pop()
}
}

.help("Edit job")
}
.buttonStyle(.borderless)
.useDefaultHover({_ in})
.buttonStyle(.plain)
.underline()
}

Expand Down
25 changes: 16 additions & 9 deletions DLPrototype/Views/Entities/Today/Calendar/CalendarToday.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,29 @@ struct CalendarToday: View {
@State private var inProgress: [EKEvent] = []
@State private var upcoming: [EKEvent] = []
@State private var currentBlock: Int = 0
@State private var currentDate: String = ""
@State private var timer: Timer? = nil
@AppStorage("today.startOfDay") public var startOfDay: Int = 9
@AppStorage("today.endOfDay") public var endOfDay: Int = 18

var body: some View {
VStack(alignment: .leading, spacing: 0) {
HStack {
Text("Events for \(currentDate)")
.font(Theme.font)
.padding(5)
Spacer()
ZStack(alignment: .bottom) {
LinearGradient(colors: [Theme.base, .clear], startPoint: .top, endPoint: .bottom)
.opacity(0.6)
.blendMode(.softLight)
.frame(height: 20)
self.page.primaryColour
HStack {
Text("Today's Events")
.padding(6)
.background(Theme.textBackground)
.foregroundStyle(.white)
.clipShape(RoundedRectangle(cornerRadius: 5))
Spacer()
}
.padding(8)
}
.frame(height: 40)
.background(self.page.primaryColour)
Divider().foregroundStyle(.white)

ScrollView(showsIndicators: false) {
HStack(spacing: 0) {
Expand Down Expand Up @@ -114,7 +122,6 @@ struct CalendarToday: View {
private func updateChips() -> Void {
ce.truncate()
currentBlock = Calendar.current.component(.hour, from: Date())
currentDate = Date().formatted(date: .abbreviated, time: .omitted)
inProgress = []
upcoming = []

Expand Down
101 changes: 65 additions & 36 deletions DLPrototype/Views/Entities/Today/LogTable/LogTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension Today {
private var buttons: [ToolbarButton] = []

@EnvironmentObject public var nav: Navigation

var body: some View {
VStack(alignment: .leading, spacing: 0) {
FancyDivider()
Expand All @@ -39,36 +39,58 @@ extension Today {
extension Today.LogTable {
/// Table row headers
struct Headers: View {
static public var required: Set<RecordTableColumn> = [.job, .message]
@EnvironmentObject public var state: Navigation
public var page: PageConfiguration.AppPage
@State private var required: Set<RecordTableColumn> = [.message]
@AppStorage("today.showColumnIndex") public var showColumnIndex: Bool = true
@AppStorage("today.showColumnTimestamp") public var showColumnTimestamp: Bool = true
@AppStorage("today.showColumnExtendedTimestamp") public var showColumnExtendedTimestamp: Bool = true
@AppStorage("today.showColumnJobId") public var showColumnJobId: Bool = true

var body: some View {
GridRow {
// project colour block
HStack(spacing: 0) {
Group {
ZStack {
Theme.subHeaderColour
ZStack(alignment: .top) {
LinearGradient(colors: [Theme.base, .clear], startPoint: .top, endPoint: .bottom)
.opacity(0.6)
.blendMode(.softLight)
self.page.primaryColour.opacity(0.4)
}
}
.frame(width: 5)
.frame(width: 15)

ForEach(RecordTableColumn.allCases, id: \.self) { column in
if Headers.required.contains(column) {
Group {
ZStack(alignment: column.alignment) {
Theme.subHeaderColour
Text(column.name).padding(10)
// Index column content is integrated into the project indicator column so we don't need to add
// another stack for it
if column != .index {
if self.required.contains(column) {
Group {
ZStack(alignment: column.alignment) {
LinearGradient(colors: [Theme.base, .clear], startPoint: .top, endPoint: .bottom)
.opacity(0.6)
.blendMode(.softLight)
self.page.primaryColour.opacity(0.4)
Text(column.name)
.padding(8)
}
}
.frame(width: column.width)
}
.frame(width: column.width)
}
}
}
.font(.caption)
.foregroundStyle(.gray)
}
.frame(height: 40)
.onAppear(perform: self.actionOnAppear)
.onChange(of: self.showColumnIndex) { self.actionOnAppear() }
.onChange(of: self.showColumnTimestamp) { self.actionOnAppear() }
.onChange(of: self.showColumnExtendedTimestamp) { self.actionOnAppear() }
.onChange(of: self.showColumnJobId) { self.actionOnAppear() }
}
}

/// Plaintext conversion of the standard display
struct Plain: View {
public var records: [LogRecord]
Expand All @@ -95,13 +117,16 @@ extension Today.LogTable {

/// Standard display, colour coded list of records
struct Full: View {
@EnvironmentObject public var nav: Navigation
@AppStorage("today.showColumnIndex") public var showColumnIndex: Bool = true
@AppStorage("today.showColumnTimestamp") public var showColumnTimestamp: Bool = true
@AppStorage("today.showColumnExtendedTimestamp") public var showColumnExtendedTimestamp: Bool = true
@AppStorage("today.showColumnJobId") public var showColumnJobId: Bool = true
public var records: [LogRecord]

@EnvironmentObject public var nav: Navigation

var body: some View {
ScrollView(showsIndicators: false) {
VStack(spacing: 1) {
VStack(spacing: 0) {
if records.count > 0 {
ForEach(records, id: \.objectID) { record in
if record.job != nil {
Expand All @@ -115,8 +140,7 @@ extension Today.LogTable {
entry: entry,
index: records.firstIndex(of: record),
colour: Color.fromStored((record.job?.colour) ?? Theme.rowColourAsDouble),
record: record,
viewRequiresColumns: Headers.required
record: record
)
}
}
Expand Down Expand Up @@ -157,12 +181,10 @@ extension Today.LogTable {
}

var Content: some View {
VStack(spacing: 1) {
Group {
ToolbarButtons()
}
.background(self.page.primaryColour)

VStack(spacing: 0) {
ToolbarButtons()
.background(self.page.primaryColour)
Divider().foregroundStyle(.white)
// TODO: fix search
// if nav.session.toolbar.showSearch {
// SearchBar(text: $searchText, disabled: (records.count == 0))
Expand All @@ -171,7 +193,7 @@ extension Today.LogTable {
if nav.session.toolbar.mode == .plain {
Plain(records: records)
} else {
Headers()
Headers(page: self.page)
Full(records: records)
}
}
Expand All @@ -188,10 +210,9 @@ extension Today.LogTable {
var body: some View {
ScrollView(showsIndicators: false) {
VStack(spacing: 1) {
Group {
ToolbarButtons()
}
.background(self.page.primaryColour)
ToolbarButtons()
.background(self.page.primaryColour)
Divider().foregroundStyle(.white)

if records.count > 0 {
ForEach(grouped) {group in group}
Expand All @@ -218,11 +239,10 @@ extension Today.LogTable {
@State private var records: [LogRecord] = []

var body: some View {
VStack(spacing: 1) {
Group {
ToolbarButtons()
}
.background(self.page.primaryColour)
VStack(spacing: 0) {
ToolbarButtons()
.background(self.page.primaryColour)
Divider().foregroundStyle(.white)

// TODO: fix search
// if nav.session.toolbar.showSearch {
Expand All @@ -232,7 +252,7 @@ extension Today.LogTable {
if nav.session.toolbar.mode == .plain {
Plain(records: records)
} else {
Headers()
Headers(page: self.page)
Full(records: records)
}
}
Expand All @@ -255,6 +275,15 @@ extension Today.LogTable {
}

// MARK: method definitions
extension Today.LogTable.Headers {
private func actionOnAppear() -> Void {
if self.showColumnIndex { self.required.insert(.index) } else { self.required.remove(.index)}
if self.showColumnTimestamp { self.required.insert(.timestamp) } else { self.required.remove(.timestamp)}
if self.showColumnExtendedTimestamp { self.required.insert(.extendedTimestamp) } else { self.required.remove(.extendedTimestamp)}
if self.showColumnJobId { self.required.insert(.job) } else { self.required.remove(.job)}
}
}

extension Today.LogTable.TabContent.Chronologic {
private func findRecords() -> Void {
DispatchQueue.with(background: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public enum RecordTableColumn: CaseIterable {

var width: CGFloat? {
switch self {
case .index: return 50
case .timestamp, .extendedTimestamp: return 101
case .index: return 20
case .timestamp: return 70
case .extendedTimestamp: return 101
case .job: return 80
case .message: return nil
}
Expand All @@ -23,7 +24,7 @@ public enum RecordTableColumn: CaseIterable {
var name: String {
switch self {
case .index: return ""
case .timestamp: return "Date"
case .timestamp: return "Time"
case .extendedTimestamp: return "Timestamp"
case .job: return "Job"
case .message: return "Message"
Expand All @@ -33,7 +34,7 @@ public enum RecordTableColumn: CaseIterable {
var alignment: Alignment {
switch self {
case .index: return .center
case .timestamp, .extendedTimestamp: return .center
case .timestamp, .extendedTimestamp: return .leading
case .job: return .center
case .message: return .leading
}
Expand Down
Loading