//////////////////////////////////////////////////////////////////////////// // Rev: 2010.2 (P4JsApi 1.0 Further examples) // // NOTE: This is an example only, and should be modified to work in // a production environment! No warranty is expressed or implied. // Scripts should be tested thoroughly on a test server before // using in a production environment. // //////////////////////////////////////////////////////////////////////////// // Copyright (c) 2010, Perforce Software, Inc. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //////////////////////////////////////////////////////////////////////////// var backStack = []; var forwardStack = []; var lastHelp = ""; function processList( output ) { var a = new Array(); var commands = output.split('\n').slice(3,-1); for( var i = 0; i < commands.length; i++ ) { var r = commands[i].match(/\t([a-z0-9]*)\w*(.*)/); if( r ) { a.push([r[1],r[2]]); } } return displayArrayAsTable(a); } function processHelp( output ) { var a = new Array(); var commands = output.split('\n'); var version = ""; for ( var i = 0; i < commands.length; i++ ) { var r = commands[i].match(/p4 help ([a-z]*)\s*(.*)/); if( r && r[1] != 'command' ) { // there is no 'p4 help command' a.push([r[1], r[2]]); } else { var v = commands[i].match(/Server (.*)./); if( v ) { version = v[1]; } } } a.push(["undoc", "unsupported or obsolete Perforce commands and options" ]); table = displayArrayAsTable(a); table += "<p>Perforce Version " + version; return table; } function createReference( command, text ) { return '<a href="#" onclick="doHelp(\'' + command + '\');">p4 ' + text + '</a>'; } function processUndocumented( output ) { var lines = output.split('\n'); var helpInfo = ""; for ( var i = 0; i < lines.length; ++i ) { helpInfo += lines[i].replace(/( p4\s+.*)/, '<h1>$1</h1>') + "\n"; } return processReferences( helpInfo ); } function processReferences( output ) { var lines = output.split('\n'); var helpInfo = ""; for ( var i = 0; i < lines.length; ++i ) { helpInfo += lines[i].replace(/\'p4\s+(help\s+)?(\w*)\'/g, createReference("$2", "$1$2")) + "\n"; } return '<pre>' + helpInfo + '</pre>'; } function displayArrayAsTable( arr ) { var helpInfo = '<table border="1" cellpadding="10">'; for (var i = 0; i < arr.length; i++) { helpInfo += '<tr><td>' + createReference(arr[i][0], "help " + arr[i][0]) + '</td><td>' + arr[i][1] + '</td></tr>'; } helpInfo += '</table>'; return helpInfo; } function doHelpIntern( command ) { var help = "Unknown P4JsAPI version"; if( P4JsApi.getApiVersion() == "1.1" ) help = P4JsApi.p4('help ' + command).data[0].info; else if( P4JsApi.getApiVersion() == "1.2" ) help = P4JsApi.p4('help ' + command).data[0].p4INFO.message; var helptext = document.getElementById("helptext"); switch( command ) { case 'administration': case 'commands': case 'simple': helptext.innerHTML = processList(help); break; case '': helptext.innerHTML = processHelp(help); break; case 'undoc': helptext.innerHTML = processUndocumented(help); break; default: helptext.innerHTML = processReferences(help); break; } lastHelp = command; var wd = document.querySelector("#helptext > table").offsetWidth; document.getElementById("topRow").style.width = wd + "px"; } function doHelp( command ) { backStack.push( lastHelp ); document.getElementById("goback").disabled = false; forwardStack = [] document.getElementById("goforward").disabled = "disabled"; doHelpIntern( command ); } function goBack() { var command = backStack.pop(); var current = lastHelp; doHelpIntern( command ); if( backStack.length == 0 ) { document.getElementById("goback").disabled = "disabled"; } forwardStack.push( current ); document.getElementById("goforward").disabled = false; } function goForward() { var command = forwardStack.pop(); backStack.push( lastHelp ); document.getElementById("goback").disabled = false; doHelpIntern( command ); if( forwardStack.length == 0 ) { document.getElementById("goforward").disabled = "disabled"; } } function help() { var command = document.p4help.command.value; doHelp(command); } function initialHelp() { doHelpIntern(""); } P4JsApi.setWebKitDeveloperExtrasEnabled(true);
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 11262 | Sven Erik Knop |
Updated p4help to work with newer versions of P4V. Also added additional 'p4 info' output at the bottom of the main page. |
||
#1 | 7772 | Sven Erik Knop |
First attempt at a 'p4 help' browser built into P4V. You need to: create and edit your centralsettings.js file point a protection table entry towards it add these three files to your depot or to a local drive accessible by the server enable applets in P4V Have fun. |