mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 01:15:44 +01:00
improve contentpanel
This commit is contained in:
@@ -33,12 +33,21 @@
|
|||||||
Sonia.repository.BlamePanel = Ext.extend(Ext.grid.GridPanel, {
|
Sonia.repository.BlamePanel = Ext.extend(Ext.grid.GridPanel, {
|
||||||
|
|
||||||
blameUrl: null,
|
blameUrl: null,
|
||||||
|
repository: null,
|
||||||
|
path: null,
|
||||||
|
revision: null,
|
||||||
|
linkTemplate: '<a class="scm-link blame-link" rel="{1}">{0}</a>',
|
||||||
|
|
||||||
initComponent: function(){
|
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({
|
var blameStore = new Sonia.rest.JsonStore({
|
||||||
proxy: new Ext.data.HttpProxy({
|
proxy: new Ext.data.HttpProxy({
|
||||||
url: this.blameUrl,
|
url: blameUrl,
|
||||||
disableCaching: false
|
disableCaching: false
|
||||||
}),
|
}),
|
||||||
root: 'blamelines',
|
root: 'blamelines',
|
||||||
@@ -54,7 +63,8 @@ Sonia.repository.BlamePanel = Ext.extend(Ext.grid.GridPanel, {
|
|||||||
id: 'revision',
|
id: 'revision',
|
||||||
dataIndex: 'revision',
|
dataIndex: 'revision',
|
||||||
renderer: this.renderRevision,
|
renderer: this.renderRevision,
|
||||||
width: 20
|
width: 20,
|
||||||
|
scope: this
|
||||||
},{
|
},{
|
||||||
id: 'code',
|
id: 'code',
|
||||||
dataIndex: 'code',
|
dataIndex: 'code',
|
||||||
@@ -72,12 +82,43 @@ Sonia.repository.BlamePanel = Ext.extend(Ext.grid.GridPanel, {
|
|||||||
autoHeight: true,
|
autoHeight: true,
|
||||||
viewConfig: {
|
viewConfig: {
|
||||||
forceFit: true
|
forceFit: true
|
||||||
|
},
|
||||||
|
listeners: {
|
||||||
|
click: {
|
||||||
|
fn: this.onClick,
|
||||||
|
scope: this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ext.apply(this, Ext.apply(this.initialConfig, config));
|
Ext.apply(this, Ext.apply(this.initialConfig, config));
|
||||||
Sonia.repository.BlamePanel.superclass.initComponent.apply(this, arguments);
|
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){
|
renderRevision: function(value, metadata, record){
|
||||||
var title = 'Revision: ' + value;
|
var title = 'Revision: ' + value;
|
||||||
var tip = 'Author: ' + record.get('author').name + '<br />';
|
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);
|
tip += 'When: ' + Ext.util.Format.formatTimestamp(when);
|
||||||
}
|
}
|
||||||
metadata.attr = 'ext:qtitle="' + title + '"' + ' ext:qtip="' + tip + '"';
|
metadata.attr = 'ext:qtitle="' + title + '"' + ' ext:qtip="' + tip + '"';
|
||||||
return '<a>' + value + '</a>';
|
return String.format(
|
||||||
|
this.linkTemplate,
|
||||||
|
value,
|
||||||
|
value
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
renderCode: function(value){
|
renderCode: function(value){
|
||||||
|
|||||||
@@ -35,20 +35,12 @@ Sonia.repository.ContentPanel = Ext.extend(Ext.Panel, {
|
|||||||
revision: null,
|
revision: null,
|
||||||
path: null,
|
path: null,
|
||||||
contentUrl: null,
|
contentUrl: null,
|
||||||
blameUrl: null,
|
|
||||||
|
|
||||||
initComponent: function(){
|
initComponent: function(){
|
||||||
var name = this.getName(this.path);
|
var name = Sonia.util.getName(this.path);
|
||||||
|
this.contentUrl = Sonia.repository.createContentUrl(
|
||||||
var repositoryUrl = restUrl + 'repositories/' + this.repository.id + '/';
|
this.repository, this.path, this.revision
|
||||||
|
);
|
||||||
|
|
||||||
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];
|
var bottomBar = [this.path];
|
||||||
this.appendRepositoryProperties(bottomBar);
|
this.appendRepositoryProperties(bottomBar);
|
||||||
@@ -71,7 +63,7 @@ Sonia.repository.ContentPanel = Ext.extend(Ext.Panel, {
|
|||||||
bbar: bottomBar,
|
bbar: bottomBar,
|
||||||
items: [{
|
items: [{
|
||||||
xtype: 'syntaxHighlighterPanel',
|
xtype: 'syntaxHighlighterPanel',
|
||||||
syntax: this.getExtension(this.path),
|
syntax: Sonia.util.getExtension(this.path),
|
||||||
contentUrl: this.contentUrl
|
contentUrl: this.contentUrl
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
@@ -83,7 +75,7 @@ Sonia.repository.ContentPanel = Ext.extend(Ext.Panel, {
|
|||||||
openSyntaxPanel: function(){
|
openSyntaxPanel: function(){
|
||||||
this.openPanel({
|
this.openPanel({
|
||||||
xtype: 'syntaxHighlighterPanel',
|
xtype: 'syntaxHighlighterPanel',
|
||||||
syntax: this.getExtension(this.path),
|
syntax: Sonia.util.getExtension(this.path),
|
||||||
contentUrl: this.contentUrl
|
contentUrl: this.contentUrl
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -91,7 +83,9 @@ Sonia.repository.ContentPanel = Ext.extend(Ext.Panel, {
|
|||||||
openBlamePanel: function(){
|
openBlamePanel: function(){
|
||||||
this.openPanel({
|
this.openPanel({
|
||||||
xtype: 'blamePanel',
|
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){
|
getExtension: function(path){
|
||||||
var ext = null;
|
var ext = null;
|
||||||
var index = path.lastIndexOf('.');
|
var index = path.lastIndexOf('.');
|
||||||
|
|||||||
@@ -48,6 +48,15 @@ Sonia.repository.openListeners = [];
|
|||||||
|
|
||||||
// functions
|
// 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){
|
Sonia.repository.isOwner = function(repository){
|
||||||
return admin || repository.permissions != null;
|
return admin || repository.permissions != null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,24 @@ Ext.ns('Sonia.util');
|
|||||||
|
|
||||||
// functions
|
// 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) {
|
Sonia.util.clone = function(obj) {
|
||||||
var newObj = (this instanceof Array) ? [] : {};
|
var newObj = (this instanceof Array) ? [] : {};
|
||||||
for (i in obj) {
|
for (i in obj) {
|
||||||
|
|||||||
Reference in New Issue
Block a user