Skip to content

Commit

Permalink
Add eventManager support (#33)
Browse files Browse the repository at this point in the history
* Add eventManager support

* Separate modes for EventManager and SeatingChart
  • Loading branch information
Ericarman authored Oct 14, 2024
1 parent b644fcd commit c6c014d
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 94 deletions.
8 changes: 8 additions & 0 deletions seatsio-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
4EDEAFCD0B067C46CCA35CBA /* ConfigChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EDEAFCFBA22E63057491CF3 /* ConfigChange.swift */; };
9EDB593A2BB19BFA00C6A0D1 /* SeatParent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EDB59392BB19BFA00C6A0D1 /* SeatParent.swift */; };
B5E85DF8A7019A1AA0D8D4DA /* SeatsioObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E851D6B4FC0C586C2A0F67 /* SeatsioObject.swift */; };
FE12BD1D2CB6B23F002A845A /* SeatsioConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE12BD1C2CB6B23F002A845A /* SeatsioConfig.swift */; };
FE12BD1F2CB6B25D002A845A /* EventManagerConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE12BD1E2CB6B25D002A845A /* EventManagerConfig.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -82,6 +84,8 @@
9EDB59392BB19BFA00C6A0D1 /* SeatParent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeatParent.swift; sourceTree = "<group>"; };
A6A88E8FAE60849004A8E8E6 /* Pods-seatsio-ios.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-seatsio-ios.release.xcconfig"; path = "Target Support Files/Pods-seatsio-ios/Pods-seatsio-ios.release.xcconfig"; sourceTree = "<group>"; };
B5E851D6B4FC0C586C2A0F67 /* SeatsioObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SeatsioObject.swift; sourceTree = "<group>"; };
FE12BD1C2CB6B23F002A845A /* SeatsioConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeatsioConfig.swift; sourceTree = "<group>"; };
FE12BD1E2CB6B25D002A845A /* EventManagerConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventManagerConfig.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -147,7 +151,9 @@
4EDEA099F1693CFC065B3A62 /* Pricing.swift */,
4EDEAF2C91ADC8500B3CA854 /* ReportBySelectability.swift */,
4EDEA6F7303F7AB3A435DCEB /* SeatingChart.swift */,
FE12BD1C2CB6B23F002A845A /* SeatsioConfig.swift */,
4EDEA52AC21D4D9AAFDB2E46 /* SeatingChartConfig.swift */,
FE12BD1E2CB6B25D002A845A /* EventManagerConfig.swift */,
4EDEAECDF76F62994037BC78 /* SeatingChartSample.swift */,
9EDB59392BB19BFA00C6A0D1 /* SeatParent.swift */,
B5E851D6B4FC0C586C2A0F67 /* SeatsioObject.swift */,
Expand Down Expand Up @@ -267,7 +273,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FE12BD1F2CB6B25D002A845A /* EventManagerConfig.swift in Sources */,
4EA4AD6622A86F590030E989 /* SeatsioWebView.swift in Sources */,
FE12BD1D2CB6B23F002A845A /* SeatsioConfig.swift in Sources */,
B5E85DF8A7019A1AA0D8D4DA /* SeatsioObject.swift in Sources */,
4EDEA979B40A137B93B88522 /* SeatingChartConfig.swift in Sources */,
4EDEA677E5530F12E5E04D0C /* Pricing.swift in Sources */,
Expand Down
219 changes: 219 additions & 0 deletions seatsio-ios/EventManagerConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
import Foundation

public enum EventManagerMode: String, Encodable {
case manageObjectStatuses
case manageForSaleConfig
case manageTableBooking
case manageChannels
case manageCategories
case select
case filterSections
case `static`
}

struct EventManagerConfigParams: Encodable {
var secretKey: String?
var event: String?
var events: [String]?
var messages: [String: String]?
var mode: EventManagerMode?
var language: String?
var colors: Colors?
var colorScheme: String?
var loading: String?
var style: Style?
var stylePreset: String?
var objectColor: String?
var extraConfig: AnyEncodable?
let divId = "chart"
}

public final class EventManagerConfig: SeatsioConfig {

private(set) var params = EventManagerConfigParams()
public private(set) var priceFormatter: ((Float) -> String)?
public private(set) var tooltipInfo: ((SeatsioObject) -> String)?
public private(set) var onSelectionValid: (() -> Void)?
public private(set) var onSelectionInvalid: (([SelectionValidatorType]) -> Void)?
public private(set) var onObjectSelected: ((SeatsioObject, TicketType?) -> Void)?
public private(set) var onObjectDeselected: ((SeatsioObject, TicketType?) -> Void)?
public private(set) var onObjectClicked: ((SeatsioObject) -> Void)?
public private(set) var onObjectStatusChanged: ((SeatsioObject) -> Void)?
public private(set) var onSessionInitialized: ((HoldToken) -> Void)?
public private(set) var onHoldTokenExpired: (() -> Void)?
public private(set) var onBestAvailableSelected: (([SeatsioObject], Bool) -> Void)?
public private(set) var onBestAvailableSelectionFailed: (() -> Void)?
public private(set) var onHoldSucceeded: (([SeatsioObject], [TicketType]?) -> Void)?
public private(set) var onHoldFailed: (([SeatsioObject], [TicketType]?) -> Void)?
public private(set) var onReleaseHoldSucceeded: (([SeatsioObject], [TicketType]?) -> Void)?
public private(set) var onReleaseHoldFailed: (([SeatsioObject], [TicketType]?) -> Void)?
public private(set) var onSelectedObjectBooked: ((SeatsioObject) -> Void)?
public private(set) var onChartRendered: ((SeatingChart) -> Void)?
public private(set) var onChartRenderingFailed: (() -> Void)?

public var toolName: String { "EventManager" }

public func secretKey(_ secretKey: String) -> Self {
params.secretKey = secretKey
return self
}

public func event(_ event: String) -> Self {
params.event = event
return self
}

public func events(_ events: [String]) -> Self {
params.events = events
return self
}

public func language(_ language: String) -> Self {
params.language = language
return self
}

public func messages(_ messages: [String: String]) -> Self {
params.messages = messages
return self
}

public func mode(_ mode: EventManagerMode) -> Self {
params.mode = mode
return self
}

public func loading(_ loading: String) -> Self {
params.loading = loading
return self
}

public func objectColor(_ objectColor: String) -> Self {
params.objectColor = objectColor
return self
}

public func extraConfig(_ extraConfig: Encodable) -> Self {
params.extraConfig = AnyEncodable(value: extraConfig)
return self
}

public func onSelectionValid(_ onSelectionValid: @escaping () -> ()) -> Self {
self.onSelectionValid = onSelectionValid
return self
}

public func onSelectionInvalid(_ onSelectionInvalid: @escaping ([SelectionValidatorType]) -> ()) -> Self {
self.onSelectionInvalid = onSelectionInvalid
return self
}

public func onObjectSelected(_ onObjectSelected: @escaping (SeatsioObject, TicketType?) -> ()) -> Self {
self.onObjectSelected = onObjectSelected
return self
}

public func onObjectDeselected(_ onObjectDeselected: @escaping (SeatsioObject, TicketType?) -> ()) -> Self {
self.onObjectDeselected = onObjectDeselected
return self
}

public func onObjectClicked(_ onObjectClicked: @escaping (SeatsioObject) -> ()) -> Self {
self.onObjectClicked = onObjectClicked
return self
}

public func onObjectStatusChanged(_ onObjectStatusChanged: @escaping (SeatsioObject) -> ()) -> Self {
self.onObjectStatusChanged = onObjectStatusChanged
return self
}

public func onSessionInitialized(_ onSessionInitialized: @escaping (HoldToken) -> ()) -> Self {
self.onSessionInitialized = onSessionInitialized
return self
}

public func onHoldTokenExpired(_ onHoldTokenExpired: @escaping () -> ()) -> Self {
self.onHoldTokenExpired = onHoldTokenExpired
return self
}

public func onBestAvailableSelected(_ onBestAvailableSelected: @escaping ([SeatsioObject], Bool) -> ()) -> Self {
self.onBestAvailableSelected = onBestAvailableSelected
return self
}

public func onBestAvailableSelectionFailed(_ onBestAvailableSelectionFailed: @escaping () -> ()) -> Self {
self.onBestAvailableSelectionFailed = onBestAvailableSelectionFailed
return self
}

public func onHoldSucceeded(_ onHoldSucceeded: @escaping ([SeatsioObject], [TicketType]?) -> ()) -> Self {
self.onHoldSucceeded = onHoldSucceeded
return self
}

public func onHoldFailed(_ onHoldFailed: @escaping ([SeatsioObject], [TicketType]?) -> ()) -> Self {
self.onHoldFailed = onHoldFailed
return self
}

public func onReleaseHoldSucceeded(_ onReleaseHoldSucceeded: @escaping ([SeatsioObject], [TicketType]?) -> ()) -> Self {
self.onReleaseHoldSucceeded = onReleaseHoldSucceeded
return self
}

public func onReleaseHoldFailed(_ onReleaseHoldFailed: @escaping ([SeatsioObject], [TicketType]?) -> ()) -> Self {
self.onReleaseHoldFailed = onReleaseHoldFailed
return self
}

public func onSelectedObjectBooked(_ onSelectedObjectBooked: @escaping (SeatsioObject) -> ()) -> Self {
self.onSelectedObjectBooked = onSelectedObjectBooked
return self
}

public func tooltipInfo(_ tooltipInfo: @escaping (SeatsioObject) -> String) -> Self {
self.tooltipInfo = tooltipInfo
return self
}

public func onChartRendered(_ onChartRendered: @escaping (SeatingChart) -> ()) -> Self {
self.onChartRendered = onChartRendered
return self
}

public func onChartRenderingFailed(_ onChartRenderingFailed: @escaping () -> ()) -> Self {
self.onChartRenderingFailed = onChartRenderingFailed
return self
}

public func colorScheme(_ colorScheme: String) -> Self {
params.colorScheme = colorScheme
return self
}

public func colors(_ colors: Colors) -> Self {
params.colors = colors
return self
}

public func stylePreset(_ stylePreset: String) -> Self {
params.stylePreset = stylePreset
return self
}

public func style(_ style: Style) -> Self {
params.style = style
return self
}

public var jsonStringRepresentation: String {
let jsonEncoder = JSONEncoder()
guard let jsonData = try? jsonEncoder.encode(params) else {
assertionFailure("Failed to encode config")
return ""
}
return String(decoding: jsonData, as: UTF8.self)
}
}
15 changes: 8 additions & 7 deletions seatsio-ios/Example/SeatingChartSample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class SeatingChartSample: UIViewController {
let config: SeatingChartConfig = SeatingChartConfig()
.workspaceKey("publicDemoKey")
.event("smallTheatreWithGAEvent")
.mode(.normal)
.pricing([
Pricing(category: "1", ticketTypes: [
TicketTypePricing(ticketType: "child", price: 10),
Expand All @@ -18,27 +19,27 @@ class SeatingChartSample: UIViewController {
TicketTypePricing(ticketType: "adult", price: 30)])
])
.priceFormatter({ (price) in "\(price)$" })
.objectTooltip(ObjectTooltip().showAvailability(true))
.objectTooltip(ObjectTooltip(showAvailability: true))
.showLegend(true)
.showSeatLabels(true)
.onSelectionInvalid({ (errors) in print(errors) })
.onObjectSelected({ (object, ticketType) in
print(object, ticketType)
print(object, ticketType ?? "nil")
})
.onObjectDeselected({ (object, ticketType) in
print(object, ticketType)
print(object, ticketType ?? "nil")
})
.selectedObjects([SelectedObject("A-1")])
.onChartRendered({ (chart) in
print("rendered")
chart.getReportBySelectability({ (report) in print(report)})
chart.changeConfig(ConfigChange().unavailableCategories(["Balcony"]))
chart.changeConfig(ConfigChange(unavailableCategories: ["Balcony"]))
chart.isObjectInChannel("K-3", "NO_CHANNEL", { (result) in print("Is object in channel NO_CHANNEL? " + String(result)) })
})
.categoryFilter(CategoryFilter().enabled(true))

.categoryFilter(CategoryFilter(enabled: true))
seatsio = SeatsioWebView(frame: UIScreen.main.bounds, region: "eu", seatsioConfig: config)

self.view = seatsio
}

Expand Down
2 changes: 1 addition & 1 deletion seatsio-ios/Html.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let HTML = """
<div id="chart" style="width: 100%; height: 100%;"></div>
<script>
let chart = new seatsio.SeatingChart(%configAsJs%).render();
let chart = new seatsio.%toolName%(%configAsJs%).render();
window.bridge.register("selectObjects", function(objects) {
chart.selectObjects(objects)
Expand Down
Loading

0 comments on commit c6c014d

Please sign in to comment.