Commit 76bf66ac authored by Leigh B Stoller's avatar Leigh B Stoller

Add a simple show profile page so that we can show more of the profile

data to guests or others without full permission to see it all.
parent fcebb252
require(window.APT_OPTIONS.configObject,
['underscore', 'js/quickvm_sup', 'moment',
'js/lib/text!template/show-profile.html',
'js/lib/text!template/waitwait-modal.html',
'js/lib/text!template/renderer-modal.html',
'js/lib/text!template/showtopo-modal.html',
'js/lib/text!template/rspectextview-modal.html',
'js/lib/text!template/guest-instantiate.html',
'js/lib/text!template/instantiate-modal.html',
'js/lib/text!template/oops-modal.html',
// jQuery modules
'marked','jquery-ui','jquery-grid'],
function (_, sup, moment,
showString, waitwaitString,
rendererString, showtopoString, rspectextviewString,
guestInstantiateString, instantiateString, oopsString)
{
'use strict';
var profile_uuid = null;
var version_uuid = null;
var gotscript = 0;
var ajaxurl = "";
var amlist = null;
var editor = null;
var myCodeMirror = null;
var showTemplate = _.template(showString);
var InstTemplate = _.template(instantiateString);
function initialize()
{
window.APT_OPTIONS.initialize(sup);
version_uuid = window.VERSION_UUID;
profile_uuid = window.PROFILE_UUID;
ajaxurl = window.AJAXURL;
var fields = JSON.parse(_.unescape($('#form-json')[0].textContent));
amlist = JSON.parse(_.unescape($('#amlist-json')[0].textContent));
if (_.has(fields, "profile_script") && fields["profile_script"] != "") {
gotscript = 1;
}
// Generate the templates.
var show_html = showTemplate({
fields: fields,
profile_uuid: profile_uuid,
version_uuid: version_uuid,
isadmin: window.ISADMIN,
});
$('#page-body').html(show_html);
$('#waitwait_div').html(waitwaitString);
$('#showtopomodal_div').html(showtopoString);
$('#guest_div').html(guestInstantiateString);
var instantiate_html = InstTemplate({ amlist: amlist,
amdefault: window.AMDEFAULT});
$('#instantiate_div').html(instantiate_html);
$('#rspectext_div').html(rspectextviewString);
$('#oops_div').html(oopsString);
// This activates the popover subsystem.
$('[data-toggle="popover"]').popover({
trigger: 'hover',
container: 'body'
});
// Format dates with moment before display.
$('.format-date').each(function() {
var date = $.trim($(this).html());
if (date != "") {
$(this).html(moment($(this).html()).format("lll"));
}
});
$('body').show();
//
// Show the visualizer.
//
$('#edit_topo_modal_button').click(function (event) {
event.preventDefault();
sup.ShowModal('#quickvm_topomodal');
});
$('#quickvm_topomodal').on('shown.bs.modal', function() {
sup.maketopmap("#showtopo_nopicker",
$('#profile_rspec_textarea').val(), null, true);
});
// The Show Source button.
$('#show_source_modal_button, #show_xml_modal_button')
.click(function (event) {
var source;
if ($(this).attr("id") == "show_source_modal_button") {
source = $.trim($('#profile_script_textarea').val());
}
if (!source.length) {
source = $.trim($('#profile_rspec_textarea').val());
}
$('#rspec_modal_editbuttons').addClass("hidden");
$('#rspec_modal_viewbuttons').removeClass("hidden");
$('#modal_profile_rspec_textarea').prop("readonly", true);
$('#modal_profile_rspec_textarea').val(source);
$('#rspec_modal').modal({'backdrop':'static','keyboard':false});
$('#rspec_modal').modal('show');
});
$('#rspec_modal').on('shown.bs.modal', function() {
var source = $('#modal_profile_rspec_textarea').val();
var mode = "text/xml";
// Need to determine the mode.
var myRe = /^import/m;
if (myRe.test(source)) {
mode = "text/x-python";
}
myCodeMirror = CodeMirror(function(elt) {
$('#modal_profile_rspec_div').prepend(elt);
}, {
value: source,
lineNumbers: false,
smartIndent: true,
autofocus: false,
readOnly: true,
mode: mode,
});
});
// Close the source/xml modal.
$('#close_rspec_modal_button')
.click(function (event) {
$('#rspec_modal').modal('hide');
$('.CodeMirror').remove();
$('#modal_profile_rspec_textarea').val("");
});
/*
* Suck the description and instructions
* out of the rspec and put them into the text boxes.
*/
ExtractFromRspec();
// We also got a geni-lib script, so show the XML button.
if (gotscript) {
$('#show_xml_modal_button').removeClass("hidden");
}
}
/*
* We want to look for and pull out the introduction and overview text,
* and put them into the text boxes. The user can edit them in the
* boxes. More likely, they will not be in the rspec, and we have to
* add them to the rspec_tour section.
*/
function ExtractFromRspec()
{
var rspec = $('#profile_rspec_textarea').val();
var xmlDoc = parseXML(rspec);
if (xmlDoc == null)
return;
var xml = $(xmlDoc);
$(xml).find("rspec_tour > description").each(function() {
var text = $(this).text();
var marked = require("marked");
$('#profile_description').html(marked(text));
});
$(xml).find("rspec_tour > instructions").each(function() {
var text = $(this).text();
var marked = require("marked");
$('#profile_instructions').html(marked(text));
});
}
function parseXML(rspec)
{
try {
var xmlDoc = $.parseXML(rspec);
return xmlDoc;
}
catch(err) {
alert("Could not parse XML!");
return -1;
}
}
$(document).ready(initialize);
});
<?php
#
# Copyright (c) 2000-2014 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");
include_once("webtask.php");
chdir("apt");
include("quickvm_sup.php");
include("profile_defs.php");
include("instance_defs.php");
$page_title = "Show Profile";
#
# Get current user.
#
RedirectSecure();
$this_user = CheckLoginOrRedirect();
$this_idx = $this_user->uid_idx();
$isadmin = (ISADMIN() ? 1 : 0);
#
# Verify page arguments.
#
$reqargs = RequiredPageArguments("uuid", PAGEARG_STRING);
SPITHEADER(1);
if (!isset($uuid)) {
SPITUSERERROR("Must provide uuid!");
}
$profile = Profile::Lookup($uuid);
if (!$profile) {
SPITUSERERROR("No such profile!");
}
if (!$profile->CanView($this_user) && !ISADMIN()) {
SPITUSERERROR("Not enough permission!");
}
$profile_uuid = $profile->profile_uuid();
$version_uuid = $profile->uuid();
$defaults = array();
$defaults["profile_name"] = $profile->name();
$defaults["profile_rspec"] = $profile->rspec();
$defaults["profile_version"] = $profile->version();
$defaults["profile_creator"] = $profile->creator();
$defaults["profile_created"] = DateStringGMT($profile->created());
$defaults["profile_version_url"] = $profile->URL();
$defaults["profile_profile_url"] = $profile->ProfileURL();
if ($profile->script() && $profile->script() != "") {
$defaults["profile_script"] = $profile->script();
}
# Place to hang the toplevel template.
echo "<div id='page-body'></div>\n";
echo "<link rel='stylesheet'
href='css/jquery-ui-1.10.4.custom.min.css'>\n";
echo "<link rel='stylesheet' href='css/codemirror.css'>\n";
# I think this will take care of XSS prevention?
echo "<script type='text/plain' id='form-json'>\n";
echo htmlentities(json_encode($defaults)) . "\n";
echo "</script>\n";
$amlist = array();
$amdefault = "";
if (($ISCLOUD || ISADMIN() || STUDLY())) {
while (list($am) = each($am_array)) {
$amlist[] = $am;
}
$amdefault = $DEFAULT_AGGREGATE;
# Temporary override until constraint system in place.
if ($profile->BestAggregate()) {
$amdefault = $profile->BestAggregate();
}
}
echo "<script type='text/plain' id='amlist-json'>\n";
echo htmlentities(json_encode($amlist));
echo "</script>\n";
echo "<script type='text/javascript'>\n";
echo " window.PROFILE_UUID = '$profile_uuid';\n";
echo " window.VERSION_UUID = '$version_uuid';\n";
echo " window.AJAXURL = 'server-ajax.php';\n";
echo " window.ISADMIN = $isadmin;\n";
echo "</script>\n";
echo "<script src='js/lib/codemirror-min.js'></script>\n";
SPITREQUIRE("show-profile");
SPITFOOTER();
?>
<div class='row'>
<div class='col-lg-8 col-lg-offset-2
col-md-8 col-md-offset-2
col-sm-10 col-sm-offset-1
col-xs-12'>
<div class='panel panel-default'>
<div class='panel-body'>
<div class='panel-body'>
<table class='table table-condensed nospaceafter border-none'>
<tr>
<td>Name:</td>
<td><%- fields.profile_name %></td>
</tr>
<tr>
<td>Version:</td>
<td><%- fields.profile_version %></td>
</tr>
<tr>
<td>Created:</td>
<td class='format-date' style='word-wrap:break-word;'>
<%- fields.profile_created %></td>
</tr>
<tr>
<td>Description:</td>
<td>
<div id='profile_description' style='border: solid #000 1px;'>
</div>
</td>
</tr>
<tr>
<td>Instructions:</td>
<td>
<div id='profile_instructions' style='border: solid #000 1px;'>
</div>
</td>
</tr>
<tr>
<td>Topology:</td>
<td>
<button class='btn btn-primary btn-xs
type='button'
style='margin-right: 10px;'
id='edit_topo_modal_button'>
Visualize</button>
<button class='btn btn-primary btn-xs'
type='button'
style='margin-right: 10px;'
id='show_source_modal_button'>
Source</button>
<button class='btn btn-primary btn-xs hidden'
type='button'
style='margin-right: 10px;'
id='show_xml_modal_button'>
XML</button>
</td>
</tr>
</table>
<a class='btn btn-primary btn-sm pull-right'
id='profile_instantiate_button'
style='margin-right: 10px;'
href='instantiate.php?profile=<%= version_uuid %>'
name='create'>Instantiate
</a>
</div>
</div>
</div>
<textarea name="formfields[profile_rspec]"
id='profile_rspec_textarea'
class='form-control hidden'
type='textarea'
data-key='profile_rspec'
rows=5><%- fields.profile_rspec %></textarea>
<textarea name="formfields[profile_script]"
id='profile_script_textarea'
class='form-control hidden'
type='textarea'
data-key='profile_script'
rows=5><%- fields.profile_script %></textarea>
</div>
<!-- place to hang the modals -->
<div id='showtopomodal_div'></div>
<div id='editmodal_div'></div>
<div id='waitwait_div'></div>
<div id='imaging_div'></div>
<div id='renderer_div'></div>
<div id='oops_div'></div>
<div id='guest_div'></div>
<div id='publish_div'></div>
<div id='instantiate_div'></div>
<div id='rspectext_div'></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