Commit 66bf14c2 authored by Leigh Stoller's avatar Leigh Stoller

Example Profiles page, linked from the Docs button. Examples can

tailored to the portal; for example, the layer1 and stitching profiles
are not shown in the Emulab Portal, but only in the Cloudlab portal.
parent abeed676
<?php
#
# Copyright (c) 2000-2019 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
chdir("..");
include("defs.php3");
chdir("apt");
include("quickvm_sup.php");
include("profile_defs.php");
$page_title = "Example Profiles";
#
# Get current user.
#
RedirectSecure();
$this_user = CheckLoginOrRedirect();
#
# Eventually use the portal to determine what profiles to show.
#
$pid = "PortalProfiles";
SPITHEADER(1);
echo "<link rel='stylesheet'
href='css/tablesorter.css'>\n";
# Place to hang the toplevel template.
echo "<div id='main-body'></div>\n";
echo "<script type='text/javascript'>\n";
echo "</script>\n";
echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
echo "<script src='js/lib/jquery.tablesorter.min.js'></script>\n";
echo "<script src='js/lib/jquery.tablesorter.widgets.min.js'></script>\n";
# List of all profiles in the PortalProfiles project.
$profiles = array();
# Make sure the profile is public, no point in showing it if not.
$query_result
= DBQueryFatal("select p.*,v.*,DATE(v.created) as created ".
" from apt_profiles as p ".
"left join apt_profile_versions as v on ".
" v.profileid=p.profileid and ".
" v.version=p.version ".
"where (p.pid='$pid' and p.public!=0 and ".
" (p.examples_portals is null or ".
" FIND_IN_SET('$PORTAL_GENESIS',examples_portals))) ".
"order by p.name");
while ($row = mysql_fetch_array($query_result)) {
$blob = array();
$blob["uuid"] = $row["uuid"];
$blob["version"] = $row["version"];
$blob["name"] = $row["name"];
$blob["desc"] = CleanString($row["description"]);
$blob["created"] = DateStringGMT($row["created"]);
$parsed_xml = simplexml_load_string($row["rspec"]);
if ($parsed_xml &&
$parsed_xml->rspec_tour && $parsed_xml->rspec_tour->description) {
$desc = $parsed_xml->rspec_tour->description;
$blob["desc"] = CleanString($desc);
}
$profiles[] = $blob;
}
echo "<script type='text/plain' id='profiles-json'>\n";
echo htmlentities(json_encode($profiles)) . "\n";
echo "</script>\n";
REQUIRE_UNDERSCORE();
REQUIRE_SUP();
REQUIRE_MOMENT();
AddTemplateList(array("example-profiles"));
SPITREQUIRE("js/example-profiles.js");
SPITFOOTER();
?>
$(function ()
{
'use strict';
var template_list = ["example-profiles"];
var templates = APT_OPTIONS.fetchTemplateList(template_list);
var listTemplate = _.template(templates["example-profiles"]);
var profiles = null;
function initialize()
{
window.APT_OPTIONS.initialize(sup);
profiles = decodejson('#profiles-json');
$('#main-body').html(listTemplate({"profiles" : profiles}));
// Format dates with moment before table update
$('.format-date').each(function() {
var date = $.trim($(this).html());
if (date != "") {
$(this).html(moment($(this).html()).format("ll"));
}
});
var table = $('#list-profiles-table')
.tablesorter({
theme : 'green',
// 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,
}
});
$.tablesorter.filter.bindSearch(table, $('#list-profiles-search'));
}
// Helper.
function decodejson(id) {
return JSON.parse(_.unescape($(id)[0].textContent));
}
$(document).ready(initialize);
});
<?php
#
# Copyright (c) 2000-2018 University of Utah and the Flux Group.
# Copyright (c) 2000-2019 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -520,24 +520,21 @@ if (!$login_user->portal()) {
$navbar_status
$navbar_right\n";
if ($PORTAL_WIKI) {
echo "<li id='quickvm_actions_menu'
echo "<li id='quickvm_actions_menu'
class='dropdown apt-left apt-nav-item'>
<a href='#'
class='dropdown-toggle btn btn-quickvm-home navbar-btn'
data-toggle='dropdown'>Docs <b class='caret'></b></a>
<ul class='dropdown-menu'>
<li><a href='$PORTAL_MANUAL' target='_blank'>Manual</a></li>
<li><a href='$PORTAL_WIKI' target='_blank'>Wiki</a></li>
</ul>
</li>\n";
}
else {
echo "<li class='apt-left'>
<a class='btn btn-quickvm-home navbar-btn'
href='$PORTAL_MANUAL' target='_blank'>Docs</a>
</li>\n";
<li><a href='$PORTAL_MANUAL' target='_blank'>Manual</a></li>";
if ($PORTAL_WIKI) {
echo " <li><a href='$PORTAL_WIKI' target='_blank'>Wiki</a></li>";
}
echo " <li><a href='example-profiles.php'
target='_blank'>Example Profiles</a></li>";
echo " </ul>
</li>\n";
if ($login_user) {
echo "
......
<div>
<center><h3>Example Profiles</h3></center>
<h5>
These profiles demonstrate how to construct various topologies and select
options such as node type, operating system, etc.</h5>
<div class="table-responsive">
<input class='form-control search' type='search' data-column='all'
id='list-profiles-search' placeholder='Search'>
<table class='tablesorter'
id='list-profiles-table'>
<thead>
<tr>
<th>Name</th>
<th>Created</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<% _.each(profiles, function(value, name) { %>
<tr>
<td class="text-nowrap">
<a href="show-profile.php?uuid=<%= value.uuid %>"
target="_blank"><%= value.name %></td>
<td class="format-date text-nowrap">
<%- value.created %></td>
<td><%- value.desc %></td>
</tr>
<% }); %>
</tbody>
</table>
</div>
</div>
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