#873 added default branch chooser to git settings

This commit is contained in:
Sebastian Sdorra
2016-11-10 20:54:20 +01:00
parent f2137bd761
commit 0c0bdfa376
6 changed files with 148 additions and 13 deletions

View File

@@ -90,6 +90,93 @@ Sonia.git.ConfigPanel = Ext.extend(Sonia.config.SimpleConfigForm, {
Ext.reg("gitConfigPanel", Sonia.git.ConfigPanel); Ext.reg("gitConfigPanel", Sonia.git.ConfigPanel);
// add default branch chooser to settings panel
Sonia.git.GitSettingsFormPanel = Ext.extend(Sonia.repository.SettingsFormPanel, {
defaultBranchText: 'Default Branch',
defaultBranchHelpText: 'The default branch which is show first on source or commit view.',
modifyDefaultConfig: function(config){
if (this.item) {
var position = -1;
for ( var i=0; i<config.items.length; i++ ) {
var field = config.items[i];
if (field.name === 'public') {
position = i;
break;
}
}
var defaultBranchComboxBox = {
fieldLabel: this.defaultBranchText,
name: 'defaultBranch',
repositoryId: this.item.id,
value: this.getDefaultBranch(this.item),
useNameAsValue: true,
xtype: 'repositoryBranchComboBox',
helpText: this.defaultBranchHelpText
};
if (position >= 0) {
config.items.splice(position, 0, defaultBranchComboxBox);
} else {
config.items.push(defaultBranchComboxBox);
}
}
},
getDefaultBranch: function(item){
if (item.properties) {
for ( var i=0; i<item.properties.length; i++ ) {
var prop = item.properties[i];
if (prop.key === 'git.default-branch') {
return prop.value;
}
}
}
return undefined;
},
setDefaultBranch: function(item, defaultBranch){
if (!item.properties) {
item.properties = [{
key: 'git.default-branch',
value: defaultBranch
}];
} else {
var found = false;
for ( var i=0; i<item.properties.length; i++ ) {
var prop = item.properties[i];
if (prop.key === 'git.default-branch') {
prop.value = defaultBranch;
found = true;
break;
}
}
if (!found) {
item.properties.push({
key: 'git.default-branch',
value: defaultBranch
});
}
}
},
prepareUpdate: function(item) {
if (item.defaultBranch) {
var defaultBranch = item.defaultBranch;
delete item.defaultBranch;
this.setDefaultBranch(item, defaultBranch);
}
}
});
Ext.reg("gitSettingsForm", Sonia.git.GitSettingsFormPanel);
// i18n // i18n
if ( i18n && i18n.country === 'de' ){ if ( i18n && i18n.country === 'de' ){
@@ -107,9 +194,21 @@ if ( i18n && i18n.country === 'de' ){
Die Seite muss neu geladen werden wenn dieser Wert geändert wird.' Die Seite muss neu geladen werden wenn dieser Wert geändert wird.'
}); });
Ext.override(Sonia.git.GitSettingsFormPanel, {
// labels
defaultBranchText: 'Standard Branch',
// helpTexts
defaultBranchHelpText: 'Der Standard Branch wird für die Source und Commit Ansicht verwendet, \n\
wenn kein anderer Branch eingestellt wurde.'
});
} }
// register information panel // register information panel
initCallbacks.push(function(main){ initCallbacks.push(function(main){
@@ -117,6 +216,9 @@ initCallbacks.push(function(main){
checkoutTemplate: 'git clone <a href="{0}" target="_blank">{0}</a>', checkoutTemplate: 'git clone <a href="{0}" target="_blank">{0}</a>',
xtype: 'repositoryExtendedInfoPanel' xtype: 'repositoryExtendedInfoPanel'
}); });
main.registerSettingsForm('git', {
xtype: 'gitSettingsForm'
});
}); });
// register panel // register panel

View File

@@ -33,6 +33,7 @@
Sonia.repository.BranchComboBox = Ext.extend(Ext.form.ComboBox, { Sonia.repository.BranchComboBox = Ext.extend(Ext.form.ComboBox, {
repositoryId: null, repositoryId: null,
useNameAsValue: false,
initComponent: function(){ initComponent: function(){
var branchStore = new Sonia.rest.JsonStore({ var branchStore = new Sonia.rest.JsonStore({
@@ -47,8 +48,8 @@ Sonia.repository.BranchComboBox = Ext.extend(Ext.form.ComboBox, {
}); });
var config = { var config = {
valueField: 'revision',
displayField: 'name', displayField: 'name',
valueField: this.useNameAsValue ? 'name' : 'revision',
typeAhead: false, typeAhead: false,
editable: false, editable: false,
triggerAction: 'all', triggerAction: 'all',

View File

@@ -61,8 +61,15 @@ Sonia.repository.FormPanel = Ext.extend(Sonia.rest.FormPanel,{
Sonia.repository.FormPanel.superclass.initComponent.apply(this, arguments); Sonia.repository.FormPanel.superclass.initComponent.apply(this, arguments);
}, },
prepareUpdate: function(item) {
},
update: function(item){ update: function(item){
item = Ext.apply( this.item, item ); item = Ext.apply( this.item, item );
// allow plugins to modify item
this.prepareUpdate(item);
if ( debug ){ if ( debug ){
console.debug( 'update repository: ' + item.name ); console.debug( 'update repository: ' + item.name );
} }

View File

@@ -432,21 +432,22 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
var infoPanel = main.getInfoPanel(item.type); var infoPanel = main.getInfoPanel(item.type);
infoPanel.item = item; infoPanel.item = item;
var settingsForm = main.getSettingsForm(item.type);
settingsForm.item = item;
settingsForm.onUpdate = {
fn: this.reload,
scope: this
};
settingsForm.onCreate = {
fn: this.reload,
scope: this
};
var panels = [infoPanel]; var panels = [infoPanel];
if ( owner ){ if ( owner ){
panels.push({ panels.push(
item: item, settingsForm, {
xtype: 'repositorySettingsForm',
onUpdate: {
fn: this.reload,
scope: this
},
onCreate: {
fn: this.reload,
scope: this
}
},{
item: item, item: item,
xtype: 'repositoryPermissionsForm', xtype: 'repositoryPermissionsForm',
listeners: { listeners: {

View File

@@ -78,9 +78,15 @@ Sonia.repository.SettingsFormPanel = Ext.extend(Sonia.repository.FormPanel, {
helpText: this.publicHelpText helpText: this.publicHelpText
}] }]
}; };
this.modifyDefaultConfig(config);
Ext.apply(this, Ext.apply(this.initialConfig, config)); Ext.apply(this, Ext.apply(this.initialConfig, config));
Sonia.repository.SettingsFormPanel.superclass.initComponent.apply(this, arguments); Sonia.repository.SettingsFormPanel.superclass.initComponent.apply(this, arguments);
},
modifyDefaultConfig: function(config){
} }
}); });

View File

@@ -78,6 +78,7 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
mainTabPanel: null, mainTabPanel: null,
infoPanels: [], infoPanels: [],
settingsForm: [],
scripts: [], scripts: [],
stylesheets: [], stylesheets: [],
@@ -96,6 +97,23 @@ Sonia.scm.Main = Ext.extend(Ext.util.Observable, {
this.infoPanels[type] = panel; this.infoPanels[type] = panel;
}, },
registerSettingsForm: function(type, form){
this.settingsForm[type] = form;
},
getSettingsForm: function(type){
var rp = null;
var panel = this.settingsForm[type];
if ( ! panel ){
rp = {
xtype: 'repositorySettingsForm'
};
} else {
rp = Sonia.util.clone( panel );
}
return rp;
},
getInfoPanel: function(type){ getInfoPanel: function(type){
var rp = null; var rp = null;
var panel = this.infoPanels[type]; var panel = this.infoPanels[type];