Skip to content

Commit

Permalink
Merge pull request #317 from aapis/feature/1.14/explore-data-widget-f…
Browse files Browse the repository at this point in the history
…eature-complete

New entity navigator, UI/UX updates & bugfixes
  • Loading branch information
aapis authored Oct 28, 2024
2 parents 2646ed0 + 11e5e2a commit 44d40de
Show file tree
Hide file tree
Showing 33 changed files with 1,060 additions and 762 deletions.
15 changes: 15 additions & 0 deletions KWCore/Sources/Extensions/StringProtocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// StringProtocol.swift
// KlockWork
//
// Created by Ryan Priebe on 2024-10-28.
// Copyright © 2024 YegCollective. All rights reserved.
//

import SwiftUI

extension StringProtocol {
// Thanks: https://stackoverflow.com/a/28288340
public var firstUppercased: String { prefix(1).uppercased() + dropFirst() }
public var firstCapitalized: String { prefix(1).capitalized + dropFirst() }
}
12 changes: 8 additions & 4 deletions KWCore/Sources/Query/CoreDataRecords.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,18 @@ public class CoreDataRecords: ObservableObject {
return count(predicate)
}

public func forDate(_ date: Date) -> [LogRecord] {
public func forDate(_ date: Date, sort: NSSortDescriptor? = nil) -> [LogRecord] {
let (start, end) = DateHelper.startAndEndOf(date)
let predicate = NSPredicate(
format: "(alive == true && timestamp > %@ && timestamp <= %@) && job.project.company.hidden == false",
start as CVarArg,
end as CVarArg
)


if sort != nil {
return query(predicate, sort: [sort!])
}

return query(predicate)
}

Expand Down Expand Up @@ -695,12 +699,12 @@ public class CoreDataRecords: ObservableObject {
return record
}

private func query(_ predicate: NSPredicate) -> [LogRecord] {
private func query(_ predicate: NSPredicate, sort: [NSSortDescriptor] = [NSSortDescriptor(keyPath: \LogRecord.timestamp, ascending: false)]) -> [LogRecord] {
lock.lock()

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

Expand Down
81 changes: 81 additions & 0 deletions KWCore/Sources/UI/WidgetLibrary/WidgetLibrary.Blocks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// WidgetLibrary.Blocks.swift
// KlockWork
//
// Created by Ryan Priebe on 2024-10-28.
// Copyright © 2024 YegCollective. All rights reserved.
//

import SwiftUI
import KWCore

extension WidgetLibrary.UI {
public struct Blocks {
struct Definition: View {
@EnvironmentObject public var state: Navigation
public var definition: TaxonomyTermDefinitions
@State private var isHighlighted: Bool = false

var body: some View {
Button {
self.state.session.job = self.definition.job
self.state.session.project = self.state.session.job?.project
self.state.session.company = self.state.session.project?.company
self.state.session.definition = self.definition
self.state.to(.definitionDetail)
} label: {
HStack(alignment: .top, spacing: 10) {
Text(self.definition.definition ?? "Error: Missing definition")
Spacer()
}
.padding(8)
.background(self.definition.job?.backgroundColor ?? Theme.rowColour)
.foregroundStyle((self.definition.job?.backgroundColor ?? Theme.rowColour).isBright() ? Theme.base : Theme.lightWhite)
}
.buttonStyle(.plain)
.useDefaultHover({ hover in self.isHighlighted = hover})
}
}

struct Icon: View, Identifiable {
@EnvironmentObject private var state: Navigation
@AppStorage("widget.navigator.viewModeIndex") private var viewModeIndex: Int = 0
public var id: UUID = UUID()
public var type: EType
public var text: String
public var colour: Color
@State private var isHighlighted: Bool = false

var body: some View {
VStack(alignment: .center, spacing: 0) {
ZStack(alignment: .center) {
(self.viewModeIndex == 0 ? Color.gray.opacity(self.isHighlighted ? 1 : 0.7) : self.colour.opacity(self.isHighlighted ? 1 : 0.7))
VStack(alignment: .center, spacing: 0) {
(self.isHighlighted ? self.type.selectedIcon : self.type.icon)
.symbolRenderingMode(.hierarchical)
.font(.largeTitle)
// .foregroundStyle(self.viewModeIndex == 0 ? self.colour : self.colour.isBright() ? Theme.base : .white)
.foregroundStyle(self.viewModeIndex == 0 ? self.colour : .white)
}
Spacer()
}
.frame(height: 65)

ZStack(alignment: .center) {
(self.isHighlighted ? Color.yellow : Theme.textBackground)
VStack(alignment: .center, spacing: 0) {
Text(self.text)
.font(.system(.title3, design: .monospaced))
.foregroundStyle(self.isHighlighted ? Theme.base : .gray)
}
.padding([.leading, .trailing], 4)
}
.frame(height: 25)
}
.frame(width: 65)
.clipShape(.rect(cornerRadius: 5))
.useDefaultHover({ hover in self.isHighlighted = hover })
}
}
}
}
Loading

0 comments on commit 44d40de

Please sign in to comment.