mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
added RepositoryResource
This commit is contained in:
176
scm-webapp/src/main/java/sonia/scm/Repository.java
Normal file
176
scm-webapp/src/main/java/sonia/scm/Repository.java
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@XmlRootElement(name = "repositories")
|
||||
@XmlType(propOrder =
|
||||
{
|
||||
"type", "name", "contact", "description"
|
||||
})
|
||||
public class Repository implements Serializable
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final long serialVersionUID = 3486560714961909711L;
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public Repository() {}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param name
|
||||
*/
|
||||
public Repository(String type, String name)
|
||||
{
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param name
|
||||
* @param contact
|
||||
* @param description
|
||||
*/
|
||||
public Repository(String type, String name, String contact,
|
||||
String description)
|
||||
{
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.contact = contact;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getContact()
|
||||
{
|
||||
return contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param contact
|
||||
*/
|
||||
public void setContact(String contact)
|
||||
{
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param description
|
||||
*/
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String contact;
|
||||
|
||||
/** Field description */
|
||||
private String description;
|
||||
|
||||
/** Field description */
|
||||
private String name;
|
||||
|
||||
/** Field description */
|
||||
private String type;
|
||||
}
|
||||
@@ -40,14 +40,14 @@ import javax.ws.rs.core.UriInfo;
|
||||
@Singleton
|
||||
@Path("groups")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public class GroupsResource
|
||||
public class GroupResource
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public GroupsResource()
|
||||
public GroupResource()
|
||||
{
|
||||
groupStore = new LinkedHashMap<String, Group>();
|
||||
groupStore.put("csit",
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.api.rest.resources;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.Repository;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
@Path("repositories")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public class RepositoryResource
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public RepositoryResource()
|
||||
{
|
||||
repositoryStore = new LinkedHashMap<String, Repository>();
|
||||
repositoryStore.put("sonia.lib",
|
||||
new Repository("hg", "sonia.lib", "csit@ostfalia.de",
|
||||
"SONIA Library"));
|
||||
repositoryStore.put("sonia.misc",
|
||||
new Repository("hg", "sonia.misc", "csit@ostfalia.de",
|
||||
"SONIA Miscelanious"));
|
||||
repositoryStore.put("PWA",
|
||||
new Repository("svn", "PWA",
|
||||
"csit@fh-wolfenbuettel.de", "PWA"));
|
||||
repositoryStore.put("sonia.app",
|
||||
new Repository("hg", "sonia.app", "csit@ostfalia.de",
|
||||
"SONIA Applications"));
|
||||
repositoryStore.put("sonia.webapps",
|
||||
new Repository("hg", "sonia.webapps",
|
||||
"csit@ostfalia.de",
|
||||
"SONIA WebApplications"));
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@Path("{name}")
|
||||
public Repository get(@PathParam("name") String name)
|
||||
{
|
||||
Repository repository = repositoryStore.get(name);
|
||||
|
||||
if (repository == null)
|
||||
{
|
||||
throw new WebApplicationException(Status.NOT_FOUND);
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
public Repository[] getAll()
|
||||
{
|
||||
Collection<Repository> repositoryCollection = repositoryStore.values();
|
||||
|
||||
return repositoryCollection.toArray(
|
||||
new Repository[repositoryCollection.size()]);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private HashMap<String, Repository> repositoryStore;
|
||||
}
|
||||
@@ -84,14 +84,33 @@ Ext.onReady(function(){
|
||||
tabPanel.setActiveTab('t_group');
|
||||
}
|
||||
|
||||
function addRepositoryPanel(){
|
||||
tabPanel.add({
|
||||
id: 't_repository',
|
||||
xtype: 'repositoryGrid',
|
||||
title: 'Repositories',
|
||||
closable: true,
|
||||
autoScroll: true
|
||||
});
|
||||
tabPanel.setActiveTab('t_repository');
|
||||
}
|
||||
|
||||
function createMainMenu(){
|
||||
var menu = Ext.get( 'main-menu' );
|
||||
|
||||
var groupsLink = menu.createChild({
|
||||
tag: 'li',
|
||||
html: 'Groups',
|
||||
style: 'cursor: pointer;'
|
||||
});
|
||||
groupsLink.on('click', addGroupPanel);
|
||||
|
||||
var repositoryLink = menu.createChild({
|
||||
tag: 'li',
|
||||
html: 'Repositories',
|
||||
style: 'cursor: pointer;'
|
||||
});
|
||||
repositoryLink.on('click', addRepositoryPanel);
|
||||
}
|
||||
|
||||
Ext.Ajax.request({
|
||||
|
||||
@@ -13,6 +13,7 @@ Sonia.group.EditForm = new Ext.extend(Sonia.rest.EditForm, {
|
||||
});
|
||||
|
||||
var config = {
|
||||
title: 'Edit Group',
|
||||
items:[{
|
||||
fieldLabel:'Name',
|
||||
name:'name',
|
||||
|
||||
@@ -5,28 +5,59 @@
|
||||
|
||||
Ext.ns('Sonia.repository');
|
||||
|
||||
Sonia.repository.Grid = Ext.extend(Ext.grid.GridPanel, {
|
||||
Sonia.repository.EditForm = Ext.extend(Sonia.rest.EditForm, {
|
||||
|
||||
initComponent: function(){
|
||||
|
||||
var repositoryStore = new Ext.data.JsonStore({
|
||||
url: 'rest/repositories.json',
|
||||
root: 'repository',
|
||||
var config = {
|
||||
title: 'Edit Repository',
|
||||
items:[
|
||||
{fieldLabel: 'Name', name: 'name', allowBlank: false},
|
||||
{
|
||||
fieldLabel: 'Type',
|
||||
name: 'type',
|
||||
xtype: 'combo',
|
||||
hiddenName : 'type',
|
||||
typeAhead: true,
|
||||
triggerAction: 'all',
|
||||
lazyRender: true,
|
||||
mode: 'local',
|
||||
editable: false,
|
||||
store: repositoryTypeStore,
|
||||
valueField: 'type',
|
||||
displayField: 'name',
|
||||
allowBlank: false
|
||||
},
|
||||
|
||||
{fieldLabel: 'Contact', name: 'contact'},
|
||||
{fieldLabel: 'Description', name: 'description', xtype: 'textarea'}
|
||||
]
|
||||
};
|
||||
|
||||
Ext.apply(this, Ext.apply(this.initialConfig, config));
|
||||
Sonia.repository.EditForm.superclass.initComponent.apply(this, arguments);
|
||||
},
|
||||
|
||||
getItem: function(form){
|
||||
var value = form.getFieldValues();
|
||||
console.debug( value );
|
||||
return value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Ext.reg('repositoryEditForm', Sonia.repository.EditForm);
|
||||
|
||||
Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
|
||||
|
||||
initComponent: function(){
|
||||
|
||||
var repositoryStore = new Sonia.rest.JsonStore({
|
||||
url: restUrl + 'repositories.json',
|
||||
root: 'repositories',
|
||||
fields: [ 'name', 'type', 'contact', 'description' ],
|
||||
sortInfo: {
|
||||
field: 'name'
|
||||
},
|
||||
autoLoad: true,
|
||||
listeners: {
|
||||
// fix jersey empty array problem
|
||||
exception: {
|
||||
fn: function(proxy, type, action, options, response, arg){
|
||||
if ( action == "read" && response.responseText == "null" ){
|
||||
this.store.removeAll();
|
||||
}
|
||||
},
|
||||
scope: this
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -39,219 +70,21 @@ Sonia.repository.Grid = Ext.extend(Ext.grid.GridPanel, {
|
||||
]
|
||||
});
|
||||
|
||||
var repositorySelModel = new Ext.grid.RowSelectionModel({
|
||||
singleSelect: true
|
||||
});
|
||||
|
||||
var repositoryToolbar = new Ext.Toolbar({
|
||||
items: [
|
||||
{xtype: 'tbbutton', text: 'Add', scope: this, handler: this.showAddWindow},
|
||||
{xtype: 'tbbutton', text: 'Edit', scope: this, handler: this.showEditWindow},
|
||||
{xtype: 'tbbutton', text: 'Remove', scope: this, handler: this.remove},
|
||||
{xtype: 'tbbutton', text: 'Reload', scope: this, handler: this.reload},
|
||||
{xtype: 'tbseparator'},
|
||||
{xtype: 'label', text: 'Search: '},
|
||||
{xtype: 'textfield', listeners: {
|
||||
specialkey: {
|
||||
fn: function(field, e){
|
||||
if (e.getKey() == e.ENTER) {
|
||||
this.search(field.getValue());
|
||||
}
|
||||
},
|
||||
scope: this
|
||||
}
|
||||
}}
|
||||
]
|
||||
});
|
||||
|
||||
var config = {
|
||||
store: repositoryStore,
|
||||
colModel: repositoryColModel,
|
||||
selModel: repositorySelModel,
|
||||
tbar: repositoryToolbar,
|
||||
viewConfig: {
|
||||
forceFit: true
|
||||
},
|
||||
loadMask: true,
|
||||
listeners: {
|
||||
celldblclick: this.showEditWindow
|
||||
}
|
||||
idField: 'name',
|
||||
searchField: 'name',
|
||||
editForm: 'repositoryEditForm',
|
||||
restAddUrl: restUrl + 'repositories.json',
|
||||
restEditUrlPattern: restUrl + 'repositories/{0}.json',
|
||||
restRemoveUrlPattern: restUrl + 'repositories/{0}.json'
|
||||
};
|
||||
|
||||
Ext.apply(this, Ext.apply(this.initialConfig, config));
|
||||
Sonia.repository.Grid.superclass.initComponent.apply(this, arguments);
|
||||
},
|
||||
|
||||
search: function( value ){
|
||||
this.store.filter('name', new RegExp('.*' + value + '.*'));
|
||||
},
|
||||
|
||||
showAddWindow: function(){
|
||||
this.showFormWindow(new Sonia.repository.EditForm());
|
||||
},
|
||||
|
||||
showEditWindow: function(){
|
||||
if ( this.selModel.hasSelection() ){
|
||||
var repository = this.selModel.getSelected().data;
|
||||
var form = new Sonia.repository.EditForm({
|
||||
url: 'rest/repositories/' + repository.name + ".json",
|
||||
method: 'PUT',
|
||||
update: true
|
||||
});
|
||||
form.load( repository );
|
||||
this.showFormWindow(form);
|
||||
}
|
||||
},
|
||||
|
||||
showFormWindow: function( form ){
|
||||
var win = new Sonia.repository.DetailWindow();
|
||||
form.on('finish', function(reload){
|
||||
win.close();
|
||||
if ( reload ){
|
||||
this.store.reload();
|
||||
}
|
||||
}, this);
|
||||
win.add(form);
|
||||
win.show();
|
||||
},
|
||||
|
||||
remove: function(){
|
||||
if ( this.selModel.hasSelection() ){
|
||||
var repository = this.selModel.getSelected().data.name;
|
||||
|
||||
var grid = this;
|
||||
|
||||
Ext.MessageBox.show({
|
||||
title: "Remove Repository?",
|
||||
msg: "Remove Repository '" + repository + "'?",
|
||||
buttons: Ext.MessageBox.OKCANCEL,
|
||||
icon: Ext.MessageBox.QUESTION,
|
||||
scope: this,
|
||||
fn: function(result){
|
||||
if ( result == "ok" ){
|
||||
Ext.Ajax.request({
|
||||
url: 'rest/repositories/' + repository + ".json",
|
||||
method: 'DELETE',
|
||||
success: function(){
|
||||
grid.reload();
|
||||
},
|
||||
failure: function(){
|
||||
alert("ERROR!!!")
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
reload: function(){
|
||||
this.store.reload();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Ext.reg('repositoryGrid', Sonia.repository.Grid);
|
||||
|
||||
Sonia.repository.EditForm = Ext.extend(Ext.form.FormPanel, {
|
||||
|
||||
url: 'rest/repositories.json',
|
||||
method: 'POST',
|
||||
update: false,
|
||||
|
||||
initComponent: function(){
|
||||
|
||||
var config = {
|
||||
labelWidth: 80,
|
||||
autoHeight: true,
|
||||
frame: true,
|
||||
url: this.url,
|
||||
title: 'Edit Repository',
|
||||
defaultType:'textfield',
|
||||
monitorValid: true,
|
||||
defaults : { width: 190 },
|
||||
items:[
|
||||
{fieldLabel: 'Name', name: 'name', readOnly: this.update, allowBlank: false},
|
||||
|
||||
// TODO: replace store with dynamic one
|
||||
{
|
||||
fieldLabel: 'Type',
|
||||
name: 'type',
|
||||
xtype: 'combo',
|
||||
hiddenName : 'type',
|
||||
typeAhead: true,
|
||||
triggerAction: 'all',
|
||||
lazyRender: true,
|
||||
readOnly: this.update,
|
||||
mode: 'local',
|
||||
editable: false,
|
||||
store: repositoryTypeStore,
|
||||
valueField: 'type',
|
||||
displayField: 'name',
|
||||
allowBlank: false
|
||||
},
|
||||
|
||||
{fieldLabel: 'Contact', name: 'contact'},
|
||||
{fieldLabel: 'Description', name: 'description', xtype: 'textarea'}
|
||||
],
|
||||
buttons:[
|
||||
{text: 'Ok', formBind: true, scope: this, handler: this.submit},
|
||||
{text: 'Cancel', scope: this, handler: this.cancel}
|
||||
]
|
||||
};
|
||||
|
||||
this.addEvents('finish');
|
||||
|
||||
Ext.apply(this, Ext.apply(this.initialConfig, config));
|
||||
Sonia.repository.EditForm.superclass.initComponent.apply(this, arguments);
|
||||
},
|
||||
|
||||
load: function(repository){
|
||||
var data = { success: true, data: repository };
|
||||
this.getForm().loadRecord( data );
|
||||
},
|
||||
|
||||
submit: function(){
|
||||
var editForm = this;
|
||||
|
||||
this.getForm().submit({
|
||||
method: editForm.method,
|
||||
success: function(){
|
||||
editForm.fireEvent('finish', true);
|
||||
},
|
||||
failure: function(){
|
||||
alert( "failure!!!" );
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
cancel: function(){
|
||||
this.fireEvent('finish', false);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Ext.reg('repositoryEditForm', Sonia.repository.EditForm);
|
||||
|
||||
|
||||
Sonia.repository.DetailWindow = Ext.extend(Ext.Window, {
|
||||
|
||||
initComponent: function(){
|
||||
var config = {
|
||||
layout:'fit',
|
||||
width:300,
|
||||
autoScroll: true,
|
||||
closable: false,
|
||||
resizable: false,
|
||||
plain: true,
|
||||
border: false,
|
||||
modal: true
|
||||
};
|
||||
|
||||
Ext.apply(this, Ext.apply(this.initialConfig, config));
|
||||
Sonia.repository.DetailWindow.superclass.initComponent.apply(this, arguments);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Ext.reg('repositoryDetailWindow', Sonia.repository.DetailWindow);
|
||||
|
||||
Reference in New Issue
Block a user