//////////////////////////////////////////////////////////////////////////// // 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.createChangesWidget = function() { try { var changeData = []; var changeStore = new Ext.data.ArrayStore({ proxy: new Ext.data.MemoryProxy(changeData), fields: [ { name: 'user' }, { name: 'changelist', type: 'float' }, { name: 'files', type: 'float' }, { name: 'sizes', type: 'float' } ] }); var loading = false; var loaded = false; function loadDone() { if (loaded) { changeStore.reload(); } else { loaded = true; changeStore.load(); } loading = false; } function loadDescribe(entry, id, total) { P4JsApi.p4("describe " + id, function(described) { var files = []; if (described.data[0]) { files = P4.changelist.files(described.data[0]); for (var i = 0; i < files.length; i++) { files[i] = files[i] + "@" + id; } entry.push(files.length); } else { entry.push(0); } loadSizes(entry, files, total); }); } function loadSizes(entry, files, total) { P4JsApi.p4("sizes \"" + files.join('\" \"') + "\"", function(sizes) { var totalSize = 0; var size = 0; while (sizes.data[size]) { var fileSize = parseInt(sizes.data[size].fileSize); if (fileSize > 0) { totalSize += fileSize; } size++; } entry.push(totalSize); if (changeData.length === total) { loadDone(); } }); } function fetchChanges() { if (loading) { return; } loading = true; var changes = P4JsApi.p4("changes -s submitted -m 10", function(changes) { var item = 0; while (changeData.length > 0) { changeData.pop(); } var change = 0; while (changes.data[change]) { var entry = []; var id = changes.data[change].Change; entry.push(changes.data[change].User); entry.push(id); changeData.push(entry); change++; } for (var i = 0; i < changeData.length; i++) { var entry = changeData[i]; loadDescribe(entry, entry[1], changeData.length); } }); } fetchChanges(); var loadId = setInterval(fetchChanges, 2 * 60 * 1000); var grid = new Ext.grid.GridPanel({ store: changeStore, columns: [ { id: 'user', header: 'User', width: 100, sortable: true, dataIndex: 'user' }, { id: 'changelist', header: 'Changelist', width: 80, sortable: true, dataIndex: 'changelist' }, { id: 'files', header: 'Files', width: 70, sortable: true, dataIndex: 'files' }, { id: 'sizes', header: 'Size', width: 70, sortable: true, renderer: Ext.util.Format.fileSize, dataIndex: 'sizes' } ], buttons: [{ id: 'spotlight', iconCls: 'silk-user-comment', text: "User spotlight", handler: function() { var selected = grid.getSelectionModel().getSelected(); if (selected && selected.get('user')) { P4.showSpotlight(selected.get('user')); } else { alert("You must select a user first!"); } } }], stripeRows: true, height: 250, autoExpandColumn: 'user', border: false, autoScroll: true, autoshow: true, }); return grid; } 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 |