Skip to content

Commit

Permalink
Merge pull request #222 from aapis/feature/hide-company
Browse files Browse the repository at this point in the history
New feature: Hide company (and all associated data)
  • Loading branch information
aapis authored May 11, 2024
2 parents 93d1f20 + 28057a3 commit 88aba54
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 50 deletions.
4 changes: 2 additions & 2 deletions DLPrototype.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 162;
CURRENT_PROJECT_VERSION = 163;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\"";
DEVELOPMENT_TEAM = 6DT7L2N5X6;
Expand Down Expand Up @@ -1659,7 +1659,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 162;
CURRENT_PROJECT_VERSION = 163;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\"";
DEVELOPMENT_TEAM = 6DT7L2N5X6;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22522" systemVersion="23B81" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22757" systemVersion="23E224" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="BannedWord" representedClassName="BannedWord" syncable="YES" codeGenerationType="class">
<attribute name="created" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
Expand All @@ -21,6 +21,7 @@
<attribute name="alive" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES"/>
<attribute name="colour" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" customClassName="[Double]"/>
<attribute name="createdDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="hidden" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="isDefault" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="lastUpdate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
Expand Down
4 changes: 2 additions & 2 deletions DLPrototype/Helpers/SearchHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public final class SearchHelper {
}
}

public func findInCompanies(_ searchText: Binding<String>) -> [Company] {
public func findInCompanies(_ searchText: Binding<String>, allowHidden: Bool = false) -> [Company] {
return companyBucket.filter {
matches(searchText, fields: [$0.name!])
matches(searchText, fields: [$0.name!]) && $0.hidden == allowHidden
}
}

Expand Down
8 changes: 4 additions & 4 deletions DLPrototype/Models/CoreData/CoreDataCompanies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public class CoreDataCompanies: ObservableObject {
]

let fetch: NSFetchRequest<Company> = Company.fetchRequest()
fetch.predicate = NSPredicate(format: "alive == true")
fetch.predicate = NSPredicate(format: "alive == true && hidden == false")
fetch.sortDescriptors = descriptors

return FetchRequest(fetchRequest: fetch, animation: .easeInOut)
}

public func byPid(_ id: Int) -> Company? {
let predicate = NSPredicate(
format: "pid = %d",
format: "pid = %d && hidden == false",
id as CVarArg
)

Expand All @@ -50,15 +50,15 @@ public class CoreDataCompanies: ObservableObject {

public func alive() -> [Company] {
let predicate = NSPredicate(
format: "alive = true"
format: "alive = true && hidden == false"
)

return query(predicate)
}

public func all() -> [Company] {
let predicate = NSPredicate(
format: "name != nil"
format: "name != nil && hidden == false"
)

return query(predicate)
Expand Down
4 changes: 2 additions & 2 deletions DLPrototype/Models/CoreData/CoreDataJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CoreDataJob: ObservableObject {
]

let fetch: NSFetchRequest<Job> = Job.fetchRequest()
fetch.predicate = NSPredicate(format: "alive == true && lastUpdate != nil && project != nil")
fetch.predicate = NSPredicate(format: "alive == true && lastUpdate != nil && project != nil && project.company.hidden == false")
fetch.sortDescriptors = descriptors
fetch.fetchLimit = 10

Expand All @@ -32,7 +32,7 @@ public class CoreDataJob: ObservableObject {

static public func fetchAll(limit: Int? = nil) -> FetchRequest<Job> {
let fetch: NSFetchRequest<Job> = Job.fetchRequest()
fetch.predicate = NSPredicate(format: "alive == true && project != nil && project.alive == true")
fetch.predicate = NSPredicate(format: "alive == true && project != nil && project.alive == true && project.company.hidden == false")
fetch.sortDescriptors = [
NSSortDescriptor(keyPath: \Job.project?, ascending: false),
NSSortDescriptor(keyPath: \Job.jid, ascending: false)
Expand Down
4 changes: 2 additions & 2 deletions DLPrototype/Models/CoreData/CoreDataNotes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ public class CoreDataNotes {

let fetch: NSFetchRequest<Note> = Note.fetchRequest()
if favouritesOnly {
fetch.predicate = NSPredicate(format: "alive == true && starred == true")
fetch.predicate = NSPredicate(format: "alive == true && starred == true && mJob.project.company.hidden == false")
} else {
fetch.predicate = NSPredicate(format: "alive == true && mJob != nil")
fetch.predicate = NSPredicate(format: "alive == true && mJob != nil && mJob.project.company.hidden == false")
}
fetch.sortDescriptors = descriptors
fetch.fetchLimit = 1000
Expand Down
16 changes: 8 additions & 8 deletions DLPrototype/Models/CoreData/CoreDataRecords.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class CoreDataRecords: ObservableObject {
let (start, end) = DateHelper.startAndEndOf(date)
let fetch: NSFetchRequest<LogRecord> = LogRecord.fetchRequest()
fetch.predicate = NSPredicate(
format: "alive == true && (timestamp > %@ && timestamp <= %@)",
format: "alive == true && (timestamp > %@ && timestamp <= %@) && job.project.company.hidden == false",
start as CVarArg,
end as CVarArg
)
Expand All @@ -85,7 +85,7 @@ public class CoreDataRecords: ObservableObject {
let (start, end) = DateHelper.startAndEndOf(date)
let fetch: NSFetchRequest<LogRecord> = LogRecord.fetchRequest()
fetch.predicate = NSPredicate(
format: "@message.count > 0 && alive == true && (timestamp > %@ && timestamp <= %@)",
format: "@message.count > 0 && alive == true && (timestamp > %@ && timestamp <= %@) && job.project.company.hidden == false",
start as CVarArg,
end as CVarArg
)
Expand All @@ -107,7 +107,7 @@ public class CoreDataRecords: ObservableObject {
let date = DateHelper.daysPast(14)

fetch.predicate = NSPredicate(
format: "alive == true && timestamp >= %@",
format: "(alive == true && timestamp >= %@) && job.project.company.hidden == false",
date
)

Expand Down Expand Up @@ -156,7 +156,7 @@ public class CoreDataRecords: ObservableObject {
let cutoff = DateHelper.daysPast(numWeeks * 7)

let predicate = NSPredicate(
format: "timestamp > %@",
format: "timestamp > %@ && job.project.company.hidden == false",
cutoff
)

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

public func recent(_ start: CVarArg, _ end: CVarArg) -> [LogRecord] {
let predicate = NSPredicate(
format: "timestamp > %@ && timestamp <= %@",
format: "(timestamp > %@ && timestamp <= %@) && job.project.company.hidden == false",
start,
end
)
Expand Down Expand Up @@ -203,7 +203,7 @@ public class CoreDataRecords: ObservableObject {

public func countAll() -> Int {
let predicate = NSPredicate(
format: "alive == true"
format: "alive == true && job.project.company.hidden == false"
)

return count(predicate)
Expand All @@ -212,7 +212,7 @@ public class CoreDataRecords: ObservableObject {
public func forDate(_ date: Date) -> [LogRecord] {
let (start, end) = DateHelper.startAndEndOf(date)
let predicate = NSPredicate(
format: "alive == true && timestamp > %@ && timestamp <= %@",
format: "(alive == true && timestamp > %@ && timestamp <= %@) && job.project.company.hidden == false",
start as CVarArg,
end as CVarArg
)
Expand All @@ -224,7 +224,7 @@ public class CoreDataRecords: ObservableObject {
if let d = date {
let (start, end) = DateHelper.startAndEndOf(d)
let predicate = NSPredicate(
format: "timestamp > %@ && timestamp <= %@",
format: "(timestamp > %@ && timestamp <= %@) && job.project.company.hidden == false",
start as CVarArg,
end as CVarArg
)
Expand Down
10 changes: 5 additions & 5 deletions DLPrototype/Models/CoreData/CoreDataTasks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CoreDataTasks {

static private var availableTasks: NSPredicate {
NSPredicate(
format: "completedDate == nil && cancelledDate == nil && owner.project.alive == true"
format: "completedDate == nil && cancelledDate == nil && owner.project.alive == true && owner.project.company.hidden == false"
)
}

Expand Down Expand Up @@ -54,8 +54,8 @@ public class CoreDataTasks {
}

// create compound predicate that includes INCOMPLETE and JOBRELEVANT predicates
let jobRelevancyPredicate = NSPredicate(format: "owner.jid IN %@ && owner.alive == true", ownerJobs)
let jobRelevancyPredicate = NSPredicate(format: "owner.jid IN %@ && owner.alive == true && owner.project.company.hidden == false", ownerJobs)

filterPredicate = NSCompoundPredicate(
type: NSCompoundPredicate.LogicalType.and,
subpredicates: [CoreDataTasks.availableTasks, jobRelevancyPredicate]
Expand Down Expand Up @@ -117,7 +117,7 @@ public class CoreDataTasks {

public func all() -> [LogTask] {
let predicate = NSPredicate(
format: "created <= %@",
format: "created <= %@ && owner.project.company.hidden == false",
Date() as CVarArg
)

Expand All @@ -126,7 +126,7 @@ public class CoreDataTasks {

public func countAll() -> Int {
let predicate = NSPredicate(
format: "created <= %@",
format: "created <= %@ && owner.project.company.hidden == false",
Date() as CVarArg
)

Expand Down
2 changes: 1 addition & 1 deletion DLPrototype/Utils/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ extension Navigation {
.padding(5)

switch field.type {
case .boolean: FancyToggle(label: self.field.label, value: self.field.value as! Bool, onChange: self.onChangeToggle)
case .boolean: FancyToggle(label: self.field.label, value: self.field.value as! Bool, showLabel: true, onChange: self.onChangeToggle)
case .colour: FancyColourPicker(initialColour: self.field.value as! [Double], onChange: self.onChangeColour, showLabel: false)
case .editor: FancyTextField(placeholder: self.field.label, lineLimit: 10, fieldStatus: self.field.status, text: $newValue)
case .projectDropdown: ProjectPickerUsing(onChangeLarge: onChangeProjectDropdown, size: .large, defaultSelection: Int((self.field.value as! Project).pid), displayName: $newValue)
Expand Down
19 changes: 17 additions & 2 deletions DLPrototype/Views/Entities/Companies/CompanyDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftUI
struct CompanyDashboard: View {
@State private var searchText: String = ""
@State private var selected: Int = 0
@State private var allowHidden: Bool = false

@AppStorage("notes.columns") private var numColumns: Int = 3
@AppStorage("general.defaultCompany") public var defaultCompany: Int = 0
Expand All @@ -27,8 +28,17 @@ struct CompanyDashboard: View {
VStack(alignment: .leading) {
VStack(alignment: .leading) {
HStack {
Title(text: "Projects & Companies")
Title(text: "Companies & Projects")
Spacer()
FancyButtonv2(
text: "Show hidden",
action: showHidden,
icon: "eye.slash",
transparent: true,
showLabel: false,
showIcon: true,
type: .clear
)
FancyButtonv2(
text: "New Company",
action: {},
Expand Down Expand Up @@ -85,7 +95,12 @@ extension CompanyDashboard {
}

private func filter(_ companies: FetchedResults<Company>) -> [Company] {
return SearchHelper(bucket: companies).findInCompanies($searchText)
return SearchHelper(bucket: companies).findInCompanies($searchText, allowHidden: allowHidden)
}

private func showHidden() -> Void {

allowHidden.toggle()
}
}

Expand Down
18 changes: 15 additions & 3 deletions DLPrototype/Views/Entities/Companies/CompanyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct CompanyView: View {
@State private var created: Date? = nil
@State private var updated: Date? = nil
@State private var colour: Color = .clear
@State private var hidden: Bool = false
@State private var isDeleteAlertShowing: Bool = false
@State private var tabs: [ToolbarButton] = []

Expand All @@ -35,6 +36,10 @@ struct CompanyView: View {

FancyTextField(placeholder: "Legal name", lineLimit: 1, onSubmit: {}, showLabel: true, text: $name)
FancyTextField(placeholder: "Abbreviation", lineLimit: 1, onSubmit: {}, showLabel: true, text: $abbreviation)
HStack {
FancyLabel(text: "Hidden")
FancyBoundToggle(label: "Hidden", value: $hidden, showLabel: false, onChange: self.onChangeToggle)
}
FancyColourPicker(initialColour: company.colour ?? Theme.rowColourAsDouble, onChange: {newColour in colour = newColour})

if let created = created {
Expand Down Expand Up @@ -103,9 +108,8 @@ struct CompanyView: View {
.onChange(of: name) { newName in
abbreviation = StringHelper.abbreviate(newName)

Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { timer in
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { _ in
self.save()
timer.invalidate()
}
}
.onChange(of: colour) { newColour in
Expand All @@ -132,6 +136,7 @@ extension CompanyView {
abbreviation = company.abbreviation!
created = company.createdDate!
colour = Color.fromStored(company.colour ?? Theme.rowColourAsDouble)
hidden = company.hidden

if let updatedAt = company.lastUpdate {
updated = updatedAt
Expand All @@ -145,8 +150,10 @@ extension CompanyView {
company.abbreviation = abbreviation
company.lastUpdate = Date()
company.colour = colour.toStored()
company.hidden = hidden

// TODO: possibly unnecessary, but sometimes projects disown themselves and this may fix it
// @TODO: possibly unnecessary, but sometimes projects disown themselves and this may fix it
// @TODO: many months later, this did not fix it
var projs: Set<Project> = []
for p in projects { projs.insert(p)}
company.projects = NSSet(set: projs)
Expand Down Expand Up @@ -211,4 +218,9 @@ extension CompanyView {
)
]
}

private func onChangeToggle(value: Bool) -> Void {
company.hidden = value
PersistenceController.shared.save()
}
}
10 changes: 5 additions & 5 deletions DLPrototype/Views/Find/FindDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ extension FindDashboard {

init(_ text: String) {
let rr: NSFetchRequest<LogRecord> = LogRecord.fetchRequest()
rr.predicate = NSPredicate(format: "message CONTAINS[cd] %@", text)
rr.predicate = NSPredicate(format: "message CONTAINS[cd] %@ && job.project.company.hidden == false", text)
rr.sortDescriptors = [
NSSortDescriptor(keyPath: \LogRecord.timestamp, ascending: false)
]
Expand Down Expand Up @@ -436,7 +436,7 @@ extension FindDashboard {

init(_ text: String) {
let req: NSFetchRequest<Note> = Note.fetchRequest()
req.predicate = NSPredicate(format: "(body CONTAINS[cd] %@ OR title CONTAINS[cd] %@) AND alive = true", text, text)
req.predicate = NSPredicate(format: "(body CONTAINS[cd] %@ OR title CONTAINS[cd] %@) AND alive = true && mJob.project.company.hidden == false", text, text)
req.sortDescriptors = [
NSSortDescriptor(keyPath: \Note.postedDate, ascending: false)
]
Expand Down Expand Up @@ -477,7 +477,7 @@ extension FindDashboard {

init(_ text: String) {
let tr: NSFetchRequest<LogTask> = LogTask.fetchRequest()
tr.predicate = NSPredicate(format: "content CONTAINS[c] %@", text)
tr.predicate = NSPredicate(format: "content CONTAINS[c] %@ && owner.project.company.hidden == false", text)
tr.sortDescriptors = [
NSSortDescriptor(keyPath: \LogTask.created, ascending: false)
]
Expand Down Expand Up @@ -518,7 +518,7 @@ extension FindDashboard {

init(_ text: String) {
let pr: NSFetchRequest<Project> = Project.fetchRequest()
pr.predicate = NSPredicate(format: "name CONTAINS[c] %@ AND alive = true", text)
pr.predicate = NSPredicate(format: "name CONTAINS[c] %@ AND alive = true && company.hidden == false", text)
pr.sortDescriptors = [
NSSortDescriptor(keyPath: \Project.created, ascending: false)
]
Expand Down Expand Up @@ -559,7 +559,7 @@ extension FindDashboard {

init(_ text: String) {
let jr: NSFetchRequest<Job> = Job.fetchRequest()
jr.predicate = NSPredicate(format: "(uri CONTAINS[c] %@ OR jid.stringValue BEGINSWITH %@ OR overview CONTAINS[c] %@ OR title CONTAINS[c] %@) AND alive = true", text, text, text, text)
jr.predicate = NSPredicate(format: "(uri CONTAINS[c] %@ OR jid.stringValue BEGINSWITH %@ OR overview CONTAINS[c] %@ OR title CONTAINS[c] %@) AND alive = true && project.company.hidden == false", text, text, text, text)
jr.sortDescriptors = [
NSSortDescriptor(keyPath: \Job.created, ascending: false)
]
Expand Down
Loading

0 comments on commit 88aba54

Please sign in to comment.