From 6e1af765cdc057b6d227e5cfaaa16c84c7dabb59 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Sun, 6 Mar 2016 14:50:05 +0100 Subject: [PATCH] AdminInterface: Support labels for commands --- include/transport/AdminInterfaceCommand.h | 7 +++++- libtransport/AdminInterface.cpp | 24 ++++++++++++------- libtransport/AdminInterfaceCommand.cpp | 3 ++- .../src/frontends/slack/SlackUserManager.cpp | 9 ++++--- spectrum_manager/src/APIServer.cpp | 7 +++--- spectrum_manager/src/html/js/app.js | 2 +- 6 files changed, 35 insertions(+), 17 deletions(-) diff --git a/include/transport/AdminInterfaceCommand.h b/include/transport/AdminInterfaceCommand.h index 4383ab94..6a4da07f 100644 --- a/include/transport/AdminInterfaceCommand.h +++ b/include/transport/AdminInterfaceCommand.h @@ -69,7 +69,7 @@ class AdminInterfaceCommand { std::string example; }; - AdminInterfaceCommand(const std::string &name, Category category, Context context, AccessMode accessMode, Actions actions); + AdminInterfaceCommand(const std::string &name, Category category, Context context, AccessMode accessMode, Actions actions, const std::string &label = ""); virtual ~AdminInterfaceCommand() { } @@ -112,6 +112,10 @@ class AdminInterfaceCommand { return m_args; } + const std::string &getLabel() { + return m_label; + } + virtual std::string handleSetRequest(UserInfo &uinfo, User *user, std::vector &args); virtual std::string handleGetRequest(UserInfo &uinfo, User *user, std::vector &args); virtual std::string handleExecuteRequest(UserInfo &uinfo, User *user, std::vector &args); @@ -124,6 +128,7 @@ class AdminInterfaceCommand { Actions m_actions; std::string m_desc; std::list m_args; + std::string m_label; }; } diff --git a/libtransport/AdminInterface.cpp b/libtransport/AdminInterface.cpp index e7b518fa..2385a150 100644 --- a/libtransport/AdminInterface.cpp +++ b/libtransport/AdminInterface.cpp @@ -247,7 +247,8 @@ class ReloadCommand : public AdminInterfaceCommand { AdminInterfaceCommand::General, AdminInterfaceCommand::GlobalContext, AdminInterfaceCommand::AdminMode, - AdminInterfaceCommand::Execute) { + AdminInterfaceCommand::Execute, + "Reload Spectrum 2 configuration") { m_component = component; setDescription("Reloads config file"); } @@ -278,7 +279,7 @@ class HasOnlineUserCommand : public AdminInterfaceCommand { AdminInterfaceCommand::Users, AdminInterfaceCommand::GlobalContext, AdminInterfaceCommand::AdminMode, - AdminInterfaceCommand::Execute) { + AdminInterfaceCommand::Execute, "Has online user") { m_userManager = userManager; setDescription("Returns 1 if user is online"); addArg("username", "Username", "user@domain.tld"); @@ -703,7 +704,8 @@ class RegisterCommand : public AdminInterfaceCommand { AdminInterfaceCommand::Users, AdminInterfaceCommand::GlobalContext, AdminInterfaceCommand::UserMode, - AdminInterfaceCommand::Execute) { + AdminInterfaceCommand::Execute, + "Register") { m_userRegistration = userRegistration; setDescription("Registers the new user"); @@ -761,7 +763,8 @@ class UnregisterCommand : public AdminInterfaceCommand { AdminInterfaceCommand::Users, AdminInterfaceCommand::UserContext, AdminInterfaceCommand::UserMode, - AdminInterfaceCommand::Execute) { + AdminInterfaceCommand::Execute, + "Unregister") { m_userRegistration = userRegistration; setDescription("Unregisters existing user"); @@ -866,7 +869,8 @@ class HelpCommand : public AdminInterfaceCommand { AdminInterfaceCommand::General, AdminInterfaceCommand::GlobalContext, AdminInterfaceCommand::AdminMode, - AdminInterfaceCommand::Execute) { + AdminInterfaceCommand::Execute, + "Help") { m_commands = commands; setDescription("Shows help message"); } @@ -920,7 +924,8 @@ class CommandsCommand : public AdminInterfaceCommand { AdminInterfaceCommand::General, AdminInterfaceCommand::GlobalContext, AdminInterfaceCommand::AdminMode, - AdminInterfaceCommand::Execute) { + AdminInterfaceCommand::Execute, + "Available commands") { m_commands = commands; setDescription("Shows all the available commands with extended information."); } @@ -958,6 +963,8 @@ class CommandsCommand : public AdminInterfaceCommand { output += " Global"; } + output += " Label: \"" + (command->getLabel().empty() ? command->getName() : command->getLabel()) + "\""; + output += "\n"; } @@ -976,7 +983,8 @@ class VariablesCommand : public AdminInterfaceCommand { AdminInterfaceCommand::General, AdminInterfaceCommand::GlobalContext, AdminInterfaceCommand::AdminMode, - AdminInterfaceCommand::Execute) { + AdminInterfaceCommand::Execute, + "Available variables") { m_commands = commands; setDescription("Shows all the available variables."); } @@ -1040,7 +1048,7 @@ class ArgsCommand : public AdminInterfaceCommand { AdminInterfaceCommand::General, AdminInterfaceCommand::GlobalContext, AdminInterfaceCommand::AdminMode, - AdminInterfaceCommand::Execute) { + AdminInterfaceCommand::Execute, "Command's arguments") { m_commands = commands; setDescription("Shows descripton of arguments for command"); addArg("command", "Command", "register"); diff --git a/libtransport/AdminInterfaceCommand.cpp b/libtransport/AdminInterfaceCommand.cpp index 9a25726f..3143b64c 100644 --- a/libtransport/AdminInterfaceCommand.cpp +++ b/libtransport/AdminInterfaceCommand.cpp @@ -30,12 +30,13 @@ namespace Transport { -AdminInterfaceCommand::AdminInterfaceCommand(const std::string &name, Category category, Context context, AccessMode accessMode, Actions actions) { +AdminInterfaceCommand::AdminInterfaceCommand(const std::string &name, Category category, Context context, AccessMode accessMode, Actions actions, const std::string &label) { m_name = name; m_category = category; m_context = context; m_accessMode = accessMode; m_actions = actions; + m_label = label; } const std::string AdminInterfaceCommand::getCategoryName(Category category) { diff --git a/spectrum/src/frontends/slack/SlackUserManager.cpp b/spectrum/src/frontends/slack/SlackUserManager.cpp index fbe2802f..22298bad 100644 --- a/spectrum/src/frontends/slack/SlackUserManager.cpp +++ b/spectrum/src/frontends/slack/SlackUserManager.cpp @@ -49,7 +49,8 @@ class ListRoomsCommand : public AdminInterfaceCommand { AdminInterfaceCommand::Frontend, AdminInterfaceCommand::UserContext, AdminInterfaceCommand::UserMode, - AdminInterfaceCommand::Execute) { + AdminInterfaceCommand::Execute, + "List joined 3rd-party network rooms") { m_storageBackend = storageBackend; setDescription("List connected rooms"); } @@ -81,7 +82,8 @@ class JoinRoomCommand : public AdminInterfaceCommand { AdminInterfaceCommand::Frontend, AdminInterfaceCommand::UserContext, AdminInterfaceCommand::UserMode, - AdminInterfaceCommand::Execute) { + AdminInterfaceCommand::Execute, + "Join 3rd-party network room") { m_storageBackend = storageBackend; setDescription("Join the room"); @@ -140,7 +142,8 @@ class LeaveRoomCommand : public AdminInterfaceCommand { AdminInterfaceCommand::Frontend, AdminInterfaceCommand::UserContext, AdminInterfaceCommand::UserMode, - AdminInterfaceCommand::Execute) { + AdminInterfaceCommand::Execute, + "Leave 3rd-party network room") { m_storageBackend = storageBackend; setDescription("Leave the room"); diff --git a/spectrum_manager/src/APIServer.cpp b/spectrum_manager/src/APIServer.cpp index 2e5bd57a..c85a1a29 100644 --- a/spectrum_manager/src/APIServer.cpp +++ b/spectrum_manager/src/APIServer.cpp @@ -310,7 +310,7 @@ void APIServer::serve_instances_commands(Server *server, Server::session *sessio tokens.push_back(*beg); } - if (tokens.size() != 9) { + if (tokens.size() != 11) { continue; } @@ -337,6 +337,7 @@ void APIServer::serve_instances_commands(Server *server, Server::session *sessio cmd.AddMember("desc", tokens[2].c_str(), json.GetAllocator()); cmd.AddMember("category", tokens[4].c_str(), json.GetAllocator()); cmd.AddMember("context", tokens[8].c_str(), json.GetAllocator()); + cmd.AddMember("label", tokens[10].c_str(), json.GetAllocator()); cmds.PushBack(cmd, json.GetAllocator()); } @@ -422,7 +423,7 @@ void APIServer::serve_instances_command_args(Server *server, Server::session *se tokens.push_back(*beg); } - if (tokens.size() != 9) { + if (tokens.size() != 11) { continue; } @@ -524,7 +525,7 @@ void APIServer::serve_instances_execute(Server *server, Server::session *session tokens.push_back(*beg); } - if (tokens.size() != 9) { + if (tokens.size() != 11) { continue; } diff --git a/spectrum_manager/src/html/js/app.js b/spectrum_manager/src/html/js/app.js index 29064288..51dc1678 100644 --- a/spectrum_manager/src/html/js/app.js +++ b/spectrum_manager/src/html/js/app.js @@ -245,7 +245,7 @@ function show_instance() { $.get($.cookie("base_location") + "api/v1/instances/commands/" + query.id, function(data) { $.each(data.commands, function(i, command) { var row = '' - row += '' + command.name + ''; + row += '' + command.label + ''; row += '' + command.category + ''; row += '' + command.desc + ''; row += '';