Display menus and handles user input. More...
#include <UserMenu.h>
Public Member Functions | |
UserMenu () | |
Default constructor. | |
~UserMenu () | |
Default destructor. | |
void | mainMenu () |
Main menu. | |
bool | login () |
User login. | |
void | display () throw (BadAuthException) |
Display a menu to the screen, according to authorization level of current user. | |
void | registerNewUser () |
Give the user the opportunity to register as new user. | |
Protected Member Functions | |
void | enableSttyEcho (bool bValue=true) |
Enable or disable STTY echo. | |
Private Member Functions | |
void | printCatalog (int aCid=0) |
Display all product beloging to a category ID. | |
void | browseProductCatalog () throw (BadAuthException) |
Browse product catalog by category. | |
void | showProductDetail () throw (BadAuthException) |
Display all details of a given product. | |
void | showConfigurationByProduct () throw (BadAuthException) |
Show all product configurations which include a given product. | |
void | showUserProfile () throw (BadAuthException) |
Show user profile and all his orders. | |
void | placeNewOrder () throw (BadAuthException) |
Place a new order. | |
void | addNewCategory () throw (BadAuthException) |
Admin operation to create a new category of products. | |
void | addNewProduct () throw (BadAuthException) |
Admin operation to add a new product. | |
void | changeProductDetail () throw (BadAuthException) |
Admin operation to update an existing product. | |
void | disableUser () throw (BadAuthException) |
Admin operation to disable a registered user. | |
void | displayMonthlyTrend () throw (BadAuthException) |
Admin operation to display monthly trend of sales. | |
void | deleteProduct () throw (BadAuthException) |
Delete a product (even if already sold). | |
void | displayUnprivilegedMenu () throw (BadAuthException) |
Display user menu (for not-admin users). | |
void | displayAdminMenu () throw (BadAuthException) |
Display all available admin operations. | |
void | wait () |
Wait for user to press enter/return to continue. | |
bool | getNotEmptyLine (const string &msg, string *buffer) |
Get input from standard input. | |
Private Attributes | |
User * | _currentUser |
map< int, op > | usr_operations |
map< int, op > | adm_operations |
Display menus and handles user input.
UserMenu::UserMenu | ( | ) |
Default constructor.
References _currentUser, addNewCategory(), addNewProduct(), adm_operations, browseProductCatalog(), changeProductDetail(), deleteProduct(), disableUser(), displayMonthlyTrend(), LOG, LOG_CTOR, placeNewOrder(), showConfigurationByProduct(), showProductDetail(), showUserProfile(), and usr_operations.
UserMenu::~UserMenu | ( | ) |
void UserMenu::addNewCategory | ( | ) | throw (BadAuthException) [private] |
Admin operation to create a new category of products.
BadAuthException | If called without being authenticated |
References _currentUser, CLEAR_SCREEN_CMD, Category::factory(), getNotEmptyLine(), ManagedObject::store(), and wait().
Referenced by UserMenu().
void UserMenu::addNewProduct | ( | ) | throw (BadAuthException) [private] |
Admin operation to add a new product.
BadAuthException | If called without being authenticated |
References _currentUser, Category::catalog(), CLEAR_SCREEN_CMD, Product::factory(), getNotEmptyLine(), ManagedObject::store(), and wait().
Referenced by UserMenu().
void UserMenu::browseProductCatalog | ( | ) | throw (BadAuthException) [private] |
Browse product catalog by category.
Display all products belonging to a category or display them all if any category is chosen.
BadAuthException | If called without being authenticated |
References _currentUser, Category::catalog(), CLEAR_SCREEN_CMD, printCatalog(), and wait().
Referenced by UserMenu().
void UserMenu::changeProductDetail | ( | ) | throw (BadAuthException) [private] |
Admin operation to update an existing product.
BadAuthException | If called without being authenticated |
References _currentUser, getNotEmptyLine(), KEY_PRD_DESCR, KEY_PRD_NAME, KEY_PRD_PRICE, printCatalog(), Product::productByID(), ManagedObject::setValueForKey(), ManagedObject::update(), and wait().
Referenced by UserMenu().
void UserMenu::deleteProduct | ( | ) | throw (BadAuthException) [private] |
Delete a product (even if already sold).
BadAuthException | If called by client programmer without any logged user |
References _currentUser, CLEAR_SCREEN_CMD, AdminUser::deleteProduct(), printCatalog(), and wait().
Referenced by UserMenu().
void UserMenu::disableUser | ( | ) | throw (BadAuthException) [private] |
Admin operation to disable a registered user.
BadAuthException | If called without being authenticated or not authorized |
References _currentUser, AdminUser::changeUserPassword(), CLEAR_SCREEN_CMD, User::fullName(), User::loginName(), User::userByID(), AdminUser::userList(), and wait().
Referenced by UserMenu().
void UserMenu::display | ( | ) | throw (BadAuthException) |
Display a menu to the screen, according to authorization level of current user.
BadAuthException | If called by client programmer without any logged user |
References _currentUser, displayAdminMenu(), displayUnprivilegedMenu(), and User::isAdmin().
Referenced by mainMenu().
void UserMenu::displayAdminMenu | ( | ) | throw (BadAuthException) [private] |
Display all available admin operations.
BadAuthException | if called without the correct level of authorization. |
References _currentUser, adm_operations, CLEAR_SCREEN_CMD, and User::fullName().
Referenced by display().
void UserMenu::displayMonthlyTrend | ( | ) | throw (BadAuthException) [private] |
Admin operation to display monthly trend of sales.
BadAuthException | If called without being authenticated or not authorized |
References _currentUser, CLEAR_SCREEN_CMD, AdminUser::showMonthlyTrend(), and wait().
Referenced by UserMenu().
void UserMenu::displayUnprivilegedMenu | ( | ) | throw (BadAuthException) [private] |
Display user menu (for not-admin users).
BadAuthException | if called without the correct level of authorization. |
References _currentUser, CLEAR_SCREEN_CMD, User::fullName(), and usr_operations.
Referenced by display().
void UserMenu::enableSttyEcho | ( | bool | bValue = true |
) | [protected] |
bool UserMenu::getNotEmptyLine | ( | const string & | msg, | |
string * | buffer | |||
) | [private] |
Get input from standard input.
[in] | msg | String to prompt before getting input |
[out] | buffer | Pointer to string to fill with data |
Referenced by addNewCategory(), addNewProduct(), changeProductDetail(), and registerNewUser().
bool UserMenu::login | ( | ) |
User login.
Ask user to enter his crendentials and test the access: if successful, an instance of User is allocated and assigned to _currentUser.
References _currentUser, CLEAR_SCREEN_CMD, enableSttyEcho(), User::login(), and wait().
Referenced by mainMenu(), and registerNewUser().
void UserMenu::mainMenu | ( | ) |
Main menu.
Displays the main menu: user is allowed to login into the system, register himself as new user or quit the application.
References CLEAR_SCREEN_CMD, display(), login(), and registerNewUser().
Referenced by main().
void UserMenu::placeNewOrder | ( | ) | throw (BadAuthException) [private] |
Place a new order.
Help the user to choose one or more items from available products and add them to his basket; after last confirmation, a new order is created.
BadAuthException | if called without the correct level of authorization. |
References _currentUser, Basket::addProduct(), CLEAR_SCREEN_CMD, User::getBasket(), Basket::itemCount(), User::placeOrder(), printCatalog(), Basket::total(), and wait().
Referenced by UserMenu().
void UserMenu::printCatalog | ( | int | aCid = 0 |
) | [private] |
Display all product beloging to a category ID.
[in] | aCid | Category ID |
BadAuthException | if called without the correct level of authorization. |
References ProductProxy::catalog(), ProductProxy::getCategory(), ProductProxy::getName(), ProductProxy::getPrice(), and ProductProxy::uniqueID().
Referenced by browseProductCatalog(), changeProductDetail(), deleteProduct(), placeNewOrder(), showConfigurationByProduct(), and showProductDetail().
void UserMenu::registerNewUser | ( | ) |
Give the user the opportunity to register as new user.
References CLEAR_SCREEN_CMD, User::factory(), getNotEmptyLine(), login(), and wait().
Referenced by mainMenu().
void UserMenu::showConfigurationByProduct | ( | ) | throw (BadAuthException) [private] |
Show all product configurations which include a given product.
BadAuthException | if called without the correct level of authorization. |
References _currentUser, CLEAR_SCREEN_CMD, printCatalog(), Product::showCompatibleProducts(), and wait().
Referenced by UserMenu().
void UserMenu::showProductDetail | ( | ) | throw (BadAuthException) [private] |
Display all details of a given product.
BadAuthException | if called without the correct level of authorization. |
References _currentUser, CLEAR_SCREEN_CMD, ProductProxy::isValid(), printCatalog(), and wait().
Referenced by UserMenu().
void UserMenu::showUserProfile | ( | ) | throw (BadAuthException) [private] |
Show user profile and all his orders.
BadAuthException | if called without the correct level of authorization. |
References _currentUser, CLEAR_SCREEN_CMD, ProductProxy::getName(), Order::ordersForUser(), Order::products(), and wait().
Referenced by UserMenu().
void UserMenu::wait | ( | ) | [private] |
Wait for user to press enter/return to continue.
Referenced by addNewCategory(), addNewProduct(), browseProductCatalog(), changeProductDetail(), deleteProduct(), disableUser(), displayMonthlyTrend(), login(), placeNewOrder(), registerNewUser(), showConfigurationByProduct(), showProductDetail(), and showUserProfile().
User* UserMenu::_currentUser [private] |
Referenced by addNewCategory(), addNewProduct(), browseProductCatalog(), changeProductDetail(), deleteProduct(), disableUser(), display(), displayAdminMenu(), displayMonthlyTrend(), displayUnprivilegedMenu(), login(), placeNewOrder(), showConfigurationByProduct(), showProductDetail(), showUserProfile(), UserMenu(), and ~UserMenu().
map<int, op> UserMenu::adm_operations [private] |
Referenced by displayAdminMenu(), and UserMenu().
map<int, op> UserMenu::usr_operations [private] |
Referenced by displayUnprivilegedMenu(), and UserMenu().