From 89b4646624e98247b74fe30e4d8811db0b40422a Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 18 Sep 2011 09:43:30 +0200 Subject: [PATCH] improve contentpanel --- .../repository/sonia.repository.blamepanel.js | 51 +++++++++++++++++-- .../sonia.repository.contentpanel.js | 33 ++++-------- .../js/repository/sonia.repository.js | 9 ++++ .../webapp/resources/js/util/sonia.util.js | 18 +++++++ 4 files changed, 84 insertions(+), 27 deletions(-) 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 index a96bea0e0c..025fcd4c86 100644 --- 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 @@ -33,12 +33,21 @@ Sonia.repository.BlamePanel = Ext.extend(Ext.grid.GridPanel, { blameUrl: null, + repository: null, + path: null, + revision: null, + linkTemplate: '{0}', initComponent: function(){ + var blameUrl = restUrl + 'repositories/' + this.repository.id + '/'; + blameUrl += 'blame.json?path=' + this.path; + if ( this.revision ){ + blameUrl += "&revision=" + this.revision; + } var blameStore = new Sonia.rest.JsonStore({ proxy: new Ext.data.HttpProxy({ - url: this.blameUrl, + url: blameUrl, disableCaching: false }), root: 'blamelines', @@ -54,7 +63,8 @@ Sonia.repository.BlamePanel = Ext.extend(Ext.grid.GridPanel, { id: 'revision', dataIndex: 'revision', renderer: this.renderRevision, - width: 20 + width: 20, + scope: this },{ id: 'code', dataIndex: 'code', @@ -72,12 +82,43 @@ Sonia.repository.BlamePanel = Ext.extend(Ext.grid.GridPanel, { autoHeight: true, viewConfig: { forceFit: true + }, + listeners: { + click: { + fn: this.onClick, + scope: this + } } } + Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.repository.BlamePanel.superclass.initComponent.apply(this, arguments); }, + onClick: function(e){ + var el = e.getTarget('.blame-link'); + if ( el != null ){ + var revision = el.rel; + if (debug){ + console.debug('load content for ' + revision); + } + this.openContentPanel(revision) + } + }, + + openContentPanel: function(revision){ + main.addTab({ + // TODO create real id + id: Ext.id(), + xtype: 'contentPanel', + repository: this.repository, + revision: revision, + path: this.path, + closable: true, + autoScroll: true + }); + }, + renderRevision: function(value, metadata, record){ var title = 'Revision: ' + value; var tip = 'Author: ' + record.get('author').name + '
'; @@ -86,7 +127,11 @@ Sonia.repository.BlamePanel = Ext.extend(Ext.grid.GridPanel, { tip += 'When: ' + Ext.util.Format.formatTimestamp(when); } metadata.attr = 'ext:qtitle="' + title + '"' + ' ext:qtip="' + tip + '"'; - return '' + value + ''; + return String.format( + this.linkTemplate, + value, + value + ); }, renderCode: function(value){ 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 0e593c1383..9b68a66cd4 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,20 +35,12 @@ Sonia.repository.ContentPanel = Ext.extend(Ext.Panel, { revision: null, path: null, contentUrl: null, - blameUrl: null, initComponent: function(){ - var name = this.getName(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 name = Sonia.util.getName(this.path); + this.contentUrl = Sonia.repository.createContentUrl( + this.repository, this.path, this.revision + ); var bottomBar = [this.path]; this.appendRepositoryProperties(bottomBar); @@ -71,7 +63,7 @@ Sonia.repository.ContentPanel = Ext.extend(Ext.Panel, { bbar: bottomBar, items: [{ xtype: 'syntaxHighlighterPanel', - syntax: this.getExtension(this.path), + syntax: Sonia.util.getExtension(this.path), contentUrl: this.contentUrl }] } @@ -83,7 +75,7 @@ Sonia.repository.ContentPanel = Ext.extend(Ext.Panel, { openSyntaxPanel: function(){ this.openPanel({ xtype: 'syntaxHighlighterPanel', - syntax: this.getExtension(this.path), + syntax: Sonia.util.getExtension(this.path), contentUrl: this.contentUrl }); }, @@ -91,7 +83,9 @@ Sonia.repository.ContentPanel = Ext.extend(Ext.Panel, { openBlamePanel: function(){ this.openPanel({ xtype: 'blamePanel', - blameUrl: this.blameUrl + repository: this.repository, + revision: this.revision, + path: this.path }); }, @@ -112,15 +106,6 @@ Sonia.repository.ContentPanel = Ext.extend(Ext.Panel, { } }, - getName: function(path){ - var name = path; - var index = path.lastIndexOf('/'); - if ( index > 0 ){ - name = path.substr(index +1); - } - return name; - }, - getExtension: function(path){ var ext = null; var index = path.lastIndexOf('.'); diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.js index be4ac4aa66..117a41b8cc 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.js @@ -48,6 +48,15 @@ Sonia.repository.openListeners = []; // functions +Sonia.repository.createContentUrl = function(repository, path, revision){ + var contentUrl = restUrl + 'repositories/' + repository.id + '/'; + contentUrl += 'content?path=' + path; + if ( revision ){ + contentUrl += "&revision=" + revision; + } + return contentUrl; +} + Sonia.repository.isOwner = function(repository){ return admin || repository.permissions != null; } diff --git a/scm-webapp/src/main/webapp/resources/js/util/sonia.util.js b/scm-webapp/src/main/webapp/resources/js/util/sonia.util.js index 1977f5b54e..6f86a4f397 100644 --- a/scm-webapp/src/main/webapp/resources/js/util/sonia.util.js +++ b/scm-webapp/src/main/webapp/resources/js/util/sonia.util.js @@ -33,6 +33,24 @@ Ext.ns('Sonia.util'); // functions +Sonia.util.getName = function(path){ + var name = path; + var index = path.lastIndexOf('/'); + if ( index > 0 ){ + name = path.substr(index +1); + } + return name; +} + +Sonia.util.getExtension = function(path){ + var ext = null; + var index = path.lastIndexOf('.'); + if ( index > 0 ){ + ext = path.substr(index + 1, path.length); + } + return ext; +} + Sonia.util.clone = function(obj) { var newObj = (this instanceof Array) ? [] : {}; for (i in obj) {