]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1576] rewrite proxies connector page
authorOlivier Lamy <olamy@apache.org>
Thu, 9 Feb 2012 23:08:43 +0000 (23:08 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 9 Feb 2012 23:08:43 +0000 (23:08 +0000)
cleanup grid and forms for add.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1242598 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/network-proxies.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/proxy-connectors.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js

index 34852932462c1b61c6dafd1d0453d6408f9f9e23..d5f8682a321022ebfd4e1641bf499bd03e34d626 100644 (file)
@@ -87,6 +87,29 @@ $(function() {
 
     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){
@@ -111,18 +134,6 @@ $(function() {
     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;
@@ -152,25 +163,7 @@ $(function() {
       }
     }
 
-    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();
@@ -198,10 +191,15 @@ $(function() {
 
     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",
@@ -212,6 +210,7 @@ $(function() {
               displaySuccessMessage($.i18n.prop('proxyconnector.added'));
               activateProxyConnectorsGridTab();
               self.proxyConnector.modified(false);
+              self.proxyConnectorsViewModel.proxyConnectors.push(self.proxyConnector);
             },
             error: function(data) {
               var res = $.parseJSON(data.responseText);
@@ -231,7 +230,6 @@ $(function() {
   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([]);
@@ -240,10 +238,9 @@ $(function() {
     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,
@@ -251,9 +248,8 @@ $(function() {
           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) {
@@ -261,24 +257,11 @@ $(function() {
             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){
@@ -298,22 +281,6 @@ $(function() {
       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(),
@@ -327,13 +294,16 @@ $(function() {
       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(
           {
@@ -345,12 +315,13 @@ $(function() {
 
       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();
@@ -465,7 +436,8 @@ $(function() {
     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)){
index 3e8867e39563e57d6f5affd0ed7433e18a40c16a..85613982f4b4468d38f3db4430298d58602a2816 100644 (file)
         {{else}}
           <td></td>
         {{/if}}
-        <td>${row.useNtlm()}</td>
-        <td>
+          <td>${row.useNtlm()}</td>
+          <td>
             <a href="#" data-bind="click: function(){ editNetworkProxy(row) }">${$.i18n.prop('edit')}</a>
-        </td>
-        <td>
+          </td>
+          <td>
             <a href="#" data-bind="click: function(){ removeNetworkProxy(row) }">
               <img src="images/edit-cut.png" title="${$.i18n.prop('delete')}"/>
             </a>
-        </td>
+          </td>
         {{if row.modified()}}
           <td>
             <a href="#" data-bind="click: function(){ updateNetworkProxy(row) }">${$.i18n.prop('save')}</a>
index 69f2557ef87f5381876873df6d07311bc821fa77..f5cdf1df9c7923ecd4ecf13632d3d8334898047f 100644 (file)
 </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'>
@@ -98,7 +95,7 @@
         <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>
index 9eaf929ef5bb5126fe5086305cc1bea75ddaab40..dff66bca29726f3f74432a15b5c40bd305320bcb 100644 (file)
@@ -312,11 +312,10 @@ appendTemplateUrl=function(){
  */
 Entry=function(key,value){
   var self=this;
-  this.modified=ko.observable(false);
   this.key=ko.observable(key);
-  this.key.subscribe(function(newValue){self.modified(true)});
+  //this.key.subscribe(function(newValue){self.modified(true)});
   this.value=ko.observable(value);
-  this.value.subscribe(function(newValue){self.modified(true)});
+  //this.value.subscribe(function(newValue){self.modified(true)});
 }
 
 // extends jquery tmpl to support var def
index 1f38f07433a4de24e51b42cb6f8e3340c3f6effc..4c2ca96ee67ecca61b186871f881011ce984d275 100644 (file)
@@ -66,7 +66,7 @@
           var pageLinksContainer = $("#"+allBindings.pageLinksId).get(0);
           if (viewModel.pageLinksUpdateCallBack){
             ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode")
-              .subscribe(viewModel.pageLinksUpdateCallBack?viewModel.pageLinksUpdateCallBack:function(){});
+              .subscribe(viewModel.pageLinksUpdateCallBack);
           } else {
             ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode");
           }