Added support of optional header names when importing CSV file.
This commit is contained in:
@ -52,6 +52,11 @@ bool CsvParser::isCsvCompatible(const rapidcsv::Document& doc) {
|
||||
qInfo() << "Checking CSV document for compatiblity...";
|
||||
const std::vector<std::string> columnNames = doc.GetColumnNames();
|
||||
for (const QString& headerName : GET_HEADER_NAMES()) {
|
||||
if (OPTIONAL_CSV_HEADERS.contains(headerName)) {
|
||||
/// no need to have a column for the optional values
|
||||
continue;
|
||||
}
|
||||
/// these column must be found in CSV document
|
||||
bool isHeaderNameFound = false;
|
||||
if (std::find(columnNames.begin(), columnNames.end(), headerName) != columnNames.end()) {
|
||||
qDebug() << QString("Header found in column names: %1").arg(headerName);
|
||||
@ -86,14 +91,13 @@ QHash<QString, std::vector<std::string>> CsvParser::extractColumnValues(
|
||||
const rapidcsv::Document& doc) {
|
||||
QHash<QString, std::vector<std::string>> columnValueMap;
|
||||
for (const QString& columnName : headerNames) {
|
||||
// TODO add support for optional columns
|
||||
// if (optionalCsvHeaderNames.contains(columnName)) {
|
||||
// const std::vector<std::string> columnNames = doc.GetColumnNames();
|
||||
// int columnIdx = doc.GetColumnIdx(columnName.toStdString());
|
||||
// if (columnIdx == -1) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
if (OPTIONAL_CSV_HEADERS.contains(columnName)) {
|
||||
const std::vector<std::string> columnNames = doc.GetColumnNames();
|
||||
int columnIdx = doc.GetColumnIdx(columnName.toStdString());
|
||||
if (columnIdx == -1) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const std::vector<std::string> columnValues =
|
||||
doc.GetColumn<std::string>(columnName.toStdString());
|
||||
columnValueMap.insert(columnName, columnValues);
|
||||
|
||||
@ -34,8 +34,8 @@ enum UserRoles {
|
||||
static UserRoles DEFAULT_ROLE = FullNameRole;
|
||||
// TODO ?rename USER_FACING_ROLES -> MAIN_ROLES ?
|
||||
static QList<UserRoles> USER_FACING_ROLES = {
|
||||
LastNameRole, FirstNameRole, MembershipNumberRole, Bidding1Role, Bidding2Role,
|
||||
Bidding3Role, DepotWish1Role, DepotWish2Role, ShareAmountRole, MailRole,
|
||||
LastNameRole, FirstNameRole, MembershipNumberRole, Bidding1Role, Bidding2Role,
|
||||
Bidding3Role, DepotWish1Role, DepotWish2Role, ShareAmountRole, MailRole,
|
||||
ShareTypeRole, BiddingTypeRole, OnlineIdRole, AccessCodeRole};
|
||||
static QHash<int, QByteArray> ROLE_NAMES = {{MembershipNumberRole, "Mitglieds-nr."},
|
||||
{LastNameRole, "Name"},
|
||||
@ -56,8 +56,8 @@ static QHash<int, QByteArray> ROLE_NAMES = {{MembershipNumberRole, "Mitglieds-nr
|
||||
static const QList<QString> SHARE_TYPES = {"bezahlt", "teils/teils", "erarbeitet", ""};
|
||||
static const QList<QString> BIDDING_TYPES = {"paper", "digital", "online", "offline", ""};
|
||||
|
||||
static QList<UserRoles> STRING_ROLES = {LastNameRole, FirstNameRole, DepotWish1Role,
|
||||
DepotWish2Role, MailRole, ShareTypeRole,
|
||||
static QList<UserRoles> STRING_ROLES = {LastNameRole, FirstNameRole, DepotWish1Role,
|
||||
DepotWish2Role, MailRole, ShareTypeRole,
|
||||
BiddingTypeRole, OnlineIdRole, AccessCodeRole};
|
||||
static QList<UserRoles> INT_ROLES = {
|
||||
MembershipNumberRole,
|
||||
@ -69,10 +69,12 @@ static QList<UserRoles> DOUBLE_ROLES = {
|
||||
ShareAmountRole,
|
||||
};
|
||||
|
||||
static const QList<UserRoles> TYPE_ROLES = {ShareTypeRole, BiddingTypeRole};
|
||||
static const QList<UserRoles> TYPE_ROLES = {ShareTypeRole, BiddingTypeRole};
|
||||
static const QList<UserRoles> SHARE_TYPE_ROLES = {ShareTypeRole};
|
||||
static const QList<UserRoles> BIDDING_TYPE_ROLES = {BiddingTypeRole};
|
||||
|
||||
static const QStringList OPTIONAL_CSV_HEADERS = {"Bietart", "Online ID", "Access Code"};
|
||||
|
||||
/// JSON keys
|
||||
static const QString ITEMS_KEY_STRING = "items";
|
||||
static const QString ITEM_KEY_STRING = "item";
|
||||
|
||||
Reference in New Issue
Block a user