Skip to content

Commit

Permalink
Implemented remove action.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarum9in committed Jun 11, 2015
1 parent 04b7ffd commit 0eaecbf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 55 deletions.
22 changes: 0 additions & 22 deletions include/mon/web/content/remove.hpp

This file was deleted.

1 change: 1 addition & 0 deletions include/mon/web/content/show.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace content {

struct show : base_form {
struct agent {
std::uint64_t id;
std::string name;
std::string target;
std::vector<CheckResponse> stats;
Expand Down
19 changes: 16 additions & 3 deletions src/web/monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <mon/web/content/edit.hpp>
#include <mon/web/content/error.hpp>
#include <mon/web/content/remove.hpp>
#include <mon/web/content/show.hpp>

#include <cppcms/url_dispatcher.h>
Expand Down Expand Up @@ -111,8 +110,21 @@ void monitor::edit(const std::string agent_id) {
void monitor::remove() {
cppdb::session sql(m_db_pool->open());
if (request().request_method() == "POST") {
content::remove data;
render("remove", data);

const std::string agent_id = request().post("agent_id");
if (!agent_id.empty()) {
sql << "DELETE FROM agents "
"WHERE id = ?"
<< agent_id
<< cppdb::exec;
response().status(cppcms::http::response::ok);
} else {
response().status(cppcms::http::response::not_found);
content::error error;
error.brief = translate("Invalid request");
error.message = translate("agent_id is not set");
render("error", error);
}
} else {
response().status(cppcms::http::response::method_not_allowed);
content::error error;
Expand Down Expand Up @@ -144,6 +156,7 @@ void monitor::show() {
std::string name;
std::string target;
result >> id >> name >> target;
agents[id].id = id;
agents[id].name = name;
agents[id].target = target;
agents[id].stats.resize(data.plugins.size());
Expand Down
10 changes: 10 additions & 0 deletions static/plain/remove_agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function remove_agent(agent_id)
{
$.post("remove", {
agent_id: agent_id
}).done(function(data) {
$("#agent_" + agent_id).remove();
}).fail(function(data) {
alert("Unable to remove agent id = " + agent_id);
});
}
28 changes: 0 additions & 28 deletions view/plain/remove.tmpl

This file was deleted.

11 changes: 9 additions & 2 deletions view/plain/show.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<% template subtitle() %>
<% gt "show" %>
<% end template %>
<% template scripts() %>
<% include base_form::scripts() %>
<script src="/static/plain/remove_agent.js" type="text/javascript"></script>
<% end template %>
<% template form() %>
<h3><% gt "Agent statistics" %></h3>
<% foreach agent in agents %>
Expand All @@ -19,8 +23,11 @@
<% end %>
</tr>
<% item %>
<tr>
<td><%= agent.name %></td>
<tr id="agent_<%= agent.id %>">
<td><%= agent.name %>
<button title="Remove agent"
onclick="remove_agent(<%= agent.id %>)">x</button>
</td>
<td><%= agent.target %></td>
<% foreach stat in agent.stats %>
<% item %>
Expand Down

0 comments on commit 0eaecbf

Please sign in to comment.