Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Suggested dates displaying in app to learners in instructor-paced cou…
Browse files Browse the repository at this point in the history
…rses - PLS (#1458)

* added check for is_self_paced for PLS banner
  • Loading branch information
mumer92 authored and salman2013 committed Jan 29, 2021
1 parent af246ed commit ab7b622
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
23 changes: 22 additions & 1 deletion Source/CourseDatesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class CourseDatesViewController: UIViewController, InterfaceOrientationOverridin
courseBannerStream.listen(self) { [weak self] result in
switch result {
case .success(let courseBanner):
self?.loadCourseDateBannerView(bannerModel: courseBanner)
self?.handleDatesBanner(courseBanner: courseBanner)
break

case .failure(let error):
Expand All @@ -152,6 +152,23 @@ class CourseDatesViewController: UIViewController, InterfaceOrientationOverridin
}
}

private func handleDatesBanner(courseBanner: CourseDateBannerModel) {
guard let isSelfPaced = environment.dataManager.enrollmentManager.enrolledCourseWithID(courseID: courseID)?.course.isSelfPaced else {
updateDatesBannerVisibility(with: 0)
return
}

if isSelfPaced {
loadCourseDateBannerView(bannerModel: courseBanner)
} else {
if let status = courseBanner.bannerInfo.status, status == .upgradeToCompleteGradedBanner {
loadCourseDateBannerView(bannerModel: courseBanner)
} else {
updateDatesBannerVisibility(with: 0)
}
}
}

private func loadCourseDateBannerView(bannerModel: CourseDateBannerModel) {
let height: CGFloat
if bannerModel.hasEnded {
Expand All @@ -164,6 +181,10 @@ class CourseDatesViewController: UIViewController, InterfaceOrientationOverridin
height = courseDateBannerView.heightForView(width: tableView.frame.size.width)
}

updateDatesBannerVisibility(with: height)
}

private func updateDatesBannerVisibility(with height: CGFloat) {
courseDateBannerView.snp.remakeConstraints { make in
make.trailing.equalTo(tableView)
make.leading.equalTo(tableView)
Expand Down
19 changes: 18 additions & 1 deletion Source/CourseOutlineViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public class CourseOutlineViewController :
courseBannerStream.listen(self) { [weak self] result in
switch result {
case .success(let courseBanner):
self?.loadCourseDateBannerView(courseBanner: courseBanner)
self?.handleDatesBanner(courseBanner: courseBanner)
break

case .failure(let error):
Expand All @@ -201,6 +201,23 @@ public class CourseOutlineViewController :
}
}

private func handleDatesBanner(courseBanner: CourseDateBannerModel) {
guard let isSelfPaced = environment.dataManager.enrollmentManager.enrolledCourseWithID(courseID: courseID)?.course.isSelfPaced else {
hideCourseBannerView()
return
}

if isSelfPaced {
loadCourseDateBannerView(courseBanner: courseBanner)
} else {
if let status = courseBanner.bannerInfo.status, status == .upgradeToCompleteGradedBanner {
loadCourseDateBannerView(courseBanner: courseBanner)
} else {
hideCourseBannerView()
}
}
}

private func loadCourseStream() {
loadController.state = .Initial
loadCourseOutlineStream()
Expand Down
4 changes: 3 additions & 1 deletion Source/HTMLBlockViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ public class HTMLBlockViewController: UIViewController, CourseBlockViewControlle
}

private func loadBannerStream() {
guard subkind == .Problem else { return }
guard subkind == .Problem,
let isSelfPaced = environment.dataManager.enrollmentManager.enrolledCourseWithID(courseID: courseID)?.course.isSelfPaced,
isSelfPaced else { return }

let courseBannerRequest = CourseDateBannerAPI.courseDateBannerRequest(courseID: courseID)
let courseBannerStream = environment.networkManager.streamForRequest(courseBannerRequest)
Expand Down
3 changes: 1 addition & 2 deletions Source/OEXCourse.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ OEXStartType OEXStartTypeForString(NSString* type);
@property (readonly, nonatomic, assign) BOOL isStartDateOld;
@property (readonly, nonatomic, assign) BOOL isEndDateOld;
@property (readonly, nonatomic, assign) BOOL isAuditExpired;


@property (readonly, nonatomic) BOOL isSelfPaced;

@end

Expand Down
2 changes: 2 additions & 0 deletions Source/OEXCourse.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ @interface OEXCourse ()
@property (nonatomic, copy) NSString* subscription_id;
@property (nonatomic, copy) NSString* number;
@property (nonatomic, copy) NSString* effort;
@property (nonatomic) BOOL isSelfPaced;
@property (nonatomic, copy) NSString* short_description;
@property (nonatomic, copy) NSString* overview_html;
@property (nonatomic, copy) NSString* course_updates; // ANNOUNCEMENTS
Expand Down Expand Up @@ -109,6 +110,7 @@ - (id)initWithDictionary:(NSDictionary *)info {
self.root_block_usage_key = [info objectForKey:@"root_block_usage_key"];
self.number = [info objectForKey:@"number"];
self.effort = [info objectForKey:@"effort"];
self.isSelfPaced = [[info objectForKey:@"is_self_paced"] boolValue];
self.short_description = [info objectForKey:@"short_description"];
self.overview_html = [info objectForKey:@"overview"];
self.course_updates = [info objectForKey:@"course_updates"];
Expand Down

0 comments on commit ab7b622

Please sign in to comment.