this.modified=ko.observable(false);
this.modified.subscribe(function(newValue){$.log("ProxyConnector modified:"+newValue)});
+
+ this.policiesEntries=[];
+ this.propertiesEntries=[];
+
+ this.deleteProperty=function(key){
+ $.log("delete property key:"+key());
+ for(i=0;i<self.properties().length;i++){
+ var entry=self.properties()[i];
+ if (entry.key()==key()){
+ self.properties.remove(entry);
+ }
+ }
+
+ }
+
+ this.addProperty=function(){
+ var mainContent=$("#main-content");
+ var key=mainContent.find("#property-key").val();
+ var value=mainContent.find("#property-value").val();
+ var oldTab = self.properties();
+ oldTab.push(new Entry(key,value));
+ self.properties(oldTab);
+ }
}
PolicyInformation=function(options,defaultOption,id,name){
this.name.subscribe(function(newValue){self.modified(true)});
}
-
- ManagedRepositoryConnectorView=function(source,sourceName,targetRepos){
- var self=this;
- this.modified=ko.observable(false);
- //this.proxyConnector=ko.observable(proxyConnector);
- //$.log("new ManagedRepositoryConnectorView:"+proxyConnector.id);
- this.source=ko.observable(source);
- this.sourceName=ko.observable(sourceName);
- //$.log("new ManagedRepositoryConnectorView source id:"+this.source.id);
- this.targetRepos=ko.observableArray(targetRepos);
- }
-
ProxyConnectorViewModel=function(proxyConnector,update,proxyConnectorsViewModel){
var self=this;
this.proxyConnector=proxyConnector;
}
}
- deleteProperty=function(key){
- $.log("delete property key:"+key());
- for(i=0;i<self.proxyConnector.properties().length;i++){
- var entry=self.proxyConnector.properties()[i];
- if (entry.key()==key()){
- self.proxyConnector.properties.remove(entry);
- }
- }
- }
-
- addProperty=function(){
- var mainContent=$("#main-content");
- var key=mainContent.find("#property-key").val();
- var value=mainContent.find("#property-value").val();
- var oldTab = self.proxyConnector.properties();
- oldTab.push(new Entry(key,value));
- self.proxyConnector.properties(oldTab);
- }
addBlacklistPattern=function(){
var pattern = $("#main-content #blacklist-value").val();
save=function(){
//FIXME data controls !!!
-
+ clearUserMessages();
if (this.update){
} else {
+ self.proxyConnector.policiesEntries=self.proxyConnector.policies();
+ self.proxyConnector.propertiesEntries=self.proxyConnector.properties();
+ var json = $.toJSON(ko.toJS(self.proxyConnector));
+ $.log("toJSON:"+json);
+
$.ajax("restServices/archivaServices/proxyConnectorService/addProxyConnector",
{
type: "POST",
displaySuccessMessage($.i18n.prop('proxyconnector.added'));
activateProxyConnectorsGridTab();
self.proxyConnector.modified(false);
+ self.proxyConnectorsViewModel.proxyConnectors.push(self.proxyConnector);
},
error: function(data) {
var res = $.parseJSON(data.responseText);
ProxyConnectorsViewModel=function(){
var self=this;
this.proxyConnectors=ko.observableArray([]);
- this.managedRepositoryConnectorViews=ko.observableArray([]);
this.policyInformations=ko.observableArray([]);
this.managedRepositories=ko.observableArray([]);
this.remoteRepositories=ko.observableArray([]);
editProxyConnector=function(managedRepositoryConnectorView){
$.log("editProxyConnector");
}
-
- removeProxyConnector=function(sourceRepoId,targetRepoId){
- proxyConnector=getProxyConnector(sourceRepoId, targetRepoId);
- /*var url="restServices/archivaServices/proxyConnectorService/removeProxyConnector?";
+ deleteProxyConnector=function(proxyConnector){
+ clearUserMessages();
+ var url="restServices/archivaServices/proxyConnectorService/removeProxyConnector?";
url += "sourceRepoId="+encodeURIComponent(proxyConnector.sourceRepoId());
url += "&targetRepoId="+encodeURIComponent(proxyConnector.targetRepoId());
$.ajax(url,
type: "GET",
contentType: 'application/json',
success: function(data) {
- clearUserMessages();
displaySuccessMessage($.i18n.prop('proxyconnector.removed'));
- //self.proxyConnectors.remove ProxyConnector=function(sourceRepoId,targetRepoId
+ self.proxyConnectors.remove(proxyConnector);
self.displayGrid();
},
error: function(data) {
displayRestError(res);
}
}
- );*/
- self.proxyConnectors.remove(proxyConnector);
- self.displayGrid();
- }
+ );
- this.findUniqueManagedRepos=function(){
- var managedRepositoriesIds=[];
- //sourceRepoId
- for(i=0;i<self.proxyConnectors().length;i++){
- var curSrcRepoId=self.proxyConnectors()[i].sourceRepoId();
- if ($.inArray(curSrcRepoId,managedRepositoriesIds)<0){
- managedRepositoriesIds.push(curSrcRepoId)
- }
- }
- $.log("managedRepositoriesIds:"+managedRepositoriesIds);
- return managedRepositoriesIds;
}
+
getManagedRepository=function(id){
var managedRepository=$.grep(self.managedRepositories(),
function(repo,idx){
return ($.isArray(remoteRepository) && remoteRepository.length>0) ? remoteRepository[0]:new RemoteRepository();
}
- // return remote repositories proxied for a managed repository
- getRemoteRepositories=function(id){
- $.log("getRemoteRepositories:"+id);
- var remoteRepositoryIds=$.grep(self.proxyConnectors(),
- function(repo,idx){
- return repo.sourceRepoId()==id;
- }
- );
- $.log("remoteRepositoryIds.length:"+remoteRepositoryIds.length);
- var remoteRepositories=[];
- for (i=0;i<remoteRepositoryIds.length;i++){
- remoteRepositories.push(getRemoteRepository(remoteRepositoryIds[i].targetRepoId()));
- }
- return remoteRepositories;
- }
-
getProxyConnector=function(sourceRepoId,targetRepoId){
$.log("getProxyConnector:"+sourceRepoId+":"+targetRepoId);
var proxyConnector=$.grep(self.proxyConnectors(),
return res;
}
- showSettings=function(sourceRepoId,targetRepoId){
- var targetContent = $("#proxy-connectors-grid-remoterepo-settings-content-"+sourceRepoId+"-"+targetRepoId);
+ showSettings=function(proxyConnector){
+ //proxyConnector=getProxyConnector(proxyConnector.sourceRepoId(),proxyConnector.targetRepoId());
+ var targetContent = $("#proxy-connectors-grid-remoterepo-settings-content-"
+ +proxyConnector.sourceRepoId()+"-"+proxyConnector.targetRepoId());
targetContent.html("");
targetContent.append($("#proxy-connectors-remote-settings-popover-tmpl")
- .tmpl(getProxyConnector(sourceRepoId,targetRepoId)));
+ .tmpl(proxyConnector));
- var targetImg = $("#proxy-connectors-grid-remoterepo-settings-edit-"+sourceRepoId+"-"+targetRepoId);
+ var targetImg = $("#proxy-connectors-grid-remoterepo-settings-edit-"+proxyConnector.sourceRepoId()
+ +"-"+proxyConnector.targetRepoId());
targetImg.attr("data-content",targetContent.html());
targetImg.popover(
{
targetImg.popover('show');
+ $.log("showSettings:"+proxyConnector.policies().length);
+
}
this.displayGrid=function(){
- self.managedRepositoryConnectorViews(this.findUniqueManagedRepos());
this.gridViewModel = new ko.simpleGrid.viewModel({
- data: self.managedRepositoryConnectorViews,
+ data: self.proxyConnectors,
pageSize: 5,
gridUpdateCallBack: function(){
$("#main-content #proxyConnectorsTable [title]").tooltip();
if (data==null){
return null;
}
- var policies = data.policies == null ? []: $.each(data.policies,function(item){
+ var policies = (data.policies == null || data.policies.entry == null ) ? []: $.each(data.policies.entry,function(item){
+ $.log("each policies:");
return new Entry(item.key, item.value);
});
if (!$.isArray(policies)){
</script>
<script id='ko-proxy-connectors-grid' type='text/x-jquery-tmpl'>
- <thead>
- <tr>
- <th title="${$.i18n.prop('proxy-connectors.grid.managedrepo.title')}">
- ${$.i18n.prop('proxy-connectors.grid.managedrepo.grid.header')}
- </th>
- <th title="${$.i18n.prop('proxy-connectors.grid.remoterepo.title')}">
- ${$.i18n.prop('proxy-connectors.grid.remoterepo.grid.header')}
- </th>
- </tr>
- </thead>
-
- {{each(i, row) itemsOnCurrentPage()}}
+ <thead>
+ <tr>
+ <th title="${$.i18n.prop('proxy-connectors.grid.managedrepo.title')}">
+ ${$.i18n.prop('proxy-connectors.grid.managedrepo.grid.header')}
+ </th>
+ <th title="${$.i18n.prop('proxy-connectors.grid.remoterepo.title')}">
+ ${$.i18n.prop('proxy-connectors.grid.remoterepo.grid.header')}
+ </th>
+ <th>
+ ${$.i18n.prop('edit')}
+ </th>
+ <th>
+ ${$.i18n.prop('delete')}
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ {{each(i, row) itemsOnCurrentPage()}}
<tr>
+ <td>${row.sourceRepoId()}</td>
+ <td>${row.targetRepoId()}</td>
<td>
- <blockquote>
- <p>${getManagedRepository(row).id()}</p>
- <p>${getManagedRepository(row).name()}</p>
- </blockquote>
+ <a popover-title="${$.i18n.prop('proxy-connectors.grid.remoterepo.settings.popover.title')}"
+ data-bind="event: { mouseover: function(){ showSettings(row)},},click: function(){ editProxyConnector(row)}"
+ id="proxy-connectors-grid-remoterepo-settings-edit-${row.sourceRepoId()}-${row.targetRepoId()}" href="#">
+ ${$.i18n.prop('edit')}
+ </a>
+ <div id="proxy-connectors-grid-remoterepo-settings-content-${row.sourceRepoId()}-${row.targetRepoId()}"
+ style="display:none"></div>
</td>
<td>
- {{each(j, targetRepo) getRemoteRepositories(row)}}
- {{var targetRepoId = targetRepo.id()}}
- <blockquote>
- <p>${targetRepoId}</p>
- <p>${getRemoteRepository(targetRepoId).name()}</p>
- <p>${getRemoteRepository(targetRepoId).url()}</p>
- <p>
- <a popover-title="${$.i18n.prop('proxy-connectors.grid.remoterepo.settings.popover.title')}"
- data-bind="event: { mouseover: function(){ showSettings(row,targetRepoId)},},click: function(){ editProxyConnector(row)}"
- id="proxy-connectors-grid-remoterepo-settings-edit-${row}-${targetRepoId}" href="#">
- ${$.i18n.prop('edit')}
- </a>
- <a href="#" data-bind="click: function(){ removeProxyConnector(row,targetRepo)}">
- <img src="images/edit-cut.png" title="${$.i18n.prop('delete')}"/>
- </a>
- <div id="proxy-connectors-grid-remoterepo-settings-content-${val}-${targetRepoId}" style="display:none"></div>
- </p>
- </blockquote>
- {{/each}}
+ <a href="#" data-bind="click: function(){ deleteProxyConnector(row)}">
+ <img src="images/edit-cut.png" title="${$.i18n.prop('delete')}"/>
+ </a>
</td>
</tr>
- {{/each}}
+ {{/each}}
+ </tbody>
+ <div id="proxy-connectors-grid-remoterepo-settings-content-${val}-${targetRepoId}" style="display:none"></div>
</script>
<script id='proxy-connectors-remote-settings-popover-tmpl' type='text/x-jquery-tmpl'>
<th colspan="2">${$.i18n.prop('proxy-connector.policies')}</th>
</thead>
<tbody>
- {{each policies().entry}}
+ {{each policies()}}
<tr>
<td>${$value.key}</td>
<td>${$value.value}</td>
<thead>
<th><input type="text" id="property-key"/></th>
<th><input type="text" id="property-value"/></th>
- <th><a href="#" data-bind="click: function(){ addProperty() }">${$.i18n.prop('add')}</a></th>
+ <th><a href="#" data-bind="click: function(){ proxyConnector.addProperty() }">${$.i18n.prop('add')}</a></th>
</thead>
<tbody data-bind="foreach: proxyConnector.properties">
<tr>