145 lines
3.3 KiB
C++
145 lines
3.3 KiB
C++
/*
|
|
File: TechnicianMenu.cpp
|
|
Description: Implementation file containing the method definitions of the
|
|
TechnicianMenu class, including menu handling, job completion,
|
|
notification viewing, password management, and logout logic.
|
|
Author: Trenser
|
|
Date:19-May-2026
|
|
*/
|
|
#include "Enums.h"
|
|
#include "InputHelper.h"
|
|
#include "JobCard.h"
|
|
#include "MenuHelper.h"
|
|
#include "OutputHelper.h"
|
|
#include "Service.h"
|
|
#include "TechnicianMenu.h"
|
|
#include "Validator.h"
|
|
|
|
/*
|
|
Function: showMenu
|
|
Description: Displays the technician menu in a loop until the user chooses to logout.
|
|
Handles exceptions and ensures smooth user interaction.
|
|
Parameters:
|
|
- None
|
|
Returns:
|
|
- void
|
|
*/
|
|
void TechnicianMenu::showMenu()
|
|
{
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
int choice;
|
|
util::clear();
|
|
std::cout << "Technician Menu"
|
|
<< "\n1. Mark Job as Completed"
|
|
<< "\n2. View Notifications"
|
|
<< "\n3. Change Password"
|
|
<< "\n4. Logout"
|
|
<< "\nEnter a choice: ";
|
|
util::read(choice);
|
|
if (!handleOperation(choice))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
catch (const std::exception& e)
|
|
{
|
|
std::cout << "Exception: " << e.what() << std::endl;
|
|
util::pressEnter();
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
Function: handleOperation
|
|
Description: Executes the corresponding technician operation based on the selected menu choice.
|
|
Parameter: int choice - selected menu option
|
|
Return type: bool - true if menu continues, false if logout
|
|
*/
|
|
bool TechnicianMenu::handleOperation(int choice)
|
|
{
|
|
switch (choice)
|
|
{
|
|
case 1:
|
|
completeJob();
|
|
break;
|
|
case 2:
|
|
viewNotifications();
|
|
break;
|
|
case 3:
|
|
changePassword();
|
|
break;
|
|
case 4:
|
|
logout();
|
|
return false;
|
|
default:
|
|
std::cout << "Enter a valid choice!" << std::endl;
|
|
util::pressEnter();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
Function: completeJob
|
|
Description: Allows the technician to mark a selected job card as completed.
|
|
Validates selection and updates job status through the controller.
|
|
Parameters:
|
|
- None
|
|
Returns:
|
|
- void
|
|
*/
|
|
void TechnicianMenu::completeJob()
|
|
{
|
|
util::Map<std::string, const JobCard*> assignedJobCards = m_controller.getJobCardsByUser();
|
|
util::Map<int, const JobCard*> incompleteJobCards;
|
|
std::cout << "Jobs to be completed.\n";
|
|
std::string selectedJobID = selectJobCardToComplete(assignedJobCards, incompleteJobCards);
|
|
if (selectedJobID == "")
|
|
{
|
|
std::cout << "Failed to complete the job.\n";
|
|
}
|
|
else
|
|
{
|
|
m_controller.completeJob(selectedJobID);
|
|
std::cout << "Job marked as completed.\n";
|
|
}
|
|
util::pressEnter();
|
|
}
|
|
|
|
/*
|
|
Function: viewNotifications
|
|
Description: Displays notifications for the technician and allows deletion of notifications.
|
|
Parameters:
|
|
- None
|
|
Returns:
|
|
- void
|
|
*/
|
|
void TechnicianMenu::viewNotifications()
|
|
{
|
|
viewAndDeleteNotification(m_controller);
|
|
}
|
|
|
|
/*
|
|
Function: logout
|
|
Description: Logs out the currently authenticated technician user.
|
|
Parameter: None
|
|
Return type: void
|
|
*/
|
|
void TechnicianMenu::logout()
|
|
{
|
|
m_controller.logout();
|
|
}
|
|
|
|
/*
|
|
Function: changePassword
|
|
Description: Allows the technician to change their password after validation.
|
|
Parameter: None
|
|
Return type: void
|
|
*/
|
|
|
|
void TechnicianMenu::changePassword()
|
|
{
|
|
changePasswordHelper(m_controller);
|
|
} |