Skip to content

Commit

Permalink
Syllabus exams redesign (#941)
Browse files Browse the repository at this point in the history
* Add badges view

* Add exam button

* Fix units access

* Add ExamSession & ProctorSession models

* Handle exam can start state

* Handle other states

* Clean up get state

* Fetch sessions

* Fix progressLabelText

* Handle exam button clicked
  • Loading branch information
ivan-magda authored Mar 30, 2021
1 parent 869860a commit b98a3c6
Show file tree
Hide file tree
Showing 41 changed files with 1,921 additions and 84 deletions.
76 changes: 75 additions & 1 deletion Stepic.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Stepic/Images.xcassets/Course info syllabus/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "course-info-syllabus-in-progress.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "course-info-syllabus-time.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
50 changes: 40 additions & 10 deletions Stepic/Legacy/Model/Entities/Course/Course+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ import Foundation

extension Course {
@NSManaged var managedId: NSNumber?
@NSManaged var managedBeginDate: Date?
@NSManaged var managedCourseDescription: String?
@NSManaged var managedTitle: String?
@NSManaged var managedBeginDate: Date?
@NSManaged var managedEndDate: Date?
@NSManaged var managedBeginDateSource: Date?
@NSManaged var managedEndDateSource: Date?
@NSManaged var managedImageURL: String?
@NSManaged var managedEnrolled: NSNumber?
@NSManaged var managedFeatured: NSNumber?
@NSManaged var managedPublic: NSNumber?
@NSManaged var managedIsProctored: NSNumber?
@NSManaged var managedIsFavorite: NSNumber?
@NSManaged var managedIsArchived: NSNumber?
@NSManaged var managedLearnersCount: NSNumber?
Expand Down Expand Up @@ -128,15 +131,6 @@ extension Course {
}
}

var beginDate: Date? {
set(date) {
self.managedBeginDate = date
}
get {
managedBeginDate
}
}

var courseDescription: String {
set(description) {
self.managedCourseDescription = description
Expand Down Expand Up @@ -164,6 +158,15 @@ extension Course {
}
}

var beginDate: Date? {
set(date) {
self.managedBeginDate = date
}
get {
managedBeginDate
}
}

var endDate: Date? {
set(date) {
self.managedEndDate = date
Expand All @@ -173,6 +176,24 @@ extension Course {
}
}

var beginDateSource: Date? {
get {
self.managedBeginDateSource
}
set {
self.managedBeginDateSource = newValue
}
}

var endDateSource: Date? {
get {
self.managedEndDateSource
}
set {
self.managedEndDateSource = newValue
}
}

var coverURLString: String {
set(url) {
self.managedImageURL = url
Expand Down Expand Up @@ -227,6 +248,15 @@ extension Course {
}
}

var isProctored: Bool {
get {
self.managedIsProctored?.boolValue ?? false
}
set {
self.managedIsProctored = NSNumber(value: newValue)
}
}

var isFavorite: Bool {
get {
self.managedIsFavorite?.boolValue ?? false
Expand Down
12 changes: 9 additions & 3 deletions Stepic/Legacy/Model/Entities/Course/Course.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ final class Course: NSManagedObject, IDFetchable {
self.courseDescription = json[JSONKey.description.rawValue].stringValue
self.coverURLString = "\(StepikApplicationsInfo.stepikURL)" + json[JSONKey.cover.rawValue].stringValue

self.beginDate = Parser.dateFromTimedateJSON(json[JSONKey.beginDateSource.rawValue])
self.endDate = Parser.dateFromTimedateJSON(json[JSONKey.lastDeadline.rawValue])
self.beginDate = Parser.dateFromTimedateJSON(json[JSONKey.beginDate.rawValue])
self.endDate = Parser.dateFromTimedateJSON(json[JSONKey.endDate.rawValue])
self.beginDateSource = Parser.dateFromTimedateJSON(json[JSONKey.beginDateSource.rawValue])
self.endDateSource = Parser.dateFromTimedateJSON(json[JSONKey.endDateSource.rawValue])

self.enrolled = json[JSONKey.enrollment.rawValue].int != nil
self.featured = json[JSONKey.isFeatured.rawValue].boolValue
self.isPublic = json[JSONKey.isPublic.rawValue].boolValue
self.isFavorite = json[JSONKey.isFavorite.rawValue].boolValue
self.isArchived = json[JSONKey.isArchived.rawValue].boolValue
self.isProctored = json[JSONKey.isProctored.rawValue].boolValue
self.readiness = json[JSONKey.readiness.rawValue].float

self.summary = json[JSONKey.summary.rawValue].stringValue
Expand Down Expand Up @@ -369,8 +372,10 @@ final class Course: NSManagedObject, IDFetchable {
case title
case description
case cover
case beginDate = "begin_date"
case endDate = "end_date"
case beginDateSource = "begin_date_source"
case lastDeadline = "last_deadline"
case endDateSource = "end_date_source"
case enrollment
case isFeatured = "is_featured"
case isPublic = "is_public"
Expand Down Expand Up @@ -407,5 +412,6 @@ final class Course: NSManagedObject, IDFetchable {
case options
case coursePreview = "course_preview"
case previewLessonID = "preview_lesson_id"
case isProctored = "is_proctored"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import CoreData
import Foundation

extension ExamSession {
@NSManaged var managedId: NSNumber?
@NSManaged var managedUserId: NSNumber?
@NSManaged var managedSectionId: NSNumber?
@NSManaged var managedBeginDate: Date?
@NSManaged var managedEndDate: Date?
@NSManaged var managedTimeLeft: NSNumber?

@NSManaged var managedSection: Section?

static var oldEntity: NSEntityDescription {
NSEntityDescription.entity(forEntityName: "ExamSession", in: CoreDataHelper.shared.context)!
}

static var fetchRequest: NSFetchRequest<ExamSession> {
NSFetchRequest<ExamSession>(entityName: "ExamSession")
}

convenience init() {
self.init(entity: Self.oldEntity, insertInto: CoreDataHelper.shared.context)
}

var id: Int {
get {
self.managedId?.intValue ?? -1
}
set {
self.managedId = NSNumber(value: newValue)
}
}

var userId: Int {
get {
self.managedUserId?.intValue ?? -1
}
set {
self.managedUserId = NSNumber(value: newValue)
}
}

var sectionId: Int {
get {
self.managedSectionId?.intValue ?? -1
}
set {
self.managedSectionId = NSNumber(value: newValue)
}
}

var beginDate: Date? {
get {
self.managedBeginDate
}
set {
self.managedBeginDate = newValue
}
}

var endDate: Date? {
get {
self.managedEndDate
}
set {
self.managedEndDate = newValue
}
}

var timeLeft: Float {
get {
self.managedTimeLeft?.floatValue ?? 0
}
set {
self.managedTimeLeft = NSNumber(value: newValue)
}
}

var section: Section? {
get {
self.managedSection
}
set {
self.managedSection = newValue
}
}
}
36 changes: 36 additions & 0 deletions Stepic/Legacy/Model/Entities/ExamSession/ExamSession.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import CoreData
import Foundation
import SwiftyJSON

final class ExamSession: NSManagedObject, JSONSerializable, IDFetchable {
typealias IdType = Int

var isActive: Bool { self.timeLeft > 0 }

required convenience init(json: JSON) {
self.init()
self.initialize(json)
}

func initialize(_ json: JSON) {
self.id = json[JSONKey.id.rawValue].intValue
self.userId = json[JSONKey.user.rawValue].intValue
self.sectionId = json[JSONKey.section.rawValue].intValue
self.beginDate = Parser.dateFromTimedateJSON(json[JSONKey.beginDate.rawValue])
self.endDate = Parser.dateFromTimedateJSON(json[JSONKey.endDate.rawValue])
self.timeLeft = json[JSONKey.timeLeft.rawValue].floatValue
}

func update(json: JSON) {
self.initialize(json)
}

enum JSONKey: String {
case id
case user
case section
case beginDate = "begin_date"
case endDate = "end_date"
case timeLeft = "time_left"
}
}
Loading

0 comments on commit b98a3c6

Please sign in to comment.