-
-
Save majidsaleem105/588ee96e0fa373ad49ddcb38ac63c302 to your computer and use it in GitHub Desktop.
This file contains 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
// This will be called each time the selected date changes. | |
// Use this as an opportunity to rebuild the content shown to the user. | |
override func dailyPageViewController(_ dailyPageViewController: OCKDailyPageViewController, | |
prepare listViewController: OCKListViewController, for date: Date) { | |
ptDoc.removeAll() | |
ptpalDocuments.removeAll() | |
var query = OCKTaskQuery(for: date) | |
query.excludesTasksWithNoEvents = true | |
var surveyT = 0 | |
var allTasks = [String: [OCKTask]]() | |
var sortedTasks = [String: [Int: OCKTask]]() | |
var surveyTasks = [String: [Int: OCKTask]]() | |
sortedTasks.removeAll() | |
surveyTasks.removeAll() | |
segmentItems.removeAll() | |
segmentControlItems = ["Activities", "Optional", "Documents", "Surveys"] | |
storeManager.store.fetchAnyTasks(query: query, callbackQueue: .main) { [self] result in | |
switch result { | |
case .failure(let error): print("Error: \(error)") | |
case .success(let tasks): | |
let grouping: [String: [OCKAnyTask]] = Dictionary(grouping: tasks, by: { $0.groupIdentifier! }) | |
for (_, keyV) in grouping.keys.enumerated() { | |
let segmentItem = keyV | |
.replacingOccurrences(of: "Physical Activities", with: "Activities") | |
.replacingOccurrences(of: " Activities", with: "") | |
.replacingOccurrences(of: "Informational", with: "Documents") | |
if ( (segmentItem != "Documents" && segmentItem != "Survey") && !segmentItems.contains( segmentItem ) ){ | |
segmentItems.append( segmentItem ) | |
} | |
} | |
// print("grouping: ", grouping.keys) | |
// print("segmentItems: ", segmentItems, segmentControlItems) | |
if( !segmentItems.isEmpty ) | |
{ | |
var toBeRemovedIndexes: [Int] = [] | |
for( segmentIndex, segmentName ) in segmentControlItems.enumerated() { | |
let segmentNameV = segmentName .contains("Surveys") ? "Survey" : segmentName | |
let foundIndex = segmentItems .firstIndex(of: segmentNameV) | |
// print("foundIndex: ", foundIndex, segmentNameV) | |
if foundIndex == nil { | |
print("removedIndex: ", segmentIndex, segmentName) | |
toBeRemovedIndexes.append( segmentIndex ) | |
} | |
} // End of for loop | |
// print("segmentControlItems: ", segmentControlItems) | |
segmentControlItems = segmentControlItems | |
.enumerated() | |
.filter { !toBeRemovedIndexes.contains($0.offset) } | |
.map { $0.element } | |
let newSegmentItems = Array( Set( segmentControlItems ) .intersection( Set( segmentItems ) ) ) | |
if( segmentControlItems.count > 0 ) { | |
// print("after segmentControlItems: ", segmentControlItems) | |
listViewController.appendView(addSegmentControl(), animated: false) | |
} | |
} | |
tasks.forEach { (eachTask) in | |
// print( eachTask.title! + " : ", eachTask.schedule) | |
if ( eachTask.groupIdentifier == groupIdentifier ) { | |
// print("groupIdentifier: ", eachTask.groupIdentifier!) | |
let newTask = eachTask as! OCKTask | |
let userInfo = newTask.userInfo! | |
var sortTask = [Int: OCKTask]() | |
var roleName = userInfo["RoleName"]! | |
roleName = roleName.lowercased() == "nav" ? "Navigator" : roleName | |
let displayOrder = Int( userInfo["DisplayOrder"]! )! | |
sortTask[ displayOrder ] = newTask | |
// print(newTask.title! + " => \( displayOrder )" ) | |
if allTasks.keys.contains( roleName ) { | |
allTasks[ roleName ]?.append( newTask ) | |
sortedTasks[ roleName ]?.updateValue(newTask, forKey: displayOrder) | |
} | |
else { | |
allTasks[ roleName ] = [newTask] | |
sortedTasks[ roleName ] = sortTask | |
} | |
} // End of if eachTask.groupIdentifier == groupIdentifier | |
if( eachTask.groupIdentifier == "Survey" ) { | |
let newTask = eachTask as! OCKTask | |
let userInfo = newTask.userInfo! | |
//var sortTask = [Int: OCKTask]() | |
var surveyTask = [Int: OCKTask]() | |
let roleName = eachTask.groupIdentifier! | |
surveyT += 1 | |
let displayOrder = surveyT | |
surveyTask[ displayOrder ] = newTask | |
// print(newTask.title! + " => \( displayOrder )" ) | |
if surveyTasks.keys.contains( roleName ) { | |
surveyTasks[ roleName ]?.updateValue(newTask, forKey: displayOrder) | |
} | |
else { | |
surveyTasks[ roleName ] = surveyTask | |
} | |
} // End of if eachTask.groupIdentifier == "Physical Activities" | |
if eachTask.groupIdentifier == "Informational Activities" { | |
var colorBG = Color.gray | |
let newTask = eachTask as! OCKTask | |
let userInfo = newTask.userInfo! | |
let bgColor = userInfo["Color"] ?? "" | |
var roleName = userInfo["RoleName"] ?? "No Role" | |
roleName = roleName.lowercased() == "nav" ? "Navigator" : roleName | |
let splitBG = bgColor != "" ? bgColor.split(separator: ",") : [] | |
if( splitBG.count > 0 ) | |
{ | |
colorBG = colorFromRGB(red: String( splitBG[ 0 ] ), green: String( splitBG[ 1 ] ), blue: String( splitBG[ 2 ] ) ) | |
} | |
let newD = DocsTask(id: newTask.id, title: newTask.title!, bgColor: colorBG) | |
if ptDoc.keys.contains( roleName ) { | |
// print("ifCVC: ", newD.title) | |
if !(ptDoc[ roleName ]?.contains( newD ))! { | |
ptDoc[ roleName ]?.append( newD ) | |
} | |
} | |
else | |
{ | |
ptDoc[ roleName ] = [ newD ] | |
generalSets.documentsRoles[ roleName ] = false | |
} | |
} // End of if eachTask.groupIdentifier == "Physical Activities" | |
} // End of tasks.forEach loop | |
if !(surveyTasks.isEmpty) && segmentControlSelectedIndex == 0 { | |
for (sectionHead, newTasks ) in surveyTasks { | |
print("sectionHead:\(sectionHead)", surveyTasks) | |
let sectionHeadlbl = sectionHead == "Survey" ? "Surveys" : sectionHead | |
// if sectionHead != "Survey" { | |
let labelV = OCKLabel(textStyle: .headline, weight: .semibold) | |
labelV.text = sectionHeadlbl.uppercased() | |
listViewController.appendView(labelV, animated: false) | |
// } | |
let sortedKeys = newTasks.keys.sorted() | |
for index in sortedKeys { | |
let eachTask = newTasks[ index ]! | |
let newTaskCard = SurveyViewController(viewSynchronizer: SurveyViewSynchronizer(), task: eachTask, eventQuery: .init(for: date), storeManager: self.storeManager) | |
newTaskCard.controller.fetchAndObserveEvents(forTaskIDs: [eachTask.id], eventQuery: OCKEventQuery(for: date) ) | |
listViewController.appendViewController(newTaskCard, animated: false) | |
} // end of newTasks.forach clouser | |
} // End of for loop | |
} // End of if !(surveyTasks.isEmpty) | |
if !(sortedTasks.isEmpty) { | |
// print("allTasks: ", allTasks) | |
// print("sortedTasks: ", sortedTasks) | |
for (sectionHead, newTasks ) in sortedTasks { | |
// print("sectionHead:\(sectionHead)") | |
let sectionHeadlbl = sectionHead == "AAA" ? "Surveys" : sectionHead | |
// if sectionHead != "Survey" { | |
let labelV = OCKLabel(textStyle: .headline, weight: .semibold) | |
labelV.text = sectionHeadlbl.uppercased() | |
listViewController.appendView(labelV, animated: false) | |
// } | |
let sortedKeys = newTasks.keys.sorted() | |
// print("sortedKeys: ", sortedKeys) | |
for index in sortedKeys { | |
let eachTask = newTasks[ index ]! | |
let newTaskCard = ActivitiesViewController(viewSynchronizer: ActivitiesViewSynchronizer(), task: eachTask, eventQuery: .init(for: date), storeManager: self.storeManager) | |
let taskDetail = eachTask.userInfo! | |
newTaskCard.taskView.headerView.isUserInteractionEnabled = false | |
// Create a configuration object that’s initialized with two palette colors. | |
var config = UIImage.SymbolConfiguration(paletteColors: [.black, .blue]) | |
if traitCollection.userInterfaceStyle == .dark { | |
config = UIImage.SymbolConfiguration(paletteColors: [.blue, .white]) | |
} | |
// Apply a configuration that scales to the system font point size of 42. | |
config = config.applying(UIImage.SymbolConfiguration(font: .systemFont(ofSize: 20.0))) | |
newTaskCard.taskView.headerView.detailDisclosureImage?.image = UIImage(systemName: ( (!generalSets.activitiesNotificationsSet.contains(eachTask.id)) ? "bell" : "bell.badge" )) //alarmImg.asUIImage() | |
newTaskCard.taskView.headerView.detailDisclosureImage?.preferredSymbolConfiguration = config | |
newTaskCard.controller.fetchAndObserveEvents(forTasks: [eachTask], eventQuery: OCKEventQuery(for: date)) | |
listViewController.appendViewController(newTaskCard, animated: false) | |
} // end of newTasks.forach clouser | |
} // End of for loop | |
} // End of if !allTasks?.isEmpty | |
} // End of switch | |
} // End of fetchAnyTasks | |
} // End of func dailyPageViewController | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment