From a90a32563ca03af40152a693941729c7028f544d Mon Sep 17 00:00:00 2001 From: benzgar Date: Wed, 13 Jan 2021 20:29:05 -0500 Subject: [PATCH] - Created backoffice base class --- orchestra/application/CMakeLists.txt | 4 +- .../backofficescreenbase.hpp} | 37 ++++++++++++++++++- .../screen/backoffice/customermgmtscreen.cpp | 20 +++++----- .../screen/backoffice/customermgmtscreen.hpp | 31 ++++------------ .../screen/backoffice/dashboardscreen.cpp | 5 ++- .../screen/backoffice/dashboardscreen.hpp | 24 +++--------- .../screen/backoffice/empmgmtscreen.cpp | 23 ++++++------ .../screen/backoffice/empmgmtscreen.hpp | 32 ++++------------ .../screen/backoffice/inventoryscreen.cpp | 22 ++++++----- .../screen/backoffice/inventoryscreen.hpp | 31 ++++------------ .../application/screen/login/loginscreen.cpp | 8 ++-- .../application/screen/login/loginscreen.hpp | 7 ++-- .../{screenbase.hpp => screeniface.hpp} | 18 ++++----- 13 files changed, 115 insertions(+), 147 deletions(-) rename orchestra/application/screen/{screenbase.cpp => backoffice/backofficescreenbase.hpp} (67%) rename orchestra/application/screen/{screenbase.hpp => screeniface.hpp} (84%) diff --git a/orchestra/application/CMakeLists.txt b/orchestra/application/CMakeLists.txt index 00e3738b..5fae4094 100644 --- a/orchestra/application/CMakeLists.txt +++ b/orchestra/application/CMakeLists.txt @@ -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 diff --git a/orchestra/application/screen/screenbase.cpp b/orchestra/application/screen/backoffice/backofficescreenbase.hpp similarity index 67% rename from orchestra/application/screen/screenbase.cpp rename to orchestra/application/screen/backoffice/backofficescreenbase.hpp index e89c0a46..02b0a08a 100644 --- a/orchestra/application/screen/screenbase.cpp +++ b/orchestra/application/screen/backoffice/backofficescreenbase.hpp @@ -18,8 +18,41 @@ * Ben Ziv * * * **************************************************************************************************/ -#include "screenbase.hpp" +#ifndef ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_BACKOFFICESCREENBASE_HPP_ +#define ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_BACKOFFICESCREENBASE_HPP_ +#include namespace screen { -} // namespace screen \ No newline at end of file +template +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_ \ No newline at end of file diff --git a/orchestra/application/screen/backoffice/customermgmtscreen.cpp b/orchestra/application/screen/backoffice/customermgmtscreen.cpp index d362e3db..bff1804d 100644 --- a/orchestra/application/screen/backoffice/customermgmtscreen.cpp +++ b/orchestra/application/screen/backoffice/customermgmtscreen.cpp @@ -34,7 +34,7 @@ namespace screen { namespace backoffice { // Customer fields -const std::vector CustomerMgmtScreen::domainFields { +const std::vector DOMAIN_FIELDS { "Person.First.Name", "Person.Middle.Name", "Person.Last.Name", @@ -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; @@ -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 @@ -281,20 +281,20 @@ bool CustomerMgmtScreen::action(Options option, std::promise* 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; diff --git a/orchestra/application/screen/backoffice/customermgmtscreen.hpp b/orchestra/application/screen/backoffice/customermgmtscreen.hpp index 537c49b9..5dd8c425 100644 --- a/orchestra/application/screen/backoffice/customermgmtscreen.hpp +++ b/orchestra/application/screen/backoffice/customermgmtscreen.hpp @@ -20,22 +20,21 @@ **************************************************************************************************/ #ifndef ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_CUSTOMERMGMTSCREEN_HPP_ #define ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_CUSTOMERMGMTSCREEN_HPP_ -#include -#include #include #include -#include -#include -#include -// core +// Core #include -// data +#include #include +// Screens +#include "backofficescreenbase.hpp" +#include namespace screen { namespace backoffice { -class CustomerMgmtScreen : public screen::ScreenBase, +class CustomerMgmtScreen : public screen::ScreenInterface, + public BackOfficeScreenBase, public domain::customermgmt::CustomerManagementViewInterface { public: CustomerMgmtScreen(); @@ -49,21 +48,6 @@ class CustomerMgmtScreen : public screen::ScreenBase mTableHelper; bool isShowingDetailsScreen; - static const std::vector domainFields; }; } // namespace backoffice diff --git a/orchestra/application/screen/backoffice/dashboardscreen.cpp b/orchestra/application/screen/backoffice/dashboardscreen.cpp index 8a06d680..60aec4e7 100644 --- a/orchestra/application/screen/backoffice/dashboardscreen.cpp +++ b/orchestra/application/screen/backoffice/dashboardscreen.cpp @@ -20,6 +20,7 @@ **************************************************************************************************/ #include "dashboardscreen.hpp" #include +#include // view #include #include @@ -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") { @@ -129,7 +130,7 @@ bool DashboardScreen::action(Options option, std::promise* nex case Options::LANDING: showLandingScreen(); break; - case Options::USER_DETAILS: + case Options::USER_PROFILE: showUserInformation(); break; case Options::INVALID: diff --git a/orchestra/application/screen/backoffice/dashboardscreen.hpp b/orchestra/application/screen/backoffice/dashboardscreen.hpp index 6e6ce439..90cb082c 100644 --- a/orchestra/application/screen/backoffice/dashboardscreen.hpp +++ b/orchestra/application/screen/backoffice/dashboardscreen.hpp @@ -20,18 +20,20 @@ **************************************************************************************************/ #ifndef ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_DASHBOARDSCREEN_HPP_ #define ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_DASHBOARDSCREEN_HPP_ -#include -#include #include +// Core #include #include -#include #include +// Screens +#include "backofficescreenbase.hpp" +#include namespace screen { namespace backoffice { -class DashboardScreen : public ScreenBase, +class DashboardScreen : public ScreenInterface, + public BackOfficeScreenBase, public domain::dashboard::DashboardViewInterface { public: explicit DashboardScreen(const std::string& userID); @@ -48,20 +50,6 @@ class DashboardScreen : public ScreenBase* promise) const; void showLandingScreen() const; void showOptions() const; diff --git a/orchestra/application/screen/backoffice/empmgmtscreen.cpp b/orchestra/application/screen/backoffice/empmgmtscreen.cpp index af442cbb..681dc41f 100644 --- a/orchestra/application/screen/backoffice/empmgmtscreen.cpp +++ b/orchestra/application/screen/backoffice/empmgmtscreen.cpp @@ -21,8 +21,9 @@ #include "empmgmtscreen.hpp" #include #include -#include #include +#include +#include #include #include // pscore utility // view @@ -35,7 +36,7 @@ namespace screen { namespace backoffice { // Employee fields -const std::vector EmployeeMgmtScreen::employeeDomainFields { +const std::vector DOMAIN_FIELDS { "Person.First.Name", "Person.Middle.Name", "Person.Last.Name", @@ -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; @@ -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 @@ -342,21 +343,21 @@ bool EmployeeMgmtScreen::action(Options option, std::promise* 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; diff --git a/orchestra/application/screen/backoffice/empmgmtscreen.hpp b/orchestra/application/screen/backoffice/empmgmtscreen.hpp index 41c7e49f..c9eedfcc 100644 --- a/orchestra/application/screen/backoffice/empmgmtscreen.hpp +++ b/orchestra/application/screen/backoffice/empmgmtscreen.hpp @@ -20,22 +20,21 @@ **************************************************************************************************/ #ifndef ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_EMPMGMTSCREEN_HPP_ #define ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_EMPMGMTSCREEN_HPP_ -#include -#include #include #include -#include -#include -#include -// core +// Core #include -// data +#include #include +// Screens +#include "backofficescreenbase.hpp" +#include namespace screen { namespace backoffice { -class EmployeeMgmtScreen : public ScreenBase, +class EmployeeMgmtScreen : public ScreenInterface, + public BackOfficeScreenBase, public domain::empmgmt::EmployeeMgmtViewInterface { public: EmployeeMgmtScreen(); @@ -54,21 +53,6 @@ class EmployeeMgmtScreen : public ScreenBase& requiredFields = {}) const; - app::utility::TableHelper mTableHelper; bool isShowingDetailsScreen; - static const std::vector employeeDomainFields; }; } // namespace backoffice diff --git a/orchestra/application/screen/backoffice/inventoryscreen.cpp b/orchestra/application/screen/backoffice/inventoryscreen.cpp index 65d16115..96a22599 100644 --- a/orchestra/application/screen/backoffice/inventoryscreen.cpp +++ b/orchestra/application/screen/backoffice/inventoryscreen.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include // pscore utility // view #include @@ -34,7 +36,7 @@ namespace screen { namespace backoffice { // Product fields -const std::vector InventoryScreen::productDomainFields { +const std::vector DOMAIN_FIELDS { "Product.SKU", "Product.Name", "Product.Description", @@ -162,7 +164,7 @@ void InventoryScreen::createProduct() { void InventoryScreen::updateProduct() { showProductDetails(true); // true - request to show the index # of each data - const std::string field = SCREENCOMMON().getUpdateField(productDomainFields); + const std::string field = SCREENCOMMON().getUpdateField(DOMAIN_FIELDS); if (field.empty()) { std::cout << "Invalid selection." << std::endl; return; @@ -203,14 +205,14 @@ InventoryScreen::Options InventoryScreen::getUserSelection() { if (input < mTableHelper.getDataCount()) { // Store user input as the selected index (zero based) mTableHelper.setCurrentIndex(input); - return Options::PRODUCT_DETAILS; + return Options::OP_READ; } } else if (userInput == "d" && isShowingDetailsScreen) { - return Options::PRODUCT_REMOVE; + return Options::OP_DELETE; } else if (userInput == "c" && !isShowingDetailsScreen) { - return Options::PRODUCT_CREATE; + return Options::OP_CREATE; } else if (userInput == "u" && isShowingDetailsScreen) { - return Options::PRODUCT_UPDATE; + return Options::OP_UPDATE; } // add more options here // Default invalid option @@ -230,21 +232,21 @@ bool InventoryScreen::action(Options option, std::promise* nex case Options::INVALID: invalidOptionSelected(); break; - case Options::PRODUCT_DETAILS: + case Options::OP_READ: showProductDetails(); isShowingDetailsScreen = true; // Must set to true break; - case Options::PRODUCT_REMOVE: + case Options::OP_DELETE: removeProduct(); // Go back to landing screen after removing the product action(Options::LANDING, nextScreen); break; - case Options::PRODUCT_CREATE: + case Options::OP_CREATE: createProduct(); // Go back to landing screen after creating the product action(Options::LANDING, nextScreen); break; - case Options::PRODUCT_UPDATE: + case Options::OP_UPDATE: updateProduct(); showProductDetails(); // refresh details screen break; diff --git a/orchestra/application/screen/backoffice/inventoryscreen.hpp b/orchestra/application/screen/backoffice/inventoryscreen.hpp index 18d93eec..726fcb6f 100644 --- a/orchestra/application/screen/backoffice/inventoryscreen.hpp +++ b/orchestra/application/screen/backoffice/inventoryscreen.hpp @@ -20,22 +20,22 @@ **************************************************************************************************/ #ifndef ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_INVENTORYSCREEN_HPP_ #define ORCHESTRA_APPLICATION_SCREEN_BACKOFFICE_INVENTORYSCREEN_HPP_ -#include -#include #include #include +// Core #include -#include -#include -// core #include -// data #include +// Screens +#include "backofficescreenbase.hpp" +#include namespace screen { namespace backoffice { -class InventoryScreen : public screen::ScreenBase, +class InventoryScreen : public screen::ScreenInterface, + public BackOfficeScreenBase + , public domain::inventory::InventoryViewInterface { public: InventoryScreen(); @@ -49,21 +49,6 @@ class InventoryScreen : public screen::ScreenBase& requiredFields) const; - app::utility::TableHelper mTableHelper; bool isShowingDetailsScreen; - static const std::vector productDomainFields; }; } // namespace backoffice diff --git a/orchestra/application/screen/login/loginscreen.cpp b/orchestra/application/screen/login/loginscreen.cpp index a218ca9b..cb362562 100644 --- a/orchestra/application/screen/login/loginscreen.cpp +++ b/orchestra/application/screen/login/loginscreen.cpp @@ -54,10 +54,10 @@ void LoginScreen::show(std::promise* promise) { } bool LoginScreen::onLogin(const std::string& id, const std::string& pin) { - mCoreController = domain::login::createLoginModule( - std::make_shared(), - std::make_shared()); - return mCoreController->authenticate(id, pin); + domain::login::LoginControllerPtr coreController = domain::login::createLoginModule( + std::make_shared(), + std::make_shared()); + return coreController->authenticate(id, pin); } std::string LoginScreen::getUserID() const { diff --git a/orchestra/application/screen/login/loginscreen.hpp b/orchestra/application/screen/login/loginscreen.hpp index db220e9a..47056969 100644 --- a/orchestra/application/screen/login/loginscreen.hpp +++ b/orchestra/application/screen/login/loginscreen.hpp @@ -20,18 +20,17 @@ **************************************************************************************************/ #ifndef ORCHESTRA_APPLICATION_SCREEN_LOGIN_LOGINSCREEN_HPP_ #define ORCHESTRA_APPLICATION_SCREEN_LOGIN_LOGINSCREEN_HPP_ -#include #include +#include // core #include #include -#include +#include namespace screen { namespace login { -class LoginScreen : public screen::ScreenBase, - public domain::login::LoginViewIface { +class LoginScreen : public screen::ScreenInterface, public domain::login::LoginViewIface { public: LoginScreen() = default; ~LoginScreen() = default; diff --git a/orchestra/application/screen/screenbase.hpp b/orchestra/application/screen/screeniface.hpp similarity index 84% rename from orchestra/application/screen/screenbase.hpp rename to orchestra/application/screen/screeniface.hpp index c744a563..639cfc53 100644 --- a/orchestra/application/screen/screenbase.hpp +++ b/orchestra/application/screen/screeniface.hpp @@ -1,6 +1,6 @@ /************************************************************************************************** * PSCORE * -* Copyright (C) 2021 Pointon Software * +* Copyright (C) 2020 Pointon Software * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Affero General Public License as published * @@ -18,25 +18,21 @@ * Ben Ziv * * * **************************************************************************************************/ -#ifndef ORCHESTRA_APPLICATION_SCREEN_SCREENBASE_HPP_ -#define ORCHESTRA_APPLICATION_SCREEN_SCREENBASE_HPP_ +#ifndef ORCHESTRA_APPLICATION_SCREEN_SCREENIFACE_HPP_ +#define ORCHESTRA_APPLICATION_SCREEN_SCREENIFACE_HPP_ #include #include namespace screen { -template -class ScreenBase { +class ScreenInterface { public: - ScreenBase() = default; - virtual ~ScreenBase() = default; + ScreenInterface() = default; + virtual ~ScreenInterface() = default; virtual void show(std::promise* promise) = 0; - - protected: - ControllerType mCoreController; }; } // namespace screen -#endif // ORCHESTRA_APPLICATION_SCREEN_SCREENBASE_HPP_ \ No newline at end of file +#endif // ORCHESTRA_APPLICATION_SCREEN_SCREENIFACE_HPP_ \ No newline at end of file