mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
improve contentpanel
This commit is contained in:
@@ -33,12 +33,21 @@
|
||||
Sonia.repository.BlamePanel = Ext.extend(Ext.grid.GridPanel, {
|
||||
|
||||
blameUrl: null,
|
||||
repository: null,
|
||||
path: null,
|
||||
revision: null,
|
||||
linkTemplate: '<a class="scm-link blame-link" rel="{1}">{0}</a>',
|
||||
|
||||
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 + '<br />';
|
||||
@@ -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 '<a>' + value + '</a>';
|
||||
return String.format(
|
||||
this.linkTemplate,
|
||||
value,
|
||||
value
|
||||
);
|
||||
},
|
||||
|
||||
renderCode: function(value){
|
||||
|
||||
@@ -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('.');
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user