Skip to content

Commit

Permalink
Merge pull request #269 from aapis/feature/note-dashboard-job-filter
Browse files Browse the repository at this point in the history
Note dashboard now auto-filters to items belonging to current Job, UI/UX updates to Today
  • Loading branch information
aapis authored Oct 5, 2024
2 parents 05e298b + 60f55e9 commit dcbd09b
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 150 deletions.
8 changes: 4 additions & 4 deletions DLPrototype.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 176;
CURRENT_PROJECT_VERSION = 177;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\"";
DEVELOPMENT_TEAM = 6DT7L2N5X6;
Expand All @@ -1804,7 +1804,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.6;
MARKETING_VERSION = 1.6;
MARKETING_VERSION = 1.7;
PRODUCT_BUNDLE_IDENTIFIER = com.yegcollective.DLPrototype;
PRODUCT_NAME = KlockWork.Beta;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
Expand All @@ -1825,7 +1825,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 176;
CURRENT_PROJECT_VERSION = 177;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\"";
DEVELOPMENT_TEAM = 6DT7L2N5X6;
Expand All @@ -1841,7 +1841,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.6;
MARKETING_VERSION = 1.6;
MARKETING_VERSION = 1.7;
PRODUCT_BUNDLE_IDENTIFIER = com.yegcollective.DLPrototype;
PRODUCT_NAME = KlockWork;
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
4 changes: 2 additions & 2 deletions DLPrototype/Helpers/SearchHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public final class SearchHelper {
self.projectBucket = Array(bucket)
}

public init(bucket: FetchedResults<Note>) {
self.noteBucket = Array(bucket)
public init(bucket: [Note]) {
self.noteBucket = bucket
}

public init(bucket: FetchedResults<LogRecord>) {
Expand Down
26 changes: 25 additions & 1 deletion DLPrototype/Models/CoreData/CoreDataNotes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,38 @@ public class CoreDataNotes {

return query(predicate)
}

/// Find notes by Job
/// - Parameter job: Job
/// - Returns: [Note]]
public func find(by job: Job) -> [Note] {
let predicate = NSPredicate(
format: "ANY mJob == %@",
job
)

return query(predicate)
}

/// Find notes by Job
/// - Parameter project: Project
/// - Returns: [Note]
public func find(by project: Project) -> [Note] {
let predicate = NSPredicate(
format: "ANY mJob.project == %@",
project
)

return query(predicate)
}

/// Count up all the jobs referenced for a given day
/// - Parameter date: Date
/// - Returns: Int
public func countByDate(for date: Date) -> Int {
return self.find(for: date).count
}

/// Updates a single NSManagedObject
/// - Parameters:
/// - entity: Note, the target to modify
Expand Down
79 changes: 27 additions & 52 deletions DLPrototype/Views/Entities/Notes/NoteDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,60 +10,20 @@ import Foundation
import SwiftUI

struct NoteDashboard: View {
public var defaultSelectedJob: Job? = nil
public var project: Project? = nil

@StateObject public var jm: CoreDataJob = CoreDataJob(moc: PersistenceController.shared.container.viewContext)

@EnvironmentObject public var nav: Navigation
@EnvironmentObject public var updater: ViewUpdater
@AppStorage("notes.columns") private var numColumns: Int = 3
@AppStorage("notedashboard.listVisible") private var listVisible: Bool = true
@State private var searchText: String = ""
@State private var selected: Int = 0
@State private var showAllNotes: Bool = false

@AppStorage("notes.columns") private var numColumns: Int = 3
@AppStorage("notedashboard.listVisible") private var listVisible: Bool = true

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

@FetchRequest public var notes: FetchedResults<Note>

@State private var notes: [Note] = []
private let page: PageConfiguration.AppPage = .explore
private let eType: PageConfiguration.EntityType = .notes

private var columns: [GridItem] {
return Array(repeating: .init(.flexible(minimum: 100)), count: numColumns)
}

public init(defaultSelectedJob: Job? = nil, project: Project? = nil) {
self.defaultSelectedJob = defaultSelectedJob
self.project = project

let sharedDescriptors = [
NSSortDescriptor(keyPath: \Note.lastUpdate?, ascending: false),
NSSortDescriptor(keyPath: \Note.mJob?.project?.pid, ascending: true),
NSSortDescriptor(keyPath: \Note.mJob?.jid, ascending: true),
NSSortDescriptor(keyPath: \Note.title, ascending: true)
]

let request: NSFetchRequest<Note> = Note.fetchRequest()
request.sortDescriptors = sharedDescriptors

if self.defaultSelectedJob != nil {
let byJobPredicate = NSPredicate(format: "ANY mJob.jid = %f && mJob.project.company.hidden == false", self.defaultSelectedJob!.jid)
let predicates = NSCompoundPredicate(type: NSCompoundPredicate.LogicalType.and, subpredicates: [byJobPredicate])
request.predicate = predicates
} else if self.project != nil {
let byJobPredicate = NSPredicate(format: "ANY mJob.project = %@ && mJob.project.company.hidden == false", self.project!)
let predicates = NSCompoundPredicate(type: NSCompoundPredicate.LogicalType.and, subpredicates: [byJobPredicate])
request.predicate = predicates
} else {
request.predicate = NSPredicate(format: "alive = true && mJob.project.company.hidden == false")
}

_notes = FetchRequest(fetchRequest: request, animation: .easeInOut)
}

var body: some View {
VStack(alignment: .leading) {
VStack(alignment: .leading, spacing: 1) {
Expand Down Expand Up @@ -110,35 +70,50 @@ struct NoteDashboard: View {
.background(.white.opacity(0.2))
.foregroundStyle(.white)

if listVisible {
// TODO: remove!
if listVisible && self.notes.count > 0 {
SearchBar(
text: $searchText,
disabled: false,
placeholder: notes.count > 1 ? "Search \(notes.count) notes" : "Search 1 note"
placeholder: notes.count > 1 ? "Search \(self.notes.count) notes" : "Search 1 note"
)

ScrollView(showsIndicators: false) {
LazyVGrid(columns: columns, alignment: .leading) {
ForEach(filter(notes), id: \.objectID) { note in
LazyVGrid(columns: self.columns, alignment: .leading) {
ForEach(self.filter(self.notes), id: \.objectID) { note in
NoteBlock(note: note)
}
}
}
}

Spacer()
}
.padding()
}
.background(Theme.toolbarColour)
.onAppear(perform: self.actionOnAppear)
.onChange(of: self.nav.session.job) { self.actionOnAppear() }
}
}

extension NoteDashboard {
private func filter(_ notes: FetchedResults<Note>) -> [Note] {
/// Perform a search of note content and meta data
/// - Parameter notes: [Note]
/// - Returns: [Note
private func filter(_ notes: [Note]) -> [Note] {
return SearchHelper(bucket: notes).findInNotes($searchText)
}

/// Onload handler. Find based on appropriate filter entity
/// - Returns: Void
private func actionOnAppear() -> Void {
self.notes = CoreDataNotes(moc: self.nav.moc).alive()

if let stored = self.nav.session.job {
self.notes = CoreDataNotes(moc: self.nav.moc).find(by: stored)
} else if let stored = self.nav.session.project {
self.notes = CoreDataNotes(moc: self.nav.moc).find(by: stored)
}
}
}

extension NoteDashboard {
Expand Down
44 changes: 27 additions & 17 deletions DLPrototype/Views/Entities/Tasks/Column.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Column: View {
public var alignment: Alignment = .leading
public var url: URL?
public var job: Job?
public var show: Bool = true

@Binding public var text: String

Expand All @@ -25,20 +26,22 @@ struct Column: View {
@AppStorage("tigerStriped") private var tigerStriped = false

var body: some View {
Group {
ZStack(alignment: alignment) {
colour
switch type {
case .index:
Index
case .timestamp:
Timestamp
case .extendedTimestamp:
ExtendedTimestamp
case .job:
Job
case .message:
Message
if self.show {
Group {
ZStack(alignment: alignment) {
colour
switch type {
case .index:
Index
case .timestamp:
Timestamp
case .extendedTimestamp:
ExtendedTimestamp
case .job:
Job
case .message:
Message
}
}
}
}
Expand Down Expand Up @@ -86,9 +89,16 @@ struct Column: View {
}

@ViewBuilder private var Index: some View {
Text(text)
.foregroundColor(textColour)
.help(text)
ZStack(alignment: .center) {
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(self.job == self.nav.session.job ? .yellow : Theme.cPurple.opacity(0.8))
.frame(height: 23)
Text(self.text)
.opacity(0.5)
.foregroundStyle((self.job == self.nav.session.job ? Theme.base : .white).opacity(0.55))
.font(.system(.subheadline, design: .monospaced))
}
.padding(6)
}

@ViewBuilder private var Message: some View {
Expand Down
24 changes: 10 additions & 14 deletions DLPrototype/Views/Entities/Today/LogTable/LogTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,18 @@ extension Today.LogTable {
.frame(width: 15)

ForEach(RecordTableColumn.allCases, id: \.self) { column in
// 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)
}
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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum RecordTableColumn: CaseIterable {

var width: CGFloat? {
switch self {
case .index: return 20
case .index: return 45
case .timestamp: return 70
case .extendedTimestamp: return 101
case .job: return 80
Expand All @@ -34,9 +34,7 @@ public enum RecordTableColumn: CaseIterable {
var alignment: Alignment {
switch self {
case .index: return .center
case .timestamp, .extendedTimestamp: return .leading
case .job: return .center
case .message: return .leading
default: return .leading
}
}
}
Loading

0 comments on commit dcbd09b

Please sign in to comment.