summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-10-01 00:38:20 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-10-01 00:38:20 +0200
commit8635603e2f4f8b61026f69532f3cda51bd711f91 (patch)
treefb7b7bd6ef019f451cf6acc4f439790c8d38c12b /src/Client
parent1a43fad56dc945c72a4ab711d2c9ff6d1a5a1502 (diff)
downloadmad-8635603e2f4f8b61026f69532f3cda51bd711f91.tar
mad-8635603e2f4f8b61026f69532f3cda51bd711f91.zip
UserListCommands: import: Edit column names before saving the list
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/UserListCommands.cpp59
-rw-r--r--src/Client/XLSSheet.h4
2 files changed, 56 insertions, 7 deletions
diff --git a/src/Client/UserListCommands.cpp b/src/Client/UserListCommands.cpp
index 581b060..1da2d38 100644
--- a/src/Client/UserListCommands.cpp
+++ b/src/Client/UserListCommands.cpp
@@ -236,18 +236,50 @@ void UserListCommands::importCommand(CommandParser *commandParser, const std::ve
std::cout << "Imported worksheet:" << std::endl;
printSheet(**sheet, 10);
- std::cout << std::endl << std::endl;
+ std::cout << std::endl;
std::cout << "Does the first line of the worksheet contain the column names? (Y/n) " << std::flush;
Core::String input = Core::String::getline(std::cin);
+ std::cout << std::endl << std ::endl;
input.toLower();
if(input.isEmpty() || input[0] != 'n') {
(*sheet)->useFirstRowAsColumnNames(true);
+ printSheet(**sheet, 10);
+ }
+ else {
+ printSheet(**sheet, 5);
}
+ std::cout << std::endl;
- std::cout << std::endl << std ::endl;
- printSheet(**sheet, 10);
- std::cout << std::endl << std ::endl;
+ while(true) {
+ std::cout << "Edit column names:" << std::endl << std::endl;
+
+ for(unsigned i = 0; i < (*sheet)->getColumnCount(); ++i) {
+ std::cout << "[" << i+1 << "] " << (*sheet)->getColumnName(i) << std::endl;
+ }
+
+ std::cout << std::endl;
+ std::cout << "Enter number of column to edit or press <enter> to save the user list: " << std::flush;
+ input = Core::String::getline(std::cin);
+ if(input.isEmpty())
+ break;
+
+ unsigned col = strtoul(input.toString().c_str(), 0, 10);
+ if(col < 1 || col > (*sheet)->getColumnCount()) {
+ std::cout << "Invalid input. " << std::endl << std::endl;
+ printSheet(**sheet, 5);
+ std::cout << std::endl;
+ continue;
+ }
+
+ std::cout << "Enter the new name for column " << col << ". An empty name will mark the column for deletion" << std::endl;
+ std::cout << "New name: " << std::flush;
+ input = Core::String::getline(std::cin);
+ (*sheet)->setColumnName(col-1, input);
+
+ printSheet(**sheet, 5);
+ std::cout << std::endl;
+ }
boost::shared_ptr<Common::UserLists::UserList> userList(new Common::UserLists::UserList);
const std::vector<XLSSheet::RowType> &rows = (*sheet)->getRows();
@@ -262,7 +294,8 @@ void UserListCommands::importCommand(CommandParser *commandParser, const std::ve
entry.setName(stream.str().c_str());
for(unsigned col = 0; col < (*sheet)->getColumnCount(); ++col) {
- entry.setDetail((*sheet)->getColumnName(col), row[col]);
+ if(!(*sheet)->getColumnName(col).isEmpty())
+ entry.setDetail((*sheet)->getColumnName(col), row[col]);
}
userList->addUser(entry);
@@ -395,11 +428,17 @@ void UserListCommands::printUserList(const Common::UserLists::UserList &list) {
}
void UserListCommands::printSheet(const XLSSheet &sheet, unsigned rowCount) {
+ static const Core::String DELETE = "<delete>";
+
const std::vector<XLSSheet::RowType> &rows = sheet.getRows();
std::vector<boost::int32_t> lengths(sheet.getColumnCount());
for(unsigned col = 0; col < sheet.getColumnCount(); ++col) {
- lengths[col] = sheet.getColumnName(col).length();
+ boost::int32_t length = sheet.getColumnName(col).length();
+ if(length > 0)
+ lengths[col] = length;
+ else
+ lengths[col] = DELETE.length();
}
for(std::vector<XLSSheet::RowType>::const_iterator rowIt = rows.begin(); rowIt != rows.end() && (rowCount == 0 || rowIt != rows.begin()+rowCount); ++rowIt) {
@@ -413,7 +452,11 @@ void UserListCommands::printSheet(const XLSSheet &sheet, unsigned rowCount) {
for(unsigned col = 0; col < sheet.getColumnCount(); ++col) {
std::cout << " ";
- printPadded(sheet.getColumnName(col), lengths[col]);
+
+ if(!sheet.getColumnName(col).isEmpty())
+ printPadded(sheet.getColumnName(col), lengths[col]);
+ else
+ printPadded(DELETE, lengths[col]);
}
std::cout << std::endl;
@@ -441,6 +484,8 @@ void UserListCommands::printSheet(const XLSSheet &sheet, unsigned rowCount) {
std::cout << " ";
printPadded("...", lengths[col]);
}
+
+ std::cout << std::endl;
}
}
diff --git a/src/Client/XLSSheet.h b/src/Client/XLSSheet.h
index 0960fc0..8cd06e2 100644
--- a/src/Client/XLSSheet.h
+++ b/src/Client/XLSSheet.h
@@ -80,6 +80,10 @@ class MAD_CLIENT_EXPORT XLSSheet : private boost::noncopyable {
return colNames[col];
}
+ void setColumnName(unsigned col, const Core::String &name) {
+ colNames[col] = name;
+ }
+
const std::vector<RowType>& getRows() const {
return rows;
}