//////////////////////////////////////////////////////////////////////////// // Rev: 2010.1 (P4JsApi 1.0 Example) // // 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 P4 = P4 || {}; P4.showSpotlight = function(user) { try { if (!user) { return; } var userMarkup = [ '<div style="width:200px">', '<b>User</b>: {user}<br/>', '<b>Full Name</b>: {fullname}<br/>', '<b>E-mail</b>: {email}<br/><hr/>', '<b>Clients</b>: {clients}<br/>', '<b>Branches</b>: {branches}<br/>', '<b>Labels</b>: {labels}<br/><hr/>', '<b>Pending Changelists</b>: {pending}<br/>', '<b>Opened Files</b>: {opened}<br/>', '</div>' ]; var userTpl = new Ext.Template(userMarkup); var data = {}; var html = userTpl.apply(data); var panel = new Ext.Panel({ frame: true, height: 225, width: 400, id: "spotlightPanel", layout: 'border', items: [ { id: 'userSummary', region: 'west', split: true, bodyStyle: { padding: '5px' }, html: html }, { id: 'userGraph', region: 'center', bodyStyle: { padding: '5px' }, html: "<div><b>Submits over last 3 months</b></div><div id='userSpotlightGraph' style='height:150px;width:200px'></div>" } ] }); var win = new Ext.Window({ width: 450, iconCls: 'silk-user-comment', title: "User Spotlight", layout: 'fit', autoScroll: true, modal: true, items: panel }); win.show(null, function() { var mask = new Ext.LoadMask(Ext.get("spotlightPanel"), { msg: "Loading...", removeMask: true }); mask.show(); function load() { var done = 0; function worked() { done++; if (done === 7) { displayResults(); } }; P4JsApi.p4("user -o " + user, function(userData) { if (userData.data[0]) { data.user = userData.data[0].User; data.fullname = userData.data[0].FullName; data.email = userData.data[0].Email; } worked(); }); P4JsApi.p4("clients -u " + user, function(clients) { data.clients = 0; while (clients.data[data.clients]) { data.clients++; } worked(); }); P4JsApi.p4("branches -u " + user, function(branches) { data.branches = 0; while (branches.data[data.branches]) { data.branches++; } worked(); }); P4JsApi.p4("labels -u " + user, function(labels) { data.labels = 0; while (labels.data[data.labels]) { data.labels++; } worked(); }); P4JsApi.p4("changes -s pending -u " + user, function(pendings) { data.pending = 0; while (pendings.data[data.pending]) { data.pending++; } worked(); }); P4JsApi.p4("opened -a -u " + user, function(opened) { data.opened = 0; while (opened.data[data.opened]) { data.opened++; } worked(); }); var today = new Date(); today = new Date(today.getTime() + (1000 * 60 * 60 * 24)); var t = today.getFullYear() + "/" + (today.getMonth() + 1) + "/" + today.getDate(); var lastWeek = new Date(today.getTime() - (1000 * 60 * 60 * 24 * 7 * 13)); var lw = lastWeek.getFullYear() + "/" + (lastWeek.getMonth() + 1) + "/" + lastWeek.getDate(); var months = []; var changeCmd = "changes -s submitted -u " + user + " @" + lw + ",@" + t; P4JsApi.p4(changeCmd, function(lastChanges) { var lastChange = 0; while (lastChanges.data[lastChange]) { var change = lastChanges.data[lastChange]; var cDate = new Date(parseInt(change.Date) * 1000); if (!months[cDate.getMonth()]) { months[cDate.getMonth()] = 1; } else { months[cDate.getMonth()]++; } lastChange++; } worked(); }); function displayResults() { userTpl.overwrite(Ext.get("userSummary"), data); var d1 = []; var current = new Date().getMonth(); for (var i = 0; i < 3; i++) { var month = current - i; if (month < 0) { month += 12; } if (months[month]) { d1.push([i, months[month]]); } else { d1.push([i, 0]); } } mask.hide(); var f = Flotr.draw($('userSpotlightGraph'), [{ data: d1, lines: { show: true, fill: true }, points: { show: true } }], { xaxis: { tickFormatter: function(n) { if (parseFloat(n) == Math.round(parseFloat(n))) { switch (current + parseInt(n) - 2) { case 0: return "Jan."; case 1: return "Feb."; case 2: return "Mar."; case 3: return "Apr."; case 4: return "May"; case 5: return "Jun."; case 6: return "Jul."; case 7: return "Aug."; case 8: return "Sep."; case 9: return "Oct."; case 10: return "Nov."; case 11: return "Dec."; default: return "Invalid"; } } return ""; }, }, yaxis: { min: 0, tickFormatter: function(n) { if (parseFloat(n) == Math.round(parseFloat(n)) && parseInt(n) >= 0) { return parseInt(n) + " "; } return ""; }, } } ); } }; load(); }); } catch(e) { alert(e); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 7663 | dscheirer | Rollback //public/perforce/p4jsapi to changelist 7643 | ||
#3 | 7660 | jhalbig |
As per meeting to resolve issue with sync calls made from within async calls hanging P4V (job039138) pulling example code from Public Depot until it can be re-worked and confirmed to function correctly with pending P4JsApi changes. |
||
#2 | 7643 | jhalbig |
Cleaned up any remaining discrepancies in the code. Removed all internal references and debugging code. Cleaned up formatting, added more commenting for submit dialog code. Ready for 2010.1 Beta. |
||
#1 | 7638 | jhalbig | Initial Addition of P4JsApi samples for 2010.1 Beta |