Skip to content

Commit

Permalink
- Created backoffice base class
Browse files Browse the repository at this point in the history
  • Loading branch information
gbenziv committed Jan 14, 2021
1 parent 4cddf0a commit a90a325
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 147 deletions.
4 changes: 2 additions & 2 deletions orchestra/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ add_executable (
# Common screens
screen/informationscreen.hpp
screen/informationscreen.cpp
screen/screenbase.hpp
screen/screenbase.cpp
screen/screeniface.hpp
# Back office screen
screen/backoffice/backofficescreenbase.hpp
screen/backoffice/customermgmtscreen.hpp
screen/backoffice/customermgmtscreen.cpp
screen/backoffice/dashboardscreen.hpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,41 @@
* Ben Ziv <[email protected]> *
* *
**************************************************************************************************/
#include "screenbase.hpp"
#ifndef ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_BACKOFFICESCREENBASE_HPP_
#define ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_BACKOFFICESCREENBASE_HPP_
#include <tablehelper.hpp>

namespace screen {

} // namespace screen
template <class ControllerType>
class BackOfficeScreenBase {
public:
BackOfficeScreenBase() = default;
virtual ~BackOfficeScreenBase() = default;

protected:
// Screen options - this represents the buttons in a GUI
enum class Options {
LANDING,
DASHBOARD,
USER_PROFILE,
EMPLOYEE_MGMT,
INVENTORY_CTRL,
CUSTOMER_MGMT,
OP_CREATE,
OP_READ,
OP_UPDATE,
OP_DELETE,
// add more enums here
LOGOUT,
APP_EXIT,
INVALID
// Warning! Don't add anything here.
// New enum values must be added before LOGOUT
};
ControllerType mCoreController;
};

} // namespace screen

#endif // ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_BACKOFFICESCREENBASE_HPP_
20 changes: 10 additions & 10 deletions orchestra/application/screen/backoffice/customermgmtscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace screen {
namespace backoffice {

// Customer fields
const std::vector<std::string> CustomerMgmtScreen::domainFields {
const std::vector<std::string> DOMAIN_FIELDS {
"Person.First.Name",
"Person.Middle.Name",
"Person.Last.Name",
Expand Down Expand Up @@ -198,7 +198,7 @@ void CustomerMgmtScreen::createCustomer() {
void CustomerMgmtScreen::updateCustomer() {
showCustomerDetails(true); // true - request to show the index # of each data
// Get the field to update
const std::string field = SCREENCOMMON().getUpdateField(domainFields);
const std::string field = SCREENCOMMON().getUpdateField(DOMAIN_FIELDS);
if (field.empty()) {
std::cout << "Invalid selection." << std::endl;
return;
Expand Down Expand Up @@ -254,14 +254,14 @@ CustomerMgmtScreen::Options CustomerMgmtScreen::getUserSelection() {
if (input < mTableHelper.getDataCount()) {
// Store user input as the selected index (zero based)
mTableHelper.setCurrentIndex(input);
return Options::CUSTOMER_DETAILS;
return Options::OP_READ;
}
} else if (userInput == "c" && !isShowingDetailsScreen) {
return Options::CUSTOMER_CREATE;
return Options::OP_CREATE;
} else if (userInput == "u" && isShowingDetailsScreen) {
return Options::CUSTOMER_UPDATE;
return Options::OP_UPDATE;
} else if (userInput == "d" && isShowingDetailsScreen) {
return Options::CUSTOMER_REMOVE;
return Options::OP_DELETE;
} // add more options here

// Default invalid option
Expand All @@ -281,20 +281,20 @@ bool CustomerMgmtScreen::action(Options option, std::promise<defines::display>*
case Options::INVALID:
invalidOptionSelected();
break;
case Options::CUSTOMER_DETAILS:
case Options::OP_READ:
showCustomerDetails();
isShowingDetailsScreen = true; // Must set to true
break;
case Options::CUSTOMER_CREATE:
case Options::OP_CREATE:
createCustomer();
// Go back to landing screen after creating the customer
action(Options::LANDING, nextScreen);
break;
case Options::CUSTOMER_UPDATE:
case Options::OP_UPDATE:
updateCustomer();
showCustomerDetails(); // refresh employee details screen
break;
case Options::CUSTOMER_REMOVE:
case Options::OP_DELETE:
removeCustomer();
action(Options::LANDING, nextScreen);
break;
Expand Down
31 changes: 7 additions & 24 deletions orchestra/application/screen/backoffice/customermgmtscreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@
**************************************************************************************************/
#ifndef ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_CUSTOMERMGMTSCREEN_HPP_
#define ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_CUSTOMERMGMTSCREEN_HPP_
#include <future>
#include <memory>
#include <string>
#include <vector>
#include <domain/customermgmt/interface/customermgmtviewif.hpp>
#include <screenbase.hpp>
#include <tablehelper.hpp>
// core
// Core
#include <domain/customermgmt/interface/customermgmtiface.hpp>
// data
#include <domain/customermgmt/interface/customermgmtviewif.hpp>
#include <customerdata.hpp>
// Screens
#include "backofficescreenbase.hpp"
#include <screeniface.hpp>

namespace screen {
namespace backoffice {

class CustomerMgmtScreen : public screen::ScreenBase<domain::customermgmt::CustomerMgmtCtrlPtr>,
class CustomerMgmtScreen : public screen::ScreenInterface,
public BackOfficeScreenBase<domain::customermgmt::CustomerMgmtCtrlPtr>,
public domain::customermgmt::CustomerManagementViewInterface {
public:
CustomerMgmtScreen();
Expand All @@ -49,21 +48,6 @@ class CustomerMgmtScreen : public screen::ScreenBase<domain::customermgmt::Custo
void showSuccessfullyRemoved(const std::string& customerName) override;

private:
// Screen options - this represents the buttons in a GUI
enum class Options {
LANDING,
DASHBOARD,
CUSTOMER_DETAILS,
CUSTOMER_CREATE,
CUSTOMER_UPDATE,
CUSTOMER_REMOVE,
// add more enums here
LOGOUT,
APP_EXIT,
INVALID
// Warning! Don't add anything here.
// New enum values must be added before LOGOUT
};
void showLandingScreen() const;
void queryCustomersList();
void showCustomers() const;
Expand All @@ -80,7 +64,6 @@ class CustomerMgmtScreen : public screen::ScreenBase<domain::customermgmt::Custo

app::utility::TableHelper<entity::Customer> mTableHelper;
bool isShowingDetailsScreen;
static const std::vector<std::string> domainFields;
};

} // namespace backoffice
Expand Down
5 changes: 3 additions & 2 deletions orchestra/application/screen/backoffice/dashboardscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
**************************************************************************************************/
#include "dashboardscreen.hpp"
#include <iostream>
#include <memory>
// view
#include <informationscreen.hpp>
#include <screencommon.hpp>
Expand Down Expand Up @@ -110,7 +111,7 @@ DashboardScreen::Options DashboardScreen::getUserSelection() const {
} else if (userInput == "0") {
return Options::LOGOUT;
} else if (userInput == "1") {
return Options::USER_DETAILS;
return Options::USER_PROFILE;
} else if (userInput == "2") {
return Options::EMPLOYEE_MGMT;
} else if (userInput == "3") {
Expand All @@ -129,7 +130,7 @@ bool DashboardScreen::action(Options option, std::promise<defines::display>* nex
case Options::LANDING:
showLandingScreen();
break;
case Options::USER_DETAILS:
case Options::USER_PROFILE:
showUserInformation();
break;
case Options::INVALID:
Expand Down
24 changes: 6 additions & 18 deletions orchestra/application/screen/backoffice/dashboardscreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@
**************************************************************************************************/
#ifndef ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_DASHBOARDSCREEN_HPP_
#define ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_DASHBOARDSCREEN_HPP_
#include <future>
#include <memory>
#include <string>
// Core
#include <domain/dashboard/interface/dashboardiface.hpp>
#include <domain/dashboard/interface/dashboardviewif.hpp>
#include <screenbase.hpp>
#include <entity/user.hpp>
// Screens
#include "backofficescreenbase.hpp"
#include <screeniface.hpp>

namespace screen {
namespace backoffice {

class DashboardScreen : public ScreenBase<domain::dashboard::DashboardControllerPtr>,
class DashboardScreen : public ScreenInterface,
public BackOfficeScreenBase<domain::dashboard::DashboardControllerPtr>,
public domain::dashboard::DashboardViewInterface {
public:
explicit DashboardScreen(const std::string& userID);
Expand All @@ -48,20 +50,6 @@ class DashboardScreen : public ScreenBase<domain::dashboard::DashboardController
private:
std::string mUserID;
entity::User mCurrentUser;
// Dashboard options - this represents the buttons in a GUI
enum class Options {
LANDING,
USER_DETAILS,
EMPLOYEE_MGMT,
INVENTORY_CTRL,
CUSTOMER_MGMT,
// add more enums here
LOGOUT,
APP_EXIT,
INVALID
// Warning! Don't add anything here.
// New enum values must be added before LOGOUT
};
void menuSelection(std::promise<defines::display>* promise) const;
void showLandingScreen() const;
void showOptions() const;
Expand Down
23 changes: 12 additions & 11 deletions orchestra/application/screen/backoffice/empmgmtscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
#include "empmgmtscreen.hpp"
#include <functional>
#include <iostream>
#include <string>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <general.hpp> // pscore utility
// view
Expand All @@ -35,7 +36,7 @@ namespace screen {
namespace backoffice {

// Employee fields
const std::vector<std::string> EmployeeMgmtScreen::employeeDomainFields {
const std::vector<std::string> DOMAIN_FIELDS {
"Person.First.Name",
"Person.Middle.Name",
"Person.Last.Name",
Expand Down Expand Up @@ -268,7 +269,7 @@ void EmployeeMgmtScreen::createEmployee() {
void EmployeeMgmtScreen::updateEmployee() {
showEmployeeInformation(true); // true - request to show the index # of each data
// Get the field to update
const std::string field = SCREENCOMMON().getUpdateField(employeeDomainFields);
const std::string field = SCREENCOMMON().getUpdateField(DOMAIN_FIELDS);
if (field.empty()) {
std::cout << "Invalid selection." << std::endl;
return;
Expand Down Expand Up @@ -315,14 +316,14 @@ EmployeeMgmtScreen::Options EmployeeMgmtScreen::getUserSelection() {
if (input < mTableHelper.getDataCount()) {
// Store user input as the selected index (zero based)
mTableHelper.setCurrentIndex(input);
return Options::EMPLOYEE_DETAILS;
return Options::OP_READ;
}
} else if (userInput == "c" && !isShowingDetailsScreen) {
return Options::EMPLOYEE_CREATE;
return Options::OP_CREATE;
} else if (userInput == "u" && isShowingDetailsScreen) {
return Options::EMPLOYEE_UPDATE;
return Options::OP_UPDATE;
} else if (userInput == "d" && isShowingDetailsScreen) {
return Options::EMPLOYEE_REMOVE;
return Options::OP_DELETE;
} // add more options here

// Default invalid option
Expand All @@ -342,21 +343,21 @@ bool EmployeeMgmtScreen::action(Options option, std::promise<defines::display>*
case Options::INVALID:
invalidOptionSelected();
break;
case Options::EMPLOYEE_DETAILS:
case Options::OP_READ:
showEmployeeInformation();
isShowingDetailsScreen = true; // Must set to true
break;
case Options::EMPLOYEE_CREATE:
case Options::OP_CREATE:
createEmployee();
// Get the employees from Core then cache the list
queryEmployeesList();
showLandingScreen();
break;
case Options::EMPLOYEE_UPDATE:
case Options::OP_UPDATE:
updateEmployee();
showEmployeeInformation(); // refresh employee details screen
break;
case Options::EMPLOYEE_REMOVE:
case Options::OP_DELETE:
removeEmployee();
action(Options::LANDING, nextScreen);
break;
Expand Down
32 changes: 7 additions & 25 deletions orchestra/application/screen/backoffice/empmgmtscreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@
**************************************************************************************************/
#ifndef ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_EMPMGMTSCREEN_HPP_
#define ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_EMPMGMTSCREEN_HPP_
#include <future>
#include <memory>
#include <string>
#include <vector>
#include <domain/employeemgmt/interface/employeemgmtviewif.hpp>
#include <screenbase.hpp>
#include <tablehelper.hpp>
// core
// Core
#include <domain/employeemgmt/interface/employeemgmtiface.hpp>
// data
#include <domain/employeemgmt/interface/employeemgmtviewif.hpp>
#include <employeedata.hpp>
// Screens
#include "backofficescreenbase.hpp"
#include <screeniface.hpp>

namespace screen {
namespace backoffice {

class EmployeeMgmtScreen : public ScreenBase<domain::empmgmt::EmpMgmtControllerPtr>,
class EmployeeMgmtScreen : public ScreenInterface,
public BackOfficeScreenBase<domain::empmgmt::EmpMgmtControllerPtr>,
public domain::empmgmt::EmployeeMgmtViewInterface {
public:
EmployeeMgmtScreen();
Expand All @@ -54,21 +53,6 @@ class EmployeeMgmtScreen : public ScreenBase<domain::empmgmt::EmpMgmtControllerP
const std::string& userID) override;

private:
// Screen options - this represents the buttons in a GUI
enum class Options {
LANDING,
DASHBOARD,
EMPLOYEE_DETAILS,
EMPLOYEE_CREATE,
EMPLOYEE_REMOVE,
EMPLOYEE_UPDATE,
// add more enums here
LOGOUT,
APP_EXIT,
INVALID
// Warning! Don't add anything here.
// New enum values must be added before LOGOUT
};
void showLandingScreen() const;
void showEmployees() const;
void showOptions() const;
Expand All @@ -82,10 +66,8 @@ class EmployeeMgmtScreen : public ScreenBase<domain::empmgmt::EmpMgmtControllerP
void removeEmployee();
void fillEmployeeInformation(entity::Employee* employee,
const std::vector<std::string>& requiredFields = {}) const;

app::utility::TableHelper<entity::Employee> mTableHelper;
bool isShowingDetailsScreen;
static const std::vector<std::string> employeeDomainFields;
};

} // namespace backoffice
Expand Down
Loading

0 comments on commit a90a325

Please sign in to comment.