[MRM-1574] remote repositories grid view

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1235176 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-01-24 09:17:50 +00:00
parent 1526829bea
commit 78c483be7f
2 changed files with 216 additions and 87 deletions

View File

@ -123,6 +123,30 @@ $(function() {
this.managedRepository = managedRepository;
}
mapManagedRepositories=function(data){
var mappedManagedRepositories = $.map(data.managedRepository, function(item) {
return mapManagedRepository(item);
});
return mappedManagedRepositories;
}
mapManagedRepository=function(data){
if (data==null){
return null;
}
return new ManagedRepository(data.id,data.name,data.layout,data.indexDirectory,data.location,data.snapshots,data.releases,
data.blockRedeployments,data.cronExpression,
data.scanned,data.daysOlder,data.retentionCount,data.deleteReleasedSnapshots,data.stageRepoNeeded);
}
mapArchivaRepositoryStatistics=function(data){
if (data==null){
return null;
}
return new ArchivaRepositoryStatistics(data.scanEndTime,data.scanStartTime,data.totalArtifactCount,data.totalArtifactFileSize,
data.totalFileCount,data.totalGroupCount,data.totalProjectCount,data.newFileCount,
data.duration,data.managedRepository)
}
ManagedRepositoryViewModel=function(managedRepository, update, managedRepositoriesViewModel){
this.managedRepository=managedRepository;
this.managedRepositoriesViewModel = managedRepositoriesViewModel;
@ -398,92 +422,6 @@ $(function() {
}
displayRepositoriesGrid=function(){
clearUserMessages();
$("#main-content").html(mediumSpinnerImg());
$("#main-content").html($("#repositoriesMain").tmpl());
$("#main-content #repositories-tabs").tabs();
$("#main-content #managed-repositories-content").append(mediumSpinnerImg());
$("#main-content #remote-repositories-content").append(mediumSpinnerImg());
var managedRepositoriesViewModel = new ManagedRepositoriesViewModel();
$.ajax("restServices/archivaServices/managedRepositoriesService/getManagedRepositories", {
type: "GET",
dataType: 'json',
success: function(data) {
managedRepositoriesViewModel.managedRepositories(mapManagedRepositories(data));
managedRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
data: managedRepositoriesViewModel.managedRepositories,
columns: [
{
headerText: $.i18n.prop('identifier'),
rowText: "id"
},
{
headerText: $.i18n.prop('name'),
rowText: "name"
},
{
headerText: $.i18n.prop('type'),
rowText: "getTypeLabel",
// FIXME i18n
title: "Repository type (default is Maven 2)"
}
],
pageSize: 5,
gridUpdateCallBack: function(){
$("#main-content #managed-repositories-table [title]").twipsy();
}
});
ko.applyBindings(managedRepositoriesViewModel,$("#main-content #managed-repositories-table").get(0));
$("#main-content #managed-repositories-pills").pills();
$("#managed-repositories-view").addClass("active");
removeMediumSpinnerImg("#main-content #managed-repositories-content");
activateManagedRepositoriesGridTab();
}
}
);
$("#main-content #managed-repositories-pills").bind('change', function (e) {
if ($(e.target).attr("href")=="#managed-repository-edit") {
var viewModel = new ManagedRepositoryViewModel(new ManagedRepository(),false,managedRepositoriesViewModel);
ko.applyBindings(viewModel,$("#main-content #managed-repository-edit").get(0));
activateManagedRepositoryFormValidation();
}
if ($(e.target).attr("href")=="#managed-repositories-view") {
$("#main-content #managed-repository-edit-li a").html($.i18n.prop("add"));
}
});
}
mapManagedRepositories=function(data){
var mappedManagedRepositories = $.map(data.managedRepository, function(item) {
return mapManagedRepository(item);
});
return mappedManagedRepositories;
}
mapManagedRepository=function(data){
if (data==null){
return null;
}
return new ManagedRepository(data.id,data.name,data.layout,data.indexDirectory,data.location,data.snapshots,data.releases,
data.blockRedeployments,data.cronExpression,
data.scanned,data.daysOlder,data.retentionCount,data.deleteReleasedSnapshots,data.stageRepoNeeded);
}
mapArchivaRepositoryStatistics=function(data){
if (data==null){
return null;
}
return new ArchivaRepositoryStatistics(data.scanEndTime,data.scanStartTime,data.totalArtifactCount,data.totalArtifactFileSize,
data.totalFileCount,data.totalGroupCount,data.totalProjectCount,data.newFileCount,
data.duration,data.managedRepository)
}
activateManagedRepositoriesGridTab=function(){
$("#main-content #managed-repository-edit-li").removeClass("active");
$("#main-content #managed-repository-edit").removeClass("active");
@ -501,6 +439,7 @@ $(function() {
$("#main-content #managed-repository-edit").addClass("active");
}
//---------------------------
// Remote repositories part
//---------------------------
@ -552,6 +491,17 @@ $(function() {
//private boolean downloadRemoteIndexOnStartup = false;
this.downloadRemoteIndexOnStartup=ko.observable(downloadRemoteIndexOnStartup);
var self=this;
this.getTypeLabel=function(){
for(i=0;i<window.managedRepositoryTypes.length;i++){
if (window.managedRepositoryTypes[i].type==self.layout()){
return window.managedRepositoryTypes[i].label;
}
}
return "no label";
}
}
mapRemoteRepository=function(data){
@ -570,4 +520,129 @@ $(function() {
return mappedRemoteRepositories;
}
RemoteRepositoriesViewModel=function(){
this.remoteRepositories=ko.observableArray([]);
this.gridViewModel = null;
var self = this;
editRemoteRepository=function(remoteRepository){
$.log("editRemoteRepository");
}
removeRemoteRepository=function(remoteRepository){
$.log("removeRemoteRepository");
}
downloadRemoteIndex=function(remoteRepository){
$.log("downloadRemoteIndex");
}
}
//---------------------------
// Screen loading
//---------------------------
displayRepositoriesGrid=function(){
clearUserMessages();
$("#main-content").html(mediumSpinnerImg());
$("#main-content").html($("#repositoriesMain").tmpl());
$("#main-content #repositories-tabs").tabs();
$("#main-content #managed-repositories-content").append(mediumSpinnerImg());
$("#main-content #remote-repositories-content").append(mediumSpinnerImg());
var managedRepositoriesViewModel = new ManagedRepositoriesViewModel();
var remoteRepositoriesViewModel = new RemoteRepositoriesViewModel();
$.ajax("restServices/archivaServices/managedRepositoriesService/getManagedRepositories", {
type: "GET",
dataType: 'json',
success: function(data) {
managedRepositoriesViewModel.managedRepositories(mapManagedRepositories(data));
managedRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
data: managedRepositoriesViewModel.managedRepositories,
columns: [
{
headerText: $.i18n.prop('identifier'),
rowText: "id"
},
{
headerText: $.i18n.prop('name'),
rowText: "name"
},
{
headerText: $.i18n.prop('type'),
rowText: "getTypeLabel",
// FIXME i18n
title: "Repository type (default is Maven 2)"
}
],
pageSize: 5,
gridUpdateCallBack: function(){
$("#main-content #managed-repositories-table [title]").twipsy();
}
});
ko.applyBindings(managedRepositoriesViewModel,$("#main-content #managed-repositories-table").get(0));
$("#main-content #managed-repositories-pills").pills();
$("#managed-repositories-view").addClass("active");
removeMediumSpinnerImg("#main-content #managed-repositories-content");
activateManagedRepositoriesGridTab();
}
}
);
$.ajax("restServices/archivaServices/remoteRepositoriesService/getRemoteRepositories", {
type: "GET",
dataType: 'json',
success: function(data) {
remoteRepositoriesViewModel.remoteRepositories(mapRemoteRepositories(data));
remoteRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
data: remoteRepositoriesViewModel.remoteRepositories,
columns: [
{
headerText: $.i18n.prop('identifier'),
rowText: "id"
},
{
headerText: $.i18n.prop('name'),
rowText: "name"
},
{
headerText: $.i18n.prop('type'),
rowText: "getTypeLabel",
// FIXME i18n
title: "Repository type (default is Maven 2)"
}
],
pageSize: 5,
gridUpdateCallBack: function(){
$("#main-content #remote-repositories-table [title]").twipsy();
}
});
ko.applyBindings(remoteRepositoriesViewModel,$("#main-content #remote-repositories-table").get(0));
$("#main-content #remote-repositories-pills").pills();
$("#remote-repositories-view").addClass("active");
removeMediumSpinnerImg("#main-content #remote-repositories-content");
//activateManagedRepositoriesGridTab();
}
}
);
$("#main-content #managed-repositories-pills").bind('change', function (e) {
if ($(e.target).attr("href")=="#managed-repository-edit") {
var viewModel = new ManagedRepositoryViewModel(new ManagedRepository(),false,managedRepositoriesViewModel);
ko.applyBindings(viewModel,$("#main-content #managed-repository-edit").get(0));
activateManagedRepositoryFormValidation();
}
if ($(e.target).attr("href")=="#managed-repositories-view") {
$("#main-content #managed-repository-edit-li a").html($.i18n.prop("add"));
}
});
}
});

View File

@ -54,7 +54,24 @@
<div id="remote-repositories-content">
grid to view edit remote repositories
<ul id="remote-repositories-pills" class="pills">
<li class="active" id="remote-repositories-view-li">
<a href="#remote-repositories-view">${$.i18n.prop('remoterepositories.grid.tab.title')}</a>
</li>
<li id="remote-repository-edit-li">
<a href="#remote-repository-edit">${$.i18n.prop('add')}</a>
</li>
</ul>
<div id="remote-repositories-tabs-content" class="pill-content">
<div id="remote-repositories-view" class="active">
<table class="bordered-table zebra-striped" id="remote-repositories-table"
data-bind="simpleGrid: gridViewModel,simpleGridTemplate:'ko_remote-repositoriesGrid',pageLinksId:'remote-repositoriesPagination',data:'remoteRepositories'">
</table>
<div id="remote-repositoriesPagination"></div>
</div>
<div id="remote-repository-edit" data-bind='template: {name:"remote-repository-edit-tmpl"}'>
</div>
</div>
</div>
</div>
</script>
@ -272,3 +289,40 @@
<div><a href="#" onclick="$('#managed-repositories-pom-snippet').effect('blind')">${$.i18n.prop('hide')}</a></div>
<pre>${$data}</pre>
</script>
<!-- remote part -->
<script id='ko_remote-repositoriesGrid' type='text/x-jquery-tmpl'>
<thead>
<tr>
{{each(i, columnDefinition) columns}}
<th title="${ columnDefinition.title }">${ columnDefinition.headerText }</th>
{{/each}}
<th>${$.i18n.prop('edit')}</th>
<th>${$.i18n.prop('delete')}</th>
<th>${$.i18n.prop('remoterepository.downloadremoteindex')}</th>
</tr>
</thead>
<tbody>
{{each(i, row) itemsOnCurrentPage()}}
<tr>
{{each(j, columnDefinition) columns}}
<td>${ typeof columnDefinition.rowText == 'function' ? columnDefinition.rowText(row) : row[columnDefinition.rowText] }</td>
{{/each}}
<td><a href="#" data-bind="click: function(){ editRemoteRepository(row) }">${$.i18n.prop('edit')}</a></td>
<td>
<a href="#" data-bind="click: function(){ removeRemoteRepository(row) }">
<img src="images/edit-cut.png" title="${$.i18n.prop('delete')}"/>
</a>
</td>
<td>
<a href="#" data-bind="click: function(){ downloadRemoteIndex(row) }">
<img src="images/view-refresh.png" data-bind="click: function(){ downloadRemoteIndex(row) }"
title="${$.i18n.prop('remoterepository.downloadremoteindex.now')}"/>
</a>
</td>
</tr>
{{/each}}
</tbody>
</script>