Skip to content

Commit

Permalink
Merge pull request #206 from aapis/feature/inspector-context-widget
Browse files Browse the repository at this point in the history
Inspector context widget
  • Loading branch information
aapis authored Dec 30, 2023
2 parents 5f8a80b + 6ff9b49 commit 59bc40c
Show file tree
Hide file tree
Showing 33 changed files with 1,769 additions and 2,083 deletions.
72 changes: 30 additions & 42 deletions DLPrototype.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions DLPrototype/DLPrototype.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct DLPrototype: App {
private let persistenceController = PersistenceController.shared
@StateObject public var updater: ViewUpdater = ViewUpdater()
@StateObject public var nav: Navigation = Navigation()
@StateObject public var ce: CoreDataCalendarEvent = CoreDataCalendarEvent(moc: PersistenceController.shared.container.viewContext)

@State private var searching: Bool = false

Expand All @@ -25,7 +24,6 @@ struct DLPrototype: App {
.environment(\.managedObjectContext, persistenceController.container.viewContext)
.environmentObject(updater)
.environmentObject(nav)
.environmentObject(ce)
.onAppear(perform: onAppear)
.defaultAppStorage(.standard)
.onChange(of: scenePhase) { phase in
Expand All @@ -46,7 +44,6 @@ struct DLPrototype: App {
Settings {
SettingsView()
.environment(\.managedObjectContext, persistenceController.container.viewContext)
.environmentObject(ce)
.environmentObject(nav)
}

Expand Down
2 changes: 1 addition & 1 deletion DLPrototype/Enums/WidgetLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
import SwiftUI

public enum WidgetLocation {
case sidebar, content, header, taskbar
case sidebar, content, header, taskbar, inspector
}
30 changes: 25 additions & 5 deletions DLPrototype/Helpers/DateHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
import Foundation
import SwiftUI

public struct IdentifiableDay: Identifiable, Equatable {
public struct IdentifiableDay: Identifiable, Equatable, Hashable {
public var id: UUID = UUID()
public var string: String = ""
public var date: Date?
public var recordCount: Int = 0
}

public struct DateBounds {
public var upper: Date
public var lower: Date
}

final public class DateHelper {
// Returns string like 2020-06-11 representing a date, for use in filtering
static public func thisAm() -> CVarArg {
Expand Down Expand Up @@ -99,8 +104,8 @@ final public class DateHelper {
for i in 0...numDays {
var components = DateComponents()
components.day = -(1*i)
let computedDay = Calendar.current.date(byAdding: components, to: Date())
let computedDay = Calendar.autoupdatingCurrent.date(byAdding: components, to: Date())

if computedDay != nil {
let fmt = DateFormatter()
fmt.dateFormat = dateFormat
Expand All @@ -126,7 +131,7 @@ final public class DateHelper {
components.day = -(1*i)


if let computedDay = Calendar.current.date(byAdding: components, to: Date()) {
if let computedDay = Calendar.autoupdatingCurrent.date(byAdding: components, to: Date()) {
let fmt = DateFormatter()
fmt.dateFormat = dateFormat
fmt.timeZone = TimeZone.autoupdatingCurrent
Expand Down Expand Up @@ -181,7 +186,22 @@ final public class DateHelper {
Calendar.autoupdatingCurrent.date(byAdding: components, to: start)!
)
}


static public func bounds(_ date: Date) -> DateBounds {
let start = Calendar.autoupdatingCurrent.startOfDay(for: date)
var sComponents = DateComponents()
sComponents.day = -7

let end = Calendar.autoupdatingCurrent.startOfDay(for: date)
var eComponents = DateComponents()
sComponents.day = +7

return DateBounds(
upper: Calendar.autoupdatingCurrent.date(byAdding: sComponents, to: start)!,
lower: Calendar.autoupdatingCurrent.date(byAdding: eComponents, to: end)!
)
}

static public func dayAtStartAndEndOfMonth() -> (CVarArg, CVarArg)? {
let calendar = Calendar.autoupdatingCurrent
let today = Date()
Expand Down
11 changes: 8 additions & 3 deletions DLPrototype/Models/CoreData/CoreDataRecords.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,12 @@ public class CoreDataRecords: ObservableObject {

private func exportableGroupedRecordsAsString(_ records: [LogRecord]) -> (String, [Intersection], [Project], [Job]) {
var buffer = ""
let groupedRecords = Dictionary(grouping: records, by: {$0.job}).sorted(by: {$0.key!.jid > $1.key!.jid})
let groupedRecords = Dictionary(grouping: records, by: {$0.job}).sorted(by: {
if $0.key != nil && $1.key != nil {
return $0.key!.jid > $1.key!.jid
}
return false
})
var projects: [Project] = []
var jobs: [Job] = []

Expand Down Expand Up @@ -440,7 +445,7 @@ public class CoreDataRecords: ObservableObject {

var results: [LogRecord] = []
let fetch: NSFetchRequest<LogRecord> = LogRecord.fetchRequest()
fetch.sortDescriptors = [NSSortDescriptor(keyPath: \LogRecord.timestamp, ascending: true)]
fetch.sortDescriptors = [NSSortDescriptor(keyPath: \LogRecord.timestamp, ascending: false)]
fetch.predicate = predicate
fetch.returnsDistinctResults = true

Expand All @@ -460,7 +465,7 @@ public class CoreDataRecords: ObservableObject {

var count = 0
let fetch: NSFetchRequest<LogRecord> = LogRecord.fetchRequest()
fetch.sortDescriptors = [NSSortDescriptor(keyPath: \LogRecord.timestamp, ascending: true)]
fetch.sortDescriptors = [NSSortDescriptor(keyPath: \LogRecord.timestamp, ascending: false)]
fetch.predicate = predicate
fetch.returnsDistinctResults = true

Expand Down
109 changes: 0 additions & 109 deletions DLPrototype/Models/LogRecords.swift

This file was deleted.

4 changes: 2 additions & 2 deletions DLPrototype/Utils/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public enum PageGroup: Hashable {
}

public class Navigation: Identifiable, ObservableObject {
public var id: UUID = UUID()
public let id: UUID = UUID()

@Published public var moc: NSManagedObjectContext = PersistenceController.shared.container.viewContext
@Published public var view: AnyView? = AnyView(Dashboard())
Expand Down Expand Up @@ -157,9 +157,9 @@ public class Navigation: Identifiable, ObservableObject {
self.setView(hp.view)
self.setParent(page)
self.setSidebar(hp.sidebar)
self.setTitle(hp.title)

self.history.push(hp: hp)
self.session.search.cancel()
}

public func reset() -> Void {
Expand Down
18 changes: 1 addition & 17 deletions DLPrototype/Views/Companies/CompanyDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ struct CompanyDashboard: View {
@AppStorage("general.defaultCompany") public var defaultCompany: Int = 0

@Environment(\.managedObjectContext) var moc
@EnvironmentObject public var updater: ViewUpdater

@FetchRequest public var companies: FetchedResults<Company>

Expand Down Expand Up @@ -47,26 +46,15 @@ struct CompanyDashboard: View {
sidebar: AnyView(DefaultCompanySidebar())
)
}

About()

SearchBar(
text: $searchText,
disabled: false,
placeholder: companies.count > 1 ? "Search \(companies.count) companies" : "Search 1 company"
)

FancyDivider()
recent

Spacer()
}
.padding()
.id(updater.ids["companies.dashboard"])
}
.background(Theme.toolbarColour)
.onChange(of: defaultCompany) { _ in
actionOnAppear()
}
}

@ViewBuilder private var recent: some View {
Expand Down Expand Up @@ -99,10 +87,6 @@ extension CompanyDashboard {
private func filter(_ companies: FetchedResults<Company>) -> [Company] {
return SearchHelper(bucket: companies).findInCompanies($searchText)
}

private func actionOnAppear() -> Void {
updater.updateOne("companies.dashboard")
}
}

extension CompanyDashboard {
Expand Down
18 changes: 18 additions & 0 deletions DLPrototype/Views/Companies/Sidebars/DefaultCompanySidebar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI

struct DefaultCompanySidebar: View {
@State private var tabs: [ToolbarButton] = []
@State private var searching: Bool = false

@EnvironmentObject public var nav: Navigation

Expand Down Expand Up @@ -39,6 +40,23 @@ extension DefaultCompanySidebar {
),
contents: AnyView(OutlineWidget())
),
ToolbarButton(
id: 1,
helpText: "Search",
label: AnyView(
HStack {
Image(systemName: "magnifyingglass").padding(.leading)
Text("Search")
}
),
contents: AnyView(
VStack(alignment: .leading) {
FindDashboard(searching: $searching, location: .sidebar)
}
.padding(8)
.background(Theme.base.opacity(0.2))
)
)
]
}
}
4 changes: 2 additions & 2 deletions DLPrototype/Views/Dashboard/Dashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ struct Dashboard: View {
@Environment(\.managedObjectContext) var moc
@EnvironmentObject public var nav: Navigation
@EnvironmentObject public var crm: CoreDataRecords
@EnvironmentObject public var ce: CoreDataCalendarEvent
@StateObject public var ce: CoreDataCalendarEvent = CoreDataCalendarEvent(moc: PersistenceController.shared.container.viewContext)
@EnvironmentObject public var updater: ViewUpdater

var body: some View {
VStack(alignment: .leading, spacing: 0) {
Header()
.environmentObject(ce)
.environmentObject(updater)

VStack(alignment: .leading, spacing: 0) {
Expand All @@ -40,7 +41,6 @@ struct Dashboard: View {
if !searching {
Widgets()
.environmentObject(crm)
.environmentObject(ce)
}
}
.font(Theme.font)
Expand Down
Loading

0 comments on commit 59bc40c

Please sign in to comment.