Commit e41a85fd authored by Leigh B Stoller's avatar Leigh B Stoller

Rework this page to use a table.

parent 0d02e2e0
window.APT_OPTIONS.config();
require(['jquery', 'js/quickvm_sup',
// jQuery modules
'bootstrap'],
'tablesorter', 'tablesorterwidgets', 'bootstrap'],
function ($, sup)
{
'use strict';
......@@ -11,30 +10,63 @@ function ($, sup)
{
window.APT_OPTIONS.initialize(sup);
sup.UpdateProfileSelection($('#profile_name li[value = ' +
window.PROFILE + ']'));
$('#quickvm_topomodal').on('hidden.bs.modal', function() {
sup.ShowProfileList($('.current'))
});
$('button#profile').click(function (event) {
event.preventDefault();
sup.ShowModal('#quickvm_topomodal');
});
$('li.profile-item').click(function (event) {
event.preventDefault();
sup.ShowProfileList(event.target);
});
$('button#showtopo_select').click(function (event) {
event.preventDefault();
sup.UpdateProfileSelection($('.selected'));
sup.HideModal('#quickvm_topomodal');
});
// We have to get the selected profile from the hidden form variable.
$('a#instantiate').click(function (event) {
var table = $(".tablesorter")
.tablesorter({
theme : 'green',
//cssChildRow: "tablesorter-childRow",
// initialize zebra and filter widgets
widgets: ["zebra", "filter", "resizable"],
widgetOptions: {
// include child row content while filtering, if true
filter_childRows : true,
// include all columns in the search.
filter_anyMatch : true,
// class name applied to filter row and each input
filter_cssFilter : 'form-control',
// search from beginning
filter_startsWith : false,
// Set this option to false for case sensitive search
filter_ignoreCase : true,
// Only one search box.
filter_columnFilters : false,
}
});
// Target the $('.search') input using built in functioning
// this binds to the search using "search" and "keyup"
// Allows using filter_liveSearch or delayed search &
// pressing escape to cancel the search
$.tablesorter.filter.bindSearch( table, $('#profile_search') );
$('.showtopo_modal_button').click(function (event) {
event.preventDefault();
var profile = $('#selected_profile').attr('value');
window.location.replace("quickvm.php?profile=" + profile);
ShowTopology($(this).data("profile"));
});
}
function ShowTopology(profile)
{
var profile;
var index;
var callback = function(json) {
var xmlDoc = $.parseXML(json.value.rspec);
var xml = $(xmlDoc);
var topo = sup.ConvertManifestToJSON(profile, xml);
sup.ShowModal("#quickvm_topomodal");
// Subtract -2 cause of the border.
sup.maketopmap("#showtopo_nopicker",
($("#showtopo_nopicker").outerWidth() - 2),
300, topo);
};
var $xmlthing = sup.CallMethod("getprofile", null, 0, profile);
$xmlthing.done(callback);
}
$(document).ready(initialize);
......
......@@ -48,20 +48,37 @@ if (!$this_user) {
RedirectLoginPage();
exit();
}
if (!isset($target_user)) {
$target_user = $this_user;
}
if (!$this_user->SameUser($target_user)) {
if (!ISADMIN()) {
if (isset($ajax_request)) {
SPITAJAX_ERROR(1, "You do not have permission to do this");
}
else {
SPITHEADER(1);
SPITUSERERROR("You do not have permission to view ".
"target user's profiles");
echo "<script src='js/lib/require.js' data-main='js/null'>
</script>\n";
SPITFOOTER();
}
exit();
}
}
$target_idx = $target_user->uid_idx();
#
# Deal with ajax requests.
#
if (isset($ajax_request)) {
if ($ajax_method == "getprofile") {
$profile_idx = addslashes($ajax_argument);
#
# XXX This query effectively allows a user to look at another
# users profile, by cheating the ajax interface. Not a big
# deal yet, but something to worry about right now.
#
$query_result =
DBQueryWarn("select * from apt_profiles ".
"where idx='$profile_idx'");
"where idx='$profile_idx' and ".
" creator_idx='$target_idx'");
if (!$query_result || !mysql_num_rows($query_result)) {
SPITAJAX_ERROR(1, "No such profile $profile_idx!");
......@@ -79,21 +96,12 @@ if (isset($ajax_request)) {
SPITHEADER(1);
if (isset($target_user) && !$this_user->SameUser($target_user)) {
if (!ISADMIN()) {
SPITUSERERROR("You do not have permission to view ".
"target user's profiles");
SPITFOOTER();
exit();
}
}
else {
$target_user = $this_user;
}
$target_idx = $target_user->uid_idx();
echo "<link rel='stylesheet'
href='tablesorter.css'>\n";
$query_result =
DBQueryFatal("select * from apt_profiles ".
DBQueryFatal("select *,DATE(created) as created ".
" from apt_profiles ".
"where creator_idx=$target_idx");
if (mysql_num_rows($query_result) == 0) {
......@@ -104,56 +112,79 @@ if (mysql_num_rows($query_result) == 0) {
SPITFOOTER();
exit();
}
$profile_array = array();
$profile_default = null;
echo "<div class='row'>
<div class='col-lg-12 col-lg-offset-0
col-md-12 col-md-offset-0
col-sm-12 col-sm-offset-0
col-xs-12 col-xs-offset-0'>\n";
echo "<input class='form-control search' type='search'
id='profile_search' placeholder='Search'>\n";
echo " <table class='tablesorter'>
<thead>
<tr>
<th>Name</th>
<th>Project</th>
<th>Description</th>
<th>Show</th>
<th>Created</th>
<th>Public</th>
</tr>
</thead>
<tbody>\n";
while ($row = mysql_fetch_array($query_result)) {
$profile_array[$row["idx"]] = $row["name"];
if (!$profile_default) {
$profile_default = $row["idx"];
}
$idx = $row["idx"];
$name = $row["name"];
$pid = $row["pid"];
$desc = $row["description"];
$created = $row["created"];
$public = $row["public"];
echo " <tr>
<td>
<a href='manage_profile.php?action=edit&idx=$idx'>$name</a>
</td>
<td style='white-space:nowrap'>$pid</td>
<td>$desc</td>
<td style='text-align:center'>
<button class='btn btn-primary btn-xs showtopo_modal_button'
data-profile=$idx>
Show</button>
</td>
<td>$created</td>
<td>$public</td>
</tr>\n";
}
echo " </tbody>
</table>
</div>
</div>\n";
echo "<div class='row'>
<div class='col-lg-6 col-lg-offset-3
col-md-6 col-md-offset-3
col-sm-8 col-sm-offset-2
col-xs-12 col-xs-offset-0'>\n";
echo " <div class='panel panel-default'>
<div class='panel-heading'>
<h3 class='panel-title'>
Your Profiles</h3>
echo "<!-- This is the topology view modal -->
<div id='quickvm_topomodal' class='modal fade'>
<div class='modal-dialog' id='showtopo_dialog'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal'
aria-hidden='true'>
&times;</button>
<h3>Topology Viewer</h3>
</div>
<div class='modal-body'>
<!-- This topo diagram goes inside this div -->
<div class='panel panel-default'
id='showtopo_container'>
<div class='panel-body'>
<div id='showtopo_nopicker'></div>
</div>
</div>
</div>
<div class='panel-body'>
<form id='quickvm_create_profile_form'
role='form'
method='get' action='manage_profile.php'>
<input type='hidden' name='action' value='edit'/>
<div id='profile_well' class='form-group well well-md'>
<span id='selected_profile_text' class='pull-left'>
</span>
<input id='selected_profile' type='hidden' name='idx'/>
<button id='profile' class='btn btn-primary btn-xs pull-right'
type='button' name='profile_button'>
Select a Profile</button>\n";
echo " </div>
<button class='btn btn-primary btn-sm pull-right'
type='submit' name='submit'>Modify</button>
<a id='instantiate'
class='btn btn-primary btn-sm pull-right'
style='margin-right: 10px;'
type='button'>Instantiate</a>
</form>
</div>
</div>
</div>
</div>\n";
SpitTopologyViewModal("quickvm_topomodal", $profile_array);
</div>\n";
echo "<script type='text/javascript'>\n";
echo "window.PROFILE = '$profile_default';\n";
echo "</script>\n";
echo "<script src='js/lib/require.js' data-main='js/myprofiles'></script>\n";
SPITFOOTER();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment