diff --git a/scm-webapp/src/main/webapp/index.html b/scm-webapp/src/main/webapp/index.html index 7c76b66929..76656d8081 100644 --- a/scm-webapp/src/main/webapp/index.html +++ b/scm-webapp/src/main/webapp/index.html @@ -109,6 +109,7 @@ + diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.blamepanel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.blamepanel.js new file mode 100644 index 0000000000..9cea6f7644 --- /dev/null +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.blamepanel.js @@ -0,0 +1,85 @@ +/* * + * Copyright (c) 2010, Sebastian Sdorra + * 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. + * 3. Neither the name of SCM-Manager; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 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 THE REGENTS OR CONTRIBUTORS 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. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + +Sonia.repository.BlamePanel = Ext.extend(Ext.grid.GridPanel, { + + blameUrl: null, + + initComponent: function(){ + + var blameStore = new Sonia.rest.JsonStore({ + proxy: new Ext.data.HttpProxy({ + url: this.blameUrl, + disableCaching: false + }), + root: 'blamelines', + idProperty: 'lineNumber', + fields: [ 'lineNumber', 'author', 'revision', 'when', 'code'], + sortInfo: { + field: 'lineNumber' + } + }); + + var blameColModel = new Ext.grid.ColumnModel({ + columns: [{ + id: 'lineNumber', + dataIndex: 'lineNumber', + width: 20 + },{ + id: 'code', + dataIndex: 'code', + renderer: this.renderCode, + width: 400 + }] + }); + + var config = { + hideHeaders: true, + autoExpandColumn: 'code', + store: blameStore, + colModel: blameColModel, + autoHeight: true, + viewConfig: { + forceFit: true + } + } + Ext.apply(this, Ext.apply(this.initialConfig, config)); + Sonia.repository.BlamePanel.superclass.initComponent.apply(this, arguments); + }, + + renderCode: function(value){ + return '
' + Ext.util.Format.htmlEncode(value) + '
'; + } + +}); + +Ext.reg('blamePanel', Sonia.repository.BlamePanel); diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.contentpanel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.contentpanel.js index 0305ff0fe9..3f00b345ea 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.contentpanel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.contentpanel.js @@ -35,13 +35,19 @@ Sonia.repository.ContentPanel = Ext.extend(Ext.Panel, { revision: null, path: null, contentUrl: null, + blameUrl: null, initComponent: function(){ var name = this.getName(this.path); - this.contentUrl = restUrl + 'repositories/' + this.repository.id + '/content?path=' + this.path; + var repositoryUrl = restUrl + 'repositories/' + this.repository.id + '/'; + + + this.contentUrl = repositoryUrl + 'content?path=' + this.path; + this.blameUrl = repositoryUrl + 'blame.json?path=' + this.path; if ( this.revision ){ this.contentUrl += "&revision=" + this.revision; + this.blameUrl += "&revision=" + this.revision; } var bottomBar = [this.path]; @@ -55,8 +61,10 @@ Sonia.repository.ContentPanel = Ext.extend(Ext.Panel, { text: 'Raw', handler: this.downlaodFile, scope: this - //},{ - // text: 'Blame' + },{ + text: 'Blame', + handler: this.openBlamePanel, + scope: this }], bbar: bottomBar, items: [{ @@ -70,6 +78,15 @@ Sonia.repository.ContentPanel = Ext.extend(Ext.Panel, { Sonia.repository.ContentPanel.superclass.initComponent.apply(this, arguments); }, + openBlamePanel: function(){ + this.removeAll(); + this.add({ + xtype: 'blamePanel', + blameUrl: this.blameUrl + }); + this.doLayout(); + }, + downlaodFile: function(){ window.open(this.contentUrl); },