]> source.dussan.org Git - archiva.git/commitdiff
add js wrapper for repository connector bean model
authorOlivier Lamy <olamy@apache.org>
Mon, 30 Jan 2012 14:58:13 +0000 (14:58 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 30 Jan 2012 14:58:13 +0000 (14:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1237696 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/proxy-connectors.html

index 6a2660e08defaac51b112181100e872997853aff..7cbcb8a78c2b37ccfed99c1da20c2f2bcc69c90a 100644 (file)
@@ -51,25 +51,30 @@ $(function() {
     this.name=ko.observable(name);
   }
 
+  ManagedRepositoryConnectorView=function(source,targetRepos){
+    this.source=ko.observable(source);
+    this.targetRepos=ko.observableArray(targetRepos);
+  }
+
   ProxyConnectorsViewModel=function(){
     this.proxyConnectors=ko.observableArray([]);
     var self=this;
+    this.uniqueManagedRepos=ko.observableArray([]);
 
     editProxyConnector=function(proxyConnector){
 
     }
 
-    this.displayGrid=function(){
+    this.findUniqueManagedRepos=function(){
       var sourcesRepos=[];
       //sourceRepoId
       for(i=0;i<self.proxyConnectors().length;i++){
         var curSrcRepo=self.proxyConnectors()[i].sourceRepoId();
-
         var curTarget=self.proxyConnectors()[i].targetRepoId();
         var sourceRepo = $.grep(sourcesRepos,
                                 function(srcRepo,idx){
                                   for (j=0;j<sourcesRepos.length;j++){
-                                    if (srcRepo.source==sourcesRepos[j].source){
+                                    if (srcRepo.source()==curSrcRepo){
                                       return true;
                                     }
                                   }
@@ -79,15 +84,25 @@ $(function() {
         if (sourceRepo.length>0){
           sourceRepo[0].targetRepos.push(curTarget);
         } else {
-          $.log("sourceRepo==null:"+curSrcRepo);
-          sourcesRepos.push({source:curSrcRepo,targetRepos:[curTarget]});
-        if (sourceRepo!=null){
-          $.log("sourceRepoId:"+curSrcRepo);
-          sourcesRepos.push({source:curSrcRepo,targetRepos:[curTarget]});
-        } else {
-          sourceRepo.targetRepos.push(curTarget);
+          sourcesRepos.push(new ManagedRepositoryConnectorView(curSrcRepo,[curTarget]));
         }
       }
+      return sourcesRepos;
+    }
+
+    this.displayGrid=function(){
+      self.uniqueManagedRepos(this.findUniqueManagedRepos());
+      $.log("uniqueManagedRepos:"+self.uniqueManagedRepos().length);
+      this.gridViewModel = new ko.simpleGrid.viewModel({
+        data: self.uniqueManagedRepos,
+        pageSize: 5,
+        gridUpdateCallBack: function(){
+          $("#main-content #proxyConnectorsTable [title]").twipsy();
+        }
+      });
+      ko.applyBindings(this,$("#main-content #proxyConnectorsTable").get(0));
+      removeSmallSpinnerImg("#main-content");
+      $("#main-content #proxy-connectors-view-tabs").tabs();
     }
   }
 
@@ -144,8 +159,8 @@ $(function() {
 
   mapPolicyInformations=function(data){
     return $.map(data.policyInformation, function(item) {
-          return mapPolicyInformation(item);
-        });
+              return mapPolicyInformation(item);
+           });
   }
 
 });
\ No newline at end of file
index 7a2445a99c81cfbc05c9f80c70eacc3ab1f9296f..c015a26b311dfb45ee0d6181360beae2ed049ff6 100644 (file)
   <div class="page-header">
     <h2>${$.i18n.prop('proxy-connectors.list')}</h2>
   </div>
-  <ul id="proxy-connector-view-tabs" class="tabs">
-    <li id="network-proxies-view-tabs-li-grid" class="active">
-      <a href="#network-proxies-view" id="network-proxies-view-tabs-a-network-proxies-grid">${$.i18n.prop('network-proxies.grid.tab.title')}</a>
+
+  <ul id="proxy-connectors-view-tabs" class="tabs">
+    <li id="proxy-connectors-view-tabs-li-grid" class="active">
+      <a href="#proxy-connectors-view" id="proxy-connectors-view-tabs-a-network-proxies-grid">${$.i18n.prop('proxy-connectors.grid.tab.title')}</a>
     </li>
-    <li id="network-proxies-view-tabs-li-edit">
-      <a href="#network-proxies-edit">${$.i18n.prop('add')}</a>
+    <li id="proxy-connectors-view-tabs-li-edit">
+      <a href="#proxy-connectors-edit">${$.i18n.prop('add')}</a>
     </li>
   </ul>
-  <div id="network-proxies-view-tabs-content" class="tab-content">
-    <div id="network-proxies-view" class="active">
-        <table class="bordered-table zebra-striped" id="networkProxiesTable"
-               data-bind="simpleGrid: gridViewModel,simpleGridTemplate:'ko-network-proxies-grid',pageLinksId:'network-proxiesPagination'">
-        </table>
-        <div id="network-proxiesPagination"></div>
+  <div id="proxy-connectors-view-tabs-content" class="tab-content">
+    <div id="proxy-connectors-view" class="active">
+      <table class="bordered-table zebra-striped" id="proxyConnectorsTable"
+             data-bind="simpleGrid: gridViewModel,simpleGridTemplate:'ko-proxy-connectors-grid',pageLinksId:'proxy-connectorsPagination'">
+      </table>
+      <div id="proxy-connectorsPagination"></div>
     </div>
-    <div id="network-proxies-edit" data-bind='template: {name:"network-proxy-edit-tmpl"}'></div>
+    <div id="proxy-connectors-edit" data-bind='template: {name:"proxy-connectors-edit-tmpl"}'></div>
   </div>
+
+</script>
+
+<script id='ko-proxy-connectors-grid' type='text/x-jquery-tmpl'>
+  <thead>
+    <tr>
+      <th>${$.i18n.prop('proxy-connectors.grid.managedrepo.title')}</th>
+      <th>${$.i18n.prop('proxy-connectors.grid.remoterepo.title')}</th>
+    </tr>
+  </thead>
+
+  {{each(i, row) itemsOnCurrentPage()}}
+    <tr>
+      <td>${row.source()}</td>
+      <td>
+          {{each(j, targetRepo) row.targetRepos()}}
+            <div>${targetRepo}</div>
+          {{/each}}
+      </td>
+    </tr>
+  {{/each}}
 </script>
\ No newline at end of file