- <!--
- Copyright (c) Perforce Software, Inc., 1997-2012. 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.
-
- User contributed content on the Perforce Public Depot is not supported by Perforce,
- although it may be supported by its author. This applies to all contributions
- even those submitted by Perforce employees.
-
- -->
- <html>
- <head>
- <title>Configurations</title>
- <link rel="stylesheet" type="text/css" href="applets.css" />
- <script type="text/javascript">
-
- // produce a friendly name for display of a depot path (dir name)
- function displayNameForComponents(dpath) {
- var idx = dpath.lastIndexOf("/");
- var dname = dpath.substr(0, idx);
- idx = dname.lastIndexOf("/");
- dname = dname.substr(idx+1);
- console.log("Converted " + dpath + " to " + dname);
- return dname;
- } // displayNameForComponents
-
- // produce a friendly name for display of a depot path (file name)
- function displayName(dpath) {
- var idx = dpath.lastIndexOf("/");
- var dname = dpath.substr(idx+1);
- idx = dname.lastIndexOf(".");
- dname = dname.substr(0, idx);
- console.log("Converted " + dpath + " to " + dname);
- return dname;
- } // displayName
-
- // display a configuration
- function viewCfg(dpath) {
- console.log("Going to display configuration " + dpath);
-
- // show table (and hide others)
- var div = document.getElementById('details_v');
- div.style.display = 'block';
- document.getElementById('details_e').style.display = 'none';
- document.getElementById('details_a').style.display = 'none';
-
- // clear table
- var table = document.getElementById('components_v');
- for(var i = table.rows.length; i > 1;i--) {
- table.deleteRow(i -1);
- }
-
- // load config file
- var printcmd = "print -q " + dpath;
- console.log(printcmd);
- var cfgdata = P4JsApi.p4(printcmd);
- var cfgfile = cfgdata.data[0].text;
- console.log(cfgfile);
-
- // set header
- var h3 = document.getElementById("viewheader_v");
- h3.innerHTML = P4JsApi.encodeForHTML("Configuration: " + displayName(dpath));
-
- // parse xml
- var parser = new DOMParser();
- var xmldoc = parser.parseFromString(cfgfile, "text/xml");
-
- // parse component tags
- var components = xmldoc.getElementsByTagName("component");
- console.log("Found " + components.length + " components");
- for(var ii=0; ii< components.length; ii++) {
- var c = components[ii];
- var depotPath = c.getElementsByTagName("depotPath")[0].childNodes[0].nodeValue;
- var access = c.getElementsByTagName("access")[0].childNodes[0].nodeValue;
- var clientLocation = c.getElementsByTagName("clientLocation")[0].childNodes[0].nodeValue;
- var viewA = c.getElementsByTagName("view");
- var view = "";
- if(viewA && viewA.length > 0) {
- view = viewA[0].childNodes[0].nodeValue;
- }
- var row = document.createElement("tr");
- row.innerHTML = "<td class='applet colone'>"
- + P4JsApi.encodeForHTML(depotPath)
- + "</td>"
- + "<td class='applet coltwo'>"
- + P4JsApi.encodeForHTML(access)
- + "</td>"
- + "<td class='applet coltwo'>"
- + P4JsApi.encodeForHTML(clientLocation)
- + "</td>"
- + "<td class='applet coltwo'>"
- + P4JsApi.encodeForHTML(view)
- + "</td>";
- table.appendChild(row);
- }
- } // viewCfg
-
- // delete a configuration
- function deleteCfg(dpath) {
- console.log("Going to delete configuration " + dpath);
-
- var submitcmd = 'submit -Z ' + dpath;
- console.log(submitcmd);
- var submitmsg = P4JsApi.p4(submitcmd);
-
- loadConfigs();
- loadConsumers();
- } // deleteCfg
-
- // edit a configuration
- function editCfg(dpath) {
- console.log("Going to edit configuration " + dpath);
-
- // show table (and hide others)
- var div = document.getElementById('details_e');
- div.style.display = 'block';
- document.getElementById('details_v').style.display = 'none';
- document.getElementById('details_a').style.display = 'none';
-
- // clear table
- var table = document.getElementById('components_e');
- for(var i = table.rows.length; i > 1;i--) {
- table.deleteRow(i -1);
- }
-
- // load config file
- var printcmd = "print -q " + dpath;
- console.log(printcmd);
- var cfgdata = P4JsApi.p4(printcmd);
- var cfgfile = cfgdata.data[0].text;
- console.log(cfgfile);
-
- // set header
- var h3 = document.getElementById("viewheader_e");
- h3.innerHTML = P4JsApi.encodeForHTML("Configuration: " + displayName(dpath));
- var dpath_e = document.getElementById("dpath_e");
- dpath_e.value = dpath;
-
- // parse xml
- var parser = new DOMParser();
- var xmldoc = parser.parseFromString(cfgfile, "text/xml");
-
- // parse component tags
- var components = xmldoc.getElementsByTagName("component");
- console.log("Found " + components.length + " components");
- for(var ii=0; ii< components.length; ii++) {
- var c = components[ii];
- var depotPath = c.getElementsByTagName("depotPath")[0].childNodes[0].nodeValue;
- var access = c.getElementsByTagName("access")[0].childNodes[0].nodeValue;
- var clientLocation = c.getElementsByTagName("clientLocation")[0].childNodes[0].nodeValue;
- var viewA = c.getElementsByTagName("view");
- var view = "";
- if(viewA && viewA.length > 0) {
- view = viewA[0].childNodes[0].nodeValue;
- }
- var row = document.createElement("tr");
- row.innerHTML = "<td class='applet colone'>"
- + "<input type='text' value='" + P4JsApi.encodeForHTMLAttribute(depotPath) + "'/>"
- + "</td>"
- + "<td class='applet coltwo'>"
- + "<select>"
- + "<option value='" + P4JsApi.encodeForHTMLAttribute("active") + "' "
- + ((access === 'active') ? "selected='selected'" : "") + ">active</option>"
- + "<option value='" + P4JsApi.encodeForHTMLAttribute("write") + "' "
- + ((access === 'write') ? "selected='selected'" : "") + ">write</option>"
- + "<option value='" + P4JsApi.encodeForHTMLAttribute("read") + "' "
- + ((access === 'read') ? "selected='selected'" : "") + ">read</option>"
- + "<option value='" + P4JsApi.encodeForHTMLAttribute("binary") + "' "
- + ((access === 'binary') ? "selected='selected'" : "") + ">binary</option>"
- + "</select>"
- + "</td>"
- + "<td class='applet coltwo'>"
- + "<input type='text' value='" + P4JsApi.encodeForHTMLAttribute(clientLocation) + "'/>"
- + "</td>"
- + "<td class='applet coltwo'>"
- + "<input type='text' value='" + P4JsApi.encodeForHTMLAttribute(view) + "'/>"
- + "</td>"
- + "<td class='applet coltwo'>"
- + "<input type='button' value='Delete' onclick='deleteComponent(this, \"components_e\")'>"
- + "</td>";
- table.appendChild(row);
- }
- } // editCfg
-
- // deletes a component in the table
- function deleteComponent(r,tname) {
- var idx = r.parentNode.parentNode.rowIndex;
- document.getElementById(tname).deleteRow(idx);
- } // deleteComponent
-
- // submits changes to a configuration
- function submitCfg() {
- console.log("Going to save configuration");
-
- var table = document.getElementById('components_e');
- var cfgxml = "<configuration>";
- var errors = '';
- for(var i = 1; i< table.rows.length; i++) {
- var row = table.rows[i];
- var dpath = row.cells[0].childNodes[0].value;
- var access = row.cells[1].childNodes[0].value;
- var clocation = row.cells[2].childNodes[0].value;
- var view = row.cells[3].childNodes[0].value;
- errors = errors + verifyRow(dpath, access, clocation, view);
- cfgxml += "<component>";
- cfgxml += "<depotPath>" + dpath + "</depotPath>";
- cfgxml += "<access>" + access + "</access>";
- cfgxml += "<clientLocation>" + clocation + "</clientLocation>";
- if(view && view.length > 0) {
- cfgxml += "<view>" + view + "</view>";
- }
- cfgxml += "</component>";
- }
- cfgxml += "</configuration>";
- console.log("Read view " + cfgxml);
-
- if(errors == '') {
- var dpath_e = document.getElementById("dpath_e").value;
- var submitcmd = 'submit -Q ' + dpath_e + " " + cfgxml;
- console.log(submitcmd);
- var submitmsg = P4JsApi.p4(submitcmd);
-
- // clean up UI
- document.getElementById('details_e').style.display = 'none';
- }
- else {
- window.alert(errors);
- }
-
- } // submitCfg
-
- function cancelAdd() {
- loadConfigs();
- } // cancelAdd
-
- function cancelEdit() {
- loadConfigs();
- } // cancelEdit
-
- // checks if string exists and is not empty
- function stringExists(s) {
- if(s && s.length > 0) {
- return true;
- }
- else {
- return false;
- }
- }
-
- // verifies one component entry
- function verifyRow(dpath, access, clocation, view) {
- errors = '';
- if(!stringExists(dpath)) {
- errors = errors + 'Depot path is required. ';
- }
- if(!stringExists(access)) {
- errors = errors + 'Access level is required. ';
- }
- if(!stringExists(clocation)) {
- errors = errors + 'Client location is required. ';
- }
- if(stringExists(view) && (access == 'read' || access == 'binary')) {
- errors = errors + 'View label only valid with active/write access. ';
- }
-
- return errors;
- } // verifyRow
-
- // adds a new configuration
- function addCfg() {
- console.log("Starting to add configuration");
-
- // show table (and hide others)
- var div = document.getElementById('details_a');
- div.style.display = 'block';
- document.getElementById('details_v').style.display = 'none';
- document.getElementById('details_e').style.display = 'none';
- document.getElementById("add_cfg_name").value = '';
-
- // clear table
- var table = document.getElementById('components_a');
- for(var i = table.rows.length; i > 1;i--) {
- table.deleteRow(i -1);
- }
- } // addCfg
-
- // submits a new configuration
- function submitNewCfg() {
- console.log("Going to add configuration");
-
- var table = document.getElementById('components_a');
- var cfgxml = "<configuration>";
- var errors = '';
- for(var i = 1; i< table.rows.length; i++) {
- var row = table.rows[i];
- var dpath = row.cells[0].childNodes[0].value;
- var access = row.cells[1].childNodes[0].value;
- var clocation = row.cells[2].childNodes[0].value;
- var view = row.cells[3].childNodes[0].value;
- errors = errors + verifyRow(dpath, access, clocation, view);
- cfgxml += "<component>";
- cfgxml += "<depotPath>" + dpath + "</depotPath>";
- cfgxml += "<access>" + access + "</access>";
- cfgxml += "<clientLocation>" + clocation + "</clientLocation>";
- if(view && view.length > 0) {
- cfgxml += "<view>" + view + "</view>";
- }
- cfgxml += "</component>";
- }
- cfgxml += "</configuration>";
- console.log("Read view " + cfgxml);
-
- if(errors == '') {
- var dname = document.getElementById("add_cfg_name").value;
- var submitcmd = 'submit -A ' + dname + " " + cfgxml;
- console.log(submitcmd);
- var submitmsg = P4JsApi.p4(submitcmd);
-
- // clean up UI
- document.getElementById('details_a').style.display = 'none';
- loadConfigs();
- loadConsumers();
- }
- else {
- window.alert(errors);
- }
-
- } // submitNewCfg
-
-
- // add a new component to the table
- function addComponent(tname) {
- console.log("Going to add new component");
-
- // make new row
- var table = document.getElementById(tname);
- var row = document.createElement("tr");
- row.innerHTML = "<td class='applet colone'>"
- + "<input type='text' value=''/>"
- + "</td>"
- + "<td class='applet coltwo'>"
- + "<select>"
- + "<option value='" + P4JsApi.encodeForHTMLAttribute("active") + "' "
- + ">active</option>"
- + "<option value='" + P4JsApi.encodeForHTMLAttribute("write") + "' "
- + ">write</option>"
- + "<option value='" + P4JsApi.encodeForHTMLAttribute("read") + "' "
- + ">read</option>"
- + "<option value='" + P4JsApi.encodeForHTMLAttribute("binary") + "' "
- + ">binary</option>"
- + "</select>"
- + "</td>"
- + "<td class='applet coltwo'>"
- + "<input type='text' value=''/>"
- + "</td>"
- + "<td class='applet coltwo'>"
- + "<input type='text' value=''/>"
- + "</td>"
- + "<td class='applet coltwo'>"
- + "<input type='button' value='Delete' onclick='deleteComponent(this, \"" + tname + "\")'>"
- + "</td>";
- table.appendChild(row);
- } // add component
-
- // populate the config list table
- function loadConfigs() {
- P4JsApi.setWebKitDeveloperExtrasEnabled(true);
- document.getElementById('details_e').style.display = 'none';
- document.getElementById('details_a').style.display = 'none';
- document.getElementById('details_v').style.display = 'none';
- var table = document.getElementById('configs');
- for(var i = table.rows.length; i > 1;i--) {
- table.deleteRow(i -1);
- }
- var filescmd = 'files -e //cbd/configurations/...';
- console.log(filescmd);
- var configs = P4JsApi.p4(filescmd);
- for(var ii = 0; ii< configs.size; ii++) {
- var cfile = configs.data[ii];
- var row = document.createElement("tr");
- row.innerHTML = "<td class='applet colone'>"
- + P4JsApi.encodeForHTML(displayName(cfile.depotFile))
- + "</td>"
- + "<td class='applet coltwo'>"
- + "<input type='button' value='View' onclick='viewCfg(\"" + cfile.depotFile + "\")'>"
- + "<input type='button' value='Edit' onclick='editCfg(\"" + cfile.depotFile + "\")'>"
- + "<input type='button' value='Delete' onclick='deleteCfg(\"" + cfile.depotFile + "\")'>"
- + "</td>";
- table.appendChild(row);
- } // all config files
- } // loadConfigs
-
- // populate the consumer list table
- function loadConsumers() {
- P4JsApi.setWebKitDeveloperExtrasEnabled(true);
- document.getElementById('details_e').style.display = 'none';
- document.getElementById('details_a').style.display = 'none';
- document.getElementById('details_v').style.display = 'none';
- var table = document.getElementById('consumers');
- for(var i = table.rows.length; i > 1;i--) {
- table.deleteRow(i -1);
- }
-
- // read all configurations
- var filescmd = 'files -e //cbd/configurations/...';
- console.log(filescmd);
- var configs = P4JsApi.p4(filescmd);
-
- // build a map: key = component, value = list of configurations that use it
- var consumerMap = new Object();
- for(var ii = 0; ii< configs.size; ii++) {
- var cfile = configs.data[ii].depotFile;
- var cname = displayName(cfile);
- console.log("Inspecting configuration " + cname);
- var content = P4JsApi.p4("print -q " + cfile).data[0].text;
- var parser = new DOMParser();
- var xmldoc = parser.parseFromString(content, "text/xml");
- var components = xmldoc.getElementsByTagName("component");
-
- for(var jj=0; jj< components.length; jj++) {
- var c = components[jj];
- var depotPath = c.getElementsByTagName("depotPath")[0].childNodes[0].nodeValue;
- var componentName = displayNameForComponents(depotPath);
- console.log("Inspecting component " + componentName);
- if(componentName in consumerMap) {
- console.log("Already know about component " + componentName);
- }
- else {
- console.log("Found new component " + componentName);
- consumerMap[componentName] = new Array();
- }
- if(consumerMap[componentName].indexOf(cname) == -1) {
- consumerMap[componentName].push(cname);
- }
- } // all components for one config
- } // all configurations
-
- for(var componentName in consumerMap) {
- var row = document.createElement("tr");
- var rowih = "<td class='applet colone'>"
- + P4JsApi.encodeForHTML(componentName)
- + "</td>"
- + "<td class='applet coltwo'>"
- + "<ul>";
- var al = consumerMap[componentName].length;
- for(var kk = 0; kk < al; kk++) {
- rowih = rowih + "<li>" + P4JsApi.encodeForHTML(consumerMap[componentName][kk]) + "</li>"
- }
- rowih = rowih + "</ul>"
- + "</td>";
- row.innerHTML = rowih;
- table.appendChild(row);
- } // all components
- } // loadConsumers
-
- </script>
- </head>
- <body onload="loadConfigs();loadConsumers();" id="thebody">
- <table class="eighty applet" id="configs">
- <tr>
- <th class="filter">Name</th>
- <th class="filter">Actions</th>
- </tr>
- </table>
- <br>
- <input type="button" value="Add" onclick="addCfg()"/>
- <input type="button" value="Refresh" onclick="loadConfigs();loadConsumers();"/>
- <div id="details_v" class="details">
- <h3 id="viewheader_v"></h3>
- <table class="eighty applet" id="components_v">
- <tr>
- <th class="filter">Component Path</th>
- <th class="filter">Access</th>
- <th class="filter">Location</th>
- <th class="filter">View</th>
- </tr>
- </table>
- </div>
- <div id="details_e" class="details">
- <h3 id="viewheader_e"></h3>
- <input type="hidden" id="dpath_e" value=""/>
- <table class="eighty applet" id="components_e">
- <tr>
- <th class="filter">Component Path</th>
- <th class="filter">Access</th>
- <th class="filter">Location</th>
- <th class="filter">View</th>
- <th class="filter">Actions</th>
- </tr>
- </table>
- <input type="button" value="Add Component" onclick="addComponent('components_e')"/>
- <input type="button" value="Save Configuration" onclick="submitCfg()"/>
- <input type="button" value="Cancel" onclick="cancelEdit()"/>
- </div>
- <div id="details_a" class="details">
- <h3>New Configuration</h3>
- Enter configuration name: <input type='text' id='add_cfg_name' value=''/>
- <table class="eighty applet" id="components_a">
- <tr>
- <th class="filter">Component Path</th>
- <th class="filter">Access</th>
- <th class="filter">Location</th>
- <th class="filter">View</th>
- <th class="filter">Actions</th>
- </tr>
- </table>
- <input type="button" value="Add Component" onclick="addComponent('components_a')"/>
- <input type="button" value="Save Configuration" onclick="submitNewCfg()"/>
- <input type="button" value="Cancel" onclick="cancelAdd()"/>
- </div>
- <br>
- <table class="eighty applet" id="consumers">
- <tr>
- <th class="filter">Component</th>
- <th class="filter">Consumed By</th>
- </tr>
- </table>
- <br>
- </body>
- </html>
# |
Change |
User |
Description |
Committed |
|
#1
|
8278 |
Randy DeFauw |
Import component development tool kit |
12 years ago
|
|