Changeset - 144ccb07e8e2
[Not reviewed]
0 2 0
Jan Kaluza - 10 years ago 2016-01-28 09:23:41
jkaluza@redhat.com
Web interface: Fix missing ',' in app.js
2 files changed with 5 insertions and 1 deletions:
0 comments (0 inline, 0 general)
spectrum_manager/src/APIServer.cpp
Show inline comments
 
@@ -107,96 +107,100 @@ void APIServer::serve_instances(Server *server, Server::session *session, struct
 
		bool running = true;
 
		if (status.find("Running") == std::string::npos) {
 
			running = false;
 
		}
 
		instance.AddMember("running", running, json.GetAllocator());
 

	
 
		UserInfo info;
 
		m_storage->getUser(session->user, info);
 
		std::string username = "";
 
		int type = (int) TYPE_STRING;
 
		m_storage->getUserSetting(info.id, id, type, username);
 

	
 
		usernames.push_back(username);
 
		instance.AddMember("registered", !username.empty(), json.GetAllocator());
 
		instance.AddMember("username", usernames.back().c_str(), json.GetAllocator());
 
		instance.AddMember("frontend", is_slack(m_config, id) ? "slack" : "xmpp", json.GetAllocator());
 

	
 
		instances.PushBack(instance, json.GetAllocator());
 
	}
 

	
 
	json.AddMember("instances", instances, json.GetAllocator());
 
	send_json(conn, json);
 
}
 

	
 
void APIServer::serve_instances_list_rooms(Server *server, Server::session *session, struct mg_connection *conn, struct http_message *hm) {
 
	std::string uri(hm->uri.p, hm->uri.len);
 
	std::string instance = uri.substr(uri.rfind("/") + 1);
 

	
 
	UserInfo info;
 
	m_storage->getUser(session->user, info);
 

	
 
	std::string username = "";
 
	int type = (int) TYPE_STRING;
 
	m_storage->getUserSetting(info.id, instance, type, username);
 

	
 
	if (username.empty()) {
 
		send_ack(conn, true, "You are not registered to this Spectrum 2 instance.");
 
		return;
 
	}
 

	
 
	std::string response = server->send_command(instance, "list_rooms " + username);
 

	
 
	std::vector<std::string> commands;
 
	boost::split(commands, response, boost::is_any_of("\n"));
 

	
 
	Document json;
 
	json.SetObject();
 
	json.AddMember("error", 0, json.GetAllocator());
 
	json.AddMember("name_label", "Nickname in 3rd-party room", json.GetAllocator());
 
	json.AddMember("legacy_room_label", "3rd-party room name", json.GetAllocator());
 
	json.AddMember("legacy_server_label", "3rd-party server", json.GetAllocator());
 
	json.AddMember("frontend_room_label", "Slack channel", json.GetAllocator());
 

	
 
	std::vector<std::vector<std::string> > tmp;
 
	Value rooms(kArrayType);
 
	BOOST_FOREACH(const std::string &command, commands) {
 
		if (command.size() > 5) {
 
			std::vector<std::string> args2;
 
			boost::split(args2, command, boost::is_any_of(" "));
 
			if (args2.size() == 6) {
 
				tmp.push_back(args2);
 
				Value room;
 
				room.SetObject();
 
				room.AddMember("name", tmp.back()[2].c_str(), json.GetAllocator());
 
				room.AddMember("legacy_room", tmp.back()[3].c_str(), json.GetAllocator());
 
				room.AddMember("legacy_server", tmp.back()[4].c_str(), json.GetAllocator());
 
				room.AddMember("frontend_room", tmp.back()[5].c_str(), json.GetAllocator());
 
				rooms.PushBack(room, json.GetAllocator());
 
			}
 
		}
 
	}
 

	
 
	json.AddMember("rooms", rooms, json.GetAllocator());
 
	send_json(conn, json);
 
}
 

	
 
void APIServer::serve_instances_start(Server *server, Server::session *session, struct mg_connection *conn, struct http_message *hm) {
 
	ALLOW_ONLY_ADMIN();
 

	
 
	std::string uri(hm->uri.p, hm->uri.len);
 
	std::string instance = uri.substr(uri.rfind("/") + 1);
 
	start_instances(m_config, instance);
 
	std::string response = get_response();
 

	
 
	// TODO: So far it needs some time to reload Spectrum 2, so just sleep here.
 
	sleep(1);
 

	
 
	send_ack(conn, response.find("OK") == std::string::npos, response);
 
}
 

	
 
void APIServer::serve_instances_stop(Server *server, Server::session *session, struct mg_connection *conn, struct http_message *hm) {
 
	ALLOW_ONLY_ADMIN();
 

	
 
	std::string uri(hm->uri.p, hm->uri.len);
 
	std::string instance = uri.substr(uri.rfind("/") + 1);
 
	stop_instances(m_config, instance);
 
	std::string response = get_response();
 
	send_ack(conn, response.find("OK") == std::string::npos, response);
 
}
 

	
spectrum_manager/src/html/js/app.js
Show inline comments
 
@@ -92,97 +92,97 @@ function show_list_rooms() {
 
				var url = $(this).attr('href');
 
				$.get(url, function(data) {
 
					show_instances();
 
				});
 
			})
 
		});
 
	});
 
}
 

	
 
function show_users() {
 
	var admin = $.cookie("admin") == "1";
 
	if (!admin) {
 
		$("#main_content").html("<h2>List of Spectrum 2 users</h2><p>Only administrator can list the users.</p>");
 
		return;
 
	}
 

	
 
	$.get($.cookie("base_location") + "api/v1/users", function(data) {
 
		$("#main_content").html("<h2>List of Spectrum 2 users</h2><p>You can add new users <a href=\"register.shtml?back_to_list=1\">here</a>.</p><table id='main_result'><tr><th>Name<th>Actions</th></tr>");
 

	
 
		$.each(data.users, function(i, user) {
 
			var row = '<tr>'
 
			row += '<td>' + user.username + '</td>'
 
			row += '<td><a class="button_command" href="' + $.cookie("base_location") +  'api/v1/users/remove/' + user.username + '">remove</a></td></tr>';
 
			$("#main_result  > tbody:last-child").append(row);
 
			$(".button_command").click(function(e) {
 
				e.preventDefault();
 
				$(this).parent().empty().progressbar( {value: false} ).css('height', '1em');
 

	
 
				var url = $(this).attr('href');
 
				$.get(url, function(data) {
 
					show_users();
 
				});
 
			})
 
		});
 
	});
 
}
 

	
 
function fill_instances_join_room_form() {
 
	var query = getQueryParams(document.location.search);
 
	$("#instance").attr("value", query.id);
 

	
 
	$(".button_command").click(function(e) {
 
		e.preventDefault();
 
		$(this).parent().empty().progressbar( {value: false} ).css('height', '1em');
 

	
 
		var postdata ={
 
			"name": $("#name").val(),
 
			"legacy_room": $("#legacy_room").val(),
 
			"legacy_server": $("#legacy_server").val()
 
			"legacy_server": $("#legacy_server").val(),
 
			"frontend_room": $("#frontend_room").val()
 
		};
 

	
 
		$.post($.cookie("base_location") + "api/v1/instances/join_room/" + $("#instance").val(), postdata, function(data) {
 
			window.location.replace("index.shtml");
 
		});
 
	})
 
	
 
	$.get($.cookie("base_location") + "api/v1/instances/join_room_form/" + query.id, function(data) {
 
		$("#name_desc").html(data.name_label + ":");
 
		$("#legacy_room_desc").html(data.legacy_room_label + ":");
 
		$("#legacy_server_desc").html(data.legacy_server_label + ":");
 
		$("#frontend_room_desc").html(data.frontend_room_label + ":");
 

	
 
		$("#name").attr("placeholder", data.name_label + ":");
 
		$("#legacy_room").attr("placeholder", data.legacy_room_label + ":");
 
		$("#legacy_server").attr("placeholder", data.legacy_server_label + ":");
 
		$("#frontend_room").attr("placeholder", data.frontend_room_label + ":");
 
	});
 
}
 

	
 
function fill_instances_register_form() {
 
	var query = getQueryParams(document.location.search);
 
	$("#instance").attr("value", query.id);
 

	
 
	$(".button_command").click(function(e) {
 
		e.preventDefault();
 
		$(this).parent().empty().progressbar( {value: false} ).css('height', '1em');
 

	
 
		var postdata ={
 
			"jid": $("#jid").val(),
 
			"uin": $("#uin").val(),
 
			"password": $("#password").val()
 
		};
 

	
 
		$.post($.cookie("base_location") + "api/v1/instances/register/" + $("#instance").val(), postdata, function(data) {
 
			if (data.oauth2_url) {
 
				window.location.replace(data.oauth2_url);
 
			}
 
			else {
 
				window.location.replace("index.shtml");
 
			}
 
		});
 
	})
 
	
 
	$.get($.cookie("base_location") + "api/v1/instances/register_form/" + query.id, function(data) {
 
		$("#jid_desc").html(data.username_label + ":");
 
		$("#uin_desc").html(data.legacy_username_label + ":");
0 comments (0 inline, 0 general)