From 08527bd90db3f1e4ff495e78818771973beaacc3 Mon Sep 17 00:00:00 2001 From: Ryan Priebe Date: Tue, 15 Oct 2024 12:13:33 -0600 Subject: [PATCH 1/3] bugfix: adding new jobs to the plan didn't refresh the view --- KlockWork/Views/Planning/Tabs/Planning.Today.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/KlockWork/Views/Planning/Tabs/Planning.Today.swift b/KlockWork/Views/Planning/Tabs/Planning.Today.swift index 17ccb305..238b4b3a 100644 --- a/KlockWork/Views/Planning/Tabs/Planning.Today.swift +++ b/KlockWork/Views/Planning/Tabs/Planning.Today.swift @@ -12,13 +12,13 @@ import KWCore extension Planning { struct Today: View { @EnvironmentObject public var nav: Navigation - @EnvironmentObject public var updater: ViewUpdater + @State private var jobs: Set = [] var body: some View { VStack(alignment: .leading, spacing: 1) { Menu() ScrollView(.vertical, showsIndicators: false) { - let jobs = Array(nav.planning.jobs).sorted(by: {$0.jid > $1.jid}) + let jobs = self.jobs.sorted(by: {$0.title ?? $0.jid.string > $1.title ?? $1.jid.string}) if jobs.count > 0 { ForEach(jobs, id: \.objectID) { job in VStack(spacing: 1) { @@ -36,14 +36,16 @@ extension Planning { } } } - .onAppear(perform: actionOnAppear) - .id(updater.get("planning.daily")) + .onAppear(perform: self.actionOnAppear) + .onChange(of: self.nav.planning.jobs) { self.actionOnAppear() } } } } extension Planning.Today { + /// Onload handler. Sets view state (jobs) + /// - Returns: Void private func actionOnAppear() -> Void { - + self.jobs = self.nav.planning.jobs } } From d1eeaceb666992d7f967b3cb368b3ad10dbf5f16 Mon Sep 17 00:00:00 2001 From: Ryan Priebe Date: Tue, 15 Oct 2024 12:28:39 -0600 Subject: [PATCH 2/3] hide companies not included in the plan --- KWCore/Sources/Query/CoreDataCompanies.swift | 37 ++++++++++++++++--- .../AppSidebar/Widgets/UnifiedSidebar.swift | 7 +++- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/KWCore/Sources/Query/CoreDataCompanies.swift b/KWCore/Sources/Query/CoreDataCompanies.swift index 3abec813..054ab133 100644 --- a/KWCore/Sources/Query/CoreDataCompanies.swift +++ b/KWCore/Sources/Query/CoreDataCompanies.swift @@ -157,13 +157,38 @@ public class CoreDataCompanies: ObservableObject { /// Fetch request to find all items /// - Returns: FetchRequest - public func all(allowKilled: Bool = false) -> [Company] { - let predicate = NSPredicate( - format: !allowKilled ? "createdDate < %@" : "alive == true && createdDate < %@", - Date() as CVarArg - ) + public func all(allowKilled: Bool = false, allowPlanMembersOnly: Bool = false, planMembers: Set) -> [Company] { + if allowPlanMembersOnly { + var subpredicates: [NSPredicate] = [] + + // Add alive check if required + if !allowKilled { + subpredicates.append( + NSPredicate(format: "alive == true") + ) + } - return query(predicate) + // Add plan members to query + for member in planMembers { + subpredicates.append( + NSPredicate(format: "name == %@", member.name!) + ) + } + + let filterPredicate = NSCompoundPredicate( + type: NSCompoundPredicate.LogicalType.or, + subpredicates: subpredicates + ) + + return query(filterPredicate) + } else { + let predicate = NSPredicate( + format: !allowKilled ? "createdDate < %@" : "alive == true && createdDate < %@", + Date() as CVarArg + ) + + return query(predicate) + } } /// Retreive all companies by pid diff --git a/KlockWork/Views/Shared/AppSidebar/Widgets/UnifiedSidebar.swift b/KlockWork/Views/Shared/AppSidebar/Widgets/UnifiedSidebar.swift index f4f60e4f..679c3705 100644 --- a/KlockWork/Views/Shared/AppSidebar/Widgets/UnifiedSidebar.swift +++ b/KlockWork/Views/Shared/AppSidebar/Widgets/UnifiedSidebar.swift @@ -45,6 +45,7 @@ struct UnifiedSidebar { } .onAppear(perform: self.actionOnAppear) .onChange(of: self.showPublished) { self.actionOnAppear() } + .onChange(of: self.state.session.gif) { self.actionOnAppear() } } } @@ -605,7 +606,11 @@ extension UnifiedSidebar.Widget { /// Onload handler. Finds companies /// - Returns: Void private func actionOnAppear() -> Void { - self.companies = CoreDataCompanies(moc: self.state.moc).all(allowKilled: self.showPublished) + self.companies = CoreDataCompanies(moc: self.state.moc).all( + allowKilled: self.showPublished, + allowPlanMembersOnly: self.state.session.gif == .focus, + planMembers: self.state.planning.companies + ) } } From 41972600ea6105cf2ada09d63cca32f780c5e57f Mon Sep 17 00:00:00 2001 From: Ryan Priebe Date: Tue, 15 Oct 2024 12:38:49 -0600 Subject: [PATCH 3/3] hide companies, projects and jobs that are not members of the plan when GIF is in focus mode --- .../AppSidebar/Widgets/UnifiedSidebar.swift | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/KlockWork/Views/Shared/AppSidebar/Widgets/UnifiedSidebar.swift b/KlockWork/Views/Shared/AppSidebar/Widgets/UnifiedSidebar.swift index 679c3705..58199f7a 100644 --- a/KlockWork/Views/Shared/AppSidebar/Widgets/UnifiedSidebar.swift +++ b/KlockWork/Views/Shared/AppSidebar/Widgets/UnifiedSidebar.swift @@ -103,8 +103,14 @@ struct UnifiedSidebar { .blendMode(.softLight) VStack(alignment: .leading, spacing: 0) { ForEach((self.entity.projects?.allObjects as? [Project] ?? []).sorted(by: {$0.created! > $1.created!}), id: \.objectID) { project in - if !showPublished || project.alive { - SingleProject(entity: project) + if self.state.session.gif == .focus { + if self.state.planning.projects.contains(project) && (!showPublished || project.alive) { + SingleProject(entity: project) + } + } else { + if !showPublished || project.alive { + SingleProject(entity: project) + } } } @@ -119,6 +125,7 @@ struct UnifiedSidebar { .foregroundStyle(self.fgColour) .onAppear(perform: self.actionOnAppear) .onChange(of: self.state.session.company) { self.actionOnChangeEntity() } + .onChange(of: self.state.session.gif) { self.actionOnAppear() } .onChange(of: self.isPresented) { // Group is minimized if self.isPresented == false { @@ -177,8 +184,14 @@ struct UnifiedSidebar { .blendMode(.softLight) VStack(alignment: .leading, spacing: 0) { ForEach((self.entity.jobs?.allObjects as? [Job] ?? []).sorted(by: {$0.created ?? Date() > $1.created ?? Date()}), id: \.objectID) { job in - if !showPublished || job.alive { - SingleJob(entity: job) + if self.state.session.gif == .focus { + if self.state.planning.jobs.contains(job) && (!showPublished || job.alive) { + SingleJob(entity: job) + } + } else { + if !showPublished || job.alive { + SingleJob(entity: job) + } } } }