Created
November 5, 2021 08:41
-
-
Save odrobnik/03acd7d908540466b78599b89d7a14ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Combine | |
import ProoficsSDK | |
import SwiftUI | |
class BundleViewModel: ObservableObject | |
{ | |
@Published var title: String = "" | |
@Published var subtitle: String? | |
@Published var status: BundleStatus = .New | |
let url: URL? | |
let bundle: ProoficsSDK.Bundle | |
var cancellables = [AnyCancellable]() | |
init(bundle: ProoficsSDK.Bundle) | |
{ | |
self.bundle = bundle | |
self.status = bundle.status | |
self.url = bundle.thumbnail?.url | |
cancellables.append(bundle.publisher(for: \.statusString).sink { newValue in | |
self.status = BundleStatus(rawValue: newValue)! | |
}) | |
bundle.publisher(for: \.displayTitle).assign(to: &$title) | |
bundle.publisher(for: \.jobName).assign(to: &$subtitle) | |
} | |
} | |
extension BundleViewModel: Identifiable | |
{ | |
var id: String | |
{ | |
return bundle.objectID! | |
} | |
} | |
extension ProoficsSDK.Bundle | |
{ | |
@objc var displayTitle: String | |
{ | |
var string = "" | |
if let number = jobNumber | |
{ | |
string += number | |
} | |
if let batch = batchNumber, !batch.isEmpty | |
{ | |
string += " / Batch: " + batch | |
} | |
return string | |
} | |
@objc dynamic var statusString: String | |
{ | |
get { | |
return status.rawValue | |
} | |
set { | |
status = BundleStatus(rawValue: newValue)! | |
} | |
} | |
} | |
open class Bundle: Entity | |
{ | |
open var status: BundleStatus = BundleStatus.New | |
{ | |
willSet | |
{ | |
willChangeValue(forKey: "statusString") | |
} | |
didSet { | |
didChangeValue(forKey: "statusString") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment