Skip to content

Commit

Permalink
Merge pull request #263 from aapis/bugfix/resource-widget-links
Browse files Browse the repository at this point in the history
Bug fixes: 1.4 launch issues
  • Loading branch information
aapis authored Oct 3, 2024
2 parents f7a008f + 4eec9b8 commit ff4c68f
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 138 deletions.
8 changes: 4 additions & 4 deletions DLPrototype.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 173;
CURRENT_PROJECT_VERSION = 174;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\"";
DEVELOPMENT_TEAM = 6DT7L2N5X6;
Expand All @@ -1772,7 +1772,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.6;
MARKETING_VERSION = 1.4;
MARKETING_VERSION = 1.5;
PRODUCT_BUNDLE_IDENTIFIER = com.yegcollective.DLPrototype;
PRODUCT_NAME = KlockWork.Beta;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
Expand All @@ -1793,7 +1793,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 173;
CURRENT_PROJECT_VERSION = 174;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\"";
DEVELOPMENT_TEAM = 6DT7L2N5X6;
Expand All @@ -1809,7 +1809,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.6;
MARKETING_VERSION = 1.4;
MARKETING_VERSION = 1.5;
PRODUCT_BUNDLE_IDENTIFIER = com.yegcollective.DLPrototype;
PRODUCT_NAME = KlockWork;
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
7 changes: 6 additions & 1 deletion DLPrototype/Utils/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ extension Navigation {
var project: Project?
var note: Note?
var plan: Plan?
var task: LogTask?
var company: Company?
var record: LogRecord?
var term: TaxonomyTerm?
var definition: TaxonomyTermDefinitions?
var date: Date = Date()
var idate: IdentifiableDay = IdentifiableDay()
var gif: PlanningState.GlobalInterfaceFilter = .normal
Expand Down Expand Up @@ -570,7 +575,7 @@ extension Navigation {
HistoryPage(page: .terms, view: AnyView(TermsDashboard()), sidebar: AnyView(TermsDashboardSidebar()), title: "Terms"),
HistoryPage(page: .definitionDetail, view: AnyView(DefinitionDetail()), sidebar: AnyView(TermsDashboardSidebar()), title: "Definition detail"),
HistoryPage(page: .taskDetail, view: AnyView(EmptyView()), sidebar: AnyView(TermsDashboardSidebar()), title: "Task detail"),
HistoryPage(page: .noteDetail, view: AnyView(NoteCreate()), sidebar: AnyView(NoteCreateSidebar()), title: "Note detail"),
HistoryPage(page: .noteDetail, view: AnyView(NoteView()), sidebar: AnyView(NoteCreateSidebar()), title: "Note detail"),
]

/// A single page representing a page the user navigated to
Expand Down
11 changes: 10 additions & 1 deletion DLPrototype/Views/Entities/Jobs/JobDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ struct JobExplorer: View {
}

public struct JobViewRedux: View {
public var job: Job? = nil
@State public var job: Job? = nil
private var fields: [Navigation.Forms.Field] { job != nil ? job!.fields : [] }
private let columnSplit: [Navigation.Forms.Field.LayoutType] = [.date, .projectDropdown, .colour]
private var columns: [GridItem] {
Expand Down Expand Up @@ -291,6 +291,7 @@ struct JobExplorer: View {
.padding(8)
}
}
.onAppear(perform: self.actionOnAppear)
}

struct SaveMessage: View {
Expand All @@ -313,6 +314,14 @@ struct JobExplorer: View {
}

extension JobExplorer.JobViewRedux {
/// Onload handler. Sets job to session resource if available
/// - Returns: Void
private func actionOnAppear() -> Void {
if let stored = self.nav.session.job {
self.job = stored
}
}

/// Deletes the current Job
/// - Returns: Void
private func triggerDelete() -> Void {
Expand Down
208 changes: 113 additions & 95 deletions DLPrototype/Views/Entities/Notes/NoteView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import SwiftUI

struct NoteView: View {
public var note: Note
public var moc: NSManagedObjectContext
@EnvironmentObject public var state: Navigation
@State public var note: Note?

@State private var title: String = ""
@State private var content: String = ""
@State private var lastUpdate: Date?
Expand All @@ -27,7 +27,7 @@ struct NoteView: View {
@State private var isShareAlertVisible: Bool = false

private var jobs: [Job] {
CoreDataJob(moc: moc).all()
CoreDataJob(moc: self.state.moc).all()
}

private var pickerItems: [CustomPickerItem] {
Expand All @@ -41,13 +41,16 @@ struct NoteView: View {
}

private var versions: [NoteVersion] {
CoreDataNoteVersions(moc: moc).by(id: note.id!)
if let id = note?.id {
return CoreDataNoteVersions(moc: self.state.moc).by(id: id)
}

return []
}

public var body: some View {
NoteView.Detail(
note: note,
moc: moc,
ref: self,
jobs: jobs,
title: $title,
Expand All @@ -64,13 +67,12 @@ struct NoteView: View {
)
}

public init(note: Note, moc: NSManagedObjectContext) {
public init(note: Note? = nil) {
self.note = note
self.moc = moc
self.title = self.note.title ?? ""
self.content = self.note.body ?? ""
self.lastUpdate = self.note.lastUpdate
self.star = self.note.starred
self.title = self.note?.title ?? ""
self.content = self.note?.body ?? ""
self.lastUpdate = self.note?.lastUpdate
self.star = self.note?.starred
}

// TODO: should not be part of this view
Expand All @@ -89,11 +91,11 @@ struct NoteView: View {

extension NoteView {
public struct Detail: View {
public var note: Note
public var moc: NSManagedObjectContext
@EnvironmentObject public var state: Navigation
@State public var note: Note?
public var ref: NoteView
public var jobs: [Job]

@Binding public var title: String
@Binding public var content: String
@Binding public var lastUpdate: Date?
Expand Down Expand Up @@ -144,7 +146,7 @@ extension NoteView {
.disabled(disableNextButton)

FancyButtonv2(
text: "Share \(note.title!)",
text: "Share \(note?.title ?? "_NO_TITLE")",
action: share,
icon: "square.and.arrow.up",
showLabel: false
Expand All @@ -154,7 +156,7 @@ extension NoteView {
}
}

if note.starred {
if star == true {
FancyButtonv2(text: "Un-favourite", action: starred, icon: "star.fill", showLabel: false, type: .star)
.keyboardShortcut("+", modifiers: .command)
} else {
Expand Down Expand Up @@ -207,113 +209,129 @@ extension NoteView {
}

public func previousVersion() -> Void {
let all = CoreDataNoteVersions(moc: moc).by(id: note.id!)

if currentVersion > 0 {
disableNextButton = false
// change text fields
let prev = all[currentVersion - 1]
title = prev.title!
content = prev.content!
lastUpdate = prev.created!

if currentVersion == noteVersions.count {
CoreDataNoteVersions(moc: moc).from(note)
if self.note != nil {
let all = CoreDataNoteVersions(moc: self.state.moc).by(id: note!.id!)

if currentVersion > 0 {
disableNextButton = false
// change text fields
let prev = all[currentVersion - 1]
title = prev.title!
content = prev.content!
lastUpdate = prev.created!

if currentVersion == noteVersions.count {
CoreDataNoteVersions(moc: self.state.moc).from(note!)
}

currentVersion -= 1
} else {
disablePreviousButton = true
}

currentVersion -= 1
} else {
disablePreviousButton = true
}
}

public func nextVersion() -> Void {
let all = CoreDataNoteVersions(moc: moc).by(id: note.id!)

if currentVersion < noteVersions.count {
disablePreviousButton = false

let next = all[currentVersion + 1]
title = next.title!
content = next.content!
lastUpdate = next.created!

currentVersion += 1
} else {
disableNextButton = true
if self.note != nil {
let all = CoreDataNoteVersions(moc: self.state.moc).by(id: note!.id!)

if currentVersion < noteVersions.count {
disablePreviousButton = false

let next = all[currentVersion + 1]
title = next.title!
content = next.content!
lastUpdate = next.created!

currentVersion += 1
} else {
disableNextButton = true
}
}
}



private func starred() -> Void {
note.starred.toggle()
note?.starred.toggle()

update()
}

public func update() -> Void {
note.title = title // TODO: REMOVE
note.body = content // TODO: REMOVE
note.lastUpdate = Date()
lastUpdate = note.lastUpdate
note.mJob = selectedJob
note.alive = true

CoreDataNoteVersions(moc: moc).from(note)

noteVersions = CoreDataNoteVersions(moc: moc).by(id: note.id!)
currentVersion = noteVersions.count

PersistenceController.shared.save()
if note != nil {
note!.title = title // TODO: REMOVE
note!.body = content // TODO: REMOVE
note!.lastUpdate = Date()
lastUpdate = note!.lastUpdate
note!.mJob = selectedJob
note!.alive = true

CoreDataNoteVersions(moc: self.state.moc).from(note!)

noteVersions = CoreDataNoteVersions(moc: self.state.moc).by(id: note!.id!)
currentVersion = noteVersions.count

PersistenceController.shared.save()
}
}

public func delete() -> Void {
note.alive = false
note?.alive = false

PersistenceController.shared.save()
}

private func hardDelete() -> Void {
delete() // soft delete
moc.delete(note)

PersistenceController.shared.save()
if self.note != nil {
delete() // soft delete
self.state.moc.delete(note!)

PersistenceController.shared.save()
}
}

public func createBindings() -> Void {
title = note.title!
content = note.body!
selectedJob = note.mJob ?? nil
lastUpdate = note.lastUpdate ?? nil
noteVersions = CoreDataNoteVersions(moc: moc).by(id: note.id!)
currentVersion = noteVersions.count
autoSelectedJobId = selectedJob?.jid.string ?? ""
if let stored = self.state.session.note {
self.note = stored
}

if self.note != nil {
selectedJob = note!.mJob ?? nil
lastUpdate = note!.lastUpdate ?? nil
noteVersions = CoreDataNoteVersions(moc: self.state.moc).by(id: note!.id!)
currentVersion = noteVersions.count
autoSelectedJobId = selectedJob?.jid.string ?? ""
self.content = noteVersions.last?.content ?? ""
self.title = noteVersions.last?.title ?? ""
}
}

private func share() -> Void {
isShareAlertVisible = true

var exportableNote = ""

if let title = note.title {
exportableNote += "\(title)\n"
}

if let job = note.mJob {
if let uri = job.uri {
exportableNote += "Job ID \(job.jid.string) - \(uri.absoluteString)\n"
} else {
exportableNote += "Job ID \(job.jid.string)\n"
if self.note != nil {
isShareAlertVisible = true

var exportableNote = ""

if let title = note!.title {
exportableNote += "\(title)\n"
}

if let job = note!.mJob {
if let uri = job.uri {
exportableNote += "Job ID \(job.jid.string) - \(uri.absoluteString)\n"
} else {
exportableNote += "Job ID \(job.jid.string)\n"
}
}

if let body = note!.body {
exportableNote += body
}

if !exportableNote.isEmpty {
ClipboardHelper.copy(exportableNote)
}
}

if let body = note.body {
exportableNote += body
}

if !exportableNote.isEmpty {
ClipboardHelper.copy(exportableNote)
}
}
}
Expand Down
Loading

0 comments on commit ff4c68f

Please sign in to comment.