Skip to content

Commit

Permalink
Merge pull request #104 from OpenStack-mobile/develop
Browse files Browse the repository at this point in the history
Release v2.3.3
  • Loading branch information
colemancda authored May 5, 2017
2 parents 1196bd5 + 230b44c commit 9c7c00c
Show file tree
Hide file tree
Showing 43 changed files with 1,194 additions and 210 deletions.
6 changes: 6 additions & 0 deletions OpenStack Summit/CoreSummit/CoreDataExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ public extension NSManagedObjectContext {
return (try self.executeFetchRequest(fetchRequest) as! [NSNumber]).first!.integerValue
}

@inline(__always)
func count<ManagedObject: NSManagedObject>(managedObjectType: ManagedObject.Type, predicate: CoreSummit.Predicate) throws -> Int {

return try count(managedObjectType, predicate: predicate.toFoundation())
}

/// Save and attempt to recover from validation errors
func validateAndSave(fileName: String = #file, _ lineNumber: Int = #line) throws {

Expand Down
8 changes: 7 additions & 1 deletion OpenStack Summit/CoreSummit/DataUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ public extension DataUpdate {
case .PresentationCategoryGroup, .PrivatePresentationCategoryGroup: return CoreSummit.TrackGroupDataUpdate.self
case .SummitLocationMap, .SummitLocationImage: return CoreSummit.Image.self
case .SummitWIFIConnection: return CoreSummit.WirelessNetwork.self

case .PresentationVideo: return CoreSummit.Video.self
case .PresentationSlide: return CoreSummit.Slide.self
case .PresentationLink: return CoreSummit.Link.self

default: return nil
}
}
Expand Down Expand Up @@ -315,3 +318,6 @@ extension TrackGroupDataUpdate: Updatable { }
extension Image: Updatable { }
extension GroupEventDataUpdate: Updatable { }
extension WirelessNetwork: Updatable { }
extension Video: Updatable { }
extension Slide: Updatable { }
extension Link: Updatable { }
6 changes: 6 additions & 0 deletions OpenStack Summit/CoreSummit/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public struct Event: Named {

public var videos: Set<Video>

public var slides: Set<Slide>

public var links: Set<Link>

public var groups: Set<Group>
}

Expand Down Expand Up @@ -78,4 +82,6 @@ public func == (lhs: Event, rhs: Event) -> Bool {
&& lhs.groups == rhs.groups
&& lhs.externalRSVP == rhs.externalRSVP
&& lhs.willRecord == rhs.willRecord
&& lhs.slides == rhs.slides
&& lhs.links == rhs.links
}
7 changes: 7 additions & 0 deletions OpenStack Summit/CoreSummit/EventDataUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public struct EventDataUpdate: Named {

public let videos: Set<Video>

public let slides: Set<Slide>

public let links: Set<Link>

public let rsvp: String?

public let attachment: String?
Expand All @@ -66,4 +70,7 @@ public func == (lhs: EventDataUpdate, rhs: EventDataUpdate) -> Bool {
&& lhs.presentation == rhs.presentation
&& lhs.videos == rhs.videos
&& lhs.rsvp == rhs.rsvp
&& lhs.attachment == rhs.attachment
&& lhs.slides == rhs.slides
&& lhs.links == rhs.links
}
23 changes: 17 additions & 6 deletions OpenStack Summit/CoreSummit/EventDataUpdateJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ extension EventDataUpdate: JSONDecodable {
self.descriptionText = JSONObject[JSONKey.description.rawValue]?.rawValue as? String
self.socialDescription = JSONObject[JSONKey.social_description.rawValue]?.rawValue as? String
self.rsvp = JSONObject[JSONKey.rsvp_link.rawValue]?.rawValue as? String
self.attachment = JSONObject[JSONKey.attachment.rawValue]?.rawValue as? String

if let track = JSONObject[JSONKey.track_id.rawValue]?.rawValue as? Int
where track > 0 {
Expand Down Expand Up @@ -95,18 +96,28 @@ extension EventDataUpdate: JSONDecodable {
self.videos = []
}

if let attachment = JSONObject[JSONKey.attachment.rawValue]?.rawValue as? String {
if let slidesJSONArray = JSONObject[JSONKey.slides.rawValue]?.arrayValue {

self.attachment = attachment
guard let slides = Slide.fromJSON(slidesJSONArray)
else { return nil }

self.slides = Set(slides)

} else {

} else if let slidesJSONArray = JSONObject[JSONKey.slides.rawValue]?.arrayValue,
let slides = String.fromJSON(slidesJSONArray) {
self.slides = []
}

if let linksJSONArray = JSONObject[JSONKey.links.rawValue]?.arrayValue {

guard let links = Link.fromJSON(linksJSONArray)
else { return nil }

self.attachment = slides.first
self.links = Set(links)

} else {

self.attachment = nil
self.links = []
}
}
}
48 changes: 35 additions & 13 deletions OpenStack Summit/CoreSummit/EventJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal extension Event {

enum JSONKey: String {

case id, summit_id, title, description, social_description, start_date, end_date, allow_feedback, avg_feedback_rate, type_id, type, sponsors, speakers, location_id, location, tags, track_id, track, videos, rsvp_link, groups, rsvp_external, to_record, attachment, slides
case id, summit_id, title, description, social_description, start_date, end_date, allow_feedback, avg_feedback_rate, type_id, type, sponsors, speakers, location_id, location, tags, track_id, track, videos, rsvp_link, groups, rsvp_external, to_record, attachment, slides, links
}
}

Expand Down Expand Up @@ -66,6 +66,7 @@ extension Event: JSONParametrizedDecodable {
self.descriptionText = JSONObject[JSONKey.description.rawValue]?.rawValue as? String
self.socialDescription = JSONObject[JSONKey.social_description.rawValue]?.rawValue as? String
self.rsvp = JSONObject[JSONKey.rsvp_link.rawValue]?.rawValue as? String
self.attachment = JSONObject[JSONKey.attachment.rawValue]?.rawValue as? String

if let track = JSONObject[JSONKey.track_id.rawValue]?.rawValue as? Int where track > 0 {

Expand Down Expand Up @@ -98,18 +99,28 @@ extension Event: JSONParametrizedDecodable {
self.videos = []
}

if let attachment = JSONObject[JSONKey.attachment.rawValue]?.rawValue as? String {
if let slidesJSONArray = JSONObject[JSONKey.slides.rawValue]?.arrayValue {

self.attachment = attachment
guard let slides = Slide.fromJSON(slidesJSONArray)
else { return nil }

self.slides = Set(slides)

} else {

} else if let slidesJSONArray = JSONObject[JSONKey.slides.rawValue]?.arrayValue,
let slides = String.fromJSON(slidesJSONArray) {
self.slides = []
}

if let linksJSONArray = JSONObject[JSONKey.links.rawValue]?.arrayValue {

guard let links = Link.fromJSON(linksJSONArray)
else { return nil }

self.attachment = slides.first
self.links = Set(links)

} else {

self.attachment = nil
self.links = []
}

// should never come in this JSON response
Expand Down Expand Up @@ -173,6 +184,7 @@ extension MemberResponse.Event: JSONDecodable {
self.descriptionText = JSONObject[JSONKey.description.rawValue]?.rawValue as? String
self.socialDescription = JSONObject[JSONKey.social_description.rawValue]?.rawValue as? String
self.rsvp = JSONObject[JSONKey.rsvp_link.rawValue]?.rawValue as? String
self.attachment = JSONObject[JSONKey.attachment.rawValue]?.rawValue as? String

if let trackJSON = JSONObject[JSONKey.track.rawValue] {

Expand Down Expand Up @@ -210,18 +222,28 @@ extension MemberResponse.Event: JSONDecodable {
self.videos = []
}

if let attachment = JSONObject[JSONKey.attachment.rawValue]?.rawValue as? String {
if let slidesJSONArray = JSONObject[JSONKey.slides.rawValue]?.arrayValue {

self.attachment = attachment
guard let slides = Slide.fromJSON(slidesJSONArray)
else { return nil }

self.slides = slides

} else {

} else if let slidesJSONArray = JSONObject[JSONKey.slides.rawValue]?.arrayValue,
let slides = String.fromJSON(slidesJSONArray) {
self.slides = []
}

if let linksJSONArray = JSONObject[JSONKey.links.rawValue]?.arrayValue {

guard let links = Link.fromJSON(linksJSONArray)
else { return nil }

self.attachment = slides.first
self.links = links

} else {

self.attachment = nil
self.links = []
}
}
}
10 changes: 10 additions & 0 deletions OpenStack Summit/CoreSummit/EventManagedObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public final class EventManagedObject: Entity {

@NSManaged public var videos: Set<VideoManagedObject>

@NSManaged public var slides: Set<SlideManagedObject>

@NSManaged public var links: Set<LinkManagedObject>

@NSManaged public var groups: Set<GroupManagedObject>

@NSManaged public var summit: SummitManagedObject
Expand Down Expand Up @@ -79,6 +83,8 @@ extension Event: CoreDataDecodable {
self.location = managedObject.location?.identifier
self.presentation = Presentation(managedObject: managedObject.presentation)
self.videos = Video.from(managedObjects: managedObject.videos)
self.slides = Slide.from(managedObjects: managedObject.slides)
self.links = Link.from(managedObjects: managedObject.links)
self.groups = Group.from(managedObjects: managedObject.groups)
}
}
Expand Down Expand Up @@ -109,6 +115,8 @@ extension Event: CoreDataEncodable {
managedObject.location = try context.relationshipFault(location)
managedObject.presentation = try context.relationshipFault(presentation)
managedObject.videos = try context.relationshipFault(videos)
managedObject.slides = try context.relationshipFault(slides)
managedObject.links = try context.relationshipFault(links)
managedObject.groups = try context.relationshipFault(groups)

managedObject.didCache()
Expand Down Expand Up @@ -143,6 +151,8 @@ extension MemberResponse.Event: CoreDataEncodable {
managedObject.location = try context.relationshipFault(location)
managedObject.presentation = try context.relationshipFault(presentation)
managedObject.videos = try context.relationshipFault(Set(videos))
managedObject.slides = try context.relationshipFault(Set(slides))
managedObject.links = try context.relationshipFault(Set(links))
managedObject.groups = try context.relationshipFault(Set(groups))

managedObject.didCache()
Expand Down
40 changes: 40 additions & 0 deletions OpenStack Summit/CoreSummit/Link.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Link.swift
// OpenStack Summit
//
// Created by Alsey Coleman Miller on 5/5/17.
// Copyright © 2017 OpenStack. All rights reserved.
//

public struct Link: PresentationMaterial {

public let identifier: Identifier

public var name: String

public var descriptionText: String?

public var displayOnSite: Bool

public var featured: Bool

public var order: Int

public var link: String

public var event: Identifier
}

// MARK: - Equatable

public func == (lhs: Link, rhs: Link) -> Bool {

return lhs.identifier == rhs.identifier
&& lhs.name == rhs.name
&& lhs.descriptionText == rhs.descriptionText
&& lhs.displayOnSite == rhs.displayOnSite
&& lhs.featured == rhs.featured
&& lhs.order == rhs.order
&& lhs.link == rhs.link
&& lhs.event == rhs.event
}
52 changes: 52 additions & 0 deletions OpenStack Summit/CoreSummit/LinkJSON.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// LinkJSON.swift
// OpenStack Summit
//
// Created by Alsey Coleman Miller on 5/5/17.
// Copyright © 2017 OpenStack. All rights reserved.
//

import SwiftFoundation

public extension Link {

enum JSONKey: String {

case id, name, description, display_on_site, featured, order, presentation_id, link
}
}

extension Link: JSONDecodable {

public init?(JSONValue: JSON.Value) {

guard let JSONObject = JSONValue.objectValue,
let identifier = JSONObject[JSONKey.id.rawValue]?.rawValue as? Int,
let featured = JSONObject[JSONKey.featured.rawValue]?.rawValue as? Bool,
let displayOnSite = JSONObject[JSONKey.display_on_site.rawValue]?.rawValue as? Bool,
let presentation = JSONObject[JSONKey.presentation_id.rawValue]?.rawValue as? Identifier,
let order = JSONObject[JSONKey.order.rawValue]?.rawValue as? Int,
let link = JSONObject[JSONKey.link.rawValue]?.rawValue as? String
else { return nil }

self.identifier = identifier
self.featured = featured
self.displayOnSite = displayOnSite
self.event = presentation
self.order = order
self.link = link

// optional
self.name = JSONObject[JSONKey.name.rawValue]?.rawValue as? String ?? ""

if let descriptionText = JSONObject[JSONKey.description.rawValue]?.rawValue as? String
where descriptionText.isEmpty == false {

self.descriptionText = descriptionText

} else {

self.descriptionText = nil
}
}
}
Loading

0 comments on commit 9c7c00c

Please sign in to comment.