diff --git a/FaceRecogAttendance/FaceRecogAttendance.xcodeproj/project.pbxproj b/FaceRecogAttendance/FaceRecogAttendance.xcodeproj/project.pbxproj index a50fe078686a536884cbe35acfa166f4295a1525..d37b37adf9cab2b17fc1ea74cd1a6475aac426e6 100644 --- a/FaceRecogAttendance/FaceRecogAttendance.xcodeproj/project.pbxproj +++ b/FaceRecogAttendance/FaceRecogAttendance.xcodeproj/project.pbxproj @@ -24,6 +24,10 @@ A0951310262F8C670066554E /* Session.swift in Sources */ = {isa = PBXBuildFile; fileRef = A095130F262F8C670066554E /* Session.swift */; }; A0951313262F8C850066554E /* Attendance.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0951312262F8C850066554E /* Attendance.swift */; }; A0951318262F8C900066554E /* Module.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0951317262F8C900066554E /* Module.swift */; }; + A0AED11E2634C2B300CA51C5 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0AED11D2634C2B300CA51C5 /* LoginViewController.swift */; }; + A0AED1212634C2CC00CA51C5 /* AdminViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0AED1202634C2CC00CA51C5 /* AdminViewController.swift */; }; + A0AED1242634C33000CA51C5 /* StudentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0AED1232634C33000CA51C5 /* StudentViewController.swift */; }; + A0AED1272634C35000CA51C5 /* StudentDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0AED1262634C35000CA51C5 /* StudentDetailViewController.swift */; }; A0B8A3562630BCC000068B14 /* RegisterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0B8A3552630BCC000068B14 /* RegisterViewController.swift */; }; A0B8A3592630BCD900068B14 /* WelcomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0B8A3582630BCD900068B14 /* WelcomeViewController.swift */; }; A0B8A35C2630C6D100068B14 /* FaceTrackerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0B8A35B2630C6D100068B14 /* FaceTrackerViewController.swift */; }; @@ -49,6 +53,10 @@ A095130F262F8C670066554E /* Session.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Session.swift; sourceTree = "<group>"; }; A0951312262F8C850066554E /* Attendance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Attendance.swift; sourceTree = "<group>"; }; A0951317262F8C900066554E /* Module.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Module.swift; sourceTree = "<group>"; }; + A0AED11D2634C2B300CA51C5 /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; }; + A0AED1202634C2CC00CA51C5 /* AdminViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdminViewController.swift; sourceTree = "<group>"; }; + A0AED1232634C33000CA51C5 /* StudentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudentViewController.swift; sourceTree = "<group>"; }; + A0AED1262634C35000CA51C5 /* StudentDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudentDetailViewController.swift; sourceTree = "<group>"; }; A0B8A3552630BCC000068B14 /* RegisterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterViewController.swift; sourceTree = "<group>"; }; A0B8A3582630BCD900068B14 /* WelcomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeViewController.swift; sourceTree = "<group>"; }; A0B8A35B2630C6D100068B14 /* FaceTrackerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaceTrackerViewController.swift; sourceTree = "<group>"; }; @@ -142,6 +150,10 @@ A0B8A3582630BCD900068B14 /* WelcomeViewController.swift */, A0B8A35B2630C6D100068B14 /* FaceTrackerViewController.swift */, A0B8A35E2630C70A00068B14 /* SuccessViewController.swift */, + A0AED11D2634C2B300CA51C5 /* LoginViewController.swift */, + A0AED1202634C2CC00CA51C5 /* AdminViewController.swift */, + A0AED1232634C33000CA51C5 /* StudentViewController.swift */, + A0AED1262634C35000CA51C5 /* StudentDetailViewController.swift */, ); path = Controller; sourceTree = "<group>"; @@ -278,16 +290,20 @@ files = ( A09512F4262F8A4D0066554E /* FaceClassifier.mlmodel in Sources */, A0940D18262E7E6800AD51BA /* AppDelegate.swift in Sources */, + A0AED1212634C2CC00CA51C5 /* AdminViewController.swift in Sources */, A09512FA262F8C0E0066554E /* CameraManager.swift in Sources */, A0B8A3562630BCC000068B14 /* RegisterViewController.swift in Sources */, A09512F1262F89550066554E /* FaceClassificationViewController.swift in Sources */, + A0AED1242634C33000CA51C5 /* StudentViewController.swift in Sources */, A0951313262F8C850066554E /* Attendance.swift in Sources */, A0B8A35C2630C6D100068B14 /* FaceTrackerViewController.swift in Sources */, A0B8A3592630BCD900068B14 /* WelcomeViewController.swift in Sources */, + A0AED1272634C35000CA51C5 /* StudentDetailViewController.swift in Sources */, A09512EE262F89460066554E /* SelectSessionViewController.swift in Sources */, A09512EB262F89340066554E /* SelectModuleViewController.swift in Sources */, A09512F7262F8B170066554E /* Student.swift in Sources */, A0940D1A262E7E6800AD51BA /* SceneDelegate.swift in Sources */, + A0AED11E2634C2B300CA51C5 /* LoginViewController.swift in Sources */, A0951318262F8C900066554E /* Module.swift in Sources */, A0B8A35F2630C70A00068B14 /* SuccessViewController.swift in Sources */, A0951310262F8C670066554E /* Session.swift in Sources */, diff --git a/FaceRecogAttendance/FaceRecogAttendance.xcworkspace/xcuserdata/Lucas.xcuserdatad/UserInterfaceState.xcuserstate b/FaceRecogAttendance/FaceRecogAttendance.xcworkspace/xcuserdata/Lucas.xcuserdatad/UserInterfaceState.xcuserstate index fc5858d49253f9eb766aff6cfcf8cee055673b3e..0ff91adcb4c8026f570d32177a8ef8afd57b6cc2 100644 Binary files a/FaceRecogAttendance/FaceRecogAttendance.xcworkspace/xcuserdata/Lucas.xcuserdatad/UserInterfaceState.xcuserstate and b/FaceRecogAttendance/FaceRecogAttendance.xcworkspace/xcuserdata/Lucas.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/FaceRecogAttendance/FaceRecogAttendance/Controller/AdminViewController.swift b/FaceRecogAttendance/FaceRecogAttendance/Controller/AdminViewController.swift new file mode 100644 index 0000000000000000000000000000000000000000..0de920579e14ddb8ded46b39db0f430c283a4f99 --- /dev/null +++ b/FaceRecogAttendance/FaceRecogAttendance/Controller/AdminViewController.swift @@ -0,0 +1,47 @@ +// +// AdminViewController.swift +// FaceRecogAttendance +// +// Created by Lucas on 24/04/2021. +// + +import Foundation +import UIKit + +class AdminViewController: UIViewController { + + var isCheckAttendance : Int = 0 + + override func viewDidLoad() { + super.viewDidLoad() + } + + @IBAction func studentButtonPressed(_ sender: UIButton) { + isCheckAttendance = 0 + self.performSegue(withIdentifier: "goToStudentList", sender: self) + } + + @IBAction func moduleButtonPressed(_ sender: UIButton) { + isCheckAttendance = 1 + self.performSegue(withIdentifier: "goToModules", sender: self) + } + + + @IBAction func checkAttendanceButtonPressed(_ sender: UIButton) { + isCheckAttendance = 2 + self.performSegue(withIdentifier: "goToModules", sender: self) + } + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if isCheckAttendance == 1 { + let destinationVC = segue.destination as! ModuleListViewController + destinationVC.isCheckAttendancePressed = true + } else if isCheckAttendance == 2 { + let destinationVC = segue.destination as! ModuleListViewController + destinationVC.isCheckAttendancePressed = false + } else { + let destinationVC = segue.destination as! StudentViewController +// destinationVC.isCheckAttendancePressed = false + } + } +} diff --git a/FaceRecogAttendance/FaceRecogAttendance/Controller/LoginViewController.swift b/FaceRecogAttendance/FaceRecogAttendance/Controller/LoginViewController.swift new file mode 100644 index 0000000000000000000000000000000000000000..5a281402196dc5bf855dccbc25193315b1b932ee --- /dev/null +++ b/FaceRecogAttendance/FaceRecogAttendance/Controller/LoginViewController.swift @@ -0,0 +1,31 @@ +// +// LoginViewController.swift +// FaceRecogAttendance +// +// Created by Lucas on 24/04/2021. +// + +import Foundation +import UIKit + +class LoginViewController: UIViewController { + + @IBOutlet weak var emailTextField: UITextField! + @IBOutlet weak var passwordTextField: UITextField! + + override func viewDidLoad() { + super.viewDidLoad() + } + + func checkifAdmin(username: String, password: String) -> Bool { + if username == "admin" && password == "admin" { + return true + } + return false + } + + @IBAction func loginButtonPressed(_ sender: UIButton) { + + performSegue(withIdentifier: "goToAdmin", sender: self) + } +} diff --git a/FaceRecogAttendance/FaceRecogAttendance/Controller/StudentDetailViewController.swift b/FaceRecogAttendance/FaceRecogAttendance/Controller/StudentDetailViewController.swift new file mode 100644 index 0000000000000000000000000000000000000000..44b38b4ac5c6fadb8adfcd11c7fd7e957f75065b --- /dev/null +++ b/FaceRecogAttendance/FaceRecogAttendance/Controller/StudentDetailViewController.swift @@ -0,0 +1,67 @@ +// +// StudentDetailViewController.swift +// FaceRecogAttendance +// +// Created by Lucas on 24/04/2021. +// + +import Foundation +import UIKit +import RealmSwift + +class StudentDetailViewController: UIViewController { + + let realm = try! Realm() + + @IBOutlet weak var studentNameLabel: UILabel! + @IBOutlet weak var studentIDLabel: UILabel! + @IBOutlet weak var studentEmailLabel: UILabel! + @IBOutlet weak var imageUploadLabel: UILabel! + @IBOutlet weak var imageTrainedSegment: UISegmentedControl! + + var student: Student? + + override func viewDidLoad() { + super.viewDidLoad() + + studentNameLabel.text = student?.studentName + studentIDLabel.text = student?.studentID + studentEmailLabel.text = student?.email + + if student?.isImageUpload == true { + imageUploadLabel.text = "Yes" + } else { + imageUploadLabel.text = "No" + } + + if student?.isImageTrained == true { + imageTrainedSegment.selectedSegmentIndex = 1 + } else { + imageTrainedSegment.selectedSegmentIndex = 0 + } + +// studentIDLabel.text = studentID +// studentEmailLabel.text = studentEmail +// imageUploadLabel.text = imageUpload?.description + } + + @IBAction func imageTrainedPressed(_ sender: UISegmentedControl) { + do { + try realm.write { + switch imageTrainedSegment.selectedSegmentIndex + { + case 0: + student?.isImageTrained = false + case 1: + student?.isImageTrained = true + default: + break + } + } + } catch { + print("Error saving data") + } + + } + +} diff --git a/FaceRecogAttendance/FaceRecogAttendance/Controller/StudentViewController.swift b/FaceRecogAttendance/FaceRecogAttendance/Controller/StudentViewController.swift new file mode 100644 index 0000000000000000000000000000000000000000..db01a992780db32d5b11550ab4412ac2ad476b59 --- /dev/null +++ b/FaceRecogAttendance/FaceRecogAttendance/Controller/StudentViewController.swift @@ -0,0 +1,107 @@ +// +// StudentViewController.swift +// FaceRecogAttendance +// +// Created by Lucas on 24/04/2021. +// + +import Foundation +import UIKit +import RealmSwift + +class StudentViewController: UITableViewController { + +// let realm = try! Realm() + + var notificationToken: NotificationToken? + var students: Results<Student>? + + override func viewDidLoad() { + super.viewDidLoad() +// loadStudents() + onLogin() + } + + deinit { + notificationToken?.invalidate() + } + + //MARK - Tableview Datasource Method + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return students?.count ?? 1 + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "StudentCell", for: indexPath) + cell.textLabel?.text = students?[indexPath.row].studentName ?? "No student added yet" + return cell + } + + //MARK - Tableview Delegate Method + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { +// print(studentArray[indexPath.row]) + performSegue(withIdentifier: "goToStudentDetail", sender: self) + tableView.deselectRow(at: indexPath, animated: true) + } + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + let destinationVC = segue.destination as! StudentDetailViewController + if let indexPath = tableView.indexPathForSelectedRow { + destinationVC.student = students?[indexPath.row] + } + } + +// func loadStudents() { +// students = realm?.objects(Student.self) +// tableView.reloadData() +// } + + func login() { + app.login(credentials: Credentials.anonymous) { (result) in + DispatchQueue.main.async { + switch result { + case .failure(let error): + print("Login Failed: \(error)") + case .success(let user): + print("Login as \(user) sucdeeded") + } + } + } + } + + func onLogin() { + let user = app.currentUser! + let partitionValue = "user=\(user.id)" + var configuration = user.configuration(partitionValue: partitionValue) + configuration.objectTypes = [Student.self] + Realm.asyncOpen(configuration: configuration) { (result) in + switch result { + case .failure(let error): + print("Failed to open realm: \(error)") + case .success(let realm): + self.onRealmOpened(realm) + } + } + } + + func onRealmOpened(_ realm: Realm) { + students = realm.objects(Student.self) + + notificationToken = students?.observe { (changes) in + switch changes { + case .initial: break + // Results are now populated and can be accessed without blocking the UI + case .update(_, let deletions, let insertions, let modifications): + // Query results have changed. + print("Deleted indices: ", deletions) + print("Inserted indices: ", insertions) + print("Modified modifications: ", modifications) + case .error(let error): + // An error occurred while opening the Realm file on the background worker thread + fatalError("\(error)") + } + } + tableView.reloadData() + } + +}